invoke-then-on-promises-every-iteration.js (1197B)
1 // |reftest| async 2 // Copyright (C) 2019 Sergey Rubanov. All rights reserved. 3 // This code is governed by the BSD license found in the LICENSE file. 4 5 /*--- 6 description: > 7 Invocation of the instance's `then` method 8 esid: sec-promise.any 9 info: | 10 5. Let result be PerformPromiseAny(iteratorRecord, C, promiseCapability). 11 6. If result is an abrupt completion, then 12 a. If iteratorRecord.[[Done]] is false, set result to IteratorClose(iteratorRecord, result). 13 b. IfAbruptRejectPromise(result, promiseCapability). 14 15 Runtime Semantics: PerformPromiseAny 16 17 r. Perform ? Invoke(nextPromise, "then", « resultCapability.[[Resolve]], rejectElement »). 18 19 flags: [async] 20 features: [Promise.any, arrow-function] 21 ---*/ 22 23 let promises = [ 24 Promise.resolve(), 25 Promise.resolve(), 26 Promise.resolve(), 27 ]; 28 let callCount = 0; 29 30 promises.forEach(promise => { 31 let boundThen = promise.then.bind(promise); 32 promise.then = function(...args) { 33 assert.sameValue(this, promises[callCount]); 34 callCount += 1; 35 return boundThen(...args); 36 }; 37 }); 38 39 Promise.any(promises) 40 .then(() => { 41 assert.sameValue(callCount, 3, '`then` invoked once for every iterated value'); 42 }).then($DONE, $DONE);