1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-10 09:27:35 +00:00

LibJS: Don't return the "last computed value" from Interpreter::run()

Only return whatever a "return" statment told us to return.
The last computed value is now available in Interpreter::last_value()
instead, where the REPL can pick it up.
This commit is contained in:
Andreas Kling 2020-04-04 23:45:13 +02:00
parent 97cd1173fa
commit 2db8716a6f
3 changed files with 17 additions and 7 deletions

View file

@ -302,8 +302,8 @@ JS::Value ReplObject::load_file(JS::Interpreter& interpreter)
auto program = JS::Parser(JS::Lexer(source)).parse_program();
if (dump_ast)
program->dump(0);
auto result = interpreter.run(*program);
print(result);
interpreter.run(*program);
print(interpreter.last_value());
}
return JS::Value(true);
}
@ -319,13 +319,13 @@ void repl(JS::Interpreter& interpreter)
if (dump_ast)
program->dump(0);
auto result = interpreter.run(*program);
interpreter.run(*program);
if (interpreter.exception()) {
printf("Uncaught exception: ");
print(interpreter.exception()->value());
interpreter.clear_exception();
} else {
print(result);
print(interpreter.last_value());
}
}
}