Debian Codegraph @

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