summaryrefslogtreecommitdiffstats
path: root/dom/bindings/nsScriptError.cpp
diff options
context:
space:
mode:
authorGaming4JC <g4jc@hyperbola.info>2019-06-16 10:21:27 -0400
committerGaming4JC <g4jc@hyperbola.info>2019-07-18 22:38:33 -0400
commit332c1c28ac6fdb66b6dc4ea6732d98be8d87749b (patch)
tree247953c3abb7a4034646f1858e6657a3be144554 /dom/bindings/nsScriptError.cpp
parent4a82fdad87107d369df20da0a4a0987b1bd821fd (diff)
downloadUXP-332c1c28ac6fdb66b6dc4ea6732d98be8d87749b.tar
UXP-332c1c28ac6fdb66b6dc4ea6732d98be8d87749b.tar.gz
UXP-332c1c28ac6fdb66b6dc4ea6732d98be8d87749b.tar.lz
UXP-332c1c28ac6fdb66b6dc4ea6732d98be8d87749b.tar.xz
UXP-332c1c28ac6fdb66b6dc4ea6732d98be8d87749b.zip
1283712 - Part 7: Add nsIScriptErrorNote and nsIScriptError.notes.
Diffstat (limited to 'dom/bindings/nsScriptError.cpp')
-rw-r--r--dom/bindings/nsScriptError.cpp177
1 files changed, 135 insertions, 42 deletions
diff --git a/dom/bindings/nsScriptError.cpp b/dom/bindings/nsScriptError.cpp
index 686b0f7fc..9248d1a31 100644
--- a/dom/bindings/nsScriptError.cpp
+++ b/dom/bindings/nsScriptError.cpp
@@ -17,6 +17,7 @@
#include "nsPIDOMWindow.h"
#include "nsILoadContext.h"
#include "nsIDocShell.h"
+#include "nsIMutableArray.h"
#include "nsIScriptError.h"
#include "nsISensitiveInfoHiddenURI.h"
@@ -47,6 +48,12 @@ nsScriptErrorBase::nsScriptErrorBase()
nsScriptErrorBase::~nsScriptErrorBase() {}
void
+nsScriptErrorBase::AddNote(nsIScriptErrorNote* note)
+{
+ mNotes.AppendObject(note);
+}
+
+void
nsScriptErrorBase::InitializeOnMainThread()
{
MOZ_ASSERT(NS_IsMainThread());
@@ -189,6 +196,28 @@ nsScriptErrorBase::Init(const nsAString& message,
0);
}
+static void
+AssignSourceNameHelper(nsString& aSourceNameDest, const nsAString& aSourceNameSrc)
+{
+ if (aSourceNameSrc.IsEmpty())
+ return;
+
+ aSourceNameDest.Assign(aSourceNameSrc);
+
+ nsCOMPtr<nsIURI> uri;
+ nsAutoCString pass;
+ if (NS_SUCCEEDED(NS_NewURI(getter_AddRefs(uri), aSourceNameSrc)) &&
+ NS_SUCCEEDED(uri->GetPassword(pass)) &&
+ !pass.IsEmpty())
+ {
+ nsCOMPtr<nsISensitiveInfoHiddenURI> safeUri = do_QueryInterface(uri);
+
+ nsAutoCString loc;
+ if (safeUri && NS_SUCCEEDED(safeUri->GetSensitiveInfoHiddenSpec(loc)))
+ aSourceNameDest.Assign(NS_ConvertUTF8toUTF16(loc));
+ }
+}
+
NS_IMETHODIMP
nsScriptErrorBase::InitWithWindowID(const nsAString& message,
const nsAString& sourceName,
@@ -200,26 +229,7 @@ nsScriptErrorBase::InitWithWindowID(const nsAString& message,
uint64_t aInnerWindowID)
{
mMessage.Assign(message);
-
- if (!sourceName.IsEmpty()) {
- mSourceName.Assign(sourceName);
-
- nsCOMPtr<nsIURI> uri;
- nsAutoCString pass;
- if (NS_SUCCEEDED(NS_NewURI(getter_AddRefs(uri), sourceName)) &&
- NS_SUCCEEDED(uri->GetPassword(pass)) &&
- !pass.IsEmpty()) {
- nsCOMPtr<nsISensitiveInfoHiddenURI> safeUri =
- do_QueryInterface(uri);
-
- nsAutoCString loc;
- if (safeUri &&
- NS_SUCCEEDED(safeUri->GetSensitiveInfoHiddenSpec(loc))) {
- mSourceName.Assign(NS_ConvertUTF8toUTF16(loc));
- }
- }
- }
-
+ AssignSourceNameHelper(mSourceName, sourceName);
mLineNumber = lineNumber;
mSourceLine.Assign(sourceLine);
mColumnNumber = columnNumber;
@@ -235,8 +245,11 @@ nsScriptErrorBase::InitWithWindowID(const nsAString& message,
return NS_OK;
}
-NS_IMETHODIMP
-nsScriptErrorBase::ToString(nsACString& /*UTF8*/ aResult)
+static nsresult
+ToStringHelper(const char* aSeverity, const nsString& aMessage,
+ const nsString& aSourceName, const nsString* aSourceLine,
+ uint32_t aLineNumber, uint32_t aColumnNumber,
+ nsACString& /*UTF8*/ aResult)
{
static const char format0[] =
"[%s: \"%s\" {file: \"%s\" line: %d column: %d source: \"%s\"}]";
@@ -245,43 +258,39 @@ nsScriptErrorBase::ToString(nsACString& /*UTF8*/ aResult)
static const char format2[] =
"[%s: \"%s\"]";
- static const char error[] = "JavaScript Error";
- static const char warning[] = "JavaScript Warning";
-
- const char* severity = !(mFlags & JSREPORT_WARNING) ? error : warning;
-
char* temp;
char* tempMessage = nullptr;
char* tempSourceName = nullptr;
char* tempSourceLine = nullptr;
- if (!mMessage.IsEmpty())
- tempMessage = ToNewUTF8String(mMessage);
- if (!mSourceName.IsEmpty())
+ if (!aMessage.IsEmpty())
+ tempMessage = ToNewUTF8String(aMessage);
+ if (!aSourceName.IsEmpty())
// Use at most 512 characters from mSourceName.
- tempSourceName = ToNewUTF8String(StringHead(mSourceName, 512));
- if (!mSourceLine.IsEmpty())
+ tempSourceName = ToNewUTF8String(StringHead(aSourceName, 512));
+ if (aSourceLine && !aSourceLine->IsEmpty())
// Use at most 512 characters from mSourceLine.
- tempSourceLine = ToNewUTF8String(StringHead(mSourceLine, 512));
+ tempSourceLine = ToNewUTF8String(StringHead(*aSourceLine, 512));
- if (nullptr != tempSourceName && nullptr != tempSourceLine)
+ if (nullptr != tempSourceName && nullptr != tempSourceLine) {
temp = JS_smprintf(format0,
- severity,
+ aSeverity,
tempMessage,
tempSourceName,
- mLineNumber,
- mColumnNumber,
+ aLineNumber,
+ aColumnNumber,
tempSourceLine);
- else if (!mSourceName.IsEmpty())
+ } else if (!aSourceName.IsEmpty()) {
temp = JS_smprintf(format1,
- severity,
+ aSeverity,
tempMessage,
tempSourceName,
- mLineNumber);
- else
+ aLineNumber);
+ } else {
temp = JS_smprintf(format2,
- severity,
+ aSeverity,
tempMessage);
+ }
if (nullptr != tempMessage)
free(tempMessage);
@@ -299,6 +308,18 @@ nsScriptErrorBase::ToString(nsACString& /*UTF8*/ aResult)
}
NS_IMETHODIMP
+nsScriptErrorBase::ToString(nsACString& /*UTF8*/ aResult)
+{
+ static const char error[] = "JavaScript Error";
+ static const char warning[] = "JavaScript Warning";
+
+ const char* severity = !(mFlags & JSREPORT_WARNING) ? error : warning;
+
+ return ToStringHelper(severity, mMessage, mSourceName, &mSourceLine,
+ mLineNumber, mColumnNumber, aResult);
+}
+
+NS_IMETHODIMP
nsScriptErrorBase::GetOuterWindowID(uint64_t* aOuterWindowID)
{
NS_WARNING_ASSERTION(NS_IsMainThread() || mInitializedOnMainThread,
@@ -342,4 +363,76 @@ nsScriptErrorBase::GetIsFromPrivateWindow(bool* aIsFromPrivateWindow)
return NS_OK;
}
+NS_IMETHODIMP
+nsScriptErrorBase::GetNotes(nsIArray** aNotes)
+{
+ nsresult rv = NS_OK;
+ nsCOMPtr<nsIMutableArray> array =
+ do_CreateInstance(NS_ARRAY_CONTRACTID, &rv);
+ NS_ENSURE_SUCCESS(rv, rv);
+
+ uint32_t len = mNotes.Length();
+ for (uint32_t i = 0; i < len; i++)
+ array->AppendElement(mNotes[i], false);
+ array.forget(aNotes);
+
+ return NS_OK;
+}
+
NS_IMPL_ISUPPORTS(nsScriptError, nsIConsoleMessage, nsIScriptError)
+
+nsScriptErrorNote::nsScriptErrorNote()
+ : mMessage(),
+ mSourceName(),
+ mLineNumber(0),
+ mColumnNumber(0)
+{
+}
+
+nsScriptErrorNote::~nsScriptErrorNote() {}
+
+void
+nsScriptErrorNote::Init(const nsAString& message,
+ const nsAString& sourceName,
+ uint32_t lineNumber,
+ uint32_t columnNumber)
+{
+ mMessage.Assign(message);
+ AssignSourceNameHelper(mSourceName, sourceName);
+ mLineNumber = lineNumber;
+ mColumnNumber = columnNumber;
+}
+
+// nsIScriptErrorNote methods
+NS_IMETHODIMP
+nsScriptErrorNote::GetErrorMessage(nsAString& aResult) {
+ aResult.Assign(mMessage);
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+nsScriptErrorNote::GetSourceName(nsAString& aResult) {
+ aResult.Assign(mSourceName);
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+nsScriptErrorNote::GetLineNumber(uint32_t* result) {
+ *result = mLineNumber;
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+nsScriptErrorNote::GetColumnNumber(uint32_t* result) {
+ *result = mColumnNumber;
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+nsScriptErrorNote::ToString(nsACString& /*UTF8*/ aResult)
+{
+ return ToStringHelper("JavaScript Note", mMessage, mSourceName, nullptr,
+ mLineNumber, mColumnNumber, aResult);
+}
+
+NS_IMPL_ISUPPORTS(nsScriptErrorNote, nsIScriptErrorNote)