1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-10 10:01:13 +09:00

LibWeb: Make sure nodes are adopted when moving between documents

Otherwise, the "referencing node count" accounting won't be accurate,
and anything that accesses the document will be confused.
This commit is contained in:
Andreas Kling 2020-10-22 23:37:17 +02:00
parent c67b45aa1f
commit 018b458962
Notes: sideshowbarker 2024-07-19 01:47:58 +09:00

View file

@ -170,6 +170,8 @@ const Element* Node::parent_element() const
RefPtr<Node> Node::append_child(NonnullRefPtr<Node> node, bool notify)
{
if (&node->document() != &document())
document().adopt_node(node);
TreeNode<Node>::append_child(node, notify);
return node;
}
@ -182,6 +184,8 @@ RefPtr<Node> Node::insert_before(NonnullRefPtr<Node> node, RefPtr<Node> child, b
dbg() << "FIXME: Trying to insert_before() a bogus child";
return nullptr;
}
if (&node->document() != &document())
document().adopt_node(node);
TreeNode<Node>::insert_before(node, child, notify);
return node;
}
@ -195,6 +199,10 @@ void Node::remove_all_children()
void Node::set_document(Badge<Document>, Document& document)
{
if (m_document == &document)
return;
document.ref_from_node({});
m_document->unref_from_node({});
m_document = &document;
}