Bug 1365097 - Convert NS_GetCurrentThread uses in dom (except for dom/media) (r=smaug)
authorBill McCloskey <billm@mozilla.com>
Thu, 01 Jun 2017 13:42:05 -0700
changeset 412323 351a4d47496ecc6d03585474d89f48b602b007e7
parent 412322 54f926563d9dc89de92293c7ff0e307ee8e61775
child 412324 d4c07cb66853887d1aa6afec7e0cacc121807755
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1365097
milestone56.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 1365097 - Convert NS_GetCurrentThread uses in dom (except for dom/media) (r=smaug) For the Quatum DOM project, it's better to work in terms of event targets than threads. This patch converts DOM code to operate on event targets rather than threads, when possible. MozReview-Commit-ID: 5FgvpKadUA2
dom/asmjscache/AsmJSCache.cpp
dom/base/DispatcherTrait.cpp
dom/base/ImageEncoder.cpp
dom/base/StructuredCloneHolder.cpp
dom/base/StructuredCloneHolder.h
dom/base/nsJSEnvironment.cpp
dom/cache/Context.cpp
dom/cache/Context.h
dom/cache/Manager.cpp
dom/cache/PrincipalVerifier.cpp
dom/cache/PrincipalVerifier.h
dom/cache/ReadStream.cpp
dom/canvas/OffscreenCanvas.cpp
dom/canvas/WebGLContextLossHandler.cpp
dom/canvas/WebGLContextLossHandler.h
dom/crypto/WebCryptoTask.cpp
dom/crypto/WebCryptoTask.h
dom/file/FileReader.cpp
dom/file/MutableBlobStorage.cpp
dom/file/MutableBlobStreamListener.cpp
dom/file/ipc/IPCBlobInputStream.cpp
dom/file/ipc/IPCBlobInputStreamChild.cpp
dom/file/ipc/IPCBlobInputStreamChild.h
dom/file/ipc/IPCBlobInputStreamThread.cpp
dom/file/ipc/IPCBlobInputStreamThread.h
dom/filehandle/ActorsParent.cpp
dom/filehandle/ActorsParent.h
dom/filesystem/FileSystemRequestParent.cpp
dom/filesystem/FileSystemTaskBase.cpp
dom/flyweb/HttpServer.cpp
dom/gamepad/ipc/GamepadEventChannelParent.cpp
dom/gamepad/ipc/GamepadEventChannelParent.h
dom/html/HTMLCanvasElement.cpp
dom/indexedDB/ActorsChild.cpp
dom/indexedDB/ActorsParent.cpp
dom/indexedDB/IDBFactory.cpp
dom/network/TCPSocket.cpp
dom/network/UDPSocketParent.cpp
dom/notification/Notification.cpp
dom/presentation/PresentationTCPSessionTransport.cpp
dom/quota/ActorsChild.cpp
dom/quota/ActorsParent.cpp
dom/workers/RuntimeService.cpp
dom/workers/ServiceWorkerManagerParent.cpp
dom/workers/ServiceWorkerRegistrar.cpp
dom/workers/WorkerPrivate.cpp
--- a/dom/asmjscache/AsmJSCache.cpp
+++ b/dom/asmjscache/AsmJSCache.cpp
@@ -340,17 +340,17 @@ class ParentRunnable final
 {
 public:
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_NSIRUNNABLE
 
   ParentRunnable(const PrincipalInfo& aPrincipalInfo,
                  OpenMode aOpenMode,
                  WriteParams aWriteParams)
-  : mOwningThread(NS_GetCurrentThread()),
+  : mOwningEventTarget(GetCurrentThreadEventTarget()),
     mPrincipalInfo(aPrincipalInfo),
     mOpenMode(aOpenMode),
     mWriteParams(aWriteParams),
     mState(eInitial),
     mResult(JS::AsmJSCache_InternalError),
     mDeleteReceived(false),
     mActorDestroyed(false),
     mOpened(false)
@@ -365,20 +365,20 @@ private:
     MOZ_ASSERT(mState == eFinished);
     MOZ_ASSERT(!mDirectoryLock);
     MOZ_ASSERT(mActorDestroyed);
   }
 
   bool
   IsOnOwningThread() const
   {
-    MOZ_ASSERT(mOwningThread);
+    MOZ_ASSERT(mOwningEventTarget);
 
     bool current;
-    return NS_SUCCEEDED(mOwningThread->IsOnCurrentThread(&current)) && current;
+    return NS_SUCCEEDED(mOwningEventTarget->IsOnCurrentThread(&current)) && current;
   }
 
   void
   AssertIsOnOwningThread() const
   {
     MOZ_ASSERT(IsOnBackgroundThread());
     MOZ_ASSERT(IsOnOwningThread());
   }
@@ -430,17 +430,17 @@ private:
   FailOnNonOwningThread()
   {
     AssertIsOnNonOwningThread();
     MOZ_ASSERT(mState != eOpened &&
                mState != eFailing &&
                mState != eFinished);
 
     mState = eFailing;
-    MOZ_ALWAYS_SUCCEEDS(mOwningThread->Dispatch(this, NS_DISPATCH_NORMAL));
+    MOZ_ALWAYS_SUCCEEDS(mOwningEventTarget->Dispatch(this, NS_DISPATCH_NORMAL));
   }
 
   nsresult
   InitOnMainThread();
 
   void
   OpenDirectory();
 
@@ -538,17 +538,17 @@ private:
 
     mModuleIndex = aModuleIndex;
     mState = eReadyToOpenCacheFileForRead;
     DispatchToIOThread();
 
     return IPC_OK();
   }
 
-  nsCOMPtr<nsIEventTarget> mOwningThread;
+  nsCOMPtr<nsIEventTarget> mOwningEventTarget;
   const PrincipalInfo mPrincipalInfo;
   const OpenMode mOpenMode;
   const WriteParams mWriteParams;
 
   // State initialized during eInitial:
   nsCString mSuffix;
   nsCString mGroup;
   nsCString mOrigin;
@@ -815,17 +815,17 @@ ParentRunnable::Run()
 
       rv = InitOnMainThread();
       if (NS_FAILED(rv)) {
         FailOnNonOwningThread();
         return NS_OK;
       }
 
       mState = eWaitingToFinishInit;
-      MOZ_ALWAYS_SUCCEEDS(mOwningThread->Dispatch(this, NS_DISPATCH_NORMAL));
+      MOZ_ALWAYS_SUCCEEDS(mOwningEventTarget->Dispatch(this, NS_DISPATCH_NORMAL));
 
       return NS_OK;
     }
 
     case eWaitingToFinishInit: {
       AssertIsOnOwningThread();
 
       if (QuotaManager::IsShuttingDown()) {
@@ -862,29 +862,29 @@ ParentRunnable::Run()
       rv = ReadMetadata();
       if (NS_FAILED(rv)) {
         FailOnNonOwningThread();
         return NS_OK;
       }
 
       if (mOpenMode == eOpenForRead) {
         mState = eSendingMetadataForRead;
-        MOZ_ALWAYS_SUCCEEDS(mOwningThread->Dispatch(this, NS_DISPATCH_NORMAL));
+        MOZ_ALWAYS_SUCCEEDS(mOwningEventTarget->Dispatch(this, NS_DISPATCH_NORMAL));
 
         return NS_OK;
       }
 
       rv = OpenCacheFileForWrite();
       if (NS_FAILED(rv)) {
         FailOnNonOwningThread();
         return NS_OK;
       }
 
       mState = eSendingCacheFile;
-      MOZ_ALWAYS_SUCCEEDS(mOwningThread->Dispatch(this, NS_DISPATCH_NORMAL));
+      MOZ_ALWAYS_SUCCEEDS(mOwningEventTarget->Dispatch(this, NS_DISPATCH_NORMAL));
       return NS_OK;
     }
 
     case eSendingMetadataForRead: {
       AssertIsOnOwningThread();
       MOZ_ASSERT(mOpenMode == eOpenForRead);
 
       mState = eWaitingToOpenCacheFileForRead;
@@ -904,17 +904,17 @@ ParentRunnable::Run()
 
       rv = OpenCacheFileForRead();
       if (NS_FAILED(rv)) {
         FailOnNonOwningThread();
         return NS_OK;
       }
 
       mState = eSendingCacheFile;
-      MOZ_ALWAYS_SUCCEEDS(mOwningThread->Dispatch(this, NS_DISPATCH_NORMAL));
+      MOZ_ALWAYS_SUCCEEDS(mOwningEventTarget->Dispatch(this, NS_DISPATCH_NORMAL));
       return NS_OK;
     }
 
     case eSendingCacheFile: {
       AssertIsOnOwningThread();
 
       mState = eOpened;
 
--- a/dom/base/DispatcherTrait.cpp
+++ b/dom/base/DispatcherTrait.cpp
@@ -19,18 +19,17 @@ DispatcherTrait::Dispatch(const char* aN
                           already_AddRefed<nsIRunnable>&& aRunnable)
 {
   return SchedulerGroup::UnlabeledDispatch(aName, aCategory, Move(aRunnable));
 }
 
 nsIEventTarget*
 DispatcherTrait::EventTargetFor(TaskCategory aCategory) const
 {
-  nsCOMPtr<nsIEventTarget> main = do_GetMainThread();
-  return main;
+  return GetMainThreadEventTarget();
 }
 
 AbstractThread*
 DispatcherTrait::AbstractMainThreadFor(TaskCategory aCategory)
 {
   // Return non DocGroup version by default.
   return AbstractThread::MainThread();
 }
--- a/dom/base/ImageEncoder.cpp
+++ b/dom/base/ImageEncoder.cpp
@@ -47,19 +47,19 @@ public:
       mDataSourceSurface = gfxUtils::
         CopySurfaceToDataSourceSurfaceWithFormat(surface,
                                                  gfx::SurfaceFormat::B8G8R8A8);
     }
     return NS_OK;
   }
 
   already_AddRefed<gfx::DataSourceSurface> GetDataSurfaceSafe() {
-    nsCOMPtr<nsIThread> mainThread = do_GetMainThread();
-    MOZ_ASSERT(mainThread);
-    SyncRunnable::DispatchToThread(mainThread, this, false);
+    nsCOMPtr<nsIEventTarget> mainTarget = GetMainThreadEventTarget();
+    MOZ_ASSERT(mainTarget);
+    SyncRunnable::DispatchToThread(mainTarget, this, false);
 
     return mDataSourceSurface.forget();
   }
 
 private:
   RefPtr<layers::Image> mImage;
   RefPtr<gfx::DataSourceSurface> mDataSourceSurface;
 };
@@ -85,19 +85,19 @@ public:
     : CancelableRunnable("EncodingCompleteEvent")
     , mImgSize(0)
     , mType()
     , mImgData(nullptr)
     , mEncodeCompleteCallback(aEncodeCompleteCallback)
     , mFailed(false)
   {
     if (!NS_IsMainThread() && workers::GetCurrentThreadWorkerPrivate()) {
-      mCreationThread = NS_GetCurrentThread();
+      mCreationEventTarget = GetCurrentThreadEventTarget();
     } else {
-      NS_GetMainThread(getter_AddRefs(mCreationThread));
+      mCreationEventTarget = GetMainThreadEventTarget();
     }
   }
 
   NS_IMETHOD Run() override
   {
     nsresult rv = NS_OK;
 
     if (!mFailed) {
@@ -121,26 +121,26 @@ public:
     mType = aType;
   }
 
   void SetFailed()
   {
     mFailed = true;
   }
 
-  nsIThread* GetCreationThread()
+  nsIEventTarget* GetCreationThreadEventTarget()
   {
-    return mCreationThread;
+    return mCreationEventTarget;
   }
 
 private:
   uint64_t mImgSize;
   nsAutoString mType;
   void* mImgData;
-  nsCOMPtr<nsIThread> mCreationThread;
+  nsCOMPtr<nsIEventTarget> mCreationEventTarget;
   RefPtr<EncodeCompleteCallback> mEncodeCompleteCallback;
   bool mFailed;
 };
 
 class EncodingRunnable : public Runnable
 {
   virtual ~EncodingRunnable() {}
 
@@ -214,17 +214,17 @@ public:
     void* imgData = nullptr;
 
     nsresult rv = ProcessImageData(&imgSize, &imgData);
     if (NS_FAILED(rv)) {
       mEncodingCompleteEvent->SetFailed();
     } else {
       mEncodingCompleteEvent->SetMembers(imgData, imgSize, mType);
     }
-    rv = mEncodingCompleteEvent->GetCreationThread()->
+    rv = mEncodingCompleteEvent->GetCreationThreadEventTarget()->
       Dispatch(mEncodingCompleteEvent, nsIThread::DISPATCH_NORMAL);
     if (NS_FAILED(rv)) {
       // Better to leak than to crash.
       Unused << mEncodingCompleteEvent.forget();
       return rv;
     }
 
     return rv;
--- a/dom/base/StructuredCloneHolder.cpp
+++ b/dom/base/StructuredCloneHolder.cpp
@@ -245,17 +245,17 @@ StructuredCloneHolderBase::CustomFreeTra
 StructuredCloneHolder::StructuredCloneHolder(CloningSupport aSupportsCloning,
                                              TransferringSupport aSupportsTransferring,
                                              StructuredCloneScope aScope)
   : StructuredCloneHolderBase(aScope)
   , mSupportsCloning(aSupportsCloning == CloningSupported)
   , mSupportsTransferring(aSupportsTransferring == TransferringSupported)
   , mParent(nullptr)
 #ifdef DEBUG
-  , mCreationThread(NS_GetCurrentThread())
+  , mCreationEventTarget(GetCurrentThreadEventTarget())
 #endif
 {}
 
 StructuredCloneHolder::~StructuredCloneHolder()
 {
   Clear();
   MOZ_ASSERT(mTransferredPorts.IsEmpty());
 }
@@ -272,32 +272,32 @@ StructuredCloneHolder::Write(JSContext* 
 void
 StructuredCloneHolder::Write(JSContext* aCx,
                              JS::Handle<JS::Value> aValue,
                              JS::Handle<JS::Value> aTransfer,
                              JS::CloneDataPolicy cloneDataPolicy,
                              ErrorResult& aRv)
 {
   MOZ_ASSERT_IF(mStructuredCloneScope == StructuredCloneScope::SameProcessSameThread,
-                mCreationThread == NS_GetCurrentThread());
+                mCreationEventTarget->IsOnCurrentThread());
 
   if (!StructuredCloneHolderBase::Write(aCx, aValue, aTransfer, cloneDataPolicy)) {
     aRv.Throw(NS_ERROR_DOM_DATA_CLONE_ERR);
     return;
   }
 }
 
 void
 StructuredCloneHolder::Read(nsISupports* aParent,
                             JSContext* aCx,
                             JS::MutableHandle<JS::Value> aValue,
                             ErrorResult& aRv)
 {
   MOZ_ASSERT_IF(mStructuredCloneScope == StructuredCloneScope::SameProcessSameThread,
-                mCreationThread == NS_GetCurrentThread());
+                mCreationEventTarget->IsOnCurrentThread());
   MOZ_ASSERT(aParent);
 
   mozilla::AutoRestore<nsISupports*> guard(mParent);
   mParent = aParent;
 
   if (!StructuredCloneHolderBase::Read(aCx, aValue)) {
     JS_ClearPendingException(aCx);
     aRv.Throw(NS_ERROR_DOM_DATA_CLONE_ERR);
@@ -329,17 +329,17 @@ void
 StructuredCloneHolder::ReadFromBuffer(nsISupports* aParent,
                                       JSContext* aCx,
                                       JSStructuredCloneData& aBuffer,
                                       uint32_t aAlgorithmVersion,
                                       JS::MutableHandle<JS::Value> aValue,
                                       ErrorResult& aRv)
 {
   MOZ_ASSERT_IF(mStructuredCloneScope == StructuredCloneScope::SameProcessSameThread,
-                mCreationThread == NS_GetCurrentThread());
+                mCreationEventTarget->IsOnCurrentThread());
 
   MOZ_ASSERT(!mBuffer, "ReadFromBuffer() must be called without a Write().");
 
   mozilla::AutoRestore<nsISupports*> guard(mParent);
   mParent = aParent;
 
   if (!JS_ReadStructuredClone(aCx, aBuffer, aAlgorithmVersion,
                               mStructuredCloneScope, aValue, &sCallbacks,
--- a/dom/base/StructuredCloneHolder.h
+++ b/dom/base/StructuredCloneHolder.h
@@ -329,16 +329,16 @@ protected:
   nsTArray<RefPtr<MessagePort>> mTransferredPorts;
 
   // This array contains the identifiers of the MessagePorts. Based on these we
   // are able to reconnect the new transferred ports with the other
   // MessageChannel ports.
   mutable nsTArray<MessagePortIdentifier> mPortIdentifiers;
 
 #ifdef DEBUG
-  nsCOMPtr<nsIThread> mCreationThread;
+  nsCOMPtr<nsIEventTarget> mCreationEventTarget;
 #endif
 };
 
 } // dom namespace
 } // mozilla namespace
 
 #endif // mozilla_dom_StructuredCloneHolder_h
--- a/dom/base/nsJSEnvironment.cpp
+++ b/dom/base/nsJSEnvironment.cpp
@@ -2661,23 +2661,23 @@ StartAsyncTaskCallback(JSContext* aCx, J
   return true;
 }
 
 static bool
 FinishAsyncTaskCallback(JS::AsyncTask* aTask)
 {
   // AsyncTasks can finish during shutdown so cannot simply
   // NS_DispatchToMainThread.
-  nsCOMPtr<nsIThread> mainThread = do_GetMainThread();
-  if (!mainThread) {
+  nsCOMPtr<nsIEventTarget> mainTarget = GetMainThreadEventTarget();
+  if (!mainTarget) {
     return false;
   }
 
   RefPtr<AsyncTaskRunnable> r = new AsyncTaskRunnable(aTask);
-  MOZ_ALWAYS_SUCCEEDS(mainThread->Dispatch(r.forget(), NS_DISPATCH_NORMAL));
+  MOZ_ALWAYS_SUCCEEDS(mainTarget->Dispatch(r.forget(), NS_DISPATCH_NORMAL));
   return true;
 }
 
 void
 nsJSContext::EnsureStatics()
 {
   if (sIsInitialized) {
     if (!nsContentUtils::XPConnect()) {
--- a/dom/cache/Context.cpp
+++ b/dom/cache/Context.cpp
@@ -49,49 +49,49 @@ using mozilla::dom::quota::AssertIsOnIOT
 using mozilla::dom::quota::OpenDirectoryListener;
 using mozilla::dom::quota::QuotaManager;
 using mozilla::dom::quota::PERSISTENCE_TYPE_DEFAULT;
 using mozilla::dom::quota::PersistenceType;
 
 class Context::Data final : public Action::Data
 {
 public:
-  explicit Data(nsIThread* aTarget)
+  explicit Data(nsISerialEventTarget* aTarget)
     : mTarget(aTarget)
   {
     MOZ_DIAGNOSTIC_ASSERT(mTarget);
   }
 
   virtual mozIStorageConnection*
   GetConnection() const override
   {
-    MOZ_ASSERT(mTarget == NS_GetCurrentThread());
+    MOZ_ASSERT(mTarget->IsOnCurrentThread());
     return mConnection;
   }
 
   virtual void
   SetConnection(mozIStorageConnection* aConn) override
   {
-    MOZ_ASSERT(mTarget == NS_GetCurrentThread());
+    MOZ_ASSERT(mTarget->IsOnCurrentThread());
     MOZ_DIAGNOSTIC_ASSERT(!mConnection);
     mConnection = aConn;
     MOZ_DIAGNOSTIC_ASSERT(mConnection);
   }
 
 private:
   ~Data()
   {
     // We could proxy release our data here, but instead just assert.  The
     // Context code should guarantee that we are destroyed on the target
     // thread once the connection is initialized.  If we're not, then
     // QuotaManager might race and try to clear the origin out from under us.
-    MOZ_ASSERT_IF(mConnection, mTarget == NS_GetCurrentThread());
+    MOZ_ASSERT_IF(mConnection, mTarget->IsOnCurrentThread());
   }
 
-  nsCOMPtr<nsIThread> mTarget;
+  nsCOMPtr<nsISerialEventTarget> mTarget;
   nsCOMPtr<mozIStorageConnection> mConnection;
 
   // Threadsafe counting because we're created on the PBackground thread
   // and destroyed on the target IO thread.
   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(Context::Data)
 };
 
 // Executed to perform the complicated dance of steps necessary to initialize
@@ -99,34 +99,34 @@ private:
 // IO occurrs.
 class Context::QuotaInitRunnable final : public nsIRunnable
                                        , public OpenDirectoryListener
 {
 public:
   QuotaInitRunnable(Context* aContext,
                     Manager* aManager,
                     Data* aData,
-                    nsIThread* aTarget,
+                    nsISerialEventTarget* aTarget,
                     Action* aInitAction)
     : mContext(aContext)
     , mThreadsafeHandle(aContext->CreateThreadsafeHandle())
     , mManager(aManager)
     , mData(aData)
     , mTarget(aTarget)
     , mInitAction(aInitAction)
-    , mInitiatingThread(NS_GetCurrentThread())
+    , mInitiatingEventTarget(GetCurrentThreadEventTarget())
     , mResult(NS_OK)
     , mState(STATE_INIT)
     , mCanceled(false)
   {
     MOZ_DIAGNOSTIC_ASSERT(mContext);
     MOZ_DIAGNOSTIC_ASSERT(mManager);
     MOZ_DIAGNOSTIC_ASSERT(mData);
     MOZ_DIAGNOSTIC_ASSERT(mTarget);
-    MOZ_DIAGNOSTIC_ASSERT(mInitiatingThread);
+    MOZ_DIAGNOSTIC_ASSERT(mInitiatingEventTarget);
     MOZ_DIAGNOSTIC_ASSERT(mInitAction);
   }
 
   nsresult Dispatch()
   {
     NS_ASSERT_OWNINGTHREAD(QuotaInitRunnable);
     MOZ_DIAGNOSTIC_ASSERT(mState == STATE_INIT);
 
@@ -210,35 +210,35 @@ private:
   {
     MOZ_DIAGNOSTIC_ASSERT(mState == STATE_RUNNING || NS_FAILED(aResult));
 
     MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(mResult));
     mResult = aResult;
 
     mState = STATE_COMPLETING;
     MOZ_ALWAYS_SUCCEEDS(
-      mInitiatingThread->Dispatch(this, nsIThread::DISPATCH_NORMAL));
+      mInitiatingEventTarget->Dispatch(this, nsIThread::DISPATCH_NORMAL));
   }
 
   void Clear()
   {
     NS_ASSERT_OWNINGTHREAD(QuotaInitRunnable);
     MOZ_DIAGNOSTIC_ASSERT(mContext);
     mContext = nullptr;
     mManager = nullptr;
     mInitAction = nullptr;
   }
 
   RefPtr<Context> mContext;
   RefPtr<ThreadsafeHandle> mThreadsafeHandle;
   RefPtr<Manager> mManager;
   RefPtr<Data> mData;
-  nsCOMPtr<nsIThread> mTarget;
+  nsCOMPtr<nsISerialEventTarget> mTarget;
   RefPtr<Action> mInitAction;
-  nsCOMPtr<nsIThread> mInitiatingThread;
+  nsCOMPtr<nsIEventTarget> mInitiatingEventTarget;
   nsresult mResult;
   QuotaInfo mQuotaInfo;
   RefPtr<DirectoryLock> mDirectoryLock;
   State mState;
   Atomic<bool> mCanceled;
 
 public:
   NS_DECL_THREADSAFE_ISUPPORTS
@@ -379,17 +379,17 @@ Context::QuotaInitRunnable::Run()
                                                        &mQuotaInfo.mOrigin);
       if (NS_WARN_IF(NS_FAILED(rv))) {
         resolver->Resolve(rv);
         break;
       }
 
       mState = STATE_CREATE_QUOTA_MANAGER;
       MOZ_ALWAYS_SUCCEEDS(
-        mInitiatingThread->Dispatch(this, nsIThread::DISPATCH_NORMAL));
+        mInitiatingEventTarget->Dispatch(this, nsIThread::DISPATCH_NORMAL));
       break;
     }
     // ----------------------------------
     case STATE_CREATE_QUOTA_MANAGER:
     {
       NS_ASSERT_OWNINGTHREAD(QuotaInitRunnable);
 
       if (mCanceled || QuotaManager::IsShuttingDown()) {
@@ -445,17 +445,17 @@ Context::QuotaInitRunnable::Run()
 
       MOZ_ALWAYS_SUCCEEDS(
         mTarget->Dispatch(this, nsIThread::DISPATCH_NORMAL));
       break;
     }
     // -------------------
     case STATE_RUN_ON_TARGET:
     {
-      MOZ_ASSERT(NS_GetCurrentThread() == mTarget);
+      MOZ_ASSERT(mTarget->IsOnCurrentThread());
 
       mState = STATE_RUNNING;
 
       // Execute the provided initialization Action.  The Action must Resolve()
       // before returning.
       mInitAction->RunOnTarget(resolver, mQuotaInfo, mData);
       MOZ_DIAGNOSTIC_ASSERT(resolver->Resolved());
 
@@ -501,24 +501,24 @@ Context::QuotaInitRunnable::Run()
 // Runnable wrapper around Action objects dispatched on the Context.  This
 // runnable executes the Action on the appropriate threads while the Context
 // is initialized.
 class Context::ActionRunnable final : public nsIRunnable
                                     , public Action::Resolver
                                     , public Context::Activity
 {
 public:
-  ActionRunnable(Context* aContext, Data* aData, nsIEventTarget* aTarget,
+  ActionRunnable(Context* aContext, Data* aData, nsISerialEventTarget* aTarget,
                  Action* aAction, const QuotaInfo& aQuotaInfo)
     : mContext(aContext)
     , mData(aData)
     , mTarget(aTarget)
     , mAction(aAction)
     , mQuotaInfo(aQuotaInfo)
-    , mInitiatingThread(NS_GetCurrentThread())
+    , mInitiatingThread(GetCurrentThreadEventTarget())
     , mState(STATE_INIT)
     , mResult(NS_OK)
     , mExecutingRunOnTarget(false)
   {
     MOZ_DIAGNOSTIC_ASSERT(mContext);
     // mData may be nullptr
     MOZ_DIAGNOSTIC_ASSERT(mTarget);
     MOZ_DIAGNOSTIC_ASSERT(mAction);
@@ -551,17 +551,17 @@ public:
   Cancel() override
   {
     NS_ASSERT_OWNINGTHREAD(ActionRunnable);
     mAction->CancelOnInitiatingThread();
   }
 
   virtual void Resolve(nsresult aRv) override
   {
-    MOZ_ASSERT(mTarget == NS_GetCurrentThread());
+    MOZ_ASSERT(mTarget->IsOnCurrentThread());
     MOZ_DIAGNOSTIC_ASSERT(mState == STATE_RUNNING);
 
     mResult = aRv;
 
     // We ultimately must complete on the initiating thread, but bounce through
     // the current thread again to ensure that we don't destroy objects and
     // state out from under the currently running action's stack.
     mState = STATE_RESOLVING;
@@ -605,20 +605,20 @@ private:
     STATE_RUNNING,
     STATE_RESOLVING,
     STATE_COMPLETING,
     STATE_COMPLETE
   };
 
   RefPtr<Context> mContext;
   RefPtr<Data> mData;
-  nsCOMPtr<nsIEventTarget> mTarget;
+  nsCOMPtr<nsISerialEventTarget> mTarget;
   RefPtr<Action> mAction;
   const QuotaInfo mQuotaInfo;
-  nsCOMPtr<nsIThread> mInitiatingThread;
+  nsCOMPtr<nsIEventTarget> mInitiatingThread;
   State mState;
   nsresult mResult;
 
   // Only accessible on target thread;
   bool mExecutingRunOnTarget;
 
 public:
   NS_DECL_THREADSAFE_ISUPPORTS
@@ -662,17 +662,17 @@ NS_IMPL_ISUPPORTS(mozilla::dom::cache::C
 // does not see any execution there.  Its all handled internal to the Action.
 NS_IMETHODIMP
 Context::ActionRunnable::Run()
 {
   switch(mState) {
     // ----------------------
     case STATE_RUN_ON_TARGET:
     {
-      MOZ_ASSERT(NS_GetCurrentThread() == mTarget);
+      MOZ_ASSERT(mTarget->IsOnCurrentThread());
       MOZ_DIAGNOSTIC_ASSERT(!mExecutingRunOnTarget);
 
       // Note that we are calling RunOnTarget().  This lets us detect
       // if Resolve() is called synchronously.
       AutoRestore<bool> executingRunOnTarget(mExecutingRunOnTarget);
       mExecutingRunOnTarget = true;
 
       mState = STATE_RUNNING;
@@ -689,17 +689,17 @@ Context::ActionRunnable::Run()
         Run();
       }
 
       break;
     }
     // -----------------
     case STATE_RESOLVING:
     {
-      MOZ_ASSERT(NS_GetCurrentThread() == mTarget);
+      MOZ_ASSERT(mTarget->IsOnCurrentThread());
       // The call to Action::RunOnTarget() must have returned now if we
       // are running on the target thread again.  We may now proceed
       // with completion.
       mState = STATE_COMPLETING;
       // Shutdown must be delayed until all Contexts are destroyed.  Crash
       // for this invariant violation.
       MOZ_ALWAYS_SUCCEEDS(
         mInitiatingThread->Dispatch(this, nsIThread::DISPATCH_NORMAL));
@@ -724,71 +724,71 @@ Context::ActionRunnable::Run()
     }
   }
   return NS_OK;
 }
 
 void
 Context::ThreadsafeHandle::AllowToClose()
 {
-  if (mOwningThread == NS_GetCurrentThread()) {
+  if (mOwningEventTarget->IsOnCurrentThread()) {
     AllowToCloseOnOwningThread();
     return;
   }
 
   // Dispatch is guaranteed to succeed here because we block shutdown until
   // all Contexts have been destroyed.
   nsCOMPtr<nsIRunnable> runnable =
     NewRunnableMethod(this, &ThreadsafeHandle::AllowToCloseOnOwningThread);
   MOZ_ALWAYS_SUCCEEDS(
-    mOwningThread->Dispatch(runnable, nsIThread::DISPATCH_NORMAL));
+    mOwningEventTarget->Dispatch(runnable.forget(), nsIThread::DISPATCH_NORMAL));
 }
 
 void
 Context::ThreadsafeHandle::InvalidateAndAllowToClose()
 {
-  if (mOwningThread == NS_GetCurrentThread()) {
+  if (mOwningEventTarget->IsOnCurrentThread()) {
     InvalidateAndAllowToCloseOnOwningThread();
     return;
   }
 
   // Dispatch is guaranteed to succeed here because we block shutdown until
   // all Contexts have been destroyed.
   nsCOMPtr<nsIRunnable> runnable =
     NewRunnableMethod(this, &ThreadsafeHandle::InvalidateAndAllowToCloseOnOwningThread);
   MOZ_ALWAYS_SUCCEEDS(
-    mOwningThread->Dispatch(runnable, nsIThread::DISPATCH_NORMAL));
+    mOwningEventTarget->Dispatch(runnable.forget(), nsIThread::DISPATCH_NORMAL));
 }
 
 Context::ThreadsafeHandle::ThreadsafeHandle(Context* aContext)
   : mStrongRef(aContext)
   , mWeakRef(aContext)
-  , mOwningThread(NS_GetCurrentThread())
+  , mOwningEventTarget(GetCurrentThreadSerialEventTarget())
 {
 }
 
 Context::ThreadsafeHandle::~ThreadsafeHandle()
 {
   // Normally we only touch mStrongRef on the owning thread.  This is safe,
   // however, because when we do use mStrongRef on the owning thread we are
   // always holding a strong ref to the ThreadsafeHandle via the owning
   // runnable.  So we cannot run the ThreadsafeHandle destructor simultaneously.
-  if (!mStrongRef || mOwningThread == NS_GetCurrentThread()) {
+  if (!mStrongRef || mOwningEventTarget->IsOnCurrentThread()) {
     return;
   }
 
   // Dispatch is guaranteed to succeed here because we block shutdown until
   // all Contexts have been destroyed.
-  NS_ProxyRelease(mOwningThread, mStrongRef.forget());
+  NS_ProxyRelease(mOwningEventTarget, mStrongRef.forget());
 }
 
 void
 Context::ThreadsafeHandle::AllowToCloseOnOwningThread()
 {
-  MOZ_ASSERT(mOwningThread == NS_GetCurrentThread());
+  MOZ_ASSERT(mOwningEventTarget->IsOnCurrentThread());
 
   // A Context "closes" when its ref count drops to zero.  Dropping this
   // strong ref is necessary, but not sufficient for the close to occur.
   // Any outstanding IO will continue and keep the Context alive.  Once
   // the Context is idle, it will be destroyed.
 
   // First, tell the context to flush any target thread shared data.  This
   // data must be released on the target thread prior to running the Context
@@ -801,49 +801,49 @@ Context::ThreadsafeHandle::AllowToCloseO
   // Now drop our strong ref and let Context finish running any outstanding
   // Actions.
   mStrongRef = nullptr;
 }
 
 void
 Context::ThreadsafeHandle::InvalidateAndAllowToCloseOnOwningThread()
 {
-  MOZ_ASSERT(mOwningThread == NS_GetCurrentThread());
+  MOZ_ASSERT(mOwningEventTarget->IsOnCurrentThread());
   // Cancel the Context through the weak reference.  This means we can
   // allow the Context to close by dropping the strong ref, but then
   // still cancel ongoing IO if necessary.
   if (mWeakRef) {
     mWeakRef->Invalidate();
   }
   // We should synchronously have AllowToCloseOnOwningThread called when
   // the Context is canceled.
   MOZ_DIAGNOSTIC_ASSERT(!mStrongRef);
 }
 
 void
 Context::ThreadsafeHandle::ContextDestroyed(Context* aContext)
 {
-  MOZ_ASSERT(mOwningThread == NS_GetCurrentThread());
+  MOZ_ASSERT(mOwningEventTarget->IsOnCurrentThread());
   MOZ_DIAGNOSTIC_ASSERT(!mStrongRef);
   MOZ_DIAGNOSTIC_ASSERT(mWeakRef);
   MOZ_DIAGNOSTIC_ASSERT(mWeakRef == aContext);
   mWeakRef = nullptr;
 }
 
 // static
 already_AddRefed<Context>
-Context::Create(Manager* aManager, nsIThread* aTarget,
+Context::Create(Manager* aManager, nsISerialEventTarget* aTarget,
                 Action* aInitAction, Context* aOldContext)
 {
   RefPtr<Context> context = new Context(aManager, aTarget, aInitAction);
   context->Init(aOldContext);
   return context.forget();
 }
 
-Context::Context(Manager* aManager, nsIThread* aTarget, Action* aInitAction)
+Context::Context(Manager* aManager, nsISerialEventTarget* aTarget, Action* aInitAction)
   : mManager(aManager)
   , mTarget(aTarget)
   , mData(new Data(aTarget))
   , mState(STATE_CONTEXT_PREINIT)
   , mOrphanedData(false)
   , mInitAction(aInitAction)
 {
   MOZ_DIAGNOSTIC_ASSERT(mManager);
--- a/dom/cache/Context.h
+++ b/dom/cache/Context.h
@@ -92,17 +92,17 @@ public:
     // owning thread.
     RefPtr<Context> mStrongRef;
 
     // Used to support cancelation even while the Context is already allowed
     // to close.  Cleared by ~Context() calling ContextDestroyed().  Only
     // safe to access on owning thread.
     Context* mWeakRef;
 
-    nsCOMPtr<nsIThread> mOwningThread;
+    nsCOMPtr<nsISerialEventTarget> mOwningEventTarget;
 
     NS_INLINE_DECL_THREADSAFE_REFCOUNTING(cache::Context::ThreadsafeHandle)
   };
 
   // Different objects hold references to the Context while some work is being
   // performed asynchronously.  These objects must implement the Activity
   // interface and register themselves with the AddActivity().  When they are
   // destroyed they must call RemoveActivity().  This allows the Context to
@@ -113,17 +113,17 @@ public:
     virtual void Cancel() = 0;
     virtual bool MatchesCacheId(CacheId aCacheId) const = 0;
   };
 
   // Create a Context attached to the given Manager.  The given Action
   // will run on the QuotaManager IO thread.  Note, this Action must
   // be execute synchronously.
   static already_AddRefed<Context>
-  Create(Manager* aManager, nsIThread* aTarget,
+  Create(Manager* aManager, nsISerialEventTarget* aTarget,
          Action* aInitAction, Context* aOldContext);
 
   // Execute given action on the target once the quota manager has been
   // initialized.
   //
   // Only callable from the thread that created the Context.
   void Dispatch(Action* aAction);
 
@@ -178,17 +178,17 @@ private:
   };
 
   struct PendingAction
   {
     nsCOMPtr<nsIEventTarget> mTarget;
     RefPtr<Action> mAction;
   };
 
-  Context(Manager* aManager, nsIThread* aTarget, Action* aInitAction);
+  Context(Manager* aManager, nsISerialEventTarget* aTarget, Action* aInitAction);
   ~Context();
   void Init(Context* aOldContext);
   void Start();
   void DispatchAction(Action* aAction, bool aDoomData = false);
   void OnQuotaInit(nsresult aRv, const QuotaInfo& aQuotaInfo,
                    already_AddRefed<DirectoryLock> aDirectoryLock);
 
 
@@ -197,17 +197,17 @@ private:
 
   void
   SetNextContext(Context* aNextContext);
 
   void
   DoomTargetData();
 
   RefPtr<Manager> mManager;
-  nsCOMPtr<nsIThread> mTarget;
+  nsCOMPtr<nsISerialEventTarget> mTarget;
   RefPtr<Data> mData;
   State mState;
   bool mOrphanedData;
   QuotaInfo mQuotaInfo;
   RefPtr<QuotaInitRunnable> mInitRunnable;
   RefPtr<Action> mInitAction;
   nsTArray<PendingAction> mPendingActions;
 
--- a/dom/cache/Manager.cpp
+++ b/dom/cache/Manager.cpp
@@ -644,19 +644,19 @@ private:
   {
     MOZ_DIAGNOSTIC_ASSERT(aResolver);
     MOZ_DIAGNOSTIC_ASSERT(aDBDir);
     MOZ_DIAGNOSTIC_ASSERT(aConn);
     MOZ_DIAGNOSTIC_ASSERT(!mResolver);
     MOZ_DIAGNOSTIC_ASSERT(!mDBDir);
     MOZ_DIAGNOSTIC_ASSERT(!mConn);
 
-    MOZ_DIAGNOSTIC_ASSERT(!mTargetThread);
-    mTargetThread = NS_GetCurrentThread();
-    MOZ_DIAGNOSTIC_ASSERT(mTargetThread);
+    MOZ_DIAGNOSTIC_ASSERT(!mTarget);
+    mTarget = GetCurrentThreadSerialEventTarget();
+    MOZ_DIAGNOSTIC_ASSERT(mTarget);
 
     // We should be pre-initialized to expect one async completion.  This is
     // the "manual" completion we call at the end of this method in all
     // cases.
     MOZ_DIAGNOSTIC_ASSERT(mExpectedAsyncCopyCompletions == 1);
 
     mResolver = aResolver;
     mDBDir = aDBDir;
@@ -689,17 +689,17 @@ private:
   }
 
   // Called once for each asynchronous file copy whether it succeeds or
   // fails.  If a file copy is canceled, it still calls this method with
   // an error code.
   void
   OnAsyncCopyComplete(nsresult aRv)
   {
-    MOZ_ASSERT(mTargetThread == NS_GetCurrentThread());
+    MOZ_ASSERT(mTarget->IsOnCurrentThread());
     MOZ_DIAGNOSTIC_ASSERT(mConn);
     MOZ_DIAGNOSTIC_ASSERT(mResolver);
     MOZ_DIAGNOSTIC_ASSERT(mExpectedAsyncCopyCompletions > 0);
 
     // Explicitly check for cancellation here to catch a race condition.
     // Consider:
     //
     // 1) NS_AsyncCopy() executes on IO thread, but has not saved its
@@ -836,17 +836,17 @@ private:
     RequestStream,
     ResponseStream
   };
 
   nsresult
   StartStreamCopy(const QuotaInfo& aQuotaInfo, Entry& aEntry,
                   StreamId aStreamId, uint32_t* aCopyCountOut)
   {
-    MOZ_ASSERT(mTargetThread == NS_GetCurrentThread());
+    MOZ_ASSERT(mTarget->IsOnCurrentThread());
     MOZ_DIAGNOSTIC_ASSERT(aCopyCountOut);
 
     if (IsCanceled()) {
       return NS_ERROR_ABORT;
     }
 
     nsCOMPtr<nsIInputStream> source;
     nsID* bodyId;
@@ -909,23 +909,23 @@ private:
   CallOnAsyncCopyCompleteOnTargetThread(nsresult aRv)
   {
     // May be on any thread, including STS event target.  Non-owning runnable
     // here since we are guaranteed the Action will survive until
     // CompleteOnInitiatingThread is called.
     nsCOMPtr<nsIRunnable> runnable = NewNonOwningRunnableMethod<nsresult>(
       this, &CachePutAllAction::OnAsyncCopyComplete, aRv);
     MOZ_ALWAYS_SUCCEEDS(
-      mTargetThread->Dispatch(runnable, nsIThread::DISPATCH_NORMAL));
+      mTarget->Dispatch(runnable.forget(), nsIThread::DISPATCH_NORMAL));
   }
 
   void
   DoResolve(nsresult aRv)
   {
-    MOZ_ASSERT(mTargetThread == NS_GetCurrentThread());
+    MOZ_ASSERT(mTarget->IsOnCurrentThread());
 
     // DoResolve() must not be called until all async copying has completed.
 #ifdef DEBUG
     {
       MutexAutoLock lock(mMutex);
       MOZ_ASSERT(mCopyContextList.IsEmpty());
     }
 #endif
@@ -936,17 +936,17 @@ private:
     }
 
     // Must be released on the target thread where it was opened.
     mConn = nullptr;
 
     // Drop our ref to the target thread as we are done with this thread.
     // Also makes our thread assertions catch any incorrect method calls
     // after resolve.
-    mTargetThread = nullptr;
+    mTarget = nullptr;
 
     // Make sure to de-ref the resolver per the Action API contract.
     RefPtr<Action::Resolver> resolver;
     mResolver.swap(resolver);
     resolver->Resolve(aRv);
   }
 
   // initiating thread only
@@ -958,17 +958,17 @@ private:
   const CacheId mCacheId;
   nsTArray<Entry> mList;
   uint32_t mExpectedAsyncCopyCompletions;
 
   // target thread only
   RefPtr<Resolver> mResolver;
   nsCOMPtr<nsIFile> mDBDir;
   nsCOMPtr<mozIStorageConnection> mConn;
-  nsCOMPtr<nsIThread> mTargetThread;
+  nsCOMPtr<nsISerialEventTarget> mTarget;
   nsresult mAsyncResult;
   nsTArray<nsID> mBodyIdWrittenList;
 
   // Written to on target thread, accessed on initiating thread after target
   // thread activity is guaranteed complete
   nsTArray<nsID> mDeletedBodyIdList;
 
   // accessed from any thread while mMutex locked
@@ -1778,18 +1778,18 @@ Manager::Init(Manager* aOldManager)
   if (aOldManager) {
     oldContext = aOldManager->mContext;
   }
 
   // Create the context immediately.  Since there can at most be one Context
   // per Manager now, this lets us cleanly call Factory::Remove() once the
   // Context goes away.
   RefPtr<Action> setupAction = new SetupAction();
-  RefPtr<Context> ref = Context::Create(this, mIOThread, setupAction,
-                                          oldContext);
+  RefPtr<Context> ref = Context::Create(this, mIOThread->SerialEventTarget(), setupAction,
+                                        oldContext);
   mContext = ref;
 }
 
 void
 Manager::Shutdown()
 {
   NS_ASSERT_OWNINGTHREAD(Manager);
 
--- a/dom/cache/PrincipalVerifier.cpp
+++ b/dom/cache/PrincipalVerifier.cpp
@@ -62,21 +62,21 @@ PrincipalVerifier::RemoveListener(Listen
   MOZ_ALWAYS_TRUE(mListenerList.RemoveElement(aListener));
 }
 
 PrincipalVerifier::PrincipalVerifier(Listener* aListener,
                                      PBackgroundParent* aActor,
                                      const PrincipalInfo& aPrincipalInfo)
   : mActor(BackgroundParent::GetContentParent(aActor))
   , mPrincipalInfo(aPrincipalInfo)
-  , mInitiatingThread(NS_GetCurrentThread())
+  , mInitiatingEventTarget(GetCurrentThreadSerialEventTarget())
   , mResult(NS_OK)
 {
   AssertIsOnBackgroundThread();
-  MOZ_DIAGNOSTIC_ASSERT(mInitiatingThread);
+  MOZ_DIAGNOSTIC_ASSERT(mInitiatingEventTarget);
   MOZ_DIAGNOSTIC_ASSERT(aListener);
 
   mListenerList.AppendElement(aListener);
 }
 
 PrincipalVerifier::~PrincipalVerifier()
 {
   // Since the PrincipalVerifier is a Runnable that executes on multiple
@@ -198,17 +198,17 @@ PrincipalVerifier::DispatchToInitiatingT
 
   mResult = aRv;
 
   // The Cache ShutdownObserver does not track all principal verifiers, so we
   // cannot ensure this always succeeds.  Instead, simply warn on failures.
   // This will result in a new CacheStorage object delaying operations until
   // shutdown completes and the browser goes away.  This is as graceful as
   // we can get here.
-  nsresult rv = mInitiatingThread->Dispatch(this, nsIThread::DISPATCH_NORMAL);
+  nsresult rv = mInitiatingEventTarget->Dispatch(this, nsIThread::DISPATCH_NORMAL);
   if (NS_FAILED(rv)) {
     NS_WARNING("Cache unable to complete principal verification due to shutdown.");
   }
 }
 
 } // namespace cache
 } // namespace dom
 } // namespace mozilla
--- a/dom/cache/PrincipalVerifier.h
+++ b/dom/cache/PrincipalVerifier.h
@@ -59,17 +59,17 @@ private:
   typedef nsTObserverArray<Listener*> ListenerList;
   ListenerList mListenerList;
 
   // set in originating thread at construction, but must be accessed and
   // released on main thread
   RefPtr<ContentParent> mActor;
 
   const mozilla::ipc::PrincipalInfo mPrincipalInfo;
-  nsCOMPtr<nsIThread> mInitiatingThread;
+  nsCOMPtr<nsIEventTarget> mInitiatingEventTarget;
   nsresult mResult;
   RefPtr<ManagerId> mManagerId;
 
 public:
   NS_DECL_NSIRUNNABLE
 };
 
 } // namespace cache
--- a/dom/cache/ReadStream.cpp
+++ b/dom/cache/ReadStream.cpp
@@ -94,17 +94,17 @@ private:
 
   // Weak ref to the stream control actor.  The actor will always call either
   // CloseStream() or CloseStreamWithoutReporting() before it's destroyed.  The
   // weak ref is cleared in the resulting NoteClosedOnOwningThread() or
   // ForgetOnOwningThread() method call.
   StreamControl* mControl;
 
   const nsID mId;
-  nsCOMPtr<nsIThread> mOwningThread;
+  nsCOMPtr<nsISerialEventTarget> mOwningEventTarget;
 
   enum State
   {
     Open,
     Closed,
     NumStates
   };
   Atomic<State> mState;
@@ -192,45 +192,45 @@ private:
 };
 
 // ----------------------------------------------------------------------------
 
 ReadStream::Inner::Inner(StreamControl* aControl, const nsID& aId,
                          nsIInputStream* aStream)
   : mControl(aControl)
   , mId(aId)
-  , mOwningThread(NS_GetCurrentThread())
+  , mOwningEventTarget(GetCurrentThreadSerialEventTarget())
   , mState(Open)
   , mHasEverBeenRead(false)
   , mMutex("dom::cache::ReadStream")
   , mStream(aStream)
   , mSnappyStream(new SnappyUncompressInputStream(aStream))
 {
   MOZ_DIAGNOSTIC_ASSERT(mStream);
   MOZ_DIAGNOSTIC_ASSERT(mControl);
   mControl->AddReadStream(this);
 }
 
 void
 ReadStream::Inner::Serialize(CacheReadStreamOrVoid* aReadStreamOut,
                              nsTArray<UniquePtr<AutoIPCStream>>& aStreamCleanupList,
                              ErrorResult& aRv)
 {
-  MOZ_ASSERT(NS_GetCurrentThread() == mOwningThread);
+  MOZ_ASSERT(mOwningEventTarget->IsOnCurrentThread());
   MOZ_DIAGNOSTIC_ASSERT(aReadStreamOut);
   *aReadStreamOut = CacheReadStream();
   Serialize(&aReadStreamOut->get_CacheReadStream(), aStreamCleanupList, aRv);
 }
 
 void
 ReadStream::Inner::Serialize(CacheReadStream* aReadStreamOut,
                              nsTArray<UniquePtr<AutoIPCStream>>& aStreamCleanupList,
                              ErrorResult& aRv)
 {
-  MOZ_ASSERT(NS_GetCurrentThread() == mOwningThread);
+  MOZ_ASSERT(mOwningEventTarget->IsOnCurrentThread());
   MOZ_DIAGNOSTIC_ASSERT(aReadStreamOut);
 
   if (mState != Open) {
     aRv.ThrowTypeError<MSG_CACHE_STREAM_CLOSED>();
     return;
   }
 
   MOZ_DIAGNOSTIC_ASSERT(mControl);
@@ -249,38 +249,38 @@ ReadStream::Inner::Serialize(CacheReadSt
   // We're passing ownership across the IPC barrier with the control, so
   // do not signal that the stream is closed here.
   Forget();
 }
 
 void
 ReadStream::Inner::CloseStream()
 {
-  MOZ_ASSERT(NS_GetCurrentThread() == mOwningThread);
+  MOZ_ASSERT(mOwningEventTarget->IsOnCurrentThread());
   Close();
 }
 
 void
 ReadStream::Inner::CloseStreamWithoutReporting()
 {
-  MOZ_ASSERT(NS_GetCurrentThread() == mOwningThread);
+  MOZ_ASSERT(mOwningEventTarget->IsOnCurrentThread());
   Forget();
 }
 
 bool
 ReadStream::Inner::MatchId(const nsID& aId) const
 {
-  MOZ_ASSERT(NS_GetCurrentThread() == mOwningThread);
+  MOZ_ASSERT(mOwningEventTarget->IsOnCurrentThread());
   return mId.Equals(aId);
 }
 
 bool
 ReadStream::Inner::HasEverBeenRead() const
 {
-  MOZ_ASSERT(NS_GetCurrentThread() == mOwningThread);
+  MOZ_ASSERT(mOwningEventTarget->IsOnCurrentThread());
   return mHasEverBeenRead;
 }
 
 nsresult
 ReadStream::Inner::Close()
 {
   // stream ops can happen on any thread
   nsresult rv = NS_OK;
@@ -383,63 +383,63 @@ ReadStream::Inner::~Inner()
 void
 ReadStream::Inner::NoteClosed()
 {
   // Any thread
   if (mState == Closed) {
     return;
   }
 
-  if (NS_GetCurrentThread() == mOwningThread) {
+  if (mOwningEventTarget->IsOnCurrentThread()) {
     NoteClosedOnOwningThread();
     return;
   }
 
   nsCOMPtr<nsIRunnable> runnable = new NoteClosedRunnable(this);
   MOZ_ALWAYS_SUCCEEDS(
-    mOwningThread->Dispatch(runnable, nsIThread::DISPATCH_NORMAL));
+    mOwningEventTarget->Dispatch(runnable.forget(), nsIThread::DISPATCH_NORMAL));
 }
 
 void
 ReadStream::Inner::Forget()
 {
   // Any thread
   if (mState == Closed) {
     return;
   }
 
-  if (NS_GetCurrentThread() == mOwningThread) {
+  if (mOwningEventTarget->IsOnCurrentThread()) {
     ForgetOnOwningThread();
     return;
   }
 
   nsCOMPtr<nsIRunnable> runnable = new ForgetRunnable(this);
   MOZ_ALWAYS_SUCCEEDS(
-    mOwningThread->Dispatch(runnable, nsIThread::DISPATCH_NORMAL));
+    mOwningEventTarget->Dispatch(runnable.forget(), nsIThread::DISPATCH_NORMAL));
 }
 
 void
 ReadStream::Inner::NoteClosedOnOwningThread()
 {
-  MOZ_ASSERT(NS_GetCurrentThread() == mOwningThread);
+  MOZ_ASSERT(mOwningEventTarget->IsOnCurrentThread());
 
   // Mark closed and do nothing if we were already closed
   if (!mState.compareExchange(Open, Closed)) {
     return;
   }
 
   MOZ_DIAGNOSTIC_ASSERT(mControl);
   mControl->NoteClosed(this, mId);
   mControl = nullptr;
 }
 
 void
 ReadStream::Inner::ForgetOnOwningThread()
 {
-  MOZ_ASSERT(NS_GetCurrentThread() == mOwningThread);
+  MOZ_ASSERT(mOwningEventTarget->IsOnCurrentThread());
 
   // Mark closed and do nothing if we were already closed
   if (!mState.compareExchange(Open, Closed)) {
     return;
   }
 
   MOZ_DIAGNOSTIC_ASSERT(mControl);
   mControl->ForgetReadStream(this);
--- a/dom/canvas/OffscreenCanvas.cpp
+++ b/dom/canvas/OffscreenCanvas.cpp
@@ -81,20 +81,20 @@ OffscreenCanvas::Constructor(const Globa
 
 void
 OffscreenCanvas::ClearResources()
 {
   if (mCanvasClient) {
     mCanvasClient->Clear();
 
     if (mCanvasRenderer) {
-      nsCOMPtr<nsIThread> activeThread = mCanvasRenderer->GetActiveThread();
-      MOZ_RELEASE_ASSERT(activeThread, "GFX: failed to get active thread.");
+      nsCOMPtr<nsISerialEventTarget> activeTarget = mCanvasRenderer->GetActiveThread();
+      MOZ_RELEASE_ASSERT(activeTarget, "GFX: failed to get active event target.");
       bool current;
-      activeThread->IsOnCurrentThread(&current);
+      activeTarget->IsOnCurrentThread(&current);
       MOZ_RELEASE_ASSERT(current, "GFX: active thread is not current thread.");
       mCanvasRenderer->SetCanvasClient(nullptr);
       mCanvasRenderer->mContext = nullptr;
       mCanvasRenderer->mGLContext = nullptr;
       mCanvasRenderer->ResetActiveThread();
     }
 
     mCanvasClient = nullptr;
--- a/dom/canvas/WebGLContextLossHandler.cpp
+++ b/dom/canvas/WebGLContextLossHandler.cpp
@@ -40,35 +40,34 @@ NS_IMPL_ISUPPORTS(WatchdogTimerEvent, ns
 ////////////////////////////////////////
 
 WebGLContextLossHandler::WebGLContextLossHandler(WebGLContext* webgl)
     : mWebGL(webgl)
     , mTimer(do_CreateInstance(NS_TIMER_CONTRACTID))
     , mTimerPending(false)
     , mShouldRunTimerAgain(false)
 #ifdef DEBUG
-    , mThread(NS_GetCurrentThread())
+    , mEventTarget(GetCurrentThreadSerialEventTarget())
 #endif
 {
-    MOZ_ASSERT(mThread);
+    MOZ_ASSERT(mEventTarget);
 }
 
 WebGLContextLossHandler::~WebGLContextLossHandler()
 {
-    // NS_GetCurrentThread() returns null during shutdown.
-    const DebugOnly<nsIThread*> callingThread = NS_GetCurrentThread();
-    MOZ_ASSERT(callingThread == mThread || !callingThread);
+    const DebugOnly<nsISerialEventTarget*> callingThread = GetCurrentThreadSerialEventTarget();
+    MOZ_ASSERT(!callingThread || mEventTarget->IsOnCurrentThread());
 }
 
 ////////////////////
 
 void
 WebGLContextLossHandler::RunTimer()
 {
-    MOZ_ASSERT(NS_GetCurrentThread() == mThread);
+    MOZ_ASSERT(mEventTarget->IsOnCurrentThread());
 
     // If the timer was already running, don't restart it here. Instead,
     // wait until the previous call is done, then fire it one more time.
     // This is also an optimization to prevent unnecessary
     // cross-communication between threads.
     if (mTimerPending) {
         mShouldRunTimerAgain = true;
         return;
@@ -81,17 +80,17 @@ WebGLContextLossHandler::RunTimer()
     mTimerPending = true;
 }
 
 ////////////////////
 
 void
 WebGLContextLossHandler::TimerCallback()
 {
-    MOZ_ASSERT(NS_GetCurrentThread() == mThread);
+    MOZ_ASSERT(mEventTarget->IsOnCurrentThread());
 
     mTimerPending = false;
 
     const bool runOnceMore = mShouldRunTimerAgain;
     mShouldRunTimerAgain = false;
 
     mWebGL->UpdateContextLossStatus();
 
--- a/dom/canvas/WebGLContextLossHandler.h
+++ b/dom/canvas/WebGLContextLossHandler.h
@@ -17,17 +17,17 @@ class WebGLContext;
 
 class WebGLContextLossHandler final : public SupportsWeakPtr<WebGLContextLossHandler>
 {
     WebGLContext* const mWebGL;
     const nsCOMPtr<nsITimer> mTimer; // If we don't hold a ref to the timer, it will think
     bool mTimerPending;              // that it's been discarded, and be canceled 'for our
     bool mShouldRunTimerAgain;       // convenience'.
 #ifdef DEBUG
-    nsIThread* const mThread;
+    nsISerialEventTarget* const mEventTarget;
 #endif
 
     friend class WatchdogTimerEvent;
 
 public:
     MOZ_DECLARE_WEAKREFERENCE_TYPENAME(WebGLContextLossHandler)
 
     explicit WebGLContextLossHandler(WebGLContext* webgl);
--- a/dom/crypto/WebCryptoTask.cpp
+++ b/dom/crypto/WebCryptoTask.cpp
@@ -379,17 +379,17 @@ WebCryptoTask::DispatchWithPromise(Promi
   // Skip NSS if we're already done, or launch a CryptoTask
   if (mEarlyComplete) {
     CallCallback(mEarlyRv);
     Skip();
     return;
   }
 
   // Store calling thread
-  mOriginalThread = NS_GetCurrentThread();
+  mOriginalEventTarget = GetCurrentThreadSerialEventTarget();
 
   // If we are running on a worker thread we must hold the worker
   // alive while we work on the thread pool.  Otherwise the worker
   // private may get torn down before we dispatch back to complete
   // the transaction.
   if (!NS_IsMainThread()) {
     mWorkerHolder = InternalWorkerHolder::Create();
     // If we can't register a holder then the worker is already
@@ -414,17 +414,17 @@ WebCryptoTask::Run()
 
     if (isAlreadyShutDown()) {
       mRv = NS_ERROR_NOT_AVAILABLE;
     } else {
       mRv = CalculateResult();
     }
 
     // Back to the original thread, i.e. continue below.
-    mOriginalThread->Dispatch(this, NS_DISPATCH_NORMAL);
+    mOriginalEventTarget->Dispatch(this, NS_DISPATCH_NORMAL);
     return NS_OK;
   }
 
   // We're now back on the calling thread.
 
   // Release NSS resources now, before calling CallCallback, so that
   // WebCryptoTasks have consistent behavior regardless of whether NSS is shut
   // down between CalculateResult being called and CallCallback being called.
@@ -3724,30 +3724,30 @@ WebCryptoTask::CreateUnwrapKeyTask(nsIGl
 
   return new FailureTask(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
 }
 
 WebCryptoTask::WebCryptoTask()
   : CancelableRunnable("WebCryptoTask")
   , mEarlyRv(NS_OK)
   , mEarlyComplete(false)
-  , mOriginalThread(nullptr)
+  , mOriginalEventTarget(nullptr)
   , mReleasedNSSResources(false)
   , mRv(NS_ERROR_NOT_INITIALIZED)
 {
 }
 
 WebCryptoTask::~WebCryptoTask()
 {
   MOZ_ASSERT(mReleasedNSSResources);
 
   nsNSSShutDownPreventionLock lock;
   if (!isAlreadyShutDown()) {
     shutdown(ShutdownCalledFrom::Object);
   }
 
   if (mWorkerHolder) {
-    NS_ProxyRelease(mOriginalThread, mWorkerHolder.forget());
+    NS_ProxyRelease(mOriginalEventTarget, mWorkerHolder.forget());
   }
 }
 
 } // namespace dom
 } // namespace mozilla
--- a/dom/crypto/WebCryptoTask.h
+++ b/dom/crypto/WebCryptoTask.h
@@ -169,17 +169,17 @@ protected:
   RefPtr<Promise> mResultPromise;
   nsresult mEarlyRv;
   bool mEarlyComplete;
 
   WebCryptoTask();
   virtual ~WebCryptoTask();
 
   bool IsOnOriginalThread() {
-    return !mOriginalThread || NS_GetCurrentThread() == mOriginalThread;
+    return !mOriginalEventTarget || mOriginalEventTarget->IsOnCurrentThread();
   }
 
   // For things that need to happen on the main thread
   // either before or after CalculateResult
   virtual nsresult BeforeCrypto() { return NS_OK; }
   virtual nsresult DoCrypto() { return NS_OK; }
   virtual nsresult AfterCrypto() { return NS_OK; }
   virtual void Resolve() {}
@@ -207,17 +207,17 @@ private:
     if (!mReleasedNSSResources) {
       mReleasedNSSResources = true;
       ReleaseNSSResources();
     }
   }
 
   class InternalWorkerHolder;
 
-  nsCOMPtr<nsIThread> mOriginalThread;
+  nsCOMPtr<nsISerialEventTarget> mOriginalEventTarget;
   RefPtr<InternalWorkerHolder> mWorkerHolder;
   bool mReleasedNSSResources;
   nsresult mRv;
 };
 
 // XXX This class is declared here (unlike others) to enable reuse by WebRTC.
 class GenerateAsymmetricKeyTask : public WebCryptoTask
 {
--- a/dom/file/FileReader.cpp
+++ b/dom/file/FileReader.cpp
@@ -115,17 +115,17 @@ FileReader::FileReader(nsIGlobalObject* 
   , mWorkerPrivate(aWorkerPrivate)
 {
   MOZ_ASSERT(aGlobal);
   MOZ_ASSERT(NS_IsMainThread() == !mWorkerPrivate);
 
   if (NS_IsMainThread()) {
     mTarget = aGlobal->EventTargetFor(TaskCategory::Other);
   } else {
-    mTarget = do_GetCurrentThread();
+    mTarget = GetCurrentThreadSerialEventTarget();
   }
 
   SetDOMStringToNull(mResult);
 }
 
 FileReader::~FileReader()
 {
   Shutdown();
--- a/dom/file/MutableBlobStorage.cpp
+++ b/dom/file/MutableBlobStorage.cpp
@@ -366,17 +366,17 @@ MutableBlobStorage::MutableBlobStorage(M
   , mStorageState(aType == eOnlyInMemory ? eKeepInMemory : eInMemory)
   , mFD(nullptr)
   , mErrorResult(NS_OK)
   , mEventTarget(aEventTarget)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   if (!mEventTarget) {
-    mEventTarget = do_GetMainThread();
+    mEventTarget = GetMainThreadEventTarget();
   }
 
   MOZ_ASSERT(mEventTarget);
 }
 
 MutableBlobStorage::~MutableBlobStorage()
 {
   free(mData);
--- a/dom/file/MutableBlobStreamListener.cpp
+++ b/dom/file/MutableBlobStreamListener.cpp
@@ -19,17 +19,17 @@ MutableBlobStreamListener::MutableBlobSt
   , mStorageType(aStorageType)
   , mContentType(aContentType)
   , mEventTarget(aEventTarget)
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(aCallback);
 
   if (!mEventTarget) {
-    mEventTarget = do_GetMainThread();
+    mEventTarget = GetMainThreadEventTarget();
   }
 
   MOZ_ASSERT(mEventTarget);
 }
 
 MutableBlobStreamListener::~MutableBlobStreamListener()
 {
   MOZ_ASSERT(NS_IsMainThread());
--- a/dom/file/ipc/IPCBlobInputStream.cpp
+++ b/dom/file/ipc/IPCBlobInputStream.cpp
@@ -298,17 +298,17 @@ IPCBlobInputStream::MaybeExecuteCallback
 
     mCallback = aCallback;
     mCallbackEventTarget = aCallbackEventTarget;
 
     if (!mCallback) {
       return NS_OK;
     }
 
-    nsCOMPtr<nsIEventTarget> target = NS_GetCurrentThread();
+    RefPtr<nsIEventTarget> target = GetCurrentThreadEventTarget();
     return asyncStream->AsyncWait(this, 0, 0, target);
   }
 
   MOZ_ASSERT(!mCallback);
   MOZ_ASSERT(!mCallbackEventTarget);
 
   if (!aCallback) {
     return NS_OK;
--- a/dom/file/ipc/IPCBlobInputStreamChild.cpp
+++ b/dom/file/ipc/IPCBlobInputStreamChild.cpp
@@ -126,17 +126,17 @@ private:
 } // anonymous
 
 IPCBlobInputStreamChild::IPCBlobInputStreamChild(const nsID& aID,
                                                  uint64_t aSize)
   : mMutex("IPCBlobInputStreamChild::mMutex")
   , mID(aID)
   , mSize(aSize)
   , mState(eActive)
-  , mOwningThread(NS_GetCurrentThread())
+  , mOwningEventTarget(GetCurrentThreadSerialEventTarget())
 {
   // If we are running in a worker, we need to send a Close() to the parent side
   // before the thread is released.
   if (!NS_IsMainThread()) {
     WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
     if (workerPrivate) {
       UniquePtr<WorkerHolder> workerHolder(
         new IPCBlobInputStreamWorkerHolder());
@@ -210,17 +210,17 @@ IPCBlobInputStreamChild::CreateStream()
 
     if (mState == eInactive) {
       return nullptr;
     }
 
     // The stream is active but maybe it is not running in the DOM-File thread.
     // We should migrate it there.
     if (mState == eActive &&
-        !IPCBlobInputStreamThread::IsOnFileThread(mOwningThread)) {
+        !IPCBlobInputStreamThread::IsOnFileEventTarget(mOwningEventTarget)) {
       MOZ_ASSERT(mStreams.IsEmpty());
       shouldMigrate = true;
       mState = eActiveMigrating;
     }
 
     mStreams.AppendElement(stream);
   }
 
@@ -244,23 +244,23 @@ IPCBlobInputStreamChild::ForgetStream(IP
     MutexAutoLock lock(mMutex);
     mStreams.RemoveElement(aStream);
 
     if (!mStreams.IsEmpty() || mState != eActive) {
       return;
     }
   }
 
-  if (mOwningThread == NS_GetCurrentThread()) {
+  if (mOwningEventTarget->IsOnCurrentThread()) {
     Shutdown();
     return;
   }
 
   RefPtr<ShutdownRunnable> runnable = new ShutdownRunnable(this);
-  mOwningThread->Dispatch(runnable, NS_DISPATCH_NORMAL);
+  mOwningEventTarget->Dispatch(runnable, NS_DISPATCH_NORMAL);
 }
 
 void
 IPCBlobInputStreamChild::StreamNeeded(IPCBlobInputStream* aStream,
                                       nsIEventTarget* aEventTarget)
 {
   MutexAutoLock lock(mMutex);
 
@@ -276,23 +276,23 @@ IPCBlobInputStreamChild::StreamNeeded(IP
 
   if (mState == eActiveMigrating || mState == eInactiveMigrating) {
     // This operation will be continued when the migration is completed.
     return;
   }
 
   MOZ_ASSERT(mState == eActive);
 
-  if (mOwningThread == NS_GetCurrentThread()) {
+  if (mOwningEventTarget->IsOnCurrentThread()) {
     SendStreamNeeded();
     return;
   }
 
   RefPtr<StreamNeededRunnable> runnable = new StreamNeededRunnable(this);
-  mOwningThread->Dispatch(runnable, NS_DISPATCH_NORMAL);
+  mOwningEventTarget->Dispatch(runnable.forget(), NS_DISPATCH_NORMAL);
 }
 
 mozilla::ipc::IPCResult
 IPCBlobInputStreamChild::RecvStreamReady(const OptionalIPCStream& aStream)
 {
   nsCOMPtr<nsIInputStream> stream = mozilla::ipc::DeserializeIPCStream(aStream);
 
   RefPtr<IPCBlobInputStream> pendingStream;
@@ -320,21 +320,21 @@ void
 IPCBlobInputStreamChild::Migrated()
 {
   MutexAutoLock lock(mMutex);
   MOZ_ASSERT(mState == eInactiveMigrating);
 
   if (mWorkerHolder) {
     RefPtr<ReleaseWorkerHolderRunnable> runnable =
       new ReleaseWorkerHolderRunnable(Move(mWorkerHolder));
-    mOwningThread->Dispatch(runnable, NS_DISPATCH_NORMAL);
+    mOwningEventTarget->Dispatch(runnable, NS_DISPATCH_NORMAL);
   }
 
-  mOwningThread = NS_GetCurrentThread();
-  MOZ_ASSERT(IPCBlobInputStreamThread::IsOnFileThread(mOwningThread));
+  mOwningEventTarget = GetCurrentThreadSerialEventTarget();
+  MOZ_ASSERT(IPCBlobInputStreamThread::IsOnFileEventTarget(mOwningEventTarget));
 
   // Maybe we have no reasons to keep this actor alive.
   if (mStreams.IsEmpty()) {
     mState = eInactive;
     SendClose();
     return;
   }
 
--- a/dom/file/ipc/IPCBlobInputStreamChild.h
+++ b/dom/file/ipc/IPCBlobInputStreamChild.h
@@ -103,17 +103,17 @@ private:
   // This struct and the array are used for creating streams when needed.
   struct PendingOperation
   {
     RefPtr<IPCBlobInputStream> mStream;
     nsCOMPtr<nsIEventTarget> mEventTarget;
   };
   nsTArray<PendingOperation> mPendingOperations;
 
-  nsCOMPtr<nsIThread> mOwningThread;
+  nsCOMPtr<nsISerialEventTarget> mOwningEventTarget;
 
   UniquePtr<workers::WorkerHolder> mWorkerHolder;
 };
 
 } // namespace dom
 } // namespace mozilla
 
 #endif // mozilla_dom_ipc_IPCBlobInputStreamChild_h
--- a/dom/file/ipc/IPCBlobInputStreamThread.cpp
+++ b/dom/file/ipc/IPCBlobInputStreamThread.cpp
@@ -86,22 +86,22 @@ private:
 NS_IMPL_ISUPPORTS_INHERITED(MigrateActorRunnable, Runnable,
                   nsIIPCBackgroundChildCreateCallback)
 
 } // anonymous
 
 NS_IMPL_ISUPPORTS(IPCBlobInputStreamThread, nsIObserver)
 
 /* static */ bool
-IPCBlobInputStreamThread::IsOnFileThread(nsIThread* aThread)
+IPCBlobInputStreamThread::IsOnFileEventTarget(nsIEventTarget* aEventTarget)
 {
-  MOZ_ASSERT(aThread);
+  MOZ_ASSERT(aEventTarget);
 
   mozilla::StaticMutexAutoLock lock(gIPCBlobThreadMutex);
-  return gIPCBlobThread && aThread == gIPCBlobThread->mThread;
+  return gIPCBlobThread && aEventTarget == gIPCBlobThread->mThread;
 }
 
 /* static */ IPCBlobInputStreamThread*
 IPCBlobInputStreamThread::GetOrCreate()
 {
   mozilla::StaticMutexAutoLock lock(gIPCBlobThreadMutex);
 
   if (gShutdownHasStarted) {
--- a/dom/file/ipc/IPCBlobInputStreamThread.h
+++ b/dom/file/ipc/IPCBlobInputStreamThread.h
@@ -18,17 +18,17 @@ class IPCBlobInputStreamChild;
 
 class IPCBlobInputStreamThread final : public nsIObserver
 {
 public:
   NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSIOBSERVER
 
   static bool
-  IsOnFileThread(nsIThread* aThread);
+  IsOnFileEventTarget(nsIEventTarget* aEventTarget);
 
   static IPCBlobInputStreamThread*
   GetOrCreate();
 
   void
   MigrateActor(IPCBlobInputStreamChild* aActor);
 
   void
--- a/dom/filehandle/ActorsParent.cpp
+++ b/dom/filehandle/ActorsParent.cpp
@@ -366,36 +366,36 @@ private:
   virtual bool
   DeallocPBackgroundFileRequestParent(PBackgroundFileRequestParent* aActor)
                                       override;
 };
 
 class FileHandleOp
 {
 protected:
-  nsCOMPtr<nsIEventTarget> mOwningThread;
+  nsCOMPtr<nsIEventTarget> mOwningEventTarget;
   RefPtr<FileHandle> mFileHandle;
 
 public:
   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(FileHandleOp)
 
   void
   AssertIsOnOwningThread() const
   {
     AssertIsOnBackgroundThread();
-    MOZ_ASSERT(mOwningThread);
+    MOZ_ASSERT(mOwningEventTarget);
     DebugOnly<bool> current;
-    MOZ_ASSERT(NS_SUCCEEDED(mOwningThread->IsOnCurrentThread(&current)));
+    MOZ_ASSERT(NS_SUCCEEDED(mOwningEventTarget->IsOnCurrentThread(&current)));
     MOZ_ASSERT(current);
   }
 
   nsIEventTarget*
   OwningThread() const
   {
-    return mOwningThread;
+    return mOwningEventTarget;
   }
 
   void
   AssertIsOnThreadPool() const
   {
     MOZ_ASSERT(mFileHandle);
     mFileHandle->AssertIsOnThreadPool();
   }
@@ -406,17 +406,17 @@ public:
   virtual void
   RunOnThreadPool() = 0;
 
   virtual void
   RunOnOwningThread() = 0;
 
 protected:
   FileHandleOp(FileHandle* aFileHandle)
-    : mOwningThread(NS_GetCurrentThread())
+    : mOwningEventTarget(GetCurrentThreadSerialEventTarget())
     , mFileHandle(aFileHandle)
   {
     AssertIsOnOwningThread();
     MOZ_ASSERT(aFileHandle);
   }
 
   virtual
   ~FileHandleOp()
@@ -781,22 +781,22 @@ GetFileHandleThreadPoolFor(FileHandleSto
 
 } // namespace
 
 /*******************************************************************************
  * FileHandleThreadPool implementation
  ******************************************************************************/
 
 FileHandleThreadPool::FileHandleThreadPool()
-  : mOwningThread(NS_GetCurrentThread())
+  : mOwningEventTarget(GetCurrentThreadSerialEventTarget())
   , mShutdownRequested(false)
   , mShutdownComplete(false)
 {
   AssertIsOnBackgroundThread();
-  MOZ_ASSERT(mOwningThread);
+  MOZ_ASSERT(mOwningEventTarget);
   AssertIsOnOwningThread();
 }
 
 FileHandleThreadPool::~FileHandleThreadPool()
 {
   AssertIsOnOwningThread();
   MOZ_ASSERT(!mDirectoryInfos.Count());
   MOZ_ASSERT(mCompleteCallbacks.IsEmpty());
@@ -821,20 +821,20 @@ FileHandleThreadPool::Create()
   return fileHandleThreadPool.forget();
 }
 
 #ifdef DEBUG
 
 void
 FileHandleThreadPool::AssertIsOnOwningThread() const
 {
-  MOZ_ASSERT(mOwningThread);
+  MOZ_ASSERT(mOwningEventTarget);
 
   bool current;
-  MOZ_ALWAYS_SUCCEEDS(mOwningThread->IsOnCurrentThread(&current));
+  MOZ_ALWAYS_SUCCEEDS(mOwningEventTarget->IsOnCurrentThread(&current));
   MOZ_ASSERT(current);
 }
 
 nsIEventTarget*
 FileHandleThreadPool::GetThreadPoolEventTarget() const
 {
   AssertIsOnOwningThread();
   MOZ_ASSERT(mThreadPool);
@@ -2247,17 +2247,17 @@ CopyFileHandleOp::DoFileWork(FileHandle*
       return NS_ERROR_FAILURE;
     }
 
     mOffset += numWrite;
 
     nsCOMPtr<nsIRunnable> runnable =
       new ProgressRunnable(this, mOffset, mSize);
 
-    mOwningThread->Dispatch(runnable, NS_DISPATCH_NORMAL);
+    mOwningEventTarget->Dispatch(runnable, NS_DISPATCH_NORMAL);
   } while (true);
 
   MOZ_ASSERT(mOffset == mSize);
 
   if (mRead) {
     MOZ_ALWAYS_SUCCEEDS(outputStream->Close());
   } else {
     MOZ_ALWAYS_SUCCEEDS(inputStream->Close());
--- a/dom/filehandle/ActorsParent.h
+++ b/dom/filehandle/ActorsParent.h
@@ -38,17 +38,17 @@ class FileHandleOp;
 class FileHandleThreadPool final
 {
   class FileHandleQueue;
   struct DelayedEnqueueInfo;
   class DirectoryInfo;
   struct StoragesCompleteCallback;
 
   nsCOMPtr<nsIThreadPool> mThreadPool;
-  nsCOMPtr<nsIEventTarget> mOwningThread;
+  nsCOMPtr<nsIEventTarget> mOwningEventTarget;
 
   nsClassHashtable<nsCStringHashKey, DirectoryInfo> mDirectoryInfos;
 
   nsTArray<nsAutoPtr<StoragesCompleteCallback>> mCompleteCallbacks;
 
   bool mShutdownRequested;
   bool mShutdownComplete;
 
--- a/dom/filesystem/FileSystemRequestParent.cpp
+++ b/dom/filesystem/FileSystemRequestParent.cpp
@@ -81,17 +81,17 @@ public:
   CheckPermissionRunnable(already_AddRefed<ContentParent> aParent,
                           FileSystemRequestParent* aActor,
                           FileSystemTaskParentBase* aTask,
                           const nsAString& aPath)
     : mContentParent(aParent)
     , mActor(aActor)
     , mTask(aTask)
     , mPath(aPath)
-    , mBackgroundEventTarget(NS_GetCurrentThread())
+    , mBackgroundEventTarget(GetCurrentThreadEventTarget())
   {
     AssertIsInMainProcess();
     AssertIsOnBackgroundThread();
 
     MOZ_ASSERT(mContentParent);
     MOZ_ASSERT(mActor);
     MOZ_ASSERT(mTask);
     MOZ_ASSERT(mBackgroundEventTarget);
--- a/dom/filesystem/FileSystemTaskBase.cpp
+++ b/dom/filesystem/FileSystemTaskBase.cpp
@@ -232,17 +232,17 @@ FileSystemTaskChildBase::SetError(const 
  */
 
 FileSystemTaskParentBase::FileSystemTaskParentBase(FileSystemBase* aFileSystem,
                                                    const FileSystemParams& aParam,
                                                    FileSystemRequestParent* aParent)
   : mErrorValue(NS_OK)
   , mFileSystem(aFileSystem)
   , mRequestParent(aParent)
-  , mBackgroundEventTarget(NS_GetCurrentThread())
+  , mBackgroundEventTarget(GetCurrentThreadEventTarget())
 {
   MOZ_ASSERT(XRE_IsParentProcess(),
              "Only call from parent process!");
   MOZ_ASSERT(aFileSystem, "aFileSystem should not be null.");
   MOZ_ASSERT(aParent);
   MOZ_ASSERT(mBackgroundEventTarget);
   AssertIsOnBackgroundThread();
 }
--- a/dom/flyweb/HttpServer.cpp
+++ b/dom/flyweb/HttpServer.cpp
@@ -322,30 +322,30 @@ HttpServer::Connection::Connection(nsISo
   rv = mTransport->OpenOutputStream(0, 0, 0, getter_AddRefs(output));
   NS_ENSURE_SUCCESS_VOID(rv);
 
   mOutput = do_QueryInterface(output);
 
   if (mServer->mHttps) {
     SetSecurityObserver(true);
   } else {
-    mInput->AsyncWait(this, 0, 0, NS_GetCurrentThread());
+    mInput->AsyncWait(this, 0, 0, GetCurrentThreadEventTarget());
   }
 }
 
 NS_IMETHODIMP
 HttpServer::Connection::OnHandshakeDone(nsITLSServerSocket* aServer,
                                         nsITLSClientStatus* aStatus)
 {
   LOG_I("HttpServer::Connection::OnHandshakeDone(%p)", this);
 
   // XXX Verify connection security
 
   SetSecurityObserver(false);
-  mInput->AsyncWait(this, 0, 0, NS_GetCurrentThread());
+  mInput->AsyncWait(this, 0, 0, GetCurrentThreadEventTarget());
 
   return NS_OK;
 }
 
 void
 HttpServer::Connection::SetSecurityObserver(bool aListen)
 {
   LOG_I("HttpServer::Connection::SetSecurityObserver(%p) - %s", this,
@@ -386,17 +386,17 @@ HttpServer::Connection::OnInputStreamRea
 
   uint32_t numRead;
   rv = mInput->ReadSegments(ReadSegmentsFunc,
                             this,
                             UINT32_MAX,
                             &numRead);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  rv = mInput->AsyncWait(this, 0, 0, NS_GetCurrentThread());
+  rv = mInput->AsyncWait(this, 0, 0, GetCurrentThreadEventTarget());
   NS_ENSURE_SUCCESS(rv, rv);
 
   return NS_OK;
 }
 
 nsresult
 HttpServer::Connection::ReadSegmentsFunc(nsIInputStream* aIn,
                                          void* aClosure,
@@ -857,17 +857,17 @@ HttpServer::Connection::HandleAcceptWebS
 
 void
 HttpServer::Connection::HandleWebSocketResponse(InternalResponse* aResponse)
 {
   MOZ_ASSERT(mPendingWebSocketRequest);
 
   mState = eRequestLine;
   mPendingWebSocketRequest = nullptr;
-  mInput->AsyncWait(this, 0, 0, NS_GetCurrentThread());
+  mInput->AsyncWait(this, 0, 0, GetCurrentThreadEventTarget());
 
   QueueResponse(aResponse);
 }
 
 void
 HttpServer::Connection::QueueResponse(InternalResponse* aResponse)
 {
   bool chunked = false;
@@ -1228,17 +1228,17 @@ HttpServer::Connection::OnOutputStreamRe
         uint32_t written = 0;
         rv = mOutput->Write(buffer.BeginReading(),
                             buffer.Length(),
                             &written);
 
         buffer.Cut(0, written);
 
         if (rv == NS_BASE_STREAM_WOULD_BLOCK) {
-          return mOutput->AsyncWait(this, 0, 0, NS_GetCurrentThread());
+          return mOutput->AsyncWait(this, 0, 0, GetCurrentThreadEventTarget());
         }
 
         if (NS_FAILED(rv)) {
           Close();
           return NS_OK;
         }
       }
       mOutputBuffers.RemoveElementAt(0);
--- a/dom/gamepad/ipc/GamepadEventChannelParent.cpp
+++ b/dom/gamepad/ipc/GamepadEventChannelParent.cpp
@@ -40,17 +40,18 @@ class SendGamepadUpdateRunnable final : 
 } // namespace
 
 GamepadEventChannelParent::GamepadEventChannelParent()
   : mHasGamepadListener(false)
 {
   RefPtr<GamepadPlatformService> service =
     GamepadPlatformService::GetParentService();
   MOZ_ASSERT(service);
-  mBackgroundThread = NS_GetCurrentThread();
+
+  mBackgroundEventTarget = GetCurrentThreadEventTarget();
   service->AddChannelParent(this);
 }
 
 mozilla::ipc::IPCResult
 GamepadEventChannelParent::RecvGamepadListenerAdded()
 {
   AssertIsOnBackgroundThread();
   MOZ_ASSERT(!mHasGamepadListener);
@@ -111,14 +112,14 @@ GamepadEventChannelParent::ActorDestroy(
     service->RemoveChannelParent(this);
   }
   MaybeStopGamepadMonitoring();
 }
 
 void
 GamepadEventChannelParent::DispatchUpdateEvent(const GamepadChangeEvent& aEvent)
 {
-  mBackgroundThread->Dispatch(new SendGamepadUpdateRunnable(this, aEvent),
-                              NS_DISPATCH_NORMAL);
+  mBackgroundEventTarget->Dispatch(new SendGamepadUpdateRunnable(this, aEvent),
+                                   NS_DISPATCH_NORMAL);
 }
 
 } // namespace dom
 } // namespace mozilla
--- a/dom/gamepad/ipc/GamepadEventChannelParent.h
+++ b/dom/gamepad/ipc/GamepadEventChannelParent.h
@@ -1,18 +1,18 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 #include "mozilla/dom/PGamepadEventChannelParent.h"
 
 #ifndef mozilla_dom_GamepadEventChannelParent_h_
 #define mozilla_dom_GamepadEventChannelParent_h_
 
-namespace mozilla{
-namespace dom{
+namespace mozilla {
+namespace dom {
 
 class GamepadEventChannelParent final : public PGamepadEventChannelParent
 {
  public:
   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(GamepadEventChannelParent)
   GamepadEventChannelParent();
   virtual void ActorDestroy(ActorDestroyReason aWhy) override;
   virtual mozilla::ipc::IPCResult RecvGamepadListenerAdded() override;
@@ -24,15 +24,15 @@ class GamepadEventChannelParent final : 
                                                     const uint32_t& aPromiseID) override;
   virtual mozilla::ipc::IPCResult RecvStopVibrateHaptic(
                                     const uint32_t& aGamepadIndex) override;
   void DispatchUpdateEvent(const GamepadChangeEvent& aEvent);
   bool HasGamepadListener() const { return mHasGamepadListener; }
  private:
   ~GamepadEventChannelParent() {}
   bool mHasGamepadListener;
-  nsCOMPtr<nsIThread> mBackgroundThread;
+  nsCOMPtr<nsIEventTarget> mBackgroundEventTarget;
 };
 
-}// namespace dom
-}// namespace mozilla
+} // namespace dom
+} // namespace mozilla
 
 #endif
--- a/dom/html/HTMLCanvasElement.cpp
+++ b/dom/html/HTMLCanvasElement.cpp
@@ -1370,19 +1370,19 @@ HTMLCanvasElement::OnVisibilityChange()
         mRenderer = nullptr;
       }
 
     private:
       RefPtr<AsyncCanvasRenderer> mRenderer;
     };
 
     RefPtr<nsIRunnable> runnable = new Runnable(mAsyncCanvasRenderer);
-    nsCOMPtr<nsIThread> activeThread = mAsyncCanvasRenderer->GetActiveThread();
-    if (activeThread) {
-      activeThread->Dispatch(runnable, nsIThread::DISPATCH_NORMAL);
+    nsCOMPtr<nsIEventTarget> activeTarget = mAsyncCanvasRenderer->GetActiveThread();
+    if (activeTarget) {
+      activeTarget->Dispatch(runnable, nsIThread::DISPATCH_NORMAL);
     }
     return;
   }
 
   if (mCurrentContext) {
     mCurrentContext->OnVisibilityChange();
   }
 }
@@ -1412,19 +1412,19 @@ HTMLCanvasElement::OnMemoryPressure()
         mRenderer = nullptr;
       }
 
     private:
       RefPtr<AsyncCanvasRenderer> mRenderer;
     };
 
     RefPtr<nsIRunnable> runnable = new Runnable(mAsyncCanvasRenderer);
-    nsCOMPtr<nsIThread> activeThread = mAsyncCanvasRenderer->GetActiveThread();
-    if (activeThread) {
-      activeThread->Dispatch(runnable, nsIThread::DISPATCH_NORMAL);
+    nsCOMPtr<nsIEventTarget> activeTarget = mAsyncCanvasRenderer->GetActiveThread();
+    if (activeTarget) {
+      activeTarget->Dispatch(runnable, nsIThread::DISPATCH_NORMAL);
     }
     return;
   }
 
   if (mCurrentContext) {
     mCurrentContext->OnMemoryPressure();
   }
 }
--- a/dom/indexedDB/ActorsChild.cpp
+++ b/dom/indexedDB/ActorsChild.cpp
@@ -1486,17 +1486,17 @@ DispatchFileHandleSuccessEvent(FileHandl
 // CancelableRunnable is used to make workers happy.
 class BackgroundRequestChild::PreprocessHelper final
   : public CancelableRunnable
   , public nsIInputStreamCallback
 {
   typedef std::pair<nsCOMPtr<nsIInputStream>,
                     nsCOMPtr<nsIInputStream>> StreamPair;
 
-  nsCOMPtr<nsIEventTarget> mOwningThread;
+  nsCOMPtr<nsIEventTarget> mOwningEventTarget;
   nsTArray<StreamPair> mStreamPairs;
   nsTArray<RefPtr<JS::WasmModule>> mModuleSet;
   BackgroundRequestChild* mActor;
 
   // These 2 are populated when the processing of the stream pairs runs.
   PRFileDesc* mCurrentBytecodeFileDesc;
   PRFileDesc* mCurrentCompiledFileDesc;
 
@@ -1504,35 +1504,35 @@ class BackgroundRequestChild::Preprocess
   nsCOMPtr<nsIEventTarget> mTaskQueueEventTarget;
 
   uint32_t mModuleSetIndex;
   nsresult mResultCode;
 
 public:
   PreprocessHelper(uint32_t aModuleSetIndex, BackgroundRequestChild* aActor)
     : CancelableRunnable("indexedDB::BackgroundRequestChild::PreprocessHelper")
-    , mOwningThread(aActor->GetActorEventTarget())
+    , mOwningEventTarget(aActor->GetActorEventTarget())
     , mActor(aActor)
     , mCurrentBytecodeFileDesc(nullptr)
     , mCurrentCompiledFileDesc(nullptr)
     , mModuleSetIndex(aModuleSetIndex)
     , mResultCode(NS_OK)
   {
     AssertIsOnOwningThread();
     MOZ_ASSERT(aActor);
     aActor->AssertIsOnOwningThread();
   }
 
   bool
   IsOnOwningThread() const
   {
-    MOZ_ASSERT(mOwningThread);
+    MOZ_ASSERT(mOwningEventTarget);
 
     bool current;
-    return NS_SUCCEEDED(mOwningThread->IsOnCurrentThread(&current)) && current;
+    return NS_SUCCEEDED(mOwningEventTarget->IsOnCurrentThread(&current)) && current;
   }
 
   void
   AssertIsOnOwningThread() const
   {
     MOZ_ASSERT(IsOnOwningThread());
   }
 
@@ -3564,21 +3564,21 @@ PreprocessHelper::ContinueWithStatus(nsr
   nsCOMPtr<nsIEventTarget> eventTarget;
 
   if (NS_WARN_IF(NS_FAILED(aStatus))) {
     // If the previous operation failed, we don't continue the processing of the
     // other stream pairs.
     MOZ_ASSERT(mResultCode == NS_OK);
     mResultCode = aStatus;
 
-    eventTarget = mOwningThread;
+    eventTarget = mOwningEventTarget;
   } else if (mStreamPairs.IsEmpty()) {
     // If all the streams have been processed, we can go back to the owning
     // thread.
-    eventTarget = mOwningThread;
+    eventTarget = mOwningEventTarget;
   } else {
     // Continue the processing.
     eventTarget = mTaskQueueEventTarget;
   }
 
   nsresult rv = eventTarget->Dispatch(this, NS_DISPATCH_NORMAL);
   Unused <<  NS_WARN_IF(NS_FAILED(rv));
 }
--- a/dom/indexedDB/ActorsParent.cpp
+++ b/dom/indexedDB/ActorsParent.cpp
@@ -5565,17 +5565,17 @@ private:
   CloseDatabaseWhenIdleInternal(const nsACString& aDatabaseId);
 };
 
 class ConnectionPool::ConnectionRunnable
   : public Runnable
 {
 protected:
   DatabaseInfo* mDatabaseInfo;
-  nsCOMPtr<nsIEventTarget> mOwningThread;
+  nsCOMPtr<nsIEventTarget> mOwningEventTarget;
 
   explicit
   ConnectionRunnable(DatabaseInfo* aDatabaseInfo);
 
   ~ConnectionRunnable() override = default;
 };
 
 class ConnectionPool::IdleConnectionRunnable final
@@ -5708,17 +5708,17 @@ protected:
   virtual ~FinishCallback() = default;
 };
 
 class ConnectionPool::FinishCallbackWrapper final
   : public Runnable
 {
   RefPtr<ConnectionPool> mConnectionPool;
   RefPtr<FinishCallback> mCallback;
-  nsCOMPtr<nsIEventTarget> mOwningThread;
+  nsCOMPtr<nsIEventTarget> mOwningEventTarget;
   uint64_t mTransactionId;
   bool mHasRunOnce;
 
 public:
   FinishCallbackWrapper(ConnectionPool* aConnectionPool,
                         uint64_t aTransactionId,
                         FinishCallback* aCallback);
 
@@ -5906,35 +5906,35 @@ class DatabaseOperationBase
 {
   friend class UpgradeFileIdsFunction;
 
 protected:
   class AutoSetProgressHandler;
 
   typedef nsDataHashtable<nsUint64HashKey, bool> UniqueIndexTable;
 
-  nsCOMPtr<nsIEventTarget> mOwningThread;
+  nsCOMPtr<nsIEventTarget> mOwningEventTarget;
   const nsID mBackgroundChildLoggingId;
   const uint64_t mLoggingSerialNumber;
   nsresult mResultCode;
 
 private:
   Atomic<bool> mOperationMayProceed;
   bool mActorDestroyed;
 
 public:
   NS_DECL_ISUPPORTS_INHERITED
 
   bool
   IsOnOwningThread() const
   {
-    MOZ_ASSERT(mOwningThread);
+    MOZ_ASSERT(mOwningEventTarget);
 
     bool current;
-    return NS_SUCCEEDED(mOwningThread->IsOnCurrentThread(&current)) && current;
+    return NS_SUCCEEDED(mOwningEventTarget->IsOnCurrentThread(&current)) && current;
   }
 
   void
   AssertIsOnOwningThread() const
   {
     MOZ_ASSERT(IsOnBackgroundThread());
     MOZ_ASSERT(IsOnOwningThread());
   }
@@ -5989,17 +5989,17 @@ public:
     MOZ_ASSERT(NS_FAILED(aErrorCode));
 
     mResultCode = aErrorCode;
   }
 
 protected:
   DatabaseOperationBase(const nsID& aBackgroundChildLoggingId,
                         uint64_t aLoggingSerialNumber)
-    : mOwningThread(NS_GetCurrentThread())
+    : mOwningEventTarget(GetCurrentThreadEventTarget())
     , mBackgroundChildLoggingId(aBackgroundChildLoggingId)
     , mLoggingSerialNumber(aLoggingSerialNumber)
     , mResultCode(NS_OK)
     , mOperationMayProceed(true)
     , mActorDestroyed(false)
   {
     AssertIsOnOwningThread();
   }
@@ -13179,37 +13179,37 @@ ConnectionPool::CloseDatabaseWhenIdleInt
   }
 
   return false;
 }
 
 ConnectionPool::
 ConnectionRunnable::ConnectionRunnable(DatabaseInfo* aDatabaseInfo)
   : mDatabaseInfo(aDatabaseInfo)
-  , mOwningThread(do_GetCurrentThread())
+  , mOwningEventTarget(GetCurrentThreadEventTarget())
 {
   AssertIsOnBackgroundThread();
   MOZ_ASSERT(aDatabaseInfo);
   MOZ_ASSERT(aDatabaseInfo->mConnectionPool);
   aDatabaseInfo->mConnectionPool->AssertIsOnOwningThread();
-  MOZ_ASSERT(mOwningThread);
+  MOZ_ASSERT(mOwningEventTarget);
 }
 
 NS_IMPL_ISUPPORTS_INHERITED0(ConnectionPool::IdleConnectionRunnable,
                              ConnectionPool::ConnectionRunnable)
 
 NS_IMETHODIMP
 ConnectionPool::
 IdleConnectionRunnable::Run()
 {
   MOZ_ASSERT(mDatabaseInfo);
   MOZ_ASSERT(!mDatabaseInfo->mIdle);
 
   nsCOMPtr<nsIEventTarget> owningThread;
-  mOwningThread.swap(owningThread);
+  mOwningEventTarget.swap(owningThread);
 
   if (owningThread) {
     mDatabaseInfo->AssertIsOnConnectionThread();
 
     // The connection could be null if EnsureConnection() didn't run or was not
     // successful in TransactionDatabaseOperationBase::RunOnConnectionThread().
     if (mDatabaseInfo->mConnection) {
       mDatabaseInfo->mConnection->DoIdleProcessing(mNeedsCheckpoint);
@@ -13245,21 +13245,21 @@ ConnectionPool::
 CloseConnectionRunnable::Run()
 {
   MOZ_ASSERT(mDatabaseInfo);
 
   PROFILER_LABEL("IndexedDB",
                  "ConnectionPool::CloseConnectionRunnable::Run",
                  js::ProfileEntry::Category::STORAGE);
 
-  if (mOwningThread) {
+  if (mOwningEventTarget) {
     MOZ_ASSERT(mDatabaseInfo->mClosing);
 
     nsCOMPtr<nsIEventTarget> owningThread;
-    mOwningThread.swap(owningThread);
+    mOwningEventTarget.swap(owningThread);
 
     // The connection could be null if EnsureConnection() didn't run or was not
     // successful in TransactionDatabaseOperationBase::RunOnConnectionThread().
     if (mDatabaseInfo->mConnection) {
       mDatabaseInfo->AssertIsOnConnectionThread();
 
       mDatabaseInfo->mConnection->Close();
 
@@ -13346,24 +13346,24 @@ DatabasesCompleteCallback::~DatabasesCom
 }
 
 ConnectionPool::
 FinishCallbackWrapper::FinishCallbackWrapper(ConnectionPool* aConnectionPool,
                                              uint64_t aTransactionId,
                                              FinishCallback* aCallback)
   : mConnectionPool(aConnectionPool)
   , mCallback(aCallback)
-  , mOwningThread(do_GetCurrentThread())
+  , mOwningEventTarget(GetCurrentThreadEventTarget())
   , mTransactionId(aTransactionId)
   , mHasRunOnce(false)
 {
   AssertIsOnBackgroundThread();
   MOZ_ASSERT(aConnectionPool);
   MOZ_ASSERT(aCallback);
-  MOZ_ASSERT(mOwningThread);
+  MOZ_ASSERT(mOwningEventTarget);
 }
 
 ConnectionPool::
 FinishCallbackWrapper::~FinishCallbackWrapper()
 {
   MOZ_ASSERT(!mConnectionPool);
   MOZ_ASSERT(!mCallback);
 }
@@ -13371,31 +13371,31 @@ FinishCallbackWrapper::~FinishCallbackWr
 NS_IMPL_ISUPPORTS_INHERITED0(ConnectionPool::FinishCallbackWrapper, Runnable)
 
 nsresult
 ConnectionPool::
 FinishCallbackWrapper::Run()
 {
   MOZ_ASSERT(mConnectionPool);
   MOZ_ASSERT(mCallback);
-  MOZ_ASSERT(mOwningThread);
+  MOZ_ASSERT(mOwningEventTarget);
 
   PROFILER_LABEL("IndexedDB",
                  "ConnectionPool::FinishCallbackWrapper::Run",
                  js::ProfileEntry::Category::STORAGE);
 
   if (!mHasRunOnce) {
     MOZ_ASSERT(!IsOnBackgroundThread());
 
     mHasRunOnce = true;
 
     Unused << mCallback->Run();
 
     MOZ_ALWAYS_SUCCEEDS(
-      mOwningThread->Dispatch(this, NS_DISPATCH_NORMAL));
+      mOwningEventTarget->Dispatch(this, NS_DISPATCH_NORMAL));
 
     return NS_OK;
   }
 
   mConnectionPool->AssertIsOnOwningThread();
   MOZ_ASSERT(mHasRunOnce);
 
   RefPtr<ConnectionPool> connectionPool = Move(mConnectionPool);
@@ -18117,17 +18117,17 @@ QuotaClient::AbortOperationsForProcess(C
 }
 
 void
 QuotaClient::StartIdleMaintenance()
 {
   AssertIsOnBackgroundThread();
   MOZ_ASSERT(!mShutdownRequested);
 
-  mBackgroundThread = do_GetCurrentThread();
+  mBackgroundThread = GetCurrentThreadEventTarget();
 
   RefPtr<Maintenance> maintenance = new Maintenance(this);
 
   mMaintenanceQueue.AppendElement(maintenance.forget());
   ProcessMaintenanceQueue();
 }
 
 void
@@ -21009,24 +21009,24 @@ FactoryOp::Open()
                              Client::IDB,
                              mDatabaseId);
 
   mDatabaseId.Append('*');
   mDatabaseId.Append(NS_ConvertUTF16toUTF8(metadata.name()));
 
   if (permission == PermissionRequestBase::kPermissionPrompt) {
     mState = State::PermissionChallenge;
-    MOZ_ALWAYS_SUCCEEDS(mOwningThread->Dispatch(this, NS_DISPATCH_NORMAL));
+    MOZ_ALWAYS_SUCCEEDS(mOwningEventTarget->Dispatch(this, NS_DISPATCH_NORMAL));
     return NS_OK;
   }
 
   MOZ_ASSERT(permission == PermissionRequestBase::kPermissionAllowed);
 
   mState = State::FinishOpen;
-  MOZ_ALWAYS_SUCCEEDS(mOwningThread->Dispatch(this, NS_DISPATCH_NORMAL));
+  MOZ_ALWAYS_SUCCEEDS(mOwningEventTarget->Dispatch(this, NS_DISPATCH_NORMAL));
 
   return NS_OK;
 }
 
 nsresult
 FactoryOp::ChallengePermission()
 {
   AssertIsOnOwningThread();
@@ -21073,17 +21073,17 @@ FactoryOp::RetryCheckPermission()
   if (permission == PermissionRequestBase::kPermissionDenied ||
       permission == PermissionRequestBase::kPermissionPrompt) {
     return NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR;
   }
 
   MOZ_ASSERT(permission == PermissionRequestBase::kPermissionAllowed);
 
   mState = State::FinishOpen;
-  MOZ_ALWAYS_SUCCEEDS(mOwningThread->Dispatch(this, NS_DISPATCH_NORMAL));
+  MOZ_ALWAYS_SUCCEEDS(mOwningEventTarget->Dispatch(this, NS_DISPATCH_NORMAL));
 
   return NS_OK;
 }
 
 nsresult
 FactoryOp::DirectoryOpen()
 {
   AssertIsOnOwningThread();
@@ -21621,17 +21621,17 @@ FactoryOp::Run()
 
     // Must set mState before dispatching otherwise we will race with the owning
     // thread.
     mState = State::SendingResults;
 
     if (IsOnOwningThread()) {
       SendResults();
     } else {
-      MOZ_ALWAYS_SUCCEEDS(mOwningThread->Dispatch(this, NS_DISPATCH_NORMAL));
+      MOZ_ALWAYS_SUCCEEDS(mOwningEventTarget->Dispatch(this, NS_DISPATCH_NORMAL));
     }
   }
 
   return NS_OK;
 }
 
 void
 FactoryOp::DirectoryLockAcquired(DirectoryLock* aLock)
@@ -21908,17 +21908,17 @@ OpenDatabaseOp::DoDatabaseWork()
   mFileManager = fileManager.forget();
 
   // Must set mState before dispatching otherwise we will race with the owning
   // thread.
   mState = (mMetadata->mCommonMetadata.version() == mRequestedVersion) ?
            State::SendingResults :
            State::BeginVersionChange;
 
-  rv = mOwningThread->Dispatch(this, NS_DISPATCH_NORMAL);
+  rv = mOwningEventTarget->Dispatch(this, NS_DISPATCH_NORMAL);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   return NS_OK;
 }
 
 nsresult
@@ -23193,17 +23193,17 @@ DeleteDatabaseOp::DoDatabaseWork()
     // deleting the file eventually.
     LoadPreviousVersion(dbFile);
 
     mState = State::BeginVersionChange;
   } else {
     mState = State::SendingResults;
   }
 
-  rv = mOwningThread->Dispatch(this, NS_DISPATCH_NORMAL);
+  rv = mOwningEventTarget->Dispatch(this, NS_DISPATCH_NORMAL);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   return NS_OK;
 }
 
 nsresult
@@ -23577,17 +23577,17 @@ VersionChangeOp::RunOnIOThread()
 
   const nsString& databaseName =
     mDeleteDatabaseOp->mCommonParams.metadata().name();
 
   mgr->InvalidateFileManager(persistenceType,
                              mDeleteDatabaseOp->mOrigin,
                              databaseName);
 
-  rv = mOwningThread->Dispatch(this, NS_DISPATCH_NORMAL);
+  rv = mOwningEventTarget->Dispatch(this, NS_DISPATCH_NORMAL);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   return NS_OK;
 }
 
 void
@@ -23670,17 +23670,17 @@ VersionChangeOp::Run()
     rv = NS_OK;
   }
 
   if (NS_WARN_IF(NS_FAILED(rv))) {
     if (NS_SUCCEEDED(mResultCode)) {
       mResultCode = rv;
     }
 
-    MOZ_ALWAYS_SUCCEEDS(mOwningThread->Dispatch(this, NS_DISPATCH_NORMAL));
+    MOZ_ALWAYS_SUCCEEDS(mOwningEventTarget->Dispatch(this, NS_DISPATCH_NORMAL));
   }
 
   return NS_OK;
 }
 
 TransactionDatabaseOperationBase::TransactionDatabaseOperationBase(
                                                   TransactionBase* aTransaction)
   : DatabaseOperationBase(aTransaction->GetLoggingInfo()->Id(),
@@ -23832,17 +23832,17 @@ TransactionDatabaseOperationBase::RunOnC
   // Must set mInternalState before dispatching otherwise we will race with the
   // owning thread.
   if (HasPreprocessInfo()) {
     mInternalState = InternalState::SendingPreprocess;
   } else {
     mInternalState = InternalState::SendingResults;
   }
 
-  MOZ_ALWAYS_SUCCEEDS(mOwningThread->Dispatch(this, NS_DISPATCH_NORMAL));
+  MOZ_ALWAYS_SUCCEEDS(mOwningEventTarget->Dispatch(this, NS_DISPATCH_NORMAL));
 }
 
 bool
 TransactionDatabaseOperationBase::HasPreprocessInfo()
 {
   return false;
 }
 
@@ -24354,17 +24354,17 @@ DatabaseOp::Run()
     if (NS_SUCCEEDED(mResultCode)) {
       mResultCode = rv;
     }
 
     // Must set mState before dispatching otherwise we will race with the owning
     // thread.
     mState = State::SendingResults;
 
-    MOZ_ALWAYS_SUCCEEDS(mOwningThread->Dispatch(this, NS_DISPATCH_NORMAL));
+    MOZ_ALWAYS_SUCCEEDS(mOwningEventTarget->Dispatch(this, NS_DISPATCH_NORMAL));
   }
 
   return NS_OK;
 }
 
 void
 DatabaseOp::ActorDestroy(ActorDestroyReason aWhy)
 {
@@ -24475,17 +24475,17 @@ CreateFileOp::DoDatabaseWork()
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   // Must set mState before dispatching otherwise we will race with the owning
   // thread.
   mState = State::SendingResults;
 
-  rv = mOwningThread->Dispatch(this, NS_DISPATCH_NORMAL);
+  rv = mOwningEventTarget->Dispatch(this, NS_DISPATCH_NORMAL);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   return NS_OK;
 }
 
 void
--- a/dom/indexedDB/IDBFactory.cpp
+++ b/dom/indexedDB/IDBFactory.cpp
@@ -296,17 +296,17 @@ IDBFactory::CreateForJSInternal(JSContex
     return NS_OK;
   }
 
   RefPtr<IDBFactory> factory = new IDBFactory();
   factory->mPrincipalInfo = aPrincipalInfo.forget();
   factory->mOwningObject = aOwningObject;
   mozilla::HoldJSObjects(factory.get());
   factory->mEventTarget = NS_IsMainThread() ?
-    SystemGroup::EventTargetFor(TaskCategory::Other) : NS_GetCurrentThread();
+    SystemGroup::EventTargetFor(TaskCategory::Other) : GetCurrentThreadEventTarget();
   factory->mInnerWindowID = aInnerWindowID;
 
   factory.forget(aFactory);
   return NS_OK;
 }
 
 // static
 bool
--- a/dom/network/TCPSocket.cpp
+++ b/dom/network/TCPSocket.cpp
@@ -195,20 +195,18 @@ TCPSocket::CreateStream()
   NS_ENSURE_SUCCESS(rv, rv);
 
   // If the other side is not listening, we will
   // get an onInputStreamReady callback where available
   // raises to indicate the connection was refused.
   nsCOMPtr<nsIAsyncInputStream> asyncStream = do_QueryInterface(mSocketInputStream);
   NS_ENSURE_TRUE(asyncStream, NS_ERROR_NOT_AVAILABLE);
 
-  nsCOMPtr<nsIThread> mainThread;
-  NS_GetMainThread(getter_AddRefs(mainThread));
-
-  rv = asyncStream->AsyncWait(this, nsIAsyncInputStream::WAIT_CLOSURE_ONLY, 0, mainThread);
+  nsCOMPtr<nsIEventTarget> mainTarget = GetMainThreadEventTarget();
+  rv = asyncStream->AsyncWait(this, nsIAsyncInputStream::WAIT_CLOSURE_ONLY, 0, mainTarget);
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (mUseArrayBuffers) {
     mInputStreamBinary = do_CreateInstance("@mozilla.org/binaryinputstream;1", &rv);
     NS_ENSURE_SUCCESS(rv, rv);
     rv = mInputStreamBinary->SetInputStream(mSocketInputStream);
     NS_ENSURE_SUCCESS(rv, rv);
   } else {
@@ -243,19 +241,18 @@ TCPSocket::CreateStream()
 nsresult
 TCPSocket::InitWithUnconnectedTransport(nsISocketTransport* aTransport)
 {
   mReadyState = TCPReadyState::Connecting;
   mTransport = aTransport;
 
   MOZ_ASSERT(XRE_GetProcessType() != GeckoProcessType_Content);
 
-  nsCOMPtr<nsIThread> mainThread;
-  NS_GetMainThread(getter_AddRefs(mainThread));
-  mTransport->SetEventSink(this, mainThread);
+  nsCOMPtr<nsIEventTarget> mainTarget = GetMainThreadEventTarget();
+  mTransport->SetEventSink(this, mainTarget);
 
   nsresult rv = CreateStream();
   NS_ENSURE_SUCCESS(rv, rv);
 
   return NS_OK;
 }
 
 nsresult
--- a/dom/network/UDPSocketParent.cpp
+++ b/dom/network/UDPSocketParent.cpp
@@ -236,23 +236,23 @@ static void CheckSTSThread()
 }
 
 
 // Proxy the Connect() request to the STS thread, since it may block and
 // should be done there.
 mozilla::ipc::IPCResult
 UDPSocketParent::RecvConnect(const UDPAddressInfo& aAddressInfo)
 {
-  nsCOMPtr<nsIEventTarget> thread(NS_GetCurrentThread());
+  nsCOMPtr<nsIEventTarget> target = GetCurrentThreadEventTarget();
   Unused <<
     NS_WARN_IF(NS_FAILED(GetSTSThread()->Dispatch(WrapRunnable(
                                                     RefPtr<UDPSocketParent>(this),
                                                     &UDPSocketParent::DoConnect,
                                                     mSocket,
-                                                    thread,
+                                                    target,
                                                     aAddressInfo),
                                                   NS_DISPATCH_NORMAL)));
   return IPC_OK();
 }
 
 void
 UDPSocketParent::DoSendConnectResponse(const UDPAddressInfo& aAddressInfo)
 {
--- a/dom/notification/Notification.cpp
+++ b/dom/notification/Notification.cpp
@@ -2719,15 +2719,15 @@ Notification::DispatchToMainThread(alrea
     return mWorkerPrivate->DispatchToMainThread(Move(aRunnable));
   }
   AssertIsOnMainThread();
   if (nsCOMPtr<nsIGlobalObject> global = GetOwnerGlobal()) {
     if (nsIEventTarget* target = global->EventTargetFor(TaskCategory::Other)) {
       return target->Dispatch(Move(aRunnable), nsIEventTarget::DISPATCH_NORMAL);
     }
   }
-  nsCOMPtr<nsIThread> mainThread = do_GetMainThread();
-  MOZ_ASSERT(mainThread);
-  return mainThread->Dispatch(Move(aRunnable), nsIEventTarget::DISPATCH_NORMAL);
+  nsCOMPtr<nsIEventTarget> mainTarget = GetMainThreadEventTarget();
+  MOZ_ASSERT(mainTarget);
+  return mainTarget->Dispatch(Move(aRunnable), nsIEventTarget::DISPATCH_NORMAL);
 }
 
 } // namespace dom
 } // namespace mozilla
--- a/dom/presentation/PresentationTCPSessionTransport.cpp
+++ b/dom/presentation/PresentationTCPSessionTransport.cpp
@@ -175,20 +175,18 @@ PresentationTCPSessionTransport::BuildTC
     return NS_ERROR_NOT_AVAILABLE;
   }
   rv = sts->CreateTransport(nullptr, 0, serverHost, serverPort, nullptr,
                             getter_AddRefs(mTransport));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  nsCOMPtr<nsIThread> mainThread;
-  NS_GetMainThread(getter_AddRefs(mainThread));
-
-  mTransport->SetEventSink(this, mainThread);
+  nsCOMPtr<nsIEventTarget> mainTarget = GetMainThreadEventTarget();
+  mTransport->SetEventSink(this, mainTarget);
 
   rv = CreateStream();
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   mRole = nsIPresentationService::ROLE_RECEIVER;
 
@@ -215,20 +213,18 @@ PresentationTCPSessionTransport::CreateS
 
   // If the other side is not listening, we will get an |onInputStreamReady|
   // callback where |available| raises to indicate the connection was refused.
   nsCOMPtr<nsIAsyncInputStream> asyncStream = do_QueryInterface(mSocketInputStream);
   if (NS_WARN_IF(!asyncStream)) {
     return NS_ERROR_NOT_AVAILABLE;
   }
 
-  nsCOMPtr<nsIThread> mainThread;
-  NS_GetMainThread(getter_AddRefs(mainThread));
-
-  rv = asyncStream->AsyncWait(this, nsIAsyncInputStream::WAIT_CLOSURE_ONLY, 0, mainThread);
+  nsCOMPtr<nsIEventTarget> mainTarget = GetMainThreadEventTarget();
+  rv = asyncStream->AsyncWait(this, nsIAsyncInputStream::WAIT_CLOSURE_ONLY, 0, mainTarget);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   mInputStreamScriptable = do_CreateInstance("@mozilla.org/scriptableinputstream;1", &rv);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
--- a/dom/quota/ActorsChild.cpp
+++ b/dom/quota/ActorsChild.cpp
@@ -17,17 +17,17 @@ namespace quota {
 
 /*******************************************************************************
  * QuotaChild
  ******************************************************************************/
 
 QuotaChild::QuotaChild(QuotaManagerService* aService)
   : mService(aService)
 #ifdef DEBUG
-  , mOwningThread(NS_GetCurrentThread())
+  , mOwningThread(GetCurrentThreadEventTarget())
 #endif
 {
   AssertIsOnOwningThread();
   MOZ_ASSERT(aService);
 
   MOZ_COUNT_CTOR(quota::QuotaChild);
 }
 
--- a/dom/quota/ActorsParent.cpp
+++ b/dom/quota/ActorsParent.cpp
@@ -784,17 +784,17 @@ public:
   {
     AssertIsOnOwningThread();
 
     return mActorDestroyed;
   }
 
 protected:
   explicit OriginOperationBase(
-                          nsIEventTarget* aOwningThread = NS_GetCurrentThread())
+                          nsIEventTarget* aOwningThread = GetCurrentThreadEventTarget())
     : BackgroundThreadObject(aOwningThread)
     , mResultCode(NS_OK)
     , mState(State_Initial)
     , mActorDestroyed(false)
     , mNeedsMainThreadInit(false)
     , mNeedsQuotaManagerInit(false)
   { }
 
@@ -1447,17 +1447,17 @@ IsTempMetadata(const nsAString& aFileNam
 {
   return aFileName.EqualsLiteral(METADATA_TMP_FILE_NAME) ||
          aFileName.EqualsLiteral(METADATA_V2_TMP_FILE_NAME);
 }
 
 } // namespace
 
 BackgroundThreadObject::BackgroundThreadObject()
-  : mOwningThread(NS_GetCurrentThread())
+  : mOwningThread(GetCurrentThreadEventTarget())
 {
   AssertIsOnOwningThread();
 }
 
 BackgroundThreadObject::BackgroundThreadObject(nsIEventTarget* aOwningThread)
   : mOwningThread(aOwningThread)
 {
 }
@@ -2729,17 +2729,17 @@ auto
 QuotaManager::
 CreateRunnable::GetNextState(nsCOMPtr<nsIEventTarget>& aThread) -> State
 {
   switch (mState) {
     case State::Initial:
       aThread = mOwningThread;
       return State::CreatingManager;
     case State::CreatingManager:
-      aThread = do_GetMainThread();
+      aThread = GetMainThreadEventTarget();
       return State::RegisteringObserver;
     case State::RegisteringObserver:
       aThread = mOwningThread;
       return State::CallingCallbacks;
     case State::CallingCallbacks:
       aThread = nullptr;
       return State::Completed;
     default:
--- a/dom/workers/RuntimeService.cpp
+++ b/dom/workers/RuntimeService.cpp
@@ -2954,22 +2954,22 @@ WorkerThreadPrimaryRunnable::Run()
   threadHelper.Nullify();
 
   mWorkerPrivate->ScheduleDeletion(WorkerPrivate::WorkerRan);
 
   // It is no longer safe to touch mWorkerPrivate.
   mWorkerPrivate = nullptr;
 
   // Now recycle this thread.
-  nsCOMPtr<nsIThread> mainThread = do_GetMainThread();
-  MOZ_ASSERT(mainThread);
+  nsCOMPtr<nsIEventTarget> mainTarget = GetMainThreadEventTarget();
+  MOZ_ASSERT(mainTarget);
 
   RefPtr<FinishedRunnable> finishedRunnable =
     new FinishedRunnable(mThread.forget());
-  MOZ_ALWAYS_SUCCEEDS(mainThread->Dispatch(finishedRunnable,
+  MOZ_ALWAYS_SUCCEEDS(mainTarget->Dispatch(finishedRunnable,
                                            NS_DISPATCH_NORMAL));
 
   profiler_unregister_thread();
   return NS_OK;
 }
 
 NS_IMPL_ISUPPORTS_INHERITED0(WorkerThreadPrimaryRunnable::FinishedRunnable,
                              Runnable)
--- a/dom/workers/ServiceWorkerManagerParent.cpp
+++ b/dom/workers/ServiceWorkerManagerParent.cpp
@@ -120,47 +120,47 @@ class CheckPrincipalWithCallbackRunnable
 {
 public:
   CheckPrincipalWithCallbackRunnable(already_AddRefed<ContentParent> aParent,
                                      const PrincipalInfo& aPrincipalInfo,
                                      Runnable* aCallback)
     : mContentParent(aParent)
     , mPrincipalInfo(aPrincipalInfo)
     , mCallback(aCallback)
-    , mBackgroundThread(NS_GetCurrentThread())
+    , mBackgroundEventTarget(GetCurrentThreadEventTarget())
   {
     AssertIsInMainProcess();
     AssertIsOnBackgroundThread();
 
     MOZ_ASSERT(mContentParent);
     MOZ_ASSERT(mCallback);
-    MOZ_ASSERT(mBackgroundThread);
+    MOZ_ASSERT(mBackgroundEventTarget);
   }
 
   NS_IMETHOD Run() override
   {
     if (NS_IsMainThread()) {
       mContentParent = nullptr;
 
-      mBackgroundThread->Dispatch(this, NS_DISPATCH_NORMAL);
+      mBackgroundEventTarget->Dispatch(this, NS_DISPATCH_NORMAL);
       return NS_OK;
     }
 
     AssertIsOnBackgroundThread();
     mCallback->Run();
     mCallback = nullptr;
 
     return NS_OK;
   }
 
 private:
   RefPtr<ContentParent> mContentParent;
   PrincipalInfo mPrincipalInfo;
   RefPtr<Runnable> mCallback;
-  nsCOMPtr<nsIThread> mBackgroundThread;
+  nsCOMPtr<nsIEventTarget> mBackgroundEventTarget;
 };
 
 } // namespace
 
 ServiceWorkerManagerParent::ServiceWorkerManagerParent()
   : mService(ServiceWorkerManagerService::GetOrCreate())
   , mID(++sServiceWorkerManagerParentID)
 {
--- a/dom/workers/ServiceWorkerRegistrar.cpp
+++ b/dom/workers/ServiceWorkerRegistrar.cpp
@@ -702,41 +702,41 @@ ServiceWorkerRegistrar::RegisterServiceW
     mData.AppendElement(aData);
   }
 }
 
 class ServiceWorkerRegistrarSaveDataRunnable final : public Runnable
 {
 public:
   ServiceWorkerRegistrarSaveDataRunnable()
-    : mThread(do_GetCurrentThread())
+    : mEventTarget(GetCurrentThreadEventTarget())
   {
     AssertIsOnBackgroundThread();
   }
 
   NS_IMETHOD
   Run() override
   {
     RefPtr<ServiceWorkerRegistrar> service = ServiceWorkerRegistrar::Get();
     MOZ_ASSERT(service);
 
     service->SaveData();
 
     RefPtr<Runnable> runnable =
       NewRunnableMethod(service, &ServiceWorkerRegistrar::DataSaved);
-    nsresult rv = mThread->Dispatch(runnable, NS_DISPATCH_NORMAL);
+    nsresult rv = mEventTarget->Dispatch(runnable, NS_DISPATCH_NORMAL);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
 
     return NS_OK;
   }
 
 private:
-  nsCOMPtr<nsIThread> mThread;
+  nsCOMPtr<nsIEventTarget> mEventTarget;
 };
 
 void
 ServiceWorkerRegistrar::ScheduleSaveData()
 {
   AssertIsOnBackgroundThread();
   MOZ_ASSERT(!mShuttingDown);
 
--- a/dom/workers/WorkerPrivate.cpp
+++ b/dom/workers/WorkerPrivate.cpp
@@ -4437,17 +4437,17 @@ WorkerPrivate::WorkerPrivate(WorkerPriva
                                        aWorkerName, aServiceWorkerScope,
                                        aLoadInfo)
   , mDebuggerRegistered(false)
   , mDebugger(nullptr)
   , mJSContext(nullptr)
   , mPRThread(nullptr)
   , mNumHoldersPreventingShutdownStart(0)
   , mDebuggerEventLoopLevel(0)
-  , mMainThreadEventTarget(do_GetMainThread())
+  , mMainThreadEventTarget(GetMainThreadEventTarget())
   , mWorkerControlEventTarget(new WorkerControlEventTarget(this))
   , mErrorHandlerRecursionCount(0)
   , mNextTimeoutId(1)
   , mStatus(Pending)
   , mFrozen(false)
   , mTimerRunning(false)
   , mRunningExpiredTimeouts(false)
   , mPendingEventQueueClearing(false)
@@ -4480,20 +4480,18 @@ WorkerPrivate::WorkerPrivate(WorkerPriva
     mMainThreadEventTarget = aParent->mMainThreadEventTarget;
     return;
   }
 
   MOZ_ASSERT(NS_IsMainThread());
   target = GetWindow() ? GetWindow()->EventTargetFor(TaskCategory::Worker) : nullptr;
 
   if (!target) {
-    nsCOMPtr<nsIThread> mainThread;
-    NS_GetMainThread(getter_AddRefs(mainThread));
-    MOZ_DIAGNOSTIC_ASSERT(mainThread);
-    target = mainThread;
+    target = GetMainThreadEventTarget();
+    MOZ_DIAGNOSTIC_ASSERT(target);
   }
 
   // Throttle events to the main thread using a ThrottledEventQueue specific to
   // this worker thread.  This may return nullptr during shutdown.
   mMainThreadThrottledEventQueue = ThrottledEventQueue::Create(target);
 
   // If we were able to creat the throttled event queue, then use it for
   // dispatching our main thread runnables.  Otherwise use our underlying