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
This commit is contained in:
Andreas Kling 2021-01-29 09:16:06 +01:00
parent c33d50872e
commit a061bd2ab9
Notes: sideshowbarker 2024-07-18 22:46:39 +09:00

View file

@ -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;
}