mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-24 13:35:12 +00:00
LibWeb: Implement ParentNode.replaceChildren
This commit is contained in:
parent
34dfdc3f37
commit
d1bc9358c1
Notes:
sideshowbarker
2024-07-17 19:56:24 +09:00
Author: https://github.com/Lubrsi Commit: https://github.com/SerenityOS/serenity/commit/d1bc9358c19 Pull-request: https://github.com/SerenityOS/serenity/pull/12208 Reviewed-by: https://github.com/awesomekling
5 changed files with 23 additions and 0 deletions
|
@ -67,6 +67,7 @@ interface Document : Node {
|
|||
|
||||
[CEReactions, Unscopable] undefined prepend((Node or DOMString)... nodes);
|
||||
[CEReactions, Unscopable] undefined append((Node or DOMString)... nodes);
|
||||
[CEReactions, Unscopable] undefined replaceChildren((Node or DOMString)... nodes);
|
||||
|
||||
Element? querySelector(DOMString selectors);
|
||||
[NewObject] NodeList querySelectorAll(DOMString selectors);
|
||||
|
|
|
@ -11,6 +11,7 @@ interface DocumentFragment : Node {
|
|||
|
||||
[CEReactions, Unscopable] undefined prepend((Node or DOMString)... nodes);
|
||||
[CEReactions, Unscopable] undefined append((Node or DOMString)... nodes);
|
||||
[CEReactions, Unscopable] undefined replaceChildren((Node or DOMString)... nodes);
|
||||
|
||||
Element? querySelector(DOMString selectors);
|
||||
[NewObject] NodeList querySelectorAll(DOMString selectors);
|
||||
|
|
|
@ -40,6 +40,7 @@ interface Element : Node {
|
|||
|
||||
[CEReactions, Unscopable] undefined prepend((Node or DOMString)... nodes);
|
||||
[CEReactions, Unscopable] undefined append((Node or DOMString)... nodes);
|
||||
[CEReactions, Unscopable] undefined replaceChildren((Node or DOMString)... nodes);
|
||||
|
||||
Element? querySelector(DOMString selectors);
|
||||
[NewObject] NodeList querySelectorAll(DOMString selectors);
|
||||
|
|
|
@ -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 this’s 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 {};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ public:
|
|||
|
||||
ExceptionOr<void> prepend(Vector<Variant<NonnullRefPtr<Node>, String>> const& nodes);
|
||||
ExceptionOr<void> append(Vector<Variant<NonnullRefPtr<Node>, String>> const& nodes);
|
||||
ExceptionOr<void> replace_children(Vector<Variant<NonnullRefPtr<Node>, String>> const& nodes);
|
||||
|
||||
protected:
|
||||
ParentNode(Document& document, NodeType type)
|
||||
|
|
Loading…
Add table
Reference in a new issue