mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-08 18:46:03 +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:
parent
2b4c2301a9
commit
7b1ba4bd5c
Notes:
sideshowbarker
2024-07-18 19:05:16 +09:00
Author: https://github.com/linusg
Commit: 7b1ba4bd5c
2 changed files with 2 additions and 1 deletions
|
@ -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 )
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue