js/src/tests/test262/language/statements/for-of/dstr/const-ary-ptrn-rest-id-iter-step-err.js
raw symbols SCIP| 1 | // This file was procedurally generated from the following sources: |
| 2 | // - src/dstr-binding/ary-ptrn-rest-id-iter-step-err.case |
| 3 | // - src/dstr-binding/error/for-of-const.template |
| 4 | /*--- |
| 5 | description: Error forwarding when IteratorStep returns an abrupt completion (for-of statement) |
| 6 | esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation |
| 7 | features: [generators, destructuring-binding] |
| 8 | flags: [generated] |
| 9 | info: | |
| 10 | IterationStatement : |
| 11 | for ( ForDeclaration of AssignmentExpression ) Statement |
| 12 | |
| 13 | [...] |
| 14 | 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, |
| 15 | lexicalBinding, labelSet). |
| 16 | |
| 17 | 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation |
| 18 | |
| 19 | [...] |
| 20 | 3. Let destructuring be IsDestructuring of lhs. |
| 21 | [...] |
| 22 | 5. Repeat |
| 23 | [...] |
| 24 | h. If destructuring is false, then |
| 25 | [...] |
| 26 | i. Else |
| 27 | i. If lhsKind is assignment, then |
| 28 | [...] |
| 29 | ii. Else if lhsKind is varBinding, then |
| 30 | [...] |
| 31 | iii. Else, |
| 32 | 1. Assert: lhsKind is lexicalBinding. |
| 33 | 2. Assert: lhs is a ForDeclaration. |
| 34 | 3. Let status be the result of performing BindingInitialization |
| 35 | for lhs passing nextValue and iterationEnv as arguments. |
| 36 | [...] |
| 37 | |
| 38 | 13.3.3.6 Runtime Semantics: IteratorBindingInitialization |
| 39 | BindingRestElement : ... BindingIdentifier |
| 40 | 1. Let lhs be ResolveBinding(StringValue of BindingIdentifier, |
| 41 | environment). |
| 42 | 2. ReturnIfAbrupt(lhs). 3. Let A be ArrayCreate(0). 4. Let n=0. 5. Repeat, |
| 43 | a. If iteratorRecord.[[done]] is false, |
| 44 | i. Let next be IteratorStep(iteratorRecord.[[iterator]]). |
| 45 | ii. If next is an abrupt completion, set iteratorRecord.[[done]] to |
| 46 | true. |
| 47 | iii. ReturnIfAbrupt(next). |
| 48 | |
| 49 | ---*/ |
| 50 | var first = 0; |
| 51 | var second = 0; |
| 52 | var iter = function*() { |
| 53 | first += 1; |
| 54 | throw new Test262Error(); |
| 55 | second += 1; |
| 56 | }(); |
| 57 | |
| 58 | assert.throws(Test262Error, function() { |
| 59 | for (const [...x] of [iter]) { |
| 60 | return; |
| 61 | } |
| 62 | }); |
| 63 | |
| 64 | iter.next(); |
| 65 | assert.sameValue(first, 1); |
| 66 | assert.sameValue(second, 0, 'Iterator is closed following abrupt completion.'); |
| 67 | |
| 68 | reportCompare(0, 0); |