From 929074ddeac1e9d98789872b0432dea0897f4773 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Mon, 21 Feb 2022 13:49:44 +0000 Subject: [PATCH] WebContent: Push execution context before ConsoleGlobalObject init This fixes a crash of the browser when loading any page. LibWeb immediately pops the 'running execution context' after creating an interpreter, but it's needed to have a 'current realm' during initialization of the ConsoleGlobalObject for NativeFunction::create() to work. Once this is done, we can immediately pop the execution context again. --- .../Services/WebContent/WebContentConsoleClient.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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); }