Bug 1295033 - Handle failure in nsXPCWrappedJS constructor r=mccr8

This commit is contained in:
Jon Coppeard 2016-12-07 13:43:24 -10:00
Родитель 4fa8f3b74f
Коммит b8a1fc66c2
2 изменённых файлов: 10 добавлений и 4 удалений

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

@ -405,7 +405,9 @@ nsXPCWrappedJS::nsXPCWrappedJS(JSContext* cx,
if (IsRootWrapper()) {
MOZ_ASSERT(!IsMultiCompartment(), "mNext is always nullptr here");
xpc::CompartmentPrivate::Get(mJSObj)->GetWrappedJSMap()->Add(cx, this);
if (!xpc::CompartmentPrivate::Get(mJSObj)->GetWrappedJSMap()->Add(cx, this)) {
*rv = NS_ERROR_OUT_OF_MEMORY;
}
} else {
NS_ADDREF(mRoot);
mNext = mRoot->mNext;
@ -416,8 +418,10 @@ nsXPCWrappedJS::nsXPCWrappedJS(JSContext* cx,
// to migrate the chain to the global table on the XPCJSContext.
if (mRoot->IsMultiCompartment()) {
xpc::CompartmentPrivate::Get(mRoot->mJSObj)->GetWrappedJSMap()->Remove(mRoot);
MOZ_RELEASE_ASSERT(nsXPConnect::GetContextInstance()->
GetMultiCompartmentWrappedJSMap()->Add(cx, mRoot));
auto destMap = nsXPConnect::GetContextInstance()->GetMultiCompartmentWrappedJSMap();
if (!destMap->Add(cx, mRoot)) {
*rv = NS_ERROR_OUT_OF_MEMORY;
}
}
}
}

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

@ -554,7 +554,9 @@ nsXPCWrappedJSClass::DelegatedQueryInterface(nsXPCWrappedJS* self,
nsresult rv = nsXPCWrappedJS::GetNewOrUsed(obj, aIID, getter_AddRefs(wrapper));
// Do the same thing we do for the "check for any existing wrapper" case above.
*aInstancePtr = wrapper.forget().take()->GetXPTCStub();
if (NS_SUCCEEDED(rv) && wrapper) {
*aInstancePtr = wrapper.forget().take()->GetXPTCStub();
}
return rv;
}