mirror of
https://github.com/tc39/test262.git
synced 2025-07-23 14:04:51 +02:00
Test that HasVarDeclaration
accounts for bindings created via eval()
(#3914)
Co-authored-by: Alexey Shvayka <ashvayka@apple.com>
This commit is contained in:
parent
6789b50cce
commit
be53234590
@ -0,0 +1,21 @@
|
|||||||
|
// Copyright (C) 2023 Alexey Shvayka. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-globaldeclarationinstantiation
|
||||||
|
description: Let binding collision with existing var declaration that was created for hoisted function.
|
||||||
|
info: |
|
||||||
|
[...]
|
||||||
|
3. For each element name of lexNames, do
|
||||||
|
a. If env.HasVarDeclaration(name) is true, throw a SyntaxError exception.
|
||||||
|
flags: [noStrict]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
eval('if (true) { function test262Fn() {} }');
|
||||||
|
|
||||||
|
assert.throws(SyntaxError, function() {
|
||||||
|
$262.evalScript('var x; let test262Fn;');
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(ReferenceError, function() {
|
||||||
|
x;
|
||||||
|
}, 'no bindings created');
|
@ -0,0 +1,21 @@
|
|||||||
|
// Copyright (C) 2023 Alexey Shvayka. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-globaldeclarationinstantiation
|
||||||
|
description: No let binding collision with existing var declaration due to strict-mode eval().
|
||||||
|
info: |
|
||||||
|
PerformEval ( x, strictCaller, direct )
|
||||||
|
|
||||||
|
[...]
|
||||||
|
16. If direct is true, then
|
||||||
|
a. Let lexEnv be NewDeclarativeEnvironment(runningContext's LexicalEnvironment).
|
||||||
|
[...]
|
||||||
|
18. If strictEval is true, set varEnv to lexEnv.
|
||||||
|
flags: [onlyStrict]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
eval('if (true) { function test262Fn() {} }');
|
||||||
|
|
||||||
|
$262.evalScript('let test262Fn = 1;');
|
||||||
|
|
||||||
|
assert.sameValue(test262Fn, 1);
|
@ -0,0 +1,23 @@
|
|||||||
|
// Copyright (C) 2023 Alexey Shvayka. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-globaldeclarationinstantiation
|
||||||
|
description: Let binding collision with existing var declaration that was created for hoisted function.
|
||||||
|
info: |
|
||||||
|
[...]
|
||||||
|
3. For each element name of lexNames, do
|
||||||
|
a. If env.HasVarDeclaration(name) is true, throw a SyntaxError exception.
|
||||||
|
flags: [noStrict]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
if (true) {
|
||||||
|
function test262Fn() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.throws(SyntaxError, function() {
|
||||||
|
$262.evalScript('var x; let test262Fn;');
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(ReferenceError, function() {
|
||||||
|
x;
|
||||||
|
}, 'no bindings created');
|
@ -0,0 +1,30 @@
|
|||||||
|
// Copyright (C) 2023 Alexey Shvayka. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-globaldeclarationinstantiation
|
||||||
|
description: Let binding collision with existing var declaration that was created via eval().
|
||||||
|
info: |
|
||||||
|
[...]
|
||||||
|
3. For each element name of lexNames, do
|
||||||
|
a. If env.HasVarDeclaration(name) is true, throw a SyntaxError exception.
|
||||||
|
flags: [noStrict]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
eval('var test262Var;');
|
||||||
|
eval('function test262Fn() {}');
|
||||||
|
|
||||||
|
assert.throws(SyntaxError, function() {
|
||||||
|
$262.evalScript('var x; let test262Var;');
|
||||||
|
}, 'variable');
|
||||||
|
|
||||||
|
assert.throws(ReferenceError, function() {
|
||||||
|
x;
|
||||||
|
}, 'no bindings created (script shadowing variable)');
|
||||||
|
|
||||||
|
assert.throws(SyntaxError, function() {
|
||||||
|
$262.evalScript('var x; let test262Fn;');
|
||||||
|
}, 'function');
|
||||||
|
|
||||||
|
assert.throws(ReferenceError, function() {
|
||||||
|
x;
|
||||||
|
}, 'no bindings created (script shadowing function)');
|
@ -0,0 +1,24 @@
|
|||||||
|
// Copyright (C) 2023 Alexey Shvayka. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-globaldeclarationinstantiation
|
||||||
|
description: No let binding collision with existing var declaration due to strict-mode eval().
|
||||||
|
info: |
|
||||||
|
PerformEval ( x, strictCaller, direct )
|
||||||
|
|
||||||
|
[...]
|
||||||
|
16. If direct is true, then
|
||||||
|
a. Let lexEnv be NewDeclarativeEnvironment(runningContext's LexicalEnvironment).
|
||||||
|
[...]
|
||||||
|
18. If strictEval is true, set varEnv to lexEnv.
|
||||||
|
flags: [onlyStrict]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
eval('var test262Var;');
|
||||||
|
eval('function test262Fn() {}');
|
||||||
|
|
||||||
|
$262.evalScript('let test262Var = 1;');
|
||||||
|
assert.sameValue(test262Var, 1);
|
||||||
|
|
||||||
|
$262.evalScript('const test262Fn = 2;');
|
||||||
|
assert.sameValue(test262Fn, 2);
|
Loading…
x
Reference in New Issue
Block a user