script-decl-lex-no-collision.js (1185B)
1 // Copyright (C) 2023 Alexey Shvayka. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 /*--- 4 esid: sec-globaldeclarationinstantiation 5 description: No let binding collision with existing var declaration due to eval(). 6 info: | 7 In strict mode: 8 9 PerformEval ( x, strictCaller, direct ) 10 11 [...] 12 16. If direct is true, then 13 a. Let lexEnv be NewDeclarativeEnvironment(runningContext's LexicalEnvironment). 14 [...] 15 18. If strictEval is true, set varEnv to lexEnv. 16 17 In sloppy mode: 18 19 GlobalDeclarationInstantiation ( script, env ) 20 21 [...] 22 3. For each element name of lexNames, do 23 a. If env.HasLexicalDeclaration(name) is true, throw a SyntaxError exception. 24 b. Let hasRestrictedGlobal be ? env.HasRestrictedGlobalProperty(name). 25 c. NOTE: Global var and function bindings (except those that are introduced by non-strict direct eval) are non-configurable and are therefore restricted global properties. 26 d. If hasRestrictedGlobal is true, throw a SyntaxError exception. 27 ---*/ 28 29 eval('if (true) { function test262Fn() {} }'); 30 31 $262.evalScript('let test262Fn = 1;'); 32 33 assert.sameValue(test262Fn, 1); 34 35 reportCompare(0, 0);