mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 15:12:45 +00:00 
			
		
		
		
	LibWeb: Minor cleanups in NodeIterator and TreeWalker
- Use TRY() when invoking the NodeFilter
- Say "nullptr" instead of "RefPtr<Node> {}"
			
			
This commit is contained in:
		
							parent
							
								
									ccee8953d0
								
							
						
					
					
						commit
						a0b0b29fa1
					
				
					 2 changed files with 8 additions and 12 deletions
				
			
		|  | @ -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
 | ||||
|  |  | |||
|  | @ -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
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling