Bug 834732 - Audit callers of GetNativeContext and use AutoPushJSContext where appropriate. r=mrbkap

This commit is contained in:
Bobby Holley 2013-02-26 11:04:13 -08:00
Родитель 66c30c5ec8
Коммит 7b9176007d
35 изменённых файлов: 98 добавлений и 109 удалений

Просмотреть файл

@ -26,6 +26,7 @@
#include "nsIDocument.h"
#include "jsfriendapi.h"
#include "xpcprivate.h"
#include "nsContentUtils.h"
#include "mozilla/Preferences.h"
#include "mozilla/Telemetry.h"
@ -64,7 +65,7 @@ static JSFunctionSpec PrivilegeManager_static_methods[] = {
NS_IMETHODIMP
nsSecurityNameSet::InitializeNameSet(nsIScriptContext* aScriptContext)
{
JSContext* cx = aScriptContext->GetNativeContext();
AutoPushJSContext cx(aScriptContext->GetNativeContext());
JSObject *global = JS_ObjectToInnerObject(cx, JS_GetGlobalObject(cx));
/*

Просмотреть файл

@ -1227,7 +1227,7 @@ EventSource::DispatchAllMessageEvents()
nsIScriptContext* scriptContext = sgo->GetContext();
NS_ENSURE_TRUE_VOID(scriptContext);
JSContext* cx = scriptContext->GetNativeContext();
AutoPushJSContext cx(scriptContext->GetNativeContext());
NS_ENSURE_TRUE_VOID(cx);
while (mMessagesToDispatch.GetSize() > 0) {

Просмотреть файл

@ -881,7 +881,7 @@ WebSocket::CreateAndDispatchMessageEvent(const nsACString& aData,
nsIScriptContext* scriptContext = sgo->GetContext();
NS_ENSURE_TRUE(scriptContext, NS_ERROR_FAILURE);
JSContext* cx = scriptContext->GetNativeContext();
AutoPushJSContext cx(scriptContext->GetNativeContext());
NS_ENSURE_TRUE(cx, NS_ERROR_FAILURE);
// Create appropriate JS object for message

Просмотреть файл

@ -6412,8 +6412,8 @@ nsContentUtils::IsPatternMatching(nsAString& aValue, nsAString& aPattern,
NS_ASSERTION(aDocument, "aDocument should be a valid pointer (not null)");
NS_ENSURE_TRUE(aDocument->GetScriptGlobalObject(), true);
JSContext* cx = aDocument->GetScriptGlobalObject()->
GetContext()->GetNativeContext();
AutoPushJSContext cx(aDocument->GetScriptGlobalObject()->
GetContext()->GetNativeContext());
NS_ENSURE_TRUE(cx, true);
JSAutoRequest ar(cx);

Просмотреть файл

@ -45,6 +45,8 @@ extern PRLogModuleInfo* GetDataChannelLog();
#undef GetBinaryType
#endif
using namespace mozilla;
class nsDOMDataChannel : public nsDOMEventTargetHelper,
public nsIDOMDataChannel,
public mozilla::DataChannelListener
@ -393,7 +395,7 @@ nsDOMDataChannel::DoOnMessageAvailable(const nsACString& aData,
nsIScriptContext* sc = sgo->GetContext();
NS_ENSURE_TRUE(sc, NS_ERROR_FAILURE);
JSContext* cx = sc->GetNativeContext();
AutoPushJSContext cx(sc->GetNativeContext());
NS_ENSURE_TRUE(cx, NS_ERROR_FAILURE);
JSAutoRequest ar(cx);

Просмотреть файл

@ -3983,19 +3983,8 @@ nsDocument::SetScriptGlobalObject(nsIScriptGlobalObject *aScriptGlobalObject)
JSObject *obj = GetWrapperPreserveColor();
if (obj) {
JSObject *newScope = aScriptGlobalObject->GetGlobalJSObject();
nsIScriptContext *scx = aScriptGlobalObject->GetContext();
JSContext *cx = scx ? scx->GetNativeContext() : nullptr;
if (!cx) {
nsContentUtils::ThreadJSContextStack()->Peek(&cx);
if (!cx) {
cx = nsContentUtils::ThreadJSContextStack()->GetSafeJSContext();
NS_ASSERTION(cx, "Uhoh, no context, this is bad!");
}
}
if (cx) {
NS_ASSERTION(JS_GetGlobalForObject(cx, obj) == newScope,
"Wrong scope, this is really bad!");
}
NS_ASSERTION(js::GetGlobalForObjectCrossCompartment(obj) == newScope,
"Wrong scope, this is really bad!");
}
}
#endif
@ -6829,7 +6818,7 @@ nsDocument::IsScriptEnabled()
nsIScriptContext *scriptContext = globalObject->GetContext();
NS_ENSURE_TRUE(scriptContext, false);
JSContext* cx = scriptContext->GetNativeContext();
AutoPushJSContext cx(scriptContext->GetNativeContext());
NS_ENSURE_TRUE(cx, false);
bool enabled;
@ -8547,7 +8536,7 @@ nsDocument::GetStateObject(nsIVariant** aState)
nsCOMPtr<nsIVariant> stateObj;
if (!mStateObjectCached && mStateObjectContainer) {
JSContext *cx = nsContentUtils::GetContextFromDocument(this);
AutoPushJSContext cx(nsContentUtils::GetContextFromDocument(this));
mStateObjectContainer->
DeserializeToVariant(cx, getter_AddRefs(mStateObjectCached));
}

Просмотреть файл

@ -2363,7 +2363,7 @@ nsFrameLoader::EnsureMessageManager()
nsIScriptContext* sctx = mOwnerContent->GetContextForEventHandlers(&rv);
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_STATE(sctx);
JSContext* cx = sctx->GetNativeContext();
AutoPushJSContext cx(sctx->GetNativeContext());
NS_ENSURE_STATE(cx);
nsCOMPtr<nsIDOMChromeWindow> chromeWindow =

Просмотреть файл

@ -822,6 +822,7 @@ nsScriptLoader::EvaluateScript(nsScriptLoadRequest* aRequest,
if (!context) {
return NS_ERROR_FAILURE;
}
AutoPushJSContext cx(context->GetNativeContext());
bool oldProcessingScriptTag = context->GetProcessingScriptTag();
context->SetProcessingScriptTag(true);
@ -837,7 +838,7 @@ nsScriptLoader::EvaluateScript(nsScriptLoadRequest* aRequest,
JSVersion version = JSVersion(aRequest->mJSVersion);
if (version != JSVERSION_UNKNOWN) {
JS::CompileOptions options(context->GetNativeContext());
JS::CompileOptions options(cx);
options.setFileAndLine(url.get(), aRequest->mLineNo)
.setVersion(JSVersion(aRequest->mJSVersion));
if (aRequest->mOriginPrincipal) {
@ -850,8 +851,6 @@ nsScriptLoader::EvaluateScript(nsScriptLoadRequest* aRequest,
// Put the old script back in case it wants to do anything else.
mCurrentScript = oldCurrent;
JSContext *cx = nullptr; // Initialize this to keep GCC happy.
cx = context->GetNativeContext();
JSAutoRequest ar(cx);
context->SetProcessingScriptTag(oldProcessingScriptTag);
return rv;

Просмотреть файл

@ -1341,8 +1341,7 @@ IsScriptEnabled(nsIDocument *aDoc, nsIDocShell *aContainer)
nsIScriptContext *scriptContext = globalObject->GetContext();
NS_ENSURE_TRUE(scriptContext, true);
JSContext* cx = scriptContext->GetNativeContext();
JSContext *cx = scriptContext->GetNativeContext();
NS_ENSURE_TRUE(cx, true);
bool enabled = true;

Просмотреть файл

@ -663,7 +663,7 @@ WebAudioDecodeJob::FinalizeBufferData()
MOZ_ASSERT(mOutput);
MOZ_ASSERT(mChannels == mChannelBuffers.Length());
JSContext* cx = GetJSContext();
AutoPushJSContext cx(GetJSContext());
if (!cx) {
return false;
}
@ -696,7 +696,7 @@ WebAudioDecodeJob::AllocateBuffer()
MOZ_ASSERT(NS_IsMainThread());
// First, get a JSContext
JSContext* cx = GetJSContext();
AutoPushJSContext cx(GetJSContext());
if (!cx) {
return false;
}

Просмотреть файл

@ -45,6 +45,8 @@
#include "nsThreadUtils.h"
#include "mozilla/dom/NodeListBinding.h"
using namespace mozilla;
// ==================================================================
// = nsAnonymousContentList
// ==================================================================
@ -1177,7 +1179,7 @@ nsBindingManager::GetBindingImplementation(nsIContent* aContent, REFNSIID aIID,
if (!context)
return NS_NOINTERFACE;
JSContext* jscontext = context->GetNativeContext();
AutoPushJSContext jscontext(context->GetNativeContext());
if (!jscontext)
return NS_NOINTERFACE;

Просмотреть файл

@ -1263,7 +1263,7 @@ nsXBLBinding::AllowScripts()
return false;
}
JSContext* cx = context->GetNativeContext();
AutoPushJSContext cx(context->GetNativeContext());
nsCOMPtr<nsIDocument> ourDocument =
mPrototypeBinding->XBLDocumentInfo()->GetDocument();

Просмотреть файл

@ -272,7 +272,7 @@ nsXBLDocGlobalObject::EnsureScriptEnvironment()
mScriptContext = newCtx;
JSContext *cx = mScriptContext->GetNativeContext();
AutoPushJSContext cx(mScriptContext->GetNativeContext());
JSAutoRequest ar(cx);
// nsJSEnvironment set the error reporter to NS_ScriptErrorReporter so

Просмотреть файл

@ -86,7 +86,7 @@ nsXBLProtoImpl::InstallImplementation(nsXBLPrototypeBinding* aPrototypeBinding,
JSObject * targetScriptObject;
holder->GetJSObject(&targetScriptObject);
JSContext *cx = context->GetNativeContext();
AutoPushJSContext cx(context->GetNativeContext());
JSAutoRequest ar(cx);
JSAutoCompartment ac(cx, targetClassObject);
AutoVersionChecker avc(cx);
@ -172,7 +172,7 @@ nsXBLProtoImpl::InitTargetObjects(nsXBLPrototypeBinding* aBinding,
// Because our prototype implementation has a class, we need to build up a corresponding
// class for the concrete implementation in the bound document.
JSContext* jscontext = aContext->GetNativeContext();
AutoPushJSContext jscontext(aContext->GetNativeContext());
JSObject* global = sgo->GetGlobalJSObject();
nsCOMPtr<nsIXPConnectJSObjectHolder> wrapper;
jsval v;
@ -211,7 +211,7 @@ nsXBLProtoImpl::CompilePrototypeMembers(nsXBLPrototypeBinding* aBinding)
nsIScriptContext *context = globalObject->GetContext();
NS_ENSURE_TRUE(context, NS_ERROR_OUT_OF_MEMORY);
JSContext *cx = context->GetNativeContext();
AutoPushJSContext cx(context->GetNativeContext());
JSObject *global = globalObject->GetGlobalJSObject();
@ -348,7 +348,7 @@ nsXBLProtoImpl::Read(nsIScriptContext* aContext,
nsIScriptGlobalObject* aGlobal)
{
// Set up a class object first so that deserialization is possible
JSContext *cx = aContext->GetNativeContext();
AutoPushJSContext cx(aContext->GetNativeContext());
JSObject *global = aGlobal->GetGlobalJSObject();
JSObject* classObject;

Просмотреть файл

@ -400,7 +400,7 @@ nsXBLProtoImplField::InstallField(nsIScriptContext* aContext,
nsAutoCString uriSpec;
aBindingDocURI->GetSpec(uriSpec);
JSContext* cx = aContext->GetNativeContext();
AutoPushJSContext cx(aContext->GetNativeContext());
NS_ASSERTION(!::JS_IsExceptionPending(cx),
"Shouldn't get here when an exception is pending!");

Просмотреть файл

@ -20,6 +20,8 @@
#include "xpcpublic.h"
#include "nsXBLPrototypeBinding.h"
using namespace mozilla;
nsXBLProtoImplMethod::nsXBLProtoImplMethod(const PRUnichar* aName) :
nsXBLProtoImplMember(aName),
mUncompiledMethod(BIT_UNCOMPILED)
@ -192,7 +194,7 @@ nsXBLProtoImplMethod::CompileMember(nsIScriptContext* aContext, const nsCString&
}
JSObject* methodObject = nullptr;
JSContext* cx = aContext->GetNativeContext();
AutoPushJSContext cx(aContext->GetNativeContext());
JSAutoRequest ar(cx);
JSAutoCompartment ac(cx, aClassObject);
JS::CompileOptions options(cx);
@ -287,7 +289,7 @@ nsXBLProtoImplAnonymousMethod::Execute(nsIContent* aBoundElement)
nsAutoMicroTask mt;
JSContext* cx = context->GetNativeContext();
AutoPushJSContext cx(context->GetNativeContext());
JSObject* globalObject = global->GetGlobalJSObject();

Просмотреть файл

@ -9,6 +9,7 @@
#include "nsIContent.h"
#include "nsXBLProtoImplProperty.h"
#include "nsUnicharUtils.h"
#include "nsContentUtils.h"
#include "nsReadableUtils.h"
#include "nsIScriptContext.h"
#include "nsJSUtils.h"
@ -17,6 +18,8 @@
#include "nsXBLSerialize.h"
#include "xpcpublic.h"
using namespace mozilla;
nsXBLProtoImplProperty::nsXBLProtoImplProperty(const PRUnichar* aName,
const PRUnichar* aGetter,
const PRUnichar* aSetter,
@ -207,7 +210,7 @@ nsXBLProtoImplProperty::CompileMember(nsIScriptContext* aContext, const nsCStrin
if (!getter.IsEmpty()) {
// Compile into a temp object so we don't wipe out mGetterText
JSObject* getterObject = nullptr;
JSContext* cx = aContext->GetNativeContext();
AutoPushJSContext cx(aContext->GetNativeContext());
JSAutoRequest ar(cx);
JSAutoCompartment ac(cx, aClassObject);
JS::CompileOptions options(cx);
@ -257,7 +260,7 @@ nsXBLProtoImplProperty::CompileMember(nsIScriptContext* aContext, const nsCStrin
if (!setter.IsEmpty()) {
// Compile into a temp object so we don't wipe out mSetterText
JSObject* setterObject = nullptr;
JSContext* cx = aContext->GetNativeContext();
AutoPushJSContext cx(aContext->GetNativeContext());
JSAutoRequest ar(cx);
JSAutoCompartment ac(cx, aClassObject);
JS::CompileOptions options(cx);

Просмотреть файл

@ -290,7 +290,7 @@ nsXBLPrototypeHandler::ExecuteHandler(nsIDOMEventTarget* aTarget,
rv = EnsureEventHandler(boundGlobal, boundContext, onEventAtom, handler);
NS_ENSURE_SUCCESS(rv, rv);
JSContext* cx = boundContext->GetNativeContext();
AutoPushJSContext cx(boundContext->GetNativeContext());
JSAutoRequest ar(cx);
JSObject* globalObject = boundGlobal->GetGlobalJSObject();
JSObject* scopeObject = xpc::GetXBLScope(cx, globalObject);
@ -370,7 +370,7 @@ nsXBLPrototypeHandler::EnsureEventHandler(nsIScriptGlobalObject* aGlobal,
nsDependentString handlerText(mHandlerText);
NS_ENSURE_TRUE(!handlerText.IsEmpty(), NS_ERROR_FAILURE);
JSContext* cx = aBoundContext->GetNativeContext();
AutoPushJSContext cx(aBoundContext->GetNativeContext());
JSObject* globalObject = aGlobal->GetGlobalJSObject();
JSObject* scopeObject = xpc::GetXBLScope(cx, globalObject);

Просмотреть файл

@ -8,12 +8,14 @@
#include "nsContentUtils.h"
#include "jsdbgapi.h"
using namespace mozilla;
nsresult
XBL_SerializeFunction(nsIScriptContext* aContext,
nsIObjectOutputStream* aStream,
JSObject* aFunctionObject)
{
JSContext* cx = aContext->GetNativeContext();
AutoPushJSContext cx(aContext->GetNativeContext());
return nsContentUtils::XPConnect()->WriteFunction(aStream, cx, aFunctionObject);
}
@ -22,7 +24,7 @@ XBL_DeserializeFunction(nsIScriptContext* aContext,
nsIObjectInputStream* aStream,
JSObject** aFunctionObjectp)
{
JSContext* cx = aContext->GetNativeContext();
AutoPushJSContext cx(aContext->GetNativeContext());
nsresult rv = nsContentUtils::XPConnect()->ReadFunction(aStream, cx, aFunctionObjectp);
NS_ENSURE_SUCCESS(rv, rv);

Просмотреть файл

@ -33,6 +33,7 @@
#include "mozilla/dom/BindingUtils.h"
using mozilla::dom::DestroyProtoAndIfaceCache;
using mozilla::AutoPushJSContext;
static NS_DEFINE_CID(kDOMScriptObjectFactoryCID,
NS_DOM_SCRIPT_OBJECT_FACTORY_CID);
@ -757,7 +758,7 @@ nsXULPDGlobalObject::EnsureScriptEnvironment()
// attach it as the global for this context. Then, we
// will re-fetch the global and set it up in our language globals array.
{
JSContext *cx = ctxNew->GetNativeContext();
AutoPushJSContext cx(ctxNew->GetNativeContext());
JSAutoRequest ar(cx);
JSObject *newGlob = JS_NewGlobalObject(cx, &gSharedGlobalClass,

Просмотреть файл

@ -71,6 +71,7 @@
#include "nsContentUtils.h"
using namespace mozilla::dom;
using namespace mozilla;
//----------------------------------------------------------------------
@ -1387,7 +1388,7 @@ nsXULTemplateBuilder::InitHTMLTemplateRoot()
if (! context)
return NS_ERROR_UNEXPECTED;
JSContext* jscontext = context->GetNativeContext();
AutoPushJSContext jscontext(context->GetNativeContext());
NS_ASSERTION(context != nullptr, "no jscontext");
if (! jscontext)
return NS_ERROR_UNEXPECTED;

Просмотреть файл

@ -18,6 +18,7 @@
using mozilla::dom::DOMRequest;
using mozilla::dom::DOMRequestService;
using mozilla::dom::DOMCursor;
using mozilla::AutoPushJSContext;
DOMRequest::DOMRequest(nsIDOMWindow* aWindow)
: mResult(JSVAL_VOID)
@ -240,9 +241,10 @@ public:
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
nsresult rv;
nsIScriptContext* sc = mReq->GetContextForEventHandlers(&rv);
MOZ_ASSERT(NS_SUCCEEDED(rv) && sc->GetNativeContext());
JSAutoRequest ar(sc->GetNativeContext());
JS_AddValueRoot(sc->GetNativeContext(), &mResult);
AutoPushJSContext cx(sc->GetNativeContext());
MOZ_ASSERT(NS_SUCCEEDED(rv) && cx);
JSAutoRequest ar(cx);
JS_AddValueRoot(cx, &mResult);
}
NS_IMETHODIMP
@ -257,12 +259,13 @@ public:
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
nsresult rv;
nsIScriptContext* sc = mReq->GetContextForEventHandlers(&rv);
MOZ_ASSERT(NS_SUCCEEDED(rv) && sc->GetNativeContext());
AutoPushJSContext cx(sc->GetNativeContext());
MOZ_ASSERT(NS_SUCCEEDED(rv) && cx);
// We need to build a new request, otherwise we assert since there won't be
// a request available yet.
JSAutoRequest ar(sc->GetNativeContext());
JS_RemoveValueRoot(sc->GetNativeContext(), &mResult);
JSAutoRequest ar(cx);
JS_RemoveValueRoot(cx, &mResult);
}
private:
nsRefPtr<DOMRequest> mReq;

Просмотреть файл

@ -1339,7 +1339,7 @@ nsGlobalWindow::FreeInnerObjects()
// Kill all of the workers for this window.
nsIScriptContext *scx = GetContextInternal();
JSContext *cx = scx ? scx->GetNativeContext() : nullptr;
AutoPushJSContext cx(scx ? scx->GetNativeContext() : nullptr);
mozilla::dom::workers::CancelWorkersForWindow(cx, this);
// Close all IndexedDB databases for this window.
@ -1893,7 +1893,7 @@ NS_IMPL_ISUPPORTS1(WindowStateHolder, WindowStateHolder)
nsresult
nsGlobalWindow::CreateOuterObject(nsGlobalWindow* aNewInner)
{
JSContext* cx = mContext->GetNativeContext();
AutoPushJSContext cx(mContext->GetNativeContext());
JSObject* outer = NewOuterWindowProxy(cx, aNewInner->FastGetGlobalJSObject(),
IsChromeWindow());
@ -2995,11 +2995,10 @@ nsGlobalWindow::SetArguments(nsIArray *aArguments, nsIPrincipal *aOrigin)
nsresult
nsGlobalWindow::DefineArgumentsProperty(nsIArray *aArguments)
{
JSContext *cx;
nsIScriptContext *ctx = GetOuterWindowInternal()->mContext;
NS_ENSURE_TRUE(aArguments && ctx &&
(cx = ctx->GetNativeContext()),
NS_ERROR_NOT_INITIALIZED);
NS_ENSURE_TRUE(aArguments && ctx, NS_ERROR_NOT_INITIALIZED);
AutoPushJSContext cx(ctx->GetNativeContext());
NS_ENSURE_TRUE(cx, NS_ERROR_NOT_INITIALIZED);
if (mIsModalContentWindow) {
// Modal content windows don't have an "arguments" property, they
@ -6486,25 +6485,10 @@ PostMessageEvent::Run()
"should have been passed an outer window!");
// Get the JSContext for the target window
JSContext* cx = nullptr;
nsIScriptContext* scriptContext = mTargetWindow->GetContext();
if (scriptContext) {
cx = scriptContext->GetNativeContext();
}
if (!cx) {
// This can happen if mTargetWindow has been closed. To avoid leaking,
// we need to find a JSContext.
nsIThreadJSContextStack* cxStack = nsContentUtils::ThreadJSContextStack();
if (cxStack) {
cx = cxStack->GetSafeJSContext();
}
if (!cx) {
NS_WARNING("Cannot find a JSContext! Leaking PostMessage buffer.");
return NS_ERROR_FAILURE;
}
}
AutoPushJSContext cx(scriptContext ? scriptContext->GetNativeContext()
: nsContentUtils::GetSafeJSContext());
MOZ_ASSERT(cx);
// If we bailed before this point we're going to leak mMessage, but
// that's probably better than crashing.
@ -9960,7 +9944,8 @@ nsGlobalWindow::RunTimeoutHandler(nsTimeout* aTimeout,
uint32_t lineNo = 0;
handler->GetLocation(&filename, &lineNo);
JS::CompileOptions options(aScx->GetNativeContext());
AutoPushJSContext cx(aScx->GetNativeContext());
JS::CompileOptions options(cx);
options.setFileAndLine(filename, lineNo)
.setVersion(JSVERSION_DEFAULT);
aScx->EvaluateString(nsDependentString(script), *FastGetGlobalJSObject(),
@ -10753,7 +10738,7 @@ nsGlobalWindow::SuspendTimeouts(uint32_t aIncrease,
// Suspend all of the workers for this window.
nsIScriptContext *scx = GetContextInternal();
JSContext *cx = scx ? scx->GetNativeContext() : nullptr;
AutoPushJSContext cx(scx ? scx->GetNativeContext() : nullptr);
mozilla::dom::workers::SuspendWorkersForWindow(cx, this);
TimeStamp now = TimeStamp::Now();
@ -10833,7 +10818,7 @@ nsGlobalWindow::ResumeTimeouts(bool aThawChildren)
// Resume all of the workers for this window.
nsIScriptContext *scx = GetContextInternal();
JSContext *cx = scx ? scx->GetNativeContext() : nullptr;
AutoPushJSContext cx(scx ? scx->GetNativeContext() : nullptr);
mozilla::dom::workers::ResumeWorkersForWindow(cx, this);
// Restore all of the timeouts, using the stored time remaining
@ -11335,7 +11320,7 @@ nsGlobalChromeWindow::GetMessageManager(nsIMessageBroadcaster** aManager)
if (!mMessageManager) {
nsIScriptContext* scx = GetContextInternal();
NS_ENSURE_STATE(scx);
JSContext* cx = scx->GetNativeContext();
AutoPushJSContext cx(scx->GetNativeContext());
NS_ENSURE_STATE(cx);
nsCOMPtr<nsIMessageBroadcaster> globalMM =
do_GetService("@mozilla.org/globalmessagemanager;1");

Просмотреть файл

@ -801,7 +801,7 @@ jsval InterfaceToJsval(nsPIDOMWindow* aWindow, nsISupports* aObject, const nsIID
return JSVAL_NULL;
}
JSContext *cx = scriptContext->GetNativeContext();
AutoPushJSContext cx(scriptContext->GetNativeContext());
if (!cx) {
return JSVAL_NULL;
}
@ -853,7 +853,7 @@ jsval StringToJsval(nsPIDOMWindow* aWindow, nsAString& aString)
return JSVAL_NULL;
}
JSContext *cx = scriptContext->GetNativeContext();
AutoPushJSContext cx(scriptContext->GetNativeContext());
if (!cx) {
return JSVAL_NULL;
}

Просмотреть файл

@ -129,7 +129,7 @@ ArchiveRequest::ReaderReady(nsTArray<nsCOMPtr<nsIDOMFile> >& aFileList,
nsIScriptContext* sc = GetContextForEventHandlers(&rv);
NS_ENSURE_STATE(sc);
JSContext* cx = sc->GetNativeContext();
AutoPushJSContext cx(sc->GetNativeContext());
NS_ASSERTION(cx, "Failed to get a context!");
JSObject* global = sc->GetNativeGlobal();

Просмотреть файл

@ -73,7 +73,7 @@ FileRequest::NotifyHelperCompleted(FileHelper* aFileHelper)
nsIScriptContext* sc = GetContextForEventHandlers(&rv);
NS_ENSURE_STATE(sc);
JSContext* cx = sc->GetNativeContext();
AutoPushJSContext cx(sc->GetNativeContext());
NS_ASSERTION(cx, "Failed to get a context!");
JSObject* global = sc->GetNativeGlobal();

Просмотреть файл

@ -96,7 +96,7 @@ IDBRequest::NotifyHelperCompleted(HelperBase* aHelper)
}
// Otherwise we need to get the result from the helper.
JSContext* cx = GetJSContext();
AutoPushJSContext cx(GetJSContext());
if (!cx) {
NS_WARNING("Failed to get safe JSContext!");
rv = NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;

Просмотреть файл

@ -212,7 +212,7 @@ MobileConnection::Observe(nsISupports* aSubject,
nsresult rv;
nsIScriptContext* sc = GetContextForEventHandlers(&rv);
NS_ENSURE_STATE(sc);
JSContext* cx = sc->GetNativeContext();
AutoPushJSContext cx(sc->GetNativeContext());
NS_ASSERTION(cx, "Failed to get a context!");
nsCOMPtr<nsIJSON> json(new nsJSON());

Просмотреть файл

@ -1221,7 +1221,7 @@ _getwindowobject(NPP npp)
NPN_PLUGIN_LOG(PLUGIN_LOG_ALWAYS,("NPN_getwindowobject called from the wrong thread\n"));
return nullptr;
}
JSContext *cx = GetJSContextFromNPP(npp);
AutoPushJSContext cx(GetJSContextFromNPP(npp));
NS_ENSURE_TRUE(cx, nullptr);
// Using ::JS_GetGlobalObject(cx) is ok here since the window we
@ -1248,7 +1248,7 @@ _getpluginelement(NPP npp)
if (!element)
return nullptr;
JSContext *cx = GetJSContextFromNPP(npp);
AutoPushJSContext cx(GetJSContextFromNPP(npp));
NS_ENSURE_TRUE(cx, nullptr);
nsCOMPtr<nsIXPConnect> xpc(do_GetService(nsIXPConnect::GetCID()));
@ -1519,7 +1519,7 @@ _evaluate(NPP npp, NPObject* npobj, NPString *script, NPVariant *result)
nsIDocument *doc = GetDocumentFromNPP(npp);
NS_ENSURE_TRUE(doc, false);
JSContext *cx = GetJSContextFromDoc(doc);
AutoPushJSContext cx(GetJSContextFromDoc(doc));
NS_ENSURE_TRUE(cx, false);
nsCOMPtr<nsIScriptContext> scx = GetScriptContextFromJSContext(cx);

Просмотреть файл

@ -171,7 +171,7 @@ SmsManager::Send(const jsval& aNumber, const nsAString& aMessage, jsval* aReturn
nsresult rv;
nsIScriptContext* sc = GetContextForEventHandlers(&rv);
NS_ENSURE_STATE(sc);
JSContext* cx = sc->GetNativeContext();
AutoPushJSContext cx(sc->GetNativeContext());
NS_ASSERTION(cx, "Failed to get a context!");
if (!aNumber.isString() &&
@ -253,10 +253,10 @@ SmsManager::Delete(const jsval& aParam, nsIDOMMozSmsRequest** aRequest)
nsresult rv;
nsIScriptContext* sc = GetContextForEventHandlers(&rv);
AutoPushJSContext cx(sc->GetNativeContext());
NS_ENSURE_STATE(sc);
nsCOMPtr<nsIDOMMozSmsMessage> message =
do_QueryInterface(nsContentUtils::XPConnect()->GetNativeOfWrapper(
sc->GetNativeContext(), &aParam.toObject()));
do_QueryInterface(nsContentUtils::XPConnect()->GetNativeOfWrapper(cx, &aParam.toObject()));
NS_ENSURE_TRUE(message, NS_ERROR_INVALID_ARG);
int32_t id;

Просмотреть файл

@ -190,7 +190,7 @@ SmsRequest::SetSuccessInternal(nsISupports* aObject)
return false;
}
JSContext* cx = sc->GetNativeContext();
AutoPushJSContext cx(sc->GetNativeContext());
NS_ASSERTION(cx, "Failed to get a context!");
JSObject* global = sc->GetNativeGlobal();
@ -514,7 +514,7 @@ SmsRequest::NotifyThreadList(const InfallibleTArray<ThreadListItem>& aItems)
NS_ENSURE_SUCCESS_VOID(rv);
NS_ENSURE_TRUE_VOID(sc);
JSContext* cx = sc->GetNativeContext();
AutoPushJSContext cx(sc->GetNativeContext());
MOZ_ASSERT(cx);
nsCOMPtr<nsIScriptGlobalObject> sgo = do_QueryInterface(GetOwner());

Просмотреть файл

@ -47,6 +47,8 @@
#include "nsIContentSecurityPolicy.h"
#include "nsSandboxFlags.h"
using mozilla::AutoPushJSContext;
static NS_DEFINE_CID(kJSURICID, NS_JSURI_CID);
class nsJSThunk : public nsIInputStream
@ -239,13 +241,7 @@ nsresult nsJSThunk::EvaluateScript(nsIChannel *aChannel,
if (!useSandbox) {
//-- Don't outside a sandbox unless the script principal subsumes the
// principal of the context.
nsCOMPtr<nsIPrincipal> objectPrincipal;
rv = securityManager->
GetObjectPrincipal(scriptContext->GetNativeContext(),
globalJSObject,
getter_AddRefs(objectPrincipal));
if (NS_FAILED(rv))
return rv;
nsIPrincipal* objectPrincipal = nsContentUtils::GetObjectPrincipal(globalJSObject);
bool subsumes;
rv = principal->Subsumes(objectPrincipal, &subsumes);
@ -258,7 +254,7 @@ nsresult nsJSThunk::EvaluateScript(nsIChannel *aChannel,
JS::Value v = JS::UndefinedValue();
// Finally, we have everything needed to evaluate the expression.
JSContext *cx = scriptContext->GetNativeContext();
AutoPushJSContext cx(scriptContext->GetNativeContext());
JSAutoRequest ar(cx);
if (useSandbox) {
// We were asked to use a sandbox, or the channel owner isn't allowed

Просмотреть файл

@ -274,10 +274,10 @@ Telephony::GetActive(jsval* aActive)
nsresult rv;
nsIScriptContext* sc = GetContextForEventHandlers(&rv);
NS_ENSURE_SUCCESS(rv, rv);
AutoPushJSContext cx(sc ? sc->GetNativeContext() : nullptr);
if (sc) {
rv =
nsContentUtils::WrapNative(sc->GetNativeContext(),
sc->GetNativeGlobal(),
nsContentUtils::WrapNative(cx, sc->GetNativeGlobal(),
mActiveCall->ToISupports(), aActive);
NS_ENSURE_SUCCESS(rv, rv);
}
@ -292,8 +292,9 @@ Telephony::GetCalls(jsval* aCalls)
nsresult rv;
nsIScriptContext* sc = GetContextForEventHandlers(&rv);
NS_ENSURE_SUCCESS(rv, rv);
AutoPushJSContext cx(sc ? sc->GetNativeContext() : nullptr);
if (sc) {
rv = nsTArrayToJSArray(sc->GetNativeContext(), mCalls, &calls);
rv = nsTArrayToJSArray(cx, mCalls, &calls);
NS_ENSURE_SUCCESS(rv, rv);
if (!mRooted) {

Просмотреть файл

@ -37,6 +37,7 @@
#include "nsBindingManager.h"
#include "nsIServiceManager.h"
#include "nsXULPopupManager.h"
#include "nsContentUtils.h"
#include "jsapi.h"
#include "nsIScriptGlobalObject.h"
@ -47,6 +48,7 @@ static bool gConstructingMenu = false;
static bool gMenuMethodsSwizzled = false;
int32_t nsMenuX::sIndexingMenuLevel = 0;
using mozilla::AutoPushJSContext;
//
@ -414,7 +416,7 @@ void nsMenuX::MenuConstruct()
nsCOMPtr<nsIScriptContext> scriptContext = sgo->GetContext();
JSObject* global = sgo->GetGlobalJSObject();
if (scriptContext && global) {
JSContext* cx = (JSContext*)scriptContext->GetNativeContext();
AutoPushJSContext cx(scriptContext->GetNativeContext());
if (cx) {
nsCOMPtr<nsIXPConnectJSObjectHolder> wrapper;
xpconnect->WrapNative(cx, global,

Просмотреть файл

@ -51,6 +51,7 @@
#include "nsXPCOMCID.h"
#include "nsIDocument.h"
#include "mozilla/Preferences.h"
#include "nsContentUtils.h"
using namespace mozilla;
@ -157,7 +158,7 @@ nsHTTPIndex::OnFTPControlLog(bool server, const char *msg)
nsIScriptContext *context = scriptGlobal->GetContext();
NS_ENSURE_TRUE(context, NS_OK);
JSContext* cx = context->GetNativeContext();
AutoPushJSContext cx(context->GetNativeContext());
NS_ENSURE_TRUE(cx, NS_OK);
JSObject* global = JS_GetGlobalObject(cx);
@ -235,7 +236,7 @@ nsHTTPIndex::OnStartRequest(nsIRequest *request, nsISupports* aContext)
nsIScriptContext *context = scriptGlobal->GetContext();
NS_ENSURE_TRUE(context, NS_ERROR_FAILURE);
JSContext* cx = context->GetNativeContext();
AutoPushJSContext cx(context->GetNativeContext());
JSObject* global = JS_GetGlobalObject(cx);
// Using XPConnect, wrap the HTTP index object...