diff options
author | Luke Wilde <lukew@serenityos.org> | 2022-01-29 20:45:17 +0000 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-01-31 15:25:36 +0100 |
commit | 34dfdc3f37324ab346bb4feb9b15ca99b5d4fca5 (patch) | |
tree | eb58a5d345b6e95c844cae6e69656e27e5cd0860 /Userland | |
parent | d5c96c3ccf6cc7bacf865d158ab23c040704f50e (diff) | |
download | serenity-34dfdc3f37324ab346bb4feb9b15ca99b5d4fca5.zip |
LibWeb: Implement ParentNode.append
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibWeb/DOM/Document.idl | 1 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/DOM/DocumentFragment.idl | 1 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/DOM/Element.idl | 1 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/DOM/ParentNode.cpp | 17 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/DOM/ParentNode.h | 1 |
5 files changed, 21 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/DOM/Document.idl b/Userland/Libraries/LibWeb/DOM/Document.idl index c5229063f0..173b73cca7 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.idl +++ b/Userland/Libraries/LibWeb/DOM/Document.idl @@ -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); diff --git a/Userland/Libraries/LibWeb/DOM/DocumentFragment.idl b/Userland/Libraries/LibWeb/DOM/DocumentFragment.idl index 938e05e9e9..5309a72957 100644 --- a/Userland/Libraries/LibWeb/DOM/DocumentFragment.idl +++ b/Userland/Libraries/LibWeb/DOM/DocumentFragment.idl @@ -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); diff --git a/Userland/Libraries/LibWeb/DOM/Element.idl b/Userland/Libraries/LibWeb/DOM/Element.idl index c796cdd9c8..66da1ec84f 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.idl +++ b/Userland/Libraries/LibWeb/DOM/Element.idl @@ -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); diff --git a/Userland/Libraries/LibWeb/DOM/ParentNode.cpp b/Userland/Libraries/LibWeb/DOM/ParentNode.cpp index 24d8675ea9..b2587bb396 100644 --- a/Userland/Libraries/LibWeb/DOM/ParentNode.cpp +++ b/Userland/Libraries/LibWeb/DOM/ParentNode.cpp @@ -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 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. Append node to this. + auto result = append_child(node); + if (result.is_exception()) + return result.exception(); + + return {}; +} + } diff --git a/Userland/Libraries/LibWeb/DOM/ParentNode.h b/Userland/Libraries/LibWeb/DOM/ParentNode.h index feaa1a73c8..e3ee6abf08 100644 --- a/Userland/Libraries/LibWeb/DOM/ParentNode.h +++ b/Userland/Libraries/LibWeb/DOM/ParentNode.h @@ -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) |