1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-02 23:42:13 +00:00

LibWeb: Implement ParentNode.replaceChildren

This commit is contained in:
Luke Wilde 2022-01-29 21:01:09 +00:00 committed by Andreas Kling
parent 34dfdc3f37
commit d1bc9358c1
5 changed files with 23 additions and 0 deletions

View file

@ -191,4 +191,23 @@ ExceptionOr<void> ParentNode::append(Vector<Variant<NonnullRefPtr<Node>, String>
return {};
}
ExceptionOr<void> ParentNode::replace_children(Vector<Variant<NonnullRefPtr<Node>, String>> const& nodes)
{
// 1. Let node be the result of converting nodes into a node given nodes and thiss node document.
auto node_or_exception = convert_nodes_to_single_node(nodes, document());
if (node_or_exception.is_exception())
return node_or_exception.exception();
auto node = node_or_exception.release_value();
// 2. Ensure pre-insertion validity of node into this before null.
auto validity_exception = ensure_pre_insertion_validity(node, nullptr);
if (validity_exception.is_exception())
return validity_exception.exception();
// 3. Replace all with node within this.
replace_all(node);
return {};
}
}