diff --git a/jscompile.c b/jscompile.c index 1bb3fbe..333dffa 100644 --- a/jscompile.c +++ b/jscompile.c @@ -302,17 +302,10 @@ static void cbinary(JF, js_Ast *exp, int opcode) static void carray(JF, js_Ast *list) { - int i = 0; while (list) { - if (list->a->type != EXP_UNDEF) { - emitline(J, F, list->a); - emitnumber(J, F, i++); - cexp(J, F, list->a); - emitline(J, F, list->a); - emit(J, F, OP_INITPROP); - } else { - ++i; - } + emitline(J, F, list->a); + cexp(J, F, list->a); + emit(J, F, OP_INITARRAY); list = list->b; } } diff --git a/jscompile.h b/jscompile.h index 172f8fd..5338322 100644 --- a/jscompile.h +++ b/jscompile.h @@ -38,6 +38,7 @@ enum js_OpCode OP_IN, /* -- */ + OP_INITARRAY, /* -- */ OP_INITPROP, /* -- */ OP_INITGETTER, /* -- */ OP_INITSETTER, /* -- */ diff --git a/jsrun.c b/jsrun.c index 198f2fd..c418e39 100644 --- a/jsrun.c +++ b/jsrun.c @@ -1438,6 +1438,10 @@ static void jsR_run(js_State *J, js_Function *F) js_pushboolean(J, b); break; + case OP_INITARRAY: + js_setindex(J, -2, js_getlength(J, -2)); + break; + case OP_INITPROP: obj = js_toobject(J, -3); str = js_tostring(J, -2); diff --git a/opnames.h b/opnames.h index 56e270d..8f40b91 100644 --- a/opnames.h +++ b/opnames.h @@ -25,6 +25,7 @@ "setvar", "delvar", "in", +"initarray", "initprop", "initgetter", "initsetter",