Bug 1045646 - Part 2: Replace AutoPushJSContext in nsCryptoRunnable::Run. r=bholley

This commit is contained in:
Bob Owen 2014-08-01 09:00:58 +01:00
parent bf632a1c9f
commit 234cfb9f03

View File

@ -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<nsISupports> m_kungFuDeathGrip;
JSContext *m_cx;
JS::PersistentRooted<JSObject*> m_scope;
nsCryptoRunArgs();
nsCOMPtr<nsIGlobalObject> 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<nsISupports *>(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<nsIGlobalObject> 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<JSObject*> 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,