| 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 |
features: [generators] |
| 22 |
---*/ |
| 23 |
|
| 24 |
var x = 'outside'; |
| 25 |
var probeParams, probeBody; |
| 26 |
|
| 27 |
({ |
| 28 |
*m(_ = probeParams = function() { return x; }) { |
| 29 |
var x = 'inside'; |
| 30 |
probeBody = function() { return x; }; |
| 31 |
} |
| 32 |
}.m().next()); |
| 33 |
|
| 34 |
assert.sameValue(probeParams(), 'outside'); |
| 35 |
assert.sameValue(probeBody(), 'inside'); |