ref: 7be32a0f5f3a4824593a56facb3c24c7f55ff4e3
parent: 7f50591861525f76e3ec7a63392656ff8c030af9
author: Tor Andersson <tor.andersson@artifex.com>
date: Fri Jan 4 05:58:30 EST 2019
Bug 700441: Handle null and undefined expressions in for-in statement.
--- a/jsproperty.c
+++ b/jsproperty.c
@@ -252,6 +252,14 @@
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];
--- a/jsrun.c
+++ b/jsrun.c
@@ -1469,11 +1469,12 @@
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:
--- a/jsvalue.h
+++ b/jsvalue.h
@@ -173,6 +173,7 @@
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);