diff options
author | Andreas Kling <kling@serenityos.org> | 2022-09-21 13:49:31 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-09-21 13:51:58 +0200 |
commit | a5bb30d2ba1a052b5af63c5d83960d15c1ab739c (patch) | |
tree | 8420f0f86f9d00632debf981f08f1303cb6935ee | |
parent | 4814e1bd650adf151f6f4c76d752a5a956e1f332 (diff) | |
download | serenity-a5bb30d2ba1a052b5af63c5d83960d15c1ab739c.zip |
LibWeb: Make Node.childNodes vend the same NodeList every time
-rw-r--r-- | Userland/Libraries/LibWeb/DOM/Node.cpp | 12 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/DOM/Node.h | 2 |
2 files changed, 9 insertions, 5 deletions
diff --git a/Userland/Libraries/LibWeb/DOM/Node.cpp b/Userland/Libraries/LibWeb/DOM/Node.cpp index 3f880e343a..2571697c38 100644 --- a/Userland/Libraries/LibWeb/DOM/Node.cpp +++ b/Userland/Libraries/LibWeb/DOM/Node.cpp @@ -90,6 +90,7 @@ void Node::visit_edges(Cell::Visitor& visitor) visitor.visit(m_last_child.ptr()); visitor.visit(m_next_sibling.ptr()); visitor.visit(m_previous_sibling.ptr()); + visitor.visit(m_child_nodes); for (auto& registered_observer : m_registered_observer_list) visitor.visit(registered_observer); @@ -861,11 +862,12 @@ ParentNode* Node::parent_or_shadow_host() JS::NonnullGCPtr<NodeList> Node::child_nodes() { - // FIXME: This should return the same LiveNodeList object every time, - // but that would cause a reference cycle since NodeList refs the root. - return LiveNodeList::create(window(), *this, [this](auto& node) { - return is_parent_of(node); - }); + if (!m_child_nodes) { + m_child_nodes = LiveNodeList::create(window(), *this, [this](auto& node) { + return is_parent_of(node); + }); + } + return *m_child_nodes; } Vector<JS::Handle<Node>> Node::children_as_vector() const diff --git a/Userland/Libraries/LibWeb/DOM/Node.h b/Userland/Libraries/LibWeb/DOM/Node.h index dcc1088192..0068e849f0 100644 --- a/Userland/Libraries/LibWeb/DOM/Node.h +++ b/Userland/Libraries/LibWeb/DOM/Node.h @@ -648,6 +648,8 @@ private: JS::GCPtr<Node> m_last_child; JS::GCPtr<Node> m_next_sibling; JS::GCPtr<Node> m_previous_sibling; + + JS::GCPtr<NodeList> m_child_nodes; }; } |