Backed out changeset 13c976344b69 (bug 1557254) for causing bug 1558836 and bug 1558852 a=backout

--HG--
extra : histedit_source : 62d780cd7c039cde0eb18472a3edf9c51aa20270
This commit is contained in:
Andreea Pavel 2019-06-12 20:27:00 +03:00
Родитель fe1531cfc1
Коммит 8552bec485
1 изменённых файлов: 15 добавлений и 46 удалений

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

@ -408,38 +408,31 @@ bool XPCConvert::NativeData2JS(JSContext* cx, MutableHandleValue d,
/***************************************************************************/
#ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
#ifdef DEBUG
static bool CheckChar16InCharRange(char16_t c) {
if (ILLEGAL_RANGE(c)) {
/* U+0080/U+0100 - U+FFFF data lost. */
MOZ_CRASH("char16_t out of char range; high bits of data lost");
static const size_t MSG_BUF_SIZE = 64;
char msg[MSG_BUF_SIZE];
snprintf(msg, MSG_BUF_SIZE,
"char16_t out of char range; high bits of data lost: 0x%x",
int(c));
NS_WARNING(msg);
return false;
}
return true;
}
# ifdef STRICT_CHECK_OF_UNICODE
template <typename CharT>
static void CheckCharsInCharRange(const CharT* chars, size_t len) {
if (!IsASCII(MakeSpan(chars, len))) {
MOZ_CRASH("char16_t out of char range; high bits of data lost");
for (size_t i = 0; i < len; i++) {
if (!CheckChar16InCharRange(chars[i])) {
break;
}
}
}
static void CheckCharsInCharRange(const unsigned char* chars, size_t len) {
return CheckCharsInCharRange(reinterpret_cast<const char*>(chars), len);
}
# else // STRICT_CHECK_OF_UNICODE
static void CheckCharsInCharRange(const char* chars, size_t len) = delete;
static void CheckCharsInCharRange(const char16_t* chars, size_t len) {
if (!IsUTF16Latin1(MakeSpan(chars, len))) {
MOZ_CRASH("char16_t out of char range; high bits of data lost");
}
}
# endif // STRICT_CHECK_OF_UNICODE
#endif // MOZ_DIAGNOSTIC_ASSERT_ENABLED
#endif
template <typename T>
bool ConvertToPrimitive(JSContext* cx, HandleValue v, T* retval) {
@ -498,7 +491,7 @@ bool XPCConvert::JSData2Native(JSContext* cx, void* d, HandleValue s,
return false;
}
}
#ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
#ifdef DEBUG
CheckChar16InCharRange(ch);
#endif
*((char*)d) = char(ch);
@ -607,9 +600,8 @@ bool XPCConvert::JSData2Native(JSContext* cx, void* d, HandleValue s,
return false;
}
#ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
#ifdef DEBUG
if (JS_StringHasLatin1Chars(str)) {
# ifdef STRICT_CHECK_OF_UNICODE
size_t len;
AutoCheckCannotGC nogc;
const Latin1Char* chars =
@ -617,7 +609,6 @@ bool XPCConvert::JSData2Native(JSContext* cx, void* d, HandleValue s,
if (chars) {
CheckCharsInCharRange(chars, len);
}
# endif // STRICT_CHECK_OF_UNICODE
} else {
size_t len;
AutoCheckCannotGC nogc;
@ -627,7 +618,7 @@ bool XPCConvert::JSData2Native(JSContext* cx, void* d, HandleValue s,
CheckCharsInCharRange(chars, len);
}
}
#endif // MOZ_DIAGNOSTIC_ASSERT_ENABLED
#endif // DEBUG
size_t length = JS_GetStringEncodingLength(cx, str);
if (length == size_t(-1)) {
@ -742,28 +733,6 @@ bool XPCConvert::JSData2Native(JSContext* cx, void* d, HandleValue s,
return false;
}
#ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
if (JS_StringHasLatin1Chars(str)) {
# ifdef STRICT_CHECK_OF_UNICODE
size_t len;
AutoCheckCannotGC nogc;
const Latin1Char* chars =
JS_GetLatin1StringCharsAndLength(cx, nogc, str, &len);
if (chars) {
CheckCharsInCharRange(chars, len);
}
# endif // STRICT_CHECK_OF_UNICODE
} else {
size_t len;
AutoCheckCannotGC nogc;
const char16_t* chars =
JS_GetTwoByteStringCharsAndLength(cx, nogc, str, &len);
if (chars) {
CheckCharsInCharRange(chars, len);
}
}
#endif // MOZ_DIAGNOSTIC_ASSERT_ENABLED
size_t length = JS_GetStringEncodingLength(cx, str);
if (length == size_t(-1)) {
return false;