Fix property cache fill to recompute protoIndex to handle XBL and other JS_SetPrototype users (418139, r/a=shaver).

This commit is contained in:
brendan%mozilla.org 2008-03-02 04:06:33 +00:00
Родитель a3e63b5ebc
Коммит 8a03eb44df
1 изменённых файлов: 26 добавлений и 1 удалений

Просмотреть файл

@ -133,7 +133,32 @@ js_FillPropertyCache(JSContext *cx, JSObject *obj, jsuword kshape,
return;
}
/* Check for overdeep scope and prototype chain. */
/*
* Check for overdeep scope and prototype chain. Because resolve, getter,
* and setter hooks can change the prototype chain using JS_SetPrototype
* after js_LookupPropertyWithFlags has returned the nominal protoIndex,
* we have to validate protoIndex if it is non-zero. If it is zero, then
* we know thanks to the SCOPE_HAS_PROPERTY test above, and from the fact
* that obj == pobj, that protoIndex is invariant.
*
* The scopeIndex can't be wrong. We require JS_SetParent calls to happen
* before any running script might consult a parent-linked scope chain. If
* this requirement is not satisfied, the fill in progress will never hit,
* but vcap vs. scope shape tests ensure nothing malfunctions.
*/
JS_ASSERT_IF(scopeIndex == 0 && protoIndex == 0, obj == pobj);
if (protoIndex != 0) {
JSObject *tmp;
JS_ASSERT(pobj != obj);
protoIndex = 1;
tmp = obj;
while ((tmp = OBJ_GET_PROTO(cx, tmp)) != NULL) {
if (tmp == pobj)
break;
++protoIndex;
}
}
if (scopeIndex > PCVCAP_SCOPEMASK || protoIndex > PCVCAP_PROTOMASK) {
PCMETER(cache->longchains++);
return;