From 8c896093c892f2f273830e21c5419e7512aed768 Mon Sep 17 00:00:00 2001 From: Bob Owen Date: Fri, 1 Aug 2014 09:00:58 +0100 Subject: [PATCH] Bug 1045646 - Part 2: Replace AutoPushJSContext in nsCryptoRunnable::Run. r=bholley --- security/manager/ssl/src/nsCrypto.cpp | 39 +++++++++++---------------- 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/security/manager/ssl/src/nsCrypto.cpp b/security/manager/ssl/src/nsCrypto.cpp index bf560bb105e2..f656eeeadbc9 100644 --- a/security/manager/ssl/src/nsCrypto.cpp +++ b/security/manager/ssl/src/nsCrypto.cpp @@ -15,6 +15,7 @@ #include "nsServiceManagerUtils.h" #ifndef MOZ_DISABLE_CRYPTOLEGACY +#include "mozilla/dom/ScriptSettings.h" #include "nsKeygenHandler.h" #include "nsKeygenThread.h" #include "nsNSSCertificate.h" @@ -33,7 +34,7 @@ #include "nsIDocument.h" #include "nsIScriptObjectPrincipal.h" #include "nsIScriptContext.h" -#include "nsIScriptGlobalObject.h" +#include "nsIGlobalObject.h" #include "nsContentUtils.h" #include "nsCxPusher.h" #include "nsDOMJSUtils.h" @@ -167,10 +168,8 @@ typedef struct nsKeyPairInfoStr { //to the nsCryptoRunnable event. class nsCryptoRunArgs : public nsISupports { public: - nsCryptoRunArgs(JSContext *aCx); - nsCOMPtr m_kungFuDeathGrip; - JSContext *m_cx; - JS::PersistentRooted m_scope; + nsCryptoRunArgs(); + nsCOMPtr m_globalObject; nsXPIDLCString m_jsCallback; NS_DECL_ISUPPORTS protected: @@ -1842,15 +1841,6 @@ loser: return nullptr; } -static nsISupports * -GetISupportsFromContext(JSContext *cx) -{ - if (JS::ContextOptionsRef(cx).privateIsNSISupports()) - return static_cast(JS_GetContextPrivate(cx)); - - return nullptr; -} - //The top level method which is a member of nsIDOMCrypto //for generate a base64 encoded CRMF request. CRMFObject* @@ -1888,8 +1878,8 @@ nsCrypto::GenerateCRMFRequest(JSContext* aContext, return nullptr; } - JS::RootedObject script_obj(aContext, GetWrapper()); - if (MOZ_UNLIKELY(!script_obj)) { + nsCOMPtr globalObject = do_QueryInterface(GetParentObject()); + if (MOZ_UNLIKELY(!globalObject)) { aRv.Throw(NS_ERROR_UNEXPECTED); return nullptr; } @@ -2036,10 +2026,9 @@ nsCrypto::GenerateCRMFRequest(JSContext* aContext, // MOZ_ASSERT(nsContentUtils::GetCurrentJSContext()); - nsCryptoRunArgs *args = new nsCryptoRunArgs(aContext); + nsCryptoRunArgs *args = new nsCryptoRunArgs(); - args->m_kungFuDeathGrip = GetISupportsFromContext(aContext); - args->m_scope = JS_GetParent(script_obj); + args->m_globalObject = globalObject; if (!aJsCallback.IsVoid()) { args->m_jsCallback = aJsCallback; } @@ -2148,7 +2137,7 @@ nsP12Runnable::Run() return NS_OK; } -nsCryptoRunArgs::nsCryptoRunArgs(JSContext *cx) : m_cx(cx), m_scope(cx) {} +nsCryptoRunArgs::nsCryptoRunArgs() {} nsCryptoRunArgs::~nsCryptoRunArgs() {} @@ -2172,10 +2161,12 @@ NS_IMETHODIMP nsCryptoRunnable::Run() { nsNSSShutDownPreventionLock locker; - AutoPushJSContext cx(m_args->m_cx); - JSAutoRequest ar(cx); - JS::Rooted scope(cx, m_args->m_scope); - JSAutoCompartment ac(cx, scope); + + // We're going to run script via JS_EvaluateScript, so we need an + // AutoEntryScript. This is Gecko specific and not on a standards track. + AutoEntryScript aes(m_args->m_globalObject); + JSContext* cx = aes.cx(); + JS::RootedObject scope(cx, JS::CurrentGlobalOrNull(cx)); bool ok = JS_EvaluateScript(cx, scope, m_args->m_jsCallback,