From 63579d4b75a6a79d0667027a105bcfe671535150 Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Tue, 13 Aug 2024 17:51:39 +0200 Subject: [PATCH] [mujs] Modified Element.closest --- src/ecmascript/mujs/element.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/ecmascript/mujs/element.c b/src/ecmascript/mujs/element.c index 68796b7e8..9708a9a74 100644 --- a/src/ecmascript/mujs/element.c +++ b/src/ecmascript/mujs/element.c @@ -2493,6 +2493,13 @@ mjs_element_closest(js_State *J) return; } + if (el) { +#ifdef ECMASCRIPT_DEBUG +fprintf(stderr, "Before: %s:%d\n", __FUNCTION__, __LINE__); +#endif + dom_node_ref(el); + } + while (el) { res = el_match_selector(selector, el); @@ -2504,9 +2511,14 @@ mjs_element_closest(js_State *J) } dom_node *node = NULL; exc = dom_node_get_parent_node(el, &node); + if (exc != DOM_NO_ERR || !node) { break; } +#ifdef ECMASCRIPT_DEBUG +fprintf(stderr, "Before: %s:%d\n", __FUNCTION__, __LINE__); +#endif + dom_node_unref(el); el = node; } #ifdef ECMASCRIPT_DEBUG @@ -2514,6 +2526,13 @@ fprintf(stderr, "Before: %s:%d\n", __FUNCTION__, __LINE__); #endif dom_node_unref(root); + if (el) { +#ifdef ECMASCRIPT_DEBUG +fprintf(stderr, "Before: %s:%d\n", __FUNCTION__, __LINE__); +#endif + dom_node_unref(el); + } + if (!res) { js_pushnull(J); return;