Bug 1892041 - Part 2: Update test262. r=spidermonkey-reviewers,dminor
[gecko.git] / js / src / tests / test262 / language / global-code / script-decl-lex-var-declared-via-eval.js
bloba92cca7b41a549b1abd49870e11f6e93d1d7db57
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:
9   PerformEval ( x, strictCaller, direct )
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.
17   In sloppy mode:
19   GlobalDeclarationInstantiation ( script, env )
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 ---*/
29 eval('var test262Var;');
30 eval('function test262Fn() {}');
32 $262.evalScript('let test262Var = 1;');
33 assert.sameValue(test262Var, 1);
35 $262.evalScript('const test262Fn = 2;');
36 assert.sameValue(test262Fn, 2);
38 reportCompare(0, 0);