diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp index 09bacb51dd92..e1a318d9741c 100644 --- a/dom/base/nsContentUtils.cpp +++ b/dom/base/nsContentUtils.cpp @@ -3477,7 +3477,8 @@ nsContentUtils::ReportToConsoleNonLocalized(const nsAString& aErrorText, nsIURI* aURI, const nsAFlatString& aSourceLine, uint32_t aLineNumber, - uint32_t aColumnNumber) + uint32_t aColumnNumber, + MissingErrorLocationMode aLocationMode) { uint64_t innerWindowID = 0; if (aDocument) { @@ -3494,14 +3495,15 @@ nsContentUtils::ReportToConsoleNonLocalized(const nsAString& aErrorText, } nsAutoCString spec; - if (!aLineNumber) { + if (!aLineNumber && aLocationMode == eUSE_CALLING_LOCATION) { JSContext *cx = GetCurrentJSContext(); if (cx) { nsJSUtils::GetCallingLocation(cx, spec, &aLineNumber, &aColumnNumber); } } - if (spec.IsEmpty() && aURI) + if (spec.IsEmpty() && aURI) { aURI->GetSpec(spec); + } nsCOMPtr errorObject = do_CreateInstance(NS_SCRIPTERROR_CONTRACTID, &rv); diff --git a/dom/base/nsContentUtils.h b/dom/base/nsContentUtils.h index 23251a5a57d0..949a79acf378 100644 --- a/dom/base/nsContentUtils.h +++ b/dom/base/nsContentUtils.h @@ -825,7 +825,15 @@ public: * @param [aColumnNumber=0] (Optional) Column number within resource containing error. If aURI is null, then aDocument->GetDocumentURI() is used. + * @param [aLocationMode] (Optional) Specifies the behavior if + error location information is omitted. */ + enum MissingErrorLocationMode { + // Don't show location information in the error console. + eOMIT_LOCATION, + // Get location information from the currently executing script. + eUSE_CALLING_LOCATION + }; static nsresult ReportToConsoleNonLocalized(const nsAString& aErrorText, uint32_t aErrorFlags, const nsACString& aCategory, @@ -834,7 +842,9 @@ public: const nsAFlatString& aSourceLine = EmptyString(), uint32_t aLineNumber = 0, - uint32_t aColumnNumber = 0); + uint32_t aColumnNumber = 0, + MissingErrorLocationMode aLocationMode + = eUSE_CALLING_LOCATION); /** * Report a localized error message to the error console. diff --git a/dom/workers/ServiceWorkerManager.cpp b/dom/workers/ServiceWorkerManager.cpp index 46410664539a..396a9052ddc4 100644 --- a/dom/workers/ServiceWorkerManager.cpp +++ b/dom/workers/ServiceWorkerManager.cpp @@ -2740,7 +2740,8 @@ ServiceWorkerManager::ReportToAllClients(const nsCString& aScope, uri, aLine, aLineNumber, - aColumnNumber); + aColumnNumber, + nsContentUtils::eOMIT_LOCATION); } // Report to any documents that have called .register() for this scope. They @@ -2772,7 +2773,8 @@ ServiceWorkerManager::ReportToAllClients(const nsCString& aScope, uri, aLine, aLineNumber, - aColumnNumber); + aColumnNumber, + nsContentUtils::eOMIT_LOCATION); } if (regList->IsEmpty()) { @@ -2843,7 +2845,8 @@ ServiceWorkerManager::ReportToAllClients(const nsCString& aScope, uri, aLine, aLineNumber, - aColumnNumber); + aColumnNumber, + nsContentUtils::eOMIT_LOCATION); return; } }