diff --git a/Userland/Libraries/LibWeb/HTML/FormControlInfrastructure.cpp b/Userland/Libraries/LibWeb/HTML/FormControlInfrastructure.cpp index 0e18b228ab..7f782e9d53 100644 --- a/Userland/Libraries/LibWeb/HTML/FormControlInfrastructure.cpp +++ b/Userland/Libraries/LibWeb/HTML/FormControlInfrastructure.cpp @@ -51,8 +51,6 @@ WebIDL::ExceptionOr create_entry(JS::Realm& realm, String co // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#constructing-the-form-data-set WebIDL::ExceptionOr>> construct_entry_list(JS::Realm& realm, HTMLFormElement& form, JS::GCPtr submitter, Optional encoding) { - auto& vm = realm.vm(); - // 1. If form's constructing entry list is true, then return null. if (form.constructing_entry_list()) return Optional> {}; @@ -61,7 +59,7 @@ WebIDL::ExceptionOr>> construct_entry_list(J form.set_constructing_entry_list(true); // 3. Let controls be a list of all the submittable elements whose form owner is form, in tree order. - auto controls = TRY_OR_THROW_OOM(vm, form.get_submittable_elements()); + auto controls = form.get_submittable_elements(); // 4. Let entry list be a new empty entry list. Vector entry_list; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp index 86f762863c..ac601371f0 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp @@ -538,31 +538,22 @@ WebIDL::ExceptionOr HTMLFormElement::report_validity() } // https://html.spec.whatwg.org/multipage/forms.html#category-submit -ErrorOr>> HTMLFormElement::get_submittable_elements() +Vector> HTMLFormElement::get_submittable_elements() { - Vector> submittable_elements = {}; - for (size_t i = 0; i < elements()->length(); i++) { - auto* element = elements()->item(i); - TRY(populate_vector_with_submittable_elements_in_tree_order(*element, submittable_elements)); - } + Vector> submittable_elements; + + root().for_each_in_subtree([&](auto& node) { + if (auto* form_associated_element = dynamic_cast(&node)) { + if (form_associated_element->is_submittable() && form_associated_element->form() == this) + submittable_elements.append(form_associated_element->form_associated_element_to_html_element()); + } + + return IterationDecision::Continue; + }); + return submittable_elements; } -ErrorOr HTMLFormElement::populate_vector_with_submittable_elements_in_tree_order(JS::NonnullGCPtr element, Vector>& elements) -{ - if (auto* form_associated_element = dynamic_cast(element.ptr())) { - if (form_associated_element->is_submittable()) - TRY(elements.try_append(element)); - } - - for (size_t i = 0; i < element->children()->length(); i++) { - auto* child = element->children()->item(i); - TRY(populate_vector_with_submittable_elements_in_tree_order(*child, elements)); - } - - return {}; -} - // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-fs-method StringView HTMLFormElement::method() const { diff --git a/Userland/Libraries/LibWeb/HTML/HTMLFormElement.h b/Userland/Libraries/LibWeb/HTML/HTMLFormElement.h index 016efb8bd6..2e40b26e2f 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLFormElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLFormElement.h @@ -74,7 +74,7 @@ public: void add_associated_element(Badge, HTMLElement&); void remove_associated_element(Badge, HTMLElement&); - ErrorOr>> get_submittable_elements(); + Vector> get_submittable_elements(); JS::NonnullGCPtr elements() const; unsigned length() const; @@ -109,8 +109,6 @@ private: virtual Vector supported_property_names() const override; virtual bool is_supported_property_index(u32) const override; - ErrorOr populate_vector_with_submittable_elements_in_tree_order(JS::NonnullGCPtr element, Vector>& elements); - ErrorOr pick_an_encoding() const; ErrorOr mutate_action_url(AK::URL parsed_action, Vector entry_list, String encoding, JS::NonnullGCPtr target_navigable, Bindings::NavigationHistoryBehavior history_handling, UserNavigationInvolvement user_involvement);