Bug 1600283 - Remove uses of already_AddRefed. r=#dom-workers-and-storage draft
authorSimon Giesecke <sgiesecke@mozilla.com>
Wed, 04 Dec 2019 16:48:10 +0000
changeset 2515980 7e30f7b9d9a25a39ca55e630c34e2e676a0712fc
parent 2515979 27a8b5ded3a921b8de13db22fd3b1f8def422898
child 2515981 1737bc9309cf76c6498d01df6f83b50fcd83aef7
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/D55483 Differential Diff: PHID-DIFF-ppqjietzd56eq74gp2fq
dom/indexedDB/IDBIndex.cpp
dom/indexedDB/IDBKeyRange.cpp
dom/indexedDB/IDBKeyRange.h
dom/indexedDB/IDBObjectStore.cpp
--- a/dom/indexedDB/IDBIndex.cpp
+++ b/dom/indexedDB/IDBIndex.cpp
@@ -315,17 +315,17 @@ RefPtr<IDBRequest> IDBIndex::GetInternal
 
   IDBTransaction* transaction = mObjectStore->Transaction();
   if (!transaction->CanAcceptRequests()) {
     aRv.Throw(NS_ERROR_DOM_INDEXEDDB_TRANSACTION_INACTIVE_ERR);
     return nullptr;
   }
 
   RefPtr<IDBKeyRange> keyRange;
-  IDBKeyRange::FromJSVal(aCx, aKey, getter_AddRefs(keyRange), aRv);
+  IDBKeyRange::FromJSVal(aCx, aKey, &keyRange, aRv);
   if (NS_WARN_IF(aRv.Failed())) {
     return nullptr;
   }
 
   if (!keyRange) {
     // Must specify a key or keyRange for get() and getKey().
     aRv.Throw(NS_ERROR_DOM_INDEXEDDB_KEY_ERR);
     return nullptr;
@@ -390,17 +390,17 @@ RefPtr<IDBRequest> IDBIndex::GetAllInter
 
   IDBTransaction* transaction = mObjectStore->Transaction();
   if (!transaction->CanAcceptRequests()) {
     aRv.Throw(NS_ERROR_DOM_INDEXEDDB_TRANSACTION_INACTIVE_ERR);
     return nullptr;
   }
 
   RefPtr<IDBKeyRange> keyRange;
-  IDBKeyRange::FromJSVal(aCx, aKey, getter_AddRefs(keyRange), aRv);
+  IDBKeyRange::FromJSVal(aCx, aKey, &keyRange, aRv);
   if (NS_WARN_IF(aRv.Failed())) {
     return nullptr;
   }
 
   const int64_t objectStoreId = mObjectStore->Id();
   const int64_t indexId = Id();
 
   Maybe<SerializedKeyRange> optionalKeyRange;
@@ -465,17 +465,17 @@ RefPtr<IDBRequest> IDBIndex::OpenCursorI
 
   IDBTransaction* transaction = mObjectStore->Transaction();
   if (!transaction->CanAcceptRequests()) {
     aRv.Throw(NS_ERROR_DOM_INDEXEDDB_TRANSACTION_INACTIVE_ERR);
     return nullptr;
   }
 
   RefPtr<IDBKeyRange> keyRange;
-  IDBKeyRange::FromJSVal(aCx, aRange, getter_AddRefs(keyRange), aRv);
+  IDBKeyRange::FromJSVal(aCx, aRange, &keyRange, aRv);
   if (NS_WARN_IF(aRv.Failed())) {
     return nullptr;
   }
 
   const int64_t objectStoreId = mObjectStore->Id();
   const int64_t indexId = Id();
 
   Maybe<SerializedKeyRange> optionalKeyRange;
@@ -545,17 +545,17 @@ RefPtr<IDBRequest> IDBIndex::Count(JSCon
 
   IDBTransaction* const transaction = mObjectStore->Transaction();
   if (!transaction->CanAcceptRequests()) {
     aRv.Throw(NS_ERROR_DOM_INDEXEDDB_TRANSACTION_INACTIVE_ERR);
     return nullptr;
   }
 
   RefPtr<IDBKeyRange> keyRange;
-  IDBKeyRange::FromJSVal(aCx, aKey, getter_AddRefs(keyRange), aRv);
+  IDBKeyRange::FromJSVal(aCx, aKey, &keyRange, aRv);
   if (aRv.Failed()) {
     return nullptr;
   }
 
   IndexCountParams params;
   params.objectStoreId() = mObjectStore->Id();
   params.indexId() = Id();
 
--- a/dom/indexedDB/IDBKeyRange.cpp
+++ b/dom/indexedDB/IDBKeyRange.cpp
@@ -58,55 +58,56 @@ IDBLocaleAwareKeyRange::IDBLocaleAwareKe
     : IDBKeyRange(aGlobal, aLowerOpen, aUpperOpen, aIsOnly) {
   AssertIsOnOwningThread();
 }
 
 IDBLocaleAwareKeyRange::~IDBLocaleAwareKeyRange() { DropJSObjects(); }
 
 // static
 void IDBKeyRange::FromJSVal(JSContext* aCx, JS::Handle<JS::Value> aVal,
-                            IDBKeyRange** aKeyRange, ErrorResult& aRv) {
+                            RefPtr<IDBKeyRange>* aKeyRange, ErrorResult& aRv) {
   MOZ_ASSERT_IF(!aCx, aVal.isUndefined());
+  MOZ_ASSERT(aKeyRange);
 
   RefPtr<IDBKeyRange> keyRange;
 
   if (aVal.isNullOrUndefined()) {
     // undefined and null returns no IDBKeyRange.
-    keyRange.forget(aKeyRange);
+    *aKeyRange = std::move(keyRange);
     return;
   }
 
   JS::Rooted<JSObject*> obj(aCx, aVal.isObject() ? &aVal.toObject() : nullptr);
 
   // Unwrap an IDBKeyRange object if possible.
   if (obj && NS_SUCCEEDED(UNWRAP_OBJECT(IDBKeyRange, obj, keyRange))) {
     MOZ_ASSERT(keyRange);
-    keyRange.forget(aKeyRange);
+    *aKeyRange = std::move(keyRange);
     return;
   }
 
   // A valid key returns an 'only' IDBKeyRange.
   keyRange = new IDBKeyRange(nullptr, false, false, true);
   GetKeyFromJSVal(aCx, aVal, keyRange->Lower(), aRv);
   if (!aRv.Failed()) {
-    keyRange.forget(aKeyRange);
+    *aKeyRange = std::move(keyRange);
   }
 }
 
 // static
-already_AddRefed<IDBKeyRange> IDBKeyRange::FromSerialized(
+RefPtr<IDBKeyRange> IDBKeyRange::FromSerialized(
     const SerializedKeyRange& aKeyRange) {
   RefPtr<IDBKeyRange> keyRange =
       new IDBKeyRange(nullptr, aKeyRange.lowerOpen(), aKeyRange.upperOpen(),
                       aKeyRange.isOnly());
   keyRange->Lower() = aKeyRange.lower();
   if (!keyRange->IsOnly()) {
     keyRange->Upper() = aKeyRange.upper();
   }
-  return keyRange.forget();
+  return keyRange;
 }
 
 void IDBKeyRange::ToSerialized(SerializedKeyRange& aKeyRange) const {
   aKeyRange.lowerOpen() = LowerOpen();
   aKeyRange.upperOpen() = UpperOpen();
   aKeyRange.isOnly() = IsOnly();
 
   aKeyRange.lower() = Lower();
@@ -244,67 +245,66 @@ bool IDBKeyRange::Includes(JSContext* aC
         break;
     }
   }
 
   return true;
 }
 
 // static
-already_AddRefed<IDBKeyRange> IDBKeyRange::Only(const GlobalObject& aGlobal,
-                                                JS::Handle<JS::Value> aValue,
-                                                ErrorResult& aRv) {
+RefPtr<IDBKeyRange> IDBKeyRange::Only(const GlobalObject& aGlobal,
+                                      JS::Handle<JS::Value> aValue,
+                                      ErrorResult& aRv) {
   RefPtr<IDBKeyRange> keyRange =
       new IDBKeyRange(aGlobal.GetAsSupports(), false, false, true);
 
   GetKeyFromJSVal(aGlobal.Context(), aValue, keyRange->Lower(), aRv);
   if (aRv.Failed()) {
     return nullptr;
   }
 
-  return keyRange.forget();
+  return keyRange;
 }
 
 // static
-already_AddRefed<IDBKeyRange> IDBKeyRange::LowerBound(
-    const GlobalObject& aGlobal, JS::Handle<JS::Value> aValue, bool aOpen,
-    ErrorResult& aRv) {
+RefPtr<IDBKeyRange> IDBKeyRange::LowerBound(const GlobalObject& aGlobal,
+                                            JS::Handle<JS::Value> aValue,
+                                            bool aOpen, ErrorResult& aRv) {
   RefPtr<IDBKeyRange> keyRange =
       new IDBKeyRange(aGlobal.GetAsSupports(), aOpen, true, false);
 
   GetKeyFromJSVal(aGlobal.Context(), aValue, keyRange->Lower(), aRv);
   if (aRv.Failed()) {
     return nullptr;
   }
 
-  return keyRange.forget();
+  return keyRange;
 }
 
 // static
-already_AddRefed<IDBKeyRange> IDBKeyRange::UpperBound(
-    const GlobalObject& aGlobal, JS::Handle<JS::Value> aValue, bool aOpen,
-    ErrorResult& aRv) {
+RefPtr<IDBKeyRange> IDBKeyRange::UpperBound(const GlobalObject& aGlobal,
+                                            JS::Handle<JS::Value> aValue,
+                                            bool aOpen, ErrorResult& aRv) {
   RefPtr<IDBKeyRange> keyRange =
       new IDBKeyRange(aGlobal.GetAsSupports(), true, aOpen, false);
 
   GetKeyFromJSVal(aGlobal.Context(), aValue, keyRange->Upper(), aRv);
   if (aRv.Failed()) {
     return nullptr;
   }
 
-  return keyRange.forget();
+  return keyRange;
 }
 
 // static
-already_AddRefed<IDBKeyRange> IDBKeyRange::Bound(const GlobalObject& aGlobal,
-                                                 JS::Handle<JS::Value> aLower,
-                                                 JS::Handle<JS::Value> aUpper,
-                                                 bool aLowerOpen,
-                                                 bool aUpperOpen,
-                                                 ErrorResult& aRv) {
+RefPtr<IDBKeyRange> IDBKeyRange::Bound(const GlobalObject& aGlobal,
+                                       JS::Handle<JS::Value> aLower,
+                                       JS::Handle<JS::Value> aUpper,
+                                       bool aLowerOpen, bool aUpperOpen,
+                                       ErrorResult& aRv) {
   RefPtr<IDBKeyRange> keyRange =
       new IDBKeyRange(aGlobal.GetAsSupports(), aLowerOpen, aUpperOpen, false);
 
   GetKeyFromJSVal(aGlobal.Context(), aLower, keyRange->Lower(), aRv);
   if (aRv.Failed()) {
     return nullptr;
   }
 
@@ -314,21 +314,21 @@ already_AddRefed<IDBKeyRange> IDBKeyRang
   }
 
   if (keyRange->Lower() > keyRange->Upper() ||
       (keyRange->Lower() == keyRange->Upper() && (aLowerOpen || aUpperOpen))) {
     aRv.Throw(NS_ERROR_DOM_INDEXEDDB_DATA_ERR);
     return nullptr;
   }
 
-  return keyRange.forget();
+  return keyRange;
 }
 
 // static
-already_AddRefed<IDBLocaleAwareKeyRange> IDBLocaleAwareKeyRange::Bound(
+RefPtr<IDBLocaleAwareKeyRange> IDBLocaleAwareKeyRange::Bound(
     const GlobalObject& aGlobal, JS::Handle<JS::Value> aLower,
     JS::Handle<JS::Value> aUpper, bool aLowerOpen, bool aUpperOpen,
     ErrorResult& aRv) {
   RefPtr<IDBLocaleAwareKeyRange> keyRange = new IDBLocaleAwareKeyRange(
       aGlobal.GetAsSupports(), aLowerOpen, aUpperOpen, false);
 
   GetKeyFromJSVal(aGlobal.Context(), aLower, keyRange->Lower(), aRv);
   if (aRv.Failed()) {
@@ -340,13 +340,13 @@ already_AddRefed<IDBLocaleAwareKeyRange>
     return nullptr;
   }
 
   if (keyRange->Lower() == keyRange->Upper() && (aLowerOpen || aUpperOpen)) {
     aRv.Throw(NS_ERROR_DOM_INDEXEDDB_DATA_ERR);
     return nullptr;
   }
 
-  return keyRange.forget();
+  return keyRange;
 }
 
 }  // namespace dom
 }  // namespace mozilla
--- a/dom/indexedDB/IDBKeyRange.h
+++ b/dom/indexedDB/IDBKeyRange.h
@@ -47,38 +47,39 @@ class IDBKeyRange : public nsISupports {
   bool mRooted : 1;
 
  public:
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(IDBKeyRange)
 
   // aCx is allowed to be null, but only if aVal.isUndefined().
   static void FromJSVal(JSContext* aCx, JS::Handle<JS::Value> aVal,
-                        IDBKeyRange** aKeyRange, ErrorResult& aRv);
+                        RefPtr<IDBKeyRange>* aKeyRange, ErrorResult& aRv);
 
-  static already_AddRefed<IDBKeyRange> FromSerialized(
+  static MOZ_MUST_USE RefPtr<IDBKeyRange> FromSerialized(
       const indexedDB::SerializedKeyRange& aKeyRange);
 
-  static already_AddRefed<IDBKeyRange> Only(const GlobalObject& aGlobal,
-                                            JS::Handle<JS::Value> aValue,
-                                            ErrorResult& aRv);
+  static MOZ_MUST_USE RefPtr<IDBKeyRange> Only(const GlobalObject& aGlobal,
+                                               JS::Handle<JS::Value> aValue,
+                                               ErrorResult& aRv);
 
-  static already_AddRefed<IDBKeyRange> LowerBound(const GlobalObject& aGlobal,
-                                                  JS::Handle<JS::Value> aValue,
-                                                  bool aOpen, ErrorResult& aRv);
+  static MOZ_MUST_USE RefPtr<IDBKeyRange> LowerBound(
+      const GlobalObject& aGlobal, JS::Handle<JS::Value> aValue, bool aOpen,
+      ErrorResult& aRv);
 
-  static already_AddRefed<IDBKeyRange> UpperBound(const GlobalObject& aGlobal,
-                                                  JS::Handle<JS::Value> aValue,
-                                                  bool aOpen, ErrorResult& aRv);
+  static MOZ_MUST_USE RefPtr<IDBKeyRange> UpperBound(
+      const GlobalObject& aGlobal, JS::Handle<JS::Value> aValue, bool aOpen,
+      ErrorResult& aRv);
 
-  static already_AddRefed<IDBKeyRange> Bound(const GlobalObject& aGlobal,
-                                             JS::Handle<JS::Value> aLower,
-                                             JS::Handle<JS::Value> aUpper,
-                                             bool aLowerOpen, bool aUpperOpen,
-                                             ErrorResult& aRv);
+  static MOZ_MUST_USE RefPtr<IDBKeyRange> Bound(const GlobalObject& aGlobal,
+                                                JS::Handle<JS::Value> aLower,
+                                                JS::Handle<JS::Value> aUpper,
+                                                bool aLowerOpen,
+                                                bool aUpperOpen,
+                                                ErrorResult& aRv);
 
   void AssertIsOnOwningThread() const { NS_ASSERT_OWNINGTHREAD(IDBKeyRange); }
 
   void ToSerialized(indexedDB::SerializedKeyRange& aKeyRange) const;
 
   const indexedDB::Key& Lower() const { return mLower; }
 
   indexedDB::Key& Lower() { return mLower; }
@@ -119,17 +120,17 @@ class IDBKeyRange : public nsISupports {
 
 class IDBLocaleAwareKeyRange final : public IDBKeyRange {
   IDBLocaleAwareKeyRange(nsISupports* aGlobal, bool aLowerOpen, bool aUpperOpen,
                          bool aIsOnly);
 
   ~IDBLocaleAwareKeyRange();
 
  public:
-  static already_AddRefed<IDBLocaleAwareKeyRange> Bound(
+  static MOZ_MUST_USE RefPtr<IDBLocaleAwareKeyRange> Bound(
       const GlobalObject& aGlobal, JS::Handle<JS::Value> aLower,
       JS::Handle<JS::Value> aUpper, bool aLowerOpen, bool aUpperOpen,
       ErrorResult& aRv);
 
   NS_INLINE_DECL_REFCOUNTING_INHERITED(IDBLocaleAwareKeyRange, IDBKeyRange)
 
   // WebIDL
   bool WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto,
--- a/dom/indexedDB/IDBObjectStore.cpp
+++ b/dom/indexedDB/IDBObjectStore.cpp
@@ -1689,17 +1689,17 @@ RefPtr<IDBRequest> IDBObjectStore::GetAl
   }
 
   if (!mTransaction->CanAcceptRequests()) {
     aRv.Throw(NS_ERROR_DOM_INDEXEDDB_TRANSACTION_INACTIVE_ERR);
     return nullptr;
   }
 
   RefPtr<IDBKeyRange> keyRange;
-  IDBKeyRange::FromJSVal(aCx, aKey, getter_AddRefs(keyRange), aRv);
+  IDBKeyRange::FromJSVal(aCx, aKey, &keyRange, aRv);
   if (NS_WARN_IF(aRv.Failed())) {
     return nullptr;
   }
 
   const int64_t id = Id();
 
   Maybe<SerializedKeyRange> optionalKeyRange;
   if (keyRange) {
@@ -2008,17 +2008,17 @@ RefPtr<IDBRequest> IDBObjectStore::GetIn
   }
 
   if (!mTransaction->CanAcceptRequests()) {
     aRv.Throw(NS_ERROR_DOM_INDEXEDDB_TRANSACTION_INACTIVE_ERR);
     return nullptr;
   }
 
   RefPtr<IDBKeyRange> keyRange;
-  IDBKeyRange::FromJSVal(aCx, aKey, getter_AddRefs(keyRange), aRv);
+  IDBKeyRange::FromJSVal(aCx, aKey, &keyRange, aRv);
   if (aRv.Failed()) {
     return nullptr;
   }
 
   if (!keyRange) {
     // Must specify a key or keyRange for get().
     aRv.Throw(NS_ERROR_DOM_INDEXEDDB_KEY_ERR);
     return nullptr;
@@ -2070,17 +2070,17 @@ RefPtr<IDBRequest> IDBObjectStore::Delet
   }
 
   if (!mTransaction->IsWriteAllowed()) {
     aRv.Throw(NS_ERROR_DOM_INDEXEDDB_READ_ONLY_ERR);
     return nullptr;
   }
 
   RefPtr<IDBKeyRange> keyRange;
-  IDBKeyRange::FromJSVal(aCx, aKey, getter_AddRefs(keyRange), aRv);
+  IDBKeyRange::FromJSVal(aCx, aKey, &keyRange, aRv);
   if (NS_WARN_IF((aRv.Failed()))) {
     return nullptr;
   }
 
   if (!keyRange) {
     // Must specify a key or keyRange for delete().
     aRv.Throw(NS_ERROR_DOM_INDEXEDDB_KEY_ERR);
     return nullptr;
@@ -2295,17 +2295,17 @@ RefPtr<IDBRequest> IDBObjectStore::Count
   }
 
   if (!mTransaction->CanAcceptRequests()) {
     aRv.Throw(NS_ERROR_DOM_INDEXEDDB_TRANSACTION_INACTIVE_ERR);
     return nullptr;
   }
 
   RefPtr<IDBKeyRange> keyRange;
-  IDBKeyRange::FromJSVal(aCx, aKey, getter_AddRefs(keyRange), aRv);
+  IDBKeyRange::FromJSVal(aCx, aKey, &keyRange, aRv);
   if (aRv.Failed()) {
     return nullptr;
   }
 
   ObjectStoreCountParams params;
   params.objectStoreId() = Id();
 
   if (keyRange) {
@@ -2346,17 +2346,17 @@ RefPtr<IDBRequest> IDBObjectStore::OpenC
   }
 
   if (!mTransaction->CanAcceptRequests()) {
     aRv.Throw(NS_ERROR_DOM_INDEXEDDB_TRANSACTION_INACTIVE_ERR);
     return nullptr;
   }
 
   RefPtr<IDBKeyRange> keyRange;
-  IDBKeyRange::FromJSVal(aCx, aRange, getter_AddRefs(keyRange), aRv);
+  IDBKeyRange::FromJSVal(aCx, aRange, &keyRange, aRv);
   if (NS_WARN_IF(aRv.Failed())) {
     return nullptr;
   }
 
   const int64_t objectStoreId = Id();
 
   Maybe<SerializedKeyRange> optionalKeyRange;