1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-25 22:35:07 +00:00

LibWeb: Make Node.childNodes vend the same NodeList every time

This commit is contained in:
Andreas Kling 2022-09-21 13:49:31 +02:00
parent 4814e1bd65
commit a5bb30d2ba
2 changed files with 9 additions and 5 deletions

View file

@ -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