summaryrefslogtreecommitdiffstats
path: root/js/xpconnect/src/nsXPConnect.cpp
diff options
context:
space:
mode:
authorwolfbeast <mcwerewolf@wolfbeast.com>2019-11-10 11:39:27 +0100
committerwolfbeast <mcwerewolf@wolfbeast.com>2019-11-10 11:39:27 +0100
commit974a481d12bf430891725bd3662876358e57e11a (patch)
treecad011151456251fef2f1b8d02ef4b4e45fad61a /js/xpconnect/src/nsXPConnect.cpp
parent6bd66b1728eeddb058066edda740aaeb2ceaec23 (diff)
parent736d25cbec4541186ed46c935c117ce4d1c7f3bb (diff)
downloadUXP-974a481d12bf430891725bd3662876358e57e11a.tar
UXP-974a481d12bf430891725bd3662876358e57e11a.tar.gz
UXP-974a481d12bf430891725bd3662876358e57e11a.tar.lz
UXP-974a481d12bf430891725bd3662876358e57e11a.tar.xz
UXP-974a481d12bf430891725bd3662876358e57e11a.zip
Merge branch 'master' into js-modules
# Conflicts: # modules/libpref/init/all.js
Diffstat (limited to 'js/xpconnect/src/nsXPConnect.cpp')
-rw-r--r--js/xpconnect/src/nsXPConnect.cpp142
1 files changed, 113 insertions, 29 deletions
diff --git a/js/xpconnect/src/nsXPConnect.cpp b/js/xpconnect/src/nsXPConnect.cpp
index 0466175b1..0d1a6be0a 100644
--- a/js/xpconnect/src/nsXPConnect.cpp
+++ b/js/xpconnect/src/nsXPConnect.cpp
@@ -33,7 +33,9 @@
#include "nsIObjectOutputStream.h"
#include "nsScriptSecurityManager.h"
#include "nsIPermissionManager.h"
+#include "nsIScriptError.h"
#include "nsContentUtils.h"
+#include "nsScriptError.h"
#include "jsfriendapi.h"
using namespace mozilla;
@@ -170,9 +172,31 @@ nsXPConnect::IsISupportsDescendant(nsIInterfaceInfo* info)
}
void
+xpc::ErrorBase::Init(JSErrorBase* aReport)
+{
+ if (!aReport->filename) {
+ mFileName.SetIsVoid(true);
+ } else {
+ mFileName.AssignWithConversion(aReport->filename);
+ }
+
+ mLineNumber = aReport->lineno;
+ mColumn = aReport->column;
+}
+
+void
+xpc::ErrorNote::Init(JSErrorNotes::Note* aNote)
+{
+ xpc::ErrorBase::Init(aNote);
+
+ ErrorNoteToMessageString(aNote, mErrorMsg);
+}
+
+void
xpc::ErrorReport::Init(JSErrorReport* aReport, const char* aToStringResult,
bool aIsChrome, uint64_t aWindowID)
{
+ xpc::ErrorBase::Init(aReport);
mCategory = aIsChrome ? NS_LITERAL_CSTRING("chrome javascript")
: NS_LITERAL_CSTRING("content javascript");
mWindowID = aWindowID;
@@ -182,12 +206,6 @@ xpc::ErrorReport::Init(JSErrorReport* aReport, const char* aToStringResult,
AppendUTF8toUTF16(aToStringResult, mErrorMsg);
}
- if (!aReport->filename) {
- mFileName.SetIsVoid(true);
- } else {
- mFileName.AssignWithConversion(aReport->filename);
- }
-
mSourceLine.Assign(aReport->linebuf(), aReport->linebufLength());
const JSErrorFormatString* efs = js::GetErrorMessage(nullptr, aReport->errorNumber);
@@ -197,10 +215,20 @@ xpc::ErrorReport::Init(JSErrorReport* aReport, const char* aToStringResult,
mErrorMsgName.AssignASCII(efs->name);
}
- mLineNumber = aReport->lineno;
- mColumn = aReport->column;
mFlags = aReport->flags;
mIsMuted = aReport->isMuted;
+
+ if (aReport->notes) {
+ if (!mNotes.SetLength(aReport->notes->length(), fallible)) {
+ return;
+ }
+
+ size_t i = 0;
+ for (auto&& note : *aReport->notes) {
+ mNotes.ElementAt(i).Init(note.get());
+ i++;
+ }
+ }
}
void
@@ -226,6 +254,59 @@ xpc::ErrorReport::Init(JSContext* aCx, mozilla::dom::Exception* aException,
static LazyLogModule gJSDiagnostics("JSDiagnostics");
void
+xpc::ErrorBase::AppendErrorDetailsTo(nsCString& error)
+{
+ error.Append(NS_LossyConvertUTF16toASCII(mFileName));
+ error.AppendLiteral(", line ");
+ error.AppendInt(mLineNumber, 10);
+ error.AppendLiteral(": ");
+ error.Append(NS_LossyConvertUTF16toASCII(mErrorMsg));
+}
+
+void
+xpc::ErrorNote::LogToStderr()
+{
+ if (!nsContentUtils::DOMWindowDumpEnabled()) {
+ return;
+ }
+
+ nsAutoCString error;
+ error.AssignLiteral("JavaScript note: ");
+ AppendErrorDetailsTo(error);
+
+ fprintf(stderr, "%s\n", error.get());
+ fflush(stderr);
+}
+
+void
+xpc::ErrorReport::LogToStderr()
+{
+ if (!nsContentUtils::DOMWindowDumpEnabled()) {
+ return;
+ }
+
+ 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: ");
+ }
+ AppendErrorDetailsTo(error);
+
+ fprintf(stderr, "%s\n", error.get());
+ fflush(stderr);
+
+ for (size_t i = 0, len = mNotes.Length(); i < len; i++) {
+ ErrorNote& note = mNotes[i];
+ note.LogToStderr();
+ }
+}
+
+void
xpc::ErrorReport::LogToConsole()
{
LogToConsoleWithStack(nullptr);
@@ -233,25 +314,7 @@ xpc::ErrorReport::LogToConsole()
void
xpc::ErrorReport::LogToConsoleWithStack(JS::HandleObject aStack)
{
- // 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);
- }
+ LogToStderr();
MOZ_LOG(gJSDiagnostics,
JSREPORT_IS_WARNING(mFlags) ? LogLevel::Warning : LogLevel::Error,
@@ -263,8 +326,9 @@ xpc::ErrorReport::LogToConsoleWithStack(JS::HandleObject aStack)
// mechanisms.
nsCOMPtr<nsIConsoleService> consoleService =
do_GetService(NS_CONSOLESERVICE_CONTRACTID);
+ NS_ENSURE_TRUE_VOID(consoleService);
- nsCOMPtr<nsIScriptError> errorObject;
+ RefPtr<nsScriptErrorBase> errorObject;
if (mWindowID && aStack) {
// Only set stack on messages related to a document
// As we cache messages in the console service,
@@ -275,18 +339,38 @@ xpc::ErrorReport::LogToConsoleWithStack(JS::HandleObject aStack)
errorObject = new nsScriptError();
}
errorObject->SetErrorMessageName(mErrorMsgName);
- NS_ENSURE_TRUE_VOID(consoleService);
nsresult rv = errorObject->InitWithWindowID(mErrorMsg, mFileName, mSourceLine,
mLineNumber, mColumn, mFlags,
mCategory, mWindowID);
NS_ENSURE_SUCCESS_VOID(rv);
+
+ for (size_t i = 0, len = mNotes.Length(); i < len; i++) {
+ ErrorNote& note = mNotes[i];
+
+ nsScriptErrorNote* noteObject = new nsScriptErrorNote();
+ noteObject->Init(note.mErrorMsg, note.mFileName,
+ note.mLineNumber, note.mColumn);
+ errorObject->AddNote(noteObject);
+ }
+
consoleService->LogMessage(errorObject);
}
/* static */
void
+xpc::ErrorNote::ErrorNoteToMessageString(JSErrorNotes::Note* aNote,
+ nsAString& aString)
+{
+ aString.Truncate();
+ if (aNote->message()) {
+ aString.Append(NS_ConvertUTF8toUTF16(aNote->message().c_str()));
+ }
+}
+
+/* static */
+void
xpc::ErrorReport::ErrorReportToMessageString(JSErrorReport* aReport,
nsAString& aString)
{