1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 18:47:34 +00:00

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().
This commit is contained in:
Linus Groh 2022-01-08 21:28:27 +01:00
parent f73afbb5ae
commit eb60d16549
13 changed files with 62 additions and 56 deletions

View file

@ -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()