summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/HTML
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-11-24 19:04:05 +0100
committerAndreas Kling <kling@serenityos.org>2022-11-25 22:49:59 +0100
commitd7c58aa58d02ad2d873549d5e3563657dfa3ef40 (patch)
tree61539235e59c8ba95606f3d7fd417fa6c0acbead /Userland/Libraries/LibWeb/HTML
parent7d8ff0c58182c8f06ecbc911d49780796cd37db1 (diff)
downloadserenity-d7c58aa58d02ad2d873549d5e3563657dfa3ef40.zip
LibWeb: Implement [SameObject] behavior for HTMLFormElement.elements
Diffstat (limited to 'Userland/Libraries/LibWeb/HTML')
-rw-r--r--Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp12
-rw-r--r--Userland/Libraries/LibWeb/HTML/HTMLFormElement.h2
-rw-r--r--Userland/Libraries/LibWeb/HTML/HTMLFormElement.idl4
3 files changed, 11 insertions, 7 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp
index 647bec6413..fd58ef88af 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp
+++ b/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp
@@ -33,6 +33,7 @@ HTMLFormElement::~HTMLFormElement() = default;
void HTMLFormElement::visit_edges(Cell::Visitor& visitor)
{
Base::visit_edges(visitor);
+ visitor.visit(m_elements);
for (auto& element : m_associated_elements)
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
JS::NonnullGCPtr<DOM::HTMLCollection> HTMLFormElement::elements() const
{
- // FIXME: This should return the same HTMLFormControlsCollection object every time,
- // but that would cause a reference cycle since HTMLCollection refs the root.
- return DOM::HTMLCollection::create(const_cast<HTMLFormElement&>(*this), [](Element const& element) {
- return is_form_control(element);
- });
+ if (!m_elements) {
+ m_elements = DOM::HTMLCollection::create(const_cast<HTMLFormElement&>(*this), [](Element const& element) {
+ return is_form_control(element);
+ });
+ }
+ return *m_elements;
}
// https://html.spec.whatwg.org/multipage/forms.html#dom-form-length
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLFormElement.h b/Userland/Libraries/LibWeb/HTML/HTMLFormElement.h
index 69eea3e773..7e63706fd3 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLFormElement.h
+++ b/Userland/Libraries/LibWeb/HTML/HTMLFormElement.h
@@ -39,6 +39,8 @@ private:
bool m_firing_submission_events { false };
Vector<JS::GCPtr<HTMLElement>> m_associated_elements;
+
+ JS::GCPtr<DOM::HTMLCollection> mutable m_elements;
};
}
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLFormElement.idl b/Userland/Libraries/LibWeb/HTML/HTMLFormElement.idl
index 9be32481e1..d282712987 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLFormElement.idl
+++ b/Userland/Libraries/LibWeb/HTML/HTMLFormElement.idl
@@ -12,8 +12,8 @@ interface HTMLFormElement : HTMLElement {
undefined submit();
- // FIXME: Should be [SameObject] and a HTMLFormControlsCollection
- readonly attribute HTMLCollection elements;
+ // FIXME: Should be a HTMLFormControlsCollection
+ [SameObject] readonly attribute HTMLCollection elements;
readonly attribute unsigned long length;