From a6cb50e413dbb6a8ff19ad37f7ce36dea6e12394 Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Sat, 6 Jul 2024 12:37:02 +0200 Subject: [PATCH] [mujs] element.remove() --- src/ecmascript/mujs/element.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/ecmascript/mujs/element.c b/src/ecmascript/mujs/element.c index 85ef3d220..d61a45e8f 100644 --- a/src/ecmascript/mujs/element.c +++ b/src/ecmascript/mujs/element.c @@ -3027,19 +3027,29 @@ mjs_element_remove(js_State *J) #ifdef ECMASCRIPT_DEBUG fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); #endif -// TODO -#if 0 - struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J); - xmlpp::Element *el = static_cast(mjs_getprivate(J, 0)); + dom_node *el = (dom_node *)(mjs_getprivate(J, 0)); + dom_node *parent = NULL; + dom_exception exc; if (!el) { js_pushundefined(J); return; } - xmlpp::Node::remove_node(el); - interpreter->changed = 1; -#endif + exc = dom_node_get_parent_node(el, &parent); + + if (exc != DOM_NO_ERR || !parent) { + js_pushundefined(J); + return; + } + 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; + } js_pushundefined(J); }