mirror of
https://github.com/ccxvii/mujs.git
synced 2026-02-06 01:41:37 +08:00
Handle null/undefined in OP_NEXTITER rather than creating empty iterator.
Only create an iterator for coercible types in OP_ITERATOR, and then detect the lack of a real iterator in OP_NEXTITER. Thus we don't need to allocate and push an empty iterator object for these cases.
This commit is contained in:
@@ -252,14 +252,6 @@ static js_Iterator *itflatten(js_State *J, js_Object *obj)
|
|||||||
return iter;
|
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)
|
js_Object *jsV_newiterator(js_State *J, js_Object *obj, int own)
|
||||||
{
|
{
|
||||||
char buf[32];
|
char buf[32];
|
||||||
|
|||||||
24
jsrun.c
24
jsrun.c
@@ -1469,20 +1469,24 @@ static void jsR_run(js_State *J, js_Function *F)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case OP_ITERATOR:
|
case OP_ITERATOR:
|
||||||
if (js_isundefined(J, -1) || js_isnull(J, -1))
|
if (js_iscoercible(J, -1)) {
|
||||||
obj = jsV_emptyiterator(J);
|
|
||||||
else
|
|
||||||
obj = jsV_newiterator(J, js_toobject(J, -1), 0);
|
obj = jsV_newiterator(J, js_toobject(J, -1), 0);
|
||||||
js_pop(J, 1);
|
js_pop(J, 1);
|
||||||
js_pushobject(J, obj);
|
js_pushobject(J, obj);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OP_NEXTITER:
|
case OP_NEXTITER:
|
||||||
obj = js_toobject(J, -1);
|
if (js_isobject(J, -1)) {
|
||||||
str = jsV_nextiterator(J, obj);
|
obj = js_toobject(J, -1);
|
||||||
if (str) {
|
str = jsV_nextiterator(J, obj);
|
||||||
js_pushliteral(J, str);
|
if (str) {
|
||||||
js_pushboolean(J, 1);
|
js_pushliteral(J, str);
|
||||||
|
js_pushboolean(J, 1);
|
||||||
|
} else {
|
||||||
|
js_pop(J, 1);
|
||||||
|
js_pushboolean(J, 0);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
js_pop(J, 1);
|
js_pop(J, 1);
|
||||||
js_pushboolean(J, 0);
|
js_pushboolean(J, 0);
|
||||||
|
|||||||
@@ -173,7 +173,6 @@ 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);
|
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);
|
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);
|
js_Object *jsV_newiterator(js_State *J, js_Object *obj, int own);
|
||||||
const char *jsV_nextiterator(js_State *J, js_Object *iter);
|
const char *jsV_nextiterator(js_State *J, js_Object *iter);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user