| 1 |
'use strict'; |
| 2 |
// Copyright (C) 2016 the V8 project authors. All rights reserved. |
| 3 |
// This code is governed by the BSD license found in the LICENSE file. |
| 4 |
/*--- |
| 5 |
esid: sec-function-definitions-runtime-semantics-evaluation |
| 6 |
description: > |
| 7 |
Creation of new variable environment for the BindingIdentifier |
| 8 |
parameter |
| 9 |
info: | |
| 10 |
[...] |
| 11 |
2. Let scope be the running execution context's LexicalEnvironment. |
| 12 |
3. Let funcEnv be NewDeclarativeEnvironment(scope). |
| 13 |
4. Let envRec be funcEnv's EnvironmentRecord. |
| 14 |
5. Let name be StringValue of BindingIdentifier. |
| 15 |
6. Perform envRec.CreateImmutableBinding(name, false). |
| 16 |
7. Let closure be FunctionCreate(Normal, FormalParameters, FunctionBody, |
| 17 |
funcEnv, strict). |
| 18 |
[...] |
| 19 |
flags: [onlyStrict] |
| 20 |
---*/ |
| 21 |
|
| 22 |
var f = 'outside'; |
| 23 |
var probeBefore = function() { return f; }; |
| 24 |
var setBefore = function() { f = null; }; |
| 25 |
var probeParams, setParams, probeBody, setBody; |
| 26 |
|
| 27 |
var func = function f( |
| 28 |
_ = ( |
| 29 |
probeParams = function() { return f; }, |
| 30 |
setParams = function() { f = null; } |
| 31 |
) |
| 32 |
) { |
| 33 |
probeBody = function() { return f; }; |
| 34 |
setBody = function() { f = null; }; |
| 35 |
}; |
| 36 |
|
| 37 |
func(); |
| 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 |
assert.throws( |
| 45 |
TypeError, setParams, 'inner binding rejects modification (from parameters)' |
| 46 |
); |
| 47 |
assert.sameValue( |
| 48 |
probeParams(), func, 'inner binding is immutable (from parameters)' |
| 49 |
); |
| 50 |
|
| 51 |
assert.sameValue(probeBody(), func, 'inner binding value (from body)'); |
| 52 |
assert.throws( |
| 53 |
TypeError, setBody, 'inner binding rejects modification (from body)' |
| 54 |
); |
| 55 |
assert.sameValue(probeBody(), func, 'inner binding is immutable (from body)'); |
| 56 |
|
| 57 |
reportCompare(0, 0); |