1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 12:07:45 +00:00

LibWeb: Remove nodes from their old parent in appendChild/insertBefore

This commit is contained in:
Andreas Kling 2021-04-06 15:52:09 +02:00
parent c70e0a4f29
commit 380e688123

View file

@ -181,6 +181,8 @@ const Element* Node::parent_element() const
RefPtr<Node> Node::append_child(NonnullRefPtr<Node> node, bool notify) RefPtr<Node> Node::append_child(NonnullRefPtr<Node> node, bool notify)
{ {
if (node->parent())
node->parent()->remove_child(node);
if (&node->document() != &document()) if (&node->document() != &document())
document().adopt_node(node); document().adopt_node(node);
TreeNode<Node>::append_child(node, notify); TreeNode<Node>::append_child(node, notify);
@ -201,6 +203,8 @@ RefPtr<Node> Node::insert_before(NonnullRefPtr<Node> node, RefPtr<Node> child, b
dbgln("FIXME: Trying to insert_before() a bogus child"); dbgln("FIXME: Trying to insert_before() a bogus child");
return nullptr; return nullptr;
} }
if (node->parent())
node->parent()->remove_child(node);
if (&node->document() != &document()) if (&node->document() != &document())
document().adopt_node(node); document().adopt_node(node);
TreeNode<Node>::insert_before(node, child, notify); TreeNode<Node>::insert_before(node, child, notify);