Commit 2b14a3f7 authored by Mathias Bynens's avatar Mathias Bynens Committed by Commit Bot

Avoid octal escape sequences

Hexadecimal escape sequences of the form `\xNN` are more readable
in the context of byte values, and are preferred per Google’s C++
style guide.

https://google.github.io/styleguide/cppguide.html#Non-ASCII_Characters

BUG=v8:7109

Change-Id: I6821ccb804388d99e5601e92fc392afdf496691e
Reviewed-on: https://chromium-review.googlesource.com/803057Reviewed-by: 's avatarMarja Hölttä <marja@chromium.org>
Commit-Queue: Mathias Bynens <mathias@chromium.org>
Cr-Commit-Position: refs/heads/master@{#49799}
parent 96e181f9
......@@ -400,7 +400,7 @@ char* itoa_r(intptr_t i, char* buf, size_t sz, int base, size_t padding) {
if (n > sz) return nullptr;
if (base < 2 || base > 16) {
buf[0] = '\000';
buf[0] = '\0';
return nullptr;
}
......@@ -415,7 +415,7 @@ char* itoa_r(intptr_t i, char* buf, size_t sz, int base, size_t padding) {
// Make sure we can write the '-' character.
if (++n > sz) {
buf[0] = '\000';
buf[0] = '\0';
return nullptr;
}
*start++ = '-';
......@@ -427,7 +427,7 @@ char* itoa_r(intptr_t i, char* buf, size_t sz, int base, size_t padding) {
do {
// Make sure there is still enough space left in our output buffer.
if (++n > sz) {
buf[0] = '\000';
buf[0] = '\0';
return nullptr;
}
......@@ -439,7 +439,7 @@ char* itoa_r(intptr_t i, char* buf, size_t sz, int base, size_t padding) {
} while (j > 0 || padding > 0);
// Terminate the output with a NUL character.
*ptr = '\000';
*ptr = '\0';
// Conversion to ASCII actually resulted in the digits being in reverse
// order. We can't easily generate them in forward order, as we can't tell
......
......@@ -47,39 +47,39 @@ const char* const JsonStringifier::JsonEscapeTable =
"p\0 q\0 r\0 s\0 "
"t\0 u\0 v\0 w\0 "
"x\0 y\0 z\0 {\0 "
"|\0 }\0 ~\0 \177\0 "
"\200\0 \201\0 \202\0 \203\0 "
"\204\0 \205\0 \206\0 \207\0 "
"\210\0 \211\0 \212\0 \213\0 "
"\214\0 \215\0 \216\0 \217\0 "
"\220\0 \221\0 \222\0 \223\0 "
"\224\0 \225\0 \226\0 \227\0 "
"\230\0 \231\0 \232\0 \233\0 "
"\234\0 \235\0 \236\0 \237\0 "
"\240\0 \241\0 \242\0 \243\0 "
"\244\0 \245\0 \246\0 \247\0 "
"\250\0 \251\0 \252\0 \253\0 "
"\254\0 \255\0 \256\0 \257\0 "
"\260\0 \261\0 \262\0 \263\0 "
"\264\0 \265\0 \266\0 \267\0 "
"\270\0 \271\0 \272\0 \273\0 "
"\274\0 \275\0 \276\0 \277\0 "
"\300\0 \301\0 \302\0 \303\0 "
"\304\0 \305\0 \306\0 \307\0 "
"\310\0 \311\0 \312\0 \313\0 "
"\314\0 \315\0 \316\0 \317\0 "
"\320\0 \321\0 \322\0 \323\0 "
"\324\0 \325\0 \326\0 \327\0 "
"\330\0 \331\0 \332\0 \333\0 "
"\334\0 \335\0 \336\0 \337\0 "
"\340\0 \341\0 \342\0 \343\0 "
"\344\0 \345\0 \346\0 \347\0 "
"\350\0 \351\0 \352\0 \353\0 "
"\354\0 \355\0 \356\0 \357\0 "
"\360\0 \361\0 \362\0 \363\0 "
"\364\0 \365\0 \366\0 \367\0 "
"\370\0 \371\0 \372\0 \373\0 "
"\374\0 \375\0 \376\0 \377\0 ";
"|\0 }\0 ~\0 \x7F\0 "
"\x80\0 \x81\0 \x82\0 \x83\0 "
"\x84\0 \x85\0 \x86\0 \x87\0 "
"\x88\0 \x89\0 \x8A\0 \x8B\0 "
"\x8C\0 \x8D\0 \x8E\0 \x8F\0 "
"\x90\0 \x91\0 \x92\0 \x93\0 "
"\x94\0 \x95\0 \x96\0 \x97\0 "
"\x98\0 \x99\0 \x9A\0 \x9B\0 "
"\x9C\0 \x9D\0 \x9E\0 \x9F\0 "
"\xA0\0 \xA1\0 \xA2\0 \xA3\0 "
"\xA4\0 \xA5\0 \xA6\0 \xA7\0 "
"\xA8\0 \xA9\0 \xAA\0 \xAB\0 "
"\xAC\0 \xAD\0 \xAE\0 \xAF\0 "
"\xB0\0 \xB1\0 \xB2\0 \xB3\0 "
"\xB4\0 \xB5\0 \xB6\0 \xB7\0 "
"\xB8\0 \xB9\0 \xBA\0 \xBB\0 "
"\xBC\0 \xBD\0 \xBE\0 \xBF\0 "
"\xC0\0 \xC1\0 \xC2\0 \xC3\0 "
"\xC4\0 \xC5\0 \xC6\0 \xC7\0 "
"\xC8\0 \xC9\0 \xCA\0 \xCB\0 "
"\xCC\0 \xCD\0 \xCE\0 \xCF\0 "
"\xD0\0 \xD1\0 \xD2\0 \xD3\0 "
"\xD4\0 \xD5\0 \xD6\0 \xD7\0 "
"\xD8\0 \xD9\0 \xDA\0 \xDB\0 "
"\xDC\0 \xDD\0 \xDE\0 \xDF\0 "
"\xE0\0 \xE1\0 \xE2\0 \xE3\0 "
"\xE4\0 \xE5\0 \xE6\0 \xE7\0 "
"\xE8\0 \xE9\0 \xEA\0 \xEB\0 "
"\xEC\0 \xED\0 \xEE\0 \xEF\0 "
"\xF0\0 \xF1\0 \xF2\0 \xF3\0 "
"\xF4\0 \xF5\0 \xF6\0 \xF7\0 "
"\xF8\0 \xF9\0 \xFA\0 \xFB\0 "
"\xFC\0 \xFD\0 \xFE\0 \xFF\0 ";
JsonStringifier::JsonStringifier(Isolate* isolate)
: isolate_(isolate), builder_(isolate), gap_(nullptr), indent_(0) {
......
......@@ -43,7 +43,7 @@ void EscapeAndAppendString(const char* value, std::string* result) {
*result += "\\\\";
break;
default:
if (c < '\040') {
if (c < '\x20') {
base::OS::SNPrintF(
number_buffer, arraysize(number_buffer), "\\u%04X",
static_cast<unsigned>(static_cast<unsigned char>(c)));
......
......@@ -7916,13 +7916,13 @@ THREADED_TEST(StringWrite) {
v8::HandleScope scope(context->GetIsolate());
v8::Local<String> str = v8_str("abcde");
// abc<Icelandic eth><Unicode snowman>.
v8::Local<String> str2 = v8_str("abc\303\260\342\230\203");
v8::Local<String> str2 = v8_str("abc\xC3\xB0\xE2\x98\x83");
v8::Local<String> str3 =
v8::String::NewFromUtf8(context->GetIsolate(), "abc\0def",
v8::NewStringType::kNormal, 7)
.ToLocalChecked();
// "ab" + lead surrogate + "cd" + trail surrogate + "ef"
uint16_t orphans[8] = { 0x61, 0x62, 0xd800, 0x63, 0x64, 0xdc00, 0x65, 0x66 };
// "ab" + lead surrogate + "wx" + trail surrogate + "yz"
uint16_t orphans[8] = {0x61, 0x62, 0xd800, 0x77, 0x78, 0xdc00, 0x79, 0x7A};
v8::Local<String> orphans_str =
v8::String::NewFromTwoByte(context->GetIsolate(), orphans,
v8::NewStringType::kNormal, 8)
......@@ -7978,58 +7978,58 @@ THREADED_TEST(StringWrite) {
len = str2->WriteUtf8(utf8buf, sizeof(utf8buf), &charlen);
CHECK_EQ(9, len);
CHECK_EQ(5, charlen);
CHECK_EQ(0, strcmp(utf8buf, "abc\303\260\342\230\203"));
CHECK_EQ(0, strcmp(utf8buf, "abc\xC3\xB0\xE2\x98\x83"));
memset(utf8buf, 0x1, 1000);
len = str2->WriteUtf8(utf8buf, 8, &charlen);
CHECK_EQ(8, len);
CHECK_EQ(5, charlen);
CHECK_EQ(0, strncmp(utf8buf, "abc\303\260\342\230\203\1", 9));
CHECK_EQ(0, strncmp(utf8buf, "abc\xC3\xB0\xE2\x98\x83\x01", 9));
memset(utf8buf, 0x1, 1000);
len = str2->WriteUtf8(utf8buf, 7, &charlen);
CHECK_EQ(5, len);
CHECK_EQ(4, charlen);
CHECK_EQ(0, strncmp(utf8buf, "abc\303\260\1", 5));
CHECK_EQ(0, strncmp(utf8buf, "abc\xC3\xB0\x01", 5));
memset(utf8buf, 0x1, 1000);
len = str2->WriteUtf8(utf8buf, 6, &charlen);
CHECK_EQ(5, len);
CHECK_EQ(4, charlen);
CHECK_EQ(0, strncmp(utf8buf, "abc\303\260\1", 5));
CHECK_EQ(0, strncmp(utf8buf, "abc\xC3\xB0\x01", 5));
memset(utf8buf, 0x1, 1000);
len = str2->WriteUtf8(utf8buf, 5, &charlen);
CHECK_EQ(5, len);
CHECK_EQ(4, charlen);
CHECK_EQ(0, strncmp(utf8buf, "abc\303\260\1", 5));
CHECK_EQ(0, strncmp(utf8buf, "abc\xC3\xB0\x01", 5));
memset(utf8buf, 0x1, 1000);
len = str2->WriteUtf8(utf8buf, 4, &charlen);
CHECK_EQ(3, len);
CHECK_EQ(3, charlen);
CHECK_EQ(0, strncmp(utf8buf, "abc\1", 4));
CHECK_EQ(0, strncmp(utf8buf, "abc\x01", 4));
memset(utf8buf, 0x1, 1000);
len = str2->WriteUtf8(utf8buf, 3, &charlen);
CHECK_EQ(3, len);
CHECK_EQ(3, charlen);
CHECK_EQ(0, strncmp(utf8buf, "abc\1", 4));
CHECK_EQ(0, strncmp(utf8buf, "abc\x01", 4));
memset(utf8buf, 0x1, 1000);
len = str2->WriteUtf8(utf8buf, 2, &charlen);
CHECK_EQ(2, len);
CHECK_EQ(2, charlen);
CHECK_EQ(0, strncmp(utf8buf, "ab\1", 3));
CHECK_EQ(0, strncmp(utf8buf, "ab\x01", 3));
// allow orphan surrogates by default
memset(utf8buf, 0x1, 1000);
len = orphans_str->WriteUtf8(utf8buf, sizeof(utf8buf), &charlen);
CHECK_EQ(13, len);
CHECK_EQ(8, charlen);
CHECK_EQ(0, strcmp(utf8buf, "ab\355\240\200cd\355\260\200ef"));
CHECK_EQ(0, strcmp(utf8buf, "ab\xED\xA0\x80wx\xED\xB0\x80yz"));
// replace orphan surrogates with unicode replacement character
// replace orphan surrogates with Unicode replacement character
memset(utf8buf, 0x1, 1000);
len = orphans_str->WriteUtf8(utf8buf,
sizeof(utf8buf),
......@@ -8037,9 +8037,9 @@ THREADED_TEST(StringWrite) {
String::REPLACE_INVALID_UTF8);
CHECK_EQ(13, len);
CHECK_EQ(8, charlen);
CHECK_EQ(0, strcmp(utf8buf, "ab\357\277\275cd\357\277\275ef"));
CHECK_EQ(0, strcmp(utf8buf, "ab\xEF\xBF\xBDwx\xEF\xBF\xBDyz"));
// replace single lead surrogate with unicode replacement character
// replace single lead surrogate with Unicode replacement character
memset(utf8buf, 0x1, 1000);
len = lead_str->WriteUtf8(utf8buf,
sizeof(utf8buf),
......@@ -8047,9 +8047,9 @@ THREADED_TEST(StringWrite) {
String::REPLACE_INVALID_UTF8);
CHECK_EQ(4, len);
CHECK_EQ(1, charlen);
CHECK_EQ(0, strcmp(utf8buf, "\357\277\275"));
CHECK_EQ(0, strcmp(utf8buf, "\xEF\xBF\xBD"));
// replace single trail surrogate with unicode replacement character
// replace single trail surrogate with Unicode replacement character
memset(utf8buf, 0x1, 1000);
len = trail_str->WriteUtf8(utf8buf,
sizeof(utf8buf),
......@@ -8057,7 +8057,7 @@ THREADED_TEST(StringWrite) {
String::REPLACE_INVALID_UTF8);
CHECK_EQ(4, len);
CHECK_EQ(1, charlen);
CHECK_EQ(0, strcmp(utf8buf, "\357\277\275"));
CHECK_EQ(0, strcmp(utf8buf, "\xEF\xBF\xBD"));
// do not replace / write anything if surrogate pair does not fit the buffer
// space
......@@ -8110,7 +8110,7 @@ THREADED_TEST(StringWrite) {
CHECK_EQ(4, len);
len = str->Write(wbuf, 0, 4);
CHECK_EQ(4, len);
CHECK_EQ(0, strncmp("abcd\1", buf, 5));
CHECK_EQ(0, strncmp("abcd\x01", buf, 5));
uint16_t answer2[] = {'a', 'b', 'c', 'd', 0x101};
CHECK_EQ(0, StrNCmp16(answer2, wbuf, 5));
......@@ -8120,7 +8120,7 @@ THREADED_TEST(StringWrite) {
CHECK_EQ(5, len);
len = str->Write(wbuf, 0, 5);
CHECK_EQ(5, len);
CHECK_EQ(0, strncmp("abcde\1", buf, 6));
CHECK_EQ(0, strncmp("abcde\x01", buf, 6));
uint16_t answer3[] = {'a', 'b', 'c', 'd', 'e', 0x101};
CHECK_EQ(0, StrNCmp16(answer3, wbuf, 6));
......@@ -8159,7 +8159,7 @@ THREADED_TEST(StringWrite) {
CHECK_EQ(1, len);
len = str->Write(wbuf, 4, 1);
CHECK_EQ(1, len);
CHECK_EQ(0, strncmp("e\1", buf, 2));
CHECK_EQ(0, strncmp("e\x01", buf, 2));
uint16_t answer6[] = {'e', 0x101};
CHECK_EQ(0, StrNCmp16(answer6, wbuf, 2));
......@@ -8169,7 +8169,7 @@ THREADED_TEST(StringWrite) {
CHECK_EQ(1, len);
len = str->Write(wbuf, 3, 1);
CHECK_EQ(1, len);
CHECK_EQ(0, strncmp("d\1", buf, 2));
CHECK_EQ(0, strncmp("d\x01", buf, 2));
uint16_t answer7[] = {'d', 0x101};
CHECK_EQ(0, StrNCmp16(answer7, wbuf, 2));
......@@ -8205,10 +8205,10 @@ THREADED_TEST(StringWrite) {
CHECK_EQ(8, len);
CHECK_EQ('X', utf8buf[8]);
CHECK_EQ(5, charlen);
CHECK_EQ(0, strncmp(utf8buf, "abc\303\260\342\230\203", 8));
CHECK_NE(0, strcmp(utf8buf, "abc\303\260\342\230\203"));
CHECK_EQ(0, strncmp(utf8buf, "abc\xC3\xB0\xE2\x98\x83", 8));
CHECK_NE(0, strcmp(utf8buf, "abc\xC3\xB0\xE2\x98\x83"));
utf8buf[8] = '\0';
CHECK_EQ(0, strcmp(utf8buf, "abc\303\260\342\230\203"));
CHECK_EQ(0, strcmp(utf8buf, "abc\xC3\xB0\xE2\x98\x83"));
memset(utf8buf, 0x1, sizeof(utf8buf));
utf8buf[5] = 'X';
......@@ -8387,11 +8387,11 @@ THREADED_TEST(Utf16Symbol) {
CompileRun(
"var sym0 = 'benedictus';"
"var sym0b = 'S\303\270ren';"
"var sym1 = '\355\240\201\355\260\207';"
"var sym2 = '\360\220\220\210';"
"var sym3 = 'x\355\240\201\355\260\207';"
"var sym4 = 'x\360\220\220\210';"
"var sym0b = 'S\xC3\xB8ren';"
"var sym1 = '\xED\xA0\x81\xED\xB0\x87';"
"var sym2 = '\xF0\x90\x90\x88';"
"var sym3 = 'x\xED\xA0\x81\xED\xB0\x87';"
"var sym4 = 'x\xF0\x90\x90\x88';"
"if (sym1.length != 2) throw sym1;"
"if (sym1.charCodeAt(1) != 0xdc07) throw sym1.charCodeAt(1);"
"if (sym2.length != 2) throw sym2;"
......@@ -8405,23 +8405,23 @@ THREADED_TEST(Utf16Symbol) {
v8::NewStringType::kInternalized)
.ToLocalChecked();
Local<String> sym0b =
v8::String::NewFromUtf8(context->GetIsolate(), "S\303\270ren",
v8::String::NewFromUtf8(context->GetIsolate(), "S\xC3\xB8ren",
v8::NewStringType::kInternalized)
.ToLocalChecked();
Local<String> sym1 =
v8::String::NewFromUtf8(context->GetIsolate(), "\355\240\201\355\260\207",
v8::String::NewFromUtf8(context->GetIsolate(), "\xED\xA0\x81\xED\xB0\x87",
v8::NewStringType::kInternalized)
.ToLocalChecked();
Local<String> sym2 =
v8::String::NewFromUtf8(context->GetIsolate(), "\360\220\220\210",
v8::String::NewFromUtf8(context->GetIsolate(), "\xF0\x90\x90\x88",
v8::NewStringType::kInternalized)
.ToLocalChecked();
Local<String> sym3 = v8::String::NewFromUtf8(context->GetIsolate(),
"x\355\240\201\355\260\207",
"x\xED\xA0\x81\xED\xB0\x87",
v8::NewStringType::kInternalized)
.ToLocalChecked();
Local<String> sym4 =
v8::String::NewFromUtf8(context->GetIsolate(), "x\360\220\220\210",
v8::String::NewFromUtf8(context->GetIsolate(), "x\xF0\x90\x90\x88",
v8::NewStringType::kInternalized)
.ToLocalChecked();
v8::Local<v8::Object> global = context->Global();
......
......@@ -1078,110 +1078,110 @@ TEST(ScopePositions) {
// Check that 6-byte and 4-byte encodings of UTF-8 strings do not throw
// the preparser off in terms of byte offsets.
// 2 surrogates, encode a character that doesn't need a surrogate.
{" 'foo\355\240\201\355\260\211';\n"
{" 'foo\xED\xA0\x81\xED\xB0\x89';\n"
" (function fun",
"(a,b) { infunction; }", ")();", i::FUNCTION_SCOPE,
i::LanguageMode::kSloppy},
// 4 byte encoding.
{" 'foo\360\220\220\212';\n"
// 4-byte encoding.
{" 'foo\xF0\x90\x90\x8A';\n"
" (function fun",
"(a,b) { infunction; }", ")();", i::FUNCTION_SCOPE,
i::LanguageMode::kSloppy},
// 3 byte encoding of \u0fff.
{" 'foo\340\277\277';\n"
// 3-byte encoding of \u0FFF.
{" 'foo\xE0\xBF\xBF';\n"
" (function fun",
"(a,b) { infunction; }", ")();", i::FUNCTION_SCOPE,
i::LanguageMode::kSloppy},
// 3 byte surrogate, followed by broken 2-byte surrogate w/ impossible 2nd
// 3-byte surrogate, followed by broken 2-byte surrogate w/ impossible 2nd
// byte and last byte missing.
{" 'foo\355\240\201\355\211';\n"
{" 'foo\xED\xA0\x81\xED\x89';\n"
" (function fun",
"(a,b) { infunction; }", ")();", i::FUNCTION_SCOPE,
i::LanguageMode::kSloppy},
// Broken 3 byte encoding of \u0fff with missing last byte.
{" 'foo\340\277';\n"
// Broken 3-byte encoding of \u0FFF with missing last byte.
{" 'foo\xE0\xBF';\n"
" (function fun",
"(a,b) { infunction; }", ")();", i::FUNCTION_SCOPE,
i::LanguageMode::kSloppy},
// Broken 3 byte encoding of \u0fff with missing 2 last bytes.
{" 'foo\340';\n"
// Broken 3-byte encoding of \u0FFF with missing 2 last bytes.
{" 'foo\xE0';\n"
" (function fun",
"(a,b) { infunction; }", ")();", i::FUNCTION_SCOPE,
i::LanguageMode::kSloppy},
// Broken 3 byte encoding of \u00ff should be a 2 byte encoding.
{" 'foo\340\203\277';\n"
// Broken 3-byte encoding of \u00FF should be a 2-byte encoding.
{" 'foo\xE0\x83\xBF';\n"
" (function fun",
"(a,b) { infunction; }", ")();", i::FUNCTION_SCOPE,
i::LanguageMode::kSloppy},
// Broken 3 byte encoding of \u007f should be a 2 byte encoding.
{" 'foo\340\201\277';\n"
// Broken 3-byte encoding of \u007F should be a 2-byte encoding.
{" 'foo\xE0\x81\xBF';\n"
" (function fun",
"(a,b) { infunction; }", ")();", i::FUNCTION_SCOPE,
i::LanguageMode::kSloppy},
// Unpaired lead surrogate.
{" 'foo\355\240\201';\n"
{" 'foo\xED\xA0\x81';\n"
" (function fun",
"(a,b) { infunction; }", ")();", i::FUNCTION_SCOPE,
i::LanguageMode::kSloppy},
// Unpaired lead surrogate where following code point is a 3 byte
// Unpaired lead surrogate where the following code point is a 3-byte
// sequence.
{" 'foo\355\240\201\340\277\277';\n"
{" 'foo\xED\xA0\x81\xE0\xBF\xBF';\n"
" (function fun",
"(a,b) { infunction; }", ")();", i::FUNCTION_SCOPE,
i::LanguageMode::kSloppy},
// Unpaired lead surrogate where following code point is a 4 byte encoding
// of a trail surrogate.
{" 'foo\355\240\201\360\215\260\211';\n"
// Unpaired lead surrogate where the following code point is a 4-byte
// encoding of a trail surrogate.
{" 'foo\xED\xA0\x81\xF0\x8D\xB0\x89';\n"
" (function fun",
"(a,b) { infunction; }", ")();", i::FUNCTION_SCOPE,
i::LanguageMode::kSloppy},
// Unpaired trail surrogate.
{" 'foo\355\260\211';\n"
{" 'foo\xED\xB0\x89';\n"
" (function fun",
"(a,b) { infunction; }", ")();", i::FUNCTION_SCOPE,
i::LanguageMode::kSloppy},
// 2 byte encoding of \u00ff.
{" 'foo\303\277';\n"
// 2-byte encoding of \u00FF.
{" 'foo\xC3\xBF';\n"
" (function fun",
"(a,b) { infunction; }", ")();", i::FUNCTION_SCOPE,
i::LanguageMode::kSloppy},
// Broken 2 byte encoding of \u00ff with missing last byte.
{" 'foo\303';\n"
// Broken 2-byte encoding of \u00FF with missing last byte.
{" 'foo\xC3';\n"
" (function fun",
"(a,b) { infunction; }", ")();", i::FUNCTION_SCOPE,
i::LanguageMode::kSloppy},
// Broken 2 byte encoding of \u007f should be a 1 byte encoding.
{" 'foo\301\277';\n"
// Broken 2-byte encoding of \u007F should be a 1-byte encoding.
{" 'foo\xC1\xBF';\n"
" (function fun",
"(a,b) { infunction; }", ")();", i::FUNCTION_SCOPE,
i::LanguageMode::kSloppy},
// Illegal 5 byte encoding.
{" 'foo\370\277\277\277\277';\n"
// Illegal 5-byte encoding.
{" 'foo\xF8\xBF\xBF\xBF\xBF';\n"
" (function fun",
"(a,b) { infunction; }", ")();", i::FUNCTION_SCOPE,
i::LanguageMode::kSloppy},
// Illegal 6 byte encoding.
{" 'foo\374\277\277\277\277\277';\n"
// Illegal 6-byte encoding.
{" 'foo\xFC\xBF\xBF\xBF\xBF\xBF';\n"
" (function fun",
"(a,b) { infunction; }", ")();", i::FUNCTION_SCOPE,
i::LanguageMode::kSloppy},
// Illegal 0xfe byte
{" 'foo\376\277\277\277\277\277\277';\n"
// Illegal 0xFE byte
{" 'foo\xFE\xBF\xBF\xBF\xBF\xBF\xBF';\n"
" (function fun",
"(a,b) { infunction; }", ")();", i::FUNCTION_SCOPE,
i::LanguageMode::kSloppy},
// Illegal 0xff byte
{" 'foo\377\277\277\277\277\277\277\277';\n"
// Illegal 0xFF byte
{" 'foo\xFF\xBF\xBF\xBF\xBF\xBF\xBF\xBF';\n"
" (function fun",
"(a,b) { infunction; }", ")();", i::FUNCTION_SCOPE,
i::LanguageMode::kSloppy},
{" 'foo';\n"
" (function fun",
"(a,b) { 'bar\355\240\201\355\260\213'; }", ")();", i::FUNCTION_SCOPE,
"(a,b) { 'bar\xED\xA0\x81\xED\xB0\x8B'; }", ")();", i::FUNCTION_SCOPE,
i::LanguageMode::kSloppy},
{" 'foo';\n"
" (function fun",
"(a,b) { 'bar\360\220\220\214'; }", ")();", i::FUNCTION_SCOPE,
"(a,b) { 'bar\xF0\x90\x90\x8C'; }", ")();", i::FUNCTION_SCOPE,
i::LanguageMode::kSloppy},
{nullptr, nullptr, nullptr, i::EVAL_SCOPE, i::LanguageMode::kSloppy}};
......@@ -2888,7 +2888,7 @@ TEST(FuncNameInferrerTwoByte) {
TEST(FuncNameInferrerEscaped) {
// The same as FuncNameInferrerTwoByte, except that we express the two-byte
// character as a unicode escape.
// character as a Unicode escape.
i::FLAG_allow_natives_syntax = true;
v8::Isolate* isolate = CcTest::isolate();
v8::HandleScope scope(isolate);
......@@ -5358,9 +5358,9 @@ TEST(InvalidUnicodeEscapes) {
// Braces gone wrong
"var foob\\u{c481r = 0;", "var foob\\uc481}r = 0;", "var \\u{0052oo = 0;",
"var \\u0052}oo = 0;", "\"foob\\u{c481r\"", "var foob\\u{}ar = 0;",
// Too high value for the unicode escape
// Too high value for the Unicode code point escape
"\"\\u{110000}\"",
// Not an unicode escape
// Not a Unicode code point escape
"var foob\\v1234r = 0;", "var foob\\U1234r = 0;",
"var foob\\v{1234}r = 0;", "var foob\\U{1234}r = 0;", nullptr};
RunParserSyncTest(context_data, data, kError);
......@@ -5378,11 +5378,10 @@ TEST(UnicodeEscapes) {
"var foob\\uc481r = 0;", "var foob\\u{c481}r = 0;",
// String with an escape
"\"foob\\uc481r\"", "\"foob\\{uc481}r\"",
// This character is a valid unicode character, representable as a
// surrogate
// pair, not representable as 4 hex digits.
// This character is a valid Unicode character, representable as a
// surrogate pair, not representable as 4 hex digits.
"\"foo\\u{10e6d}\"",
// Max value for the unicode escape
// Max value for the Unicode code point escape
"\"\\u{10ffff}\"", nullptr};
RunParserSyncTest(context_data, data, kSuccess);
}
......
......@@ -114,13 +114,13 @@ TEST(Escaping) {
std::string json;
value->AppendAsTraceFormat(&json);
// Cannot use the expected value literal directly in CHECK_EQ
// as it fails to process # character on Windows.
// as it fails to process the # character on Windows.
const char* expected =
"{\"a\":\"abc\\\"\'\\\\\\\\x\\\"y\'z\\n\\t\\u0017\",\"b\":"
"\"\\u0001\\u0002\\u0003\\u0004\\u0005\\u0006\\u0007\\u0008\\t\\n\\u000B"
"\\u000C\\u000D\\u000E\\u000F\\u0010\\u0011\\u0012\\u0013\\u0014\\u0015\\"
"u0016\\u0017\\u0018\\u0019\\u001A\\u001B\\u001C\\u001D\\u001E\\u001F "
"!\\\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\\\]^_`"
"abcdefghijklmnopqrstuvwxyz{|}~\177\"}";
"abcdefghijklmnopqrstuvwxyz{|}~\x7F\"}";
CHECK_EQ(expected, json);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment