invoke-resolve-on-promises-every-iteration-of-custom.js (1249B)
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 description: > 7 Invocation of the constructor's `resolve` method for iterable with promise values 8 esid: sec-promise.all 9 info: | 10 Let result be PerformPromiseAll(iteratorRecord, C, promiseCapability). 11 12 Runtime Semantics: PerformPromiseAll 13 14 Repeat 15 ... 16 Let nextPromise be ? Call(promiseResolve, constructor, « nextValue »). 17 18 flags: [async] 19 features: [class, arrow-function] 20 ---*/ 21 class Custom extends Promise {} 22 23 let values = [1, 1, 1]; 24 let cresolveCallCount = 0; 25 let presolveCallCount = 0; 26 let boundCustomResolve = Custom.resolve.bind(Custom); 27 let boundPromiseResolve = Promise.resolve.bind(Promise); 28 29 Custom.resolve = function(...args) { 30 cresolveCallCount += 1; 31 return boundCustomResolve(...args); 32 }; 33 34 Promise.resolve = function(...args) { 35 presolveCallCount += 1; 36 return boundPromiseResolve(...args); 37 }; 38 39 Promise.all.call(Custom, values) 40 .then(() => { 41 assert.sameValue(presolveCallCount, 0, '`Promise.resolve` is never invoked'); 42 assert.sameValue(cresolveCallCount, 3, '`Custom.resolve` invoked once for every iterated promise'); 43 }).then($DONE, $DONE);