scope-meth-paramsbody-var-close.js (1165B)
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-functiondeclarationinstantiation 5 description: > 6 Disposal of variable environment for the function body 7 info: | 8 [...] 9 26. If hasParameterExpressions is false, then 10 [...] 11 27. Else, 12 a. NOTE A separate Environment Record is needed to ensure that closures 13 created by expressions in the formal parameter list do not have 14 visibility of declarations in the function body. 15 b. Let varEnv be NewDeclarativeEnvironment(env). 16 c. Let varEnvRec be varEnv's EnvironmentRecord. 17 d. Set the VariableEnvironment of calleeContext to varEnv. 18 e. Let instantiatedVarNames be a new empty List. 19 [...] 20 ---*/ 21 22 var probe; 23 24 var C = class { 25 // A parameter expression is necessary to trigger the creation of the scope 26 // under test. 27 m(_ = null) { 28 var x = 'inside'; 29 probe = function() { return x; }; 30 } 31 }; 32 C.prototype.m(); 33 34 var x = 'outside'; 35 36 assert.sameValue(probe(), 'inside'); 37 assert.sameValue(x, 'outside'); 38 39 reportCompare(0, 0);