Bug 1290614, part 2 - Split XPCNativeSetKey into three constructors. r=mrbkap
This explicitly represents the three types of keys that are used:
1. A key for an existing set.
2. A key for a new set with one interface added.
3. A key for an existing set with one new interface added at a
specified position.
MozReview-Commit-ID: Ctw41EymHbd
--- a/js/xpconnect/src/XPCInlines.h
+++ b/js/xpconnect/src/XPCInlines.h
@@ -274,16 +274,30 @@ XPCNativeInterface::HasAncestor(const ns
inline size_t
XPCNativeInterface::OffsetOfMembers()
{
return offsetof(XPCNativeInterface, mMembers);
}
/***************************************************************************/
+inline XPCNativeSetKey::XPCNativeSetKey(XPCNativeSet* baseSet,
+ XPCNativeInterface* addition,
+ uint16_t position)
+ : mBaseSet(baseSet)
+ , mAddition(addition)
+ , mPosition(position)
+{
+ MOZ_ASSERT(mBaseSet);
+ MOZ_ASSERT(mAddition);
+ MOZ_ASSERT(!mBaseSet->HasInterface(mAddition));
+}
+
+/***************************************************************************/
+
inline bool
XPCNativeSet::FindMember(jsid name, XPCNativeMember** pMember,
uint16_t* pInterfaceIndex) const
{
XPCNativeInterface* const * iface;
int count = (int) mInterfaceCount;
int i;
--- a/js/xpconnect/src/XPCMaps.h
+++ b/js/xpconnect/src/XPCMaps.h
@@ -412,17 +412,17 @@ public:
entry->key_value = set;
return set;
}
inline void Remove(XPCNativeSet* set)
{
MOZ_ASSERT(set, "bad param");
- XPCNativeSetKey key(set, nullptr, 0);
+ XPCNativeSetKey key(set);
mTable.Remove(&key);
}
inline uint32_t Count() { return mTable.EntryCount(); }
PLDHashTable::Iterator Iter() { return mTable.Iter(); }
size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const;
--- a/js/xpconnect/src/XPCWrappedNative.cpp
+++ b/js/xpconnect/src/XPCWrappedNative.cpp
@@ -427,17 +427,17 @@ XPCWrappedNative::GetNewOrUsed(xpcObject
wrapper = new XPCWrappedNative(helper.forgetCanonical(), proto);
} else {
RefPtr<XPCNativeInterface> iface = Interface;
if (!iface)
iface = XPCNativeInterface::GetISupports();
AutoMarkingNativeSetPtr set(cx);
- XPCNativeSetKey key(nullptr, iface, 0);
+ XPCNativeSetKey key(iface);
set = XPCNativeSet::GetNewOrUsed(&key);
if (!set)
return NS_ERROR_FAILURE;
wrapper =
new XPCWrappedNative(helper.forgetCanonical(), Scope, set);
}
--- a/js/xpconnect/src/XPCWrappedNativeInfo.cpp
+++ b/js/xpconnect/src/XPCWrappedNativeInfo.cpp
@@ -469,17 +469,17 @@ XPCNativeSet::GetNewOrUsed(const nsIID*
AutoJSContext cx;
AutoMarkingNativeSetPtr set(cx);
RefPtr<XPCNativeInterface> iface =
XPCNativeInterface::GetNewOrUsed(iid);
if (!iface)
return nullptr;
- XPCNativeSetKey key(nullptr, iface, 0);
+ XPCNativeSetKey key(iface);
XPCJSRuntime* rt = XPCJSRuntime::Get();
NativeSetMap* map = rt->GetNativeSetMap();
if (!map)
return nullptr;
set = map->Find(&key);
@@ -561,17 +561,17 @@ XPCNativeSet::GetNewOrUsed(nsIClassInfo*
if (interfaceArray.Length() > 0) {
set = NewInstance(Move(interfaceArray));
if (set) {
NativeSetMap* map2 = rt->GetNativeSetMap();
if (!map2)
goto out;
- XPCNativeSetKey key(set, nullptr, 0);
+ XPCNativeSetKey key(set);
XPCNativeSet* set2 = map2->Add(&key, set);
if (!set2) {
NS_ERROR("failed to add our set!");
DestroyInstance(set);
set = nullptr;
goto out;
}
--- a/js/xpconnect/src/xpcprivate.h
+++ b/js/xpconnect/src/xpcprivate.h
@@ -1264,24 +1264,43 @@ private:
nsCOMPtr<nsIInterfaceInfo> mInfo;
jsid mName;
uint16_t mMemberCount;
XPCNativeMember mMembers[1]; // always last - object sized for array
};
/***************************************************************************/
// XPCNativeSetKey is used to key a XPCNativeSet in a NativeSetMap.
+// It represents a new XPCNativeSet we are considering constructing, without
+// requiring that the set actually be built.
class XPCNativeSetKey final
{
public:
- explicit XPCNativeSetKey(XPCNativeSet* baseSet = nullptr,
- XPCNativeInterface* addition = nullptr,
- uint16_t position = 0)
- : mBaseSet(baseSet), mAddition(addition), mPosition(position) {}
+ // This represents an existing set |baseSet|.
+ explicit XPCNativeSetKey(XPCNativeSet* baseSet)
+ : mBaseSet(baseSet), mAddition(nullptr), mPosition(0)
+ {
+ MOZ_ASSERT(baseSet);
+ }
+
+ // This represents a new set containing only nsISupports and
+ // |addition|.
+ explicit XPCNativeSetKey(XPCNativeInterface* addition)
+ : mBaseSet(nullptr), mAddition(addition), mPosition(0)
+ {
+ MOZ_ASSERT(addition);
+ }
+
+ // This represents the existing set |baseSet| with the interface
+ // |addition| inserted at position |position|. |addition| must
+ // not already be present in |baseSet|.
+ explicit XPCNativeSetKey(XPCNativeSet* baseSet,
+ XPCNativeInterface* addition,
+ uint16_t position);
~XPCNativeSetKey() {}
XPCNativeSet* GetBaseSet() const {return mBaseSet;}
XPCNativeInterface* GetAddition() const {return mAddition;}
uint16_t GetPosition() const {return mPosition;}
PLDHashNumber Hash() const;