Bug 1044658 - 3/6 - make WeakPtr<const T> work - r=froydnj
authorBenoit Jacob <bjacob@mozilla.com>
Wed, 30 Jul 2014 15:52:03 -0400
changeset 196939 77a2a058bc912c083750a9dd85cf1792e6141ff9
parent 196938 a8f57c397a0449f565b61b3791a071304292b012
child 196940 5beea07a9f5f5ba7920d2bf74a87c6b93219d35f
push id27228
push usercbook@mozilla.com
push dateThu, 31 Jul 2014 10:58:52 +0000
treeherdermozilla-central@aa176fcc56b8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1044658
milestone34.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1044658 - 3/6 - make WeakPtr<const T> work - r=froydnj
mfbt/WeakPtr.h
--- a/mfbt/WeakPtr.h
+++ b/mfbt/WeakPtr.h
@@ -135,16 +135,22 @@ public:
   WeakPtr<T> asWeakPtr()
   {
     if (!weakRef) {
       weakRef = new detail::WeakReference<T>(static_cast<T*>(this));
     }
     return WeakPtr<T>(weakRef);
   }
 
+  WeakPtr<const T> asWeakPtr() const
+  {
+     WeakPtr<T> p = const_cast<SupportsWeakPtr*>(this)->asWeakPtr();
+     return *reinterpret_cast<WeakPtr<const T>*>(&p);
+  }
+
 protected:
   ~SupportsWeakPtr()
   {
     static_assert(IsBaseOf<SupportsWeakPtr<T>, T>::value,
                   "T must derive from SupportsWeakPtr<T>");
     if (weakRef) {
       weakRef->detach();
     }
@@ -155,17 +161,17 @@ private:
 
   RefPtr<detail::WeakReference<T>> weakRef;
 };
 
 template <typename T>
 class WeakPtr
 {
 public:
-  WeakPtr(const WeakPtr<T>& aOther)
+  WeakPtr(const WeakPtr& aOther)
     : mRef(aOther.mRef)
   {}
 
   // Ensure that mRef is dereferenceable in the uninitialized state.
   WeakPtr() : mRef(new detail::WeakReference<T>(nullptr)) {}
 
   operator T*() const { return mRef->get(); }
   T& operator*() const { return *mRef->get(); }