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

LibWeb: Convert ParentNode to use TRY for error propagation

This commit is contained in:
Linus Groh 2022-03-22 12:39:49 +00:00
parent 8d20fb1e94
commit a68d31debd

View file

@ -160,16 +160,10 @@ NonnullRefPtr<HTMLCollection> ParentNode::get_elements_by_tag_name_ns(FlyString
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();
auto node = TRY(convert_nodes_to_single_node(nodes, document()));
// 2. Pre-insert node into this before thiss first child.
auto result = pre_insert(node, first_child());
if (result.is_exception())
return result.exception();
(void)TRY(pre_insert(node, first_child()));
return {};
}
@ -177,16 +171,10 @@ ExceptionOr<void> ParentNode::prepend(Vector<Variant<NonnullRefPtr<Node>, String
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();
auto node = TRY(convert_nodes_to_single_node(nodes, document()));
// 2. Append node to this.
auto result = append_child(node);
if (result.is_exception())
return result.exception();
(void)TRY(append_child(node));
return {};
}
@ -194,16 +182,10 @@ ExceptionOr<void> ParentNode::append(Vector<Variant<NonnullRefPtr<Node>, String>
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();
auto node = TRY(convert_nodes_to_single_node(nodes, document()));
// 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();
TRY(ensure_pre_insertion_validity(node, nullptr));
// 3. Replace all with node within this.
replace_all(node);