1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 08:58:11 +00:00

LibWeb: Implement [SameObject] behavior for HTMLFormElement.elements

This commit is contained in:
Andreas Kling 2022-11-24 19:04:05 +01:00
parent 7d8ff0c581
commit d7c58aa58d
3 changed files with 11 additions and 7 deletions

View file

@ -33,6 +33,7 @@ HTMLFormElement::~HTMLFormElement() = default;
void HTMLFormElement::visit_edges(Cell::Visitor& visitor) void HTMLFormElement::visit_edges(Cell::Visitor& visitor)
{ {
Base::visit_edges(visitor); Base::visit_edges(visitor);
visitor.visit(m_elements);
for (auto& element : m_associated_elements) for (auto& element : m_associated_elements)
visitor.visit(element.ptr()); visitor.visit(element.ptr());
} }
@ -185,11 +186,12 @@ static bool is_form_control(DOM::Element const& element)
// https://html.spec.whatwg.org/multipage/forms.html#dom-form-elements // https://html.spec.whatwg.org/multipage/forms.html#dom-form-elements
JS::NonnullGCPtr<DOM::HTMLCollection> HTMLFormElement::elements() const JS::NonnullGCPtr<DOM::HTMLCollection> HTMLFormElement::elements() const
{ {
// FIXME: This should return the same HTMLFormControlsCollection object every time, if (!m_elements) {
// but that would cause a reference cycle since HTMLCollection refs the root. m_elements = DOM::HTMLCollection::create(const_cast<HTMLFormElement&>(*this), [](Element const& element) {
return DOM::HTMLCollection::create(const_cast<HTMLFormElement&>(*this), [](Element const& element) { return is_form_control(element);
return is_form_control(element); });
}); }
return *m_elements;
} }
// https://html.spec.whatwg.org/multipage/forms.html#dom-form-length // https://html.spec.whatwg.org/multipage/forms.html#dom-form-length

View file

@ -39,6 +39,8 @@ private:
bool m_firing_submission_events { false }; bool m_firing_submission_events { false };
Vector<JS::GCPtr<HTMLElement>> m_associated_elements; Vector<JS::GCPtr<HTMLElement>> m_associated_elements;
JS::GCPtr<DOM::HTMLCollection> mutable m_elements;
}; };
} }

View file

@ -12,8 +12,8 @@ interface HTMLFormElement : HTMLElement {
undefined submit(); undefined submit();
// FIXME: Should be [SameObject] and a HTMLFormControlsCollection // FIXME: Should be a HTMLFormControlsCollection
readonly attribute HTMLCollection elements; [SameObject] readonly attribute HTMLCollection elements;
readonly attribute unsigned long length; readonly attribute unsigned long length;