Bug 1483042 - Remove more ~RefPtr that fire after a Rooted has been unwrapped for a return value, r=janv
authorSteve Fink <sfink@mozilla.com>
Mon, 13 Aug 2018 14:51:20 -0700
changeset 488169 c2a1d27fb7a9777e1f08719f0c59e104eb325d53
parent 488168 8b7adcbe197982d69af6308a78a178b419c6fa16
child 488170 ed8e57ba1b07cced1517a62573617ff3cac0fab9
push id9719
push userffxbld-merge
push dateFri, 24 Aug 2018 17:49:46 +0000
treeherdermozilla-beta@719ec98fba77 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjanv
bugs1483042
milestone63.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 1483042 - Remove more ~RefPtr that fire after a Rooted has been unwrapped for a return value, r=janv
dom/indexedDB/IDBObjectStore.cpp
--- a/dom/indexedDB/IDBObjectStore.cpp
+++ b/dom/indexedDB/IDBObjectStore.cpp
@@ -901,46 +901,48 @@ CopyingStructuredCloneReadCallback(JSCon
       MOZ_ASSERT(false, "Bad index value!");
       return nullptr;
     }
 
     StructuredCloneFile& file = cloneInfo->mFiles[aData];
 
     if (aTag == SCTAG_DOM_BLOB) {
       MOZ_ASSERT(file.mType == StructuredCloneFile::eBlob);
-
-      RefPtr<Blob> blob = file.mBlob;
-      MOZ_ASSERT(!blob->IsFile());
+      MOZ_ASSERT(!file.mBlob->IsFile());
 
       JS::Rooted<JS::Value> wrappedBlob(aCx);
-      if (NS_WARN_IF(!ToJSValue(aCx, blob, &wrappedBlob))) {
+      if (NS_WARN_IF(!ToJSValue(aCx, file.mBlob, &wrappedBlob))) {
         return nullptr;
       }
 
       result.set(&wrappedBlob.toObject());
 
       return result;
     }
 
     if (aTag == SCTAG_DOM_FILE) {
       MOZ_ASSERT(file.mType == StructuredCloneFile::eBlob);
 
-      RefPtr<Blob> blob = file.mBlob;
-      MOZ_ASSERT(blob->IsFile());
-
-      RefPtr<File> file = blob->ToFile();
-      MOZ_ASSERT(file);
-
-      JS::Rooted<JS::Value> wrappedFile(aCx);
-      if (NS_WARN_IF(!ToJSValue(aCx, file, &wrappedFile))) {
-        return nullptr;
+      {
+        // Create a scope so ~RefPtr fires before returning an unwrapped
+        // JS::Value.
+        RefPtr<Blob> blob = file.mBlob;
+        MOZ_ASSERT(blob->IsFile());
+
+        RefPtr<File> file = blob->ToFile();
+        MOZ_ASSERT(file);
+
+        JS::Rooted<JS::Value> wrappedFile(aCx);
+        if (NS_WARN_IF(!ToJSValue(aCx, file, &wrappedFile))) {
+          return nullptr;
+        }
+
+        result.set(&wrappedFile.toObject());
       }
 
-      result.set(&wrappedFile.toObject());
-
       return result;
     }
 
     if (aTag == SCTAG_DOM_MUTABLEFILE) {
       MOZ_ASSERT(file.mType == StructuredCloneFile::eMutableFile);
 
       JS::Rooted<JS::Value> wrappedMutableFile(aCx);
       if (NS_WARN_IF(!ToJSValue(aCx, file.mMutableFile, &wrappedMutableFile))) {