diff --git a/mfbt/RefPtr.h b/mfbt/RefPtr.h index 47cfac2fecf8..5237f59f11f1 100644 --- a/mfbt/RefPtr.h +++ b/mfbt/RefPtr.h @@ -19,6 +19,7 @@ class nsCOMPtr_helper; namespace mozilla { template class OwningNonNull; +template class StaticRefPtr; // Traditionally, RefPtr supports automatic refcounting of any pointer type // with AddRef() and Release() methods that follow the traditional semantics. @@ -148,6 +149,10 @@ public: template MOZ_IMPLICIT RefPtr(const mozilla::OwningNonNull& aOther); + // Defined in StaticPtr.h + template + MOZ_IMPLICIT RefPtr(const mozilla::StaticRefPtr& aOther); + // Assignment operators RefPtr& @@ -208,6 +213,11 @@ public: RefPtr& operator=(const mozilla::OwningNonNull& aOther); + // Defined in StaticPtr.h + template + RefPtr& + operator=(const mozilla::StaticRefPtr& aOther); + // Other pointer operators void diff --git a/xpcom/base/StaticPtr.h b/xpcom/base/StaticPtr.h index 21109e709d18..f2c820a93937 100644 --- a/xpcom/base/StaticPtr.h +++ b/xpcom/base/StaticPtr.h @@ -7,8 +7,10 @@ #ifndef mozilla_StaticPtr_h #define mozilla_StaticPtr_h +#include "mozilla/AlreadyAddRefed.h" #include "mozilla/Assertions.h" #include "mozilla/Attributes.h" +#include "mozilla/RefPtr.h" namespace mozilla { @@ -110,6 +112,26 @@ public: return (this = aRhs.mRawPtr); } + StaticRefPtr& operator=(already_AddRefed& aRhs) + { + AssignAssumingAddRef(aRhs.take()); + return *this; + } + + StaticRefPtr& operator=(already_AddRefed&& aRhs) + { + AssignAssumingAddRef(aRhs.take()); + return *this; + } + + already_AddRefed + forget() + { + T* temp = mRawPtr; + mRawPtr = nullptr; + return already_AddRefed(temp); + } + T* get() const { return mRawPtr; } operator T*() const { return get(); } @@ -232,4 +254,17 @@ REFLEXIVE_EQUALITY_OPERATORS(const StaticRefPtr&, StaticPtr_internal::Zero*, } // namespace mozilla +// Declared in mozilla/RefPtr.h +template template +RefPtr::RefPtr(const mozilla::StaticRefPtr& aOther) + : RefPtr(aOther.get()) +{} + +template template +RefPtr& +RefPtr::operator=(const mozilla::StaticRefPtr& aOther) +{ + return operator=(aOther.get()); +} + #endif