Debian Codegraph @

js/src/tests/test262/language/statements/for-of/scope-body-var-none.js

raw
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: No variable environment is created for the statement body
6 info: |
7 IterationStatement : for ( ForDeclaration of AssignmentExpression ) Statement
8
9 [...]
10 2. Return ? ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult,
11 lexicalBinding, labelSet).
12
13 13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation
14
15 [...]
16 5. Repeat
17 [...]
18 d. If lhsKind is either assignment or varBinding, then
19 [...]
20 e. Else,
21 i. Assert: lhsKind is lexicalBinding.
22 ii. Assert: lhs is a ForDeclaration.
23 iii. Let iterationEnv be NewDeclarativeEnvironment(oldEnv).
24 iv. Perform BindingInstantiation for lhs passing iterationEnv as the
25 argument.
26 v. Set the running execution context's LexicalEnvironment to
27 iterationEnv.
28 [...]
29 features: [let]
30 ---*/
31
32 var probeBefore = function() { return x; };
33 var probeExpr, probeDecl, probeBody;
34 var x = 1;
35
36 for (
37 let [_, __ = probeDecl = function() { return x; }]
38 of
39 [[probeExpr = function() { return x; }]]
40 )
41 var x = 2, ___ = probeBody = function() { return x; };
42
43
44 assert.sameValue(probeBefore(), 2, 'reference preceding statement');
45 assert.sameValue(probeExpr(), 2, 'reference from AssignmentExpression');
46 assert.sameValue(probeDecl(), 2, 'reference from ForDelaration');
47 assert.sameValue(probeBody(), 2, 'reference from statement body');
48 assert.sameValue(x, 2, 'reference following statement');
49
50 reportCompare(0, 0);