LibJS: Make eval() return the last value from the executed statement

This is kinda awkward but since the statement we're executing is
actually a JS::Program, we have to get the result via VM::last_value().
This commit is contained in:
Andreas Kling 2021-03-15 21:42:44 +01:00
commit 45e6b5e601
Notes: sideshowbarker 2024-07-18 21:19:24 +09:00
2 changed files with 14 additions and 2 deletions

View file

@ -0,0 +1,10 @@
test("basic eval() functionality", () => {
expect(eval("1 + 2")).toBe(3);
function foo(a) {
var x = 5;
eval("x += a");
return x;
}
expect(foo(7)).toBe(12);
});