mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1062077 - Hoist console logging duties into xpc::ErrorReport. r=bz
This commit is contained in:
parent
35d62e8c00
commit
25ec5c8219
@ -97,10 +97,6 @@ using namespace mozilla::dom;
|
|||||||
|
|
||||||
const size_t gStackSize = 8192;
|
const size_t gStackSize = 8192;
|
||||||
|
|
||||||
#ifdef PR_LOGGING
|
|
||||||
static PRLogModuleInfo* gJSDiagnostics;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Thank you Microsoft!
|
// Thank you Microsoft!
|
||||||
#ifdef CompareString
|
#ifdef CompareString
|
||||||
#undef CompareString
|
#undef CompareString
|
||||||
@ -352,45 +348,7 @@ NS_HandleScriptError(nsIScriptGlobalObject *aScriptGlobal,
|
|||||||
return called;
|
return called;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace mozilla {
|
class ScriptErrorEvent : public nsRunnable
|
||||||
namespace dom {
|
|
||||||
|
|
||||||
void
|
|
||||||
AsyncErrorReporter::ReportError()
|
|
||||||
{
|
|
||||||
nsCOMPtr<nsIScriptError> errorObject =
|
|
||||||
do_CreateInstance("@mozilla.org/scripterror;1");
|
|
||||||
if (!errorObject) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint64_t windowID = mReport->mWindow ? mReport->mWindow->WindowID() : 0;
|
|
||||||
nsresult rv = errorObject->InitWithWindowID(mReport->mErrorMsg,
|
|
||||||
mReport->mFileName,
|
|
||||||
mReport->mSourceLine,
|
|
||||||
mReport->mLineNumber,
|
|
||||||
mReport->mColumn,
|
|
||||||
mReport->mFlags,
|
|
||||||
mReport->Category(),
|
|
||||||
windowID);
|
|
||||||
if (NS_FAILED(rv)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
nsCOMPtr<nsIConsoleService> consoleService =
|
|
||||||
do_GetService(NS_CONSOLESERVICE_CONTRACTID);
|
|
||||||
if (!consoleService) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
consoleService->LogMessage(errorObject);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace dom
|
|
||||||
} // namespace mozilla
|
|
||||||
|
|
||||||
class ScriptErrorEvent : public AsyncErrorReporter
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ScriptErrorEvent(JSRuntime* aRuntime,
|
ScriptErrorEvent(JSRuntime* aRuntime,
|
||||||
@ -398,8 +356,7 @@ public:
|
|||||||
nsIPrincipal* aScriptOriginPrincipal,
|
nsIPrincipal* aScriptOriginPrincipal,
|
||||||
JS::Handle<JS::Value> aError,
|
JS::Handle<JS::Value> aError,
|
||||||
bool aDispatchEvent)
|
bool aDispatchEvent)
|
||||||
// Pass an empty category, then compute ours
|
: mReport(aReport)
|
||||||
: AsyncErrorReporter(aRuntime, aReport)
|
|
||||||
, mOriginPrincipal(aScriptOriginPrincipal)
|
, mOriginPrincipal(aScriptOriginPrincipal)
|
||||||
, mDispatchEvent(aDispatchEvent)
|
, mDispatchEvent(aDispatchEvent)
|
||||||
, mError(aRuntime, aError)
|
, mError(aRuntime, aError)
|
||||||
@ -464,13 +421,14 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (status != nsEventStatus_eConsumeNoDefault) {
|
if (status != nsEventStatus_eConsumeNoDefault) {
|
||||||
AsyncErrorReporter::ReportError();
|
mReport->LogToConsole();
|
||||||
}
|
}
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
nsRefPtr<xpc::ErrorReport> mReport;
|
||||||
nsCOMPtr<nsIPrincipal> mOriginPrincipal;
|
nsCOMPtr<nsIPrincipal> mOriginPrincipal;
|
||||||
bool mDispatchEvent;
|
bool mDispatchEvent;
|
||||||
JS::PersistentRootedValue mError;
|
JS::PersistentRootedValue mError;
|
||||||
@ -521,49 +479,6 @@ NS_ScriptErrorReporter(JSContext *cx,
|
|||||||
*/
|
*/
|
||||||
report->errorNumber != JSMSG_OUT_OF_MEMORY));
|
report->errorNumber != JSMSG_OUT_OF_MEMORY));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nsContentUtils::DOMWindowDumpEnabled()) {
|
|
||||||
// Print it to stderr as well, for the benefit of those invoking
|
|
||||||
// mozilla with -console.
|
|
||||||
nsAutoCString error;
|
|
||||||
error.AssignLiteral("JavaScript ");
|
|
||||||
if (JSREPORT_IS_STRICT(report->flags))
|
|
||||||
error.AppendLiteral("strict ");
|
|
||||||
if (JSREPORT_IS_WARNING(report->flags))
|
|
||||||
error.AppendLiteral("warning: ");
|
|
||||||
else
|
|
||||||
error.AppendLiteral("error: ");
|
|
||||||
error.Append(report->filename);
|
|
||||||
error.AppendLiteral(", line ");
|
|
||||||
error.AppendInt(report->lineno, 10);
|
|
||||||
error.AppendLiteral(": ");
|
|
||||||
if (report->ucmessage) {
|
|
||||||
AppendUTF16toUTF8(reinterpret_cast<const char16_t*>(report->ucmessage),
|
|
||||||
error);
|
|
||||||
} else {
|
|
||||||
error.Append(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
fprintf(stderr, "%s\n", error.get());
|
|
||||||
fflush(stderr);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef PR_LOGGING
|
|
||||||
if (!gJSDiagnostics)
|
|
||||||
gJSDiagnostics = PR_NewLogModule("JSDiagnostics");
|
|
||||||
|
|
||||||
if (gJSDiagnostics) {
|
|
||||||
PR_LOG(gJSDiagnostics,
|
|
||||||
JSREPORT_IS_WARNING(report->flags) ? PR_LOG_WARNING : PR_LOG_ERROR,
|
|
||||||
("file %s, line %u: %s\n%s%s",
|
|
||||||
report->filename, report->lineno, message,
|
|
||||||
report->linebuf ? report->linebuf : "",
|
|
||||||
(report->linebuf &&
|
|
||||||
report->linebuf[strlen(report->linebuf)-1] != '\n')
|
|
||||||
? "\n"
|
|
||||||
: ""));
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
@ -197,14 +197,11 @@ public:
|
|||||||
|
|
||||||
NS_IMETHOD Run()
|
NS_IMETHOD Run()
|
||||||
{
|
{
|
||||||
ReportError();
|
mReport->LogToConsole();
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Do the actual error reporting
|
|
||||||
void ReportError();
|
|
||||||
|
|
||||||
nsRefPtr<xpc::ErrorReport> mReport;
|
nsRefPtr<xpc::ErrorReport> mReport;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -297,6 +297,62 @@ xpc::ErrorReport::InitInternal(JSErrorReport *aReport,
|
|||||||
mFlags = aReport->flags;
|
mFlags = aReport->flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef PR_LOGGING
|
||||||
|
static PRLogModuleInfo* gJSDiagnostics;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void
|
||||||
|
xpc::ErrorReport::LogToConsole()
|
||||||
|
{
|
||||||
|
// Log to stdout.
|
||||||
|
if (nsContentUtils::DOMWindowDumpEnabled()) {
|
||||||
|
nsAutoCString error;
|
||||||
|
error.AssignLiteral("JavaScript ");
|
||||||
|
if (JSREPORT_IS_STRICT(mFlags))
|
||||||
|
error.AppendLiteral("strict ");
|
||||||
|
if (JSREPORT_IS_WARNING(mFlags))
|
||||||
|
error.AppendLiteral("warning: ");
|
||||||
|
else
|
||||||
|
error.AppendLiteral("error: ");
|
||||||
|
error.Append(NS_LossyConvertUTF16toASCII(mFileName));
|
||||||
|
error.AppendLiteral(", line ");
|
||||||
|
error.AppendInt(mLineNumber, 10);
|
||||||
|
error.AppendLiteral(": ");
|
||||||
|
error.Append(NS_LossyConvertUTF16toASCII(mErrorMsg));
|
||||||
|
|
||||||
|
fprintf(stderr, "%s\n", error.get());
|
||||||
|
fflush(stderr);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef PR_LOGGING
|
||||||
|
// Log to the PR Log Module.
|
||||||
|
if (!gJSDiagnostics)
|
||||||
|
gJSDiagnostics = PR_NewLogModule("JSDiagnostics");
|
||||||
|
if (gJSDiagnostics) {
|
||||||
|
PR_LOG(gJSDiagnostics,
|
||||||
|
JSREPORT_IS_WARNING(mFlags) ? PR_LOG_WARNING : PR_LOG_ERROR,
|
||||||
|
("file %s, line %u\n%s", NS_LossyConvertUTF16toASCII(mFileName).get(),
|
||||||
|
mLineNumber, NS_LossyConvertUTF16toASCII(mErrorMsg).get()));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Log to the console. We do this last so that we can simply return if
|
||||||
|
// there's no console service without affecting the other reporting
|
||||||
|
// mechanisms.
|
||||||
|
nsCOMPtr<nsIConsoleService> consoleService =
|
||||||
|
do_GetService(NS_CONSOLESERVICE_CONTRACTID);
|
||||||
|
nsCOMPtr<nsIScriptError> errorObject =
|
||||||
|
do_CreateInstance("@mozilla.org/scripterror;1");
|
||||||
|
NS_ENSURE_TRUE_VOID(consoleService && errorObject);
|
||||||
|
|
||||||
|
nsresult rv = errorObject->InitWithWindowID(mErrorMsg, mFileName, mSourceLine,
|
||||||
|
mLineNumber, mColumn, mFlags, Category(),
|
||||||
|
mWindow ? mWindow->WindowID() : 0);
|
||||||
|
NS_ENSURE_SUCCESS_VOID(rv);
|
||||||
|
consoleService->LogMessage(errorObject);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/***************************************************************************/
|
/***************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
@ -506,6 +506,8 @@ class ErrorReport {
|
|||||||
void InitOnWorkerThread(JSErrorReport *aReport, const char *aFallbackMessage,
|
void InitOnWorkerThread(JSErrorReport *aReport, const char *aFallbackMessage,
|
||||||
bool aIsChrome);
|
bool aIsChrome);
|
||||||
|
|
||||||
|
void LogToConsole();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void InitInternal(JSErrorReport *aReport, const char *aFallbackMessage);
|
void InitInternal(JSErrorReport *aReport, const char *aFallbackMessage);
|
||||||
bool mIsChrome;
|
bool mIsChrome;
|
||||||
|
Loading…
Reference in New Issue
Block a user