Bug 700441: Handle null and undefined expressions in for-in statement.

This commit is contained in:
Tor Andersson
2019-01-04 10:58:30 +01:00
parent 7f50591861
commit 7be32a0f5f
3 changed files with 14 additions and 4 deletions

View File

@@ -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];

View File

@@ -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:

View File

@@ -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);