From abdbcef8795acdeb5de7dcc5ee2a9d01e94a0dab Mon Sep 17 00:00:00 2001 From: "bzbarsky%mit.edu" Date: Fri, 2 Mar 2007 01:05:46 +0000 Subject: [PATCH] Report chrome JS errors to the error console again. Bug 324142, r+sr=jst git-svn-id: svn://10.0.0.236/trunk@221190 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/dom/src/base/nsJSEnvironment.cpp | 52 +++++++++++++----------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/mozilla/dom/src/base/nsJSEnvironment.cpp b/mozilla/dom/src/base/nsJSEnvironment.cpp index c33d470527d..487339c5174 100644 --- a/mozilla/dom/src/base/nsJSEnvironment.cpp +++ b/mozilla/dom/src/base/nsJSEnvironment.cpp @@ -286,9 +286,9 @@ NS_ScriptErrorReporter(JSContext *cx, ::JS_ClearPendingException(cx); if (context) { - nsCOMPtr win(do_QueryInterface(context->GetGlobalObject())); + nsIScriptGlobalObject *globalObject = context->GetGlobalObject(); - if (win) { + if (globalObject) { nsAutoString fileName, msg; if (report) { @@ -313,31 +313,37 @@ NS_ScriptErrorReporter(JSContext *cx, * then we'd need to generate a new OOM event for that * new OOM instance -- this isn't pretty. */ - nsIDocShell *docShell = win->GetDocShell(); - if (docShell && - (!report || - (report->errorNumber != JSMSG_OUT_OF_MEMORY && - !JSREPORT_IS_WARNING(report->flags)))) { - static PRInt32 errorDepth; // Recursion prevention - ++errorDepth; + { + // Scope to make sure we're not using |win| in the rest of + // this function when we should be using |globalObject|. We + // only need |win| for the event dispatch. + nsCOMPtr win(do_QueryInterface(globalObject)); + nsIDocShell *docShell = win ? win->GetDocShell() : nsnull; + if (docShell && + (!report || + (report->errorNumber != JSMSG_OUT_OF_MEMORY && + !JSREPORT_IS_WARNING(report->flags)))) { + static PRInt32 errorDepth; // Recursion prevention + ++errorDepth; - nsCOMPtr presContext; - docShell->GetPresContext(getter_AddRefs(presContext)); + nsCOMPtr presContext; + docShell->GetPresContext(getter_AddRefs(presContext)); - if (presContext && errorDepth < 2) { - nsScriptErrorEvent errorevent(PR_TRUE, NS_LOAD_ERROR); + if (presContext && errorDepth < 2) { + nsScriptErrorEvent errorevent(PR_TRUE, NS_LOAD_ERROR); - errorevent.fileName = fileName.get(); - errorevent.errorMsg = msg.get(); - errorevent.lineNr = report ? report->lineno : 0; + errorevent.fileName = fileName.get(); + errorevent.errorMsg = msg.get(); + errorevent.lineNr = report ? report->lineno : 0; - // Dispatch() must be synchronous for the recursion block - // (errorDepth) to work. - nsEventDispatcher::Dispatch(win, presContext, &errorevent, nsnull, - &status); + // Dispatch() must be synchronous for the recursion block + // (errorDepth) to work. + nsEventDispatcher::Dispatch(win, presContext, &errorevent, nsnull, + &status); + } + + --errorDepth; } - - --errorDepth; } if (status != nsEventStatus_eConsumeNoDefault) { @@ -351,7 +357,7 @@ NS_ScriptErrorReporter(JSContext *cx, // Set category to chrome or content nsCOMPtr scriptPrincipal = - do_QueryInterface(win); + do_QueryInterface(globalObject); NS_ASSERTION(scriptPrincipal, "Global objects must implement " "nsIScriptObjectPrincipal"); nsCOMPtr systemPrincipal;