Bug 889911 - Introduce xpc::SystemErrorReporter, roughly based on mozJSComponentLoader's error reporter. r=mrbkap

This commit is contained in:
Bobby Holley 2013-07-15 11:44:49 -07:00
parent 91e7e344e1
commit 3b5f53a397
2 changed files with 60 additions and 0 deletions

View File

@ -222,8 +222,62 @@ nsXPConnect::IsISupportsDescendant(nsIInterfaceInfo* info)
return found;
}
NS_EXPORT_(void)
xpc::SystemErrorReporter(JSContext *cx, const char *message, JSErrorReport *rep)
{
// It would be nice to assert !JS_DescribeScriptedCaller here, to be sure
// that there isn't any script running that could catch the exception. But
// the JS engine invokes the error reporter directly if someone reports an
// ErrorReport that it doesn't know how to turn into an exception. Arguably
// it should just learn how to throw everything. But either way, if the
// exception is ending here, it's not going to get propagated to a caller,
// so it's up to us to make it known.
nsresult rv;
/* Use the console service to register the error. */
nsCOMPtr<nsIConsoleService> consoleService =
do_GetService(NS_CONSOLESERVICE_CONTRACTID);
/*
* Make an nsIScriptError, populate it with information from this
* error, then log it with the console service.
*/
nsCOMPtr<nsIScriptError> errorObject =
do_CreateInstance(NS_SCRIPTERROR_CONTRACTID);
if (consoleService && errorObject) {
uint32_t column = rep->uctokenptr - rep->uclinebuf;
const PRUnichar* ucmessage =
static_cast<const PRUnichar*>(rep->ucmessage);
const PRUnichar* uclinebuf =
static_cast<const PRUnichar*>(rep->uclinebuf);
rv = errorObject->Init(
ucmessage ? nsDependentString(ucmessage) : EmptyString(),
NS_ConvertASCIItoUTF16(rep->filename),
uclinebuf ? nsDependentString(uclinebuf) : EmptyString(),
rep->lineno, column, rep->flags,
"system javascript");
if (NS_SUCCEEDED(rv))
consoleService->LogMessage(errorObject);
}
/* Log to stderr in debug builds. */
#ifdef DEBUG
fprintf(stderr, "System JS : %s %s:%d\n"
" %s\n",
JSREPORT_IS_WARNING(rep->flags) ? "WARNING" : "ERROR",
rep->filename, rep->lineno,
message ? message : "<no message>");
#endif
}
/***************************************************************************/
nsresult
nsXPConnect::GetInfoForIID(const nsIID * aIID, nsIInterfaceInfo** info)
{

View File

@ -413,6 +413,12 @@ GetNativeForGlobal(JSObject *global);
*/
JSObject *
GetJunkScope();
// Error reporter used when there is no associated DOM window on to which to
// report errors and warnings.
NS_EXPORT_(void)
SystemErrorReporter(JSContext *cx, const char *message, JSErrorReport *rep);
} // namespace xpc
namespace mozilla {