Debian Codegraph @

js/src/tests/test262/built-ins/Promise/allSettled/invoke-resolve.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 Invocation of the constructor's `resolve` method
7 esid: sec-promise.allsettled
8 info: |
9 6. Let result be PerformPromiseAllSettled(iteratorRecord, C, promiseCapability).
10
11 Runtime Semantics: PerformPromiseAllSettled
12
13 6. Repeat
14 ...
15 i. Let nextPromise be ? Invoke(constructor, "resolve", « nextValue »).
16 ...
17 z. Perform ? Invoke(nextPromise, "then", « resolveElement, rejectElement »).
18 features: [Promise.allSettled]
19 ---*/
20
21 var p1 = new Promise(function() {});
22 var p2 = new Promise(function() {});
23 var p3 = new Promise(function() {});
24 var resolve = Promise.resolve;
25 var callCount = 0;
26 var current = p1;
27 var next = p2;
28 var afterNext = p3;
29
30 Promise.resolve = function(nextValue) {
31 assert.sameValue(
32 nextValue, current, '`resolve` invoked with next iterated value'
33 );
34 assert.sameValue(
35 arguments.length, 1, '`resolve` invoked with a single argument'
36 );
37 assert.sameValue(this, Promise, '`this` value is the constructor');
38
39 current = next;
40 next = afterNext;
41 afterNext = null;
42
43 callCount += 1;
44
45 return resolve.apply(Promise, arguments);
46 };
47
48 Promise.allSettled([p1, p2, p3]);
49
50 assert.sameValue(
51 callCount, 3, '`resolve` invoked once for each iterated value'
52 );
53
54 reportCompare(0, 0);