diff --git a/jsproperty.c b/jsproperty.c index a66c433..4aa3a49 100644 --- a/jsproperty.c +++ b/jsproperty.c @@ -252,6 +252,14 @@ static js_Iterator *itflatten(js_State *J, js_Object *obj) return iter; } +js_Object *jsV_emptyiterator(js_State *J) +{ + js_Object *io = jsV_newobject(J, JS_CITERATOR, NULL); + io->u.iter.target = NULL; + io->u.iter.head = NULL; + return io; +} + js_Object *jsV_newiterator(js_State *J, js_Object *obj, int own) { char buf[32]; diff --git a/jsrun.c b/jsrun.c index a53d289..68c963e 100644 --- a/jsrun.c +++ b/jsrun.c @@ -1469,11 +1469,12 @@ static void jsR_run(js_State *J, js_Function *F) break; case OP_ITERATOR: - if (!js_isundefined(J, -1) && !js_isnull(J, -1)) { + if (js_isundefined(J, -1) || js_isnull(J, -1)) + obj = jsV_emptyiterator(J); + else obj = jsV_newiterator(J, js_toobject(J, -1), 0); - js_pop(J, 1); - js_pushobject(J, obj); - } + js_pop(J, 1); + js_pushobject(J, obj); break; case OP_NEXTITER: diff --git a/jsvalue.h b/jsvalue.h index 09427da..05750c9 100644 --- a/jsvalue.h +++ b/jsvalue.h @@ -173,6 +173,7 @@ js_Property *jsV_setproperty(js_State *J, js_Object *obj, const char *name); js_Property *jsV_nextproperty(js_State *J, js_Object *obj, const char *name); void jsV_delproperty(js_State *J, js_Object *obj, const char *name); +js_Object *jsV_emptyiterator(js_State *J); js_Object *jsV_newiterator(js_State *J, js_Object *obj, int own); const char *jsV_nextiterator(js_State *J, js_Object *iter);