1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 08:58:11 +00:00

LibWeb/HTML: Port Window.length to IDL

This commit is contained in:
Linus Groh 2023-03-05 20:37:41 +00:00
parent c42496187b
commit baaf891c64
4 changed files with 13 additions and 15 deletions

View file

@ -1112,7 +1112,6 @@ WebIDL::ExceptionOr<void> Window::initialize_web_interfaces(Badge<WindowEnvironm
define_native_accessor(realm, "pageXOffset", scroll_x_getter, {}, attr);
define_native_accessor(realm, "scrollY", scroll_y_getter, {}, attr);
define_native_accessor(realm, "pageYOffset", scroll_y_getter, {}, attr);
define_native_accessor(realm, "length", length_getter, {}, attr);
define_native_function(realm, "scroll", scroll, 2, attr);
define_native_function(realm, "scrollTo", scroll, 2, attr);
@ -1245,6 +1244,13 @@ JS::NonnullGCPtr<WindowProxy> Window::frames() const
return verify_cast<WindowProxy>(relevant_realm(*this).global_environment().global_this_value());
}
// https://html.spec.whatwg.org/multipage/window-object.html#dom-length
u32 Window::length() const
{
// The length getter steps are to return this's associated Document's document-tree child navigables's size.
return static_cast<u32>(document_tree_child_browsing_context_count());
}
// https://html.spec.whatwg.org/multipage/system-state.html#dom-navigator
JS::NonnullGCPtr<Navigator> Window::navigator() const
{
@ -1531,7 +1537,7 @@ JS_DEFINE_NATIVE_FUNCTION(Window::focus)
}
// https://html.spec.whatwg.org/multipage/window-object.html#number-of-document-tree-child-browsing-contexts
JS::ThrowCompletionOr<size_t> Window::document_tree_child_browsing_context_count() const
size_t Window::document_tree_child_browsing_context_count() const
{
// 1. If W's browsing context is null, then return 0.
auto* this_browsing_context = associated_document().browsing_context();
@ -1542,15 +1548,6 @@ JS::ThrowCompletionOr<size_t> Window::document_tree_child_browsing_context_count
return this_browsing_context->document_tree_child_browsing_context_count();
}
// https://html.spec.whatwg.org/multipage/window-object.html#dom-length
JS_DEFINE_NATIVE_FUNCTION(Window::length_getter)
{
auto* impl = TRY(impl_from(vm));
// The length getter steps are to return the number of document-tree child browsing contexts of this.
return TRY(impl->document_tree_child_browsing_context_count());
}
// https://html.spec.whatwg.org/multipage/browsers.html#dom-top
JS_DEFINE_NATIVE_FUNCTION(Window::top_getter)
{