From 00c00c33d145127ebf23e48c7c3ab84852894588 Mon Sep 17 00:00:00 2001 From: Lukas Kurz Date: Sun, 13 Oct 2024 19:17:05 +0200 Subject: [PATCH] Add test for indirect eval --- test/es12/optional-calls.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/test/es12/optional-calls.js b/test/es12/optional-calls.js index 28eec0414db..f5f51340126 100644 --- a/test/es12/optional-calls.js +++ b/test/es12/optional-calls.js @@ -112,7 +112,7 @@ const tests = [ }, { name: "Optional call of root function", - body(){ + body() { assert.areEqual(42, eval?.("42")); globalThis.doNotUseThisBadGlobalFunction = () => 42; @@ -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"); + } } ];