From 0d73487204dec68920a833bf735711b38c349f14 Mon Sep 17 00:00:00 2001 From: davidot Date: Sun, 3 Oct 2021 13:58:26 +0200 Subject: [PATCH] LibWeb: Fix that $0 was no longer accessible We now set the realm (twice) on every console input. This can probably be avoided if we use two executing contexts one for the website the other for the console. This achieves a similar behavior but is not really nice and not really spec like. --- Userland/Services/WebContent/WebContentConsoleClient.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Userland/Services/WebContent/WebContentConsoleClient.cpp b/Userland/Services/WebContent/WebContentConsoleClient.cpp index eb87b410cd..54a0cc6ab9 100644 --- a/Userland/Services/WebContent/WebContentConsoleClient.cpp +++ b/Userland/Services/WebContent/WebContentConsoleClient.cpp @@ -39,7 +39,16 @@ void WebContentConsoleClient::handle_input(String const& js_source) output_html.append(String::formatted("
{}
", escape_html_entities(hint))); m_interpreter->vm().throw_exception(*m_console_global_object.cell(), error.to_string()); } else { + // FIXME: This is not the correct way to do this, we probably want to have + // multiple execution contexts we switch between. + auto& global_object_before = m_interpreter->realm().global_object(); + VERIFY(is(global_object_before)); + auto& this_value_before = m_interpreter->realm().global_environment().global_this_value(); + m_interpreter->realm().set_global_object(*m_console_global_object.cell(), &global_object_before); + m_interpreter->run(*m_console_global_object.cell(), *program); + + m_interpreter->realm().set_global_object(global_object_before, &this_value_before); } if (m_interpreter->exception()) {