From 9b923c550bd8170409c7d76580d95e565d89988c Mon Sep 17 00:00:00 2001 From: Pierre Tachoire Date: Thu, 16 Nov 2023 17:20:41 +0100 Subject: [PATCH] dom: remove unreachable from html collection --- src/dom/html_collection.zig | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/dom/html_collection.zig b/src/dom/html_collection.zig index b388032b..10a4210c 100644 --- a/src/dom/html_collection.zig +++ b/src/dom/html_collection.zig @@ -47,14 +47,21 @@ pub const HTMLCollection = struct { } // TODO deinit parent - var parent = parser.nodeParentNode(cur) orelse unreachable; + // Back to the parent of cur. + // If cur has no parent, then the iteration is over. + var parent = parser.nodeParentNode(cur) orelse return null; + // TODO deinit lastchild var lastchild = parser.nodeLastChild(parent); var prev = cur; while (prev != root and prev == lastchild) { prev = parent; + // TODO deinit parent - parent = parser.nodeParentNode(cur) orelse unreachable; + // Back to the prev's parent. + // If prev has no parent, then the loop must stop. + parent = parser.nodeParentNode(cur) orelse break; + // TODO deinit lastchild lastchild = parser.nodeLastChild(parent); }