diff options
author | Andreas Kling <kling@serenityos.org> | 2021-01-29 09:16:06 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-01-29 09:16:06 +0100 |
commit | a061bd2ab961d7e5f9cf44e553fa634f71a66394 (patch) | |
tree | 5bbebfe46bd6f17b531435f472db92ea861c0bf0 /Userland/Utilities | |
parent | c33d50872ead19259c1dafc461534d7b67a01aaf (diff) | |
download | serenity-a061bd2ab961d7e5f9cf44e553fa634f71a66394.zip |
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
Diffstat (limited to 'Userland/Utilities')
-rw-r--r-- | Userland/Utilities/js.cpp | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/Userland/Utilities/js.cpp b/Userland/Utilities/js.cpp index a7538d5107..d7b48407fd 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; } |