1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 03:47:35 +00:00

LibJS: Fallback to undefined if last value in eval() is empty

For something like eval(""), the VM's 'last value' is an empty value,
which we must not leak.

Fixes #6643.
This commit is contained in:
Linus Groh 2021-04-25 22:52:19 +02:00
parent 2b4c2301a9
commit 7b1ba4bd5c
2 changed files with 2 additions and 1 deletions

View file

@ -323,7 +323,7 @@ JS_DEFINE_NATIVE_FUNCTION(GlobalObject::eval)
vm.interpreter().execute_statement(global_object, program);
if (vm.exception())
return {};
return vm.last_value();
return vm.last_value().value_or(js_undefined());
}
// 19.2.6.1.1 Encode ( string, unescapedSet )

View file

@ -11,6 +11,7 @@ test("basic eval() functionality", () => {
test("returns value of last value-producing statement", () => {
// See https://tc39.es/ecma262/#sec-block-runtime-semantics-evaluation
expect(eval("")).toBeUndefined();
expect(eval("1;;;;;")).toBe(1);
expect(eval("1;{}")).toBe(1);
expect(eval("1;var a;")).toBe(1);