From e6c99cfc1a07a654e104fa584a972aec7f9ba7f7 Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Sat, 6 Jul 2024 12:27:30 +0200 Subject: [PATCH] [quickjs] Fix in element.remove --- src/ecmascript/quickjs/element.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/ecmascript/quickjs/element.c b/src/ecmascript/quickjs/element.c index b7a55393e..8a7cfe21c 100644 --- a/src/ecmascript/quickjs/element.c +++ b/src/ecmascript/quickjs/element.c @@ -3444,27 +3444,27 @@ js_element_remove(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); #endif REF_JS(this_val); - -// TODO - -#if 0 - - if (argc != 0) { -#ifdef ECMASCRIPT_DEBUG - fprintf(stderr, "%s:%s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - return JS_UNDEFINED; - } struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx); - xmlpp::Element *el = static_cast(js_getopaque(this_val, js_element_class_id)); + dom_node *el = (dom_node *)(js_getopaque(this_val, js_element_class_id)); + dom_node *parent = NULL; + dom_exception exc; if (!el) { return JS_UNDEFINED; } + exc = dom_node_get_parent_node(el, &parent); - xmlpp::Node::remove_node(el); - interpreter->changed = 1; -#endif + if (exc != DOM_NO_ERR || !parent) { + return JS_UNDEFINED; + } + dom_node *res = NULL; + exc = dom_node_remove_child(parent, el, &res); + dom_node_unref(parent); + + if (exc == DOM_NO_ERR) { + dom_node_unref(res); + interpreter->changed = 1; + } return JS_UNDEFINED; }