Bug 1258095 - patch 3/3 - Directory tasks should use FallibleArray, r=smaug
authorAndrea Marchesini <amarchesini@mozilla.com>
Wed, 30 Mar 2016 07:18:32 +0100
changeset 291019 7f1ca2749ce7060fef60202c3125cad9e448436b
parent 291018 554e58d8b27df2d58241421f8de97b1502e60702
child 291020 341c531db14221b3efe74518c8f7ff76bb99dc48
push id19656
push usergwagner@mozilla.com
push dateMon, 04 Apr 2016 13:43:23 +0000
treeherderb2g-inbound@e99061fde28a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1258095
milestone48.0a1
Bug 1258095 - patch 3/3 - Directory tasks should use FallibleArray, r=smaug
dom/filesystem/GetDirectoryListingTask.cpp
dom/filesystem/GetDirectoryListingTask.h
--- a/dom/filesystem/GetDirectoryListingTask.cpp
+++ b/dom/filesystem/GetDirectoryListingTask.cpp
@@ -167,28 +167,33 @@ GetDirectoryListingTask::SetSuccessReque
   MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!");
   MOZ_ASSERT(aValue.type() ==
                FileSystemResponseValue::TFileSystemDirectoryListingResponse);
 
   FileSystemDirectoryListingResponse r = aValue;
   for (uint32_t i = 0; i < r.data().Length(); ++i) {
     const FileSystemDirectoryListingResponseData& data = r.data()[i];
 
+    Directory::BlobImplOrDirectoryPath element;
+
     if (data.type() == FileSystemDirectoryListingResponseData::TFileSystemDirectoryListingResponseBlob) {
       PBlobChild* blob = data.get_FileSystemDirectoryListingResponseBlob().blobChild();
 
-      Directory::BlobImplOrDirectoryPath* element = mTargetData.AppendElement();
-      element->mType = Directory::BlobImplOrDirectoryPath::eBlobImpl;
-      element->mBlobImpl = static_cast<BlobChild*>(blob)->GetBlobImpl();
+      element.mType = Directory::BlobImplOrDirectoryPath::eBlobImpl;
+      element.mBlobImpl = static_cast<BlobChild*>(blob)->GetBlobImpl();
     } else {
       MOZ_ASSERT(data.type() == FileSystemDirectoryListingResponseData::TFileSystemDirectoryListingResponseDirectory);
 
-      Directory::BlobImplOrDirectoryPath* element = mTargetData.AppendElement();
-      element->mType = Directory::BlobImplOrDirectoryPath::eDirectoryPath;
-      element->mDirectoryPath = data.get_FileSystemDirectoryListingResponseDirectory().directoryRealPath();
+      element.mType = Directory::BlobImplOrDirectoryPath::eDirectoryPath;
+      element.mDirectoryPath = data.get_FileSystemDirectoryListingResponseDirectory().directoryRealPath();
+    }
+
+    if (!mTargetData.AppendElement(element, fallible)) {
+      aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
+      return;
     }
   }
 }
 
 nsresult
 GetDirectoryListingTask::Work()
 {
   MOZ_ASSERT(XRE_IsParentProcess(),
@@ -282,31 +287,34 @@ GetDirectoryListingTask::Work()
       if (NS_WARN_IF(NS_FAILED(currFile->GetLeafName(leafName)))) {
         continue;
       }
       if (leafName[0] == char16_t('.')) {
         continue;
       }
     }
 
+    Directory::BlobImplOrDirectoryPath element;
     if (isDir) {
       nsAutoString path;
       if (NS_WARN_IF(NS_FAILED(currFile->GetPath(path)))) {
         continue;
       }
 
-      Directory::BlobImplOrDirectoryPath* element = mTargetData.AppendElement();
-      element->mType = Directory::BlobImplOrDirectoryPath::eDirectoryPath;
-      element->mDirectoryPath = path;
+      element.mType = Directory::BlobImplOrDirectoryPath::eDirectoryPath;
+      element.mDirectoryPath = path;
     } else {
       BlobImplFile* impl = new BlobImplFile(currFile);
 
-      Directory::BlobImplOrDirectoryPath* element = mTargetData.AppendElement();
-      element->mType = Directory::BlobImplOrDirectoryPath::eBlobImpl;
-      element->mBlobImpl = impl;
+      element.mType = Directory::BlobImplOrDirectoryPath::eBlobImpl;
+      element.mBlobImpl = impl;
+    }
+
+    if (!mTargetData.AppendElement(element, fallible)) {
+      return NS_ERROR_OUT_OF_MEMORY;
     }
   }
   return NS_OK;
 }
 
 void
 GetDirectoryListingTask::HandlerCallback()
 {
--- a/dom/filesystem/GetDirectoryListingTask.h
+++ b/dom/filesystem/GetDirectoryListingTask.h
@@ -72,15 +72,15 @@ private:
 
   RefPtr<Promise> mPromise;
   nsCOMPtr<nsIFile> mTargetPath;
   nsString mFilters;
   Directory::DirectoryType mType;
 
   // We cannot store File or Directory objects bacause this object is created
   // on a different thread and File and Directory are not thread-safe.
-  nsTArray<Directory::BlobImplOrDirectoryPath> mTargetData;
+  FallibleTArray<Directory::BlobImplOrDirectoryPath> mTargetData;
 };
 
 } // namespace dom
 } // namespace mozilla
 
 #endif // mozilla_dom_GetDirectoryListing_h