diff --git a/Userland/Libraries/LibWeb/DOM/Node.cpp b/Userland/Libraries/LibWeb/DOM/Node.cpp index ba003535e3..c81705ab6a 100644 --- a/Userland/Libraries/LibWeb/DOM/Node.cpp +++ b/Userland/Libraries/LibWeb/DOM/Node.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -258,7 +259,7 @@ void Node::insert_before(NonnullRefPtr node, RefPtr child, bool supp { NonnullRefPtrVector nodes; if (is(*node)) - nodes = verify_cast(*node).child_nodes(); + nodes = verify_cast(*node).children_as_vector(); else nodes.append(node); @@ -591,7 +592,16 @@ ParentNode* Node::parent_or_shadow_host() return verify_cast(parent()); } -NonnullRefPtrVector Node::child_nodes() const +NonnullRefPtr 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(*this, [this](auto& node) { + return is_parent_of(node); + }); +} + +NonnullRefPtrVector Node::children_as_vector() const { NonnullRefPtrVector nodes; diff --git a/Userland/Libraries/LibWeb/DOM/Node.h b/Userland/Libraries/LibWeb/DOM/Node.h index ae21a766fd..a19bad0546 100644 --- a/Userland/Libraries/LibWeb/DOM/Node.h +++ b/Userland/Libraries/LibWeb/DOM/Node.h @@ -96,7 +96,8 @@ public: // NOTE: This is intended for the JS bindings. bool has_child_nodes() const { return has_children(); } - NonnullRefPtrVector child_nodes() const; + NonnullRefPtr child_nodes(); + NonnullRefPtrVector children_as_vector() const; virtual RefPtr create_layout_node(); diff --git a/Userland/Libraries/LibWeb/DOM/Node.idl b/Userland/Libraries/LibWeb/DOM/Node.idl index a1a15d6baa..619164e8d7 100644 --- a/Userland/Libraries/LibWeb/DOM/Node.idl +++ b/Userland/Libraries/LibWeb/DOM/Node.idl @@ -4,8 +4,7 @@ interface Node : EventTarget { readonly attribute DOMString nodeName; boolean hasChildNodes(); - // FIXME: This should be a NodeList - readonly attribute ArrayFromVector childNodes; + [SameObject] readonly attribute NodeList childNodes; readonly attribute Node? firstChild; readonly attribute Node? lastChild; readonly attribute Node? previousSibling;