async-gen-decl-dstr-array-elem-iter-rtrn-close-null.js (2699B)
1 // |reftest| async 2 // This file was procedurally generated from the following sources: 3 // - src/dstr-assignment-for-await/array-elem-iter-rtrn-close-null.case 4 // - src/dstr-assignment-for-await/async-generator/async-gen-decl.template 5 /*--- 6 description: IteratorClose throws a TypeError when `return` returns a non-Object value (for-await-of statement in an async generator declaration) 7 esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation 8 features: [Symbol.iterator, generators, destructuring-binding, async-iteration] 9 flags: [generated, async] 10 info: | 11 IterationStatement : 12 for await ( LeftHandSideExpression of AssignmentExpression ) Statement 13 14 1. Let keyResult be the result of performing ? ForIn/OfHeadEvaluation(« », 15 AssignmentExpression, iterate). 16 2. Return ? ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, 17 keyResult, assignment, labelSet). 18 19 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation 20 21 [...] 22 5. If destructuring is true and if lhsKind is assignment, then 23 a. Assert: lhs is a LeftHandSideExpression. 24 b. Let assignmentPattern be the parse of the source text corresponding to 25 lhs using AssignmentPattern as the goal symbol. 26 [...] 27 28 ArrayAssignmentPattern : [ AssignmentElementList ] 29 30 [...] 31 4. If iteratorRecord.[[Done]] is false, return ? IteratorClose(iterator, result). 32 5. Return result. 33 34 7.4.6 IteratorClose( iterator, completion ) 35 36 [...] 37 5. Let innerResult be Call(return, iterator, « »). 38 6. If completion.[[Type]] is throw, return Completion(completion). 39 7. If innerResult.[[Type]] is throw, return Completion(innerResult). 40 8. If Type(innerResult.[[Value]]) is not Object, throw a TypeError exception. 41 42 ---*/ 43 let unreachable = 0; 44 let nextCount = 0; 45 let returnCount = 0; 46 let iterator = { 47 next() { 48 nextCount += 1; 49 return {done: false, value: undefined}; 50 }, 51 return() { 52 returnCount += 1; 53 return null; 54 } 55 }; 56 let iterable = { 57 [Symbol.iterator]() { 58 return iterator; 59 } 60 }; 61 62 let iterCount = 0; 63 async function * fn() { 64 for await ([ {} = yield ] of [iterable]) { 65 unreachable += 1; 66 iterCount += 1; 67 } 68 } 69 70 let iter = fn(); 71 72 iter.next().then(result => { 73 assert.sameValue(nextCount, 1); 74 assert.sameValue(returnCount, 0); 75 assert.sameValue(result.value, undefined); 76 assert.sameValue(result.done, false); 77 78 iter.return().then(() => $DONE('Promise incorrectly fulfilled.'), ({ constructor }) => { 79 assert.sameValue(nextCount, 1); 80 assert.sameValue(returnCount, 1); 81 assert.sameValue(unreachable, 0); 82 assert.sameValue(constructor, TypeError); 83 }).then($DONE, $DONE); 84 }, $DONE).catch($DONE);