| 1 |
// Copyright (C) 2016 the V8 project authors. All rights reserved. |
| 2 |
// This code is governed by the BSD license found in the LICENSE file. |
| 3 |
/*--- |
| 4 |
esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation |
| 5 |
description: > |
| 6 |
Creation of new lexical environment for the initial evaluation of the |
| 7 |
statement body |
| 8 |
info: | |
| 9 |
IterationStatement : for ( ForDeclaration of AssignmentExpression ) Statement |
| 10 |
|
| 11 |
[...] |
| 12 |
2. Return ? ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, |
| 13 |
lexicalBinding, labelSet). |
| 14 |
|
| 15 |
13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation |
| 16 |
|
| 17 |
[...] |
| 18 |
5. Repeat |
| 19 |
[...] |
| 20 |
d. If lhsKind is either assignment or varBinding, then |
| 21 |
[...] |
| 22 |
e. Else, |
| 23 |
i. Assert: lhsKind is lexicalBinding. |
| 24 |
ii. Assert: lhs is a ForDeclaration. |
| 25 |
iii. Let iterationEnv be NewDeclarativeEnvironment(oldEnv). |
| 26 |
iv. Perform BindingInstantiation for lhs passing iterationEnv as the |
| 27 |
argument. |
| 28 |
v. Set the running execution context's LexicalEnvironment to |
| 29 |
iterationEnv. |
| 30 |
[...] |
| 31 |
features: [let] |
| 32 |
---*/ |
| 33 |
|
| 34 |
var probeBefore = function() { return x; }; |
| 35 |
let x = 'outside'; |
| 36 |
var probeExpr, probeDecl, probeBody; |
| 37 |
|
| 38 |
for ( |
| 39 |
let [x, _ = probeDecl = function() { return x; }] |
| 40 |
in |
| 41 |
{ i: probeExpr = function() { typeof x; }} |
| 42 |
) |
| 43 |
probeBody = function() { return x; }; |
| 44 |
|
| 45 |
assert.sameValue(probeBefore(), 'outside'); |
| 46 |
assert.throws(ReferenceError, probeExpr); |
| 47 |
assert.sameValue(probeDecl(), 'i', 'reference from ForDeclaration'); |
| 48 |
assert.sameValue(probeBody(), 'i', 'reference from statement body'); |
| 49 |
|
| 50 |
reportCompare(0, 0); |