LibJS+LibWeb: Defer initialization of the Agent after VM constructor

This helps unwind a niggly depedency where the VM owns and constructs
the Heap and the Agent. But the agent wants to have customized
construction that depends on the heap. Solve this by defering
the initialization of the Agent to after we have constructed the
VM and the heap.
This commit is contained in:
Shannon Booth 2025-04-24 15:58:00 +12:00 committed by Andreas Kling
commit 7dd7e5b438
Notes: github-actions[bot] 2025-04-25 14:45:40 +00:00
3 changed files with 8 additions and 7 deletions

View file

@ -47,7 +47,7 @@ enum class EvalMode {
class VM : public RefCounted<VM> {
public:
static NonnullRefPtr<VM> create(OwnPtr<Agent> = {});
static NonnullRefPtr<VM> create();
~VM();
GC::Heap& heap() { return m_heap; }
@ -240,6 +240,7 @@ public:
Function<void(Promise&)> on_promise_rejection_handled;
Function<void(Object const&, PropertyKey const&)> on_unimplemented_property_access;
void set_agent(OwnPtr<Agent> 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<Agent>, ErrorMessages);
explicit VM(ErrorMessages);
void load_imported_module(ImportedModuleReferrer, ModuleRequest const&, GC::Ptr<GraphLoadingState::HostDefined>, ImportedModulePayload);
ThrowCompletionOr<void> link_and_eval_module(CyclicModule&);