OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 static bool CheckParse(const char* input) { | 93 static bool CheckParse(const char* input) { |
94 v8::HandleScope scope(CcTest::isolate()); | 94 v8::HandleScope scope(CcTest::isolate()); |
95 Zone zone; | 95 Zone zone; |
96 FlatStringReader reader(CcTest::i_isolate(), CStrVector(input)); | 96 FlatStringReader reader(CcTest::i_isolate(), CStrVector(input)); |
97 RegExpCompileData result; | 97 RegExpCompileData result; |
98 return v8::internal::RegExpParser::ParseRegExp( | 98 return v8::internal::RegExpParser::ParseRegExp( |
99 CcTest::i_isolate(), &zone, &reader, false, false, &result); | 99 CcTest::i_isolate(), &zone, &reader, false, false, &result); |
100 } | 100 } |
101 | 101 |
102 | 102 |
103 static void CheckParseEq(const char* input, const char* expected) { | 103 static void CheckParseEq(const char* input, const char* expected, |
| 104 bool unicode = false) { |
104 v8::HandleScope scope(CcTest::isolate()); | 105 v8::HandleScope scope(CcTest::isolate()); |
105 Zone zone; | 106 Zone zone; |
106 FlatStringReader reader(CcTest::i_isolate(), CStrVector(input)); | 107 FlatStringReader reader(CcTest::i_isolate(), CStrVector(input)); |
107 RegExpCompileData result; | 108 RegExpCompileData result; |
108 CHECK(v8::internal::RegExpParser::ParseRegExp( | 109 CHECK(v8::internal::RegExpParser::ParseRegExp( |
109 CcTest::i_isolate(), &zone, &reader, false, false, &result)); | 110 CcTest::i_isolate(), &zone, &reader, false, unicode, &result)); |
110 CHECK(result.tree != NULL); | 111 CHECK(result.tree != NULL); |
111 CHECK(result.error.is_null()); | 112 CHECK(result.error.is_null()); |
112 std::ostringstream os; | 113 std::ostringstream os; |
113 result.tree->Print(os, &zone); | 114 result.tree->Print(os, &zone); |
114 if (strcmp(expected, os.str().c_str()) != 0) { | 115 if (strcmp(expected, os.str().c_str()) != 0) { |
115 printf("%s | %s\n", expected, os.str().c_str()); | 116 printf("%s | %s\n", expected, os.str().c_str()); |
116 } | 117 } |
117 CHECK_EQ(0, strcmp(expected, os.str().c_str())); | 118 CHECK_EQ(0, strcmp(expected, os.str().c_str())); |
118 } | 119 } |
119 | 120 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 #define CHECK_SIMPLE(input, simple) CHECK_EQ(simple, CheckSimple(input)); | 157 #define CHECK_SIMPLE(input, simple) CHECK_EQ(simple, CheckSimple(input)); |
157 #define CHECK_MIN_MAX(input, min, max) \ | 158 #define CHECK_MIN_MAX(input, min, max) \ |
158 { MinMaxPair min_max = CheckMinMaxMatch(input); \ | 159 { MinMaxPair min_max = CheckMinMaxMatch(input); \ |
159 CHECK_EQ(min, min_max.min_match); \ | 160 CHECK_EQ(min, min_max.min_match); \ |
160 CHECK_EQ(max, min_max.max_match); \ | 161 CHECK_EQ(max, min_max.max_match); \ |
161 } | 162 } |
162 | 163 |
163 | 164 |
164 void TestRegExpParser(bool lookbehind) { | 165 void TestRegExpParser(bool lookbehind) { |
165 FLAG_harmony_regexp_lookbehind = lookbehind; | 166 FLAG_harmony_regexp_lookbehind = lookbehind; |
| 167 FLAG_harmony_unicode_regexps = true; |
166 | 168 |
167 CHECK_PARSE_ERROR("?"); | 169 CHECK_PARSE_ERROR("?"); |
168 | 170 |
169 CheckParseEq("abc", "'abc'"); | 171 CheckParseEq("abc", "'abc'"); |
170 CheckParseEq("", "%"); | 172 CheckParseEq("", "%"); |
171 CheckParseEq("abc|def", "(| 'abc' 'def')"); | 173 CheckParseEq("abc|def", "(| 'abc' 'def')"); |
172 CheckParseEq("abc|def|ghi", "(| 'abc' 'def' 'ghi')"); | 174 CheckParseEq("abc|def|ghi", "(| 'abc' 'def' 'ghi')"); |
173 CheckParseEq("^xxx$", "(: @^i 'xxx' @$i)"); | 175 CheckParseEq("^xxx$", "(: @^i 'xxx' @$i)"); |
174 CheckParseEq("ab\\b\\d\\bcd", "(: 'ab' @b [0-9] @b 'cd')"); | 176 CheckParseEq("ab\\b\\d\\bcd", "(: 'ab' @b [0-9] @b 'cd')"); |
175 CheckParseEq("\\w|\\d", "(| [0-9 A-Z _ a-z] [0-9])"); | 177 CheckParseEq("\\w|\\d", "(| [0-9 A-Z _ a-z] [0-9])"); |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 CheckParseEq("[\\111]", "[I]"); | 300 CheckParseEq("[\\111]", "[I]"); |
299 CheckParseEq("[\\1111]", "[I 1]"); | 301 CheckParseEq("[\\1111]", "[I 1]"); |
300 CheckParseEq("\\x34", "'\x34'"); | 302 CheckParseEq("\\x34", "'\x34'"); |
301 CheckParseEq("\\x60", "'\x60'"); | 303 CheckParseEq("\\x60", "'\x60'"); |
302 CheckParseEq("\\x3z", "'x3z'"); | 304 CheckParseEq("\\x3z", "'x3z'"); |
303 CheckParseEq("\\c", "'\\c'"); | 305 CheckParseEq("\\c", "'\\c'"); |
304 CheckParseEq("\\u0034", "'\x34'"); | 306 CheckParseEq("\\u0034", "'\x34'"); |
305 CheckParseEq("\\u003z", "'u003z'"); | 307 CheckParseEq("\\u003z", "'u003z'"); |
306 CheckParseEq("foo[z]*", "(: 'foo' (# 0 - g [z]))"); | 308 CheckParseEq("foo[z]*", "(: 'foo' (# 0 - g [z]))"); |
307 | 309 |
| 310 // Unicode regexps |
| 311 CheckParseEq("\\u{12345}", "'\\ud808\\udf45'", true); |
| 312 CheckParseEq("\\u{12345}\\u{23456}", "'\\ud808\\udf45\\ud84d\\udc56'", true); |
| 313 CheckParseEq("\\u{12345}|\\u{23456}", "(| '\\ud808\\udf45' '\\ud84d\\udc56')", |
| 314 true); |
| 315 |
308 CHECK_SIMPLE("", false); | 316 CHECK_SIMPLE("", false); |
309 CHECK_SIMPLE("a", true); | 317 CHECK_SIMPLE("a", true); |
310 CHECK_SIMPLE("a|b", false); | 318 CHECK_SIMPLE("a|b", false); |
311 CHECK_SIMPLE("a\\n", false); | 319 CHECK_SIMPLE("a\\n", false); |
312 CHECK_SIMPLE("^a", false); | 320 CHECK_SIMPLE("^a", false); |
313 CHECK_SIMPLE("a$", false); | 321 CHECK_SIMPLE("a$", false); |
314 CHECK_SIMPLE("a\\b!", false); | 322 CHECK_SIMPLE("a\\b!", false); |
315 CHECK_SIMPLE("a\\Bb", false); | 323 CHECK_SIMPLE("a\\Bb", false); |
316 CHECK_SIMPLE("a*", false); | 324 CHECK_SIMPLE("a*", false); |
317 CHECK_SIMPLE("a*?", false); | 325 CHECK_SIMPLE("a*?", false); |
(...skipping 1602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1920 // .toString() throws on non-RegExps that aren't RegExp.prototype | 1928 // .toString() throws on non-RegExps that aren't RegExp.prototype |
1921 v8::Local<v8::Value> resultToStringError = CompileRun( | 1929 v8::Local<v8::Value> resultToStringError = CompileRun( |
1922 "var exception;" | 1930 "var exception;" |
1923 "try { RegExp.prototype.toString.call(null) }" | 1931 "try { RegExp.prototype.toString.call(null) }" |
1924 "catch (e) { exception = e; }" | 1932 "catch (e) { exception = e; }" |
1925 "exception"); | 1933 "exception"); |
1926 CHECK_EQ(1, use_counts[v8::Isolate::kRegExpPrototypeStickyGetter]); | 1934 CHECK_EQ(1, use_counts[v8::Isolate::kRegExpPrototypeStickyGetter]); |
1927 CHECK_EQ(1, use_counts[v8::Isolate::kRegExpPrototypeToString]); | 1935 CHECK_EQ(1, use_counts[v8::Isolate::kRegExpPrototypeToString]); |
1928 CHECK(resultToStringError->IsObject()); | 1936 CHECK(resultToStringError->IsObject()); |
1929 } | 1937 } |
OLD | NEW |