Bug 1454207 - Part 3: Introduces a new function |ValueToPrintableUtf8| so that we report ReferenceError with readable Unicode characters instead of unreadable Unicode escape sequences r=arai

MozReview-Commit-ID: HtAVxVg54IL

--HG--
extra : rebase_source : 2079f41bbd3723aa633bac58c1661444f5862985
This commit is contained in:
Zhang Junzhi 2018-04-15 13:18:03 +08:00
Родитель fc7e9397b8
Коммит 296650a6ea
3 изменённых файлов: 22 добавлений и 2 удалений

Просмотреть файл

@ -884,9 +884,9 @@ void
js::ReportIsNotDefined(JSContext* cx, HandleId id)
{
JSAutoByteString printable;
if (!ValueToPrintableLatin1(cx, IdToValue(id), &printable))
if (!ValueToPrintableUTF8(cx, IdToValue(id), &printable))
return;
JS_ReportErrorNumberLatin1(cx, GetErrorMessage, nullptr, JSMSG_NOT_DEFINED, printable.ptr());
JS_ReportErrorNumberUTF8(cx, GetErrorMessage, nullptr, JSMSG_NOT_DEFINED, printable.ptr());
}
void

Просмотреть файл

@ -1926,6 +1926,20 @@ js::ValueToPrintableLatin1(JSContext* cx, const Value& vArg, JSAutoByteString* b
return bytes->encodeLatin1(cx, str);
}
const char*
js::ValueToPrintableUTF8(JSContext* cx, const Value& vArg, JSAutoByteString* bytes, bool asSource)
{
RootedValue v(cx, vArg);
JSString* str;
if (asSource)
str = ValueToSource(cx, v);
else
str = ToString<CanGC>(cx, v);
if (!str)
return nullptr;
return bytes->encodeUtf8(cx, RootedString(cx, str));
}
template <AllowGC allowGC>
JSString*
js::ToStringSlow(JSContext* cx, typename MaybeRooted<Value, allowGC>::HandleType arg)

Просмотреть файл

@ -1598,6 +1598,12 @@ extern const char*
ValueToPrintableLatin1(JSContext* cx, const Value&, JSAutoByteString* bytes,
bool asSource = false);
/*
* Convert a value to a printable C string encoded in UTF-8.
*/
extern const char*
ValueToPrintableUTF8(JSContext* cx, const Value&, JSAutoByteString* bytes, bool asSource = false);
/*
* Convert a non-string value to a string, returning null after reporting an
* error, otherwise returning a new string reference.