Navigate scope chain properly. bug=353079 r=brendan

This commit is contained in:
igor.bukanov%gmail.com 2006-10-07 01:14:51 +00:00
parent 4d79de55ec
commit 2d1499e739

View File

@ -480,7 +480,8 @@ js_GetScopeChain(JSContext *cx, JSStackFrame *fp)
* the cloned child after we clone the parent. In the following loop when
* clonedChild is null it indicates the first iteration when no special GC
* rooting is necessary. On the second and the following iterations we
* have to protect clonedChild against the GC during cloning of the parent.
* have to protect cloned so far chain against the GC during cloning of
* the cursor object.
*/
cursor = obj;
clonedChild = NULL;
@ -499,22 +500,25 @@ js_GetScopeChain(JSContext *cx, JSStackFrame *fp)
return NULL;
}
if (!clonedChild) {
/*
* The first iteration. Check if other follow and root obj if so
* to protect the whole cloned chain against GC.
*/
obj = cursor;
if (parent)
JS_PUSH_SINGLE_TEMP_ROOT(cx, cursor, &tvr);
if (!parent)
break;
JS_PUSH_SINGLE_TEMP_ROOT(cx, obj, &tvr);
} else {
/*
* Avoid OBJ_SET_PARENT overhead as clonedChild cannot escape to
* other threads.
*/
clonedChild->slots[JSSLOT_PARENT] = OBJECT_TO_JSVAL(cursor);
JS_ASSERT(tvr.u.value == OBJECT_TO_JSVAL(clonedChild));
tvr.u.value = OBJECT_TO_JSVAL(cursor);
}
if (!parent) {
if (clonedChild)
if (!parent) {
JS_ASSERT(tvr.u.value == OBJECT_TO_JSVAL(obj));
JS_POP_TEMP_ROOT(cx, &tvr);
break;
break;
}
}
clonedChild = cursor;
cursor = parent;