diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.cpp
index e19956c5537..aa44d76d9ff 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.cpp
+++ b/Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.cpp
@@ -23,17 +23,24 @@ HTMLTableRowElement::HTMLTableRowElement(DOM::Document& document, DOM::Qualified
HTMLTableRowElement::~HTMLTableRowElement() = default;
+void HTMLTableRowElement::visit_edges(Cell::Visitor& visitor)
+{
+ Base::visit_edges(visitor);
+ visitor.visit(m_cells);
+}
+
// https://html.spec.whatwg.org/multipage/tables.html#dom-tr-cells
JS::NonnullGCPtr HTMLTableRowElement::cells() const
{
// The cells attribute must return an HTMLCollection rooted at this tr element,
// whose filter matches only td and th elements that are children of the tr element.
- // FIXME: This should return the same HTMLCollection object every time,
- // but that would cause a reference cycle since HTMLCollection refs the root.
- return DOM::HTMLCollection::create(const_cast(*this), [this](Element const& element) {
- return element.parent() == this
- && is(element);
- });
+ if (!m_cells) {
+ m_cells = DOM::HTMLCollection::create(const_cast(*this), [this](Element const& element) {
+ return element.parent() == this
+ && is(element);
+ });
+ }
+ return *m_cells;
}
// https://html.spec.whatwg.org/multipage/tables.html#dom-tr-rowindex
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.h b/Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.h
index 64d386889bf..1ee1b10f1dd 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.h
+++ b/Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.h
@@ -25,6 +25,10 @@ public:
private:
HTMLTableRowElement(DOM::Document&, DOM::QualifiedName);
+
+ virtual void visit_edges(Cell::Visitor&) override;
+
+ JS::GCPtr mutable m_cells;
};
}