1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 08:47:34 +00:00

LibWeb: Replace ScriptExecutionContext::interpreter() with realm()

Here goes another step towards Document not having a JS::Interpreter.
This commit is contained in:
Andreas Kling 2021-09-19 15:39:40 +02:00
parent 7a6ad1b19c
commit e649144a90
4 changed files with 10 additions and 5 deletions

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org> * Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
@ -16,8 +16,7 @@ class ScriptExecutionContext {
public: public:
virtual ~ScriptExecutionContext(); virtual ~ScriptExecutionContext();
// FIXME: This should not work this way long-term, interpreters should be on the stack. virtual JS::Realm& realm() = 0;
virtual JS::Interpreter& interpreter() = 0;
}; };
} }

View file

@ -630,6 +630,11 @@ Color Document::visited_link_color() const
return page()->palette().visited_link(); return page()->palette().visited_link();
} }
JS::Realm& Document::realm()
{
return interpreter().realm();
}
JS::Interpreter& Document::interpreter() JS::Interpreter& Document::interpreter()
{ {
if (!m_interpreter) { if (!m_interpreter) {

View file

@ -173,7 +173,8 @@ public:
const String& source() const { return m_source; } const String& source() const { return m_source; }
void set_source(const String& source) { m_source = 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)"); JS::Value run_javascript(const StringView& source, const StringView& filename = "(unknown)");

View file

@ -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); dbgln("Failed to parse script in event handler attribute '{}'", name);
return; 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); VERIFY(function);
listener = adopt_ref(*new DOM::EventListener(JS::make_handle(static_cast<JS::FunctionObject*>(function)))); listener = adopt_ref(*new DOM::EventListener(JS::make_handle(static_cast<JS::FunctionObject*>(function))));
} }