diff --git a/Userland/Services/WebContent/WebContentConsoleClient.cpp b/Userland/Services/WebContent/WebContentConsoleClient.cpp index adfa7dd2a78..8c3bc70d566 100644 --- a/Userland/Services/WebContent/WebContentConsoleClient.cpp +++ b/Userland/Services/WebContent/WebContentConsoleClient.cpp @@ -9,18 +9,12 @@ #include #include -#include #include #include -#include -#include -#include #include #include -#include -#include -#include #include +#include #include #include #include @@ -51,17 +45,21 @@ void WebContentConsoleClient::handle_input(ByteString const& js_source) if (!m_console_global_environment_extensions) return; - auto& settings = Web::HTML::relevant_settings_object(*m_console_global_environment_extensions); - auto script = Web::HTML::ClassicScript::create("(console)", js_source, settings, settings.api_base_url()); + auto& realm = m_console->realm(); + auto& window = verify_cast(realm.global_object()); - JS::NonnullGCPtr with_scope = JS::new_object_environment(*m_console_global_environment_extensions, true, &settings.realm().global_environment()); + auto source_text = ByteString::formatted("return {}", js_source); - // FIXME: Add parse error printouts back once ClassicScript can report parse errors. - auto result = script->run(Web::HTML::ClassicScript::RethrowErrors::No, with_scope); + auto completion = Web::WebDriver::execute_a_function_body(window, source_text, {}, m_console_global_environment_extensions); - if (result.value().has_value()) { - m_console_global_environment_extensions->set_most_recent_result(result.value().value()); - print_html(JS::MarkupGenerator::html_from_value(*result.value()).release_value_but_fixme_should_propagate_errors().to_byte_string()); + if (completion.has_value()) { + m_console_global_environment_extensions->set_most_recent_result(completion.value()); + print_html(JS::MarkupGenerator::html_from_value(completion.value()).release_value_but_fixme_should_propagate_errors().to_byte_string()); + } else { + m_console_global_environment_extensions->set_most_recent_result(JS::js_undefined()); + + if (completion.error().value().has_value()) + print_html(JS::MarkupGenerator::html_from_value(completion.error().value().value()).release_value_but_fixme_should_propagate_errors().to_byte_string()); } }