/* * Copyright (c) 2024, Shannon Booth * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include namespace Web::HTML { class HTMLAllCollection : public Bindings::PlatformObject { WEB_PLATFORM_OBJECT(HTMLAllCollection, Bindings::PlatformObject); JS_DECLARE_ALLOCATOR(HTMLAllCollection); public: enum class Scope { Children, Descendants, }; [[nodiscard]] static JS::NonnullGCPtr create(DOM::ParentNode& root, Scope, ESCAPING Function filter); virtual ~HTMLAllCollection() override; size_t length() const; Variant, JS::NonnullGCPtr, Empty> item(Optional const& name_or_index) const; Variant, JS::NonnullGCPtr, Empty> named_item(FlyString const& name) const; JS::MarkedVector> collect_matching_elements() const; virtual WebIDL::ExceptionOr item_value(size_t index) const override; virtual WebIDL::ExceptionOr named_item_value(FlyString const& name) const override; virtual Vector supported_property_names() const override; virtual bool is_supported_property_index(u32) const override; protected: HTMLAllCollection(DOM::ParentNode& root, Scope, ESCAPING Function filter); virtual void initialize(JS::Realm&) override; virtual bool is_htmldda() const override { return true; } private: Variant, JS::NonnullGCPtr, Empty> get_the_all_named_elements(FlyString const& name) const; JS::GCPtr get_the_all_indexed_element(u32 index) const; Variant, JS::NonnullGCPtr, Empty> get_the_all_indexed_or_named_elements(JS::PropertyKey const& name_or_index) const; virtual void visit_edges(Cell::Visitor&) override; JS::NonnullGCPtr m_root; Function m_filter; Scope m_scope { Scope::Descendants }; }; }