| 1 |
// This file was procedurally generated from the following sources: |
| 2 |
// - src/dstr-assignment/array-elem-trlg-iter-rest-rtrn-close-err.case |
| 3 |
// - src/dstr-assignment/default/assignment-expr.template |
| 4 |
/*--- |
| 5 |
description: IteratorClose is called when AssignmentRestEvaluation produces a "return" completion due to reference evaluation (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 |
7. If AssignmentRestElement is present, then |
| 24 |
a. Let status be the result of performing |
| 25 |
IteratorDestructuringAssignmentEvaluation of AssignmentRestElement |
| 26 |
with iteratorRecord as the argument. |
| 27 |
8. If iteratorRecord.[[done]] is false, return IteratorClose(iterator, |
| 28 |
status). |
| 29 |
9. Return Completion(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 x; |
| 43 |
var iterable = {}; |
| 44 |
var iterator = { |
| 45 |
next: function() { |
| 46 |
nextCount += 1; |
| 47 |
// Set an upper-bound to limit unnecessary iteration in non-conformant |
| 48 |
// implementations |
| 49 |
return { done: nextCount > 10 }; |
| 50 |
}, |
| 51 |
return: function() { |
| 52 |
returnCount += 1; |
| 53 |
|
| 54 |
throw new Test262Error(); |
| 55 |
} |
| 56 |
}; |
| 57 |
var iter; |
| 58 |
iterable[Symbol.iterator] = function() { |
| 59 |
return iterator; |
| 60 |
}; |
| 61 |
function* g() { |
| 62 |
|
| 63 |
var result; |
| 64 |
var vals = iterable; |
| 65 |
|
| 66 |
result = [ x , ...{}[yield] ] = vals; |
| 67 |
|
| 68 |
unreachable += 1; |
| 69 |
|
| 70 |
assert.sameValue(result, vals); |
| 71 |
|
| 72 |
} |
| 73 |
|
| 74 |
iter = g(); |
| 75 |
iter.next(); |
| 76 |
|
| 77 |
assert.throws(Test262Error, function() { |
| 78 |
iter.return(); |
| 79 |
}); |
| 80 |
|
| 81 |
assert.sameValue(nextCount, 1); |
| 82 |
assert.sameValue(returnCount, 1); |
| 83 |
assert.sameValue(unreachable, 0, 'Unreachable statement was not executed'); |