blob: f66dc68c3c93b5df9b6ada0ed998b1e0e51a4fd7 [file] [log] [blame]
keith_miller@apple.combcc77f22016-07-15 06:03:25 +00001// 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/*---
5description: >
6 Explicit iterator closing in response to error
7es6id: 25.4.4.3
8info: >
9 11. Let result be PerformPromiseRace(iteratorRecord, promiseCapability, C).
10 12. If result is an abrupt completion, then
11 a. If iteratorRecord.[[done]] is false, let result be
12 IteratorClose(iterator,result).
13 b. IfAbruptRejectPromise(result, promiseCapability).
14
15
16 25.4.4.3.1 Runtime Semantics: PerformPromiseRace
17
18 1. Repeat
19 [...]
20 h. Let nextPromise be Invoke(C, "resolve", «nextValue»).
21 i. ReturnIfAbrupt(nextPromise).
22features: [Symbol.iterator]
23flags: [async]
24---*/
25
26var err = new Test262Error();
27var iterDoneSpy = {};
28var callCount = 0;
29var CustomPromise = function(executor) {
30 return new Promise(executor);
31};
32iterDoneSpy[Symbol.iterator] = function() {
33 return {
34 next: function() {
35 return { value: null, done: false };
36 },
37 return: function() {
38 callCount += 1;
39 }
40 };
41};
42
43CustomPromise.resolve = function() {
44 throw err;
45};
46
47Promise.race.call(CustomPromise, iterDoneSpy)
48 .then(function() {
49 $ERROR('The promise should be rejected.');
50 }, function(reason) {
51 assert.sameValue(reason, err);
52 $DONE();
53 });
54
55assert.sameValue(callCount, 1);