Debian Codegraph @

js/src/tests/test262/built-ins/Promise/all/capability-resolve-throws-no-close.js

raw
1 // Copyright (C) 2016 the V8 project authors. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
3 /*---
4 esid: sec-promise.all
5 description: >
6 Iterator is not closed when the "resolve" capability returns an abrupt
7 completion.
8 info: |
9 1. Let C be the this value.
10 [...]
11 3. Let promiseCapability be ? NewPromiseCapability(C).
12 [...]
13 7. Let result be PerformPromiseAll(iteratorRecord, C, promiseCapability).
14 8. If result is an abrupt completion, then
15 a. If iteratorRecord.[[Done]] is false, let result be
16 IteratorClose(iterator, result).
17 b. IfAbruptRejectPromise(result, promiseCapability).
18
19 25.4.4.1.1 Runtime Semantics: PerformPromiseAll
20
21 [...]
22 6. Repeat
23 [...]
24 d. If next is false, then
25 [...]
26 iii. If remainingElementsCount.[[Value]] is 0, then
27 1. Let valuesArray be CreateArrayFromList(values).
28 2. Perform ? Call(resultCapability.[[Resolve]], undefined, «
29 valuesArray »).
30
31 25.4.1.1.1 IfAbruptRejectPromise
32
33 IfAbruptRejectPromise is a short hand for a sequence of algorithm steps that
34 use a PromiseCapability Record. An algorithm step of the form:
35
36 1. IfAbruptRejectPromise(value, capability).
37
38 means the same thing as:
39
40 1. If value is an abrupt completion, then
41 a. Perform ? Call(capability.[[Reject]], undefined, « value.[[Value]] »).
42 b. Return capability.[[Promise]].
43 2. Else if value is a Completion Record, let value be value.[[Value]].
44 features: [Symbol.iterator]
45 ---*/
46
47 var nextCount = 0;
48 var returnCount = 0;
49 var iter = {};
50 iter[Symbol.iterator] = function() {
51 return {
52 next: function() {
53 nextCount += 1;
54 return {
55 done: true
56 };
57 },
58 return: function() {
59 returnCount += 1;
60 return {};
61 }
62 };
63 };
64 var P = function(executor) {
65 return new Promise(function(_, reject) {
66 executor(function() {
67 throw new Test262Error();
68 }, reject);
69 });
70 };
71
72 P.resolve = Promise.resolve;
73
74 Promise.all.call(P, iter);
75
76 assert.sameValue(nextCount, 1);
77 assert.sameValue(returnCount, 0);
78
79 reportCompare(0, 0);