diff --git a/Userland/Services/WebContent/WebContentConsoleClient.cpp b/Userland/Services/WebContent/WebContentConsoleClient.cpp index 896b644005..f33ba5143b 100644 --- a/Userland/Services/WebContent/WebContentConsoleClient.cpp +++ b/Userland/Services/WebContent/WebContentConsoleClient.cpp @@ -22,8 +22,19 @@ WebContentConsoleClient::WebContentConsoleClient(JS::Console& console, WeakPtrheap()); - auto console_global_object = m_interpreter->heap().allocate_without_global_object(static_cast(m_interpreter->global_object())); + + auto& vm = m_interpreter->vm(); + auto& global_object = m_interpreter->global_object(); + + auto console_global_object = m_interpreter->heap().allocate_without_global_object(static_cast(global_object)); + + // NOTE: We need to push an execution context here for NativeFunction::create() to succeed during global object initialization. + // It gets removed immediately after creating the interpreter in Document::interpreter(). + auto& eso = verify_cast(*m_interpreter->realm().host_defined()); + vm.push_execution_context(eso.realm_execution_context(), global_object); console_global_object->initialize_global_object(); + vm.pop_execution_context(); + m_console_global_object = JS::make_handle(console_global_object); }