diff options
author | Linus Groh <mail@linusgroh.de> | 2022-02-21 13:49:44 +0000 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-02-21 13:51:34 +0000 |
commit | 929074ddeac1e9d98789872b0432dea0897f4773 (patch) | |
tree | 6d9024ce5dbf9a83a1fa1fbdb49975c0ce3f0446 | |
parent | f2ca64cecd2930130fd5f06b3b042d13f96bd108 (diff) | |
download | serenity-929074ddeac1e9d98789872b0432dea0897f4773.zip |
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.
-rw-r--r-- | Userland/Services/WebContent/WebContentConsoleClient.cpp | 13 |
1 files changed, 12 insertions, 1 deletions
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, WeakPtr<J , m_interpreter(interpreter) { JS::DeferGC defer_gc(m_interpreter->heap()); - auto console_global_object = m_interpreter->heap().allocate_without_global_object<ConsoleGlobalObject>(static_cast<Web::Bindings::WindowObject&>(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<ConsoleGlobalObject>(static_cast<Web::Bindings::WindowObject&>(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<Web::HTML::EnvironmentSettingsObject>(*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); } |