| 1 |
// |reftest| async |
| 2 |
// Copyright (C) 2019 Leo Balter. All rights reserved. |
| 3 |
// This code is governed by the BSD license found in the LICENSE file. |
| 4 |
|
| 5 |
/*--- |
| 6 |
esid: sec-promise.allsettled |
| 7 |
description: > |
| 8 |
Resolution ticks are set in a predictable sequence of mixed fulfilled and rejected promises |
| 9 |
info: | |
| 10 |
Runtime Semantics: PerformPromiseAllSettled ( iteratorRecord, constructor, resultCapability ) |
| 11 |
|
| 12 |
4. Let remainingElementsCount be a new Record { [[Value]]: 1 }. |
| 13 |
... |
| 14 |
6.d ... |
| 15 |
ii. Set remainingElementsCount.[[value]] to remainingElementsCount.[[value]] − 1. |
| 16 |
iii. If remainingElementsCount.[[value]] is 0, then |
| 17 |
1. Let valuesArray be CreateArrayFromList(values). |
| 18 |
2. Perform ? Call(resultCapability.[[Resolve]], undefined, « valuesArray »). |
| 19 |
... |
| 20 |
flags: [async] |
| 21 |
includes: [promiseHelper.js] |
| 22 |
features: [Promise.allSettled] |
| 23 |
---*/ |
| 24 |
|
| 25 |
var sequence = []; |
| 26 |
|
| 27 |
var p1 = new Promise(function(_, reject) { |
| 28 |
reject(''); |
| 29 |
}); |
| 30 |
var p2 = new Promise(function(resolve) { |
| 31 |
resolve(''); |
| 32 |
}); |
| 33 |
var p3 = new Promise(function(_, reject) { |
| 34 |
reject(''); |
| 35 |
}); |
| 36 |
|
| 37 |
sequence.push(1); |
| 38 |
|
| 39 |
p1.catch(function() { |
| 40 |
sequence.push(3); |
| 41 |
assert.sameValue(sequence.length, 3); |
| 42 |
checkSequence(sequence, 'Expected to be called first.'); |
| 43 |
}); |
| 44 |
|
| 45 |
Promise.allSettled([p1, p2, p3]).then(function() { |
| 46 |
sequence.push(6); |
| 47 |
assert.sameValue(sequence.length, 6); |
| 48 |
checkSequence(sequence, 'Expected to be called fourth.'); |
| 49 |
}).then($DONE, $DONE); |
| 50 |
|
| 51 |
p2.then(function() { |
| 52 |
sequence.push(4); |
| 53 |
assert.sameValue(sequence.length, 4); |
| 54 |
checkSequence(sequence, 'Expected to be called second.'); |
| 55 |
}); |
| 56 |
|
| 57 |
sequence.push(2); |
| 58 |
|
| 59 |
p3.catch(function() { |
| 60 |
sequence.push(5); |
| 61 |
assert.sameValue(sequence.length, 5); |
| 62 |
checkSequence(sequence, 'Expected to be called third.'); |
| 63 |
}); |