keith_miller@apple.com | bcc77f2 | 2016-07-15 06:03:25 +0000 | [diff] [blame] | 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 | Creation of new variable environment for the function body (as disinct from |
| 7 | that for the function's parameters) |
| 8 | info: | |
| 9 | [...] |
| 10 | 26. If hasParameterExpressions is false, then |
| 11 | [...] |
| 12 | 27. Else, |
| 13 | a. NOTE A separate Environment Record is needed to ensure that closures |
| 14 | created by expressions in the formal parameter list do not have |
| 15 | visibility of declarations in the function body. |
| 16 | b. Let varEnv be NewDeclarativeEnvironment(env). |
| 17 | c. Let varEnvRec be varEnv's EnvironmentRecord. |
| 18 | d. Set the VariableEnvironment of calleeContext to varEnv. |
| 19 | e. Let instantiatedVarNames be a new empty List. |
| 20 | [...] |
| 21 | ---*/ |
| 22 | |
| 23 | var x = 'outside'; |
| 24 | var probeParams, probeBody; |
| 25 | |
| 26 | class C { |
| 27 | m(_ = probeParams = function() { return x; }) { |
| 28 | var x = 'inside'; |
| 29 | probeBody = function() { return x; }; |
| 30 | } |
| 31 | } |
| 32 | C.prototype.m(); |
| 33 | |
| 34 | assert.sameValue(probeParams(), 'outside'); |
| 35 | assert.sameValue(probeBody(), 'inside'); |