From 296c6e81415d59518290594ec1da9a1c27685dcc Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Thu, 18 Aug 2022 22:04:49 +0200 Subject: [PATCH] [mujs] no js_dup --- src/ecmascript/mujs/form.cpp | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/ecmascript/mujs/form.cpp b/src/ecmascript/mujs/form.cpp index 3576545f4..98fbc5330 100644 --- a/src/ecmascript/mujs/form.cpp +++ b/src/ecmascript/mujs/form.cpp @@ -118,6 +118,9 @@ mjs_form_set_items(js_State *J, void *node) int counter = 0; struct el_form_control *fc; + + js_newarray(J); + foreach (fc, form->items) { struct form_state *fs = find_form_state(doc_view, fc); @@ -125,15 +128,14 @@ mjs_form_set_items(js_State *J, void *node) continue; } mjs_push_form_control_object(J, fc->type, fs); - js_dup(J); - js_setindex(J, 0, counter); + js_setindex(J, -2, counter); if (fc->id && strcmp(fc->id, "item") && strcmp(fc->id, "namedItem")) { - js_setproperty(J, 0, fc->id); + mjs_push_form_control_object(J, fc->type, fs); + js_setproperty(J, -2, fc->id); } else if (fc->name && strcmp(fc->name, "item") && strcmp(fc->name, "namedItem")) { - js_setproperty(J, 0, fc->name); - } else { - js_pop(J, 1); + mjs_push_form_control_object(J, fc->type, fs); + js_setproperty(J, -2, fc->name); } counter++; } @@ -155,6 +157,9 @@ mjs_form_set_items2(js_State *J, void *node) int counter = 0; struct el_form_control *fc; + + js_newarray(J); + foreach (fc, form->items) { struct form_state *fs = find_form_state(doc_view, fc); @@ -162,15 +167,14 @@ mjs_form_set_items2(js_State *J, void *node) continue; } mjs_push_form_control_object(J, fc->type, fs); - js_dup(J); - js_setindex(J, 0, counter); + js_setindex(J, -2, counter); if (fc->id && strcmp(fc->id, "item") && strcmp(fc->id, "namedItem")) { - js_setproperty(J, 0, fc->id); + mjs_push_form_control_object(J, fc->type, fs); + js_setproperty(J, -2, fc->id); } else if (fc->name && strcmp(fc->name, "item") && strcmp(fc->name, "namedItem")) { - js_setproperty(J, 0, fc->name); - } else { - js_pop(J, 1); + mjs_push_form_control_object(J, fc->type, fs); + js_setproperty(J, -2, fc->name); } counter++; }