Bug 1600283 - Remove uses of already_AddRefed. r=#dom-workers-and-storage draft
authorSimon Giesecke <sgiesecke@mozilla.com>
Wed, 04 Dec 2019 16:48:55 +0000
changeset 2515990 1d81b6d9f6c52e4ffb799a1942625f483975d987
parent 2515989 8b28af9eadc72a6b23e483236dfbba8ab3a2945e
child 2515991 dc781fa59f81642a387f9453dc0c3a8915b68891
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/D55494 Differential Diff: PHID-DIFF-tldt6zmu5u7kqh5xepa3
dom/indexedDB/ActorsChild.cpp
dom/indexedDB/IDBEvents.cpp
dom/indexedDB/IDBEvents.h
dom/indexedDB/IDBFileHandle.cpp
dom/indexedDB/IDBFileHandle.h
dom/indexedDB/IDBRequest.cpp
dom/indexedDB/IDBTransaction.cpp
--- a/dom/indexedDB/ActorsChild.cpp
+++ b/dom/indexedDB/ActorsChild.cpp
@@ -655,17 +655,16 @@ void DispatchErrorEvent(IDBRequest* aReq
 
   request->SetError(aErrorCode);
 
   RefPtr<Event> errorEvent;
   if (!aEvent) {
     // Make an error event and fire it at the target.
     errorEvent = CreateGenericEvent(request, nsDependentString(kErrorEventType),
                                     eDoesBubble, eCancelable);
-    MOZ_ASSERT(errorEvent);
 
     aEvent = errorEvent;
   }
 
   Maybe<AutoSetCurrentTransaction> asct;
   if (aTransaction) {
     asct.emplace(aTransaction);
   }
@@ -726,18 +725,16 @@ void DispatchSuccessEvent(ResultHelper* 
     return;
   }
 
   RefPtr<Event> successEvent;
   if (!aEvent) {
     successEvent =
         CreateGenericEvent(request, nsDependentString(kSuccessEventType),
                            eDoesNotBubble, eNotCancelable);
-    MOZ_ASSERT(successEvent);
-
     aEvent = successEvent;
   }
 
   request->SetResultCallback(aResultHelper);
 
   MOZ_ASSERT(aEvent);
   MOZ_ASSERT_IF(transaction, transaction->CanAcceptRequests());
 
--- a/dom/indexedDB/IDBEvents.cpp
+++ b/dom/indexedDB/IDBEvents.cpp
@@ -23,20 +23,21 @@ const char16_t* kAbortEventType = u"abor
 const char16_t* kBlockedEventType = u"blocked";
 const char16_t* kCompleteEventType = u"complete";
 const char16_t* kErrorEventType = u"error";
 const char16_t* kSuccessEventType = u"success";
 const char16_t* kUpgradeNeededEventType = u"upgradeneeded";
 const char16_t* kVersionChangeEventType = u"versionchange";
 const char16_t* kCloseEventType = u"close";
 
-RefPtr<Event> CreateGenericEvent(EventTarget* aOwner,
-                                 const nsDependentString& aType,
-                                 Bubbles aBubbles, Cancelable aCancelable) {
-  RefPtr<Event> event = new Event(aOwner, nullptr, nullptr);
+OwningNonNull<Event> CreateGenericEvent(EventTarget* aOwner,
+                                        const nsDependentString& aType,
+                                        Bubbles aBubbles,
+                                        Cancelable aCancelable) {
+  OwningNonNull<Event> event = MakeAndAddRef<Event>(aOwner, nullptr, nullptr);
 
   event->InitEvent(aType, aBubbles == eDoesBubble ? true : false,
                    aCancelable == eCancelable ? true : false);
 
   event->SetTrusted(true);
 
   return event;
 }
--- a/dom/indexedDB/IDBEvents.h
+++ b/dom/indexedDB/IDBEvents.h
@@ -40,20 +40,19 @@ extern const char16_t* kAbortEventType;
 extern const char16_t* kBlockedEventType;
 extern const char16_t* kCompleteEventType;
 extern const char16_t* kErrorEventType;
 extern const char16_t* kSuccessEventType;
 extern const char16_t* kUpgradeNeededEventType;
 extern const char16_t* kVersionChangeEventType;
 extern const char16_t* kCloseEventType;
 
-MOZ_MUST_USE RefPtr<Event> CreateGenericEvent(EventTarget* aOwner,
-                                              const nsDependentString& aType,
-                                              Bubbles aBubbles,
-                                              Cancelable aCancelable);
+MOZ_MUST_USE OwningNonNull<Event> CreateGenericEvent(
+    EventTarget* aOwner, const nsDependentString& aType, Bubbles aBubbles,
+    Cancelable aCancelable);
 
 }  // namespace indexedDB
 
 class IDBVersionChangeEvent final : public Event {
   uint64_t mOldVersion;
   Nullable<uint64_t> mNewVersion;
 
  public:
--- a/dom/indexedDB/IDBFileHandle.cpp
+++ b/dom/indexedDB/IDBFileHandle.cpp
@@ -25,26 +25,21 @@
 namespace mozilla {
 namespace dom {
 
 using namespace mozilla::dom::indexedDB;
 using namespace mozilla::ipc;
 
 namespace {
 
-already_AddRefed<IDBFileRequest> GenerateFileRequest(
-    IDBFileHandle* aFileHandle) {
+RefPtr<IDBFileRequest> GenerateFileRequest(IDBFileHandle* aFileHandle) {
   MOZ_ASSERT(aFileHandle);
   aFileHandle->AssertIsOnOwningThread();
 
-  RefPtr<IDBFileRequest> fileRequest =
-      IDBFileRequest::Create(aFileHandle, /* aWrapAsDOMRequest */ false);
-  MOZ_ASSERT(fileRequest);
-
-  return fileRequest.forget();
+  return IDBFileRequest::Create(aFileHandle, /* aWrapAsDOMRequest */ false);
 }
 
 }  // namespace
 
 IDBFileHandle::IDBFileHandle(IDBMutableFile* aMutableFile, FileMode aMode)
     : mMutableFile(aMutableFile),
       mBackgroundActor(nullptr),
       mLocation(0),
@@ -75,18 +70,18 @@ IDBFileHandle::~IDBFileHandle() {
   if (mBackgroundActor) {
     mBackgroundActor->SendDeleteMeInternal();
 
     MOZ_ASSERT(!mBackgroundActor, "SendDeleteMeInternal should have cleared!");
   }
 }
 
 // static
-already_AddRefed<IDBFileHandle> IDBFileHandle::Create(
-    IDBMutableFile* aMutableFile, FileMode aMode) {
+RefPtr<IDBFileHandle> IDBFileHandle::Create(IDBMutableFile* aMutableFile,
+                                            FileMode aMode) {
   MOZ_ASSERT(aMutableFile);
   aMutableFile->AssertIsOnOwningThread();
   MOZ_ASSERT(aMode == FileMode::Readonly || aMode == FileMode::Readwrite);
 
   RefPtr<IDBFileHandle> fileHandle = new IDBFileHandle(aMutableFile, aMode);
 
   fileHandle->BindToOwner(aMutableFile);
 
@@ -95,17 +90,17 @@ already_AddRefed<IDBFileHandle> IDBFileH
 
   nsCOMPtr<nsIRunnable> runnable = do_QueryObject(fileHandle);
   nsContentUtils::AddPendingIDBTransaction(runnable.forget());
 
   fileHandle->mCreating = true;
 
   aMutableFile->RegisterFileHandle(fileHandle);
 
-  return fileHandle.forget();
+  return fileHandle;
 }
 
 // static
 IDBFileHandle* IDBFileHandle::GetCurrent() {
   MOZ_ASSERT(BackgroundChild::GetForCurrentThread());
 
   BackgroundChildImpl::ThreadLocal* threadLocal =
       BackgroundChildImpl::GetThreadLocalForCurrentThread();
@@ -188,27 +183,22 @@ void IDBFileHandle::FireCompleteOrAbortE
   MOZ_ASSERT(!mFiredCompleteOrAbort);
 
   mReadyState = DONE;
 
 #ifdef DEBUG
   mFiredCompleteOrAbort = true;
 #endif
 
-  RefPtr<Event> event;
-  if (aAborted) {
-    event = CreateGenericEvent(this, nsDependentString(kAbortEventType),
-                               eDoesBubble, eNotCancelable);
-  } else {
-    event = CreateGenericEvent(this, nsDependentString(kCompleteEventType),
-                               eDoesNotBubble, eNotCancelable);
-  }
-  if (NS_WARN_IF(!event)) {
-    return;
-  }
+  // TODO: Why is it necessary to create the Event on the heap at all?
+  const auto event = CreateGenericEvent(
+      this,
+      aAborted ? nsDependentString(kAbortEventType)
+               : nsDependentString(kCompleteEventType),
+      aAborted ? eDoesBubble : eDoesNotBubble, eNotCancelable);
 
   IgnoredErrorResult rv;
   DispatchEvent(*event, rv);
   if (rv.Failed()) {
     NS_WARNING("DispatchEvent failed!");
   }
 }
 
@@ -255,17 +245,17 @@ void IDBFileHandle::Abort() {
 
   // Fire the abort event if there are no outstanding requests. Otherwise the
   // abort event will be fired when all outstanding requests finish.
   if (needToSendAbort) {
     SendAbort();
   }
 }
 
-already_AddRefed<IDBFileRequest> IDBFileHandle::GetMetadata(
+RefPtr<IDBFileRequest> IDBFileHandle::GetMetadata(
     const IDBFileMetadataParameters& aParameters, ErrorResult& aRv) {
   AssertIsOnOwningThread();
 
   // Common state checking
   if (!CheckState(aRv)) {
     return nullptr;
   }
 
@@ -279,25 +269,25 @@ already_AddRefed<IDBFileRequest> IDBFile
   if (!CheckWindow()) {
     return nullptr;
   }
 
   FileRequestGetMetadataParams params;
   params.size() = aParameters.mSize;
   params.lastModified() = aParameters.mLastModified;
 
-  RefPtr<IDBFileRequest> fileRequest = GenerateFileRequest(this);
+  auto fileRequest = GenerateFileRequest(this);
 
   StartRequest(fileRequest, params);
 
-  return fileRequest.forget();
+  return fileRequest;
 }
 
-already_AddRefed<IDBFileRequest> IDBFileHandle::Truncate(
-    const Optional<uint64_t>& aSize, ErrorResult& aRv) {
+RefPtr<IDBFileRequest> IDBFileHandle::Truncate(const Optional<uint64_t>& aSize,
+                                               ErrorResult& aRv) {
   AssertIsOnOwningThread();
 
   // State checking for write
   if (!CheckStateForWrite(aRv)) {
     return nullptr;
   }
 
   // Getting location and additional state checking for truncate
@@ -317,47 +307,47 @@ already_AddRefed<IDBFileRequest> IDBFile
   // Do nothing if the window is closed
   if (!CheckWindow()) {
     return nullptr;
   }
 
   FileRequestTruncateParams params;
   params.offset() = location;
 
-  RefPtr<IDBFileRequest> fileRequest = GenerateFileRequest(this);
+  auto fileRequest = GenerateFileRequest(this);
 
   StartRequest(fileRequest, params);
 
   if (aSize.WasPassed()) {
     mLocation = aSize.Value();
   }
 
-  return fileRequest.forget();
+  return fileRequest;
 }
 
-already_AddRefed<IDBFileRequest> IDBFileHandle::Flush(ErrorResult& aRv) {
+RefPtr<IDBFileRequest> IDBFileHandle::Flush(ErrorResult& aRv) {
   AssertIsOnOwningThread();
 
   // State checking for write
   if (!CheckStateForWrite(aRv)) {
     return nullptr;
   }
 
   // Do nothing if the window is closed
   if (!CheckWindow()) {
     return nullptr;
   }
 
   FileRequestFlushParams params;
 
-  RefPtr<IDBFileRequest> fileRequest = GenerateFileRequest(this);
+  auto fileRequest = GenerateFileRequest(this);
 
   StartRequest(fileRequest, params);
 
-  return fileRequest.forget();
+  return fileRequest;
 }
 
 void IDBFileHandle::Abort(ErrorResult& aRv) {
   AssertIsOnOwningThread();
 
   // This method is special enough for not using generic state checking methods.
 
   if (IsFinishingOrDone()) {
@@ -430,49 +420,48 @@ bool IDBFileHandle::CheckStateForWriteOr
 }
 
 bool IDBFileHandle::CheckWindow() {
   AssertIsOnOwningThread();
 
   return GetOwner();
 }
 
-already_AddRefed<IDBFileRequest> IDBFileHandle::Read(uint64_t aSize,
-                                                     bool aHasEncoding,
-                                                     const nsAString& aEncoding,
-                                                     ErrorResult& aRv) {
+RefPtr<IDBFileRequest> IDBFileHandle::Read(uint64_t aSize, bool aHasEncoding,
+                                           const nsAString& aEncoding,
+                                           ErrorResult& aRv) {
   AssertIsOnOwningThread();
 
   // State and argument checking for read
   if (!CheckStateAndArgumentsForRead(aSize, aRv)) {
     return nullptr;
   }
 
   // Do nothing if the window is closed
   if (!CheckWindow()) {
     return nullptr;
   }
 
   FileRequestReadParams params;
   params.offset() = mLocation;
   params.size() = aSize;
 
-  RefPtr<IDBFileRequest> fileRequest = GenerateFileRequest(this);
+  auto fileRequest = GenerateFileRequest(this);
   if (aHasEncoding) {
     fileRequest->SetEncoding(aEncoding);
   }
 
   StartRequest(fileRequest, params);
 
   mLocation += aSize;
 
-  return fileRequest.forget();
+  return fileRequest;
 }
 
-already_AddRefed<IDBFileRequest> IDBFileHandle::WriteOrAppend(
+RefPtr<IDBFileRequest> IDBFileHandle::WriteOrAppend(
     const StringOrArrayBufferOrArrayBufferViewOrBlob& aValue, bool aAppend,
     ErrorResult& aRv) {
   AssertIsOnOwningThread();
 
   if (aValue.IsString()) {
     return WriteOrAppend(aValue.GetAsString(), aAppend, aRv);
   }
 
@@ -483,18 +472,19 @@ already_AddRefed<IDBFileRequest> IDBFile
   if (aValue.IsArrayBufferView()) {
     return WriteOrAppend(aValue.GetAsArrayBufferView(), aAppend, aRv);
   }
 
   MOZ_ASSERT(aValue.IsBlob());
   return WriteOrAppend(aValue.GetAsBlob(), aAppend, aRv);
 }
 
-already_AddRefed<IDBFileRequest> IDBFileHandle::WriteOrAppend(
-    const nsAString& aValue, bool aAppend, ErrorResult& aRv) {
+RefPtr<IDBFileRequest> IDBFileHandle::WriteOrAppend(const nsAString& aValue,
+                                                    bool aAppend,
+                                                    ErrorResult& aRv) {
   AssertIsOnOwningThread();
 
   // State checking for write or append
   if (!CheckStateForWriteOrAppend(aAppend, aRv)) {
     return nullptr;
   }
 
   NS_ConvertUTF16toUTF8 cstr(aValue);
@@ -510,18 +500,19 @@ already_AddRefed<IDBFileRequest> IDBFile
   // Do nothing if the window is closed
   if (!CheckWindow()) {
     return nullptr;
   }
 
   return WriteInternal(stringData, dataLength, aAppend, aRv);
 }
 
-already_AddRefed<IDBFileRequest> IDBFileHandle::WriteOrAppend(
-    const ArrayBuffer& aValue, bool aAppend, ErrorResult& aRv) {
+RefPtr<IDBFileRequest> IDBFileHandle::WriteOrAppend(const ArrayBuffer& aValue,
+                                                    bool aAppend,
+                                                    ErrorResult& aRv) {
   AssertIsOnOwningThread();
 
   // State checking for write or append
   if (!CheckStateForWriteOrAppend(aAppend, aRv)) {
     return nullptr;
   }
 
   aValue.ComputeLengthAndData();
@@ -544,17 +535,17 @@ already_AddRefed<IDBFileRequest> IDBFile
   // Do nothing if the window is closed
   if (!CheckWindow()) {
     return nullptr;
   }
 
   return WriteInternal(stringData, dataLength, aAppend, aRv);
 }
 
-already_AddRefed<IDBFileRequest> IDBFileHandle::WriteOrAppend(
+RefPtr<IDBFileRequest> IDBFileHandle::WriteOrAppend(
     const ArrayBufferView& aValue, bool aAppend, ErrorResult& aRv) {
   AssertIsOnOwningThread();
 
   // State checking for write or append
   if (!CheckStateForWriteOrAppend(aAppend, aRv)) {
     return nullptr;
   }
 
@@ -578,18 +569,18 @@ already_AddRefed<IDBFileRequest> IDBFile
   // Do nothing if the window is closed
   if (!CheckWindow()) {
     return nullptr;
   }
 
   return WriteInternal(stringData, dataLength, aAppend, aRv);
 }
 
-already_AddRefed<IDBFileRequest> IDBFileHandle::WriteOrAppend(
-    Blob& aValue, bool aAppend, ErrorResult& aRv) {
+RefPtr<IDBFileRequest> IDBFileHandle::WriteOrAppend(Blob& aValue, bool aAppend,
+                                                    ErrorResult& aRv) {
   AssertIsOnOwningThread();
 
   // State checking for write or append
   if (!CheckStateForWriteOrAppend(aAppend, aRv)) {
     return nullptr;
   }
 
   ErrorResult error;
@@ -620,44 +611,44 @@ already_AddRefed<IDBFileRequest> IDBFile
   // Do nothing if the window is closed
   if (!CheckWindow()) {
     return nullptr;
   }
 
   return WriteInternal(blobData, dataLength, aAppend, aRv);
 }
 
-already_AddRefed<IDBFileRequest> IDBFileHandle::WriteInternal(
+RefPtr<IDBFileRequest> IDBFileHandle::WriteInternal(
     const FileRequestData& aData, uint64_t aDataLength, bool aAppend,
     ErrorResult& aRv) {
   AssertIsOnOwningThread();
 
   DebugOnly<ErrorResult> error;
   MOZ_ASSERT(CheckStateForWrite(error));
   MOZ_ASSERT_IF(!aAppend, mLocation != UINT64_MAX);
   MOZ_ASSERT(aDataLength);
   MOZ_ASSERT(CheckWindow());
 
   FileRequestWriteParams params;
   params.offset() = aAppend ? UINT64_MAX : mLocation;
   params.data() = aData;
   params.dataLength() = aDataLength;
 
-  RefPtr<IDBFileRequest> fileRequest = GenerateFileRequest(this);
+  auto fileRequest = GenerateFileRequest(this);
   MOZ_ASSERT(fileRequest);
 
   StartRequest(fileRequest, params);
 
   if (aAppend) {
     mLocation = UINT64_MAX;
   } else {
     mLocation += aDataLength;
   }
 
-  return fileRequest.forget();
+  return fileRequest;
 }
 
 void IDBFileHandle::SendFinish() {
   AssertIsOnOwningThread();
   MOZ_ASSERT(!mAborted);
   MOZ_ASSERT(IsFinishingOrDone());
   MOZ_ASSERT(!mSentFinishOrAbort);
   MOZ_ASSERT(!mPendingRequestCount);
--- a/dom/indexedDB/IDBFileHandle.h
+++ b/dom/indexedDB/IDBFileHandle.h
@@ -53,18 +53,18 @@ class IDBFileHandle final : public DOMEv
   bool mCreating;
 
 #ifdef DEBUG
   bool mSentFinishOrAbort;
   bool mFiredCompleteOrAbort;
 #endif
 
  public:
-  static already_AddRefed<IDBFileHandle> Create(IDBMutableFile* aMutableFile,
-                                                FileMode aMode);
+  static MOZ_MUST_USE RefPtr<IDBFileHandle> Create(IDBMutableFile* aMutableFile,
+                                                   FileMode aMode);
 
   static IDBFileHandle* GetCurrent();
 
   void AssertIsOnOwningThread() const
 #ifdef DEBUG
       ;
 #else
   {
@@ -146,50 +146,50 @@ class IDBFileHandle final : public DOMEv
     // Null means the end-of-file.
     if (aLocation.IsNull()) {
       mLocation = UINT64_MAX;
     } else {
       mLocation = aLocation.Value();
     }
   }
 
-  already_AddRefed<IDBFileRequest> GetMetadata(
+  MOZ_MUST_USE RefPtr<IDBFileRequest> GetMetadata(
       const IDBFileMetadataParameters& aParameters, ErrorResult& aRv);
 
-  already_AddRefed<IDBFileRequest> ReadAsArrayBuffer(uint64_t aSize,
-                                                     ErrorResult& aRv) {
+  MOZ_MUST_USE RefPtr<IDBFileRequest> ReadAsArrayBuffer(uint64_t aSize,
+                                                        ErrorResult& aRv) {
     AssertIsOnOwningThread();
     return Read(aSize, false, VoidString(), aRv);
   }
 
-  already_AddRefed<IDBFileRequest> ReadAsText(uint64_t aSize,
-                                              const nsAString& aEncoding,
-                                              ErrorResult& aRv) {
+  MOZ_MUST_USE RefPtr<IDBFileRequest> ReadAsText(uint64_t aSize,
+                                                 const nsAString& aEncoding,
+                                                 ErrorResult& aRv) {
     AssertIsOnOwningThread();
     return Read(aSize, true, aEncoding, aRv);
   }
 
-  already_AddRefed<IDBFileRequest> Write(
+  MOZ_MUST_USE RefPtr<IDBFileRequest> Write(
       const StringOrArrayBufferOrArrayBufferViewOrBlob& aValue,
       ErrorResult& aRv) {
     AssertIsOnOwningThread();
     return WriteOrAppend(aValue, false, aRv);
   }
 
-  already_AddRefed<IDBFileRequest> Append(
+  MOZ_MUST_USE RefPtr<IDBFileRequest> Append(
       const StringOrArrayBufferOrArrayBufferViewOrBlob& aValue,
       ErrorResult& aRv) {
     AssertIsOnOwningThread();
     return WriteOrAppend(aValue, true, aRv);
   }
 
-  already_AddRefed<IDBFileRequest> Truncate(const Optional<uint64_t>& aSize,
-                                            ErrorResult& aRv);
+  MOZ_MUST_USE RefPtr<IDBFileRequest> Truncate(const Optional<uint64_t>& aSize,
+                                               ErrorResult& aRv);
 
-  already_AddRefed<IDBFileRequest> Flush(ErrorResult& aRv);
+  MOZ_MUST_USE RefPtr<IDBFileRequest> Flush(ErrorResult& aRv);
 
   void Abort(ErrorResult& aRv);
 
   IMPL_EVENT_HANDLER(complete)
   IMPL_EVENT_HANDLER(abort)
   IMPL_EVENT_HANDLER(error)
 
   NS_DECL_ISUPPORTS_INHERITED
@@ -212,43 +212,41 @@ class IDBFileHandle final : public DOMEv
   bool CheckStateAndArgumentsForRead(uint64_t aSize, ErrorResult& aRv);
 
   bool CheckStateForWrite(ErrorResult& aRv);
 
   bool CheckStateForWriteOrAppend(bool aAppend, ErrorResult& aRv);
 
   bool CheckWindow();
 
-  already_AddRefed<IDBFileRequest> Read(uint64_t aSize, bool aHasEncoding,
-                                        const nsAString& aEncoding,
-                                        ErrorResult& aRv);
+  MOZ_MUST_USE RefPtr<IDBFileRequest> Read(uint64_t aSize, bool aHasEncoding,
+                                           const nsAString& aEncoding,
+                                           ErrorResult& aRv);
 
-  already_AddRefed<IDBFileRequest> WriteOrAppend(
+  MOZ_MUST_USE RefPtr<IDBFileRequest> WriteOrAppend(
       const StringOrArrayBufferOrArrayBufferViewOrBlob& aValue, bool aAppend,
       ErrorResult& aRv);
 
-  already_AddRefed<IDBFileRequest> WriteOrAppend(const nsAString& aValue,
-                                                 bool aAppend,
-                                                 ErrorResult& aRv);
+  MOZ_MUST_USE RefPtr<IDBFileRequest> WriteOrAppend(const nsAString& aValue,
+                                                    bool aAppend,
+                                                    ErrorResult& aRv);
 
-  already_AddRefed<IDBFileRequest> WriteOrAppend(const ArrayBuffer& aValue,
-                                                 bool aAppend,
-                                                 ErrorResult& aRv);
+  MOZ_MUST_USE RefPtr<IDBFileRequest> WriteOrAppend(const ArrayBuffer& aValue,
+                                                    bool aAppend,
+                                                    ErrorResult& aRv);
 
-  already_AddRefed<IDBFileRequest> WriteOrAppend(const ArrayBufferView& aValue,
-                                                 bool aAppend,
-                                                 ErrorResult& aRv);
+  MOZ_MUST_USE RefPtr<IDBFileRequest> WriteOrAppend(
+      const ArrayBufferView& aValue, bool aAppend, ErrorResult& aRv);
 
-  already_AddRefed<IDBFileRequest> WriteOrAppend(Blob& aValue, bool aAppend,
-                                                 ErrorResult& aRv);
+  MOZ_MUST_USE RefPtr<IDBFileRequest> WriteOrAppend(Blob& aValue, bool aAppend,
+                                                    ErrorResult& aRv);
 
-  already_AddRefed<IDBFileRequest> WriteInternal(const FileRequestData& aData,
-                                                 uint64_t aDataLength,
-                                                 bool aAppend,
-                                                 ErrorResult& aRv);
+  MOZ_MUST_USE RefPtr<IDBFileRequest> WriteInternal(
+      const FileRequestData& aData, uint64_t aDataLength, bool aAppend,
+      ErrorResult& aRv);
 
   void SendFinish();
 
   void SendAbort();
 };
 
 }  // namespace dom
 }  // namespace mozilla
--- a/dom/indexedDB/IDBRequest.cpp
+++ b/dom/indexedDB/IDBRequest.cpp
@@ -432,19 +432,18 @@ void IDBOpenDBRequest::DispatchNonTransa
 
   // The actor failed to initiate, decrease the number of active IDBOpenRequests
   // here since NoteComplete won't be called.
   MaybeDecreaseActiveDatabaseCount();
 
   SetError(aErrorCode);
 
   // Make an error event and fire it at the target.
-  RefPtr<Event> event = CreateGenericEvent(
-      this, nsDependentString(kErrorEventType), eDoesBubble, eCancelable);
-  MOZ_ASSERT(event);
+  auto event = CreateGenericEvent(this, nsDependentString(kErrorEventType),
+                                  eDoesBubble, eCancelable);
 
   IgnoredErrorResult rv;
   DispatchEvent(*event, rv);
   if (rv.Failed()) {
     NS_WARNING("Failed to dispatch event!");
   }
 }
 
--- a/dom/indexedDB/IDBTransaction.cpp
+++ b/dom/indexedDB/IDBTransaction.cpp
@@ -707,33 +707,31 @@ void IDBTransaction::FireCompleteOrAbort
 
   // Make sure we drop the WorkerRef when this function completes.
   const auto scopeExit = MakeScopeExit([&] { mWorkerRef = nullptr; });
 
   RefPtr<Event> event;
   if (NS_SUCCEEDED(aResult)) {
     event = CreateGenericEvent(this, nsDependentString(kCompleteEventType),
                                eDoesNotBubble, eNotCancelable);
-    MOZ_ASSERT(event);
 
     // If we hit this assertion, it probably means transaction object on the
     // parent process doesn't propagate error properly.
     MOZ_ASSERT(NS_SUCCEEDED(mAbortCode));
   } else {
     if (aResult == NS_ERROR_DOM_INDEXEDDB_QUOTA_ERR) {
       mDatabase->SetQuotaExceeded();
     }
 
     if (!mError && !mAbortedByScript) {
       mError = DOMException::Create(aResult);
     }
 
     event = CreateGenericEvent(this, nsDependentString(kAbortEventType),
                                eDoesBubble, eNotCancelable);
-    MOZ_ASSERT(event);
 
     if (NS_SUCCEEDED(mAbortCode)) {
       mAbortCode = aResult;
     }
   }
 
   if (NS_SUCCEEDED(mAbortCode)) {
     IDB_LOG_MARK_CHILD_TRANSACTION("Firing 'complete' event",