Debian Codegraph @

js/src/tests/test262/built-ins/Promise/race/resolved-sequence-mixed.js

raw
1 // |reftest| async
2 // Copyright (C) 2020 Rick Waldron. All rights reserved.
3 // This code is governed by the BSD license found in the LICENSE file.
4
5 /*---
6 esid: sec-promise.race
7 description: >
8 Resolution ticks are set in a predictable sequence of mixed fulfilled and rejected promises
9 info: |
10 PerformPromiseRace
11
12 Repeat,
13 Let next be IteratorStep(iteratorRecord).
14 If next is an abrupt completion, set iteratorRecord.[[Done]] to true.
15 ReturnIfAbrupt(next).
16 If next is false, then
17 Set iteratorRecord.[[Done]] to true.
18 Return resultCapability.[[Promise]].
19 Let nextValue be IteratorValue(next).
20 If nextValue is an abrupt completion, set iteratorRecord.[[Done]] to true.
21 ReturnIfAbrupt(nextValue).
22 Let nextPromise be ? Call(promiseResolve, constructor, « nextValue »).
23 Perform ? Invoke(nextPromise, "then", « resultCapability.[[Resolve]], resultCapability.[[Reject]] »).
24
25 flags: [async]
26 includes: [promiseHelper.js]
27 ---*/
28
29 let a = Promise.reject('');
30 let b = new Promise(resolve => resolve(''));
31 let c = new Promise((_, reject) => reject(''));
32 let sequence = [1];
33 Promise.all([
34 a.catch(() => {
35 sequence.push(3);
36 }),
37 Promise.race([a, b, c]).then(() => {
38 // This should not be present when the final
39 // sequence is evaluated.
40 sequence.push(5);
41 }),
42 b.then(() => {
43 sequence.push(4);
44 }),
45 ]).catch(() => {
46 assert.sameValue(sequence.length, 4);
47 checkSequence(sequence);
48 }).then($DONE, $DONE);
49 sequence.push(2);