Bug 1409852 - nsContentUtils::ExtractErrorValues with nsAString;r=bz

nsContentUtils::ExtractErrorValues converts `aSourceSpecOut` from
UTF-16 to UTF-8, which is generally not what we want. This patch
introduces a new version of ExtractErrorValues that doesn't perform
the conversion. To keep the patch short and avoid rewriting existing
clients, the existing version of the function is left in place.

MozReview-Commit-ID: J2NQb5ZCfht

--HG--
extra : rebase_source : c2bec753280bf7a2ea92d350ff42c03a8fd808b4
This commit is contained in:
David Teller 2017-12-12 18:20:06 -06:00
parent 1dcea46201
commit 533c311f31
2 changed files with 25 additions and 6 deletions

View File

@ -10992,7 +10992,7 @@ template <prototypes::ID PrototypeID, class NativeType, typename T>
static Result<Ok, nsresult>
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<T> exn;
MOZ_TRY((UnwrapObject<PrototypeID, NativeType>(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<JS::Value> 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;
}

View File

@ -1134,6 +1134,14 @@ public:
static bool PrefetchPreloadEnabled(nsIDocShell* aDocShell);
static void
ExtractErrorValues(JSContext* aCx, JS::Handle<JS::Value> 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<JS::Value> aValue,
nsACString& aSourceSpecOut, uint32_t *aLineOut,