1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 14:38:11 +00:00

LibWeb: Implement ParentNode.prepend

`convert_nodes_to_single_node` is inside its own file so ChildNode can
include and use it without having to include other headers such as
DOM/Node.h. This is to prevent circular includes.
This commit is contained in:
Luke Wilde 2022-01-29 20:23:48 +00:00 committed by Andreas Kling
parent d7998c5dbd
commit d5c96c3ccf
9 changed files with 92 additions and 2 deletions

View file

@ -7,6 +7,7 @@
#include <LibWeb/CSS/Parser/Parser.h>
#include <LibWeb/CSS/SelectorEngine.h>
#include <LibWeb/DOM/HTMLCollection.h>
#include <LibWeb/DOM/NodeOperations.h>
#include <LibWeb/DOM/ParentNode.h>
#include <LibWeb/DOM/StaticNodeList.h>
#include <LibWeb/Dump.h>
@ -155,4 +156,22 @@ NonnullRefPtr<HTMLCollection> ParentNode::get_elements_by_tag_name_ns(FlyString
});
}
// https://dom.spec.whatwg.org/#dom-parentnode-prepend
ExceptionOr<void> ParentNode::prepend(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. Pre-insert node into this before thiss first child.
auto result = pre_insert(node, first_child());
if (result.is_exception())
return result.exception();
return {};
}
}