| 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-generator-function-definitions-runtime-semantics-evaluation |
| 5 |
description: > |
| 6 |
Creation of new variable environment for the BindingIdentifier |
| 7 |
parameter |
| 8 |
info: | |
| 9 |
[...] |
| 10 |
2. Let scope be the running execution context's LexicalEnvironment. |
| 11 |
3. Let funcEnv be NewDeclarativeEnvironment(scope). |
| 12 |
4. Let envRec be funcEnv's EnvironmentRecord. |
| 13 |
5. Let name be StringValue of BindingIdentifier. |
| 14 |
6. Perform envRec.CreateImmutableBinding(name, false). |
| 15 |
7. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, |
| 16 |
GeneratorBody, funcEnv, strict). |
| 17 |
[...] |
| 18 |
flags: [noStrict] |
| 19 |
features: [generators] |
| 20 |
---*/ |
| 21 |
|
| 22 |
var g = 'outside'; |
| 23 |
var probeBefore = function() { return g; }; |
| 24 |
var setBefore = function() { g = null; }; |
| 25 |
var probeParams, setParams, probeBody, setBody; |
| 26 |
|
| 27 |
var func = function* g( |
| 28 |
_ = ( |
| 29 |
probeParams = function() { return g; }, |
| 30 |
setParams = function() { g = null; } |
| 31 |
) |
| 32 |
) { |
| 33 |
probeBody = function() { return g; }; |
| 34 |
setBody = function() { g = null; }; |
| 35 |
}; |
| 36 |
|
| 37 |
func().next(); |
| 38 |
|
| 39 |
assert.sameValue(probeBefore(), 'outside'); |
| 40 |
setBefore(); |
| 41 |
assert.sameValue(probeBefore(), null); |
| 42 |
|
| 43 |
assert.sameValue(probeParams(), func, 'inner binding value (from parameters)'); |
| 44 |
setParams(); |
| 45 |
assert.sameValue( |
| 46 |
probeParams(), func, 'inner binding is immutable (from parameters)' |
| 47 |
); |
| 48 |
|
| 49 |
assert.sameValue(probeBody(), func, 'inner binding value (from body)'); |
| 50 |
setBody(); |
| 51 |
assert.sameValue(probeBody(), func, 'inner binding is immutable (from body)'); |