From a061bd2ab961d7e5f9cf44e553fa634f71a66394 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 29 Jan 2021 09:16:06 +0100 Subject: [PATCH] js: Handle exceptions thrown during value printing If an exception was thrown while printing the last computed value in the REPL, it would always assert on next input. Something like this would always assert: > a=[];Object.defineProperty(a,"0",{get:()=>{throw ""}}) > 1 + 2 --- Userland/Utilities/js.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Userland/Utilities/js.cpp b/Userland/Utilities/js.cpp index a7538d51070..d7b48407fd0 100644 --- a/Userland/Utilities/js.cpp +++ b/Userland/Utilities/js.cpp @@ -467,7 +467,7 @@ static bool parse_and_run(JS::Interpreter& interpreter, const StringView& source interpreter.run(interpreter.global_object(), *program); } - if (vm->exception()) { + auto handle_exception = [&] { out("Uncaught exception: "); print(vm->exception()->value()); auto trace = vm->exception()->trace(); @@ -493,10 +493,15 @@ static bool parse_and_run(JS::Interpreter& interpreter, const StringView& source } } vm->clear_exception(); - return false; - } - if (s_print_last_result) + }; + if (vm->exception()) + handle_exception(); + + if (s_print_last_result) { print(vm->last_value()); + if (vm->exception()) + handle_exception(); + } return true; }