Bug 1450321, part 3 - Make xptiInterfaceInfo use normal refcounting.
This class can only be used on the main thread, so there's no need to
worry about an object going away from under us while we're in
Release(). The clearing of the weak pointer gets moved to the dtor.
MozReview-Commit-ID: 9XhLWsRmO87
--- a/xpcom/reflect/xptinfo/xptiInterfaceInfo.cpp
+++ b/xpcom/reflect/xptinfo/xptiInterfaceInfo.cpp
@@ -580,70 +580,31 @@ xptiInterfaceInfo::BuildParent()
mEntry->Parent(),
"bad BuildParent call");
mParent = mEntry->Parent()->InterfaceInfo();
return true;
}
/***************************************************************************/
-NS_IMPL_QUERY_INTERFACE(xptiInterfaceInfo, nsIInterfaceInfo)
+NS_IMPL_ISUPPORTS(xptiInterfaceInfo, nsIInterfaceInfo)
-xptiInterfaceInfo::xptiInterfaceInfo(xptiInterfaceEntry* entry)
- : mEntry(entry)
+xptiInterfaceInfo::xptiInterfaceInfo(xptiInterfaceEntry* aEntry)
+ : mEntry(aEntry)
{
+ MOZ_ASSERT(aEntry);
}
xptiInterfaceInfo::~xptiInterfaceInfo()
{
- NS_ASSERTION(!mEntry, "bad state in dtor");
+ if (mEntry) {
+ mEntry->InterfaceInfoDeathNotification();
+ }
}
void
xptiInterfaceInfo::Invalidate()
{
mParent = nullptr;
mEntry = nullptr;
}
-MozExternalRefCountType
-xptiInterfaceInfo::AddRef(void)
-{
- nsrefcnt cnt = ++mRefCnt;
- NS_LOG_ADDREF(this, cnt, "xptiInterfaceInfo", sizeof(*this));
- return cnt;
-}
-
-MozExternalRefCountType
-xptiInterfaceInfo::Release(void)
-{
- xptiInterfaceEntry* entry = mEntry;
- nsrefcnt cnt = --mRefCnt;
- NS_LOG_RELEASE(this, cnt, "xptiInterfaceInfo");
- if (!cnt) {
- // If InterfaceInfo added and *released* a reference before we
- // acquired the monitor then 'this' might already be dead. In that
- // case we would not want to try to access any instance data. We
- // would want to bail immediately. If 'this' is already dead then the
- // entry will no longer have a pointer to 'this'. So, we can protect
- // ourselves from danger without more aggressive locking.
- if (entry && !entry->InterfaceInfoEquals(this)) {
- return 0;
- }
-
- // If InterfaceInfo added a reference before we acquired the monitor
- // then we want to bail out of here without destorying the object.
- if (mRefCnt) {
- return 1;
- }
-
- if (mEntry) {
- mEntry->InterfaceInfoDeathNotification();
- mEntry = nullptr;
- }
-
- delete this;
- return 0;
- }
- return cnt;
-}
-
/***************************************************************************/
--- a/xpcom/reflect/xptinfo/xptiprivate.h
+++ b/xpcom/reflect/xptinfo/xptiprivate.h
@@ -214,20 +214,16 @@ public:
bool GetHasNotXPCOMFlag() const { return mFlags.GetFlagBit(HASNOTXPCOM); }
const nsID* GetTheIID() const { return &mIID; }
const char* GetTheName() const { return mName; }
bool EnsureResolved() { return IsFullyResolved() ? true : Resolve(); }
already_AddRefed<xptiInterfaceInfo> InterfaceInfo();
- bool InterfaceInfoEquals(const xptiInterfaceInfo* info) const
- {
- return info == mInfo;
- }
void InvalidateInterfaceInfo();
void InterfaceInfoDeathNotification() { mInfo = nullptr; }
xptiInterfaceEntry* Parent() const
{
NS_ASSERTION(IsFullyResolved(), "Parent() called while not resolved?");
return mParent;