From 716136efd968c358efd7673a334ac1ab539c6bb8 Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Thu, 18 Aug 2022 21:51:17 +0200 Subject: [PATCH] [mujs] fixes in collections set_items --- src/ecmascript/mujs/collection.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/ecmascript/mujs/collection.cpp b/src/ecmascript/mujs/collection.cpp index 74a1e126a..d71d1ec55 100644 --- a/src/ecmascript/mujs/collection.cpp +++ b/src/ecmascript/mujs/collection.cpp @@ -165,7 +165,7 @@ mjs_htmlCollection_set_items(js_State *J, void *node) #endif int counter = 0; - xmlpp::Node::NodeSet *ns = static_cast(js_touserdata(J, 0, "collection")); + xmlpp::Node::NodeSet *ns = static_cast(node); if (!ns) { return; @@ -173,16 +173,19 @@ mjs_htmlCollection_set_items(js_State *J, void *node) xmlpp::Element *element; + js_newarray(J); + while (1) { try { element = dynamic_cast(ns->at(counter)); - } catch (std::out_of_range &e) { return;} + } catch (std::out_of_range &e) { + return; + } if (!element) { return; } mjs_push_element(J, element); - js_dup(J); js_setindex(J, -2, counter); xmlpp::ustring name = element->get_attribute_value("id"); @@ -190,9 +193,9 @@ mjs_htmlCollection_set_items(js_State *J, void *node) name = element->get_attribute_value("name"); } if (name != "" && name != "item" && name != "namedItem") { + mjs_push_element(J, element); js_setproperty(J, -2, name.c_str()); } - js_pop(J, 1); counter++; } }