mirror of
https://github.com/tc39/test262.git
synced 2025-10-17 22:09:07 +02:00
72 lines
1.9 KiB
Plaintext
72 lines
1.9 KiB
Plaintext
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
|
// This code is governed by the BSD license found in the LICENSE file.
|
|
/*---
|
|
desc: >
|
|
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]
|
|
template: default
|
|
esid: sec-runtime-semantics-destructuringassignmentevaluation
|
|
---*/
|
|
|
|
//- setup
|
|
var nextCount = 0;
|
|
var returnCount = 0;
|
|
var unreachable = 0;
|
|
var iterator = {
|
|
next: function() {
|
|
nextCount += 1;
|
|
return {done: false, value: undefined};
|
|
},
|
|
return: function() {
|
|
returnCount += 1;
|
|
|
|
throw new Test262Error();
|
|
}
|
|
};
|
|
var iterable = {};
|
|
iterable[Symbol.iterator] = function() {
|
|
return iterator;
|
|
};
|
|
|
|
function* g() {
|
|
//- elems
|
|
[ {} = yield , ]
|
|
//- vals
|
|
iterable
|
|
//- body
|
|
unreachable += 1;
|
|
//- teardown
|
|
}
|
|
|
|
var iter = g();
|
|
iter.next();
|
|
|
|
assert.sameValue(nextCount, 1);
|
|
assert.sameValue(returnCount, 0);
|
|
assert.throws(Test262Error, function() {
|
|
iter.return();
|
|
});
|
|
assert.sameValue(nextCount, 1);
|
|
assert.sameValue(returnCount, 1);
|
|
assert.sameValue(unreachable, 0, 'Unreachable statement was not executed');
|