keith_miller@apple.com | bcc77f2 | 2016-07-15 06:03:25 +0000 | [diff] [blame] | 1 | // This file was procedurally generated from the following sources: |
| 2 | // - src/dstr-binding/obj-ptrn-prop-id-init-skipped.case |
| 3 | // - src/dstr-binding/default/for-of-const.template |
| 4 | /*--- |
| 5 | description: Destructuring initializer is not evaluated when value is not `undefined` (for-of statement) |
| 6 | esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation |
| 7 | es6id: 13.7.5.11 |
| 8 | features: [destructuring-binding] |
| 9 | flags: [generated] |
| 10 | info: | |
| 11 | IterationStatement : |
| 12 | for ( ForDeclaration of AssignmentExpression ) Statement |
| 13 | |
| 14 | [...] |
| 15 | 3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, |
| 16 | lexicalBinding, labelSet). |
| 17 | |
| 18 | 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation |
| 19 | |
| 20 | [...] |
| 21 | 3. Let destructuring be IsDestructuring of lhs. |
| 22 | [...] |
| 23 | 5. Repeat |
| 24 | [...] |
| 25 | h. If destructuring is false, then |
| 26 | [...] |
| 27 | i. Else |
| 28 | i. If lhsKind is assignment, then |
| 29 | [...] |
| 30 | ii. Else if lhsKind is varBinding, then |
| 31 | [...] |
| 32 | iii. Else, |
| 33 | 1. Assert: lhsKind is lexicalBinding. |
| 34 | 2. Assert: lhs is a ForDeclaration. |
| 35 | 3. Let status be the result of performing BindingInitialization |
| 36 | for lhs passing nextValue and iterationEnv as arguments. |
| 37 | [...] |
| 38 | |
| 39 | 13.3.3.7 Runtime Semantics: KeyedBindingInitialization |
| 40 | |
| 41 | BindingElement : BindingPattern Initializeropt |
| 42 | |
| 43 | [...] |
| 44 | 3. If Initializer is present and v is undefined, then |
| 45 | [...] |
| 46 | ---*/ |
| 47 | var initCount = 0; |
| 48 | function counter() { |
| 49 | initCount += 1; |
| 50 | } |
| 51 | |
| 52 | var iterCount = 0; |
| 53 | |
| 54 | for (const { s: t = counter(), u: v = counter(), w: x = counter(), y: z = counter() } of [{ s: null, u: 0, w: false, y: '' }]) { |
| 55 | assert.sameValue(t, null); |
| 56 | assert.sameValue(v, 0); |
| 57 | assert.sameValue(x, false); |
| 58 | assert.sameValue(z, ''); |
| 59 | assert.sameValue(initCount, 0); |
| 60 | |
| 61 | assert.throws(ReferenceError, function() { |
| 62 | s; |
| 63 | }); |
| 64 | assert.throws(ReferenceError, function() { |
| 65 | u; |
| 66 | }); |
| 67 | assert.throws(ReferenceError, function() { |
| 68 | w; |
| 69 | }); |
| 70 | assert.throws(ReferenceError, function() { |
| 71 | y; |
| 72 | }); |
| 73 | |
| 74 | iterCount += 1; |
| 75 | } |
| 76 | |
| 77 | assert.sameValue(iterCount, 1, 'iteration occurred as expected'); |