Przeglądaj źródła

LibWeb: Hook on_call_stack_emptied after m_interpreter was initialized

We must hook `on_call_stack_emptied` after the interpreter was created,
as the initialization of the WindowsObject can invoke some internal
calls, which will eventually lead to this hook being called without
`m_interpreter` being fully initialized yet.
Idan Horowitz 4 lat temu
rodzic
commit
2f60508ae0
1 zmienionych plików z 5 dodań i 1 usunięć
  1. 5 1
      Userland/Libraries/LibWeb/DOM/Document.cpp

+ 5 - 1
Userland/Libraries/LibWeb/DOM/Document.cpp

@@ -625,6 +625,11 @@ JS::Interpreter& Document::interpreter()
 {
     if (!m_interpreter) {
         auto& vm = Bindings::main_thread_vm();
+        m_interpreter = JS::Interpreter::create<Bindings::WindowObject>(vm, *m_window);
+
+        // NOTE: We must hook `on_call_stack_emptied` after the interpreter was created, as the initialization of the
+        // WindowsObject can invoke some internal calls, which will eventually lead to this hook being called without
+        // `m_interpreter` being fully initialized yet.
         // TODO: Hook up vm.on_promise_unhandled_rejection and vm.on_promise_rejection_handled
         // See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises#promise_rejection_events
         vm.on_call_stack_emptied = [this] {
@@ -659,7 +664,6 @@ JS::Interpreter& Document::interpreter()
 
             vm.finish_execution_generation();
         };
-        m_interpreter = JS::Interpreter::create<Bindings::WindowObject>(vm, *m_window);
     }
     return *m_interpreter;
 }