From e649144a90ec8b8ec1c7c5bc11790e711abc648f Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 19 Sep 2021 15:39:40 +0200 Subject: [PATCH] LibWeb: Replace ScriptExecutionContext::interpreter() with realm() Here goes another step towards Document not having a JS::Interpreter. --- Userland/Libraries/LibWeb/Bindings/ScriptExecutionContext.h | 5 ++--- Userland/Libraries/LibWeb/DOM/Document.cpp | 5 +++++ Userland/Libraries/LibWeb/DOM/Document.h | 3 ++- Userland/Libraries/LibWeb/DOM/EventTarget.cpp | 2 +- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Userland/Libraries/LibWeb/Bindings/ScriptExecutionContext.h b/Userland/Libraries/LibWeb/Bindings/ScriptExecutionContext.h index 4299fd04d5..3219a80a95 100644 --- a/Userland/Libraries/LibWeb/Bindings/ScriptExecutionContext.h +++ b/Userland/Libraries/LibWeb/Bindings/ScriptExecutionContext.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, Andreas Kling + * Copyright (c) 2020-2021, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ @@ -16,8 +16,7 @@ class ScriptExecutionContext { public: virtual ~ScriptExecutionContext(); - // FIXME: This should not work this way long-term, interpreters should be on the stack. - virtual JS::Interpreter& interpreter() = 0; + virtual JS::Realm& realm() = 0; }; } diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index e873970150..217db327ca 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -630,6 +630,11 @@ Color Document::visited_link_color() const return page()->palette().visited_link(); } +JS::Realm& Document::realm() +{ + return interpreter().realm(); +} + JS::Interpreter& Document::interpreter() { if (!m_interpreter) { diff --git a/Userland/Libraries/LibWeb/DOM/Document.h b/Userland/Libraries/LibWeb/DOM/Document.h index 2c9d044555..b4e2d5ff67 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.h +++ b/Userland/Libraries/LibWeb/DOM/Document.h @@ -173,7 +173,8 @@ public: const String& source() const { return m_source; } void set_source(const String& source) { m_source = source; } - virtual JS::Interpreter& interpreter() override; + JS::Realm& realm(); + JS::Interpreter& interpreter(); JS::Value run_javascript(const StringView& source, const StringView& filename = "(unknown)"); diff --git a/Userland/Libraries/LibWeb/DOM/EventTarget.cpp b/Userland/Libraries/LibWeb/DOM/EventTarget.cpp index 755637e1aa..142a48d96b 100644 --- a/Userland/Libraries/LibWeb/DOM/EventTarget.cpp +++ b/Userland/Libraries/LibWeb/DOM/EventTarget.cpp @@ -133,7 +133,7 @@ void EventTarget::set_event_handler_attribute(FlyString const& name, HTML::Event dbgln("Failed to parse script in event handler attribute '{}'", name); return; } - auto* function = JS::OrdinaryFunctionObject::create(target->script_execution_context()->interpreter().global_object(), name, program->body(), program->parameters(), program->function_length(), nullptr, JS::FunctionKind::Regular, false, false); + auto* function = JS::OrdinaryFunctionObject::create(target->script_execution_context()->realm().global_object(), name, program->body(), program->parameters(), program->function_length(), nullptr, JS::FunctionKind::Regular, false, false); VERIFY(function); listener = adopt_ref(*new DOM::EventListener(JS::make_handle(static_cast(function)))); }