Skip to content

Commit

Permalink
LibWeb: Implement Node.removeChild() in terms of "pre-remove"
Browse files Browse the repository at this point in the history
This is what the spec wants us to do.
  • Loading branch information
awesomekling committed Feb 21, 2022
1 parent 8b2499b commit 19b5033
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 7 additions & 1 deletion Userland/Libraries/LibWeb/DOM/Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,12 @@ ExceptionOr<NonnullRefPtr<Node>> Node::pre_insert(NonnullRefPtr<Node> node, RefP
return node;
}

// https://dom.spec.whatwg.org/#dom-node-removechild
ExceptionOr<NonnullRefPtr<Node>> Node::remove_child(NonnullRefPtr<Node> child)
{
return pre_remove(child);
}

// https://dom.spec.whatwg.org/#concept-node-pre-remove
ExceptionOr<NonnullRefPtr<Node>> Node::pre_remove(NonnullRefPtr<Node> child)
{
Expand Down Expand Up @@ -383,7 +389,7 @@ void Node::remove(bool suppress_observers)
// FIXME: Let oldPreviousSibling be node’s previous sibling. (Currently unused so not included)
// FIXME: Let oldNextSibling be node’s next sibling. (Currently unused so not included)

parent->remove_child(*this);
parent->TreeNode::remove_child(*this);

// FIXME: If node is assigned, then run assign slottables for node’s assigned slot.

Expand Down
2 changes: 2 additions & 0 deletions Userland/Libraries/LibWeb/DOM/Node.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ class Node
ExceptionOr<NonnullRefPtr<Node>> pre_remove(NonnullRefPtr<Node>);

ExceptionOr<NonnullRefPtr<Node>> append_child(NonnullRefPtr<Node>);
ExceptionOr<NonnullRefPtr<Node>> remove_child(NonnullRefPtr<Node>);

void insert_before(NonnullRefPtr<Node> node, RefPtr<Node> child, bool suppress_observers = false);
void remove(bool suppress_observers = false);
void remove_all_children(bool suppress_observers = false);
Expand Down

0 comments on commit 19b5033

Please sign in to comment.