keith_miller@apple.com | bcc77f2 | 2016-07-15 06:03:25 +0000 | [diff] [blame] | 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 | Explicit iterator closing in response to error |
| 7 | es6id: 25.4.4.3 |
| 8 | info: > |
| 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). |
| 22 | features: [Symbol.iterator] |
| 23 | flags: [async] |
| 24 | ---*/ |
| 25 | |
| 26 | var err = new Test262Error(); |
| 27 | var iterDoneSpy = {}; |
| 28 | var callCount = 0; |
| 29 | var CustomPromise = function(executor) { |
| 30 | return new Promise(executor); |
| 31 | }; |
| 32 | iterDoneSpy[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 | |
| 43 | CustomPromise.resolve = function() { |
| 44 | throw err; |
| 45 | }; |
| 46 | |
| 47 | Promise.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 | |
| 55 | assert.sameValue(callCount, 1); |