From 7d8ff0c58182c8f06ecbc911d49780796cd37db1 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 24 Nov 2022 19:03:22 +0100 Subject: [PATCH] LibWeb: Implement [SameObject] behavior for HTMLTableRowElement.cells --- .../LibWeb/HTML/HTMLTableRowElement.cpp | 19 +++++++++++++------ .../LibWeb/HTML/HTMLTableRowElement.h | 4 ++++ 2 files changed, 17 insertions(+), 6 deletions(-) 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; }; }