summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordavidot <davidot@serenityos.org>2021-11-17 13:00:38 +0100
committerLinus Groh <mail@linusgroh.de>2021-11-17 13:12:05 +0000
commit22e679d8444a2a24ab9d4f48965e72e14e7c16b5 (patch)
tree13f5234524273d6a320161d5022e150e93d04ab7
parent3666d2132b49dfb090243356cbfc2fdf722dd87c (diff)
downloadserenity-22e679d8444a2a24ab9d4f48965e72e14e7c16b5.zip
LibJS + js: Rethrow exception on the vm after bytecode interpreter run
When the bytecode interpreter was converted to ThrowCompletionOr<Value> it then also cleared the vm.exception() making it seem like no exception was thrown. Also removed the TRY_OR_DISCARD as that would skip the error handling parts.
-rw-r--r--Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp6
-rw-r--r--Userland/Utilities/js.cpp5
2 files changed, 9 insertions, 2 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp b/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp
index 94e1a6a6c2..2a638dc0bf 100644
--- a/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp
+++ b/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp
@@ -769,7 +769,11 @@ Completion ECMAScriptFunctionObject::ordinary_call_evaluate_body()
return throw_completion(exception->value());
VERIFY(result_and_frame.frame != nullptr);
- auto result = TRY(result_and_frame.value);
+ if (result_and_frame.value.is_error()) {
+ vm.throw_exception(bytecode_interpreter->global_object(), result_and_frame.value.release_error().value());
+ return throw_completion(vm.exception()->value());
+ }
+ auto result = result_and_frame.value.release_value();
// NOTE: Running the bytecode should eventually return a completion.
// Until it does, we assume "return" and include the undefined fallback from the call site.
diff --git a/Userland/Utilities/js.cpp b/Userland/Utilities/js.cpp
index b8ff9b9881..29d57f2cfd 100644
--- a/Userland/Utilities/js.cpp
+++ b/Userland/Utilities/js.cpp
@@ -837,7 +837,10 @@ 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());
- TRY_OR_DISCARD(bytecode_interpreter.run(executable));
+ auto result = bytecode_interpreter.run(executable);
+ // Since all the error handling code uses vm.exception() we just rethrow any exception we got here.
+ if (result.is_error())
+ vm->throw_exception(interpreter.global_object(), result.throw_completion().value());
} else {
return true;
}