array-elem-trlg-iter-rest-rtrn-close.js (2661B)
1 // This file was procedurally generated from the following sources: 2 // - src/dstr-assignment/array-elem-trlg-iter-rest-rtrn-close.case 3 // - src/dstr-assignment/default/assignment-expr.template 4 /*--- 5 description: IteratorClose is called when AssignmentRestEvaluation produces a "return" completion due to reference evaluation (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 7. If AssignmentRestElement is present, then 23 a. Let status be the result of performing 24 IteratorDestructuringAssignmentEvaluation of AssignmentRestElement 25 with iteratorRecord as the argument. 26 8. If iteratorRecord.[[done]] is false, return IteratorClose(iterator, 27 status). 28 9. Return Completion(status). 29 30 7.4.6 IteratorClose( iterator, completion ) 31 32 [...] 33 6. Let innerResult be Call(return, iterator, « »). 34 7. If completion.[[type]] is throw, return Completion(completion). 35 8. If innerResult.[[type]] is throw, return Completion(innerResult). 36 37 ---*/ 38 var nextCount = 0; 39 var returnCount = 0; 40 var unreachable = 0; 41 var thisValue = null; 42 var args = null; 43 var iterable = {}; 44 var x; 45 var iterator = { 46 next: function() { 47 nextCount += 1; 48 // Set an upper-bound to limit unnecessary iteration in non-conformant 49 // implementations 50 return { done: nextCount > 10 }; 51 }, 52 return: function() { 53 returnCount += 1; 54 thisValue = this; 55 args = arguments; 56 return {}; 57 } 58 }; 59 var iter, result; 60 iterable[Symbol.iterator] = function() { 61 return iterator; 62 }; 63 64 function* g() { 65 66 var result; 67 var vals = iterable; 68 69 result = [ x , ...{}[yield] ] = vals; 70 71 unreachable += 1; 72 73 assert.sameValue(result, vals); 74 75 } 76 77 iter = g(); 78 iter.next(); 79 result = iter.return(999); 80 81 assert.sameValue(nextCount, 1); 82 assert.sameValue(returnCount, 1); 83 assert.sameValue(unreachable, 0, 'Unreachable statement was not executed'); 84 assert.sameValue(result.value, 999); 85 assert(result.done, 'Iterator correctly closed'); 86 assert.sameValue(thisValue, iterator, 'correct `this` value'); 87 assert(!!args, 'arguments object provided'); 88 assert.sameValue(args.length, 0, 'zero arguments specified'); 89 90 reportCompare(0, 0);