Bug 1029209 - Additional patch to fix a rooting hazard; r=bent
authorJan Varga <jan.varga@gmail.com>
Thu, 17 Jul 2014 12:41:08 -0400
changeset 216655 9d72b50b8460d0bdb0cf135aea364b0635d31e51
parent 216654 027f3828d0ab77915c613653f077ed83371538f9
child 216656 2329ce673fca393386586d0d4f1887ba2930c1f8
push id515
push userraliiev@mozilla.com
push dateMon, 06 Oct 2014 12:51:51 +0000
treeherdermozilla-release@267c7a481bef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbent
bugs1029209
milestone33.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 1029209 - Additional patch to fix a rooting hazard; r=bent
dom/indexedDB/IDBObjectStore.cpp
--- a/dom/indexedDB/IDBObjectStore.cpp
+++ b/dom/indexedDB/IDBObjectStore.cpp
@@ -775,29 +775,36 @@ ResolveMysteryBlob(nsIDOMBlob* aBlob, co
     return actor->SetMysteryBlobInfo(aContentType, aSize);
   }
   return true;
 }
 
 class MainThreadDeserializationTraits
 {
 public:
-  static JSObject* CreateAndWrapMutableFile(JSContext* aCx,
-                                            IDBDatabase* aDatabase,
-                                            StructuredCloneFile& aFile,
-                                            const MutableFileData& aData)
+  static bool CreateAndWrapMutableFile(JSContext* aCx,
+                                       IDBDatabase* aDatabase,
+                                       StructuredCloneFile& aFile,
+                                       const MutableFileData& aData,
+                                       JS::MutableHandle<JSObject*> aResult)
   {
     MOZ_ASSERT(NS_IsMainThread());
 
     nsRefPtr<FileInfo>& fileInfo = aFile.mFileInfo;
 
     nsRefPtr<IDBMutableFile> mutableFile = IDBMutableFile::Create(aData.name,
       aData.type, aDatabase, fileInfo.forget());
 
-    return mutableFile->WrapObject(aCx);
+    JS::Rooted<JSObject*> result(aCx, mutableFile->WrapObject(aCx));
+    if (NS_WARN_IF(!result)) {
+      return false;
+    }
+ 
+    aResult.set(result);
+    return true;
   }
 
   static JSObject* CreateAndWrapBlobOrFile(JSContext* aCx,
                                            IDBDatabase* aDatabase,
                                            StructuredCloneFile& aFile,
                                            const BlobOrFileData& aData)
   {
     MOZ_ASSERT(NS_IsMainThread());
@@ -877,23 +884,32 @@ public:
     return wrappedFile.toObjectOrNull();
   }
 };
 
 
 class CreateIndexDeserializationTraits
 {
 public:
-  static JSObject* CreateAndWrapMutableFile(JSContext* aCx,
-                                            IDBDatabase* aDatabase,
-                                            StructuredCloneFile& aFile,
-                                            const MutableFileData& aData)
+  static bool CreateAndWrapMutableFile(JSContext* aCx,
+                                       IDBDatabase* aDatabase,
+                                       StructuredCloneFile& aFile,
+                                       const MutableFileData& aData,
+                                       JS::MutableHandle<JSObject*> aResult)
   {
     // MutableFile can't be used in index creation, so just make a dummy object.
-    return JS_NewObject(aCx, nullptr, JS::NullPtr(), JS::NullPtr());
+    JS::Rooted<JSObject*> obj(aCx,
+      JS_NewObject(aCx, nullptr, JS::NullPtr(), JS::NullPtr()));
+
+    if (NS_WARN_IF(!obj)) {
+      return false;
+    }
+
+    aResult.set(obj);
+    return true;
   }
 
   static JSObject* CreateAndWrapBlobOrFile(JSContext* aCx,
                                            IDBDatabase* aDatabase,
                                            StructuredCloneFile& aFile,
                                            const BlobOrFileData& aData)
   {
     MOZ_ASSERT(aData.tag == SCTAG_DOM_FILE ||
@@ -1484,17 +1500,17 @@ IDBObjectStore::ReadBlobOrFile(JSStructu
     return false;
   }
   CopyUTF8toUTF16(name, aRetval->name);
 
   return true;
 }
 
 // static
-template <class DeserializationTraits>
+template <class Traits>
 JSObject*
 IDBObjectStore::StructuredCloneReadCallback(JSContext* aCx,
                                             JSStructuredCloneReader* aReader,
                                             uint32_t aTag,
                                             uint32_t aData,
                                             void* aClosure)
 {
   // We need to statically assert that our tag values are what we expect
@@ -1522,27 +1538,34 @@ IDBObjectStore::StructuredCloneReadCallb
     IDBDatabase* database = cloneReadInfo->mDatabase;
 
     if (aTag == SCTAG_DOM_MUTABLEFILE) {
       MutableFileData data;
       if (!ReadMutableFile(aReader, &data)) {
         return nullptr;
       }
 
-      return DeserializationTraits::CreateAndWrapMutableFile(aCx, database,
-                                                             file, data);
+      JS::Rooted<JSObject*> result(aCx);
+      if (NS_WARN_IF(!Traits::CreateAndWrapMutableFile(aCx,
+                                                       database,
+                                                       file,
+                                                       data,
+                                                       &result))) {
+        return nullptr;
+      }
+
+      return result;
     }
 
     BlobOrFileData data;
     if (!ReadBlobOrFile(aReader, aTag, &data)) {
       return nullptr;
     }
 
-    return DeserializationTraits::CreateAndWrapBlobOrFile(aCx, database,
-                                                          file, data);
+    return Traits::CreateAndWrapBlobOrFile(aCx, database, file, data);
   }
 
   const JSStructuredCloneCallbacks* runtimeCallbacks =
     js::GetContextStructuredCloneCallbacks(aCx);
 
   if (runtimeCallbacks) {
     return runtimeCallbacks->read(aCx, aReader, aTag, aData, nullptr);
   }