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

LibWeb: Implement ParentNode.append

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

View file

@ -66,6 +66,7 @@ interface Document : Node {
readonly attribute unsigned long childElementCount;
[CEReactions, Unscopable] undefined prepend((Node or DOMString)... nodes);
[CEReactions, Unscopable] undefined append((Node or DOMString)... nodes);
Element? querySelector(DOMString selectors);
[NewObject] NodeList querySelectorAll(DOMString selectors);

View file

@ -10,6 +10,7 @@ interface DocumentFragment : Node {
readonly attribute unsigned long childElementCount;
[CEReactions, Unscopable] undefined prepend((Node or DOMString)... nodes);
[CEReactions, Unscopable] undefined append((Node or DOMString)... nodes);
Element? querySelector(DOMString selectors);
[NewObject] NodeList querySelectorAll(DOMString selectors);

View file

@ -39,6 +39,7 @@ interface Element : Node {
readonly attribute unsigned long childElementCount;
[CEReactions, Unscopable] undefined prepend((Node or DOMString)... nodes);
[CEReactions, Unscopable] undefined append((Node or DOMString)... nodes);
Element? querySelector(DOMString selectors);
[NewObject] NodeList querySelectorAll(DOMString selectors);

View file

@ -174,4 +174,21 @@ ExceptionOr<void> ParentNode::prepend(Vector<Variant<NonnullRefPtr<Node>, String
return {};
}
ExceptionOr<void> ParentNode::append(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. Append node to this.
auto result = append_child(node);
if (result.is_exception())
return result.exception();
return {};
}
}

View file

@ -31,6 +31,7 @@ public:
NonnullRefPtr<HTMLCollection> get_elements_by_tag_name_ns(FlyString const&, FlyString const&);
ExceptionOr<void> prepend(Vector<Variant<NonnullRefPtr<Node>, String>> const& nodes);
ExceptionOr<void> append(Vector<Variant<NonnullRefPtr<Node>, String>> const& nodes);
protected:
ParentNode(Document& document, NodeType type)