Debian Codegraph @

js/src/tests/test262/built-ins/Promise/any/capability-resolve-throws-reject.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 esid: sec-promise.any
6 description: >
7 Iterator is not closed when the "resolve" capability returns an abrupt
8 completion.
9 info: |
10 Let C be the this value.
11 Let promiseCapability be ? NewPromiseCapability(C).
12 Let iteratorRecord be GetIterator(iterable).
13 IfAbruptRejectPromise(iteratorRecord, promiseCapability).
14 Let result be PerformPromiseAny(iteratorRecord, C, promiseCapability).
15 If result is an abrupt completion, then
16 If iteratorRecord.[[Done]] is false, set result to IteratorClose(iteratorRecord, result).
17 IfAbruptRejectPromise(result, promiseCapability).
18 Return Completion(result).
19
20 features: [Promise.any, Symbol.iterator]
21 flags: [async]
22 ---*/
23 let callCount = 0;
24 let thrown = new Test262Error();
25 function P(executor) {
26 callCount++;
27 return new Promise((_, reject) => {
28 callCount++;
29 executor(() => {
30 callCount++;
31 throw thrown;
32 }, (...args) => {
33 callCount++;
34 reject(...args);
35 });
36 });
37 };
38 P.resolve = Promise.resolve;
39
40 Promise.any.call(P, [1])
41 .then(() => {
42 $DONE('Promise incorrectly fulfilled.');
43 }, (error) => {
44 // The error was not the result of promise
45 // resolution, so will not be an AggregateError
46 assert.sameValue(thrown, error);
47 assert.sameValue(callCount, 6);
48 }).then($DONE, $DONE);
49
50