array-elision-iter-nrml-close-null.js (1730B)
1 // This file was procedurally generated from the following sources: 2 // - src/dstr-assignment/array-elision-iter-nrml-close-null.case 3 // - src/dstr-assignment/error/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, 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 : [ Elision ] 19 20 1. Let iterator be GetIterator(value). 21 [...] 22 5. If iteratorRecord.[[done]] is false, return IteratorClose(iterator, 23 result). 24 [...] 25 26 7.4.6 IteratorClose( iterator, completion ) 27 28 [...] 29 6. Let innerResult be Call(return, iterator, « »). 30 7. If completion.[[type]] is throw, return Completion(completion). 31 8. If innerResult.[[type]] is throw, return Completion(innerResult). 32 9. If Type(innerResult.[[value]]) is not Object, throw a TypeError 33 exception. 34 35 ---*/ 36 var iterable = {}; 37 var nextCount = 0; 38 var iterator = { 39 next: function() { 40 nextCount += 1; 41 // Set an upper-bound to limit unnecessary iteration in non-conformant 42 // implementations 43 return { done: nextCount > 10 }; 44 }, 45 return: function() { 46 return null; 47 } 48 }; 49 iterable[Symbol.iterator] = function() { 50 return iterator; 51 }; 52 53 assert.throws(TypeError, function() { 54 0, [ , ] = iterable; 55 }); 56 57 reportCompare(0, 0);