Bug 821804 - Allow unitialized WeakPtrs to work properly. r=Waldo
authorJeff Muizelaar <jmuizelaar@mozilla.com>
Tue, 18 Dec 2012 11:37:14 -0500
changeset 125510 c155591689563acb69005e63dfc65a7a647fb91a
parent 125509 b43311784b7fac3de06c0ddd73d149a0f5de63e4
child 125511 b682f3b118b1873e4278ba6611691d2e40990bbc
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersWaldo
bugs821804
milestone20.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 821804 - Allow unitialized WeakPtrs to work properly. r=Waldo This ensures that the WeakPtr always points at a valid object and avoids the need to test for that during operations.
mfbt/WeakPtr.h
--- a/mfbt/WeakPtr.h
+++ b/mfbt/WeakPtr.h
@@ -108,17 +108,18 @@ class SupportsWeakPtr
     RefPtr<WeakReference> weakRef;
 };
 
 template <typename T>
 class WeakPtr
 {
   public:
     WeakPtr(const WeakPtr<T>& o) : ref(o.ref) {}
-    WeakPtr() : ref(nullptr) {}
+    // Ensure that ref is dereferenceable in the uninitialized state
+    WeakPtr() : ref(new typename SupportsWeakPtr<T>::WeakReference(nullptr)) {}
 
     operator T*() const {
       return ref->get();
     }
     T& operator*() const {
       return *ref->get();
     }