diff --git a/dom/base/StructuredCloneHolder.cpp b/dom/base/StructuredCloneHolder.cpp index 9f697fc2878e..0fbf5975399c 100644 --- a/dom/base/StructuredCloneHolder.cpp +++ b/dom/base/StructuredCloneHolder.cpp @@ -378,7 +378,7 @@ StructuredCloneHolder::ReadFullySerializableObjects(JSContext* aCx, } if (aTag == SCTAG_DOM_WEBCRYPTO_KEY || aTag == SCTAG_DOM_URLSEARCHPARAMS) { - nsIGlobalObject *global = xpc::NativeGlobal(JS::CurrentGlobalOrNull(aCx)); + nsIGlobalObject* global = xpc::CurrentNativeGlobal(aCx); if (!global) { return nullptr; } @@ -436,7 +436,7 @@ StructuredCloneHolder::ReadFullySerializableObjects(JSContext* aCx, return nullptr; } - nsIGlobalObject *global = xpc::NativeGlobal(JS::CurrentGlobalOrNull(aCx)); + nsIGlobalObject* global = xpc::CurrentNativeGlobal(aCx); if (!global) { return nullptr; } diff --git a/dom/indexedDB/IDBObjectStore.cpp b/dom/indexedDB/IDBObjectStore.cpp index 0f1fa8a03242..6c5caba66374 100644 --- a/dom/indexedDB/IDBObjectStore.cpp +++ b/dom/indexedDB/IDBObjectStore.cpp @@ -952,7 +952,7 @@ public: if (aDatabase && aDatabase->GetParentObject()) { parent = aDatabase->GetParentObject(); } else { - parent = xpc::NativeGlobal(JS::CurrentGlobalOrNull(aCx)); + parent = xpc::CurrentNativeGlobal(aCx); } } else { WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate(); diff --git a/dom/ipc/StructuredCloneData.cpp b/dom/ipc/StructuredCloneData.cpp index e17637003287..1b9f10585768 100644 --- a/dom/ipc/StructuredCloneData.cpp +++ b/dom/ipc/StructuredCloneData.cpp @@ -101,7 +101,7 @@ StructuredCloneData::Read(JSContext* aCx, { MOZ_ASSERT(mInitialized); - nsIGlobalObject *global = xpc::NativeGlobal(JS::CurrentGlobalOrNull(aCx)); + nsIGlobalObject* global = xpc::CurrentNativeGlobal(aCx); MOZ_ASSERT(global); ReadFromBuffer(global, aCx, Data(), aValue, aRv); diff --git a/dom/script/ScriptSettings.cpp b/dom/script/ScriptSettings.cpp index 293e49f3d7c4..40c59e7234a4 100644 --- a/dom/script/ScriptSettings.cpp +++ b/dom/script/ScriptSettings.cpp @@ -693,8 +693,7 @@ AutoEntryScript::DocshellEntryMonitor::Entry(JSContext* aCx, JSFunction* aFuncti rootedScript = aScript; } - nsCOMPtr window = - do_QueryInterface(xpc::NativeGlobal(JS::CurrentGlobalOrNull(aCx))); + nsCOMPtr window = xpc::CurrentWindowOrNull(aCx); if (!window || !window->GetDocShell() || !window->GetDocShell()->GetRecordProfileTimelineMarkers()) { return; @@ -738,8 +737,7 @@ AutoEntryScript::DocshellEntryMonitor::Entry(JSContext* aCx, JSFunction* aFuncti void AutoEntryScript::DocshellEntryMonitor::Exit(JSContext* aCx) { - nsCOMPtr window = - do_QueryInterface(xpc::NativeGlobal(JS::CurrentGlobalOrNull(aCx))); + nsCOMPtr window = xpc::CurrentWindowOrNull(aCx); // Not really worth checking GetRecordProfileTimelineMarkers here. if (window && window->GetDocShell()) { nsCOMPtr docShellForJSRunToCompletion = window->GetDocShell(); diff --git a/dom/webauthn/PublicKeyCredential.cpp b/dom/webauthn/PublicKeyCredential.cpp index db3c88ed34e9..79bf234b65b0 100644 --- a/dom/webauthn/PublicKeyCredential.cpp +++ b/dom/webauthn/PublicKeyCredential.cpp @@ -86,8 +86,7 @@ PublicKeyCredential::SetResponse(RefPtr aResponse) /* static */ already_AddRefed PublicKeyCredential::IsUserVerifyingPlatformAuthenticatorAvailable(GlobalObject& aGlobal) { - nsIGlobalObject* globalObject = - xpc::NativeGlobal(JS::CurrentGlobalOrNull(aGlobal.Context())); + nsIGlobalObject* globalObject = xpc::CurrentNativeGlobal(aGlobal.Context()); if (NS_WARN_IF(!globalObject)) { return nullptr; } diff --git a/gfx/src/nsThebesFontEnumerator.cpp b/gfx/src/nsThebesFontEnumerator.cpp index b7e21d07af15..c69b14c9a04c 100644 --- a/gfx/src/nsThebesFontEnumerator.cpp +++ b/gfx/src/nsThebesFontEnumerator.cpp @@ -179,8 +179,7 @@ nsThebesFontEnumerator::EnumerateFontsAsync(const char* aLangGroup, { MOZ_ASSERT(NS_IsMainThread()); - nsCOMPtr global = - xpc::NativeGlobal(JS::CurrentGlobalOrNull(aCx)); + nsCOMPtr global = xpc::CurrentNativeGlobal(aCx); NS_ENSURE_TRUE(global, NS_ERROR_UNEXPECTED); ErrorResult errv; diff --git a/js/xpconnect/src/ExportHelpers.cpp b/js/xpconnect/src/ExportHelpers.cpp index ee724778b278..ac6ac152f470 100644 --- a/js/xpconnect/src/ExportHelpers.cpp +++ b/js/xpconnect/src/ExportHelpers.cpp @@ -119,7 +119,7 @@ public: return nullptr; } - nsIGlobalObject* global = xpc::NativeGlobal(JS::CurrentGlobalOrNull(aCx)); + nsIGlobalObject* global = xpc::CurrentNativeGlobal(aCx); MOZ_ASSERT(global); // RefPtr needs to go out of scope before toObjectOrNull() is called because diff --git a/js/xpconnect/src/XPCConvert.cpp b/js/xpconnect/src/XPCConvert.cpp index 3d5281ba835d..ca2a9b9aea28 100644 --- a/js/xpconnect/src/XPCConvert.cpp +++ b/js/xpconnect/src/XPCConvert.cpp @@ -813,7 +813,7 @@ XPCConvert::JSData2Native(void* d, HandleValue s, case nsXPTType::T_PROMISE: { - nsIGlobalObject* glob = NativeGlobal(CurrentGlobalOrNull(cx)); + nsIGlobalObject* glob = CurrentNativeGlobal(cx); if (!glob) { if (pErr) { *pErr = NS_ERROR_UNEXPECTED; diff --git a/js/xpconnect/src/xpcpublic.h b/js/xpconnect/src/xpcpublic.h index 616466f30210..56992cbd3cad 100644 --- a/js/xpconnect/src/xpcpublic.h +++ b/js/xpconnect/src/xpcpublic.h @@ -504,6 +504,13 @@ CompilationScope(); nsIGlobalObject* NativeGlobal(JSObject* aObj); +/** + * Returns the nsIGlobalObject corresponding to |cx|'s JS global. Must not be + * called when |cx| is not in a Realm. + */ +nsIGlobalObject* +CurrentNativeGlobal(JSContext* cx); + /** * If |aObj| is a window, returns the associated nsGlobalWindow. * Otherwise, returns null. @@ -519,7 +526,7 @@ nsGlobalWindowInner* WindowGlobalOrNull(JSObject* aObj); /** - * If |cx| is in a compartment whose global is a window, returns the associated + * If |cx| is in a realm whose global is a window, returns the associated * nsGlobalWindow. Otherwise, returns null. */ nsGlobalWindowInner* diff --git a/js/xpconnect/wrappers/WrapperFactory.cpp b/js/xpconnect/wrappers/WrapperFactory.cpp index 074b90b70435..28fe883629b4 100644 --- a/js/xpconnect/wrappers/WrapperFactory.cpp +++ b/js/xpconnect/wrappers/WrapperFactory.cpp @@ -701,4 +701,10 @@ NativeGlobal(JSObject* obj) return global; } +nsIGlobalObject* +CurrentNativeGlobal(JSContext* cx) +{ + return xpc::NativeGlobal(JS::CurrentGlobalOrNull(cx)); +} + } // namespace xpc diff --git a/layout/base/nsStyleSheetService.cpp b/layout/base/nsStyleSheetService.cpp index 0e379477584a..1c7f21638448 100644 --- a/layout/base/nsStyleSheetService.cpp +++ b/layout/base/nsStyleSheetService.cpp @@ -310,8 +310,7 @@ nsStyleSheetService::PreloadSheetAsync(nsIURI* aSheetURI, uint32_t aSheetType, nsresult rv = GetParsingMode(aSheetType, &parsingMode); NS_ENSURE_SUCCESS(rv, rv); - nsCOMPtr global = - xpc::NativeGlobal(JS::CurrentGlobalOrNull(aCx)); + nsCOMPtr global = xpc::CurrentNativeGlobal(aCx); NS_ENSURE_TRUE(global, NS_ERROR_UNEXPECTED); ErrorResult errv; diff --git a/security/manager/ssl/SecretDecoderRing.cpp b/security/manager/ssl/SecretDecoderRing.cpp index e7d505ff803f..70122388373f 100644 --- a/security/manager/ssl/SecretDecoderRing.cpp +++ b/security/manager/ssl/SecretDecoderRing.cpp @@ -152,9 +152,7 @@ SecretDecoderRing::AsyncEncryptStrings(uint32_t plaintextsCount, NS_ENSURE_ARG_POINTER(plaintexts); NS_ENSURE_ARG_POINTER(aCx); - nsIGlobalObject* globalObject = - xpc::NativeGlobal(JS::CurrentGlobalOrNull(aCx)); - + nsIGlobalObject* globalObject = xpc::CurrentNativeGlobal(aCx); if (NS_WARN_IF(!globalObject)) { return NS_ERROR_UNEXPECTED; } diff --git a/toolkit/components/telemetry/Telemetry.cpp b/toolkit/components/telemetry/Telemetry.cpp index ef83bb7e4ee7..e6c56e3d2e32 100644 --- a/toolkit/components/telemetry/Telemetry.cpp +++ b/toolkit/components/telemetry/Telemetry.cpp @@ -848,7 +848,7 @@ NS_IMETHODIMP TelemetryImpl::GetLoadedModules(JSContext *cx, Promise** aPromise) { #if defined(MOZ_GECKO_PROFILER) - nsIGlobalObject* global = xpc::NativeGlobal(JS::CurrentGlobalOrNull(cx)); + nsIGlobalObject* global = xpc::CurrentNativeGlobal(cx); if (NS_WARN_IF(!global)) { return NS_ERROR_FAILURE; } diff --git a/tools/profiler/gecko/nsProfiler.cpp b/tools/profiler/gecko/nsProfiler.cpp index 85eafd7bd568..7499f16a1c74 100644 --- a/tools/profiler/gecko/nsProfiler.cpp +++ b/tools/profiler/gecko/nsProfiler.cpp @@ -234,9 +234,7 @@ nsProfiler::GetProfileDataAsync(double aSinceTime, JSContext* aCx, return NS_ERROR_FAILURE; } - nsIGlobalObject* globalObject = - xpc::NativeGlobal(JS::CurrentGlobalOrNull(aCx)); - + nsIGlobalObject* globalObject = xpc::CurrentNativeGlobal(aCx); if (NS_WARN_IF(!globalObject)) { return NS_ERROR_FAILURE; } @@ -302,9 +300,7 @@ nsProfiler::GetProfileDataAsArrayBuffer(double aSinceTime, JSContext* aCx, return NS_ERROR_FAILURE; } - nsIGlobalObject* globalObject = - xpc::NativeGlobal(JS::CurrentGlobalOrNull(aCx)); - + nsIGlobalObject* globalObject = xpc::CurrentNativeGlobal(aCx); if (NS_WARN_IF(!globalObject)) { return NS_ERROR_FAILURE; } @@ -359,9 +355,7 @@ nsProfiler::DumpProfileToFileAsync(const nsACString& aFilename, return NS_ERROR_FAILURE; } - nsIGlobalObject* globalObject = - xpc::NativeGlobal(JS::CurrentGlobalOrNull(aCx)); - + nsIGlobalObject* globalObject = xpc::CurrentNativeGlobal(aCx); if (NS_WARN_IF(!globalObject)) { return NS_ERROR_FAILURE; } @@ -673,4 +667,4 @@ nsProfiler::ClearExpiredExitProfiles() mExitProfiles.RemoveElementsBy([bufferRangeStart](ExitProfile& aExitProfile){ return aExitProfile.mBufferPositionAtGatherTime < bufferRangeStart; }); -} \ No newline at end of file +}