Index: test/cctest/test-parsing.cc |
diff --git a/test/cctest/test-parsing.cc b/test/cctest/test-parsing.cc |
index 4e2f828a60c3c660edf7bef7d6814d74dd9ec06b..7da5daca90706fe88f2aa286ddbcf58570a8c7e7 100644 |
--- a/test/cctest/test-parsing.cc |
+++ b/test/cctest/test-parsing.cc |
@@ -1357,7 +1357,8 @@ enum ParserFlag { |
kAllowHarmonyClasses, |
kAllowHarmonyObjectLiterals, |
kAllowHarmonyTemplates, |
- kAllowHarmonySloppy |
+ kAllowHarmonySloppy, |
+ kAllowHarmonyUnicode |
}; |
@@ -1383,6 +1384,7 @@ void SetParserFlags(i::ParserBase<Traits>* parser, |
parser->set_allow_harmony_classes(flags.Contains(kAllowHarmonyClasses)); |
parser->set_allow_harmony_templates(flags.Contains(kAllowHarmonyTemplates)); |
parser->set_allow_harmony_sloppy(flags.Contains(kAllowHarmonySloppy)); |
+ parser->set_allow_harmony_unicode(flags.Contains(kAllowHarmonyUnicode)); |
} |
@@ -1693,6 +1695,7 @@ void RunParserSyncTest(const char* context_data[][2], |
kAllowHarmonyModules, |
kAllowHarmonyTemplates, |
kAllowHarmonySloppy, |
+ kAllowHarmonyUnicode, |
kAllowLazy, |
kAllowNatives, |
}; |
@@ -4374,8 +4377,52 @@ TEST(InvalidUnicodeEscapes) { |
// No escapes allowed in regexp flags |
"/regex/\\u0069g", |
"/regex/\\u006g", |
+ // 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 |
+ "\"\\u{110000}\"", |
+ // Not an unicode escape |
+ "var foob\\v1234r = 0;", |
+ "var foob\\U1234r = 0;", |
+ "var foob\\v{1234}r = 0;", |
+ "var foob\\U{1234}r = 0;", |
NULL}; |
- RunParserSyncTest(context_data, data, kError); |
+ static const ParserFlag always_flags[] = {kAllowHarmonyUnicode}; |
+ RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, |
+ arraysize(always_flags)); |
+} |
+ |
+ |
+TEST(UnicodeEscapes) { |
+ const char* context_data[][2] = {{"", ""}, |
+ {"'use strict';", ""}, |
+ {NULL, NULL}}; |
+ const char* data[] = { |
+ // Identifier starting with escape |
+ "var \\u0052oo = 0;", |
+ "var \\u{0052}oo = 0;", |
+ "var \\u{52}oo = 0;", |
+ "var \\u{00000000052}oo = 0;", |
+ // Identifier with an escape but not starting with an escape |
+ "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. |
+ "\"foo\\u{10e6d}\"", |
+ // Max value for the unicode escape |
+ "\"\\u{10ffff}\"", |
+ NULL}; |
+ static const ParserFlag always_flags[] = {kAllowHarmonyUnicode}; |
+ RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags, |
+ arraysize(always_flags)); |
} |