1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 06:37:43 +00:00

LibJS: Correct behaviour of direct vs. indirect eval

eval only has direct access to the local scope when accessed through
the name eval. This includes locals named eval, because of course it
does.
This commit is contained in:
Anonymous 2021-06-19 20:13:53 -07:00 committed by Linus Groh
parent 5d24b5f4be
commit 2822da8c8f
10 changed files with 121 additions and 20 deletions

View file

@ -0,0 +1,15 @@
test("variable named 'eval' pointing to another function calls that function", function () {
var testValue = "inner";
// This breaks prettier as it considers this to be a parse error
// before even trying to do any linting
var eval = () => {
return "wat";
};
expect(eval("testValue")).toEqual("wat");
});
test("variable named 'eval' pointing to real eval works as a direct eval", function () {
var testValue = "inner";
var eval = globalThis.eval;
expect(eval("testValue")).toEqual("inner");
});