diff --git a/content/xbl/src/nsXBLBinding.cpp b/content/xbl/src/nsXBLBinding.cpp index 89a19d58364..760c6a107c8 100644 --- a/content/xbl/src/nsXBLBinding.cpp +++ b/content/xbl/src/nsXBLBinding.cpp @@ -1084,6 +1084,8 @@ nsXBLBinding::InstallProperties() rv = global->GetContext(getter_AddRefs(context)); if (NS_FAILED(rv)) return rv; + if (!context) return NS_OK; + // Init our class and insert it into the prototype chain. nsAutoString className; nsCAutoString classStr; @@ -1779,6 +1781,8 @@ nsXBLBinding::AddScriptEventListener(nsIContent* aElement, nsIAtom* aName, rv = global->GetContext(getter_AddRefs(context)); if (NS_FAILED(rv)) return rv; + if (!context) return NS_OK; + nsCOMPtr manager; rv = receiver->GetListenerManager(getter_AddRefs(manager)); if (NS_FAILED(rv)) return rv; diff --git a/content/xbl/src/nsXBLPrototypeHandler.cpp b/content/xbl/src/nsXBLPrototypeHandler.cpp index 7e6b3a1cf38..502c8a095ba 100644 --- a/content/xbl/src/nsXBLPrototypeHandler.cpp +++ b/content/xbl/src/nsXBLPrototypeHandler.cpp @@ -384,6 +384,7 @@ nsXBLPrototypeHandler::ExecuteHandler(nsIDOMEventReceiver* aReceiver, nsCOMPtr boundContext; boundGlobal->GetContext(getter_AddRefs(boundContext)); + if (!boundContext) return NS_OK; JSObject* scriptObject = nsnull; diff --git a/content/xul/content/src/nsXULElement.cpp b/content/xul/content/src/nsXULElement.cpp index a1d281e6012..cc10c9ef446 100644 --- a/content/xul/content/src/nsXULElement.cpp +++ b/content/xul/content/src/nsXULElement.cpp @@ -1857,6 +1857,8 @@ nsXULElement::AddScriptEventListener(nsIAtom* aName, rv = global->GetContext(getter_AddRefs(context)); if (NS_FAILED(rv)) return rv; + + if (!context) return NS_OK; } nsCOMPtr root; diff --git a/content/xul/content/src/nsXULPopupListener.cpp b/content/xul/content/src/nsXULPopupListener.cpp index 1f95ff8e880..30f6493c297 100644 --- a/content/xul/content/src/nsXULPopupListener.cpp +++ b/content/xul/content/src/nsXULPopupListener.cpp @@ -813,7 +813,7 @@ XULPopupListenerImpl::LaunchPopup(PRInt32 aClientX, PRInt32 aClientY) nsCOMPtr global; document->GetScriptGlobalObject(getter_AddRefs(global)); if (global) { - if (NS_OK == global->GetContext(getter_AddRefs(context))) { + if ((NS_OK == global->GetContext(getter_AddRefs(context))) && context) { // Get the DOM window nsCOMPtr domWindow = do_QueryInterface(global); if (domWindow != nsnull) { diff --git a/content/xul/document/src/nsXULDocument.cpp b/content/xul/document/src/nsXULDocument.cpp index 3d75f5521f0..55f9c683399 100644 --- a/content/xul/document/src/nsXULDocument.cpp +++ b/content/xul/document/src/nsXULDocument.cpp @@ -5173,6 +5173,8 @@ nsXULDocument::ExecuteScript(JSObject* aScriptObject) rv = mScriptGlobalObject->GetContext(getter_AddRefs(context)); if (NS_FAILED(rv)) return rv; + if (! context) return NS_ERROR_UNEXPECTED; + rv = context->ExecuteScript(aScriptObject, nsnull, nsnull, nsnull); return rv; } diff --git a/dom/src/jsurl/nsJSProtocolHandler.cpp b/dom/src/jsurl/nsJSProtocolHandler.cpp index 20152b72339..75b6073d199 100644 --- a/dom/src/jsurl/nsJSProtocolHandler.cpp +++ b/dom/src/jsurl/nsJSProtocolHandler.cpp @@ -155,6 +155,8 @@ nsresult nsJSThunk::EvaluateScript() if (NS_FAILED(rv)) return rv; + if (!scriptContext) return NS_ERROR_FAILURE; + // Get principal of code for execution nsCOMPtr owner; rv = mChannel->GetOwner(getter_AddRefs(owner)); diff --git a/modules/plugin/base/src/nsPluginInstancePeer.cpp b/modules/plugin/base/src/nsPluginInstancePeer.cpp index fd229e6edea..2f8c947ecb3 100644 --- a/modules/plugin/base/src/nsPluginInstancePeer.cpp +++ b/modules/plugin/base/src/nsPluginInstancePeer.cpp @@ -882,8 +882,10 @@ NS_IMETHODIMP nsPluginInstancePeerImpl::GetJSContext(JSContext* *outContext) nsCOMPtr context; if (global->GetContext(getter_AddRefs(context)) == NS_OK) { - *outContext = (JSContext*) context->GetNativeContext(); - rv = NS_OK; + if (context) { + *outContext = (JSContext*) context->GetNativeContext(); + rv = NS_OK; + } } } } diff --git a/modules/plugin/nglsrc/nsPluginInstancePeer.cpp b/modules/plugin/nglsrc/nsPluginInstancePeer.cpp index fd229e6edea..2f8c947ecb3 100644 --- a/modules/plugin/nglsrc/nsPluginInstancePeer.cpp +++ b/modules/plugin/nglsrc/nsPluginInstancePeer.cpp @@ -882,8 +882,10 @@ NS_IMETHODIMP nsPluginInstancePeerImpl::GetJSContext(JSContext* *outContext) nsCOMPtr context; if (global->GetContext(getter_AddRefs(context)) == NS_OK) { - *outContext = (JSContext*) context->GetNativeContext(); - rv = NS_OK; + if (context) { + *outContext = (JSContext*) context->GetNativeContext(); + rv = NS_OK; + } } } } diff --git a/webshell/tests/viewer/nsViewerApp.cpp b/webshell/tests/viewer/nsViewerApp.cpp index c26237b9633..9bcaf7f5aed 100644 --- a/webshell/tests/viewer/nsViewerApp.cpp +++ b/webshell/tests/viewer/nsViewerApp.cpp @@ -1593,7 +1593,7 @@ static void ShowConsole(nsBrowserWindow* aWindow) nsIScriptContext *context = nsnull; nsCOMPtr scriptGlobal(do_GetInterface(aWindow->mDocShell)); if (scriptGlobal) { - if (NS_OK == scriptGlobal->GetContext(&context)) { + if ((NS_OK == scriptGlobal->GetContext(&context)) && context) { // create the console gConsole = JSConsole::CreateConsole();