ref: 7a45bb4363e8afa095ca18346c1b8a70f1269491
parent: 195816c208ff272861e3d7f71f0837a147a18aea
author: Tor Andersson <tor@ccxvii.net>
date: Thu Jan 23 18:04:59 EST 2014
Free iterator nodes as they are being iterated over.
--- a/jsgc.c
+++ b/jsgc.c
@@ -41,7 +41,7 @@
if (obj->properties->level)
jsG_freeproperty(J, obj->properties);
if (obj->type == JS_CITERATOR)
- jsG_freeiterator(J, obj->u.iterator.head);
+ jsG_freeiterator(J, obj->u.iter);
free(obj);
}
--- a/jsproperty.c
+++ b/jsproperty.c
@@ -170,20 +170,23 @@
js_Object *jsV_newiterator(js_State *J, js_Object *obj)
{
js_Object *iobj = jsV_newobject(J, JS_CITERATOR, NULL);
- iobj->u.iterator.head = itflatten(J, obj);
- iobj->u.iterator.next = iobj->u.iterator.head;
+ iobj->u.iter = itflatten(J, obj);
return iobj;
}
const char *jsV_nextiterator(js_State *J, js_Object *iobj)
{
- js_Iterator *result;
+ js_Iterator *iter, *next;
+ const char *name;
if (iobj->type != JS_CITERATOR)
js_typeerror(J, "not an iterator");
- result = iobj->u.iterator.next;
- if (result) {
- iobj->u.iterator.next = result->next;
- return result->name;
+ iter = iobj->u.iter;
+ if (iter) {
+ name = iter->name;
+ next = iter->next;
+ free(iter);
+ iobj->u.iter = next;
+ return name;
}
return NULL;
}
--- a/jsvalue.h
+++ b/jsvalue.h
@@ -60,10 +60,7 @@
js_CFunction function;
js_CFunction constructor;
} c;
- struct {
- js_Iterator *head;
- js_Iterator *next;
- } iterator;
+ js_Iterator *iter;
} u;
js_Object *gcnext;
int gcmark;