Bug 1539407 - Use the correct global for DOMEventTargetHelper in IndexedDB, r=smaug
authorAndrea Marchesini <amarchesini@mozilla.com>
Fri, 29 Mar 2019 18:05:11 +0000
changeset 466802 7cc45cebde1c57b3fc4a4fa38dfe104061a88aeb
parent 466801 e3bb3f30b313de16b3a8021d37de20dd40c4f307
child 466803 c8763665035c988c2c47cf7f2a9ac8bf29a82ad2
push id35780
push useropoprus@mozilla.com
push dateFri, 29 Mar 2019 21:53:01 +0000
treeherdermozilla-central@414f37afbe07 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1539407
milestone68.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 1539407 - Use the correct global for DOMEventTargetHelper in IndexedDB, r=smaug Differential Revision: https://phabricator.services.mozilla.com/D25041
dom/base/nsGlobalWindowInner.cpp
dom/indexedDB/ActorsChild.cpp
dom/indexedDB/IDBCursor.cpp
dom/indexedDB/IDBCursor.h
dom/indexedDB/IDBDatabase.cpp
dom/indexedDB/IDBDatabase.h
dom/indexedDB/IDBFactory.cpp
dom/indexedDB/IDBFactory.h
dom/indexedDB/IDBFileHandle.h
dom/indexedDB/IDBFileRequest.cpp
dom/indexedDB/IDBIndex.cpp
dom/indexedDB/IDBIndex.h
dom/indexedDB/IDBMutableFile.h
dom/indexedDB/IDBObjectStore.cpp
dom/indexedDB/IDBObjectStore.h
dom/indexedDB/IDBRequest.cpp
dom/indexedDB/IDBRequest.h
dom/indexedDB/IDBTransaction.cpp
dom/indexedDB/IDBTransaction.h
dom/indexedDB/IDBWrapperCache.cpp
dom/indexedDB/IDBWrapperCache.h
dom/indexedDB/IndexedDatabaseManager.cpp
dom/indexedDB/KeyPath.cpp
dom/indexedDB/PermissionRequestBase.cpp
dom/indexedDB/moz.build
dom/workers/WorkerScope.cpp
--- a/dom/base/nsGlobalWindowInner.cpp
+++ b/dom/base/nsGlobalWindowInner.cpp
@@ -1148,17 +1148,17 @@ void nsGlobalWindowInner::FreeInnerObjec
 
   if (mApplicationCache) {
     static_cast<nsDOMOfflineResourceList*>(mApplicationCache.get())
         ->Disconnect();
     mApplicationCache = nullptr;
   }
 
   if (mIndexedDB) {
-    mIndexedDB->DisconnectFromWindow(this);
+    mIndexedDB->DisconnectFromGlobal(this);
     mIndexedDB = nullptr;
   }
 
   UnlinkHostObjectURIs();
 
   NotifyWindowIDDestroyed("inner-window-destroyed");
 
   CleanupCachedXBLHandlers();
@@ -1444,17 +1444,17 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(ns
   NS_IMPL_CYCLE_COLLECTION_UNLINK(mLocalStorage)
   NS_IMPL_CYCLE_COLLECTION_UNLINK(mSessionStorage)
   if (tmp->mApplicationCache) {
     static_cast<nsDOMOfflineResourceList*>(tmp->mApplicationCache.get())
         ->Disconnect();
     NS_IMPL_CYCLE_COLLECTION_UNLINK(mApplicationCache)
   }
   if (tmp->mIndexedDB) {
-    tmp->mIndexedDB->DisconnectFromWindow(tmp);
+    tmp->mIndexedDB->DisconnectFromGlobal(tmp);
     NS_IMPL_CYCLE_COLLECTION_UNLINK(mIndexedDB)
   }
   NS_IMPL_CYCLE_COLLECTION_UNLINK(mDocumentPrincipal)
   NS_IMPL_CYCLE_COLLECTION_UNLINK(mTabChild)
   NS_IMPL_CYCLE_COLLECTION_UNLINK(mDoc)
 
   NS_IMPL_CYCLE_COLLECTION_UNLINK(mGamepads)
 
--- a/dom/indexedDB/ActorsChild.cpp
+++ b/dom/indexedDB/ActorsChild.cpp
@@ -517,17 +517,18 @@ void DeserializeStructuredCloneFiles(
         case StructuredCloneFile::eBlob: {
           MOZ_ASSERT(blobOrMutableFile.type() == BlobOrMutableFile::TIPCBlob);
 
           const IPCBlob& ipcBlob = blobOrMutableFile.get_IPCBlob();
 
           RefPtr<BlobImpl> blobImpl = IPCBlobUtils::Deserialize(ipcBlob);
           MOZ_ASSERT(blobImpl);
 
-          RefPtr<Blob> blob = Blob::Create(aDatabase->GetOwner(), blobImpl);
+          RefPtr<Blob> blob =
+              Blob::Create(aDatabase->GetOwnerGlobal(), blobImpl);
 
           StructuredCloneFile* file = aFiles.AppendElement();
           MOZ_ASSERT(file);
 
           file->mType = StructuredCloneFile::eBlob;
           file->mBlob.swap(blob);
 
           break;
@@ -605,17 +606,18 @@ void DeserializeStructuredCloneFiles(
 
           MOZ_ASSERT(blobOrMutableFile.type() == BlobOrMutableFile::TIPCBlob);
 
           const IPCBlob& ipcBlob = blobOrMutableFile.get_IPCBlob();
 
           RefPtr<BlobImpl> blobImpl = IPCBlobUtils::Deserialize(ipcBlob);
           MOZ_ASSERT(blobImpl);
 
-          RefPtr<Blob> blob = Blob::Create(aDatabase->GetOwner(), blobImpl);
+          RefPtr<Blob> blob =
+              Blob::Create(aDatabase->GetOwnerGlobal(), blobImpl);
 
           StructuredCloneFile* file = aFiles.AppendElement();
           MOZ_ASSERT(file);
 
           file->mType = StructuredCloneFile::eWasmBytecode;
           file->mBlob.swap(blob);
 
           break;
@@ -1220,17 +1222,18 @@ already_AddRefed<File> ConvertActorToFil
   RefPtr<BlobImpl> blobImpl = actor->SetPendingInfoAndDeleteActor(
       mutableFile->Name(), mutableFile->Type(), size.value(),
       lastModified.value());
   MOZ_ASSERT(blobImpl);
 
   RefPtr<BlobImpl> blobImplSnapshot =
       new BlobImplSnapshot(blobImpl, static_cast<IDBFileHandle*>(aFileHandle));
 
-  RefPtr<File> file = File::Create(mutableFile->GetOwner(), blobImplSnapshot);
+  RefPtr<File> file =
+      File::Create(mutableFile->GetOwnerGlobal(), blobImplSnapshot);
   return file.forget();
 }
 
 void DispatchFileHandleErrorEvent(IDBFileRequest* aFileRequest,
                                   nsresult aErrorCode,
                                   IDBFileHandle* aFileHandle) {
   MOZ_ASSERT(aFileRequest);
   aFileRequest->AssertIsOnOwningThread();
@@ -1672,17 +1675,18 @@ mozilla::ipc::IPCResult BackgroundFactor
   nsresult rv;
   nsCOMPtr<nsIPrincipal> principal =
       mozilla::ipc::PrincipalInfoToPrincipal(aPrincipalInfo, &rv);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return IPC_FAIL_NO_REASON(this);
   }
 
   if (XRE_IsParentProcess()) {
-    nsCOMPtr<nsPIDOMWindowInner> window = mFactory->GetParentObject();
+    nsCOMPtr<nsIGlobalObject> global = mFactory->GetParentObject();
+    nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(global);
     MOZ_ASSERT(window);
 
     nsCOMPtr<Element> ownerElement =
         do_QueryInterface(window->GetChromeEventHandler());
     if (NS_WARN_IF(!ownerElement)) {
       // If this fails, the page was navigated. Fail the permission check by
       // forcing an immediate retry.
       if (!SendPermissionRetry()) {
--- a/dom/indexedDB/IDBCursor.cpp
+++ b/dom/indexedDB/IDBCursor.cpp
@@ -29,17 +29,16 @@ using namespace indexedDB;
 
 IDBCursor::IDBCursor(Type aType, BackgroundCursorChild* aBackgroundActor,
                      const Key& aKey)
     : mBackgroundActor(aBackgroundActor),
       mRequest(aBackgroundActor->GetRequest()),
       mSourceObjectStore(aBackgroundActor->GetObjectStore()),
       mSourceIndex(aBackgroundActor->GetIndex()),
       mTransaction(mRequest->GetTransaction()),
-      mScriptOwner(mTransaction->Database()->GetScriptOwner()),
       mCachedKey(JS::UndefinedValue()),
       mCachedPrimaryKey(JS::UndefinedValue()),
       mCachedValue(JS::UndefinedValue()),
       mKey(aKey),
       mType(aType),
       mDirection(aBackgroundActor->GetDirection()),
       mHaveCachedKey(false),
       mHaveCachedPrimaryKey(false),
@@ -50,22 +49,16 @@ IDBCursor::IDBCursor(Type aType, Backgro
   MOZ_ASSERT(aBackgroundActor);
   aBackgroundActor->AssertIsOnOwningThread();
   MOZ_ASSERT(mRequest);
   MOZ_ASSERT_IF(aType == Type_ObjectStore || aType == Type_ObjectStoreKey,
                 mSourceObjectStore);
   MOZ_ASSERT_IF(aType == Type_Index || aType == Type_IndexKey, mSourceIndex);
   MOZ_ASSERT(mTransaction);
   MOZ_ASSERT(!aKey.IsUnset());
-  MOZ_ASSERT(mScriptOwner);
-
-  if (mScriptOwner) {
-    mozilla::HoldJSObjects(this);
-    mRooted = true;
-  }
 }
 
 bool IDBCursor::IsLocaleAware() const {
   return mSourceIndex && !mSourceIndex->Locale().IsEmpty();
 }
 
 IDBCursor::~IDBCursor() {
   AssertIsOnOwningThread();
@@ -185,17 +178,16 @@ void IDBCursor::DropJSObjects() {
   AssertIsOnOwningThread();
 
   Reset();
 
   if (!mRooted) {
     return;
   }
 
-  mScriptOwner = nullptr;
   mRooted = false;
 
   mozilla::DropJSObjects(this);
 }
 
 bool IDBCursor::IsSourceDeleted() const {
   AssertIsOnOwningThread();
   MOZ_ASSERT(mTransaction);
@@ -229,17 +221,17 @@ void IDBCursor::Reset() {
 
   mHaveCachedKey = false;
   mHaveCachedPrimaryKey = false;
   mHaveCachedValue = false;
   mHaveValue = false;
   mContinueCalled = false;
 }
 
-nsPIDOMWindowInner* IDBCursor::GetParentObject() const {
+nsIGlobalObject* IDBCursor::GetParentObject() const {
   AssertIsOnOwningThread();
   MOZ_ASSERT(mTransaction);
 
   return mTransaction->GetParentObject();
 }
 
 IDBCursorDirection IDBCursor::GetDirection() const {
   AssertIsOnOwningThread();
@@ -868,17 +860,16 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(IDBCursor)
   MOZ_ASSERT_IF(!tmp->mHaveCachedKey, tmp->mCachedKey.isUndefined());
   MOZ_ASSERT_IF(!tmp->mHaveCachedPrimaryKey,
                 tmp->mCachedPrimaryKey.isUndefined());
   MOZ_ASSERT_IF(!tmp->mHaveCachedValue, tmp->mCachedValue.isUndefined());
 
   NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER
-  NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mScriptOwner)
   NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mCachedKey)
   NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mCachedPrimaryKey)
   NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mCachedValue)
 NS_IMPL_CYCLE_COLLECTION_TRACE_END
 
 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(IDBCursor)
   // Don't unlink mRequest, mSourceObjectStore, or mSourceIndex!
   NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
--- a/dom/indexedDB/IDBCursor.h
+++ b/dom/indexedDB/IDBCursor.h
@@ -10,17 +10,17 @@
 #include "IndexedDatabase.h"
 #include "js/RootingAPI.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/dom/IDBCursorBinding.h"
 #include "mozilla/dom/indexedDB/Key.h"
 #include "nsCycleCollectionParticipant.h"
 #include "nsWrapperCache.h"
 
-class nsPIDOMWindowInner;
+class nsIGlobalObject;
 
 namespace mozilla {
 
 class ErrorResult;
 
 namespace dom {
 
 class IDBIndex;
@@ -60,18 +60,16 @@ class IDBCursor final : public nsISuppor
 
   RefPtr<IDBRequest> mRequest;
   RefPtr<IDBObjectStore> mSourceObjectStore;
   RefPtr<IDBIndex> mSourceIndex;
 
   // mSourceObjectStore or mSourceIndex will hold this alive.
   IDBTransaction* mTransaction;
 
-  JS::Heap<JSObject*> mScriptOwner;
-
   // These are cycle-collected!
   JS::Heap<JS::Value> mCachedKey;
   JS::Heap<JS::Value> mCachedPrimaryKey;
   JS::Heap<JS::Value> mCachedValue;
 
   Key mKey;
   Key mSortKey;
   Key mPrimaryKey;
@@ -109,17 +107,17 @@ class IDBCursor final : public nsISuppor
   void AssertIsOnOwningThread() const
 #ifdef DEBUG
       ;
 #else
   {
   }
 #endif
 
-  nsPIDOMWindowInner* GetParentObject() const;
+  nsIGlobalObject* GetParentObject() const;
 
   void GetSource(OwningIDBObjectStoreOrIDBIndex& aSource) const;
 
   IDBCursorDirection GetDirection() const;
 
   void GetKey(JSContext* aCx, JS::MutableHandle<JS::Value> aResult,
               ErrorResult& aRv);
 
--- a/dom/indexedDB/IDBDatabase.cpp
+++ b/dom/indexedDB/IDBDatabase.cpp
@@ -145,17 +145,17 @@ class IDBDatabase::Observer final : publ
     MOZ_ASSERT(!mWeakDatabase);
   }
 
   NS_DECL_NSIOBSERVER
 };
 
 IDBDatabase::IDBDatabase(IDBOpenDBRequest* aRequest, IDBFactory* aFactory,
                          BackgroundDatabaseChild* aActor, DatabaseSpec* aSpec)
-    : IDBWrapperCache(aRequest),
+    : DOMEventTargetHelper(aRequest),
       mFactory(aFactory),
       mSpec(aSpec),
       mBackgroundActor(aActor),
       mFileHandleDisabled(aRequest->IsFileHandleDisabled()),
       mClosed(false),
       mInvalidated(false),
       mQuotaExceeded(false),
       mIncreasedActiveDatabaseCount(false) {
@@ -179,20 +179,20 @@ already_AddRefed<IDBDatabase> IDBDatabas
   MOZ_ASSERT(aRequest);
   MOZ_ASSERT(aFactory);
   aFactory->AssertIsOnOwningThread();
   MOZ_ASSERT(aActor);
   MOZ_ASSERT(aSpec);
 
   RefPtr<IDBDatabase> db = new IDBDatabase(aRequest, aFactory, aActor, aSpec);
 
-  db->SetScriptOwner(aRequest->GetScriptOwner());
-
   if (NS_IsMainThread()) {
-    if (nsPIDOMWindowInner* window = aFactory->GetParentObject()) {
+    nsCOMPtr<nsPIDOMWindowInner> window =
+        do_QueryInterface(aFactory->GetParentObject());
+    if (window) {
       uint64_t windowId = window->WindowID();
 
       RefPtr<Observer> observer = new Observer(db, windowId);
 
       nsCOMPtr<nsIObserverService> obsSvc = GetObserverService();
       MOZ_ASSERT(obsSvc);
 
       // This topic must be successfully registered.
@@ -313,20 +313,16 @@ void IDBDatabase::RefreshSpec(bool aMayD
   for (auto iter = mTransactions.Iter(); !iter.Done(); iter.Next()) {
     RefPtr<IDBTransaction> transaction = iter.Get()->GetKey();
     MOZ_ASSERT(transaction);
     transaction->AssertIsOnOwningThread();
     transaction->RefreshSpec(aMayDelete);
   }
 }
 
-nsPIDOMWindowInner* IDBDatabase::GetParentObject() const {
-  return mFactory->GetParentObject();
-}
-
 const nsString& IDBDatabase::Name() const {
   AssertIsOnOwningThread();
   MOZ_ASSERT(mSpec);
 
   return mSpec->metadata().name();
 }
 
 uint64_t IDBDatabase::Version() const {
@@ -1055,42 +1051,44 @@ void IDBDatabase::LogWarning(const char*
   MOZ_ASSERT(aMessageName);
 
   ScriptErrorHelper::DumpLocalizedMessage(
       nsDependentCString(aMessageName), aFilename, aLineNumber, aColumnNumber,
       nsIScriptError::warningFlag, mFactory->IsChrome(),
       mFactory->InnerWindowID());
 }
 
-NS_IMPL_ADDREF_INHERITED(IDBDatabase, IDBWrapperCache)
-NS_IMPL_RELEASE_INHERITED(IDBDatabase, IDBWrapperCache)
+NS_IMPL_ADDREF_INHERITED(IDBDatabase, DOMEventTargetHelper)
+NS_IMPL_RELEASE_INHERITED(IDBDatabase, DOMEventTargetHelper)
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(IDBDatabase)
-NS_INTERFACE_MAP_END_INHERITING(IDBWrapperCache)
+NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(IDBDatabase)
 
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(IDBDatabase, IDBWrapperCache)
+NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(IDBDatabase,
+                                                  DOMEventTargetHelper)
   tmp->AssertIsOnOwningThread();
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mFactory)
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
-NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(IDBDatabase, IDBWrapperCache)
+NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(IDBDatabase,
+                                                DOMEventTargetHelper)
   tmp->AssertIsOnOwningThread();
 
   // Don't unlink mFactory!
 
   // We've been unlinked, at the very least we should be able to prevent further
   // transactions from starting and unblock any other SetVersion callers.
   tmp->CloseInternal();
 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
 
 void IDBDatabase::DisconnectFromOwner() {
   InvalidateInternal();
-  IDBWrapperCache::DisconnectFromOwner();
+  DOMEventTargetHelper::DisconnectFromOwner();
 }
 
 void IDBDatabase::LastRelease() {
   AssertIsOnOwningThread();
 
   CloseInternal();
 
   if (mBackgroundActor) {
--- a/dom/indexedDB/IDBDatabase.h
+++ b/dom/indexedDB/IDBDatabase.h
@@ -5,26 +5,26 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_dom_idbdatabase_h__
 #define mozilla_dom_idbdatabase_h__
 
 #include "mozilla/Attributes.h"
 #include "mozilla/dom/IDBTransactionBinding.h"
 #include "mozilla/dom/StorageTypeBinding.h"
-#include "mozilla/dom/IDBWrapperCache.h"
 #include "mozilla/dom/quota/PersistenceType.h"
+#include "mozilla/DOMEventTargetHelper.h"
 #include "nsAutoPtr.h"
 #include "nsDataHashtable.h"
 #include "nsHashKeys.h"
 #include "nsString.h"
 #include "nsTHashtable.h"
 
 class nsIEventTarget;
-class nsPIDOMWindowInner;
+class nsIGlobalObject;
 
 namespace mozilla {
 
 class ErrorResult;
 class EventChainPostVisitor;
 
 namespace dom {
 
@@ -42,17 +42,17 @@ class Optional;
 class StringOrStringSequence;
 
 namespace indexedDB {
 class BackgroundDatabaseChild;
 class DatabaseSpec;
 class PBackgroundIDBDatabaseFileChild;
 }  // namespace indexedDB
 
-class IDBDatabase final : public IDBWrapperCache {
+class IDBDatabase final : public DOMEventTargetHelper {
   typedef mozilla::dom::indexedDB::DatabaseSpec DatabaseSpec;
   typedef mozilla::dom::StorageType StorageType;
   typedef mozilla::dom::quota::PersistenceType PersistenceType;
 
   class Observer;
   friend class Observer;
 
   friend class IDBObjectStore;
@@ -173,18 +173,16 @@ class IDBDatabase final : public IDBWrap
   nsresult GetQuotaInfo(nsACString& aOrigin, PersistenceType* aPersistenceType);
 
   bool IsFileHandleDisabled() const { return mFileHandleDisabled; }
 
   void NoteLiveMutableFile(IDBMutableFile* aMutableFile);
 
   void NoteFinishedMutableFile(IDBMutableFile* aMutableFile);
 
-  nsPIDOMWindowInner* GetParentObject() const;
-
   already_AddRefed<DOMStringList> ObjectStoreNames() const;
 
   already_AddRefed<IDBObjectStore> CreateObjectStore(
       const nsAString& aName,
       const IDBObjectStoreParameters& aOptionalParameters, ErrorResult& aRv);
 
   void DeleteObjectStore(const nsAString& name, ErrorResult& aRv);
 
@@ -223,17 +221,17 @@ class IDBDatabase final : public IDBWrap
     MaybeDecreaseActiveDatabaseCount();
 
     mBackgroundActor = nullptr;
   }
 
   const DatabaseSpec* Spec() const { return mSpec; }
 
   NS_DECL_ISUPPORTS_INHERITED
-  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(IDBDatabase, IDBWrapperCache)
+  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(IDBDatabase, DOMEventTargetHelper)
 
   // DOMEventTargetHelper
   void DisconnectFromOwner() override;
 
   virtual void LastRelease() override;
 
   virtual nsresult PostHandleEvent(EventChainPostVisitor& aVisitor) override;
 
--- a/dom/indexedDB/IDBFactory.cpp
+++ b/dom/indexedDB/IDBFactory.cpp
@@ -65,32 +65,28 @@ struct IDBFactory::PendingRequestInfo {
                      const FactoryRequestParams& aParams)
       : mRequest(aRequest), mParams(aParams) {
     MOZ_ASSERT(aRequest);
     MOZ_ASSERT(aParams.type() != FactoryRequestParams::T__None);
   }
 };
 
 IDBFactory::IDBFactory()
-    : mOwningObject(nullptr),
-      mBackgroundActor(nullptr),
+    : mBackgroundActor(nullptr),
       mInnerWindowID(0),
       mActiveTransactionCount(0),
       mActiveDatabaseCount(0),
       mBackgroundActorFailed(false),
       mPrivateBrowsingMode(false) {
   AssertIsOnOwningThread();
 }
 
 IDBFactory::~IDBFactory() {
   MOZ_ASSERT_IF(mBackgroundActorFailed, !mBackgroundActor);
 
-  mOwningObject = nullptr;
-  mozilla::DropJSObjects(this);
-
   if (mBackgroundActor) {
     mBackgroundActor->SendDeleteMeInternal();
     MOZ_ASSERT(!mBackgroundActor, "SendDeleteMeInternal should have cleared!");
   }
 }
 
 // static
 nsresult IDBFactory::CreateForWindow(nsPIDOMWindowInner* aWindow,
@@ -138,136 +134,141 @@ nsresult IDBFactory::CreateForWindow(nsP
     return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
   }
 
   nsCOMPtr<nsIWebNavigation> webNav = do_GetInterface(aWindow);
   nsCOMPtr<nsILoadContext> loadContext = do_QueryInterface(webNav);
 
   RefPtr<IDBFactory> factory = new IDBFactory();
   factory->mPrincipalInfo = std::move(principalInfo);
-  factory->mWindow = aWindow;
+
+  factory->mGlobal = do_QueryInterface(aWindow);
+  MOZ_ASSERT(factory->mGlobal);
+
   factory->mTabChild = TabChild::GetFrom(aWindow);
   factory->mEventTarget =
       nsGlobalWindowInner::Cast(aWindow)->EventTargetFor(TaskCategory::Other);
   factory->mInnerWindowID = aWindow->WindowID();
   factory->mPrivateBrowsingMode =
       loadContext && loadContext->UsePrivateBrowsing();
 
   factory.forget(aFactory);
   return NS_OK;
 }
 
 // static
-nsresult IDBFactory::CreateForMainThreadJS(JSContext* aCx,
-                                           JS::Handle<JSObject*> aOwningObject,
+nsresult IDBFactory::CreateForMainThreadJS(nsIGlobalObject* aGlobal,
                                            IDBFactory** aFactory) {
   MOZ_ASSERT(NS_IsMainThread());
+  MOZ_ASSERT(aGlobal);
+
+  nsCOMPtr<nsIScriptObjectPrincipal> sop = do_QueryInterface(aGlobal);
+  if (NS_WARN_IF(!sop)) {
+    return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
+  }
 
   nsAutoPtr<PrincipalInfo> principalInfo(new PrincipalInfo());
-  nsIPrincipal* principal = nsContentUtils::ObjectPrincipal(aOwningObject);
+  nsIPrincipal* principal = sop->GetPrincipal();
   MOZ_ASSERT(principal);
   bool isSystem;
   if (!AllowedForPrincipal(principal, &isSystem)) {
     return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
   }
 
   nsresult rv = PrincipalToPrincipalInfo(principal, principalInfo);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   if (NS_WARN_IF(!QuotaManager::IsPrincipalInfoValid(*principalInfo))) {
     return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
   }
 
-  rv = CreateForMainThreadJSInternal(aCx, aOwningObject, principalInfo,
-                                     aFactory);
+  rv = CreateForMainThreadJSInternal(aGlobal, principalInfo, aFactory);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   MOZ_ASSERT(!principalInfo);
 
   return NS_OK;
 }
 
 // static
-nsresult IDBFactory::CreateForWorker(JSContext* aCx,
-                                     JS::Handle<JSObject*> aOwningObject,
+nsresult IDBFactory::CreateForWorker(nsIGlobalObject* aGlobal,
                                      const PrincipalInfo& aPrincipalInfo,
                                      uint64_t aInnerWindowID,
                                      IDBFactory** aFactory) {
   MOZ_ASSERT(!NS_IsMainThread());
+  MOZ_ASSERT(aGlobal);
   MOZ_ASSERT(aPrincipalInfo.type() != PrincipalInfo::T__None);
 
   nsAutoPtr<PrincipalInfo> principalInfo(new PrincipalInfo(aPrincipalInfo));
 
-  nsresult rv = CreateForJSInternal(aCx, aOwningObject, principalInfo,
-                                    aInnerWindowID, aFactory);
+  nsresult rv =
+      CreateInternal(aGlobal, principalInfo, aInnerWindowID, aFactory);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   MOZ_ASSERT(!principalInfo);
 
   return NS_OK;
 }
 
 // static
 nsresult IDBFactory::CreateForMainThreadJSInternal(
-    JSContext* aCx, JS::Handle<JSObject*> aOwningObject,
-    nsAutoPtr<PrincipalInfo>& aPrincipalInfo, IDBFactory** aFactory) {
+    nsIGlobalObject* aGlobal, nsAutoPtr<PrincipalInfo>& aPrincipalInfo,
+    IDBFactory** aFactory) {
   MOZ_ASSERT(NS_IsMainThread());
+  MOZ_ASSERT(aGlobal);
   MOZ_ASSERT(aPrincipalInfo);
 
   if (aPrincipalInfo->type() != PrincipalInfo::TSystemPrincipalInfo &&
       NS_WARN_IF(!Preferences::GetBool(kPrefIndexedDBEnabled, false))) {
     *aFactory = nullptr;
     return NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR;
   }
 
   IndexedDatabaseManager* mgr = IndexedDatabaseManager::GetOrCreate();
   if (NS_WARN_IF(!mgr)) {
     IDB_REPORT_INTERNAL_ERR();
     return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
   }
 
-  nsresult rv = CreateForJSInternal(aCx, aOwningObject, aPrincipalInfo,
-                                    /* aInnerWindowID */ 0, aFactory);
+  nsresult rv =
+      CreateInternal(aGlobal, aPrincipalInfo, /* aInnerWindowID */ 0, aFactory);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   return NS_OK;
 }
 
 // static
-nsresult IDBFactory::CreateForJSInternal(
-    JSContext* aCx, JS::Handle<JSObject*> aOwningObject,
-    nsAutoPtr<PrincipalInfo>& aPrincipalInfo, uint64_t aInnerWindowID,
-    IDBFactory** aFactory) {
-  MOZ_ASSERT(aCx);
-  MOZ_ASSERT(aOwningObject);
+nsresult IDBFactory::CreateInternal(nsIGlobalObject* aGlobal,
+                                    nsAutoPtr<PrincipalInfo>& aPrincipalInfo,
+                                    uint64_t aInnerWindowID,
+                                    IDBFactory** aFactory) {
+  MOZ_ASSERT(aGlobal);
   MOZ_ASSERT(aPrincipalInfo);
   MOZ_ASSERT(aPrincipalInfo->type() != PrincipalInfo::T__None);
   MOZ_ASSERT(aFactory);
-  MOZ_ASSERT(JS_IsGlobalObject(aOwningObject));
 
   if (aPrincipalInfo->type() != PrincipalInfo::TContentPrincipalInfo &&
       aPrincipalInfo->type() != PrincipalInfo::TSystemPrincipalInfo) {
     NS_WARNING("IndexedDB not allowed for this principal!");
     aPrincipalInfo = nullptr;
     *aFactory = nullptr;
     return NS_OK;
   }
 
   RefPtr<IDBFactory> factory = new IDBFactory();
   factory->mPrincipalInfo = aPrincipalInfo.forget();
-  factory->mOwningObject = aOwningObject;
-  mozilla::HoldJSObjects(factory.get());
+  factory->mGlobal = aGlobal;
   factory->mEventTarget = GetCurrentThreadEventTarget();
   factory->mInnerWindowID = aInnerWindowID;
 
   factory.forget(aFactory);
   return NS_OK;
 }
 
 // static
@@ -372,28 +373,31 @@ bool IDBFactory::AllowedForPrincipal(nsI
   return true;
 }
 
 void IDBFactory::UpdateActiveTransactionCount(int32_t aDelta) {
   AssertIsOnOwningThread();
   MOZ_DIAGNOSTIC_ASSERT(aDelta > 0 || (mActiveTransactionCount + aDelta) <
                                           mActiveTransactionCount);
   mActiveTransactionCount += aDelta;
-  if (mWindow) {
-    mWindow->UpdateActiveIndexedDBTransactionCount(aDelta);
+  nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(mGlobal);
+  if (window) {
+    window->UpdateActiveIndexedDBTransactionCount(aDelta);
   }
 }
 
 void IDBFactory::UpdateActiveDatabaseCount(int32_t aDelta) {
   AssertIsOnOwningThread();
   MOZ_DIAGNOSTIC_ASSERT(aDelta > 0 ||
                         (mActiveDatabaseCount + aDelta) < mActiveDatabaseCount);
   mActiveDatabaseCount += aDelta;
-  if (mWindow) {
-    mWindow->UpdateActiveIndexedDBDatabaseCount(aDelta);
+
+  nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(mGlobal);
+  if (window) {
+    window->UpdateActiveIndexedDBDatabaseCount(aDelta);
   }
 }
 
 bool IDBFactory::IsChrome() const {
   AssertIsOnOwningThread();
   MOZ_ASSERT(mPrincipalInfo);
 
   return mPrincipalInfo->type() == PrincipalInfo::TSystemPrincipalInfo;
@@ -416,18 +420,19 @@ already_AddRefed<IDBOpenDBRequest> IDBFa
                       Optional<uint64_t>(aVersion), Optional<StorageType>(),
                       /* aDeleting */ false, aCallerType, aRv);
 }
 
 already_AddRefed<IDBOpenDBRequest> IDBFactory::Open(
     JSContext* aCx, const nsAString& aName, const IDBOpenDBOptions& aOptions,
     CallerType aCallerType, ErrorResult& aRv) {
   if (!IsChrome() && aOptions.mStorage.WasPassed()) {
-    if (mWindow && mWindow->GetExtantDoc()) {
-      mWindow->GetExtantDoc()->WarnOnceAbout(
+    nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(mGlobal);
+    if (window && window->GetExtantDoc()) {
+      window->GetExtantDoc()->WarnOnceAbout(
           Document::eIDBOpenDBOptions_StorageType);
     } else if (!NS_IsMainThread()) {
       // The method below reports on the main thread too, so we need to make
       // sure we're on a worker. Workers don't have a WarnOnceAbout mechanism,
       // so this will be reported every time.
       WorkerPrivate::ReportErrorToConsole("IDBOpenDBOptions_StorageType");
     }
 
@@ -558,18 +563,17 @@ already_AddRefed<IDBOpenDBRequest> IDBFa
                       /* aDeleting */ true, aGuarantee, aRv);
 }
 
 already_AddRefed<IDBOpenDBRequest> IDBFactory::OpenInternal(
     JSContext* aCx, nsIPrincipal* aPrincipal, const nsAString& aName,
     const Optional<uint64_t>& aVersion,
     const Optional<StorageType>& aStorageType, bool aDeleting,
     CallerType aCallerType, ErrorResult& aRv) {
-  MOZ_ASSERT(mWindow || mOwningObject);
-  MOZ_ASSERT_IF(!mWindow, !mPrivateBrowsingMode);
+  MOZ_ASSERT(mGlobal);
 
   CommonFactoryRequestParams commonParams;
 
   PrincipalInfo& principalInfo = commonParams.principalInfo();
 
   if (aPrincipal) {
     if (!NS_IsMainThread()) {
       MOZ_CRASH(
@@ -719,34 +723,22 @@ already_AddRefed<IDBOpenDBRequest> IDBFa
       }
       MOZ_ASSERT(threadLocal);
       MOZ_ASSERT(!threadLocal->mIndexedDBThreadLocal);
 
       threadLocal->mIndexedDBThreadLocal = newIDBThreadLocal.forget();
     }
   }
 
-  RefPtr<IDBOpenDBRequest> request;
-
-  if (mWindow) {
-    JS::Rooted<JSObject*> scriptOwner(
-        aCx, nsGlobalWindowInner::Cast(mWindow.get())->FastGetGlobalJSObject());
-    MOZ_ASSERT(scriptOwner);
-
-    request =
-        IDBOpenDBRequest::CreateForWindow(aCx, this, mWindow, scriptOwner);
-  } else {
-    JS::Rooted<JSObject*> scriptOwner(aCx, mOwningObject);
-
-    request = IDBOpenDBRequest::CreateForJS(aCx, this, scriptOwner);
-    if (!request) {
-      MOZ_ASSERT(!NS_IsMainThread());
-      aRv.ThrowUncatchableException();
-      return nullptr;
-    }
+  RefPtr<IDBOpenDBRequest> request =
+      IDBOpenDBRequest::Create(aCx, this, mGlobal);
+  if (!request) {
+    MOZ_ASSERT(!NS_IsMainThread());
+    aRv.ThrowUncatchableException();
+    return nullptr;
   }
 
   MOZ_ASSERT(request);
 
   if (aDeleting) {
     IDB_LOG_MARK(
         "IndexedDB %s: Child  Request[%llu]: "
         "indexedDB.deleteDatabase(\"%s\")",
@@ -812,51 +804,49 @@ nsresult IDBFactory::InitiateRequest(IDB
   }
 
   MOZ_ASSERT(actor->GetActorEventTarget(),
              "The event target shall be inherited from its manager actor.");
 
   return NS_OK;
 }
 
-void IDBFactory::DisconnectFromWindow(nsPIDOMWindowInner* aOldWindow) {
-  MOZ_DIAGNOSTIC_ASSERT(aOldWindow);
-  // If CC unlinks us first, then mWindow might be nullptr
-  MOZ_DIAGNOSTIC_ASSERT(!mWindow || mWindow == aOldWindow);
+void IDBFactory::DisconnectFromGlobal(nsIGlobalObject* aOldGlobal) {
+  MOZ_DIAGNOSTIC_ASSERT(aOldGlobal);
+  // If CC unlinks us first, then mGlobal might be nullptr
+  MOZ_DIAGNOSTIC_ASSERT(!mGlobal || mGlobal == aOldGlobal);
 
-  mWindow = nullptr;
+  mGlobal = nullptr;
 }
 
 NS_IMPL_CYCLE_COLLECTING_ADDREF(IDBFactory)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(IDBFactory)
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(IDBFactory)
   NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
   NS_INTERFACE_MAP_ENTRY(nsISupports)
 NS_INTERFACE_MAP_END
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(IDBFactory)
 
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(IDBFactory)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mWindow)
+  NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mGlobal)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mTabChild)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mEventTarget)
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(IDBFactory)
   NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
-  tmp->mOwningObject = nullptr;
-  NS_IMPL_CYCLE_COLLECTION_UNLINK(mWindow)
+  NS_IMPL_CYCLE_COLLECTION_UNLINK(mGlobal)
   NS_IMPL_CYCLE_COLLECTION_UNLINK(mTabChild)
   NS_IMPL_CYCLE_COLLECTION_UNLINK(mEventTarget)
 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
 
 NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(IDBFactory)
   NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER
-  NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mOwningObject)
 NS_IMPL_CYCLE_COLLECTION_TRACE_END
 
 JSObject* IDBFactory::WrapObject(JSContext* aCx,
                                  JS::Handle<JSObject*> aGivenProto) {
   return IDBFactory_Binding::Wrap(aCx, this, aGivenProto);
 }
 
 }  // namespace dom
--- a/dom/indexedDB/IDBFactory.h
+++ b/dom/indexedDB/IDBFactory.h
@@ -13,16 +13,17 @@
 #include "nsAutoPtr.h"
 #include "nsCOMPtr.h"
 #include "nsCycleCollectionParticipant.h"
 #include "nsISupports.h"
 #include "nsString.h"
 #include "nsTArray.h"
 #include "nsWrapperCache.h"
 
+class nsIGlobalObject;
 class nsIEventTarget;
 class nsIPrincipal;
 class nsPIDOMWindowInner;
 
 namespace mozilla {
 
 class ErrorResult;
 
@@ -53,20 +54,17 @@ class IDBFactory final : public nsISuppo
   typedef mozilla::ipc::PBackgroundChild PBackgroundChild;
   typedef mozilla::ipc::PrincipalInfo PrincipalInfo;
 
   class BackgroundCreateCallback;
   struct PendingRequestInfo;
 
   nsAutoPtr<PrincipalInfo> mPrincipalInfo;
 
-  // If this factory lives on a window then mWindow must be non-null. Otherwise
-  // mOwningObject must be non-null.
-  nsCOMPtr<nsPIDOMWindowInner> mWindow;
-  JS::Heap<JSObject*> mOwningObject;
+  nsCOMPtr<nsIGlobalObject> mGlobal;
 
   // This will only be set if the factory belongs to a window in a child
   // process.
   RefPtr<TabChild> mTabChild;
 
   indexedDB::BackgroundFactoryChild* mBackgroundActor;
 
   // It is either set to a DocGroup-specific EventTarget if created by
@@ -79,22 +77,20 @@ class IDBFactory final : public nsISuppo
 
   bool mBackgroundActorFailed;
   bool mPrivateBrowsingMode;
 
  public:
   static nsresult CreateForWindow(nsPIDOMWindowInner* aWindow,
                                   IDBFactory** aFactory);
 
-  static nsresult CreateForMainThreadJS(JSContext* aCx,
-                                        JS::Handle<JSObject*> aOwningObject,
+  static nsresult CreateForMainThreadJS(nsIGlobalObject* aGlobal,
                                         IDBFactory** aFactory);
 
-  static nsresult CreateForWorker(JSContext* aCx,
-                                  JS::Handle<JSObject*> aOwningObject,
+  static nsresult CreateForWorker(nsIGlobalObject* aGlobal,
                                   const PrincipalInfo& aPrincipalInfo,
                                   uint64_t aInnerWindowID,
                                   IDBFactory** aFactory);
 
   static bool AllowedForWindow(nsPIDOMWindowInner* aWindow);
 
   static bool AllowedForPrincipal(nsIPrincipal* aPrincipal,
                                   bool* aIsSystemPrincipal = nullptr);
@@ -122,17 +118,17 @@ class IDBFactory final : public nsISuppo
   // Increase/Decrease the number of active databases and IDBOpenRequests for
   // the decision making of preemption and throttling.
   // Note: A non-closed database or a pending IDBOpenRequest could block
   // IDB operations in other window.
   void UpdateActiveDatabaseCount(int32_t aDelta);
 
   void IncrementParentLoggingRequestSerialNumber();
 
-  nsPIDOMWindowInner* GetParentObject() const { return mWindow; }
+  nsIGlobalObject* GetParentObject() const { return mGlobal; }
 
   TabChild* GetTabChild() const { return mTabChild; }
 
   PrincipalInfo* GetPrincipalInfo() const {
     AssertIsOnOwningThread();
 
     return mPrincipalInfo;
   }
@@ -173,38 +169,37 @@ class IDBFactory final : public nsISuppo
       const IDBOpenDBOptions& aOptions, SystemCallerGuarantee,
       ErrorResult& aRv);
 
   already_AddRefed<IDBOpenDBRequest> DeleteForPrincipal(
       JSContext* aCx, nsIPrincipal* aPrincipal, const nsAString& aName,
       const IDBOpenDBOptions& aOptions, SystemCallerGuarantee,
       ErrorResult& aRv);
 
-  void DisconnectFromWindow(nsPIDOMWindowInner* aOldWindow);
+  void DisconnectFromGlobal(nsIGlobalObject* aOldGlobal);
 
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(IDBFactory)
 
   // nsWrapperCache
   virtual JSObject* WrapObject(JSContext* aCx,
                                JS::Handle<JSObject*> aGivenProto) override;
 
  private:
   IDBFactory();
   ~IDBFactory();
 
   static nsresult CreateForMainThreadJSInternal(
-      JSContext* aCx, JS::Handle<JSObject*> aOwningObject,
-      nsAutoPtr<PrincipalInfo>& aPrincipalInfo, IDBFactory** aFactory);
+      nsIGlobalObject* aGlobal, nsAutoPtr<PrincipalInfo>& aPrincipalInfo,
+      IDBFactory** aFactory);
 
-  static nsresult CreateForJSInternal(JSContext* aCx,
-                                      JS::Handle<JSObject*> aOwningObject,
-                                      nsAutoPtr<PrincipalInfo>& aPrincipalInfo,
-                                      uint64_t aInnerWindowID,
-                                      IDBFactory** aFactory);
+  static nsresult CreateInternal(nsIGlobalObject* aGlobal,
+                                 nsAutoPtr<PrincipalInfo>& aPrincipalInfo,
+                                 uint64_t aInnerWindowID,
+                                 IDBFactory** aFactory);
 
   static nsresult AllowedForWindowInternal(nsPIDOMWindowInner* aWindow,
                                            nsIPrincipal** aPrincipal);
 
   already_AddRefed<IDBOpenDBRequest> OpenInternal(
       JSContext* aCx, nsIPrincipal* aPrincipal, const nsAString& aName,
       const Optional<uint64_t>& aVersion,
       const Optional<StorageType>& aStorageType, bool aDeleting,
--- a/dom/indexedDB/IDBFileHandle.h
+++ b/dom/indexedDB/IDBFileHandle.h
@@ -11,18 +11,16 @@
 #include "js/TypeDecls.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/dom/FileModeBinding.h"
 #include "mozilla/DOMEventTargetHelper.h"
 #include "nsCycleCollectionParticipant.h"
 #include "nsIRunnable.h"
 #include "nsWeakReference.h"
 
-class nsPIDOMWindowInner;
-
 namespace mozilla {
 namespace dom {
 
 class Blob;
 class FileRequestData;
 class FileRequestParams;
 struct IDBFileMetadataParameters;
 class IDBFileRequest;
@@ -107,21 +105,16 @@ class IDBFileHandle final : public DOMEv
   bool IsAborted() const {
     AssertIsOnOwningThread();
     return mAborted;
   }
 
   void Abort();
 
   // WebIDL
-  nsPIDOMWindowInner* GetParentObject() const {
-    AssertIsOnOwningThread();
-    return GetOwner();
-  }
-
   IDBMutableFile* GetMutableFile() const {
     AssertIsOnOwningThread();
     return mMutableFile;
   }
 
   IDBMutableFile* GetFileHandle() const {
     AssertIsOnOwningThread();
     return GetMutableFile();
--- a/dom/indexedDB/IDBFileRequest.cpp
+++ b/dom/indexedDB/IDBFileRequest.cpp
@@ -21,17 +21,17 @@
 
 namespace mozilla {
 namespace dom {
 
 using namespace mozilla::dom::indexedDB;
 
 IDBFileRequest::IDBFileRequest(IDBFileHandle* aFileHandle,
                                bool aWrapAsDOMRequest)
-    : DOMRequest(aFileHandle->GetOwner()),
+    : DOMRequest(aFileHandle->GetOwnerGlobal()),
       mFileHandle(aFileHandle),
       mWrapAsDOMRequest(aWrapAsDOMRequest),
       mHasEncoding(false) {
   MOZ_ASSERT(aFileHandle);
   aFileHandle->AssertIsOnOwningThread();
 }
 
 IDBFileRequest::~IDBFileRequest() { AssertIsOnOwningThread(); }
@@ -67,17 +67,17 @@ void IDBFileRequest::FireProgressEvent(u
   DispatchTrustedEvent(event);
 }
 
 void IDBFileRequest::SetResultCallback(ResultCallback* aCallback) {
   AssertIsOnOwningThread();
   MOZ_ASSERT(aCallback);
 
   AutoJSAPI autoJS;
-  if (NS_WARN_IF(!autoJS.Init(GetOwner()))) {
+  if (NS_WARN_IF(!autoJS.Init(GetOwnerGlobal()))) {
     FireError(NS_ERROR_DOM_FILEHANDLE_UNKNOWN_ERR);
     return;
   }
 
   JSContext* cx = autoJS.cx();
 
   JS::Rooted<JS::Value> result(cx);
   nsresult rv = aCallback->GetResult(cx, &result);
--- a/dom/indexedDB/IDBIndex.cpp
+++ b/dom/indexedDB/IDBIndex.cpp
@@ -233,17 +233,17 @@ const nsCString& IDBIndex::Locale() cons
 
 bool IDBIndex::IsAutoLocale() const {
   AssertIsOnOwningThread();
   MOZ_ASSERT(mMetadata);
 
   return mMetadata->autoLocale();
 }
 
-nsPIDOMWindowInner* IDBIndex::GetParentObject() const {
+nsIGlobalObject* IDBIndex::GetParentObject() const {
   AssertIsOnOwningThread();
 
   return mObjectStore->GetParentObject();
 }
 
 void IDBIndex::GetKeyPath(JSContext* aCx, JS::MutableHandle<JS::Value> aResult,
                           ErrorResult& aRv) {
   AssertIsOnOwningThread();
--- a/dom/indexedDB/IDBIndex.h
+++ b/dom/indexedDB/IDBIndex.h
@@ -11,17 +11,17 @@
 #include "mozilla/Attributes.h"
 #include "mozilla/dom/IDBCursorBinding.h"
 #include "nsAutoPtr.h"
 #include "nsCycleCollectionParticipant.h"
 #include "nsISupports.h"
 #include "nsTArrayForwardDeclare.h"
 #include "nsWrapperCache.h"
 
-class nsPIDOMWindowInner;
+class nsIGlobalObject;
 
 namespace mozilla {
 
 class ErrorResult;
 
 namespace dom {
 
 class IDBObjectStore;
@@ -78,17 +78,17 @@ class IDBIndex final : public nsISupport
 
   bool IsAutoLocale() const;
 
   IDBObjectStore* ObjectStore() const {
     AssertIsOnOwningThread();
     return mObjectStore;
   }
 
-  nsPIDOMWindowInner* GetParentObject() const;
+  nsIGlobalObject* GetParentObject() const;
 
   void GetName(nsString& aName) const { aName = Name(); }
 
   void SetName(const nsAString& aName, ErrorResult& aRv);
 
   void GetKeyPath(JSContext* aCx, JS::MutableHandle<JS::Value> aResult,
                   ErrorResult& aRv);
 
--- a/dom/indexedDB/IDBMutableFile.h
+++ b/dom/indexedDB/IDBMutableFile.h
@@ -12,18 +12,16 @@
 #include "mozilla/Attributes.h"
 #include "mozilla/DOMEventTargetHelper.h"
 #include "mozilla/dom/FileModeBinding.h"
 #include "nsCycleCollectionParticipant.h"
 #include "nsHashKeys.h"
 #include "nsString.h"
 #include "nsTHashtable.h"
 
-class nsPIDOMWindowInner;
-
 namespace mozilla {
 
 class ErrorResult;
 
 namespace dom {
 
 class DOMRequest;
 class File;
@@ -100,18 +98,16 @@ class IDBMutableFile final : public DOME
 
   void RegisterFileHandle(IDBFileHandle* aFileHandle);
 
   void UnregisterFileHandle(IDBFileHandle* aFileHandle);
 
   void AbortFileHandles();
 
   // WebIDL
-  nsPIDOMWindowInner* GetParentObject() const { return GetOwner(); }
-
   void GetName(nsString& aName) const { aName = mName; }
 
   void GetType(nsString& aType) const { aType = mType; }
 
   IDBDatabase* Database() const;
 
   already_AddRefed<IDBFileHandle> Open(FileMode aMode, ErrorResult& aError);
 
--- a/dom/indexedDB/IDBObjectStore.cpp
+++ b/dom/indexedDB/IDBObjectStore.cpp
@@ -1864,17 +1864,17 @@ NS_INTERFACE_MAP_END
 NS_IMPL_CYCLE_COLLECTING_ADDREF(IDBObjectStore)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(IDBObjectStore)
 
 JSObject* IDBObjectStore::WrapObject(JSContext* aCx,
                                      JS::Handle<JSObject*> aGivenProto) {
   return IDBObjectStore_Binding::Wrap(aCx, this, aGivenProto);
 }
 
-nsPIDOMWindowInner* IDBObjectStore::GetParentObject() const {
+nsIGlobalObject* IDBObjectStore::GetParentObject() const {
   return mTransaction->GetParentObject();
 }
 
 void IDBObjectStore::GetKeyPath(JSContext* aCx,
                                 JS::MutableHandle<JS::Value> aResult,
                                 ErrorResult& aRv) {
   if (!mCachedKeyPath.isUndefined()) {
     aResult.set(mCachedKeyPath);
--- a/dom/indexedDB/IDBObjectStore.h
+++ b/dom/indexedDB/IDBObjectStore.h
@@ -13,17 +13,17 @@
 #include "nsAutoPtr.h"
 #include "nsCycleCollectionParticipant.h"
 #include "nsISupports.h"
 #include "nsString.h"
 #include "nsTArray.h"
 #include "nsWrapperCache.h"
 
 struct JSClass;
-class nsPIDOMWindowInner;
+class nsIGlobalObject;
 
 namespace mozilla {
 
 class ErrorResult;
 
 namespace dom {
 
 class DOMStringList;
@@ -132,17 +132,17 @@ class IDBObjectStore final : public nsIS
   const nsString& Name() const;
 
   bool AutoIncrement() const;
 
   const KeyPath& GetKeyPath() const;
 
   bool HasValidKeyPath() const;
 
-  nsPIDOMWindowInner* GetParentObject() const;
+  nsIGlobalObject* GetParentObject() const;
 
   void GetName(nsString& aName) const {
     AssertIsOnOwningThread();
 
     aName = Name();
   }
 
   void SetName(const nsAString& aName, ErrorResult& aRv);
--- a/dom/indexedDB/IDBRequest.cpp
+++ b/dom/indexedDB/IDBRequest.cpp
@@ -13,28 +13,29 @@
 #include "IDBFactory.h"
 #include "IDBIndex.h"
 #include "IDBObjectStore.h"
 #include "IDBTransaction.h"
 #include "IndexedDatabaseManager.h"
 #include "mozilla/ContentEvents.h"
 #include "mozilla/ErrorResult.h"
 #include "mozilla/EventDispatcher.h"
+#include "mozilla/HoldDropJSObjects.h"
 #include "mozilla/Move.h"
 #include "mozilla/dom/DOMException.h"
 #include "mozilla/dom/ErrorEventBinding.h"
 #include "mozilla/dom/IDBOpenDBRequestBinding.h"
 #include "mozilla/dom/ScriptSettings.h"
 #include "mozilla/dom/WorkerPrivate.h"
 #include "mozilla/dom/WorkerRef.h"
 #include "nsCOMPtr.h"
 #include "nsContentUtils.h"
 #include "nsIScriptContext.h"
 #include "nsJSUtils.h"
-#include "nsPIDOMWindow.h"
+#include "nsIGlobalObject.h"
 #include "nsString.h"
 #include "ReportInternalError.h"
 
 // Include this last to avoid path problems on Windows.
 #include "ActorsChild.h"
 
 namespace mozilla {
 namespace dom {
@@ -44,37 +45,40 @@ using namespace mozilla::ipc;
 
 namespace {
 
 NS_DEFINE_IID(kIDBRequestIID, PRIVATE_IDBREQUEST_IID);
 
 }  // namespace
 
 IDBRequest::IDBRequest(IDBDatabase* aDatabase)
-    : IDBWrapperCache(aDatabase),
+    : DOMEventTargetHelper(aDatabase),
       mLoggingSerialNumber(0),
       mLineNo(0),
       mColumn(0),
       mHaveResultOrErrorCode(false) {
   MOZ_ASSERT(aDatabase);
   aDatabase->AssertIsOnOwningThread();
 
   InitMembers();
 }
 
-IDBRequest::IDBRequest(nsPIDOMWindowInner* aOwner)
-    : IDBWrapperCache(aOwner),
+IDBRequest::IDBRequest(nsIGlobalObject* aGlobal)
+    : DOMEventTargetHelper(aGlobal),
       mLoggingSerialNumber(0),
       mLineNo(0),
       mColumn(0),
       mHaveResultOrErrorCode(false) {
   InitMembers();
 }
 
-IDBRequest::~IDBRequest() { AssertIsOnOwningThread(); }
+IDBRequest::~IDBRequest() {
+  AssertIsOnOwningThread();
+  mozilla::DropJSObjects(this);
+}
 
 void IDBRequest::InitMembers() {
   AssertIsOnOwningThread();
 
   mResultVal.setUndefined();
   mLoggingSerialNumber = NextSerialNumber();
   mErrorCode = NS_OK;
   mLineNo = 0;
@@ -89,17 +93,16 @@ already_AddRefed<IDBRequest> IDBRequest:
   MOZ_ASSERT(aCx);
   MOZ_ASSERT(aDatabase);
   aDatabase->AssertIsOnOwningThread();
 
   RefPtr<IDBRequest> request = new IDBRequest(aDatabase);
   CaptureCaller(aCx, request->mFilename, &request->mLineNo, &request->mColumn);
 
   request->mTransaction = aTransaction;
-  request->SetScriptOwner(aDatabase->GetScriptOwner());
 
   return request.forget();
 }
 
 // static
 already_AddRefed<IDBRequest> IDBRequest::Create(
     JSContext* aCx, IDBObjectStore* aSourceAsObjectStore,
     IDBDatabase* aDatabase, IDBTransaction* aTransaction) {
@@ -176,16 +179,17 @@ void IDBRequest::GetSource(
     aSource.SetNull();
   }
 }
 
 void IDBRequest::Reset() {
   AssertIsOnOwningThread();
 
   mResultVal.setUndefined();
+
   mHaveResultOrErrorCode = false;
   mError = nullptr;
 }
 
 void IDBRequest::SetError(nsresult aRv) {
   AssertIsOnOwningThread();
   MOZ_ASSERT(NS_FAILED(aRv));
   MOZ_ASSERT(NS_ERROR_GET_MODULE(aRv) == NS_ERROR_MODULE_DOM_INDEXEDDB);
@@ -262,60 +266,55 @@ void IDBRequest::GetResult(JS::MutableHa
 
 void IDBRequest::SetResultCallback(ResultCallback* aCallback) {
   AssertIsOnOwningThread();
   MOZ_ASSERT(aCallback);
   MOZ_ASSERT(!mHaveResultOrErrorCode);
   MOZ_ASSERT(mResultVal.isUndefined());
   MOZ_ASSERT(!mError);
 
+  // Already disconnected from the owner.
+  if (!GetOwnerGlobal()) {
+    SetError(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
+    return;
+  }
+
   // See if our window is still valid.
   if (NS_WARN_IF(NS_FAILED(CheckInnerWindowCorrectness()))) {
     SetError(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
     return;
   }
 
   AutoJSAPI autoJS;
-  Maybe<JSAutoRealm> ar;
-
-  if (GetScriptOwner()) {
-    // If we have a script owner we want the SafeJSContext and then to enter the
-    // script owner's realm.
-    autoJS.Init();
-    ar.emplace(autoJS.cx(), GetScriptOwner());
-  } else {
-    // Otherwise our owner is a window and we use that to initialize.
-    MOZ_ASSERT(GetOwner());
-    if (!autoJS.Init(GetOwner())) {
-      IDB_WARNING("Failed to initialize AutoJSAPI!");
-      SetError(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
-      return;
-    }
+  if (!autoJS.Init(GetOwnerGlobal())) {
+    IDB_WARNING("Failed to initialize AutoJSAPI!");
+    SetError(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
+    return;
   }
 
   JSContext* cx = autoJS.cx();
 
-  AssertIsRooted();
-
   JS::Rooted<JS::Value> result(cx);
   nsresult rv = aCallback->GetResult(cx, &result);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     // This can only fail if the structured clone contains a mutable file
     // and the child is not in the main thread and main process.
     // In that case CreateAndWrapMutableFile() returns false which shows up
     // as NS_ERROR_DOM_DATA_CLONE_ERR here.
     MOZ_ASSERT(rv == NS_ERROR_DOM_DATA_CLONE_ERR);
 
     // We are not setting a result or an error object here since we want to
     // throw an exception when the 'result' property is being touched.
     return;
   }
 
   mError = nullptr;
+
   mResultVal = result;
+  mozilla::HoldJSObjects(this);
 
   mHaveResultOrErrorCode = true;
 }
 
 DOMException* IDBRequest::GetError(ErrorResult& aRv) {
   AssertIsOnOwningThread();
 
   if (!mHaveResultOrErrorCode) {
@@ -323,110 +322,88 @@ DOMException* IDBRequest::GetError(Error
     return nullptr;
   }
 
   return mError;
 }
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(IDBRequest)
 
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(IDBRequest, IDBWrapperCache)
+NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(IDBRequest,
+                                                  DOMEventTargetHelper)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSourceAsObjectStore)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSourceAsIndex)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSourceAsCursor)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mTransaction)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mError)
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
-NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(IDBRequest, IDBWrapperCache)
+NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(IDBRequest,
+                                                DOMEventTargetHelper)
   tmp->mResultVal.setUndefined();
+  mozilla::DropJSObjects(tmp);
   NS_IMPL_CYCLE_COLLECTION_UNLINK(mSourceAsObjectStore)
   NS_IMPL_CYCLE_COLLECTION_UNLINK(mSourceAsIndex)
   NS_IMPL_CYCLE_COLLECTION_UNLINK(mSourceAsCursor)
   NS_IMPL_CYCLE_COLLECTION_UNLINK(mTransaction)
   NS_IMPL_CYCLE_COLLECTION_UNLINK(mError)
 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
 
-NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(IDBRequest, IDBWrapperCache)
+NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(IDBRequest, DOMEventTargetHelper)
   // Don't need NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER because
   // DOMEventTargetHelper does it for us.
   NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mResultVal)
 NS_IMPL_CYCLE_COLLECTION_TRACE_END
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(IDBRequest)
   if (aIID.Equals(kIDBRequestIID)) {
     foundInterface = this;
   } else
-NS_INTERFACE_MAP_END_INHERITING(IDBWrapperCache)
+NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
 
-NS_IMPL_ADDREF_INHERITED(IDBRequest, IDBWrapperCache)
-NS_IMPL_RELEASE_INHERITED(IDBRequest, IDBWrapperCache)
+NS_IMPL_ADDREF_INHERITED(IDBRequest, DOMEventTargetHelper)
+NS_IMPL_RELEASE_INHERITED(IDBRequest, DOMEventTargetHelper)
 
 void IDBRequest::GetEventTargetParent(EventChainPreVisitor& aVisitor) {
   AssertIsOnOwningThread();
 
   aVisitor.mCanHandle = true;
   aVisitor.SetParentTarget(mTransaction, false);
 }
 
 IDBOpenDBRequest::IDBOpenDBRequest(IDBFactory* aFactory,
-                                   nsPIDOMWindowInner* aOwner,
+                                   nsIGlobalObject* aGlobal,
                                    bool aFileHandleDisabled)
-    : IDBRequest(aOwner),
+    : IDBRequest(aGlobal),
       mFactory(aFactory),
       mFileHandleDisabled(aFileHandleDisabled),
       mIncreasedActiveDatabaseCount(false) {
   AssertIsOnOwningThread();
   MOZ_ASSERT(aFactory);
-
-  // aOwner may be null.
+  MOZ_ASSERT(aGlobal);
 }
 
 IDBOpenDBRequest::~IDBOpenDBRequest() {
   AssertIsOnOwningThread();
   MOZ_ASSERT(!mIncreasedActiveDatabaseCount);
 }
 
 // static
-already_AddRefed<IDBOpenDBRequest> IDBOpenDBRequest::CreateForWindow(
-    JSContext* aCx, IDBFactory* aFactory, nsPIDOMWindowInner* aOwner,
-    JS::Handle<JSObject*> aScriptOwner) {
+already_AddRefed<IDBOpenDBRequest> IDBOpenDBRequest::Create(
+    JSContext* aCx, IDBFactory* aFactory, nsIGlobalObject* aGlobal) {
   MOZ_ASSERT(aFactory);
   aFactory->AssertIsOnOwningThread();
-  MOZ_ASSERT(aOwner);
-  MOZ_ASSERT(aScriptOwner);
+  MOZ_ASSERT(aGlobal);
 
   bool fileHandleDisabled = !IndexedDatabaseManager::IsFileHandleEnabled();
 
   RefPtr<IDBOpenDBRequest> request =
-      new IDBOpenDBRequest(aFactory, aOwner, fileHandleDisabled);
+      new IDBOpenDBRequest(aFactory, aGlobal, fileHandleDisabled);
   CaptureCaller(aCx, request->mFilename, &request->mLineNo, &request->mColumn);
 
-  request->SetScriptOwner(aScriptOwner);
-
-  request->IncreaseActiveDatabaseCount();
-
-  return request.forget();
-}
-
-// static
-already_AddRefed<IDBOpenDBRequest> IDBOpenDBRequest::CreateForJS(
-    JSContext* aCx, IDBFactory* aFactory, JS::Handle<JSObject*> aScriptOwner) {
-  MOZ_ASSERT(aFactory);
-  aFactory->AssertIsOnOwningThread();
-  MOZ_ASSERT(aScriptOwner);
-
-  bool fileHandleDisabled = !IndexedDatabaseManager::IsFileHandleEnabled();
-
-  RefPtr<IDBOpenDBRequest> request =
-      new IDBOpenDBRequest(aFactory, nullptr, fileHandleDisabled);
-  CaptureCaller(aCx, request->mFilename, &request->mLineNo, &request->mColumn);
-
-  request->SetScriptOwner(aScriptOwner);
-
   if (!NS_IsMainThread()) {
     WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
     MOZ_ASSERT(workerPrivate);
 
     workerPrivate->AssertIsOnWorkerThread();
 
     request->mWorkerRef =
         StrongWorkerRef::Create(workerPrivate, "IDBOpenDBRequest");
--- a/dom/indexedDB/IDBRequest.h
+++ b/dom/indexedDB/IDBRequest.h
@@ -6,28 +6,28 @@
 
 #ifndef mozilla_dom_idbrequest_h__
 #define mozilla_dom_idbrequest_h__
 
 #include "js/RootingAPI.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/EventForwards.h"
 #include "mozilla/dom/IDBRequestBinding.h"
-#include "mozilla/dom/IDBWrapperCache.h"
+#include "mozilla/DOMEventTargetHelper.h"
 #include "nsAutoPtr.h"
 #include "nsCycleCollectionParticipant.h"
 
 #define PRIVATE_IDBREQUEST_IID                       \
   {                                                  \
     0xe68901e5, 0x1d50, 0x4ee9, {                    \
       0xaf, 0x49, 0x90, 0x99, 0x4a, 0xff, 0xc8, 0x39 \
     }                                                \
   }
 
-class nsPIDOMWindowInner;
+class nsIGlobalObject;
 
 namespace mozilla {
 
 class ErrorResult;
 
 namespace dom {
 
 class DOMException;
@@ -37,17 +37,17 @@ class IDBFactory;
 class IDBIndex;
 class IDBObjectStore;
 class IDBTransaction;
 template <typename>
 struct Nullable;
 class OwningIDBObjectStoreOrIDBIndexOrIDBCursor;
 class StrongWorkerRef;
 
-class IDBRequest : public IDBWrapperCache {
+class IDBRequest : public DOMEventTargetHelper {
  protected:
   // mSourceAsObjectStore and mSourceAsIndex are exclusive and one must always
   // be set. mSourceAsCursor is sometimes set also.
   RefPtr<IDBObjectStore> mSourceAsObjectStore;
   RefPtr<IDBIndex> mSourceAsIndex;
   RefPtr<IDBCursor> mSourceAsCursor;
 
   RefPtr<IDBTransaction> mTransaction;
@@ -123,17 +123,17 @@ class IDBRequest : public IDBWrapperCach
   uint64_t LoggingSerialNumber() const {
     AssertIsOnOwningThread();
 
     return mLoggingSerialNumber;
   }
 
   void SetLoggingSerialNumber(uint64_t aLoggingSerialNumber);
 
-  nsPIDOMWindowInner* GetParentObject() const { return GetOwner(); }
+  nsIGlobalObject* GetParentObject() const { return GetOwnerGlobal(); }
 
   void GetResult(JS::MutableHandle<JS::Value> aResult, ErrorResult& aRv) const;
 
   void GetResult(JSContext* aCx, JS::MutableHandle<JS::Value> aResult,
                  ErrorResult& aRv) const {
     GetResult(aResult, aRv);
   }
 
@@ -149,25 +149,25 @@ class IDBRequest : public IDBWrapperCach
 
   IMPL_EVENT_HANDLER(success);
   IMPL_EVENT_HANDLER(error);
 
   void AssertIsOnOwningThread() const { NS_ASSERT_OWNINGTHREAD(IDBRequest); }
 
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(IDBRequest,
-                                                         IDBWrapperCache)
+                                                         DOMEventTargetHelper)
 
   // nsWrapperCache
   virtual JSObject* WrapObject(JSContext* aCx,
                                JS::Handle<JSObject*> aGivenProto) override;
 
  protected:
   explicit IDBRequest(IDBDatabase* aDatabase);
-  explicit IDBRequest(nsPIDOMWindowInner* aOwner);
+  explicit IDBRequest(nsIGlobalObject* aGlobal);
   ~IDBRequest();
 
   void InitMembers();
 
   void ConstructResult();
 };
 
 class NS_NO_VTABLE IDBRequest::ResultCallback {
@@ -184,22 +184,19 @@ class IDBOpenDBRequest final : public ID
   RefPtr<IDBFactory> mFactory;
 
   RefPtr<StrongWorkerRef> mWorkerRef;
 
   const bool mFileHandleDisabled;
   bool mIncreasedActiveDatabaseCount;
 
  public:
-  static already_AddRefed<IDBOpenDBRequest> CreateForWindow(
-      JSContext* aCx, IDBFactory* aFactory, nsPIDOMWindowInner* aOwner,
-      JS::Handle<JSObject*> aScriptOwner);
-
-  static already_AddRefed<IDBOpenDBRequest> CreateForJS(
-      JSContext* aCx, IDBFactory* aFactory, JS::Handle<JSObject*> aScriptOwner);
+  static already_AddRefed<IDBOpenDBRequest> Create(JSContext* aCx,
+                                                   IDBFactory* aFactory,
+                                                   nsIGlobalObject* aGlobal);
 
   bool IsFileHandleDisabled() const { return mFileHandleDisabled; }
 
   void SetTransaction(IDBTransaction* aTransaction);
 
   void DispatchNonTransactionError(nsresult aErrorCode);
 
   void NoteComplete();
@@ -215,17 +212,17 @@ class IDBOpenDBRequest final : public ID
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(IDBOpenDBRequest, IDBRequest)
 
   // nsWrapperCache
   virtual JSObject* WrapObject(JSContext* aCx,
                                JS::Handle<JSObject*> aGivenProto) override;
 
  private:
-  IDBOpenDBRequest(IDBFactory* aFactory, nsPIDOMWindowInner* aOwner,
+  IDBOpenDBRequest(IDBFactory* aFactory, nsIGlobalObject* aGlobal,
                    bool aFileHandleDisabled);
 
   ~IDBOpenDBRequest();
 
   void IncreaseActiveDatabaseCount();
 
   void MaybeDecreaseActiveDatabaseCount();
 };
--- a/dom/indexedDB/IDBTransaction.cpp
+++ b/dom/indexedDB/IDBTransaction.cpp
@@ -8,16 +8,17 @@
 
 #include "BackgroundChildImpl.h"
 #include "IDBDatabase.h"
 #include "IDBEvents.h"
 #include "IDBObjectStore.h"
 #include "IDBRequest.h"
 #include "mozilla/ErrorResult.h"
 #include "mozilla/EventDispatcher.h"
+#include "mozilla/HoldDropJSObjects.h"
 #include "mozilla/dom/DOMException.h"
 #include "mozilla/dom/DOMStringList.h"
 #include "mozilla/dom/WorkerRef.h"
 #include "mozilla/dom/WorkerPrivate.h"
 #include "mozilla/ipc/BackgroundChild.h"
 #include "mozilla/ScopeExit.h"
 #include "nsAutoPtr.h"
 #include "nsPIDOMWindow.h"
@@ -34,17 +35,17 @@ namespace mozilla {
 namespace dom {
 
 using namespace mozilla::dom::indexedDB;
 using namespace mozilla::ipc;
 
 IDBTransaction::IDBTransaction(IDBDatabase* aDatabase,
                                const nsTArray<nsString>& aObjectStoreNames,
                                Mode aMode)
-    : IDBWrapperCache(aDatabase),
+    : DOMEventTargetHelper(aDatabase),
       mDatabase(aDatabase),
       mObjectStoreNames(aObjectStoreNames),
       mLoggingSerialNumber(0),
       mNextObjectStoreId(0),
       mNextIndexId(0),
       mAbortCode(NS_OK),
       mPendingRequestCount(0),
       mLineNo(0),
@@ -90,16 +91,18 @@ IDBTransaction::IDBTransaction(IDBDataba
     }
 
     // Make sure there are no duplicates in our objectStore names.
     for (uint32_t index = 0; index < count - 1; index++) {
       MOZ_ASSERT(sortedNames[index] != sortedNames[index + 1]);
     }
   }
 #endif
+
+  mozilla::HoldJSObjects(this);
 }
 
 IDBTransaction::~IDBTransaction() {
   AssertIsOnOwningThread();
   MOZ_ASSERT(!mPendingRequestCount);
   MOZ_ASSERT(!mCreating);
   MOZ_ASSERT(!mNotedActiveTransaction);
   MOZ_ASSERT(mSentCommitOrAbort);
@@ -125,16 +128,19 @@ IDBTransaction::~IDBTransaction() {
                  "SendDeleteMeInternal should have cleared!");
     }
   } else if (auto* actor = mBackgroundActor.mNormalBackgroundActor) {
     actor->SendDeleteMeInternal();
 
     MOZ_ASSERT(!mBackgroundActor.mNormalBackgroundActor,
                "SendDeleteMeInternal should have cleared!");
   }
+
+  ReleaseWrapper(this);
+  mozilla::DropJSObjects(this);
 }
 
 // static
 already_AddRefed<IDBTransaction> IDBTransaction::CreateVersionChange(
     IDBDatabase* aDatabase, BackgroundVersionChangeTransactionChild* aActor,
     IDBOpenDBRequest* aOpenRequest, int64_t aNextObjectStoreId,
     int64_t aNextIndexId) {
   MOZ_ASSERT(aDatabase);
@@ -146,18 +152,16 @@ already_AddRefed<IDBTransaction> IDBTran
 
   nsTArray<nsString> emptyObjectStoreNames;
 
   RefPtr<IDBTransaction> transaction =
       new IDBTransaction(aDatabase, emptyObjectStoreNames, VERSION_CHANGE);
   aOpenRequest->GetCallerLocation(transaction->mFilename, &transaction->mLineNo,
                                   &transaction->mColumn);
 
-  transaction->SetScriptOwner(aDatabase->GetScriptOwner());
-
   transaction->NoteActiveTransaction();
 
   transaction->mBackgroundActor.mVersionChangeBackgroundActor = aActor;
   transaction->mNextObjectStoreId = aNextObjectStoreId;
   transaction->mNextIndexId = aNextIndexId;
 
   aDatabase->RegisterTransaction(transaction);
   transaction->mRegistered = true;
@@ -175,18 +179,16 @@ already_AddRefed<IDBTransaction> IDBTran
   MOZ_ASSERT(aMode == READ_ONLY || aMode == READ_WRITE ||
              aMode == READ_WRITE_FLUSH || aMode == CLEANUP);
 
   RefPtr<IDBTransaction> transaction =
       new IDBTransaction(aDatabase, aObjectStoreNames, aMode);
   IDBRequest::CaptureCaller(aCx, transaction->mFilename, &transaction->mLineNo,
                             &transaction->mColumn);
 
-  transaction->SetScriptOwner(aDatabase->GetScriptOwner());
-
   if (!NS_IsMainThread()) {
     WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
     MOZ_ASSERT(workerPrivate);
 
     workerPrivate->AssertIsOnWorkerThread();
 
     RefPtr<StrongWorkerRef> workerRef = StrongWorkerRef::Create(
         workerPrivate, "IDBTransaction", [transaction]() {
@@ -793,17 +795,17 @@ int64_t IDBTransaction::NextObjectStoreI
 
 int64_t IDBTransaction::NextIndexId() {
   AssertIsOnOwningThread();
   MOZ_ASSERT(VERSION_CHANGE == mMode);
 
   return mNextIndexId++;
 }
 
-nsPIDOMWindowInner* IDBTransaction::GetParentObject() const {
+nsIGlobalObject* IDBTransaction::GetParentObject() const {
   AssertIsOnOwningThread();
 
   return mDatabase->GetParentObject();
 }
 
 IDBTransactionMode IDBTransaction::GetMode(ErrorResult& aRv) const {
   AssertIsOnOwningThread();
 
@@ -897,34 +899,35 @@ already_AddRefed<IDBObjectStore> IDBTran
     MOZ_ASSERT(objectStore);
 
     mObjectStores.AppendElement(objectStore);
   }
 
   return objectStore.forget();
 }
 
-NS_IMPL_ADDREF_INHERITED(IDBTransaction, IDBWrapperCache)
-NS_IMPL_RELEASE_INHERITED(IDBTransaction, IDBWrapperCache)
+NS_IMPL_ADDREF_INHERITED(IDBTransaction, DOMEventTargetHelper)
+NS_IMPL_RELEASE_INHERITED(IDBTransaction, DOMEventTargetHelper)
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(IDBTransaction)
   NS_INTERFACE_MAP_ENTRY(nsIRunnable)
-NS_INTERFACE_MAP_END_INHERITING(IDBWrapperCache)
+NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(IDBTransaction)
 
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(IDBTransaction,
-                                                  IDBWrapperCache)
+                                                  DOMEventTargetHelper)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDatabase)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mError)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mObjectStores)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDeletedObjectStores)
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
-NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(IDBTransaction, IDBWrapperCache)
+NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(IDBTransaction,
+                                                DOMEventTargetHelper)
   // Don't unlink mDatabase!
   NS_IMPL_CYCLE_COLLECTION_UNLINK(mError)
   NS_IMPL_CYCLE_COLLECTION_UNLINK(mObjectStores)
   NS_IMPL_CYCLE_COLLECTION_UNLINK(mDeletedObjectStores)
 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
 
 JSObject* IDBTransaction::WrapObject(JSContext* aCx,
                                      JS::Handle<JSObject*> aGivenProto) {
--- a/dom/indexedDB/IDBTransaction.h
+++ b/dom/indexedDB/IDBTransaction.h
@@ -4,25 +4,23 @@
  * 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/. */
 
 #ifndef mozilla_dom_idbtransaction_h__
 #define mozilla_dom_idbtransaction_h__
 
 #include "mozilla/Attributes.h"
 #include "mozilla/dom/IDBTransactionBinding.h"
-#include "mozilla/dom/IDBWrapperCache.h"
+#include "mozilla/DOMEventTargetHelper.h"
 #include "nsAutoPtr.h"
 #include "nsCycleCollectionParticipant.h"
 #include "nsIRunnable.h"
 #include "nsString.h"
 #include "nsTArray.h"
 
-class nsPIDOMWindowInner;
-
 namespace mozilla {
 
 class ErrorResult;
 class EventChainPreVisitor;
 
 namespace dom {
 
 class DOMException;
@@ -39,17 +37,17 @@ class BackgroundRequestChild;
 class BackgroundTransactionChild;
 class BackgroundVersionChangeTransactionChild;
 class IndexMetadata;
 class ObjectStoreSpec;
 class OpenCursorParams;
 class RequestParams;
 }  // namespace indexedDB
 
-class IDBTransaction final : public IDBWrapperCache, public nsIRunnable {
+class IDBTransaction final : public DOMEventTargetHelper, public nsIRunnable {
   friend class indexedDB::BackgroundCursorChild;
   friend class indexedDB::BackgroundRequestChild;
 
   class WorkerHolder;
   friend class WorkerHolder;
 
  public:
   enum Mode {
@@ -225,17 +223,17 @@ class IDBTransaction final : public IDBW
   void Abort(nsresult aAbortCode);
 
   int64_t LoggingSerialNumber() const {
     AssertIsOnOwningThread();
 
     return mLoggingSerialNumber;
   }
 
-  nsPIDOMWindowInner* GetParentObject() const;
+  nsIGlobalObject* GetParentObject() const;
 
   IDBTransactionMode GetMode(ErrorResult& aRv) const;
 
   DOMException* GetError() const;
 
   already_AddRefed<IDBObjectStore> ObjectStore(const nsAString& aName,
                                                ErrorResult& aRv);
 
@@ -252,17 +250,17 @@ class IDBTransaction final : public IDBW
   // Only for VERSION_CHANGE transactions.
   int64_t NextObjectStoreId();
 
   // Only for VERSION_CHANGE transactions.
   int64_t NextIndexId();
 
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_NSIRUNNABLE
-  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(IDBTransaction, IDBWrapperCache)
+  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(IDBTransaction, DOMEventTargetHelper)
 
   // nsWrapperCache
   virtual JSObject* WrapObject(JSContext* aCx,
                                JS::Handle<JSObject*> aGivenProto) override;
 
   // EventTarget
   void GetEventTargetParent(EventChainPreVisitor& aVisitor) override;
 
deleted file mode 100644
--- a/dom/indexedDB/IDBWrapperCache.cpp
+++ /dev/null
@@ -1,72 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* 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 "IDBWrapperCache.h"
-
-#include "mozilla/HoldDropJSObjects.h"
-#include "nsCOMPtr.h"
-#include "nsIScriptGlobalObject.h"
-#include "nsPIDOMWindow.h"
-
-namespace mozilla {
-namespace dom {
-
-NS_IMPL_CYCLE_COLLECTION_CLASS(IDBWrapperCache)
-
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(IDBWrapperCache,
-                                                  DOMEventTargetHelper)
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
-
-NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(IDBWrapperCache,
-                                                DOMEventTargetHelper)
-  if (tmp->mScriptOwner) {
-    tmp->mScriptOwner = nullptr;
-    mozilla::DropJSObjects(tmp);
-  }
-NS_IMPL_CYCLE_COLLECTION_UNLINK_END
-
-NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(IDBWrapperCache,
-                                               DOMEventTargetHelper)
-  // Don't need NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER because
-  // DOMEventTargetHelper does it for us.
-  NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mScriptOwner)
-NS_IMPL_CYCLE_COLLECTION_TRACE_END
-
-NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(IDBWrapperCache)
-NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
-
-NS_IMPL_ADDREF_INHERITED(IDBWrapperCache, DOMEventTargetHelper)
-NS_IMPL_RELEASE_INHERITED(IDBWrapperCache, DOMEventTargetHelper)
-
-IDBWrapperCache::IDBWrapperCache(DOMEventTargetHelper* aOwner)
-    : DOMEventTargetHelper(aOwner), mScriptOwner(nullptr) {}
-
-IDBWrapperCache::IDBWrapperCache(nsPIDOMWindowInner* aOwner)
-    : DOMEventTargetHelper(aOwner), mScriptOwner(nullptr) {}
-
-IDBWrapperCache::~IDBWrapperCache() {
-  mScriptOwner = nullptr;
-  ReleaseWrapper(this);
-  mozilla::DropJSObjects(this);
-}
-
-void IDBWrapperCache::SetScriptOwner(JSObject* aScriptOwner) {
-  MOZ_ASSERT(aScriptOwner);
-  MOZ_ASSERT(JS_IsGlobalObject(aScriptOwner));
-
-  mScriptOwner = aScriptOwner;
-  mozilla::HoldJSObjects(this);
-}
-
-#ifdef DEBUG
-void IDBWrapperCache::AssertIsRooted() const {
-  MOZ_ASSERT(IsJSHolder(const_cast<IDBWrapperCache*>(this)),
-             "Why aren't we rooted?!");
-}
-#endif
-
-}  // namespace dom
-}  // namespace mozilla
deleted file mode 100644
--- a/dom/indexedDB/IDBWrapperCache.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* 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/. */
-
-#ifndef mozilla_dom_idbwrappercache_h__
-#define mozilla_dom_idbwrappercache_h__
-
-#include "js/RootingAPI.h"
-#include "mozilla/DOMEventTargetHelper.h"
-#include "nsCycleCollectionParticipant.h"
-#include "nsWrapperCache.h"
-
-class nsPIDOMWindowInnter;
-
-namespace mozilla {
-namespace dom {
-
-class IDBWrapperCache : public DOMEventTargetHelper {
-  JS::Heap<JSObject*> mScriptOwner;
-
- public:
-  NS_DECL_ISUPPORTS_INHERITED
-  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(IDBWrapperCache,
-                                                         DOMEventTargetHelper)
-
-  JSObject* GetScriptOwner() const { return mScriptOwner; }
-
-  void SetScriptOwner(JSObject* aScriptOwner);
-
-  void AssertIsRooted() const
-#ifdef DEBUG
-      ;
-#else
-  {
-  }
-#endif
-
- protected:
-  explicit IDBWrapperCache(DOMEventTargetHelper* aOwner);
-  explicit IDBWrapperCache(nsPIDOMWindowInner* aOwner);
-
-  virtual ~IDBWrapperCache();
-};
-
-}  // namespace dom
-}  // namespace mozilla
-
-#endif  // mozilla_dom_idbwrappercache_h__
--- a/dom/indexedDB/IndexedDatabaseManager.cpp
+++ b/dom/indexedDB/IndexedDatabaseManager.cpp
@@ -96,17 +96,17 @@ class FileManagerInfo {
 };
 
 }  // namespace indexedDB
 
 using namespace mozilla::dom::indexedDB;
 
 namespace {
 
-NS_DEFINE_IID(kIDBRequestIID, PRIVATE_IDBREQUEST_IID);
+NS_DEFINE_IID(kIDBPrivateRequestIID, PRIVATE_IDBREQUEST_IID);
 
 const uint32_t kDeleteTimeoutMs = 1000;
 
 // The threshold we use for structured clone data storing.
 // Anything smaller than the threshold is compressed and stored in the database.
 // Anything larger is compressed and stored outside the database.
 const int32_t kDefaultDataThresholdBytes = 1024 * 1024;  // 1MB
 
@@ -365,17 +365,17 @@ nsresult IndexedDatabaseManager::CommonP
     return NS_OK;
   }
 
   nsCOMPtr<EventTarget> eventTarget = aVisitor.mDOMEvent->GetTarget();
   MOZ_ASSERT(eventTarget);
 
   // Only mess with events that were originally targeted to an IDBRequest.
   RefPtr<IDBRequest> request;
-  if (NS_FAILED(eventTarget->QueryInterface(kIDBRequestIID,
+  if (NS_FAILED(eventTarget->QueryInterface(kIDBPrivateRequestIID,
                                             getter_AddRefs(request))) ||
       !request) {
     return NS_OK;
   }
 
   RefPtr<DOMException> error = request->GetErrorAfterResult();
 
   nsString errorName;
@@ -476,19 +476,24 @@ bool IndexedDatabaseManager::ResolveSand
 
 // static
 bool IndexedDatabaseManager::DefineIndexedDB(JSContext* aCx,
                                              JS::Handle<JSObject*> aGlobal) {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(js::GetObjectClass(aGlobal)->flags & JSCLASS_DOM_GLOBAL,
              "Passed object is not a global object!");
 
+  nsIGlobalObject* global = xpc::CurrentNativeGlobal(aCx);
+  if (NS_WARN_IF(!global)) {
+    return false;
+  }
+
   RefPtr<IDBFactory> factory;
-  if (NS_FAILED(IDBFactory::CreateForMainThreadJS(aCx, aGlobal,
-                                                  getter_AddRefs(factory)))) {
+  if (NS_FAILED(
+          IDBFactory::CreateForMainThreadJS(global, getter_AddRefs(factory)))) {
     return false;
   }
 
   MOZ_ASSERT(factory, "This should never fail for chrome!");
 
   JS::Rooted<JS::Value> indexedDB(aCx);
   js::AssertSameCompartment(aCx, aGlobal);
   if (!GetOrCreateDOMReflector(aCx, factory, &indexedDB)) {
--- a/dom/indexedDB/KeyPath.cpp
+++ b/dom/indexedDB/KeyPath.cpp
@@ -10,17 +10,19 @@
 #include "ReportInternalError.h"
 
 #include "nsCharSeparatedTokenizer.h"
 #include "nsJSUtils.h"
 #include "nsPrintfCString.h"
 #include "xpcpublic.h"
 
 #include "mozilla/dom/BindingDeclarations.h"
+#include "mozilla/dom/Blob.h"
 #include "mozilla/dom/BlobBinding.h"
+#include "mozilla/dom/File.h"
 #include "mozilla/dom/IDBObjectStoreBinding.h"
 
 namespace mozilla {
 namespace dom {
 namespace indexedDB {
 
 namespace {
 
--- a/dom/indexedDB/PermissionRequestBase.cpp
+++ b/dom/indexedDB/PermissionRequestBase.cpp
@@ -8,17 +8,16 @@
 
 #include "MainThreadUtils.h"
 #include "mozilla/Assertions.h"
 #include "mozilla/Services.h"
 #include "mozilla/dom/Element.h"
 #include "nsIDOMWindow.h"
 #include "nsIObserverService.h"
 #include "nsIPrincipal.h"
-#include "nsPIDOMWindow.h"
 #include "nsXULAppAPI.h"
 
 namespace mozilla {
 namespace dom {
 namespace indexedDB {
 
 using namespace mozilla::services;
 
--- a/dom/indexedDB/moz.build
+++ b/dom/indexedDB/moz.build
@@ -29,17 +29,16 @@ EXPORTS.mozilla.dom += [
     'IDBFileHandle.h',
     'IDBFileRequest.h',
     'IDBIndex.h',
     'IDBKeyRange.h',
     'IDBMutableFile.h',
     'IDBObjectStore.h',
     'IDBRequest.h',
     'IDBTransaction.h',
-    'IDBWrapperCache.h',
     'IndexedDatabase.h',
     'IndexedDatabaseManager.h',
 ]
 
 EXPORTS.mozilla.dom.indexedDB += [
     'ActorsParent.h',
     'FileSnapshot.h',
     'Key.h',
@@ -59,17 +58,16 @@ UNIFIED_SOURCES += [
     'IDBFileHandle.cpp',
     'IDBFileRequest.cpp',
     'IDBIndex.cpp',
     'IDBKeyRange.cpp',
     'IDBMutableFile.cpp',
     'IDBObjectStore.cpp',
     'IDBRequest.cpp',
     'IDBTransaction.cpp',
-    'IDBWrapperCache.cpp',
     'IndexedDatabaseManager.cpp',
     'KeyPath.cpp',
     'PermissionRequestBase.cpp',
     'ReportInternalError.cpp',
     'ScriptErrorHelper.cpp',
 ]
 
 SOURCES += [
--- a/dom/workers/WorkerScope.cpp
+++ b/dom/workers/WorkerScope.cpp
@@ -390,25 +390,19 @@ already_AddRefed<IDBFactory> WorkerGloba
 
   if (!indexedDB) {
     if (!mWorkerPrivate->IsStorageAllowed()) {
       NS_WARNING("IndexedDB is not allowed in this worker!");
       aErrorResult = NS_ERROR_DOM_SECURITY_ERR;
       return nullptr;
     }
 
-    JSContext* cx = mWorkerPrivate->GetJSContext();
-    MOZ_ASSERT(cx);
-
-    JS::Rooted<JSObject*> owningObject(cx, GetGlobalJSObject());
-    MOZ_ASSERT(owningObject);
-
     const PrincipalInfo& principalInfo = mWorkerPrivate->GetPrincipalInfo();
 
-    nsresult rv = IDBFactory::CreateForWorker(cx, owningObject, principalInfo,
+    nsresult rv = IDBFactory::CreateForWorker(this, principalInfo,
                                               mWorkerPrivate->WindowID(),
                                               getter_AddRefs(indexedDB));
     if (NS_WARN_IF(NS_FAILED(rv))) {
       aErrorResult = rv;
       return nullptr;
     }
 
     mIndexedDB = indexedDB;