From b105c06824d7ec1dd2b47f11590d6f40547a16e8 Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Sat, 26 Oct 2024 19:46:13 +1300 Subject: [PATCH] LibWeb: Introduce a SyntheticHostDefined class This class is the host defined field of a synthetic realm created as part of a shadow realm. --- .../LibWeb/Bindings/SyntheticHostDefined.cpp | 20 ++++++++++ .../LibWeb/Bindings/SyntheticHostDefined.h | 27 ++++++++++++++ Userland/Libraries/LibWeb/CMakeLists.txt | 2 + Userland/Libraries/LibWeb/Forward.h | 2 + .../HTML/Scripting/SyntheticRealmSettings.cpp | 20 ++++++++++ .../HTML/Scripting/SyntheticRealmSettings.h | 37 +++++++++++++++++++ 6 files changed, 108 insertions(+) create mode 100644 Userland/Libraries/LibWeb/Bindings/SyntheticHostDefined.cpp create mode 100644 Userland/Libraries/LibWeb/Bindings/SyntheticHostDefined.h create mode 100644 Userland/Libraries/LibWeb/HTML/Scripting/SyntheticRealmSettings.cpp create mode 100644 Userland/Libraries/LibWeb/HTML/Scripting/SyntheticRealmSettings.h diff --git a/Userland/Libraries/LibWeb/Bindings/SyntheticHostDefined.cpp b/Userland/Libraries/LibWeb/Bindings/SyntheticHostDefined.cpp new file mode 100644 index 00000000000..0aa7e24f3e7 --- /dev/null +++ b/Userland/Libraries/LibWeb/Bindings/SyntheticHostDefined.cpp @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2024, Shannon Booth + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include +#include +#include + +namespace Web::Bindings { + +void SyntheticHostDefined::visit_edges(JS::Cell::Visitor& visitor) +{ + JS::Realm::HostDefined::visit_edges(visitor); + synthetic_realm_settings.visit_edges(visitor); +} + +} diff --git a/Userland/Libraries/LibWeb/Bindings/SyntheticHostDefined.h b/Userland/Libraries/LibWeb/Bindings/SyntheticHostDefined.h new file mode 100644 index 00000000000..f404dacb0fb --- /dev/null +++ b/Userland/Libraries/LibWeb/Bindings/SyntheticHostDefined.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024, Shannon Booth + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include +#include + +namespace Web::Bindings { + +struct SyntheticHostDefined : public JS::Realm::HostDefined { + SyntheticHostDefined(HTML::SyntheticRealmSettings synthetic_realm_settings) + : synthetic_realm_settings(move(synthetic_realm_settings)) + { + } + + virtual ~SyntheticHostDefined() override = default; + virtual void visit_edges(JS::Cell::Visitor& visitor) override; + + HTML::SyntheticRealmSettings synthetic_realm_settings; +}; + +} diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index 0812e4ed72a..f9e4cfc8059 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -23,6 +23,7 @@ set(SOURCES Bindings/OptionConstructor.cpp Bindings/PlatformObject.cpp Bindings/PrincipalHostDefined.cpp + Bindings/SyntheticHostDefined.cpp Clipboard/Clipboard.cpp Clipboard/ClipboardEvent.cpp Crypto/Crypto.cpp @@ -449,6 +450,7 @@ set(SOURCES HTML/Scripting/ModuleMap.cpp HTML/Scripting/ModuleScript.cpp HTML/Scripting/Script.cpp + HTML/Scripting/SyntheticRealmSettings.cpp HTML/Scripting/TemporaryExecutionContext.cpp HTML/Scripting/WindowEnvironmentSettingsObject.cpp HTML/Scripting/WorkerEnvironmentSettingsObject.cpp diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h index b6c3f7fca37..2060fdba116 100644 --- a/Userland/Libraries/LibWeb/Forward.h +++ b/Userland/Libraries/LibWeb/Forward.h @@ -491,6 +491,7 @@ class MessageEvent; class MessagePort; class MimeType; class MimeTypeArray; +class ModuleMap; class Navigable; class NavigableContainer; class NavigateEvent; @@ -555,6 +556,7 @@ struct ScrollOptions; struct ScrollToOptions; struct SerializedFormData; struct StructuredSerializeOptions; +struct SyntheticRealmSettings; struct ToggleTaskTracker; struct TransferDataHolder; } diff --git a/Userland/Libraries/LibWeb/HTML/Scripting/SyntheticRealmSettings.cpp b/Userland/Libraries/LibWeb/HTML/Scripting/SyntheticRealmSettings.cpp new file mode 100644 index 00000000000..d1cbf9d0d55 --- /dev/null +++ b/Userland/Libraries/LibWeb/HTML/Scripting/SyntheticRealmSettings.cpp @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2024, Shannon Booth + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include + +namespace Web::HTML { + +void SyntheticRealmSettings::visit_edges(JS::Cell::Visitor& visitor) +{ + execution_context->visit_edges(visitor); + visitor.visit(principal_realm); + visitor.visit(underlying_realm); + visitor.visit(module_map); +} + +} diff --git a/Userland/Libraries/LibWeb/HTML/Scripting/SyntheticRealmSettings.h b/Userland/Libraries/LibWeb/HTML/Scripting/SyntheticRealmSettings.h new file mode 100644 index 00000000000..eb59931f032 --- /dev/null +++ b/Userland/Libraries/LibWeb/HTML/Scripting/SyntheticRealmSettings.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024, Shannon Booth + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include +#include + +namespace Web::HTML { + +// https://whatpr.org/html/9893/webappapis.html#synthetic-realm-settings-objects +// Each synthetic realm has an associated synthetic realm settings object with the following fields: +struct SyntheticRealmSettings { + // An execution context + // The JavaScript execution context for the scripts within this realm. + NonnullOwnPtr execution_context; + + // A principal realm + // The principal realm which this synthetic realm exists within. + JS::NonnullGCPtr principal_realm; + + // An underlying realm + // The synthetic realm which this settings object represents. + JS::NonnullGCPtr underlying_realm; + + // A module map + // A module map that is used when importing JavaScript modules. + JS::NonnullGCPtr module_map; + + void visit_edges(JS::Cell::Visitor&); +}; + +}