From 431776ebb7b3ef95f8b86614966eb0c54113e6d8 Mon Sep 17 00:00:00 2001 From: Ali Mohammad Pur Date: Sat, 2 Apr 2022 11:53:13 +0430 Subject: [PATCH] js: Print the accumulator instead of the returned value in BC mode The REPL is supposed to show the last value (and not the _returned_ value), so use the accumulator register as the 'value'. --- Userland/Utilities/js.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Userland/Utilities/js.cpp b/Userland/Utilities/js.cpp index 56f0a306aa..bb15a89691 100644 --- a/Userland/Utilities/js.cpp +++ b/Userland/Utilities/js.cpp @@ -1051,7 +1051,11 @@ static bool parse_and_run(JS::Interpreter& interpreter, StringView source, Strin if (s_run_bytecode) { JS::Bytecode::Interpreter bytecode_interpreter(interpreter.global_object(), interpreter.realm()); - result = bytecode_interpreter.run(*executable); + auto result_or_error = bytecode_interpreter.run_and_return_frame(*executable, nullptr); + if (result_or_error.value.is_error()) + result = result_or_error.value.release_error(); + else + result = result_or_error.frame->registers[0]; } else { return ReturnEarly::Yes; }