Bug 823348 - Do a better job of lying about the holder and make assertions fatal. r=mrbkap

I noticed this nonfatal assertion firing, unrelated to my patches. Leaking
the holder is not so great. Let's fix this for real.
This commit is contained in:
Bobby Holley 2013-01-23 06:04:38 +01:00
parent d0a9794947
commit ddece7045a
2 changed files with 19 additions and 11 deletions

View File

@ -321,11 +321,11 @@ WrapperFactory::Rewrap(JSContext *cx, JSObject *existing, JSObject *obj,
JSObject *wrappedProto, JSObject *parent,
unsigned flags)
{
NS_ASSERTION(!IsWrapper(obj) ||
GetProxyHandler(obj) == &XrayWaiver ||
js::GetObjectClass(obj)->ext.innerObject,
"wrapped object passed to rewrap");
NS_ASSERTION(JS_GetClass(obj) != &XrayUtils::HolderClass, "trying to wrap a holder");
MOZ_ASSERT(!IsWrapper(obj) ||
GetProxyHandler(obj) == &XrayWaiver ||
js::GetObjectClass(obj)->ext.innerObject,
"wrapped object passed to rewrap");
MOZ_ASSERT(JS_GetClass(obj) != &XrayUtils::HolderClass, "trying to wrap a holder");
JSCompartment *origin = js::GetObjectCompartment(obj);
JSCompartment *target = js::GetContextCompartment(cx);

View File

@ -1399,8 +1399,10 @@ XrayWrapper<Base, Traits>::getPropertyDescriptor(JSContext *cx, JSObject *wrappe
if (!Traits::singleton.resolveOwnProperty(cx, *this, wrapper, holder, id, desc, flags))
return false;
if (desc->obj)
if (desc->obj) {
desc->obj = wrapper;
return true;
}
if (!JS_GetPropertyDescriptorById(cx, holder, id, 0, desc))
return false;
@ -1428,11 +1430,15 @@ XrayWrapper<Base, Traits>::getPropertyDescriptor(JSContext *cx, JSObject *wrappe
desc->value.setObject(*JS_GetFunctionObject(toString));
}
if (!JS_DefinePropertyById(cx, holder, id, desc->value, desc->getter,
desc->setter, desc->attrs) ||
!JS_GetPropertyDescriptorById(cx, holder, id, flags, desc))
{
return false;
}
MOZ_ASSERT(desc->obj);
desc->obj = wrapper;
return JS_DefinePropertyById(cx, holder, id, desc->value, desc->getter, desc->setter,
desc->attrs) &&
JS_GetPropertyDescriptorById(cx, holder, id, flags, desc);
return true;
}
template <typename Base, typename Traits>
@ -1472,8 +1478,10 @@ XrayWrapper<Base, Traits>::getOwnPropertyDescriptor(JSContext *cx, JSObject *wra
if (!Traits::singleton.resolveOwnProperty(cx, *this, wrapper, holder, id, desc, flags))
return false;
if (desc->obj)
if (desc->obj) {
desc->obj = wrapper;
return true;
}
if (!JS_GetPropertyDescriptorById(cx, holder, id, flags, desc))
return false;