diff options
author | John-Mark Bell <jmb@netsurf-browser.org> | 2024-01-21 22:58:44 +0000 |
---|---|---|
committer | John-Mark Bell <jmb@netsurf-browser.org> | 2024-01-21 22:58:44 +0000 |
commit | abd621e972cfac28d2e4d9184c059df7d310aeae (patch) | |
tree | dd6aaba3a79aabdf639afdbddcd81b8533a94421 | |
parent | 0aeccbf5125c4554cc651453beceb4a3d2551de8 (diff) | |
download | netsurf-abd621e972cfac28d2e4d9184c059df7d310aeae.tar.gz netsurf-abd621e972cfac28d2e4d9184c059df7d310aeae.tar.bz2 |
HTML: rework iterators
-rw-r--r-- | content/handlers/html/box/manager.c | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/content/handlers/html/box/manager.c b/content/handlers/html/box/manager.c index 6d558e41e..c70e747bf 100644 --- a/content/handlers/html/box/manager.c +++ b/content/handlers/html/box/manager.c @@ -189,24 +189,29 @@ _find_parent_element_or_document(dom_node *target) do { exc = dom_node_get_parent_node(target, &parent); dom_node_unref(target); + target = NULL; + if (exc == DOM_NO_ERR && parent != NULL) { dom_node_type node_type; - exc = dom_node_get_node_type(parent, &node_type); + + target = parent; + parent = NULL; + + exc = dom_node_get_node_type(target, &node_type); if (exc == DOM_NO_ERR && (node_type == DOM_ELEMENT_NODE || node_type == DOM_DOCUMENT_NODE)) { break; } - target = parent; } - } while (exc == DOM_NO_ERR && parent != NULL); + } while (exc == DOM_NO_ERR && target != NULL); if (exc != DOM_NO_ERR) { - dom_node_unref(parent); - parent = NULL; + dom_node_unref(target); + target = NULL; } - return parent; + return target; } static dom_exception @@ -216,22 +221,25 @@ _foreach_element_sibling(dom_node *cur, dom_node *sibling = NULL; dom_exception exc; + /* Take ref on cur (we'll release it in the loop) */ dom_node_ref(cur); do { exc = dom_node_get_next_sibling(cur, &sibling); dom_node_unref(cur); - cur = sibling; - sibling = NULL; + cur = NULL; - if (exc == DOM_NO_ERR && cur != NULL) { + if (exc == DOM_NO_ERR && sibling != NULL) { dom_node_type sibling_type; - exc = dom_node_get_node_type(cur, &sibling_type); + exc = dom_node_get_node_type(sibling, &sibling_type); if (exc == DOM_NO_ERR && sibling_type == DOM_ELEMENT_NODE) { - exc = cb(cur, pw); + exc = cb(sibling, pw); } + + cur = sibling; + sibling = NULL; } } while (exc == DOM_NO_ERR && cur != NULL); |