array-elem-trlg-iter-list-rtrn-close.js (2737B)
1 // This file was procedurally generated from the following sources: 2 // - src/dstr-assignment/array-elem-trlg-iter-list-rtrn-close.case 3 // - src/dstr-assignment/default/assignment-expr.template 4 /*--- 5 description: IteratorClose is invoked when evaluation of AssignmentElementList returns a "return" completion and the iterator has not been marked as "done" (AssignmentExpression) 6 esid: sec-variable-statement-runtime-semantics-evaluation 7 features: [Symbol.iterator, generators, destructuring-binding] 8 flags: [generated] 9 info: | 10 VariableDeclaration : BindingPattern Initializer 11 12 1. Let rhs be the result of evaluating Initializer. 13 2. Let rval be GetValue(rhs). 14 3. ReturnIfAbrupt(rval). 15 4. Return the result of performing BindingInitialization for 16 BindingPattern passing rval and undefined as arguments. 17 18 ArrayAssignmentPattern : 19 [ AssignmentElementList , Elisionopt AssignmentRestElementopt ] 20 21 [...] 22 3. Let iteratorRecord be Record {[[iterator]]: iterator, [[done]]: false}. 23 4. Let status be the result of performing 24 IteratorDestructuringAssignmentEvaluation of AssignmentElementList using 25 iteratorRecord as the argument. 26 5. If status is an abrupt completion, then 27 a. If iteratorRecord.[[done]] is false, return IteratorClose(iterator, 28 status). 29 b. Return Completion(status). 30 31 7.4.6 IteratorClose( iterator, completion ) 32 33 [...] 34 6. Let innerResult be Call(return, iterator, « »). 35 7. If completion.[[type]] is throw, return Completion(completion). 36 8. If innerResult.[[type]] is throw, return Completion(innerResult). 37 38 ---*/ 39 var nextCount = 0; 40 var returnCount = 0; 41 var unreachable = 0; 42 var thisValue = null; 43 var args = null; 44 var iterable = {}; 45 var iterator = { 46 next: function() { 47 nextCount += 1; 48 return {done: false, value: undefined}; 49 }, 50 return: function() { 51 returnCount += 1; 52 thisValue = this; 53 args = arguments; 54 return {}; 55 } 56 }; 57 var iter, result; 58 59 iterable[Symbol.iterator] = function() { 60 return iterator; 61 }; 62 63 function* g() { 64 65 var result; 66 var vals = iterable; 67 68 result = [ {} = yield , ] = vals; 69 70 unreachable += 1; 71 72 assert.sameValue(result, vals); 73 74 }; 75 76 iter = g(); 77 iter.next(); 78 79 assert.sameValue(nextCount, 1); 80 assert.sameValue(returnCount, 0); 81 82 result = iter.return(888); 83 84 assert.sameValue(nextCount, 1); 85 assert.sameValue(returnCount, 1); 86 assert.sameValue(unreachable, 0, 'Unreachable statement was not executed'); 87 assert.sameValue(result.value, 888); 88 assert(result.done, 'Iterator correctly closed'); 89 assert.sameValue(thisValue, iterator, 'correct `this` value'); 90 assert(!!args, 'arguments object provided'); 91 assert.sameValue(args.length, 0, 'zero arguments specified'); 92 93 reportCompare(0, 0);