diff --git a/Libraries/LibJS/Runtime/VM.cpp b/Libraries/LibJS/Runtime/VM.cpp index b1739c03c3..0340e60dd4 100644 --- a/Libraries/LibJS/Runtime/VM.cpp +++ b/Libraries/LibJS/Runtime/VM.cpp @@ -37,12 +37,12 @@ namespace JS { -NonnullRefPtr VM::create(OwnPtr agent) +NonnullRefPtr VM::create() { ErrorMessages error_messages {}; error_messages[to_underlying(ErrorMessage::OutOfMemory)] = ErrorType::OutOfMemory.message(); - auto vm = adopt_ref(*new VM(move(agent), move(error_messages))); + auto vm = adopt_ref(*new VM(move(error_messages))); WellKnownSymbols well_known_symbols { #define __JS_ENUMERATE(SymbolName, snake_name) \ @@ -63,12 +63,11 @@ static constexpr auto make_single_ascii_character_strings(IndexSequence()); -VM::VM(OwnPtr agent, ErrorMessages error_messages) +VM::VM(ErrorMessages error_messages) : m_heap(this, [this](HashMap& roots) { gather_roots(roots); }) , m_error_messages(move(error_messages)) - , m_agent(move(agent)) { m_bytecode_interpreter = make(*this); diff --git a/Libraries/LibJS/Runtime/VM.h b/Libraries/LibJS/Runtime/VM.h index adc87b3793..e2666dd649 100644 --- a/Libraries/LibJS/Runtime/VM.h +++ b/Libraries/LibJS/Runtime/VM.h @@ -47,7 +47,7 @@ enum class EvalMode { class VM : public RefCounted { public: - static NonnullRefPtr create(OwnPtr = {}); + static NonnullRefPtr create(); ~VM(); GC::Heap& heap() { return m_heap; } @@ -240,6 +240,7 @@ public: Function on_promise_rejection_handled; Function on_unimplemented_property_access; + void set_agent(OwnPtr agent) { m_agent = move(agent); } Agent* agent() { return m_agent; } Agent const* agent() const { return m_agent; } @@ -290,7 +291,7 @@ private: #undef __JS_ENUMERATE }; - VM(OwnPtr, ErrorMessages); + explicit VM(ErrorMessages); void load_imported_module(ImportedModuleReferrer, ModuleRequest const&, GC::Ptr, ImportedModulePayload); ThrowCompletionOr link_and_eval_module(CyclicModule&); diff --git a/Libraries/LibWeb/Bindings/MainThreadVM.cpp b/Libraries/LibWeb/Bindings/MainThreadVM.cpp index 650c9bfe14..83a9843487 100644 --- a/Libraries/LibWeb/Bindings/MainThreadVM.cpp +++ b/Libraries/LibWeb/Bindings/MainThreadVM.cpp @@ -76,7 +76,8 @@ void initialize_main_thread_vm(HTML::EventLoop::Type type) { VERIFY(!s_main_thread_vm); - s_main_thread_vm = JS::VM::create(make()); + s_main_thread_vm = JS::VM::create(); + s_main_thread_vm->set_agent(make()); auto& agent = as(*s_main_thread_vm->agent()); agent.event_loop = s_main_thread_vm->heap().allocate(type);