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

LibWeb: Make NodeFilter::Result an enum class

This commit is contained in:
Sam Atkins 2023-01-27 13:22:36 +00:00 committed by Linus Groh
parent a078fad787
commit 27d4912f12
3 changed files with 19 additions and 19 deletions

View file

@ -81,7 +81,7 @@ JS::ThrowCompletionOr<JS::GCPtr<Node>> TreeWalker::parent_node()
// then set thiss current to node and return node.
if (node) {
auto result = TRY(filter(*node));
if (result == NodeFilter::FILTER_ACCEPT) {
if (result == NodeFilter::Result::FILTER_ACCEPT) {
m_current = *node;
return node;
}
@ -135,7 +135,7 @@ JS::ThrowCompletionOr<JS::GCPtr<Node>> TreeWalker::previous_node()
auto result = TRY(filter(*node));
// 3. While result is not FILTER_REJECT and node has a child:
while (result != NodeFilter::FILTER_REJECT && node->has_children()) {
while (result != NodeFilter::Result::FILTER_REJECT && node->has_children()) {
// 1. Set node to nodes last child.
node = *node->last_child();
@ -144,7 +144,7 @@ JS::ThrowCompletionOr<JS::GCPtr<Node>> TreeWalker::previous_node()
}
// 4. If result is FILTER_ACCEPT, then set thiss current to node and return node.
if (result == NodeFilter::FILTER_ACCEPT) {
if (result == NodeFilter::Result::FILTER_ACCEPT) {
m_current = node;
return node;
}
@ -161,7 +161,7 @@ JS::ThrowCompletionOr<JS::GCPtr<Node>> TreeWalker::previous_node()
node = *node->parent();
// 5. If the return value of filtering node within this is FILTER_ACCEPT, then set thiss current to node and return node.
if (TRY(filter(*node)) == NodeFilter::FILTER_ACCEPT) {
if (TRY(filter(*node)) == NodeFilter::Result::FILTER_ACCEPT) {
m_current = node;
return node;
}
@ -177,12 +177,12 @@ JS::ThrowCompletionOr<JS::GCPtr<Node>> TreeWalker::next_node()
JS::NonnullGCPtr<Node> node = m_current;
// 2. Let result be FILTER_ACCEPT.
auto result = NodeFilter::FILTER_ACCEPT;
auto result = NodeFilter::Result::FILTER_ACCEPT;
// 3. While true:
while (true) {
// 1. While result is not FILTER_REJECT and node has a child:
while (result != NodeFilter::FILTER_REJECT && node->has_children()) {
while (result != NodeFilter::Result::FILTER_REJECT && node->has_children()) {
// 1. Set node to its first child.
node = *node->first_child();
@ -190,7 +190,7 @@ JS::ThrowCompletionOr<JS::GCPtr<Node>> TreeWalker::next_node()
result = TRY(filter(*node));
// 3. If result is FILTER_ACCEPT, then set thiss current to node and return node.
if (result == NodeFilter::FILTER_ACCEPT) {
if (result == NodeFilter::Result::FILTER_ACCEPT) {
m_current = *node;
return node;
}
@ -225,7 +225,7 @@ JS::ThrowCompletionOr<JS::GCPtr<Node>> TreeWalker::next_node()
result = TRY(filter(*node));
// 6. If result is FILTER_ACCEPT, then set thiss current to node and return node.
if (result == NodeFilter::FILTER_ACCEPT) {
if (result == NodeFilter::Result::FILTER_ACCEPT) {
m_current = *node;
return node;
}
@ -244,11 +244,11 @@ JS::ThrowCompletionOr<NodeFilter::Result> TreeWalker::filter(Node& node)
// 3. If the nth bit (where 0 is the least significant bit) of traversers whatToShow is not set, then return FILTER_SKIP.
if (!(m_what_to_show & (1u << n)))
return NodeFilter::FILTER_SKIP;
return NodeFilter::Result::FILTER_SKIP;
// 4. If traversers filter is null, then return FILTER_ACCEPT.
if (!m_filter)
return NodeFilter::FILTER_ACCEPT;
return NodeFilter::Result::FILTER_ACCEPT;
// 5. Set traversers active flag.
m_active = true;
@ -284,13 +284,13 @@ JS::ThrowCompletionOr<JS::GCPtr<Node>> TreeWalker::traverse_children(ChildTraver
auto result = TRY(filter(*node));
// 2. If result is FILTER_ACCEPT, then set walkers current to node and return node.
if (result == NodeFilter::FILTER_ACCEPT) {
if (result == NodeFilter::Result::FILTER_ACCEPT) {
m_current = *node;
return node;
}
// 3. If result is FILTER_SKIP, then:
if (result == NodeFilter::FILTER_SKIP) {
if (result == NodeFilter::Result::FILTER_SKIP) {
// 1. Let child be nodes first child if type is first, and nodes last child if type is last.
JS::GCPtr<Node> child = type == ChildTraversalType::First ? node->first_child() : node->last_child();
@ -352,7 +352,7 @@ JS::ThrowCompletionOr<JS::GCPtr<Node>> TreeWalker::traverse_siblings(SiblingTrav
auto result = TRY(filter(*node));
// 3. If result is FILTER_ACCEPT, then set walkers current to node and return node.
if (result == NodeFilter::FILTER_ACCEPT) {
if (result == NodeFilter::Result::FILTER_ACCEPT) {
m_current = *node;
return node;
}
@ -361,7 +361,7 @@ JS::ThrowCompletionOr<JS::GCPtr<Node>> TreeWalker::traverse_siblings(SiblingTrav
sibling = type == SiblingTraversalType::Next ? node->first_child() : node->last_child();
// 5. If result is FILTER_REJECT or sibling is null, then set sibling to nodes next sibling if type is next, and nodes previous sibling if type is previous.
if (result == NodeFilter::FILTER_REJECT || !sibling)
if (result == NodeFilter::Result::FILTER_REJECT || !sibling)
sibling = type == SiblingTraversalType::Next ? node->next_sibling() : node->previous_sibling();
}
@ -373,7 +373,7 @@ JS::ThrowCompletionOr<JS::GCPtr<Node>> TreeWalker::traverse_siblings(SiblingTrav
return nullptr;
// 5. If the return value of filtering node within walker is FILTER_ACCEPT, then return null.
if (TRY(filter(*node)) == NodeFilter::FILTER_ACCEPT)
if (TRY(filter(*node)) == NodeFilter::Result::FILTER_ACCEPT)
return nullptr;
}
}