Web Inspector: Uncaught Exception: TypeError: undefined is not an object (evaluating 'node.endPosition.isBefore')
https://bugs.webkit.org/show_bug.cgi?id=294183

Reviewed by BJ Burg.

* Source/WebInspectorUI/UserInterface/Models/ScriptSyntaxTree.js:
(WI.ScriptSyntaxTree.prototype.containersOfPosition):
(WI.ScriptSyntaxTree.prototype.filterByRange):
If it's possible for `node.endPosition` to not exist then don't assume it does.

Canonical link: https://commits.webkit.org/296072@main
diff --git a/Source/WebInspectorUI/UserInterface/Models/ScriptSyntaxTree.js b/Source/WebInspectorUI/UserInterface/Models/ScriptSyntaxTree.js
index 9863085..d6cc87a 100644
--- a/Source/WebInspectorUI/UserInterface/Models/ScriptSyntaxTree.js
+++ b/Source/WebInspectorUI/UserInterface/Models/ScriptSyntaxTree.js
@@ -88,9 +88,9 @@
         let allNodes = [];
 
         this.forEachNode((node, state) => {
-            if (node.endPosition.isBefore(position))
+            if (node.endPosition?.isBefore(position))
                 state.skipChildNodes = true;
-            else if (node.startPosition.isAfter(position))
+            else if (node.startPosition?.isAfter(position))
                 state.shouldStopEarly = true;
             else
                 allNodes.push(node);
@@ -114,13 +114,13 @@
 
             // If a node's range ends before the range we're interested in starts, we don't need to search any of its
             // enclosing ranges, because, by definition, those enclosing ranges are contained within this node's range.
-            if (node.endPosition.isBefore(startPosition)) {
+            if (node.endPosition?.isBefore(startPosition)) {
                 state.skipChildNodes = true;
                 return;
             }
 
             // We are only interested in nodes whose start position is within our range.
-            if (node.startPosition.isWithin(startPosition, endPosition)) {
+            if (node.startPosition?.isWithin(startPosition, endPosition)) {
                 allNodes.push(node);
                 return;
             }
@@ -128,7 +128,7 @@
             // Once we see nodes that start beyond our range, we can quit traversing the AST. We can do this safely
             // because we know the AST is traversed using depth first search, so it will traverse into enclosing ranges
             // before it traverses into adjacent ranges.
-            if (node.startPosition.isAfter(endPosition))
+            if (node.startPosition?.isAfter(endPosition))
                 state.shouldStopEarly = true;
         }