diff --git a/mozilla/caps/src/nsScriptSecurityManager.cpp b/mozilla/caps/src/nsScriptSecurityManager.cpp index cc5cabedcc2..7c0c056b8c8 100644 --- a/mozilla/caps/src/nsScriptSecurityManager.cpp +++ b/mozilla/caps/src/nsScriptSecurityManager.cpp @@ -1558,13 +1558,25 @@ nsScriptSecurityManager::CanExecuteScripts(JSContext* cx, //-- See if the current window allows JS execution nsIScriptContext *scriptContext = GetScriptContext(cx); if (!scriptContext) return NS_ERROR_FAILURE; - nsCOMPtr window = - do_QueryInterface(scriptContext->GetGlobalObject()); - if (!window) return NS_ERROR_FAILURE; + nsIScriptGlobalObject *sgo = scriptContext->GetGlobalObject(); + if (!sgo) { + return NS_ERROR_FAILURE; + } + + // window can be null here if we're running with a non-DOM window + // as the script global (i.e. a XUL prototype document). + nsCOMPtr window = do_QueryInterface(sgo); + nsCOMPtr docshell; nsresult rv; - nsCOMPtr docshell = window->GetDocShell(); - nsCOMPtr globalObjTreeItem = do_QueryInterface(docshell); + + if (window) { + docshell = window->GetDocShell(); + } + + nsCOMPtr globalObjTreeItem = + do_QueryInterface(docshell); + if (globalObjTreeItem) { nsCOMPtr treeItem(globalObjTreeItem);