1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 12:28:12 +00:00

LibWeb: Use a WeakPtr for DocumentFragment's "host" field

We had a reference cycle between fragments and their hosts.
This commit is contained in:
Andreas Kling 2022-03-14 12:46:14 +01:00
parent 7a82a6dfe8
commit fdb647c097
2 changed files with 12 additions and 4 deletions

View file

@ -701,7 +701,14 @@ u16 Node::compare_document_position(RefPtr<Node> other)
// https://dom.spec.whatwg.org/#concept-tree-host-including-inclusive-ancestor
bool Node::is_host_including_inclusive_ancestor_of(const Node& other) const
{
return is_inclusive_ancestor_of(other) || (is<DocumentFragment>(other.root()) && verify_cast<DocumentFragment>(other.root()).host() && is_inclusive_ancestor_of(*verify_cast<DocumentFragment>(other.root()).host().ptr()));
if (is_inclusive_ancestor_of(other))
return true;
if (is<DocumentFragment>(other.root())
&& static_cast<DocumentFragment const&>(other.root()).host()
&& is_inclusive_ancestor_of(*static_cast<DocumentFragment const&>(other.root()).host())) {
return true;
}
return false;
}
// https://dom.spec.whatwg.org/#dom-node-ownerdocument