From 53a06709eb7fe56e1b19ec1351bd8196f5beaee8 Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Wed, 18 Sep 2024 15:34:49 +0200 Subject: [PATCH] [mujs] DocumentFragment.nodeValue and Element.nodeValue setters --- src/ecmascript/mujs/element.c | 33 ++++++++++++++++++++++++++++++++- src/ecmascript/mujs/fragment.c | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 64 insertions(+), 2 deletions(-) diff --git a/src/ecmascript/mujs/element.c b/src/ecmascript/mujs/element.c index 420a6122f..7e12286a8 100644 --- a/src/ecmascript/mujs/element.c +++ b/src/ecmascript/mujs/element.c @@ -903,6 +903,37 @@ mjs_element_get_property_nodeValue(js_State *J) dom_string_unref(content); } +static void +mjs_element_set_property_nodeValue(js_State *J) +{ +#ifdef ECMASCRIPT_DEBUG + fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); +#endif + dom_node *node = (dom_node *)(mjs_getprivate(J, 0)); + + if (!node) { + js_error(J, "error"); + return; + } + const char *str = js_tostring(J, 1); + + if (!str) { + js_error(J, "out of memory"); + return; + } + dom_string *value = NULL; + dom_exception exc = dom_string_create((const uint8_t *)str, strlen(str), &value); + + if (exc != DOM_NO_ERR || !value) { + js_pushundefined(J); + return; + } + exc = dom_node_set_node_value(node, value); + dom_string_unref(value); + + js_pushundefined(J); +} + static void mjs_element_get_property_nextSibling(js_State *J) { @@ -3402,7 +3433,7 @@ fprintf(stderr, "Before: %s:%d\n", __FUNCTION__, __LINE__); addproperty(J, "nextSibling", mjs_element_get_property_nextSibling, NULL); addproperty(J, "nodeName", mjs_element_get_property_nodeName, NULL); addproperty(J, "nodeType", mjs_element_get_property_nodeType, NULL); - addproperty(J, "nodeValue", mjs_element_get_property_nodeValue, NULL); + addproperty(J, "nodeValue", mjs_element_get_property_nodeValue, mjs_element_set_property_nodeValue); // addproperty(J, "offsetHeight", mjs_element_get_property_offsetHeight, NULL); // addproperty(J, "offsetLeft", mjs_element_get_property_offsetLeft, NULL); addproperty(J, "offsetParent", mjs_element_get_property_offsetParent, NULL); diff --git a/src/ecmascript/mujs/fragment.c b/src/ecmascript/mujs/fragment.c index 8c3af324f..4790027ee 100644 --- a/src/ecmascript/mujs/fragment.c +++ b/src/ecmascript/mujs/fragment.c @@ -464,6 +464,37 @@ mjs_fragment_get_property_nodeValue(js_State *J) dom_string_unref(content); } +static void +mjs_fragment_set_property_nodeValue(js_State *J) +{ +#ifdef ECMASCRIPT_DEBUG + fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); +#endif + dom_node *node = (dom_node *)(mjs_getprivate_fragment(J, 0)); + + if (!node) { + js_error(J, "error"); + return; + } + const char *str = js_tostring(J, 1); + + if (!str) { + js_error(J, "out of memory"); + return; + } + dom_string *value = NULL; + dom_exception exc = dom_string_create((const uint8_t *)str, strlen(str), &value); + + if (exc != DOM_NO_ERR || !value) { + js_pushundefined(J); + return; + } + exc = dom_node_set_node_value(node, value); + dom_string_unref(value); + + js_pushundefined(J); +} + static void mjs_fragment_get_property_nextSibling(js_State *J) { @@ -1306,7 +1337,7 @@ fprintf(stderr, "Before: %s:%d\n", __FUNCTION__, __LINE__); addproperty(J, "nextSibling", mjs_fragment_get_property_nextSibling, NULL); addproperty(J, "nodeName", mjs_fragment_get_property_nodeName, NULL); addproperty(J, "nodeType", mjs_fragment_get_property_nodeType, NULL); - addproperty(J, "nodeValue", mjs_fragment_get_property_nodeValue, NULL); + addproperty(J, "nodeValue", mjs_fragment_get_property_nodeValue, mjs_fragment_set_property_nodeValue); addproperty(J, "ownerDocument", mjs_fragment_get_property_ownerDocument, NULL); addproperty(J, "parentElement", mjs_fragment_get_property_parentElement, NULL); addproperty(J, "parentNode", mjs_fragment_get_property_parentNode, NULL);