Debian Codegraph @

tests/auto/qml/ecmascripttests/test262/test/built-ins/Promise/all/capability-resolve-throws-reject.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 es6id: 25.4.4.1
6 description: >
7 Promise is rejected when the "resolve" capability returns an abrupt
8 completion.
9 info: |
10 1. Let C be the this value.
11 [...]
12 3. Let promiseCapability be ? NewPromiseCapability(C).
13 [...]
14 7. Let result be PerformPromiseAll(iteratorRecord, C, promiseCapability).
15 8. If result is an abrupt completion, then
16 a. If iteratorRecord.[[Done]] is false, let result be
17 IteratorClose(iterator, result).
18 b. IfAbruptRejectPromise(result, promiseCapability).
19
20 25.4.4.1.1 Runtime Semantics: PerformPromiseAll
21
22 [...]
23 6. Repeat
24 [...]
25 d. If next is false, then
26 [...]
27 iii. If remainingElementsCount.[[Value]] is 0, then
28 1. Let valuesArray be CreateArrayFromList(values).
29 2. Perform ? Call(resultCapability.[[Resolve]], undefined, «
30 valuesArray »).
31
32 25.4.1.1.1 IfAbruptRejectPromise
33
34 IfAbruptRejectPromise is a short hand for a sequence of algorithm steps that
35 use a PromiseCapability Record. An algorithm step of the form:
36
37 1. IfAbruptRejectPromise(value, capability).
38
39 means the same thing as:
40
41 1. If value is an abrupt completion, then
42 a. Perform ? Call(capability.[[Reject]], undefined, « value.[[Value]] »).
43 b. Return capability.[[Promise]].
44 2. Else if value is a Completion Record, let value be value.[[Value]].
45 flags: [async]
46 ---*/
47
48 var thrown = new Test262Error();
49 var P = function(executor) {
50 return new Promise(function(_, reject) {
51 executor(function() {
52 throw thrown;
53 }, reject);
54 });
55 };
56
57 Promise.all.call(P, [])
58 .then(function() {
59 $DONE('Promise incorrectly fulfilled.');
60 }, function(reason) {
61 if (reason !== thrown) {
62 $DONE('Promise rejected with incorrect "reason."');
63 return;
64 }
65 $DONE();
66 });