tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

script-decl-lex-var-declared-via-eval.js (1271B)


      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('var test262Var;');
     30 eval('function test262Fn() {}');
     31 
     32 $262.evalScript('let test262Var = 1;');
     33 assert.sameValue(test262Var, 1);
     34 
     35 $262.evalScript('const test262Fn = 2;');
     36 assert.sameValue(test262Fn, 2);
     37 
     38 reportCompare(0, 0);