зеркало из https://github.com/mozilla/gecko-dev.git
Bug 229437Report script errors to the console service ourselves when our script global object has no owner to report them to.Patch by Karsten D�sterloh <mnyromyr@tprac.de>r=caillon, sr=jst
This commit is contained in:
Родитель
f9882ae022
Коммит
70d68cfda0
|
@ -65,6 +65,7 @@
|
||||||
#include "nsIDocShell.h"
|
#include "nsIDocShell.h"
|
||||||
#include "nsIDocShellTreeItem.h"
|
#include "nsIDocShellTreeItem.h"
|
||||||
#include "nsIPresContext.h"
|
#include "nsIPresContext.h"
|
||||||
|
#include "nsIConsoleService.h"
|
||||||
#include "nsIScriptError.h"
|
#include "nsIScriptError.h"
|
||||||
#include "nsIInterfaceRequestor.h"
|
#include "nsIInterfaceRequestor.h"
|
||||||
#include "nsIInterfaceRequestorUtils.h"
|
#include "nsIInterfaceRequestorUtils.h"
|
||||||
|
@ -150,13 +151,6 @@ NS_ScriptErrorReporter(JSContext *cx,
|
||||||
context->GetGlobalObject(getter_AddRefs(globalObject));
|
context->GetGlobalObject(getter_AddRefs(globalObject));
|
||||||
|
|
||||||
if (globalObject) {
|
if (globalObject) {
|
||||||
nsCOMPtr<nsIScriptGlobalObjectOwner> owner;
|
|
||||||
if(NS_FAILED(globalObject->GetGlobalObjectOwner(getter_AddRefs(owner))) ||
|
|
||||||
!owner) {
|
|
||||||
NS_WARNING("Failed to get a global Object Owner");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
nsAutoString fileName, msg;
|
nsAutoString fileName, msg;
|
||||||
|
|
||||||
if (report) {
|
if (report) {
|
||||||
|
@ -174,40 +168,43 @@ NS_ScriptErrorReporter(JSContext *cx,
|
||||||
msg.AssignWithConversion(message);
|
msg.AssignWithConversion(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
//send error event first, then proceed
|
|
||||||
nsCOMPtr<nsIDocShell> docShell;
|
nsCOMPtr<nsIDocShell> docShell;
|
||||||
globalObject->GetDocShell(getter_AddRefs(docShell));
|
nsCOMPtr<nsIScriptGlobalObjectOwner> owner;
|
||||||
if (docShell && !JSREPORT_IS_WARNING(report->flags)) {
|
globalObject->GetGlobalObjectOwner(getter_AddRefs(owner));
|
||||||
static PRInt32 errorDepth; // Recursion prevention
|
if (owner) {
|
||||||
errorDepth++;
|
// First, notify the DOM that we have a script error.
|
||||||
|
globalObject->GetDocShell(getter_AddRefs(docShell));
|
||||||
|
if (docShell && !JSREPORT_IS_WARNING(report->flags)) {
|
||||||
|
static PRInt32 errorDepth; // Recursion prevention
|
||||||
|
++errorDepth;
|
||||||
|
|
||||||
nsCOMPtr<nsIPresContext> presContext;
|
nsCOMPtr<nsIPresContext> presContext;
|
||||||
docShell->GetPresContext(getter_AddRefs(presContext));
|
docShell->GetPresContext(getter_AddRefs(presContext));
|
||||||
|
|
||||||
if(presContext && errorDepth < 2) {
|
if (presContext && errorDepth < 2) {
|
||||||
nsScriptErrorEvent errorevent;
|
nsScriptErrorEvent errorevent;
|
||||||
errorevent.eventStructType = NS_EVENT;
|
errorevent.eventStructType = NS_EVENT;
|
||||||
errorevent.message = NS_SCRIPT_ERROR;
|
errorevent.message = NS_SCRIPT_ERROR;
|
||||||
|
|
||||||
errorevent.fileName = fileName.get();
|
errorevent.fileName = fileName.get();
|
||||||
errorevent.errorMsg = msg.get();
|
errorevent.errorMsg = msg.get();
|
||||||
errorevent.lineNr = report ? report->lineno : 0;
|
errorevent.lineNr = report ? report->lineno : 0;
|
||||||
|
|
||||||
// HandleDOMEvent() must be synchronous for the recursion block
|
// HandleDOMEvent() must be synchronous for the recursion block
|
||||||
// (errorDepth) to work.
|
// (errorDepth) to work.
|
||||||
globalObject->HandleDOMEvent(presContext, &errorevent, nsnull,
|
globalObject->HandleDOMEvent(presContext, &errorevent, nsnull,
|
||||||
NS_EVENT_FLAG_INIT, &status);
|
NS_EVENT_FLAG_INIT, &status);
|
||||||
|
}
|
||||||
|
|
||||||
|
--errorDepth;
|
||||||
}
|
}
|
||||||
|
|
||||||
errorDepth--;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (status != nsEventStatus_eConsumeNoDefault) {
|
if (status != nsEventStatus_eConsumeNoDefault) {
|
||||||
|
|
||||||
// Make an nsIScriptError and populate it with information from
|
// Make an nsIScriptError and populate it with information from
|
||||||
// this error.
|
// this error.
|
||||||
nsCOMPtr<nsIScriptError>
|
nsCOMPtr<nsIScriptError> errorObject =
|
||||||
errorObject(do_CreateInstance("@mozilla.org/scripterror;1"));
|
do_CreateInstance("@mozilla.org/scripterror;1");
|
||||||
|
|
||||||
if (errorObject != nsnull) {
|
if (errorObject != nsnull) {
|
||||||
nsresult rv;
|
nsresult rv;
|
||||||
|
@ -240,8 +237,19 @@ NS_ScriptErrorReporter(JSContext *cx,
|
||||||
category);
|
category);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NS_SUCCEEDED(rv))
|
if (NS_SUCCEEDED(rv)) {
|
||||||
owner->ReportScriptError(errorObject);
|
if (owner) {
|
||||||
|
owner->ReportScriptError(errorObject);
|
||||||
|
} else {
|
||||||
|
// We lack an owner to report this error to, so let's just
|
||||||
|
// report it to the console service so as to not lose it.
|
||||||
|
nsCOMPtr<nsIConsoleService> consoleService =
|
||||||
|
do_GetService(NS_CONSOLESERVICE_CONTRACTID, &rv);
|
||||||
|
if (NS_SUCCEEDED(rv)) {
|
||||||
|
consoleService->LogMessage(errorObject);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче