Bug 1600283 - Remove uses of already_AddRefed. r=#dom-workers-and-storage draft
authorSimon Giesecke <sgiesecke@mozilla.com>
Wed, 04 Dec 2019 16:47:54 +0000
changeset 2515977 6dd3fd46bb224645f041f3a2ee4363984afe172f
parent 2515976 2440f9a3dda4be26ed7a156e96cb8002bdfdf74c
child 2515978 f7fff033e36e7637d7525cdb0e8a2bffef267703
push id460090
push userreviewbot
push dateWed, 04 Dec 2019 16:51:29 +0000
treeherdertry@35d310cdd9cf [default view] [failures only]
bugs1600283
milestone73.0a1
Bug 1600283 - Remove uses of already_AddRefed. r=#dom-workers-and-storage Differential Revision: https://phabricator.services.mozilla.com/D55479 Differential Diff: PHID-DIFF-so2uawe7lantbkogluim
dom/indexedDB/IDBIndex.cpp
dom/indexedDB/IDBIndex.h
--- a/dom/indexedDB/IDBIndex.cpp
+++ b/dom/indexedDB/IDBIndex.cpp
@@ -25,27 +25,23 @@
 
 namespace mozilla {
 namespace dom {
 
 using namespace mozilla::dom::indexedDB;
 
 namespace {
 
-already_AddRefed<IDBRequest> GenerateRequest(JSContext* aCx, IDBIndex* aIndex) {
+RefPtr<IDBRequest> GenerateRequest(JSContext* aCx, IDBIndex* aIndex) {
   MOZ_ASSERT(aIndex);
   aIndex->AssertIsOnOwningThread();
 
-  IDBTransaction* const transaction = aIndex->ObjectStore()->Transaction();
+  auto* const transaction = aIndex->ObjectStore()->Transaction();
 
-  RefPtr<IDBRequest> request =
-      IDBRequest::Create(aCx, aIndex, transaction->Database(), transaction);
-  MOZ_ASSERT(request);
-
-  return request.forget();
+  return IDBRequest::Create(aCx, aIndex, transaction->Database(), transaction);
 }
 
 }  // namespace
 
 IDBIndex::IDBIndex(IDBObjectStore* aObjectStore, const IndexMetadata* aMetadata)
     : mObjectStore(aObjectStore),
       mCachedKeyPath(JS::UndefinedValue()),
       mMetadata(aMetadata),
@@ -60,35 +56,83 @@ IDBIndex::~IDBIndex() {
   AssertIsOnOwningThread();
 
   if (mRooted) {
     mCachedKeyPath.setUndefined();
     mozilla::DropJSObjects(this);
   }
 }
 
-already_AddRefed<IDBIndex> IDBIndex::Create(IDBObjectStore* aObjectStore,
-                                            const IndexMetadata& aMetadata) {
+RefPtr<IDBIndex> IDBIndex::Create(IDBObjectStore* aObjectStore,
+                                  const IndexMetadata& aMetadata) {
   MOZ_ASSERT(aObjectStore);
   aObjectStore->AssertIsOnOwningThread();
 
-  RefPtr<IDBIndex> index = new IDBIndex(aObjectStore, &aMetadata);
-
-  return index.forget();
+  return new IDBIndex(aObjectStore, &aMetadata);
 }
 
 #ifdef DEBUG
 
 void IDBIndex::AssertIsOnOwningThread() const {
   MOZ_ASSERT(mObjectStore);
   mObjectStore->AssertIsOnOwningThread();
 }
 
 #endif  // DEBUG
 
+RefPtr<IDBRequest> IDBIndex::OpenCursor(JSContext* aCx,
+                                        JS::Handle<JS::Value> aRange,
+                                        IDBCursorDirection aDirection,
+                                        ErrorResult& aRv) {
+  AssertIsOnOwningThread();
+
+  return OpenCursorInternal(/* aKeysOnly */ false, aCx, aRange, aDirection,
+                            aRv);
+}
+
+RefPtr<IDBRequest> IDBIndex::OpenKeyCursor(JSContext* aCx,
+                                           JS::Handle<JS::Value> aRange,
+                                           IDBCursorDirection aDirection,
+                                           ErrorResult& aRv) {
+  AssertIsOnOwningThread();
+
+  return OpenCursorInternal(/* aKeysOnly */ true, aCx, aRange, aDirection, aRv);
+}
+
+RefPtr<IDBRequest> IDBIndex::Get(JSContext* aCx, JS::Handle<JS::Value> aKey,
+                                 ErrorResult& aRv) {
+  AssertIsOnOwningThread();
+
+  return GetInternal(/* aKeyOnly */ false, aCx, aKey, aRv);
+}
+
+RefPtr<IDBRequest> IDBIndex::GetKey(JSContext* aCx, JS::Handle<JS::Value> aKey,
+                                    ErrorResult& aRv) {
+  AssertIsOnOwningThread();
+
+  return GetInternal(/* aKeyOnly */ true, aCx, aKey, aRv);
+}
+
+RefPtr<IDBRequest> IDBIndex::GetAll(JSContext* aCx, JS::Handle<JS::Value> aKey,
+                                    const Optional<uint32_t>& aLimit,
+                                    ErrorResult& aRv) {
+  AssertIsOnOwningThread();
+
+  return GetAllInternal(/* aKeysOnly */ false, aCx, aKey, aLimit, aRv);
+}
+
+RefPtr<IDBRequest> IDBIndex::GetAllKeys(JSContext* aCx,
+                                        JS::Handle<JS::Value> aKey,
+                                        const Optional<uint32_t>& aLimit,
+                                        ErrorResult& aRv) {
+  AssertIsOnOwningThread();
+
+  return GetAllInternal(/* aKeysOnly */ true, aCx, aKey, aLimit, aRv);
+}
+
 void IDBIndex::RefreshMetadata(bool aMayDelete) {
   AssertIsOnOwningThread();
   MOZ_ASSERT_IF(mDeletedMetadata, mMetadata == mDeletedMetadata);
 
   const auto& indexes = mObjectStore->Spec().indexes();
   const auto foundIt = std::find_if(
       indexes.cbegin(), indexes.cend(),
       [id = Id()](const auto& metadata) { return metadata.id() == id; });
@@ -254,20 +298,19 @@ void IDBIndex::GetKeyPath(JSContext* aCx
   if (mCachedKeyPath.isGCThing()) {
     mozilla::HoldJSObjects(this);
     mRooted = true;
   }
 
   aResult.set(mCachedKeyPath);
 }
 
-already_AddRefed<IDBRequest> IDBIndex::GetInternal(bool aKeyOnly,
-                                                   JSContext* aCx,
-                                                   JS::Handle<JS::Value> aKey,
-                                                   ErrorResult& aRv) {
+RefPtr<IDBRequest> IDBIndex::GetInternal(bool aKeyOnly, JSContext* aCx,
+                                         JS::Handle<JS::Value> aKey,
+                                         ErrorResult& aRv) {
   AssertIsOnOwningThread();
 
   if (mDeletedMetadata) {
     aRv.Throw(NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR);
     return nullptr;
   }
 
   IDBTransaction* transaction = mObjectStore->Transaction();
@@ -297,18 +340,17 @@ already_AddRefed<IDBRequest> IDBIndex::G
   RequestParams params;
 
   if (aKeyOnly) {
     params = IndexGetKeyParams(objectStoreId, indexId, serializedKeyRange);
   } else {
     params = IndexGetParams(objectStoreId, indexId, serializedKeyRange);
   }
 
-  RefPtr<IDBRequest> request = GenerateRequest(aCx, this);
-  MOZ_ASSERT(request);
+  auto request = GenerateRequest(aCx, this);
 
   if (aKeyOnly) {
     IDB_LOG_MARK_CHILD_TRANSACTION_REQUEST(
         "database(%s).transaction(%s).objectStore(%s).index(%s)."
         "getKey(%s)",
         "IDBIndex.getKey()", transaction->LoggingSerialNumber(),
         request->LoggingSerialNumber(),
         IDB_LOG_STRINGIFY(transaction->Database()),
@@ -327,22 +369,23 @@ already_AddRefed<IDBRequest> IDBIndex::G
 
   // TODO: This is necessary to preserve request ordering only. Proper
   // sequencing of requests should be done in a more sophisticated manner that
   // doesn't require invalidating cursor caches (Bug 1580499).
   transaction->InvalidateCursorCaches();
 
   transaction->StartRequest(request, params);
 
-  return request.forget();
+  return request;
 }
 
-already_AddRefed<IDBRequest> IDBIndex::GetAllInternal(
-    bool aKeysOnly, JSContext* aCx, JS::Handle<JS::Value> aKey,
-    const Optional<uint32_t>& aLimit, ErrorResult& aRv) {
+RefPtr<IDBRequest> IDBIndex::GetAllInternal(bool aKeysOnly, JSContext* aCx,
+                                            JS::Handle<JS::Value> aKey,
+                                            const Optional<uint32_t>& aLimit,
+                                            ErrorResult& aRv) {
   AssertIsOnOwningThread();
 
   if (mDeletedMetadata) {
     aRv.Throw(NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR);
     return nullptr;
   }
 
   IDBTransaction* transaction = mObjectStore->Transaction();
@@ -370,18 +413,17 @@ already_AddRefed<IDBRequest> IDBIndex::G
   const uint32_t limit = aLimit.WasPassed() ? aLimit.Value() : 0;
 
   const auto& params =
       aKeysOnly ? RequestParams{IndexGetAllKeysParams(objectStoreId, indexId,
                                                       optionalKeyRange, limit)}
                 : RequestParams{IndexGetAllParams(objectStoreId, indexId,
                                                   optionalKeyRange, limit)};
 
-  RefPtr<IDBRequest> request = GenerateRequest(aCx, this);
-  MOZ_ASSERT(request);
+  auto request = GenerateRequest(aCx, this);
 
   if (aKeysOnly) {
     IDB_LOG_MARK_CHILD_TRANSACTION_REQUEST(
         "database(%s).transaction(%s).objectStore(%s).index(%s)."
         "getAllKeys(%s, %s)",
         "IDBIndex.getAllKeys()", transaction->LoggingSerialNumber(),
         request->LoggingSerialNumber(),
         IDB_LOG_STRINGIFY(transaction->Database()),
@@ -402,22 +444,23 @@ already_AddRefed<IDBRequest> IDBIndex::G
 
   // TODO: This is necessary to preserve request ordering only. Proper
   // sequencing of requests should be done in a more sophisticated manner that
   // doesn't require invalidating cursor caches (Bug 1580499).
   transaction->InvalidateCursorCaches();
 
   transaction->StartRequest(request, params);
 
-  return request.forget();
+  return request;
 }
 
-already_AddRefed<IDBRequest> IDBIndex::OpenCursorInternal(
-    bool aKeysOnly, JSContext* aCx, JS::Handle<JS::Value> aRange,
-    IDBCursorDirection aDirection, ErrorResult& aRv) {
+RefPtr<IDBRequest> IDBIndex::OpenCursorInternal(bool aKeysOnly, JSContext* aCx,
+                                                JS::Handle<JS::Value> aRange,
+                                                IDBCursorDirection aDirection,
+                                                ErrorResult& aRv) {
   AssertIsOnOwningThread();
 
   if (mDeletedMetadata) {
     aRv.Throw(NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR);
     return nullptr;
   }
 
   IDBTransaction* transaction = mObjectStore->Transaction();
@@ -449,18 +492,17 @@ already_AddRefed<IDBRequest> IDBIndex::O
 
   const CommonIndexOpenCursorParams commonIndexParams = {
       {objectStoreId, std::move(optionalKeyRange), direction}, indexId};
 
   const auto params =
       aKeysOnly ? OpenCursorParams{IndexOpenKeyCursorParams{commonIndexParams}}
                 : OpenCursorParams{IndexOpenCursorParams{commonIndexParams}};
 
-  RefPtr<IDBRequest> request = GenerateRequest(aCx, this);
-  MOZ_ASSERT(request);
+  auto request = GenerateRequest(aCx, this);
 
   if (aKeysOnly) {
     IDB_LOG_MARK_CHILD_TRANSACTION_REQUEST(
         "database(%s).transaction(%s).objectStore(%s).index(%s)."
         "openKeyCursor(%s, %s)",
         "IDBIndex.openKeyCursor()", transaction->LoggingSerialNumber(),
         request->LoggingSerialNumber(),
         IDB_LOG_STRINGIFY(transaction->Database()),
@@ -484,22 +526,21 @@ already_AddRefed<IDBRequest> IDBIndex::O
 
   // TODO: This is necessary to preserve request ordering only. Proper
   // sequencing of requests should be done in a more sophisticated manner that
   // doesn't require invalidating cursor caches (Bug 1580499).
   transaction->InvalidateCursorCaches();
 
   mObjectStore->Transaction()->OpenCursor(actor, params);
 
-  return request.forget();
+  return request;
 }
 
-already_AddRefed<IDBRequest> IDBIndex::Count(JSContext* aCx,
-                                             JS::Handle<JS::Value> aKey,
-                                             ErrorResult& aRv) {
+RefPtr<IDBRequest> IDBIndex::Count(JSContext* aCx, JS::Handle<JS::Value> aKey,
+                                   ErrorResult& aRv) {
   AssertIsOnOwningThread();
 
   if (mDeletedMetadata) {
     aRv.Throw(NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR);
     return nullptr;
   }
 
   IDBTransaction* const transaction = mObjectStore->Transaction();
@@ -519,18 +560,17 @@ already_AddRefed<IDBRequest> IDBIndex::C
   params.indexId() = Id();
 
   if (keyRange) {
     SerializedKeyRange serializedKeyRange;
     keyRange->ToSerialized(serializedKeyRange);
     params.optionalKeyRange().emplace(serializedKeyRange);
   }
 
-  RefPtr<IDBRequest> request = GenerateRequest(aCx, this);
-  MOZ_ASSERT(request);
+  auto request = GenerateRequest(aCx, this);
 
   IDB_LOG_MARK_CHILD_TRANSACTION_REQUEST(
       "database(%s).transaction(%s).objectStore(%s).index(%s)."
       "count(%s)",
       "IDBIndex.count()", transaction->LoggingSerialNumber(),
       request->LoggingSerialNumber(),
       IDB_LOG_STRINGIFY(transaction->Database()),
       IDB_LOG_STRINGIFY(transaction), IDB_LOG_STRINGIFY(mObjectStore),
@@ -538,17 +578,17 @@ already_AddRefed<IDBRequest> IDBIndex::C
 
   // TODO: This is necessary to preserve request ordering only. Proper
   // sequencing of requests should be done in a more sophisticated manner that
   // doesn't require invalidating cursor caches (Bug 1580499).
   transaction->InvalidateCursorCaches();
 
   transaction->StartRequest(request, params);
 
-  return request.forget();
+  return request;
 }
 
 NS_IMPL_CYCLE_COLLECTING_ADDREF(IDBIndex)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(IDBIndex)
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(IDBIndex)
   NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
   NS_INTERFACE_MAP_ENTRY(nsISupports)
--- a/dom/indexedDB/IDBIndex.h
+++ b/dom/indexedDB/IDBIndex.h
@@ -50,17 +50,17 @@ class IDBIndex final : public nsISupport
 
   const int64_t mId;
   bool mRooted;
 
  public:
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(IDBIndex)
 
-  static already_AddRefed<IDBIndex> Create(
+  static MOZ_MUST_USE RefPtr<IDBIndex> Create(
       IDBObjectStore* aObjectStore, const indexedDB::IndexMetadata& aMetadata);
 
   int64_t Id() const {
     AssertIsOnOwningThread();
 
     return mId;
   }
 
@@ -89,71 +89,47 @@ class IDBIndex final : public nsISupport
 
   void GetName(nsString& aName) const { aName = Name(); }
 
   void SetName(const nsAString& aName, ErrorResult& aRv);
 
   void GetKeyPath(JSContext* aCx, JS::MutableHandle<JS::Value> aResult,
                   ErrorResult& aRv);
 
-  already_AddRefed<IDBRequest> OpenCursor(JSContext* aCx,
-                                          JS::Handle<JS::Value> aRange,
-                                          IDBCursorDirection aDirection,
-                                          ErrorResult& aRv) {
-    AssertIsOnOwningThread();
-
-    return OpenCursorInternal(/* aKeysOnly */ false, aCx, aRange, aDirection,
-                              aRv);
-  }
-
-  already_AddRefed<IDBRequest> OpenKeyCursor(JSContext* aCx,
+  MOZ_MUST_USE RefPtr<IDBRequest> OpenCursor(JSContext* aCx,
                                              JS::Handle<JS::Value> aRange,
                                              IDBCursorDirection aDirection,
-                                             ErrorResult& aRv) {
-    AssertIsOnOwningThread();
-
-    return OpenCursorInternal(/* aKeysOnly */ true, aCx, aRange, aDirection,
-                              aRv);
-  }
+                                             ErrorResult& aRv);
 
-  already_AddRefed<IDBRequest> Get(JSContext* aCx, JS::Handle<JS::Value> aKey,
-                                   ErrorResult& aRv) {
-    AssertIsOnOwningThread();
+  MOZ_MUST_USE RefPtr<IDBRequest> OpenKeyCursor(JSContext* aCx,
+                                                JS::Handle<JS::Value> aRange,
+                                                IDBCursorDirection aDirection,
+                                                ErrorResult& aRv);
 
-    return GetInternal(/* aKeyOnly */ false, aCx, aKey, aRv);
-  }
-
-  already_AddRefed<IDBRequest> GetKey(JSContext* aCx,
+  MOZ_MUST_USE RefPtr<IDBRequest> Get(JSContext* aCx,
                                       JS::Handle<JS::Value> aKey,
-                                      ErrorResult& aRv) {
-    AssertIsOnOwningThread();
+                                      ErrorResult& aRv);
 
-    return GetInternal(/* aKeyOnly */ true, aCx, aKey, aRv);
-  }
-
-  already_AddRefed<IDBRequest> Count(JSContext* aCx, JS::Handle<JS::Value> aKey,
-                                     ErrorResult& aRv);
+  MOZ_MUST_USE RefPtr<IDBRequest> GetKey(JSContext* aCx,
+                                         JS::Handle<JS::Value> aKey,
+                                         ErrorResult& aRv);
 
-  already_AddRefed<IDBRequest> GetAll(JSContext* aCx,
-                                      JS::Handle<JS::Value> aKey,
-                                      const Optional<uint32_t>& aLimit,
-                                      ErrorResult& aRv) {
-    AssertIsOnOwningThread();
+  MOZ_MUST_USE RefPtr<IDBRequest> Count(JSContext* aCx,
+                                        JS::Handle<JS::Value> aKey,
+                                        ErrorResult& aRv);
 
-    return GetAllInternal(/* aKeysOnly */ false, aCx, aKey, aLimit, aRv);
-  }
+  MOZ_MUST_USE RefPtr<IDBRequest> GetAll(JSContext* aCx,
+                                         JS::Handle<JS::Value> aKey,
+                                         const Optional<uint32_t>& aLimit,
+                                         ErrorResult& aRv);
 
-  already_AddRefed<IDBRequest> GetAllKeys(JSContext* aCx,
-                                          JS::Handle<JS::Value> aKey,
-                                          const Optional<uint32_t>& aLimit,
-                                          ErrorResult& aRv) {
-    AssertIsOnOwningThread();
-
-    return GetAllInternal(/* aKeysOnly */ true, aCx, aKey, aLimit, aRv);
-  }
+  MOZ_MUST_USE RefPtr<IDBRequest> GetAllKeys(JSContext* aCx,
+                                             JS::Handle<JS::Value> aKey,
+                                             const Optional<uint32_t>& aLimit,
+                                             ErrorResult& aRv);
 
   void RefreshMetadata(bool aMayDelete);
 
   void NoteDeletion();
 
   bool IsDeleted() const {
     AssertIsOnOwningThread();
 
@@ -173,28 +149,25 @@ class IDBIndex final : public nsISupport
                                JS::Handle<JSObject*> aGivenProto) override;
 
  private:
   IDBIndex(IDBObjectStore* aObjectStore,
            const indexedDB::IndexMetadata* aMetadata);
 
   ~IDBIndex();
 
-  already_AddRefed<IDBRequest> GetInternal(bool aKeyOnly, JSContext* aCx,
-                                           JS::Handle<JS::Value> aKey,
-                                           ErrorResult& aRv);
-
-  already_AddRefed<IDBRequest> GetAllInternal(bool aKeysOnly, JSContext* aCx,
+  MOZ_MUST_USE RefPtr<IDBRequest> GetInternal(bool aKeyOnly, JSContext* aCx,
                                               JS::Handle<JS::Value> aKey,
-                                              const Optional<uint32_t>& aLimit,
                                               ErrorResult& aRv);
 
-  already_AddRefed<IDBRequest> OpenCursorInternal(bool aKeysOnly,
-                                                  JSContext* aCx,
-                                                  JS::Handle<JS::Value> aRange,
-                                                  IDBCursorDirection aDirection,
-                                                  ErrorResult& aRv);
+  MOZ_MUST_USE RefPtr<IDBRequest> GetAllInternal(
+      bool aKeysOnly, JSContext* aCx, JS::Handle<JS::Value> aKey,
+      const Optional<uint32_t>& aLimit, ErrorResult& aRv);
+
+  MOZ_MUST_USE RefPtr<IDBRequest> OpenCursorInternal(
+      bool aKeysOnly, JSContext* aCx, JS::Handle<JS::Value> aRange,
+      IDBCursorDirection aDirection, ErrorResult& aRv);
 };
 
 }  // namespace dom
 }  // namespace mozilla
 
 #endif  // mozilla_dom_idbindex_h__