Debian Codegraph @

tests/auto/qml/ecmascripttests/test262/test/built-ins/Promise/all/invoke-resolve.js

raw
1 // Copyright (C) 2015 the V8 project authors. 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 es6id: 25.4.4.1
8 info: |
9 11. Let result be PerformPromiseAll(iteratorRecord, C, promiseCapability).
10
11 [...]
12
13 25.4.4.1.1 Runtime Semantics: PerformPromiseAll
14
15 [...]
16 6. Repeat
17 [...]
18 i. Let nextPromise be Invoke(constructor, "resolve", «nextValue»).
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.all([p1, p2, p3]);
49
50 assert.sameValue(
51 callCount, 3, '`resolve` invoked once for each iterated value'
52 );