Skip to content

Commit 00c00c3

Browse files
Add test for indirect eval
1 parent 4160295 commit 00c00c3

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

test/es12/optional-calls.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ const tests = [
112112
},
113113
{
114114
name: "Optional call of root function",
115-
body(){
115+
body() {
116116
assert.areEqual(42, eval?.("42"));
117117

118118
globalThis.doNotUseThisBadGlobalFunction = () => 42;
@@ -166,6 +166,15 @@ const tests = [
166166
fn?.()
167167
`));
168168
},
169+
},
170+
{
171+
name: "Optional call to eval should be indirect eval",
172+
body() {
173+
const x = 2;
174+
const y = 4;
175+
assert.areEqual(6, eval("x + y"));
176+
assert.throws(() => eval?.("x + y"), ReferenceError, "Should not have access to local scope", "'x' is not defined");
177+
}
169178
}
170179
];
171180

0 commit comments

Comments
 (0)