summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Interpreter.cpp
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2022-01-08 21:28:27 +0100
committerLinus Groh <mail@linusgroh.de>2022-01-08 23:43:03 +0100
commiteb60d16549eb9415cdbd729afb1f318e8f010dbd (patch)
treea2cbf9f97cc5b825b0b633b7a6d1d9e9fd7d637a /Userland/Libraries/LibJS/Interpreter.cpp
parentf73afbb5ae533706d2445799473de72e7ecfd224 (diff)
downloadserenity-eb60d16549eb9415cdbd729afb1f318e8f010dbd.zip
LibJS: Convert Interpreter::run() to ThrowCompletionOr<Value>
Instead of making it a void function, checking for an exception, and then receiving the relevant result via VM::last_value(), we can consolidate all of this by using completions. This allows us to remove more uses of VM::exception(), and all uses of VM::last_value().
Diffstat (limited to 'Userland/Libraries/LibJS/Interpreter.cpp')
-rw-r--r--Userland/Libraries/LibJS/Interpreter.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/Userland/Libraries/LibJS/Interpreter.cpp b/Userland/Libraries/LibJS/Interpreter.cpp
index eb1cc9df18..bcd17733b2 100644
--- a/Userland/Libraries/LibJS/Interpreter.cpp
+++ b/Userland/Libraries/LibJS/Interpreter.cpp
@@ -38,7 +38,7 @@ Interpreter::~Interpreter()
{
}
-void Interpreter::run(GlobalObject& global_object, const Program& program)
+ThrowCompletionOr<Value> Interpreter::run(GlobalObject& global_object, const Program& program)
{
// FIXME: Why does this receive a GlobalObject? Interpreter has one already, and this might not be in sync with the Realm's GlobalObject.
@@ -71,6 +71,12 @@ void Interpreter::run(GlobalObject& global_object, const Program& program)
vm.pop_execution_context();
vm.finish_execution_generation();
+
+ if (completion.is_abrupt()) {
+ VERIFY(completion.type() == Completion::Type::Throw);
+ return completion.release_error();
+ }
+ return completion.value().value_or(js_undefined());
}
GlobalObject& Interpreter::global_object()