diff --git a/Userland/Libraries/LibWeb/HTML/Window.cpp b/Userland/Libraries/LibWeb/HTML/Window.cpp index 2b4e97ddd8..403951ead2 100644 --- a/Userland/Libraries/LibWeb/HTML/Window.cpp +++ b/Userland/Libraries/LibWeb/HTML/Window.cpp @@ -1073,7 +1073,6 @@ WebIDL::ExceptionOr Window::initialize_web_interfaces(Badge(document_tree_child_browsing_context_count()); } +// https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-top +JS::GCPtr Window::top() const +{ + // 1. If this's navigable is null, then return null. + auto const* browsing_context = this->browsing_context(); + if (!browsing_context) + return {}; + + // 2. Return this's navigable's top-level traversable's active WindowProxy. + return browsing_context->top_level_browsing_context().window_proxy(); +} + // https://html.spec.whatwg.org/multipage/system-state.html#dom-navigator JS::NonnullGCPtr Window::navigator() const { @@ -1548,20 +1559,6 @@ size_t Window::document_tree_child_browsing_context_count() const return this_browsing_context->document_tree_child_browsing_context_count(); } -// https://html.spec.whatwg.org/multipage/browsers.html#dom-top -JS_DEFINE_NATIVE_FUNCTION(Window::top_getter) -{ - auto* impl = TRY(impl_from(vm)); - - // 1. If this Window object's browsing context is null, then return null. - auto* browsing_context = impl->browsing_context(); - if (!browsing_context) - return JS::js_null(); - - // 2. Return this Window object's browsing context's top-level browsing context's WindowProxy object. - return browsing_context->top_level_browsing_context().window_proxy(); -} - JS_DEFINE_NATIVE_FUNCTION(Window::parent_getter) { auto* impl = TRY(impl_from(vm)); diff --git a/Userland/Libraries/LibWeb/HTML/Window.h b/Userland/Libraries/LibWeb/HTML/Window.h index e6774cbf68..e75db1c3bd 100644 --- a/Userland/Libraries/LibWeb/HTML/Window.h +++ b/Userland/Libraries/LibWeb/HTML/Window.h @@ -147,6 +147,7 @@ public: JS::NonnullGCPtr frames() const; u32 length() const; + JS::GCPtr top() const; JS::NonnullGCPtr navigator() const; @@ -218,8 +219,6 @@ public: CrossOriginPropertyDescriptorMap& cross_origin_property_descriptor_map() { return m_cross_origin_property_descriptor_map; } private: - JS_DECLARE_NATIVE_FUNCTION(top_getter); - JS_DECLARE_NATIVE_FUNCTION(frame_element_getter); JS_DECLARE_NATIVE_FUNCTION(location_setter); diff --git a/Userland/Libraries/LibWeb/HTML/Window.idl b/Userland/Libraries/LibWeb/HTML/Window.idl index 250ba9014e..b589298c79 100644 --- a/Userland/Libraries/LibWeb/HTML/Window.idl +++ b/Userland/Libraries/LibWeb/HTML/Window.idl @@ -17,6 +17,7 @@ interface Window : EventTarget { // other browsing contexts [Replaceable] readonly attribute WindowProxy frames; [Replaceable] readonly attribute unsigned long length; + [LegacyUnforgeable] readonly attribute WindowProxy? top; // the user agent readonly attribute Navigator navigator;