Skip to content

Commit

Permalink
LibWeb: Fix that $0 was no longer accessible
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
davidot authored and awesomekling committed Oct 3, 2021
1 parent 04454ef commit 0d73487
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Userland/Services/WebContent/WebContentConsoleClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,16 @@ void WebContentConsoleClient::handle_input(String const& js_source)
output_html.append(String::formatted("<pre>{}</pre>", escape_html_entities(hint)));
m_interpreter->vm().throw_exception<JS::SyntaxError>(*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<Web::Bindings::WindowObject>(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()) {
Expand Down

0 comments on commit 0d73487

Please sign in to comment.