Debian Codegraph @

tests/auto/qml/ecmascripttests/test262/test/language/expressions/generators/scope-body-lex-distinct.js

raw
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: [generators, let]
44 ---*/
45
46 var g = function*() {
47 let x;
48 eval('var x;');
49 };
50 var iter = g();
51
52 assert.throws(SyntaxError, function() {
53 iter.next();
54 });