diff options
-rw-r--r-- | Userland/Libraries/LibWeb/Bindings/MainThreadVM.cpp | 4 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp | 6 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.h | 7 |
3 files changed, 16 insertions, 1 deletions
diff --git a/Userland/Libraries/LibWeb/Bindings/MainThreadVM.cpp b/Userland/Libraries/LibWeb/Bindings/MainThreadVM.cpp index cfdf20bf4a..0f17296c8b 100644 --- a/Userland/Libraries/LibWeb/Bindings/MainThreadVM.cpp +++ b/Userland/Libraries/LibWeb/Bindings/MainThreadVM.cpp @@ -12,8 +12,10 @@ namespace Web::Bindings { JS::VM& main_thread_vm() { static RefPtr<JS::VM> vm; - if (!vm) + if (!vm) { vm = JS::VM::create(make<WebEngineCustomData>()); + static_cast<WebEngineCustomData*>(vm->custom_data())->event_loop.set_vm(*vm); + } return *vm; } diff --git a/Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp b/Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp index 72e808ee76..ed74909e97 100644 --- a/Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp +++ b/Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp @@ -18,6 +18,12 @@ EventLoop::~EventLoop() { } +void EventLoop::set_vm(JS::VM& vm) +{ + VERIFY(!m_vm); + m_vm = &vm; +} + EventLoop& main_thread_event_loop() { return static_cast<Bindings::WebEngineCustomData*>(Bindings::main_thread_vm().custom_data())->event_loop; diff --git a/Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.h b/Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.h index a22178b1c8..26ee3ebdd7 100644 --- a/Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.h +++ b/Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.h @@ -35,6 +35,11 @@ public: Task const* currently_running_task() const { return m_currently_running_task; } + JS::VM& vm() { return *m_vm; } + JS::VM const& vm() const { return *m_vm; } + + void set_vm(JS::VM&); + private: Type m_type { Type::Window }; @@ -42,6 +47,8 @@ private: // https://html.spec.whatwg.org/multipage/webappapis.html#currently-running-task Task* m_currently_running_task { nullptr }; + + JS::VM* m_vm { nullptr }; }; EventLoop& main_thread_event_loop(); |