Bug 1247089 - Add an overload for `ReportToConsoleNonLocalized` that doesn't use `GetCallingLocation`. r?bkelly
`PushService.jsm` omits the script name and line number when reporting
decryption failures. This causes `ReportToConsoleNonLocalized` to query
the current JS context for location info. With e10s disabled, the
reported error links to `PushService.jsm` instead of `<unknown>`.
MozReview-Commit-ID: E5EGXsMqO
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -3476,46 +3476,75 @@ nsContentUtils::ReportToConsoleNonLocali
uint32_t aErrorFlags,
const nsACString& aCategory,
const nsIDocument* aDocument,
nsIURI* aURI,
const nsAFlatString& aSourceLine,
uint32_t aLineNumber,
uint32_t aColumnNumber)
{
- uint64_t innerWindowID = 0;
- if (aDocument) {
- if (!aURI) {
- aURI = aDocument->GetDocumentURI();
- }
- innerWindowID = aDocument->InnerWindowID();
- }
-
- nsresult rv;
- if (!sConsoleService) { // only need to bother null-checking here
- rv = CallGetService(NS_CONSOLESERVICE_CONTRACTID, &sConsoleService);
- NS_ENSURE_SUCCESS(rv, rv);
- }
-
nsAutoCString spec;
if (!aLineNumber) {
JSContext *cx = GetCurrentJSContext();
if (cx) {
nsJSUtils::GetCallingLocation(cx, spec, &aLineNumber, &aColumnNumber);
}
}
if (spec.IsEmpty() && aURI)
aURI->GetSpec(spec);
+ return ReportToConsoleNonLocalized(aErrorText,
+ aErrorFlags,
+ aCategory,
+ aDocument,
+ NS_ConvertUTF8toUTF16(spec), // file name
+ aSourceLine,
+ aLineNumber,
+ aColumnNumber);
+}
+
+/* static */ nsresult
+nsContentUtils::ReportToConsoleNonLocalized(const nsAString& aErrorText,
+ uint32_t aErrorFlags,
+ const nsACString& aCategory,
+ const nsIDocument* aDocument,
+ const nsAString& aSpec,
+ const nsAFlatString& aSourceLine,
+ uint32_t aLineNumber,
+ uint32_t aColumnNumber)
+{
+ nsAutoString fileName;
+ uint64_t innerWindowID = 0;
+ if (aDocument) {
+ if (aSpec.IsEmpty()) {
+ nsCOMPtr<nsIURI> uri = aDocument->GetDocumentURI();
+ if (uri) {
+ nsAutoCString spec;
+ uri->GetSpec(spec);
+ fileName = NS_ConvertUTF8toUTF16(spec);
+ }
+ }
+ innerWindowID = aDocument->InnerWindowID();
+ }
+ if (fileName.IsEmpty()) {
+ fileName = aSpec;
+ }
+
+ nsresult rv;
+ if (!sConsoleService) { // only need to bother null-checking here
+ rv = CallGetService(NS_CONSOLESERVICE_CONTRACTID, &sConsoleService);
+ NS_ENSURE_SUCCESS(rv, rv);
+ }
+
nsCOMPtr<nsIScriptError> errorObject =
do_CreateInstance(NS_SCRIPTERROR_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
rv = errorObject->InitWithWindowID(aErrorText,
- NS_ConvertUTF8toUTF16(spec), // file name
+ fileName,
aSourceLine,
aLineNumber, aColumnNumber,
aErrorFlags, aCategory,
innerWindowID);
NS_ENSURE_SUCCESS(rv, rv);
return sConsoleService->LogMessage(errorObject);
}
--- a/dom/base/nsContentUtils.h
+++ b/dom/base/nsContentUtils.h
@@ -840,16 +840,30 @@ public:
const nsIDocument* aDocument,
nsIURI* aURI = nullptr,
const nsAFlatString& aSourceLine
= EmptyString(),
uint32_t aLineNumber = 0,
uint32_t aColumnNumber = 0);
/**
+ * Report a non-localized error message. This overload does not use location
+ * information from the current JS context if |aLineNumber| is omitted.
+ */
+ static nsresult ReportToConsoleNonLocalized(const nsAString& aErrorText,
+ uint32_t aErrorFlags,
+ const nsACString& aCategory,
+ const nsIDocument* aDocument,
+ const nsAString& aSpec,
+ const nsAFlatString& aSourceLine
+ = EmptyString(),
+ uint32_t aLineNumber = 0,
+ uint32_t aColumnNumber = 0);
+
+ /**
* Report a localized error message to the error console.
* @param aErrorFlags See nsIScriptError.
* @param aCategory Name of module reporting error.
* @param aDocument Reference to the document which triggered the message.
* @param aFile Properties file containing localized message.
* @param aMessageName Name of localized message.
* @param [aParams=nullptr] (Optional) Parameters to be substituted into
localized message.
--- a/dom/workers/ServiceWorkerManager.cpp
+++ b/dom/workers/ServiceWorkerManager.cpp
@@ -2632,22 +2632,17 @@ void
ServiceWorkerManager::ReportToAllClients(const nsCString& aScope,
const nsString& aMessage,
const nsString& aFilename,
const nsString& aLine,
uint32_t aLineNumber,
uint32_t aColumnNumber,
uint32_t aFlags)
{
- nsCOMPtr<nsIURI> uri;
- nsresult rv = NS_NewURI(getter_AddRefs(uri), aFilename);
- if (NS_WARN_IF(NS_FAILED(rv))) {
- return;
- }
-
+ nsresult rv;
AutoTArray<uint64_t, 16> windows;
// Report errors to every controlled document.
for (auto iter = mControlledDocuments.Iter(); !iter.Done(); iter.Next()) {
ServiceWorkerRegistrationInfo* reg = iter.UserData();
MOZ_ASSERT(reg);
if (!reg->mScope.Equals(aScope)) {
continue;
@@ -2659,17 +2654,17 @@ ServiceWorkerManager::ReportToAllClients
}
windows.AppendElement(doc->InnerWindowID());
nsContentUtils::ReportToConsoleNonLocalized(aMessage,
aFlags,
NS_LITERAL_CSTRING("Service Workers"),
doc,
- uri,
+ aFilename,
aLine,
aLineNumber,
aColumnNumber);
}
// Report to any documents that have called .register() for this scope. They
// may not be controlled, but will still want to see error reports.
WeakDocumentList* regList = mRegisteringDocuments.Get(aScope);
@@ -2691,17 +2686,17 @@ ServiceWorkerManager::ReportToAllClients
}
windows.AppendElement(innerWindowId);
nsContentUtils::ReportToConsoleNonLocalized(aMessage,
aFlags,
NS_LITERAL_CSTRING("Service Workers"),
doc,
- uri,
+ aFilename,
aLine,
aLineNumber,
aColumnNumber);
}
if (regList->IsEmpty()) {
regList = nullptr;
nsAutoPtr<WeakDocumentList> doomed;
@@ -2762,17 +2757,17 @@ ServiceWorkerManager::ReportToAllClients
// If there are no documents to report to, at least report something to the
// browser console.
if (windows.IsEmpty()) {
nsContentUtils::ReportToConsoleNonLocalized(aMessage,
aFlags,
NS_LITERAL_CSTRING("Service Workers"),
nullptr, // document
- uri,
+ aFilename,
aLine,
aLineNumber,
aColumnNumber);
return;
}
}
void