yield-star-getiter-async-throw-method-is-null.js (1957B)
1 // |reftest| async 2 // Copyright (C) 2020 Alexey Shvayka. All rights reserved. 3 // This code is governed by the BSD license found in the LICENSE file. 4 /*--- 5 esid: sec-generator-function-definitions-runtime-semantics-evaluation 6 description: > 7 If iterator's "throw" method is `null`, 8 AsyncIteratorClose is called before rising TypeError. 9 info: | 10 YieldExpression : yield * AssignmentExpression 11 12 [...] 13 7. Repeat, 14 [...] 15 b. Else if received.[[Type]] is throw, then 16 i. Let throw be ? GetMethod(iterator, "throw"). 17 ii. If throw is not undefined, then 18 [...] 19 iii. Else, 20 [...] 21 3. If generatorKind is async, perform ? AsyncIteratorClose(iteratorRecord, closeCompletion). 22 [...] 23 6. Throw a TypeError exception. 24 25 GetMethod ( V, P ) 26 27 [...] 28 2. Let func be ? GetV(V, P). 29 3. If func is either undefined or null, return undefined. 30 31 AsyncIteratorClose ( iteratorRecord, completion ) 32 33 [...] 34 4. Let innerResult be GetMethod(iterator, "return"). 35 5. If innerResult.[[Type]] is normal, then 36 a. Let return be innerResult.[[Value]]. 37 b. If return is undefined, return Completion(completion). 38 features: [Symbol.asyncIterator, async-iteration] 39 flags: [async] 40 ---*/ 41 42 var throwGets = 0; 43 var returnGets = 0; 44 var asyncIterable = { 45 [Symbol.asyncIterator]: function() { 46 return this; 47 }, 48 next: function() { 49 return {value: 1, done: false}; 50 }, 51 get throw() { 52 throwGets += 1; 53 return null; 54 }, 55 get return() { 56 returnGets += 1; 57 }, 58 }; 59 60 async function* asyncGenerator() { 61 yield* asyncIterable; 62 } 63 64 var asyncIterator = asyncGenerator(); 65 asyncIterator.next().then(function() { 66 return asyncIterator.throw(); 67 }).then(function(result) { 68 throw new Test262Error("Promise should be rejected, got: " + result.value); 69 }, function(err) { 70 assert.sameValue(err.constructor, TypeError); 71 assert.sameValue(throwGets, 1); 72 assert.sameValue(returnGets, 1); 73 }).then($DONE, $DONE);