summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/HTML/Window.cpp
diff options
context:
space:
mode:
authornetworkException <git@nwex.de>2022-09-06 19:56:29 +0200
committerLinus Groh <mail@linusgroh.de>2022-09-09 17:42:30 +0100
commite377e28fd29081f809f934c9107a2d742dae7718 (patch)
tree910c59133c7e7c840c413f971b541fb614c1c339 /Userland/Libraries/LibWeb/HTML/Window.cpp
parentb70e4e9909acdb3e6da19b9a749b2cb805280126 (diff)
downloadserenity-e377e28fd29081f809f934c9107a2d742dae7718.zip
LibWeb: Implement window.length
Diffstat (limited to 'Userland/Libraries/LibWeb/HTML/Window.cpp')
-rw-r--r--Userland/Libraries/LibWeb/HTML/Window.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/Window.cpp b/Userland/Libraries/LibWeb/HTML/Window.cpp
index db68182a71..5cd97faf81 100644
--- a/Userland/Libraries/LibWeb/HTML/Window.cpp
+++ b/Userland/Libraries/LibWeb/HTML/Window.cpp
@@ -794,6 +794,7 @@ void Window::initialize(JS::Realm& realm)
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);
@@ -1074,6 +1075,29 @@ JS_DEFINE_NATIVE_FUNCTION(Window::btoa)
return JS::js_string(vm, move(encoded));
}
+// 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
+{
+ auto* impl = TRY(impl_from(vm()));
+
+ // 1. If W's browsing context is null, then return 0.
+ auto* this_browsing_context = impl->associated_document().browsing_context();
+ if (!this_browsing_context)
+ return 0;
+
+ // 2. Return the number of document-tree child browsing contexts of W's browsing context.
+ 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)
{