Debian Codegraph @

js/src/tests/test262/built-ins/Promise/race/resolve-from-same-thenable.js

raw
1 // Copyright (C) 2020 Rick Waldron. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
3
4 /*---
5 esid: sec-performpromiserace
6 description: >
7 Promise.race does not prevent resolve from being called multiple times.
8 info: |
9 PerformPromiseRace
10
11 Repeat,
12 Let next be IteratorStep(iteratorRecord).
13 If next is an abrupt completion, set iteratorRecord.[[Done]] to true.
14 ReturnIfAbrupt(next).
15 If next is false, then
16 Set iteratorRecord.[[Done]] to true.
17 Return resultCapability.[[Promise]].
18 Let nextValue be IteratorValue(next).
19 If nextValue is an abrupt completion, set iteratorRecord.[[Done]] to true.
20 ReturnIfAbrupt(nextValue).
21 Let nextPromise be ? Call(promiseResolve, constructor, « nextValue »).
22 Perform ? Invoke(nextPromise, "then", « resultCapability.[[Resolve]], resultCapability.[[Reject]] »).
23
24 includes: [promiseHelper.js]
25 ---*/
26
27 let callCount = 0;
28 let sequence = [];
29
30 function Constructor(executor) {
31 function resolve(value) {
32 callCount += 1;
33 sequence.push(value);
34 }
35 executor(resolve, Test262Error.thrower);
36 }
37 Constructor.resolve = function(v) {
38 return v;
39 };
40
41 let pResolve;
42 let a = {
43 then(resolver, rejector) {
44 pResolve = resolver;
45 }
46 };
47
48 assert.sameValue(callCount, 0, 'callCount before call to race()');
49
50 Promise.race.call(Constructor, [a]);
51
52 assert.sameValue(callCount, 0, 'callCount after call to race()');
53
54 pResolve(1);
55 pResolve(2);
56 pResolve(3);
57
58 assert.sameValue(callCount, 3, 'callCount after resolving a');
59 assert.sameValue(sequence.length, 3);
60 checkSequence(sequence);
61
62 reportCompare(0, 0);