scope-var-open.js (1456B)
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-prepareforordinarycall 5 description: > 6 Creation of new variable environment for the function parameters and body 7 (as distinct from that for the function's BindingIdentifier) 8 info: | 9 [...] 10 3. Let callerContext be the running execution context. 11 4. Let calleeContext be PrepareForOrdinaryCall(F, undefined). 12 [...] 13 14 9.2.1.1 PrepareForOrdinaryCall 15 16 [...] 17 8. Let localEnv be NewFunctionEnvironment(F, newTarget). 18 9. Set the LexicalEnvironment of calleeContext to localEnv. 19 10. Set the VariableEnvironment of calleeContext to localEnv. 20 [...] 21 ---*/ 22 23 var n = 'outside'; 24 var probeBefore = function() { return n; }; 25 var probeBody; 26 27 // This test intentionally elides parameter expressions because their presence 28 // triggers the creation of an additional LexicalEnvironment dedicated to the 29 // function body (see sec-functiondeclarationinstantiation) 30 var func = function n() { 31 // The initializer is intentionally omitted from the following 32 // VariableStatement in order to demonstrate that a new binding is created 33 // (and not simply re-used from the FunctionExpression's BindingIdentifier). 34 var n; 35 probeBody = function() { return n; }; 36 }; 37 38 func(); 39 40 assert.sameValue(probeBefore(), 'outside'); 41 assert.sameValue(probeBody(), undefined); 42 43 reportCompare(0, 0);