reject-ignored-deferred.js (1821B)
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 esid: sec-promise.any 6 description: > 7 Resolved promises ignore rejections through deferred invocation of the 8 provided resolving function 9 info: | 10 Let result be PerformPromiseAny(iteratorRecord, C, promiseCapability). 11 12 Runtime Semantics: PerformPromiseAny 13 14 ... 15 Let remainingElementsCount be a new Record { [[value]]: 1 }. 16 ... 17 8.d ... 18 ii. Set remainingElementsCount.[[value]] to remainingElementsCount.[[value]] − 1. 19 iii. If remainingElementsCount.[[value]] is 0, 20 1. Let error be a newly created AggregateError object. 21 2. Perform ! DefinePropertyOrThrow(error, "errors", Property Descriptor { [[Configurable]]: true, [[Enumerable]]: false, [[Writable]]: true, [[Value]]: errors }). 22 3. Return ThrowCompletion(error). 23 ... 24 25 Promise.any Reject Element Functions 26 ... 27 Let alreadyCalled be the value of F's [[AlreadyCalled]] internal slot. 28 If alreadyCalled.[[value]] is true, return undefined. 29 Set alreadyCalled.[[value]] to true. 30 ... 31 32 flags: [async] 33 features: [Promise.any, arrow-function] 34 ---*/ 35 36 let callCount = 0; 37 let fulfiller = { 38 then(resolve) { 39 new Promise((resolve) => { 40 callCount++; 41 resolve(); 42 }) 43 .then(() => { 44 callCount++; 45 resolve(); 46 }); 47 } 48 }; 49 let rejector = { 50 then(resolve, reject) { 51 new Promise((resolve) => { 52 callCount++; 53 resolve(); 54 }) 55 .then(() => { 56 callCount++; 57 resolve(); 58 reject(); 59 }); 60 } 61 }; 62 63 Promise.all([fulfiller, rejector]) 64 .then(() => { 65 assert.sameValue(callCount, 4, "callCount === 4"); 66 $DONE(); 67 }, () => { 68 $DONE("The promise should not be rejected."); 69 });