1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 09:38:11 +00:00

LibJS/Bytecode: Simplify Bytecode::Interpreter lifetime model

The JS::VM now owns the one Bytecode::Interpreter. We no longer have
multiple bytecode interpreters, and there is no concept of a "current"
bytecode interpreter.

If you ask for VM::bytecode_interpreter_if_exists(), it will return null
if we're not running the program in "bytecode enabled" mode.

If you ask for VM::bytecode_interpreter(), it will return a bytecode
interpreter in all modes. This is used for situations where even the AST
interpreter switches to bytecode mode (generators, etc.)
This commit is contained in:
Andreas Kling 2023-06-22 15:59:18 +02:00
parent 6150960671
commit 6537ed8fff
15 changed files with 117 additions and 106 deletions

View file

@ -104,18 +104,7 @@ ThrowCompletionOr<Value> GeneratorObject::execute(VM& vm, Completion const& comp
completion_object->define_direct_property(vm.names.type, Value(to_underlying(completion.type())), default_attributes);
completion_object->define_direct_property(vm.names.value, completion.value().value(), default_attributes);
auto* bytecode_interpreter = Bytecode::Interpreter::current();
// If we're coming from a context which has no bytecode interpreter, e.g. from AST mode calling Generate.prototype.next,
// we need to make one to be able to continue, as generators are only supported in bytecode mode.
// See also ECMAScriptFunctionObject::ordinary_call_evaluate_body where this is done as well.
OwnPtr<Bytecode::Interpreter> temp_bc_interpreter;
if (!bytecode_interpreter) {
temp_bc_interpreter = make<Bytecode::Interpreter>(realm);
bytecode_interpreter = temp_bc_interpreter.ptr();
}
VERIFY(bytecode_interpreter);
auto& bytecode_interpreter = vm.bytecode_interpreter();
auto const* next_block = generated_continuation(m_previous_value);
@ -131,9 +120,9 @@ ThrowCompletionOr<Value> GeneratorObject::execute(VM& vm, Completion const& comp
if (frame)
frame->registers[0] = completion_object;
else
bytecode_interpreter->accumulator() = completion_object;
bytecode_interpreter.accumulator() = completion_object;
auto next_result = bytecode_interpreter->run_and_return_frame(*m_generating_function->bytecode_executable(), next_block, frame);
auto next_result = bytecode_interpreter.run_and_return_frame(realm, *m_generating_function->bytecode_executable(), next_block, frame);
vm.pop_execution_context();