Bug 825025. MaybeWrapValue should work with all gcthings. r=peterv

This commit is contained in:
Boris Zbarsky 2012-12-29 22:13:26 -08:00
parent 8509682076
commit 6378ed05fd
2 changed files with 11 additions and 7 deletions

View File

@ -368,16 +368,20 @@ DefineUnforgeableAttributes(JSContext* cx, JSObject* obj,
bool
DefineWebIDLBindingPropertiesOnXPCProto(JSContext* cx, JSObject* proto, const NativeProperties* properties);
// If *vp is an object and *vp and obj are not in the same compartment, wrap *vp
// into the compartment of obj (typically by replacing it with an Xray or
// If *vp is a gcthing and is not in the compartment of cx, wrap *vp
// into the compartment of cx (typically by replacing it with an Xray or
// cross-compartment wrapper around the original object).
inline bool
MaybeWrapValue(JSContext* cx, JSObject* obj, JS::Value* vp)
MaybeWrapValue(JSContext* cx, JS::Value* vp)
{
if (vp->isObject() &&
js::GetObjectCompartment(&vp->toObject()) != js::GetContextCompartment(cx)) {
if (vp->isGCThing()) {
void* gcthing = vp->toGCThing();
// Might be null if vp.isNull() :(
if (gcthing &&
js::GetGCThingCompartment(gcthing) != js::GetContextCompartment(cx)) {
return JS_WrapValue(cx, vp);
}
}
return true;
}

View File

@ -3212,7 +3212,7 @@ def getWrapTemplateForType(type, descriptorProvider, result, successCode,
if not callWrapValue:
tail = successCode
else:
tail = ("if (!MaybeWrapValue(cx, ${obj}, ${jsvalPtr})) {\n" +
tail = ("if (!MaybeWrapValue(cx, ${jsvalPtr})) {\n" +
("%s\n" % exceptionCodeIndented.define()) +
"}\n" +
successCode)