diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp index 4b94e19153a5..282ca4acda00 100644 --- a/dom/base/nsContentUtils.cpp +++ b/dom/base/nsContentUtils.cpp @@ -10992,7 +10992,7 @@ template static Result ExtractExceptionValues(JSContext* aCx, JS::HandleObject aObj, - nsACString& aSourceSpecOut, + nsAString& aSourceSpecOut, uint32_t* aLineOut, uint32_t* aColumnOut, nsString& aMessageOut) @@ -11000,10 +11000,8 @@ ExtractExceptionValues(JSContext* aCx, RefPtr exn; MOZ_TRY((UnwrapObject(aObj, exn))); - nsAutoString filename; - exn->GetFilename(aCx, filename); - if (!filename.IsEmpty()) { - CopyUTF16toUTF8(filename, aSourceSpecOut); + exn->GetFilename(aCx, aSourceSpecOut); + if (!aSourceSpecOut.IsEmpty()) { *aLineOut = exn->LineNumber(aCx); *aColumnOut = exn->ColumnNumber(); } @@ -11024,6 +11022,19 @@ nsContentUtils::ExtractErrorValues(JSContext* aCx, uint32_t* aLineOut, uint32_t* aColumnOut, nsString& aMessageOut) +{ + nsAutoString sourceSpec; + ExtractErrorValues(aCx, aValue, sourceSpec, aLineOut, aColumnOut, aMessageOut); + CopyUTF16toUTF8(sourceSpec, aSourceSpecOut); +} + +/* static */ void +nsContentUtils::ExtractErrorValues(JSContext* aCx, + JS::Handle aValue, + nsAString& aSourceSpecOut, + uint32_t* aLineOut, + uint32_t* aColumnOut, + nsString& aMessageOut) { MOZ_ASSERT(aLineOut); MOZ_ASSERT(aColumnOut); @@ -11045,7 +11056,7 @@ nsContentUtils::ExtractErrorValues(JSContext* aCx, 0); // window ID if (!report->mFileName.IsEmpty()) { - CopyUTF16toUTF8(report->mFileName, aSourceSpecOut); + aSourceSpecOut = report->mFileName; *aLineOut = report->mLineNumber; *aColumnOut = report->mColumn; } diff --git a/dom/base/nsContentUtils.h b/dom/base/nsContentUtils.h index 83d3974d32a9..601e7c121f24 100644 --- a/dom/base/nsContentUtils.h +++ b/dom/base/nsContentUtils.h @@ -1134,6 +1134,14 @@ public: static bool PrefetchPreloadEnabled(nsIDocShell* aDocShell); + static void + ExtractErrorValues(JSContext* aCx, JS::Handle aValue, + nsAString& aSourceSpecOut, uint32_t *aLineOut, + uint32_t *aColumnOut, nsString& aMessageOut); + + // Variant on `ExtractErrorValues` with a `nsACString`. This + // method is provided for backwards compatibility. Prefer the + // faster method above for your code. static void ExtractErrorValues(JSContext* aCx, JS::Handle aValue, nsACString& aSourceSpecOut, uint32_t *aLineOut,