array-rest-iter-rtrn-close-null.js (2148B)
1 // This file was procedurally generated from the following sources: 2 // - src/dstr-assignment/array-rest-iter-rtrn-close-null.case 3 // - src/dstr-assignment/default/assignment-expr.template 4 /*--- 5 description: IteratorClose throws a TypeError when `return` returns a non-Object value (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 : [ Elisionopt AssignmentRestElement ] 19 20 [...] 21 5. Let result be the result of performing 22 IteratorDestructuringAssignmentEvaluation of AssignmentRestElement with 23 iteratorRecord as the argument 24 6. If iteratorRecord.[[done]] is false, return IteratorClose(iterator, 25 result). 26 27 AssignmentRestElement[Yield] : ... DestructuringAssignmentTarget 28 29 1. If DestructuringAssignmentTarget is neither an ObjectLiteral nor an 30 ArrayLiteral, then 31 a. Let lref be the result of evaluating DestructuringAssignmentTarget. 32 b. ReturnIfAbrupt(lref). 33 34 7.4.6 IteratorClose( iterator, completion ) 35 36 [...] 37 6. Let innerResult be Call(return, iterator, « »). 38 [...] 39 40 7.4.6 IteratorClose( iterator, completion ) 41 42 [...] 43 6. Let innerResult be Call(return, iterator, « »). 44 7. If completion.[[type]] is throw, return Completion(completion). 45 8. If innerResult.[[type]] is throw, return Completion(innerResult). 46 47 ---*/ 48 var iterable = {}; 49 var iterator = { 50 return: function() { 51 return null; 52 } 53 }; 54 var iter; 55 iterable[Symbol.iterator] = function() { 56 return iterator; 57 }; 58 59 function* g() { 60 61 var result; 62 var vals = iterable; 63 64 result = [...{}[yield]] = vals; 65 66 67 68 assert.sameValue(result, vals); 69 70 } 71 72 iter = g(); 73 iter.next(); 74 75 assert.throws(TypeError, function() { 76 iter.return(); 77 }); 78 79 reportCompare(0, 0);