1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-16 17:55:06 +00:00

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
3 changed files with 14 additions and 17 deletions

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