1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -05:00

[mujs] fixes in collections set_items

This commit is contained in:
Witold Filipczyk 2022-08-18 21:51:17 +02:00
parent 4faac6e164
commit 716136efd9

View File

@ -165,7 +165,7 @@ mjs_htmlCollection_set_items(js_State *J, void *node)
#endif #endif
int counter = 0; int counter = 0;
xmlpp::Node::NodeSet *ns = static_cast<xmlpp::Node::NodeSet *>(js_touserdata(J, 0, "collection")); xmlpp::Node::NodeSet *ns = static_cast<xmlpp::Node::NodeSet *>(node);
if (!ns) { if (!ns) {
return; return;
@ -173,16 +173,19 @@ mjs_htmlCollection_set_items(js_State *J, void *node)
xmlpp::Element *element; xmlpp::Element *element;
js_newarray(J);
while (1) { while (1) {
try { try {
element = dynamic_cast<xmlpp::Element *>(ns->at(counter)); element = dynamic_cast<xmlpp::Element *>(ns->at(counter));
} catch (std::out_of_range &e) { return;} } catch (std::out_of_range &e) {
return;
}
if (!element) { if (!element) {
return; return;
} }
mjs_push_element(J, element); mjs_push_element(J, element);
js_dup(J);
js_setindex(J, -2, counter); js_setindex(J, -2, counter);
xmlpp::ustring name = element->get_attribute_value("id"); 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"); name = element->get_attribute_value("name");
} }
if (name != "" && name != "item" && name != "namedItem") { if (name != "" && name != "item" && name != "namedItem") {
mjs_push_element(J, element);
js_setproperty(J, -2, name.c_str()); js_setproperty(J, -2, name.c_str());
} }
js_pop(J, 1);
counter++; counter++;
} }
} }