| 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 lexical environment (distinct from the variable |
| 7 |
environment) for the function body outside of strict mode |
| 8 |
info: | |
| 9 |
[...] |
| 10 |
29. If strict is false, then |
| 11 |
a. Let lexEnv be NewDeclarativeEnvironment(varEnv). |
| 12 |
b. NOTE: Non-strict functions use a separate lexical Environment Record |
| 13 |
for top-level lexical declarations so that a direct eval can |
| 14 |
determine whether any var scoped declarations introduced by the eval |
| 15 |
code conflict with pre-existing top-level lexically scoped |
| 16 |
declarations. This is not needed for strict functions because a |
| 17 |
strict direct eval always places all declarations into a new |
| 18 |
Environment Record. |
| 19 |
[...] |
| 20 |
|
| 21 |
18.2.1.3 Runtime Semantics: EvalDeclarationInstantiation |
| 22 |
|
| 23 |
[...] |
| 24 |
5. If strict is false, then |
| 25 |
[...] |
| 26 |
b. Let thisLex be lexEnv. |
| 27 |
c. Assert: The following loop will terminate. |
| 28 |
d. Repeat while thisLex is not the same as varEnv, |
| 29 |
i. Let thisEnvRec be thisLex's EnvironmentRecord. |
| 30 |
ii. If thisEnvRec is not an object Environment Record, then |
| 31 |
1. NOTE: The environment of with statements cannot contain any |
| 32 |
lexical declaration so it doesn't need to be checked for |
| 33 |
var/let hoisting conflicts. |
| 34 |
2. For each name in varNames, do |
| 35 |
a. If thisEnvRec.HasBinding(name) is true, then |
| 36 |
i. Throw a SyntaxError exception. |
| 37 |
ii. NOTE: Annex B.3.5 defines alternate semantics for the |
| 38 |
above step. |
| 39 |
b. NOTE: A direct eval will not hoist var declaration over a |
| 40 |
like-named lexical declaration. |
| 41 |
iii. Let thisLex be thisLex's outer environment reference. |
| 42 |
flags: [noStrict] |
| 43 |
features: [let] |
| 44 |
---*/ |
| 45 |
|
| 46 |
var a = () => { let x; eval('var x;'); }; |
| 47 |
|
| 48 |
assert.throws(SyntaxError, a); |