summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-03-22 21:10:59 +0100
committerAndreas Kling <kling@serenityos.org>2022-03-23 00:19:57 +0100
commita0b0b29fa18f36b0949be7d0367ad88d85d62ba3 (patch)
tree9bf13d2668287f4606e18fda9588def8d27e0fbb
parentccee8953d0c61b6497f00d96fa233dfa218d738d (diff)
downloadserenity-a0b0b29fa18f36b0949be7d0367ad88d85d62ba3.zip
LibWeb: Minor cleanups in NodeIterator and TreeWalker
- Use TRY() when invoking the NodeFilter - Say "nullptr" instead of "RefPtr<Node> {}"
-rw-r--r--Userland/Libraries/LibWeb/DOM/NodeIterator.cpp12
-rw-r--r--Userland/Libraries/LibWeb/DOM/TreeWalker.cpp8
2 files changed, 8 insertions, 12 deletions
diff --git a/Userland/Libraries/LibWeb/DOM/NodeIterator.cpp b/Userland/Libraries/LibWeb/DOM/NodeIterator.cpp
index 310cf60431..21a0c455e9 100644
--- a/Userland/Libraries/LibWeb/DOM/NodeIterator.cpp
+++ b/Userland/Libraries/LibWeb/DOM/NodeIterator.cpp
@@ -71,7 +71,7 @@ JS::ThrowCompletionOr<RefPtr<Node>> NodeIterator::traverse(Direction direction)
if (!before_node) {
auto* next_node = node->next_in_pre_order(m_root.ptr());
if (!next_node)
- return RefPtr<Node> {};
+ return nullptr;
node = *next_node;
} else {
// If beforeNode is true, then set it to false.
@@ -86,7 +86,7 @@ JS::ThrowCompletionOr<RefPtr<Node>> NodeIterator::traverse(Direction direction)
return nullptr;
auto* previous_node = node->previous_in_pre_order();
if (!previous_node)
- return RefPtr<Node> {};
+ return nullptr;
node = *previous_node;
} else {
// If beforeNode is false, then set it to true.
@@ -95,12 +95,10 @@ JS::ThrowCompletionOr<RefPtr<Node>> NodeIterator::traverse(Direction direction)
}
// 2. Let result be the result of filtering node within iterator.
- auto result = filter(*node);
- if (result.is_throw_completion())
- return result.release_error();
+ auto result = TRY(filter(*node));
// 3. If result is FILTER_ACCEPT, then break.
- if (result.value() == NodeFilter::FILTER_ACCEPT)
+ if (result == NodeFilter::FILTER_ACCEPT)
break;
}
@@ -111,7 +109,7 @@ JS::ThrowCompletionOr<RefPtr<Node>> NodeIterator::traverse(Direction direction)
m_pointer_before_reference = before_node;
// 6. Return node.
- return RefPtr<Node> { node };
+ return node;
}
// https://dom.spec.whatwg.org/#concept-node-filter
diff --git a/Userland/Libraries/LibWeb/DOM/TreeWalker.cpp b/Userland/Libraries/LibWeb/DOM/TreeWalker.cpp
index 4649bfcb20..42958541d3 100644
--- a/Userland/Libraries/LibWeb/DOM/TreeWalker.cpp
+++ b/Userland/Libraries/LibWeb/DOM/TreeWalker.cpp
@@ -65,17 +65,15 @@ JS::ThrowCompletionOr<RefPtr<Node>> TreeWalker::parent_node()
// 2. If node is non-null and filtering node within this returns FILTER_ACCEPT,
// then set thisโ€™s current to node and return node.
if (node) {
- auto result = filter(*node);
- if (result.is_throw_completion())
- return result.release_error();
- if (result.value() == NodeFilter::FILTER_ACCEPT) {
+ auto result = TRY(filter(*node));
+ if (result == NodeFilter::FILTER_ACCEPT) {
m_current = *node;
return node;
}
}
}
- return RefPtr<Node> {};
+ return nullptr;
}
// https://dom.spec.whatwg.org/#dom-treewalker-firstchild