| 1 |
// This file was procedurally generated from the following sources: |
| 2 |
// - src/dstr-assignment/array-elem-trlg-iter-list-rtrn-close-err.case |
| 3 |
// - src/dstr-assignment/default/assignment-expr.template |
| 4 |
/*--- |
| 5 |
description: IteratorClose is invoked when evaluation of AssignmentElementList returns a "return" completion and the iterator has not been marked as "done" (AssignmentExpression) |
| 6 |
esid: sec-variable-statement-runtime-semantics-evaluation |
| 7 |
es6id: 13.3.2.4 |
| 8 |
features: [Symbol.iterator, generators, destructuring-binding] |
| 9 |
flags: [generated] |
| 10 |
info: | |
| 11 |
VariableDeclaration : BindingPattern Initializer |
| 12 |
|
| 13 |
1. Let rhs be the result of evaluating Initializer. |
| 14 |
2. Let rval be GetValue(rhs). |
| 15 |
3. ReturnIfAbrupt(rval). |
| 16 |
4. Return the result of performing BindingInitialization for |
| 17 |
BindingPattern passing rval and undefined as arguments. |
| 18 |
|
| 19 |
ArrayAssignmentPattern : |
| 20 |
[ AssignmentElementList , Elisionopt AssignmentRestElementopt ] |
| 21 |
|
| 22 |
[...] |
| 23 |
3. Let iteratorRecord be Record {[[iterator]]: iterator, [[done]]: false}. |
| 24 |
4. Let status be the result of performing |
| 25 |
IteratorDestructuringAssignmentEvaluation of AssignmentElementList using |
| 26 |
iteratorRecord as the argument. |
| 27 |
5. If status is an abrupt completion, then |
| 28 |
a. If iteratorRecord.[[done]] is false, return IteratorClose(iterator, |
| 29 |
status). |
| 30 |
|
| 31 |
7.4.6 IteratorClose( iterator, completion ) |
| 32 |
|
| 33 |
[...] |
| 34 |
6. Let innerResult be Call(return, iterator, « »). |
| 35 |
7. If completion.[[type]] is throw, return Completion(completion). |
| 36 |
8. If innerResult.[[type]] is throw, return Completion(innerResult). |
| 37 |
|
| 38 |
---*/ |
| 39 |
var nextCount = 0; |
| 40 |
var returnCount = 0; |
| 41 |
var unreachable = 0; |
| 42 |
var iterator = { |
| 43 |
next: function() { |
| 44 |
nextCount += 1; |
| 45 |
return {done: false, value: undefined}; |
| 46 |
}, |
| 47 |
return: function() { |
| 48 |
returnCount += 1; |
| 49 |
|
| 50 |
throw new Test262Error(); |
| 51 |
} |
| 52 |
}; |
| 53 |
var iterable = {}; |
| 54 |
iterable[Symbol.iterator] = function() { |
| 55 |
return iterator; |
| 56 |
}; |
| 57 |
|
| 58 |
function* g() { |
| 59 |
|
| 60 |
var result; |
| 61 |
var vals = iterable; |
| 62 |
|
| 63 |
result = [ {} = yield , ] = vals; |
| 64 |
|
| 65 |
unreachable += 1; |
| 66 |
|
| 67 |
assert.sameValue(result, vals); |
| 68 |
|
| 69 |
} |
| 70 |
|
| 71 |
var iter = g(); |
| 72 |
iter.next(); |
| 73 |
|
| 74 |
assert.sameValue(nextCount, 1); |
| 75 |
assert.sameValue(returnCount, 0); |
| 76 |
assert.throws(Test262Error, function() { |
| 77 |
iter.return(); |
| 78 |
}); |
| 79 |
assert.sameValue(nextCount, 1); |
| 80 |
assert.sameValue(returnCount, 1); |
| 81 |
assert.sameValue(unreachable, 0, 'Unreachable statement was not executed'); |