diff --git a/Tests/LibWeb/Text/expected/all-window-properties.txt b/Tests/LibWeb/Text/expected/all-window-properties.txt index 565e69e1a36..8e3b83a0bc6 100644 --- a/Tests/LibWeb/Text/expected/all-window-properties.txt +++ b/Tests/LibWeb/Text/expected/all-window-properties.txt @@ -338,6 +338,7 @@ ServiceWorkerContainer ServiceWorkerRegistration Set ShadowRealm +ShadowRealmGlobalScope ShadowRoot SharedArrayBuffer SourceBuffer diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index f9e4cfc8059..24ec7c34678 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -462,6 +462,7 @@ set(SOURCES HTML/ServiceWorkerRegistration.cpp HTML/SessionHistoryEntry.cpp HTML/SessionHistoryTraversalQueue.cpp + HTML/ShadowRealmGlobalScope.cpp HTML/SharedResourceRequest.cpp HTML/SourceSet.cpp HTML/Storage.cpp diff --git a/Userland/Libraries/LibWeb/HTML/ShadowRealmGlobalScope.cpp b/Userland/Libraries/LibWeb/HTML/ShadowRealmGlobalScope.cpp new file mode 100644 index 00000000000..8083d4298cd --- /dev/null +++ b/Userland/Libraries/LibWeb/HTML/ShadowRealmGlobalScope.cpp @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024, Shannon Booth + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include + +namespace Web::HTML { + +JS_DEFINE_ALLOCATOR(ShadowRealmGlobalScope); + +ShadowRealmGlobalScope::ShadowRealmGlobalScope(JS::Realm& realm) + : DOM::EventTarget(realm) +{ +} + +ShadowRealmGlobalScope::~ShadowRealmGlobalScope() = default; + +JS::NonnullGCPtr ShadowRealmGlobalScope::create(JS::Realm& realm) +{ + return realm.heap().allocate(realm, realm); +} + +void ShadowRealmGlobalScope::initialize(JS::Realm&) +{ + // FIXME: This does not work as we do not have any intrinsics in the [HostDefined] of a shadow realm. Figure out how this _should_ work. + // Base::initialize(realm); + // WEB_SET_PROTOTYPE_FOR_INTERFACE(ShadowRealmGlobalScope); +} + +void ShadowRealmGlobalScope::visit_edges(Cell::Visitor& visitor) +{ + Base::visit_edges(visitor); +} + +} diff --git a/Userland/Libraries/LibWeb/HTML/ShadowRealmGlobalScope.h b/Userland/Libraries/LibWeb/HTML/ShadowRealmGlobalScope.h new file mode 100644 index 00000000000..931764f8803 --- /dev/null +++ b/Userland/Libraries/LibWeb/HTML/ShadowRealmGlobalScope.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024, Shannon Booth + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include + +namespace Web::HTML { + +// https://whatpr.org/html/9893/webappapis.html#shadowrealmglobalscope +class ShadowRealmGlobalScope : public DOM::EventTarget { + WEB_PLATFORM_OBJECT(ShadowRealmGlobalScope, DOM::EventTarget); + JS_DECLARE_ALLOCATOR(ShadowRealmGlobalScope); + +public: + virtual ~ShadowRealmGlobalScope() override; + + static JS::NonnullGCPtr create(JS::Realm&); + + // https://whatpr.org/html/9893/webappapis.html#dom-shadowrealmglobalscope-self + JS::NonnullGCPtr self() + { + // The self getter steps are to return this. + return *this; + } + +protected: + explicit ShadowRealmGlobalScope(JS::Realm&); + + virtual void initialize(JS::Realm&) override; + virtual void visit_edges(Cell::Visitor&) override; +}; + +} diff --git a/Userland/Libraries/LibWeb/HTML/ShadowRealmGlobalScope.idl b/Userland/Libraries/LibWeb/HTML/ShadowRealmGlobalScope.idl new file mode 100644 index 00000000000..043b16981c5 --- /dev/null +++ b/Userland/Libraries/LibWeb/HTML/ShadowRealmGlobalScope.idl @@ -0,0 +1,6 @@ +// https://whatpr.org/html/9893/webappapis.html#shadowrealmglobalscope +// FIXME: This is not correct! We should not have Exposed=Window here. +[Global, Exposed=Window] +interface ShadowRealmGlobalScope : EventTarget { + readonly attribute ShadowRealmGlobalScope self; +}; diff --git a/Userland/Libraries/LibWeb/idl_files.cmake b/Userland/Libraries/LibWeb/idl_files.cmake index 3b5eb8cc689..2e5436e4026 100644 --- a/Userland/Libraries/LibWeb/idl_files.cmake +++ b/Userland/Libraries/LibWeb/idl_files.cmake @@ -222,6 +222,7 @@ libweb_js_bindings(HTML/RadioNodeList) libweb_js_bindings(HTML/ServiceWorker) libweb_js_bindings(HTML/ServiceWorkerContainer) libweb_js_bindings(HTML/ServiceWorkerRegistration) +libweb_js_bindings(HTML/ShadowRealmGlobalScope) libweb_js_bindings(HTML/Storage) libweb_js_bindings(HTML/SubmitEvent) libweb_js_bindings(HTML/TextMetrics)