LibWeb/HTML: Port Window.top to IDL

This commit is contained in:
Linus Groh 2023-03-05 20:43:53 +00:00
parent baaf891c64
commit dba8dbe07d
Notes: sideshowbarker 2024-07-17 22:55:25 +09:00
3 changed files with 14 additions and 17 deletions
Userland/Libraries/LibWeb/HTML

View file

@ -1073,7 +1073,6 @@ WebIDL::ExceptionOr<void> Window::initialize_web_interfaces(Badge<WindowEnvironm
MUST_OR_THROW_OOM(Bindings::WindowGlobalMixin::initialize(realm, *this));
// FIXME: These should be native accessors, not properties
define_native_accessor(realm, "top", top_getter, nullptr, JS::Attribute::Enumerable);
define_native_accessor(realm, "parent", parent_getter, {}, JS::Attribute::Enumerable);
define_native_accessor(realm, "frameElement", frame_element_getter, {}, JS::Attribute::Enumerable);
define_native_accessor(realm, "performance", performance_getter, performance_setter, JS::Attribute::Enumerable | JS::Attribute::Configurable);
@ -1251,6 +1250,18 @@ u32 Window::length() const
return static_cast<u32>(document_tree_child_browsing_context_count());
}
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-top
JS::GCPtr<WindowProxy const> 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<Navigator> 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));

View file

@ -147,6 +147,7 @@ public:
JS::NonnullGCPtr<WindowProxy> frames() const;
u32 length() const;
JS::GCPtr<WindowProxy const> top() const;
JS::NonnullGCPtr<Navigator> 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);

View file

@ -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;