// Copyright (C) 2016 the V8 project authors. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. /*--- description: > IteratorClose is invoked when evaluation of AssignmentElementList returns a "return" completion and the iterator has not been marked as "done" info: | ArrayAssignmentPattern : [ AssignmentElementList , Elisionopt AssignmentRestElementopt ] [...] 3. Let iteratorRecord be Record {[[iterator]]: iterator, [[done]]: false}. 4. Let status be the result of performing IteratorDestructuringAssignmentEvaluation of AssignmentElementList using iteratorRecord as the argument. 5. If status is an abrupt completion, then a. If iteratorRecord.[[done]] is false, return IteratorClose(iterator, status). 7.4.6 IteratorClose( iterator, completion ) [...] 6. Let innerResult be Call(return, iterator, « »). 7. If completion.[[type]] is throw, return Completion(completion). 8. If innerResult.[[type]] is throw, return Completion(innerResult). features: [Symbol.iterator, generators] es6id: 12.14.5.2 esid: sec-runtime-semantics-destructuringassignmentevaluation ---*/ var returnCount = 0; var unreachable = 0; var iterable = {}; var iterator = { return: function() { returnCount += 1; throw new Test262Error(); } }; var iter; iterable[Symbol.iterator] = function() { return iterator; }; function* g() { [ {}[yield] , ] = iterable; unreachable += 1; } iter = g(); iter.next(); assert.throws(Test262Error, function() { iter.return(); }); assert.sameValue(returnCount, 1); assert.sameValue(unreachable, 0, 'Unreachable statement was not executed');