Debian Codegraph @

js/src/tests/test262/built-ins/Promise/any/capability-resolve-throws-no-close.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 flags: [async]
21 features: [Promise.any, Symbol.iterator]
22 ---*/
23 let callCount = 0;
24 let nextCount = 0;
25 let returnCount = 0;
26 let iter = {
27 [Symbol.iterator]() {
28 callCount++;
29 return {
30 next() {
31 callCount++;
32 nextCount += 1;
33 return {
34 done: true
35 };
36 },
37 return() {
38 callCount++;
39 returnCount += 1;
40 return {};
41 }
42 };
43 }
44 };
45
46 function P(executor) {
47 callCount++;
48 return new Promise((_, reject) => {
49 callCount++;
50 executor(() => {
51 callCount++;
52 throw new Test262Error();
53 }, (...args) => {
54 callCount++;
55 reject(...args);
56 });
57 });
58 };
59
60 P.resolve = Promise.resolve;
61
62 Promise.any.call(P, iter).then(
63 () => {
64 $DONE('The promise should be rejected.');
65 }, (reason) => {
66 assert.sameValue(nextCount, 1);
67 assert.sameValue(returnCount, 0);
68 assert.sameValue(callCount, 5);
69 }).then($DONE, $DONE);