1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-23 20:17:42 +00:00

LibJS: Make Interpreter::run() a void function

With one small exception, this is how we've been using this API already,
and it makes sense: a Program is just a ScopeNode with any number of
statements, which are executed one by one. There's no explicit return
value at the end, only a completion value of the last value-producing
statement, which we then access using VM::last_value() if needed (e.g.
in the REPL).
This commit is contained in:
Linus Groh 2021-03-16 09:09:56 +01:00 committed by Andreas Kling
parent ef3679f9c3
commit dadf2e8251
3 changed files with 8 additions and 8 deletions

View file

@ -54,7 +54,7 @@ Interpreter::~Interpreter()
{ {
} }
Value Interpreter::run(GlobalObject& global_object, const Program& program) void Interpreter::run(GlobalObject& global_object, const Program& program)
{ {
auto& vm = this->vm(); auto& vm = this->vm();
VERIFY(!vm.exception()); VERIFY(!vm.exception());
@ -71,9 +71,8 @@ Value Interpreter::run(GlobalObject& global_object, const Program& program)
global_call_frame.is_strict_mode = program.is_strict_mode(); global_call_frame.is_strict_mode = program.is_strict_mode();
vm.push_call_frame(global_call_frame, global_object); vm.push_call_frame(global_call_frame, global_object);
VERIFY(!vm.exception()); VERIFY(!vm.exception());
auto result = program.execute(*this, global_object); program.execute(*this, global_object);
vm.pop_call_frame(); vm.pop_call_frame();
return result;
} }
GlobalObject& Interpreter::global_object() GlobalObject& Interpreter::global_object()

View file

@ -61,7 +61,7 @@ public:
~Interpreter(); ~Interpreter();
Value run(GlobalObject&, const Program&); void run(GlobalObject&, const Program&);
GlobalObject& global_object(); GlobalObject& global_object();
const GlobalObject& global_object() const; const GlobalObject& global_object() const;

View file

@ -555,10 +555,11 @@ JS::Value Document::run_javascript(const StringView& source, const StringView& f
return JS::js_undefined(); return JS::js_undefined();
} }
auto& interpreter = document().interpreter(); auto& interpreter = document().interpreter();
auto result = interpreter.run(interpreter.global_object(), *program); auto& vm = interpreter.vm();
if (interpreter.exception()) interpreter.run(interpreter.global_object(), *program);
interpreter.vm().clear_exception(); if (vm.exception())
return result; vm.clear_exception();
return vm.last_value();
} }
// https://dom.spec.whatwg.org/#dom-document-createelement // https://dom.spec.whatwg.org/#dom-document-createelement