Bug 1463299: Add RefPtr::forget special case for ambiguous nsISupports casts. r=bz
authorKris Maglione <maglione.k@gmail.com>
Mon, 21 May 2018 17:23:10 -0700
changeset 476058 bfdfd3388e9a17d65a81ddbdc4fc669ab2887b3a
parent 476057 a1bf5dfd3c00c5e59a59272fb03d0d6684539b82
child 476059 b47348c5f123fda2a1d14c923ef2bada5af82a59
push id1757
push userffxbld-merge
push dateFri, 24 Aug 2018 17:02:43 +0000
treeherdermozilla-release@736023aebdb1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs1463299
milestone62.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 1463299: Add RefPtr::forget special case for ambiguous nsISupports casts. r=bz When we use RefPtr with nsISupports sub-classes, it's usually because the type cannot be unambiguously cast to nsISupports. We already have a ToSupports generic function to resolve ambiguity in these cases, so we may as well use it here. MozReview-Commit-ID: FaHhPKAPn6j
mfbt/RefPtr.h
widget/nsBaseFilePicker.cpp
--- a/mfbt/RefPtr.h
+++ b/mfbt/RefPtr.h
@@ -12,16 +12,17 @@
 #include "mozilla/Attributes.h"
 
 /*****************************************************************************/
 
 // template <class T> class RefPtrGetterAddRefs;
 
 class nsQueryReferent;
 class nsCOMPtr_helper;
+class nsISupports;
 
 namespace mozilla {
 template<class T> class OwningNonNull;
 template<class T> class StaticRefPtr;
 
 // Traditionally, RefPtr supports automatic refcounting of any pointer type
 // with AddRef() and Release() methods that follow the traditional semantics.
 //
@@ -272,16 +273,24 @@ public:
   // parameters where aRhs bay be a T** or an I** where I is a base class
   // of T.
   {
     MOZ_ASSERT(aRhs, "Null pointer passed to forget!");
     *aRhs = mRawPtr;
     mRawPtr = nullptr;
   }
 
+  void
+  forget(nsISupports** aRhs)
+  {
+    MOZ_ASSERT(aRhs, "Null pointer passed to forget!");
+    *aRhs = ToSupports(mRawPtr);
+    mRawPtr = nullptr;
+  }
+
   T*
   get() const
   /*
     Prefer the implicit conversion provided automatically by |operator T*() const|.
     Use |get()| to resolve ambiguity or to get a castable pointer.
   */
   {
     return const_cast<T*>(mRawPtr);
--- a/widget/nsBaseFilePicker.cpp
+++ b/widget/nsBaseFilePicker.cpp
@@ -48,17 +48,18 @@ LocalFileToDirectoryOrBlob(nsPIDOMWindow
 
     RefPtr<Directory> directory = Directory::Create(aWindow, aFile);
     MOZ_ASSERT(directory);
 
     directory.forget(aResult);
     return NS_OK;
   }
 
-  *aResult = ToSupports(File::CreateFromFile(aWindow, aFile).take());
+  RefPtr<File> file = File::CreateFromFile(aWindow, aFile);
+  file.forget(aResult);
   return NS_OK;
 }
 
 } // anonymous namespace
 
 /**
  * A runnable to dispatch from the main thread to the main thread to display
  * the file picker while letting the showAsync method return right away.