Debian Codegraph @

js/src/tests/test262/built-ins/Promise/all/invoke-resolve-get-once-no-calls.js

raw
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.all
8 info: |
9 Runtime Semantics: PerformPromiseAll
10
11 1. Let promiseResolve be ? Get(constructor, `"resolve"`).
12 1. If IsCallable(promiseResolve) is false, throw a TypeError exception.
13 ...
14 1. Repeat,
15 ...
16 1. Let nextPromise be ? Call(promiseResolve, constructor, « nextValue »).
17 ---*/
18
19 var resolve = Promise.resolve;
20 var getCount = 0;
21 var callCount = 0;
22
23 Object.defineProperty(Promise, 'resolve', {
24 configurable: true,
25 get() {
26 getCount += 1;
27 return function() {
28 callCount += 1;
29 return resolve.apply(Promise, arguments);
30 };
31 }
32 });
33
34 Promise.all([]);
35
36 assert.sameValue(
37 getCount, 1, 'Got `resolve` only once for each iterated value'
38 );
39 assert.sameValue(
40 callCount, 0, '`resolve` not called for empty iterator'
41 );
42
43 reportCompare(0, 0);