invoke-resolve-get-once-no-calls.js (1151B)
1 // Copyright (C) 2019 Leo Balter. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 4 /*--- 5 description: > 6 Gets constructor's `resolve` method once from zero to many invocations. 7 esid: sec-promise.allsettled 8 info: | 9 6. Let result be PerformPromiseAllSettled(iteratorRecord, C, promiseCapability). 10 11 Runtime Semantics: PerformPromiseAllSettled 12 13 6. Let promiseResolve be ? Get(constructor, `"resolve"`). 14 7. 1. If IsCallable(promiseResolve) is false, throw a TypeError exception. 15 8. Repeat 16 ... 17 i. Let nextPromise be ? Call(promiseResolve, constructor, « nextValue »). 18 features: [Promise.allSettled] 19 ---*/ 20 21 var resolve = Promise.resolve; 22 var getCount = 0; 23 var callCount = 0; 24 25 Object.defineProperty(Promise, 'resolve', { 26 configurable: true, 27 get() { 28 getCount += 1; 29 return function() { 30 callCount += 1; 31 return resolve.apply(Promise, arguments); 32 }; 33 } 34 }); 35 36 Promise.allSettled([]); 37 38 assert.sameValue( 39 getCount, 1, 'Got `resolve` only once for each iterated value' 40 ); 41 assert.sameValue( 42 callCount, 0, '`resolve` not called for empty iterator' 43 ); 44 45 reportCompare(0, 0);