Debian Codegraph @

js/src/tests/test262/built-ins/Promise/any/invoke-then-error-close.js

raw
1 // |reftest| async
2 // Copyright (C) 2019 Leo Balter, 2020 Rick Waldron. All rights reserved.
3 // This code is governed by the BSD license found in the LICENSE file.
4 /*---
5 description: >
6 Error thrown when invoking the instance's `then` method (closing iterator)
7 esid: sec-promise.any
8 info: |
9 5. Let result be PerformPromiseAny(iteratorRecord, C, promiseCapability).
10 6. If result is an abrupt completion, then
11 a. If iteratorRecord.[[Done]] is false, set result to IteratorClose(iteratorRecord, result).
12 b. IfAbruptRejectPromise(result, promiseCapability).
13
14 Runtime Semantics: PerformPromiseAny
15
16 r. Perform ? Invoke(nextPromise, "then", « resultCapability.[[Resolve]], rejectElement »).
17
18 flags: [async]
19 features: [Promise.any, Symbol.iterator, arrow-function, computed-property-names, Symbol]
20 ---*/
21
22 let error = new Test262Error();
23 let promise = Promise.resolve();
24 let returnCount = 0;
25 let iter = {
26 [Symbol.iterator]() {
27 return {
28 next() {
29 return {
30 done: false,
31 value: promise
32 };
33 },
34 return() {
35 returnCount += 1;
36 return {};
37 }
38 };
39 }
40 };
41
42 promise.then = function() {
43 throw error;
44 };
45
46 Promise.any(iter).then(() => {
47 $DONE('The promise should be rejected, but was resolved');
48 }, (reason) => {
49 assert.sameValue(returnCount, 1);
50 assert.sameValue(reason, error);
51 }).then($DONE, $DONE);