Add missing validation to Range.comparePoint

Also re-order the validation to match what  WPT expects. Fixes all cases in
dom/ranges/Range-comparePoint.html
This commit is contained in:
Karl Seguin
2026-02-13 14:54:43 +08:00
parent d91bec08c3
commit da1eb71ad0

View File

@@ -186,10 +186,6 @@ pub fn compareBoundaryPoints(self: *const Range, how_raw: i32, source_range: *co
}
pub fn comparePoint(self: *const Range, node: *Node, offset: u32) !i16 {
if (offset > node.getLength()) {
return error.IndexSizeError;
}
// Check if node is in a different tree than the range
const node_root = node.getRootNode(null);
const start_root = self._proto._start_container.getRootNode(null);
@@ -197,6 +193,14 @@ pub fn comparePoint(self: *const Range, node: *Node, offset: u32) !i16 {
return error.WrongDocument;
}
if (node._type == .document_type) {
return error.InvalidNodeType;
}
if (offset > node.getLength()) {
return error.IndexSizeError;
}
// Compare point with start boundary
const cmp_start = AbstractRange.compareBoundaryPoints(
node,