Skip to content

Commit

Permalink
Add test for indirect eval
Browse files Browse the repository at this point in the history
  • Loading branch information
ShortDevelopment committed Oct 13, 2024
1 parent 4160295 commit 00c00c3
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion test/es12/optional-calls.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ const tests = [
},
{
name: "Optional call of root function",
body(){
body() {
assert.areEqual(42, eval?.("42"));

globalThis.doNotUseThisBadGlobalFunction = () => 42;
Expand Down Expand Up @@ -166,6 +166,15 @@ const tests = [
fn?.()
`));
},
},
{
name: "Optional call to eval should be indirect eval",
body() {
const x = 2;
const y = 4;
assert.areEqual(6, eval("x + y"));
assert.throws(() => eval?.("x + y"), ReferenceError, "Should not have access to local scope", "'x' is not defined");
}
}
];

Expand Down

0 comments on commit 00c00c3

Please sign in to comment.