Debian Codegraph @

tests/auto/qml/ecmascripttests/test262/test/built-ins/Promise/race/invoke-then-error-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 /*---
5 description: >
6 Error thrown when invoking the instance's `then` method (closing iterator)
7 esid: sec-promise.race
8 es6id: 25.4.4.3
9 info: |
10 11. Let result be PerformPromiseRace(iteratorRecord, C, promiseCapability).
11 12. If result is an abrupt completion,
12 a. If iteratorRecord.[[done]] is false, let result be
13 IteratorClose(iterator, result).
14 b. IfAbruptRejectPromise(result, promiseCapability).
15
16 [...]
17
18 25.4.4.3.1 Runtime Semantics: PerformPromiseRace
19
20 1. Repeat
21 [...]
22 j. Let result be Invoke(nextPromise, "then",
23 «promiseCapability.[[Resolve]], promiseCapability.[[Reject]]»).
24 k. ReturnIfAbrupt(result).
25 features: [Symbol.iterator]
26 ---*/
27
28 var promise = new Promise(function() {});
29 var iter = {};
30 var returnCount = 0;
31 iter[Symbol.iterator] = function() {
32 return {
33 next: function() {
34 return {
35 done: false,
36 value: promise
37 };
38 },
39 return: function() {
40 returnCount += 1;
41 return {};
42 }
43 };
44 };
45 promise.then = function() {
46 throw new Test262Error();
47 };
48
49 Promise.race(iter);
50
51 assert.sameValue(returnCount, 1);