resolved-sequence-with-rejections.js (1829B)
1 // |reftest| async 2 // Copyright (C) 2020 Rick Waldron. All rights reserved. 3 // This code is governed by the BSD license found in the LICENSE file. 4 5 /*--- 6 esid: sec-promise.any 7 description: Resolution ticks are set in a predictable sequence 8 info: | 9 Runtime Semantics: PerformPromiseAny ( iteratorRecord, constructor, resultCapability ) 10 11 Let remainingElementsCount be a new Record { [[Value]]: 1 }. 12 ... 13 14 Set remainingElementsCount.[[Value]] to remainingElementsCount.[[Value]] - 1. 15 If remainingElementsCount.[[Value]] is 0, then 16 Let error be a newly created AggregateError object. 17 Perform ! DefinePropertyOrThrow(error, "errors", 18 Property Descriptor { 19 [[Configurable]]: true, 20 [[Enumerable]]: false, 21 [[Writable]]: true, 22 [[Value]]: errors 23 }). 24 Return ? Call(promiseCapability.[[Reject]], undefined, « error »). 25 ... 26 flags: [async] 27 includes: [promiseHelper.js] 28 features: [Promise.any] 29 ---*/ 30 31 let sequence = []; 32 33 let p1 = new Promise((_, reject) => { 34 reject('foo'); 35 }); 36 let p2 = new Promise((_, reject) => { 37 reject('bar'); 38 }); 39 40 sequence.push(1); 41 42 p1.catch(() => { 43 sequence.push(3); 44 assert.sameValue(sequence.length, 3); 45 checkSequence(sequence, 'Expected to be called first.'); 46 }).catch($DONE); 47 48 Promise.any([p1, p2]).then(() => { 49 sequence.push(5); 50 assert.sameValue(sequence.length, 5); 51 checkSequence(sequence, 'Expected to be called third.'); 52 }).then($DONE, outcome => { 53 assert(outcome instanceof AggregateError); 54 assert.sameValue(outcome.errors.length, 2); 55 assert.sameValue(outcome.errors[0], 'foo'); 56 assert.sameValue(outcome.errors[1], 'bar'); 57 }).then($DONE, $DONE); 58 59 p2.catch(() => { 60 sequence.push(4); 61 assert.sameValue(sequence.length, 4); 62 checkSequence(sequence, 'Expected to be called second.'); 63 }).catch($DONE); 64 65 sequence.push(2);