mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 22:27:42 +00:00
LibWeb/HTML: Port Window.length to IDL
This commit is contained in:
parent
c42496187b
commit
baaf891c64
4 changed files with 13 additions and 15 deletions
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -58,7 +58,7 @@ public:
|
|||
HTML::BrowsingContext const* browsing_context() const;
|
||||
HTML::BrowsingContext* browsing_context();
|
||||
|
||||
JS::ThrowCompletionOr<size_t> 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> history() const;
|
||||
|
||||
JS::NonnullGCPtr<WindowProxy> frames() const;
|
||||
u32 length() const;
|
||||
|
||||
JS::NonnullGCPtr<Navigator> 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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -72,7 +72,7 @@ JS::ThrowCompletionOr<Optional<JS::PropertyDescriptor>> 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<JS::Value> value;
|
||||
|
@ -227,7 +227,7 @@ JS::ThrowCompletionOr<JS::MarkedVector<JS::Value>> WindowProxy::internal_own_pro
|
|||
auto keys = JS::MarkedVector<JS::Value> { 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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue