diff --git a/Userland/Libraries/LibWeb/HTML/Window.cpp b/Userland/Libraries/LibWeb/HTML/Window.cpp
index 2a75b43999..2b4e97ddd8 100644
--- a/Userland/Libraries/LibWeb/HTML/Window.cpp
+++ b/Userland/Libraries/LibWeb/HTML/Window.cpp
@@ -1112,7 +1112,6 @@ WebIDL::ExceptionOr Window::initialize_web_interfaces(Badge Window::frames() const
return verify_cast(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(document_tree_child_browsing_context_count());
+}
+
// https://html.spec.whatwg.org/multipage/system-state.html#dom-navigator
JS::NonnullGCPtr 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 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 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)
{
diff --git a/Userland/Libraries/LibWeb/HTML/Window.h b/Userland/Libraries/LibWeb/HTML/Window.h
index ac7be95a4c..e6774cbf68 100644
--- a/Userland/Libraries/LibWeb/HTML/Window.h
+++ b/Userland/Libraries/LibWeb/HTML/Window.h
@@ -58,7 +58,7 @@ public:
HTML::BrowsingContext const* browsing_context() const;
HTML::BrowsingContext* browsing_context();
- JS::ThrowCompletionOr document_tree_child_browsing_context_count() const;
+ size_t document_tree_child_browsing_context_count() const;
ImportMap const& import_map() const { return m_import_map; }
@@ -146,6 +146,7 @@ public:
JS::NonnullGCPtr history() const;
JS::NonnullGCPtr frames() const;
+ u32 length() const;
JS::NonnullGCPtr navigator() const;
@@ -217,7 +218,6 @@ public:
CrossOriginPropertyDescriptorMap& cross_origin_property_descriptor_map() { return m_cross_origin_property_descriptor_map; }
private:
- JS_DECLARE_NATIVE_FUNCTION(length_getter);
JS_DECLARE_NATIVE_FUNCTION(top_getter);
JS_DECLARE_NATIVE_FUNCTION(frame_element_getter);
diff --git a/Userland/Libraries/LibWeb/HTML/Window.idl b/Userland/Libraries/LibWeb/HTML/Window.idl
index 8f0def8a5b..250ba9014e 100644
--- a/Userland/Libraries/LibWeb/HTML/Window.idl
+++ b/Userland/Libraries/LibWeb/HTML/Window.idl
@@ -16,6 +16,7 @@ interface Window : EventTarget {
// other browsing contexts
[Replaceable] readonly attribute WindowProxy frames;
+ [Replaceable] readonly attribute unsigned long length;
// the user agent
readonly attribute Navigator navigator;
diff --git a/Userland/Libraries/LibWeb/HTML/WindowProxy.cpp b/Userland/Libraries/LibWeb/HTML/WindowProxy.cpp
index 0a741b73ec..e6841461d0 100644
--- a/Userland/Libraries/LibWeb/HTML/WindowProxy.cpp
+++ b/Userland/Libraries/LibWeb/HTML/WindowProxy.cpp
@@ -72,7 +72,7 @@ JS::ThrowCompletionOr> WindowProxy::internal_ge
auto index = property_key.as_number();
// 2. Let maxProperties be the number of document-tree child browsing contexts of W.
- auto max_properties = TRY(m_window->document_tree_child_browsing_context_count());
+ auto max_properties = m_window->document_tree_child_browsing_context_count();
// 3. Let value be undefined.
Optional value;
@@ -227,7 +227,7 @@ JS::ThrowCompletionOr> WindowProxy::internal_own_pro
auto keys = JS::MarkedVector { vm.heap() };
// 3. Let maxProperties be the number of document-tree child browsing contexts of W.
- auto max_properties = TRY(m_window->document_tree_child_browsing_context_count());
+ auto max_properties = m_window->document_tree_child_browsing_context_count();
// 4. Let index be 0.
// 5. Repeat while index < maxProperties,