summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-09-01 20:08:38 +0200
committerAndreas Kling <kling@serenityos.org>2022-09-06 00:27:09 +0200
commit2d72abc3d4dbe685cb5c78b6b8a89ed5898d03a8 (patch)
treeb84c3d97dbe773933e4985948d8671862b75c7b4 /Userland
parent905eb8cb4de12bd4c788a65e2e1e2fc48db3d170 (diff)
downloadserenity-2d72abc3d4dbe685cb5c78b6b8a89ed5898d03a8.zip
LibWeb+WebContent: Store Realm instead of Interpreter in ConsoleClient
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibWeb/DOM/Document.cpp6
-rw-r--r--Userland/Services/WebContent/ConnectionFromClient.cpp11
-rw-r--r--Userland/Services/WebContent/ConnectionFromClient.h2
-rw-r--r--Userland/Services/WebContent/WebContentConsoleClient.cpp16
-rw-r--r--Userland/Services/WebContent/WebContentConsoleClient.h4
5 files changed, 20 insertions, 19 deletions
diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp
index dd180b8f4a..e9903c0b35 100644
--- a/Userland/Libraries/LibWeb/DOM/Document.cpp
+++ b/Userland/Libraries/LibWeb/DOM/Document.cpp
@@ -1058,14 +1058,14 @@ JS::Interpreter& Document::interpreter()
JS::Value Document::run_javascript(StringView source, StringView filename)
{
// FIXME: The only user of this function now is javascript: URLs. Refactor them to follow the spec: https://html.spec.whatwg.org/multipage/browsing-the-web.html#javascript-protocol
- auto& interpreter = document().interpreter();
- auto script_or_error = JS::Script::parse(source, interpreter.realm(), filename);
+ auto interpreter = JS::Interpreter::create_with_existing_realm(realm());
+ auto script_or_error = JS::Script::parse(source, realm(), filename);
if (script_or_error.is_error()) {
// FIXME: Add error logging back.
return JS::js_undefined();
}
- auto result = interpreter.run(script_or_error.value());
+ auto result = interpreter->run(script_or_error.value());
if (result.is_error()) {
// FIXME: I'm sure the spec could tell us something about error propagation here!
diff --git a/Userland/Services/WebContent/ConnectionFromClient.cpp b/Userland/Services/WebContent/ConnectionFromClient.cpp
index 901f56bd33..65a0cb3ca7 100644
--- a/Userland/Services/WebContent/ConnectionFromClient.cpp
+++ b/Userland/Services/WebContent/ConnectionFromClient.cpp
@@ -13,7 +13,6 @@
#include <LibGfx/SystemTheme.h>
#include <LibJS/Console.h>
#include <LibJS/Heap/Heap.h>
-#include <LibJS/Interpreter.h>
#include <LibJS/Parser.h>
#include <LibJS/Runtime/ConsoleObject.h>
#include <LibWeb/Bindings/MainThreadVM.h>
@@ -386,13 +385,13 @@ Messages::WebContentServer::GetHoveredNodeIdResponse ConnectionFromClient::get_h
void ConnectionFromClient::initialize_js_console(Badge<PageHost>)
{
auto* document = page().top_level_browsing_context().active_document();
- auto interpreter = document->interpreter().make_weak_ptr();
- if (m_interpreter.ptr() == interpreter.ptr())
+ auto realm = document->realm().make_weak_ptr();
+ if (m_realm.ptr() == realm.ptr())
return;
- auto& console_object = *interpreter->realm().intrinsics().console_object();
- m_interpreter = interpreter;
- m_console_client = make<WebContentConsoleClient>(console_object.console(), interpreter, *this);
+ auto& console_object = *realm->intrinsics().console_object();
+ m_realm = realm;
+ m_console_client = make<WebContentConsoleClient>(console_object.console(), *m_realm, *this);
console_object.console().set_client(*m_console_client.ptr());
}
diff --git a/Userland/Services/WebContent/ConnectionFromClient.h b/Userland/Services/WebContent/ConnectionFromClient.h
index ffb00dbfab..676426630f 100644
--- a/Userland/Services/WebContent/ConnectionFromClient.h
+++ b/Userland/Services/WebContent/ConnectionFromClient.h
@@ -92,7 +92,7 @@ private:
HashMap<i32, NonnullRefPtr<Gfx::Bitmap>> m_backing_stores;
- WeakPtr<JS::Interpreter> m_interpreter;
+ WeakPtr<JS::Realm> m_realm;
OwnPtr<WebContentConsoleClient> m_console_client;
JS::Handle<JS::GlobalObject> m_console_global_object;
diff --git a/Userland/Services/WebContent/WebContentConsoleClient.cpp b/Userland/Services/WebContent/WebContentConsoleClient.cpp
index 9b4a30b0a4..44f07c8f0d 100644
--- a/Userland/Services/WebContent/WebContentConsoleClient.cpp
+++ b/Userland/Services/WebContent/WebContentConsoleClient.cpp
@@ -16,18 +16,17 @@
namespace WebContent {
-WebContentConsoleClient::WebContentConsoleClient(JS::Console& console, WeakPtr<JS::Interpreter> interpreter, ConnectionFromClient& client)
+WebContentConsoleClient::WebContentConsoleClient(JS::Console& console, JS::Realm& realm, ConnectionFromClient& client)
: ConsoleClient(console)
, m_client(client)
- , m_interpreter(interpreter)
+ , m_realm(realm)
{
- JS::DeferGC defer_gc(m_interpreter->heap());
+ JS::DeferGC defer_gc(realm.heap());
- auto& vm = m_interpreter->vm();
- auto& realm = m_interpreter->realm();
+ auto& vm = realm.vm();
auto& window = static_cast<Web::HTML::Window&>(realm.global_object());
- auto console_global_object = m_interpreter->heap().allocate_without_realm<ConsoleGlobalObject>(realm, window);
+ auto console_global_object = realm.heap().allocate_without_realm<ConsoleGlobalObject>(realm, window);
// 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().
@@ -41,7 +40,10 @@ WebContentConsoleClient::WebContentConsoleClient(JS::Console& console, WeakPtr<J
void WebContentConsoleClient::handle_input(String const& js_source)
{
- auto& settings = verify_cast<Web::HTML::EnvironmentSettingsObject>(*m_interpreter->realm().host_defined());
+ if (!m_realm)
+ return;
+
+ auto& settings = verify_cast<Web::HTML::EnvironmentSettingsObject>(*m_realm->host_defined());
auto script = Web::HTML::ClassicScript::create("(console)", js_source, settings, settings.api_base_url());
// FIXME: Add parse error printouts back once ClassicScript can report parse errors.
diff --git a/Userland/Services/WebContent/WebContentConsoleClient.h b/Userland/Services/WebContent/WebContentConsoleClient.h
index 9456750d55..a8dfc28a16 100644
--- a/Userland/Services/WebContent/WebContentConsoleClient.h
+++ b/Userland/Services/WebContent/WebContentConsoleClient.h
@@ -18,7 +18,7 @@ namespace WebContent {
class WebContentConsoleClient final : public JS::ConsoleClient {
public:
- WebContentConsoleClient(JS::Console&, WeakPtr<JS::Interpreter>, ConnectionFromClient&);
+ WebContentConsoleClient(JS::Console&, JS::Realm&, ConnectionFromClient&);
void handle_input(String const& js_source);
void send_messages(i32 start_index);
@@ -28,7 +28,7 @@ private:
virtual JS::ThrowCompletionOr<JS::Value> printer(JS::Console::LogLevel log_level, PrinterArguments) override;
ConnectionFromClient& m_client;
- WeakPtr<JS::Interpreter> m_interpreter;
+ WeakPtr<JS::Realm> m_realm;
JS::Handle<ConsoleGlobalObject> m_console_global_object;
void clear_output();