scope-body-var-none.js (2853B)
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: > 6 No variable environment is created for each evaluation of the statement 7 body 8 info: | 9 [...] 10 11. Let bodyResult be ForBodyEvaluation(the first Expression, the second 11 Expression, Statement, perIterationLets, labelSet). 12 [...] 13 14 13.7.4.8 Runtime Semantics: ForBodyEvaluation 15 16 [...] 17 2. Perform ? CreatePerIterationEnvironment(perIterationBindings). 18 3. Repeat 19 [...] 20 b. Let result be the result of evaluating stmt. 21 [...] 22 e. Perform ? CreatePerIterationEnvironment(perIterationBindings). 23 [...] 24 25 13.7.4.9 Runtime Semantics: CreatePerIterationEnvironment 26 27 1. If perIterationBindings has any elements, then 28 [...] 29 e. Let thisIterationEnv be NewDeclarativeEnvironment(outer). 30 f. Let thisIterationEnvRec be thisIterationEnv's EnvironmentRecord. 31 flags: [noStrict] 32 ---*/ 33 34 var probeBefore = function() { return [x, y, z]; }; 35 var probeTest, probeIncr, probeBody; 36 var run = true; 37 38 for ( 39 ; 40 run && (eval('var x = 1;'), probeTest = function() { return [x, y, z]; }); 41 eval('var y = 1;'), probeIncr = function() { return [x, y, z]; } 42 ) 43 var z = 1, _ = (probeBody = function() { return [x, y, z]; }), run = false; 44 45 var x = 2; 46 var y = 2; 47 var z = 2; 48 49 assert.sameValue( 50 probeBefore()[0], 51 2, 52 'reference preceding statement (redeclared in "test" position)' 53 ); 54 assert.sameValue( 55 probeBefore()[1], 56 2, 57 'reference preceding statement (redeclared in statement body)' 58 ); 59 assert.sameValue( 60 probeBefore()[2], 61 2, 62 'reference preceding statement (redeclared in "increment" position)' 63 ); 64 65 assert.sameValue( 66 probeTest()[0], 67 2, 68 'reference from "test" position (redeclared in "test" position)' 69 ); 70 assert.sameValue( 71 probeTest()[1], 72 2, 73 'reference from "test" position (redeclared in statement body)' 74 ); 75 assert.sameValue( 76 probeTest()[2], 77 2, 78 'reference from "test" position (redeclared in "increment" position)' 79 ); 80 81 assert.sameValue( 82 probeBody()[0], 83 2, 84 'reference from statement body (redeclared in "test" position)' 85 ); 86 assert.sameValue( 87 probeBody()[1], 88 2, 89 'reference from statement body (redeclared in statement body)' 90 ); 91 assert.sameValue( 92 probeBody()[2], 93 2, 94 'reference from statement body (redeclared in "increment" position)' 95 ); 96 97 assert.sameValue( 98 probeIncr()[0], 99 2, 100 'reference from "increment" position (redeclared in "test" position)' 101 ); 102 assert.sameValue( 103 probeIncr()[1], 104 2, 105 'reference from "increment" position (redeclared in statement body)' 106 ); 107 assert.sameValue( 108 probeIncr()[2], 109 2, 110 'reference from "increment" position (redeclared in "increment" position)' 111 ); 112 113 reportCompare(0, 0);