scope-head-lex-close.js (1549B)
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-statement-runtime-semantics-labelledevaluation 5 description: Removal of lexical environment for the statement "head" 6 info: | 7 [...] 8 2. Let loopEnv be NewDeclarativeEnvironment(oldEnv). 9 3. Let loopEnvRec be loopEnv's EnvironmentRecord. 10 4. Let isConst be the result of performing IsConstantDeclaration of 11 LexicalDeclaration. 12 5. Let boundNames be the BoundNames of LexicalDeclaration. 13 6. For each element dn of boundNames do 14 a. If isConst is true, then 15 i. Perform ! loopEnvRec.CreateImmutableBinding(dn, true). 16 b. Else, 17 i. Perform ! loopEnvRec.CreateMutableBinding(dn, false). 18 7. Set the running execution context's LexicalEnvironment to loopEnv. 19 [...] 20 12. Set the running execution context's LexicalEnvironment to oldEnv. 21 13. Return Completion(bodyResult). 22 features: [let] 23 ---*/ 24 25 let x = 'outside'; 26 var run = true; 27 var probeTest, probeIncr, probeBody; 28 29 for ( 30 let x = 'inside'; 31 (probeTest = function() { return x; }) && run; 32 probeIncr = function() { return x; } 33 ) 34 probeBody = function() { return x; }, run = false; 35 36 assert.sameValue(probeBody(), 'inside', 'reference from statement body'); 37 assert.sameValue(probeIncr(), 'inside', 'reference from "increment" position'); 38 assert.sameValue(probeTest(), 'inside', 'reference from "test" position'); 39 assert.sameValue(x, 'outside'); 40 41 reportCompare(0, 0);