diff --git a/content/base/src/Element.cpp b/content/base/src/Element.cpp index 75b13d4f5bb0..f99469faf8a2 100644 --- a/content/base/src/Element.cpp +++ b/content/base/src/Element.cpp @@ -73,7 +73,6 @@ #include "nsLayoutUtils.h" #include "nsGkAtoms.h" #include "nsContentUtils.h" -#include "nsIJSContextStack.h" #include "nsIDOMEventListener.h" #include "nsIWebNavigation.h" diff --git a/content/base/src/EventSource.cpp b/content/base/src/EventSource.cpp index e4ea6458bd9f..dff04f6583c4 100644 --- a/content/base/src/EventSource.cpp +++ b/content/base/src/EventSource.cpp @@ -12,7 +12,6 @@ #include "nsNetUtil.h" #include "nsMimeTypes.h" #include "nsDOMMessageEvent.h" -#include "nsIJSContextStack.h" #include "nsIPromptFactory.h" #include "nsIWindowWatcher.h" #include "nsPresContext.h" @@ -201,10 +200,8 @@ EventSource::Init(nsISupports* aOwner, mWithCredentials = aWithCredentials; BindToOwner(ownerWindow); - nsCOMPtr stack = - do_GetService("@mozilla.org/js/xpc/ContextStack;1"); - JSContext* cx = nullptr; - if (stack && NS_SUCCEEDED(stack->Peek(&cx)) && cx) { + // The conditional here is historical and not necessarily sane. + if (JSContext *cx = nsContentUtils::GetCurrentJSContext()) { const char *filename; if (nsJSUtils::GetCallingLocation(cx, &filename, &mScriptLine)) { mScriptFile.AssignASCII(filename); diff --git a/content/base/src/FragmentOrElement.cpp b/content/base/src/FragmentOrElement.cpp index 853f9c1fe822..ee55537c961e 100644 --- a/content/base/src/FragmentOrElement.cpp +++ b/content/base/src/FragmentOrElement.cpp @@ -72,7 +72,6 @@ #include "nsLayoutUtils.h" #include "nsGkAtoms.h" #include "nsContentUtils.h" -#include "nsIJSContextStack.h" #include "nsIDOMEventListener.h" #include "nsIWebNavigation.h" diff --git a/content/base/src/WebSocket.cpp b/content/base/src/WebSocket.cpp index 1552f8937b83..ae1f6362eaeb 100644 --- a/content/base/src/WebSocket.cpp +++ b/content/base/src/WebSocket.cpp @@ -32,7 +32,6 @@ #include "nsIDOMCloseEvent.h" #include "nsICryptoHash.h" #include "jsdbgapi.h" -#include "nsIJSContextStack.h" #include "nsJSUtils.h" #include "nsIScriptError.h" #include "nsNetUtil.h" diff --git a/content/base/src/nsDOMFileReader.cpp b/content/base/src/nsDOMFileReader.cpp index b0b70a8d70a1..f996a3cd7b4e 100644 --- a/content/base/src/nsDOMFileReader.cpp +++ b/content/base/src/nsDOMFileReader.cpp @@ -28,7 +28,6 @@ #include "nsStreamUtils.h" #include "nsXPCOM.h" #include "nsIDOMEventListener.h" -#include "nsIJSContextStack.h" #include "nsJSEnvironment.h" #include "nsIScriptGlobalObject.h" #include "nsCExternalHandlerService.h" diff --git a/content/base/src/nsDocument.cpp b/content/base/src/nsDocument.cpp index a29c733714f6..c51f31c5f6af 100644 --- a/content/base/src/nsDocument.cpp +++ b/content/base/src/nsDocument.cpp @@ -124,7 +124,6 @@ #include "nsDOMCID.h" #include "jsapi.h" -#include "nsIJSContextStack.h" #include "nsIXPConnect.h" #include "nsCycleCollector.h" #include "nsCCUncollectableMarker.h" diff --git a/content/base/src/nsFrameLoader.cpp b/content/base/src/nsFrameLoader.cpp index 855de66033e2..02d86bc7486f 100644 --- a/content/base/src/nsFrameLoader.cpp +++ b/content/base/src/nsFrameLoader.cpp @@ -34,7 +34,6 @@ #include "nsIBaseWindow.h" #include "nsContentUtils.h" #include "nsIXPConnect.h" -#include "nsIJSContextStack.h" #include "nsUnicharUtils.h" #include "nsIScriptGlobalObject.h" #include "nsIScriptSecurityManager.h" diff --git a/content/base/src/nsFrameMessageManager.cpp b/content/base/src/nsFrameMessageManager.cpp index e0f9f3143d42..45ae0fd9bf8d 100644 --- a/content/base/src/nsFrameMessageManager.cpp +++ b/content/base/src/nsFrameMessageManager.cpp @@ -19,7 +19,6 @@ #include "nsNetUtil.h" #include "nsScriptLoader.h" #include "nsFrameLoader.h" -#include "nsIJSContextStack.h" #include "nsIXULRuntime.h" #include "nsIScriptError.h" #include "nsIConsoleService.h" @@ -630,10 +629,10 @@ nsFrameMessageManager::ReceiveMessage(nsISupports* aTarget, InfallibleTArray* aJSONRetVal, JSContext* aContext) { - JSContext* ctx = mContext ? mContext : aContext; - if (!ctx) { - ctx = nsContentUtils::ThreadJSContextStack()->GetSafeJSContext(); - } + JSContext *cxToUse = mContext ? mContext + : (aContext ? aContext + : nsContentUtils::GetSafeJSContext()); + AutoPushJSContext ctx(cxToUse); if (mListeners.Length()) { nsCOMPtr name = do_GetAtom(aMessage); MMListenerRemover lr(this); @@ -976,17 +975,10 @@ void nsFrameScriptExecutor::Shutdown() { if (sCachedScripts) { - JSContext* cx = nsContentUtils::ThreadJSContextStack()->GetSafeJSContext(); - if (cx) { -#ifdef DEBUG_smaug - printf("Will clear cached frame manager scripts!\n"); -#endif - JSAutoRequest ar(cx); - NS_ASSERTION(sCachedScripts != nullptr, "Need cached scripts"); - sCachedScripts->Enumerate(CachedScriptUnrooter, cx); - } else { - NS_WARNING("No context available. Leaking cached scripts!\n"); - } + SafeAutoJSContext cx; + JSAutoRequest ar(cx); + NS_ASSERTION(sCachedScripts != nullptr, "Need cached scripts"); + sCachedScripts->Enumerate(CachedScriptUnrooter, cx); delete sCachedScripts; sCachedScripts = nullptr; diff --git a/content/base/src/nsINode.cpp b/content/base/src/nsINode.cpp index 08b9541889be..3c3f235dc1b6 100644 --- a/content/base/src/nsINode.cpp +++ b/content/base/src/nsINode.cpp @@ -62,7 +62,6 @@ #include "nsIEditor.h" #include "nsIEditorIMESupport.h" #include "nsIFrame.h" -#include "nsIJSContextStack.h" #include "nsILinkHandler.h" #include "nsINameSpaceManager.h" #include "nsINodeInfo.h" diff --git a/content/base/src/nsInProcessTabChildGlobal.cpp b/content/base/src/nsInProcessTabChildGlobal.cpp index f4ff2bd4f828..fd0f6c114498 100644 --- a/content/base/src/nsInProcessTabChildGlobal.cpp +++ b/content/base/src/nsInProcessTabChildGlobal.cpp @@ -15,7 +15,6 @@ #include "nsComponentManagerUtils.h" #include "nsNetUtil.h" #include "nsScriptLoader.h" -#include "nsIJSContextStack.h" #include "nsFrameLoader.h" #include "xpcpublic.h" #include "nsIMozBrowserFrame.h" diff --git a/content/base/src/nsObjectLoadingContent.cpp b/content/base/src/nsObjectLoadingContent.cpp index 4b4e76cc3f38..49d9b9c72265 100644 --- a/content/base/src/nsObjectLoadingContent.cpp +++ b/content/base/src/nsObjectLoadingContent.cpp @@ -24,7 +24,6 @@ #include "nsIPermissionManager.h" #include "nsPluginHost.h" #include "nsJSNPRuntime.h" -#include "nsIJSContextStack.h" #include "nsIPresShell.h" #include "nsIScriptGlobalObject.h" #include "nsIScriptSecurityManager.h" diff --git a/content/base/src/nsXMLHttpRequest.cpp b/content/base/src/nsXMLHttpRequest.cpp index e36112e9018e..6c8851f75992 100644 --- a/content/base/src/nsXMLHttpRequest.cpp +++ b/content/base/src/nsXMLHttpRequest.cpp @@ -26,7 +26,6 @@ #include "nsGUIEvent.h" #include "prprf.h" #include "nsIDOMEventListener.h" -#include "nsIJSContextStack.h" #include "nsIScriptSecurityManager.h" #include "nsWeakPtr.h" #include "nsIScriptGlobalObject.h" diff --git a/content/canvas/src/WebGLContextUtils.cpp b/content/canvas/src/WebGLContextUtils.cpp index 740522e92d91..89567e7f737b 100644 --- a/content/canvas/src/WebGLContextUtils.cpp +++ b/content/canvas/src/WebGLContextUtils.cpp @@ -9,7 +9,6 @@ #include "prprf.h" -#include "nsIJSContextStack.h" #include "jsapi.h" #include "nsIScriptSecurityManager.h" #include "nsServiceManagerUtils.h" @@ -46,15 +45,12 @@ WebGLContext::GenerateWarning(const char *fmt, va_list ap) // no need to print to stderr, as JS_ReportWarning takes care of this for us. - nsCOMPtr stack = do_GetService("@mozilla.org/js/xpc/ContextStack;1"); - JSContext* ccx = nullptr; - if (stack && NS_SUCCEEDED(stack->Peek(&ccx)) && ccx) { - JS_ReportWarning(ccx, "WebGL: %s", buf); - if (!ShouldGenerateWarnings()) { - JS_ReportWarning(ccx, - "WebGL: No further warnings will be reported for this WebGL context " - "(already reported %d warnings)", mAlreadyGeneratedWarnings); - } + AutoJSContext cx; + JS_ReportWarning(cx, "WebGL: %s", buf); + if (!ShouldGenerateWarnings()) { + JS_ReportWarning(cx, + "WebGL: No further warnings will be reported for this WebGL context " + "(already reported %d warnings)", mAlreadyGeneratedWarnings); } } diff --git a/content/events/src/nsDOMEventTargetHelper.cpp b/content/events/src/nsDOMEventTargetHelper.cpp index be677fa65ce2..d4356e447ea7 100644 --- a/content/events/src/nsDOMEventTargetHelper.cpp +++ b/content/events/src/nsDOMEventTargetHelper.cpp @@ -8,7 +8,6 @@ #include "nsEventDispatcher.h" #include "nsGUIEvent.h" #include "nsIDocument.h" -#include "nsIJSContextStack.h" #include "nsDOMJSUtils.h" #include "prprf.h" #include "nsGlobalWindow.h" diff --git a/content/events/src/nsEventListenerManager.cpp b/content/events/src/nsEventListenerManager.cpp index b7d08dabf762..969793d4b23c 100644 --- a/content/events/src/nsEventListenerManager.cpp +++ b/content/events/src/nsEventListenerManager.cpp @@ -32,7 +32,6 @@ #include "nsIServiceManager.h" #include "nsIScriptSecurityManager.h" #include "nsError.h" -#include "nsIJSContextStack.h" #include "nsIDocument.h" #include "nsIPresShell.h" #include "nsMutationEvent.h" diff --git a/content/events/src/nsEventListenerService.cpp b/content/events/src/nsEventListenerService.cpp index 22b9f706879d..4bfb9a15e50f 100644 --- a/content/events/src/nsEventListenerService.cpp +++ b/content/events/src/nsEventListenerService.cpp @@ -13,7 +13,6 @@ #include "nsIDOMWindow.h" #include "nsPIDOMWindow.h" #include "nsJSUtils.h" -#include "nsIJSContextStack.h" #include "nsGUIEvent.h" #include "nsEventDispatcher.h" #include "nsIJSEventListener.h" diff --git a/content/html/content/src/HTMLImageElement.cpp b/content/html/content/src/HTMLImageElement.cpp index 325b66be3497..848a2f9f3e1c 100644 --- a/content/html/content/src/HTMLImageElement.cpp +++ b/content/html/content/src/HTMLImageElement.cpp @@ -35,7 +35,6 @@ #include "nsRuleData.h" -#include "nsIJSContextStack.h" #include "nsIDOMHTMLMapElement.h" #include "nsEventDispatcher.h" diff --git a/content/html/document/src/nsHTMLDocument.cpp b/content/html/document/src/nsHTMLDocument.cpp index 2e37901d83ba..f37651a9628e 100644 --- a/content/html/document/src/nsHTMLDocument.cpp +++ b/content/html/document/src/nsHTMLDocument.cpp @@ -69,7 +69,6 @@ #include "nsIDocumentInlines.h" #include "nsIDocumentEncoder.h" //for outputting selection #include "nsICachingChannel.h" -#include "nsIJSContextStack.h" #include "nsIContentViewer.h" #include "nsIWyciwygChannel.h" #include "nsIScriptElement.h" @@ -3323,39 +3322,32 @@ nsHTMLDocument::DoClipboardSecurityCheck(bool aPaste) { nsresult rv = NS_ERROR_FAILURE; - nsCOMPtr stack = - do_GetService("@mozilla.org/js/xpc/ContextStack;1"); + JSContext *cx = nsContentUtils::GetCurrentJSContext(); + if (!cx) { + return NS_OK; + } + JSAutoRequest ar(cx); - if (stack) { - JSContext *cx = nullptr; - stack->Peek(&cx); - if (!cx) { - return NS_OK; + NS_NAMED_LITERAL_CSTRING(classNameStr, "Clipboard"); + + nsIScriptSecurityManager *secMan = nsContentUtils::GetSecurityManager(); + + if (aPaste) { + if (nsHTMLDocument::sPasteInternal_id == JSID_VOID) { + nsHTMLDocument::sPasteInternal_id = + INTERNED_STRING_TO_JSID(cx, ::JS_InternString(cx, "paste")); } - - JSAutoRequest ar(cx); - - NS_NAMED_LITERAL_CSTRING(classNameStr, "Clipboard"); - - nsIScriptSecurityManager *secMan = nsContentUtils::GetSecurityManager(); - - if (aPaste) { - if (nsHTMLDocument::sPasteInternal_id == JSID_VOID) { - nsHTMLDocument::sPasteInternal_id = - INTERNED_STRING_TO_JSID(cx, ::JS_InternString(cx, "paste")); - } - rv = secMan->CheckPropertyAccess(cx, nullptr, classNameStr.get(), - nsHTMLDocument::sPasteInternal_id, - nsIXPCSecurityManager::ACCESS_GET_PROPERTY); - } else { - if (nsHTMLDocument::sCutCopyInternal_id == JSID_VOID) { - nsHTMLDocument::sCutCopyInternal_id = - INTERNED_STRING_TO_JSID(cx, ::JS_InternString(cx, "cutcopy")); - } - rv = secMan->CheckPropertyAccess(cx, nullptr, classNameStr.get(), - nsHTMLDocument::sCutCopyInternal_id, - nsIXPCSecurityManager::ACCESS_GET_PROPERTY); + rv = secMan->CheckPropertyAccess(cx, nullptr, classNameStr.get(), + nsHTMLDocument::sPasteInternal_id, + nsIXPCSecurityManager::ACCESS_GET_PROPERTY); + } else { + if (nsHTMLDocument::sCutCopyInternal_id == JSID_VOID) { + nsHTMLDocument::sCutCopyInternal_id = + INTERNED_STRING_TO_JSID(cx, ::JS_InternString(cx, "cutcopy")); } + rv = secMan->CheckPropertyAccess(cx, nullptr, classNameStr.get(), + nsHTMLDocument::sCutCopyInternal_id, + nsIXPCSecurityManager::ACCESS_GET_PROPERTY); } return rv; } diff --git a/content/xml/document/src/XMLDocument.cpp b/content/xml/document/src/XMLDocument.cpp index 2dfc1328be14..f9232c38e9b6 100644 --- a/content/xml/document/src/XMLDocument.cpp +++ b/content/xml/document/src/XMLDocument.cpp @@ -42,7 +42,6 @@ #include "nsCRT.h" #include "nsIAuthPrompt.h" #include "nsIScriptGlobalObjectOwner.h" -#include "nsIJSContextStack.h" #include "nsContentCreatorFunctions.h" #include "nsContentPolicyUtils.h" #include "nsIDOMUserDataHandler.h"