Bug 1290612 - XPCNativeSet::NewInstanceMutate() is always called with a non-null first argument. r=mrbkap
MozReview-Commit-ID: FQGL7pe02xY
--- a/js/xpconnect/src/XPCWrappedNativeInfo.cpp
+++ b/js/xpconnect/src/XPCWrappedNativeInfo.cpp
@@ -762,50 +762,45 @@ XPCNativeSet::NewInstance(XPCNativeInter
obj->mMemberCount = memberCount;
obj->mInterfaceCount = slots;
return obj;
}
// static
XPCNativeSet*
-XPCNativeSet::NewInstanceMutate(XPCNativeSet* otherSet,
+XPCNativeSet::NewInstanceMutate(XPCNativeSet* otherSet,
XPCNativeInterface* newInterface,
- uint16_t position)
+ uint16_t position)
{
+ MOZ_ASSERT(otherSet);
+
if (!newInterface)
return nullptr;
- if (otherSet && position > otherSet->mInterfaceCount)
+ if (position > otherSet->mInterfaceCount)
return nullptr;
// Use placement new to create an object with the right amount of space
// to hold the members array
int size = sizeof(XPCNativeSet);
- if (otherSet)
- size += otherSet->mInterfaceCount * sizeof(XPCNativeInterface*);
+ size += otherSet->mInterfaceCount * sizeof(XPCNativeInterface*);
void* place = new char[size];
XPCNativeSet* obj = new(place) XPCNativeSet();
- if (otherSet) {
- obj->mMemberCount = otherSet->GetMemberCount() +
- newInterface->GetMemberCount();
- obj->mInterfaceCount = otherSet->mInterfaceCount + 1;
+ obj->mMemberCount = otherSet->GetMemberCount() +
+ newInterface->GetMemberCount();
+ obj->mInterfaceCount = otherSet->mInterfaceCount + 1;
- XPCNativeInterface** src = otherSet->mInterfaces;
- XPCNativeInterface** dest = obj->mInterfaces;
- for (uint16_t i = 0; i < obj->mInterfaceCount; i++) {
- if (i == position)
- *dest++ = newInterface;
- else
- *dest++ = *src++;
- }
- } else {
- obj->mMemberCount = newInterface->GetMemberCount();
- obj->mInterfaceCount = 1;
- obj->mInterfaces[0] = newInterface;
+ XPCNativeInterface** src = otherSet->mInterfaces;
+ XPCNativeInterface** dest = obj->mInterfaces;
+ for (uint16_t i = 0; i < obj->mInterfaceCount; i++) {
+ if (i == position)
+ *dest++ = newInterface;
+ else
+ *dest++ = *src++;
}
return obj;
}
// static
void
XPCNativeSet::DestroyInstance(XPCNativeSet* inst)