Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(457)

Side by Side Diff: test/cctest/test-regexp.cc

Issue 14886: Bring toiger up to date with bleeding edge 984. (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/toiger/
Patch Set: Created 12 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « test/cctest/test-mark-compact.cc ('k') | test/mjsunit/switch.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2008 the V8 project authors. All rights reserved. 1 // Copyright 2008 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 48
49 49
50 using namespace v8::internal; 50 using namespace v8::internal;
51 51
52 52
53 static SmartPointer<const char> Parse(const char* input) { 53 static SmartPointer<const char> Parse(const char* input) {
54 V8::Initialize(NULL); 54 V8::Initialize(NULL);
55 v8::HandleScope scope; 55 v8::HandleScope scope;
56 ZoneScope zone_scope(DELETE_ON_EXIT); 56 ZoneScope zone_scope(DELETE_ON_EXIT);
57 FlatStringReader reader(CStrVector(input)); 57 FlatStringReader reader(CStrVector(input));
58 RegExpParseResult result; 58 RegExpCompileData result;
59 CHECK(v8::internal::ParseRegExp(&reader, false, &result)); 59 CHECK(v8::internal::ParseRegExp(&reader, false, &result));
60 CHECK(result.tree != NULL); 60 CHECK(result.tree != NULL);
61 CHECK(result.error.is_null()); 61 CHECK(result.error.is_null());
62 SmartPointer<const char> output = result.tree->ToString(); 62 SmartPointer<const char> output = result.tree->ToString();
63 return output; 63 return output;
64 } 64 }
65 65
66 static bool ParseEscapes(const char* input) { 66 static bool CheckSimple(const char* input) {
67 V8::Initialize(NULL); 67 V8::Initialize(NULL);
68 v8::HandleScope scope; 68 v8::HandleScope scope;
69 unibrow::Utf8InputBuffer<> buffer(input, strlen(input)); 69 unibrow::Utf8InputBuffer<> buffer(input, strlen(input));
70 ZoneScope zone_scope(DELETE_ON_EXIT); 70 ZoneScope zone_scope(DELETE_ON_EXIT);
71 FlatStringReader reader(CStrVector(input)); 71 FlatStringReader reader(CStrVector(input));
72 RegExpParseResult result; 72 RegExpCompileData result;
73 CHECK(v8::internal::ParseRegExp(&reader, false, &result)); 73 CHECK(v8::internal::ParseRegExp(&reader, false, &result));
74 CHECK(result.tree != NULL); 74 CHECK(result.tree != NULL);
75 CHECK(result.error.is_null()); 75 CHECK(result.error.is_null());
76 return result.has_character_escapes; 76 return result.simple;
77 } 77 }
78 78
79 79
80 #define CHECK_PARSE_EQ(input, expected) CHECK_EQ(expected, *Parse(input)) 80 #define CHECK_PARSE_EQ(input, expected) CHECK_EQ(expected, *Parse(input))
81 #define CHECK_ESCAPES(input, has_escapes) CHECK_EQ(has_escapes, \ 81 #define CHECK_SIMPLE(input, simple) CHECK_EQ(simple, CheckSimple(input));
82 ParseEscapes(input));
83 82
84 TEST(Parser) { 83 TEST(Parser) {
85 V8::Initialize(NULL); 84 V8::Initialize(NULL);
86 CHECK_PARSE_EQ("abc", "'abc'"); 85 CHECK_PARSE_EQ("abc", "'abc'");
87 CHECK_PARSE_EQ("", "%"); 86 CHECK_PARSE_EQ("", "%");
88 CHECK_PARSE_EQ("abc|def", "(| 'abc' 'def')"); 87 CHECK_PARSE_EQ("abc|def", "(| 'abc' 'def')");
89 CHECK_PARSE_EQ("abc|def|ghi", "(| 'abc' 'def' 'ghi')"); 88 CHECK_PARSE_EQ("abc|def|ghi", "(| 'abc' 'def' 'ghi')");
90 CHECK_PARSE_EQ("^xxx$", "(: @^i 'xxx' @$i)"); 89 CHECK_PARSE_EQ("^xxx$", "(: @^i 'xxx' @$i)");
91 CHECK_PARSE_EQ("ab\\b\\d\\bcd", "(: 'ab' @b [0-9] @b 'cd')"); 90 CHECK_PARSE_EQ("ab\\b\\d\\bcd", "(: 'ab' @b [0-9] @b 'cd')");
92 CHECK_PARSE_EQ("\\w|\\d", "(| [0-9 A-Z _ a-z] [0-9])"); 91 CHECK_PARSE_EQ("\\w|\\d", "(| [0-9 A-Z _ a-z] [0-9])");
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 " (# 0 - g '\\x04'))"); 160 " (# 0 - g '\\x04'))");
162 CHECK_PARSE_EQ("(x)(x)(x)(x)(x)(x)(x)(x)(x)(x)\\10", 161 CHECK_PARSE_EQ("(x)(x)(x)(x)(x)(x)(x)(x)(x)(x)\\10",
163 "(: (^ 'x') (^ 'x') (^ 'x') (^ 'x') (^ 'x') (^ 'x')" 162 "(: (^ 'x') (^ 'x') (^ 'x') (^ 'x') (^ 'x') (^ 'x')"
164 " (^ 'x') (^ 'x') (^ 'x') (^ 'x') (<- 10))"); 163 " (^ 'x') (^ 'x') (^ 'x') (^ 'x') (<- 10))");
165 CHECK_PARSE_EQ("(x)(x)(x)(x)(x)(x)(x)(x)(x)(x)\\11", 164 CHECK_PARSE_EQ("(x)(x)(x)(x)(x)(x)(x)(x)(x)(x)\\11",
166 "(: (^ 'x') (^ 'x') (^ 'x') (^ 'x') (^ 'x') (^ 'x')" 165 "(: (^ 'x') (^ 'x') (^ 'x') (^ 'x') (^ 'x') (^ 'x')"
167 " (^ 'x') (^ 'x') (^ 'x') (^ 'x') '\\x09')"); 166 " (^ 'x') (^ 'x') (^ 'x') (^ 'x') '\\x09')");
168 CHECK_PARSE_EQ("(a)\\1", "(: (^ 'a') (<- 1))"); 167 CHECK_PARSE_EQ("(a)\\1", "(: (^ 'a') (<- 1))");
169 CHECK_PARSE_EQ("(a\\1)", "(^ 'a')"); 168 CHECK_PARSE_EQ("(a\\1)", "(^ 'a')");
170 CHECK_PARSE_EQ("(\\1a)", "(^ 'a')"); 169 CHECK_PARSE_EQ("(\\1a)", "(^ 'a')");
170 CHECK_PARSE_EQ("(?=a)?a", "'a'");
171 CHECK_PARSE_EQ("(?=a){0,10}a", "'a'");
172 CHECK_PARSE_EQ("(?=a){1,10}a", "(: (-> + 'a') 'a')");
173 CHECK_PARSE_EQ("(?=a){9,10}a", "(: (-> + 'a') 'a')");
174 CHECK_PARSE_EQ("(?!a)?a", "'a'");
171 CHECK_PARSE_EQ("\\1(a)", "(^ 'a')"); 175 CHECK_PARSE_EQ("\\1(a)", "(^ 'a')");
172 CHECK_PARSE_EQ("(?!(a))\\1", "(-> - (^ 'a'))"); 176 CHECK_PARSE_EQ("(?!(a))\\1", "(-> - (^ 'a'))");
173 CHECK_PARSE_EQ("(?!\\1(a\\1)\\1)\\1", "(-> - (: (^ 'a') (<- 1)))"); 177 CHECK_PARSE_EQ("(?!\\1(a\\1)\\1)\\1", "(-> - (: (^ 'a') (<- 1)))");
174 CHECK_PARSE_EQ("[\\0]", "[\\x00]"); 178 CHECK_PARSE_EQ("[\\0]", "[\\x00]");
175 CHECK_PARSE_EQ("[\\11]", "[\\x09]"); 179 CHECK_PARSE_EQ("[\\11]", "[\\x09]");
176 CHECK_PARSE_EQ("[\\11a]", "[\\x09 a]"); 180 CHECK_PARSE_EQ("[\\11a]", "[\\x09 a]");
177 CHECK_PARSE_EQ("[\\011]", "[\\x09]"); 181 CHECK_PARSE_EQ("[\\011]", "[\\x09]");
178 CHECK_PARSE_EQ("[\\00011]", "[\\x00 1 1]"); 182 CHECK_PARSE_EQ("[\\00011]", "[\\x00 1 1]");
179 CHECK_PARSE_EQ("[\\118]", "[\\x09 8]"); 183 CHECK_PARSE_EQ("[\\118]", "[\\x09 8]");
180 CHECK_PARSE_EQ("[\\111]", "[I]"); 184 CHECK_PARSE_EQ("[\\111]", "[I]");
181 CHECK_PARSE_EQ("[\\1111]", "[I 1]"); 185 CHECK_PARSE_EQ("[\\1111]", "[I 1]");
182 CHECK_PARSE_EQ("\\x34", "'\x34'"); 186 CHECK_PARSE_EQ("\\x34", "'\x34'");
183 CHECK_PARSE_EQ("\\x60", "'\x60'"); 187 CHECK_PARSE_EQ("\\x60", "'\x60'");
184 CHECK_PARSE_EQ("\\x3z", "'x3z'"); 188 CHECK_PARSE_EQ("\\x3z", "'x3z'");
185 CHECK_PARSE_EQ("\\u0034", "'\x34'"); 189 CHECK_PARSE_EQ("\\u0034", "'\x34'");
186 CHECK_PARSE_EQ("\\u003z", "'u003z'"); 190 CHECK_PARSE_EQ("\\u003z", "'u003z'");
187 CHECK_PARSE_EQ("foo[z]*", "(: 'foo' (# 0 - g [z]))"); 191 CHECK_PARSE_EQ("foo[z]*", "(: 'foo' (# 0 - g [z]))");
188 192
189 CHECK_ESCAPES("a", false); 193 CHECK_SIMPLE("a", true);
190 CHECK_ESCAPES("a|b", false); 194 CHECK_SIMPLE("a|b", false);
191 CHECK_ESCAPES("a\\n", true); 195 CHECK_SIMPLE("a\\n", false);
192 CHECK_ESCAPES("^a", false); 196 CHECK_SIMPLE("^a", false);
193 CHECK_ESCAPES("a$", false); 197 CHECK_SIMPLE("a$", false);
194 CHECK_ESCAPES("a\\b!", false); 198 CHECK_SIMPLE("a\\b!", false);
195 CHECK_ESCAPES("a\\Bb", false); 199 CHECK_SIMPLE("a\\Bb", false);
196 CHECK_ESCAPES("a*", false); 200 CHECK_SIMPLE("a*", false);
197 CHECK_ESCAPES("a*?", false); 201 CHECK_SIMPLE("a*?", false);
198 CHECK_ESCAPES("a?", false); 202 CHECK_SIMPLE("a?", false);
199 CHECK_ESCAPES("a??", false); 203 CHECK_SIMPLE("a??", false);
200 CHECK_ESCAPES("a{0,1}?", false); 204 CHECK_SIMPLE("a{0,1}?", false);
201 CHECK_ESCAPES("a{1,1}?", false); 205 CHECK_SIMPLE("a{1,1}?", false);
202 CHECK_ESCAPES("a{1,2}?", false); 206 CHECK_SIMPLE("a{1,2}?", false);
203 CHECK_ESCAPES("a+?", false); 207 CHECK_SIMPLE("a+?", false);
204 CHECK_ESCAPES("(a)", false); 208 CHECK_SIMPLE("(a)", false);
205 CHECK_ESCAPES("(a)\\1", false); 209 CHECK_SIMPLE("(a)\\1", false);
206 CHECK_ESCAPES("(\\1a)", false); 210 CHECK_SIMPLE("(\\1a)", false);
207 CHECK_ESCAPES("\\1(a)", false); 211 CHECK_SIMPLE("\\1(a)", false);
208 CHECK_ESCAPES("a\\s", false); 212 CHECK_SIMPLE("a\\s", false);
209 CHECK_ESCAPES("a\\S", false); 213 CHECK_SIMPLE("a\\S", false);
210 CHECK_ESCAPES("a\\d", false); 214 CHECK_SIMPLE("a\\d", false);
211 CHECK_ESCAPES("a\\D", false); 215 CHECK_SIMPLE("a\\D", false);
212 CHECK_ESCAPES("a\\w", false); 216 CHECK_SIMPLE("a\\w", false);
213 CHECK_ESCAPES("a\\W", false); 217 CHECK_SIMPLE("a\\W", false);
214 CHECK_ESCAPES("a.", false); 218 CHECK_SIMPLE("a.", false);
215 CHECK_ESCAPES("a\\q", true); 219 CHECK_SIMPLE("a\\q", false);
216 CHECK_ESCAPES("a[a]", false); 220 CHECK_SIMPLE("a[a]", false);
217 CHECK_ESCAPES("a[^a]", false); 221 CHECK_SIMPLE("a[^a]", false);
218 CHECK_ESCAPES("a[a-z]", false); 222 CHECK_SIMPLE("a[a-z]", false);
219 CHECK_ESCAPES("a[\\q]", false); 223 CHECK_SIMPLE("a[\\q]", false);
220 CHECK_ESCAPES("a(?:b)", false); 224 CHECK_SIMPLE("a(?:b)", false);
221 CHECK_ESCAPES("a(?=b)", false); 225 CHECK_SIMPLE("a(?=b)", false);
222 CHECK_ESCAPES("a(?!b)", false); 226 CHECK_SIMPLE("a(?!b)", false);
223 CHECK_ESCAPES("\\x60", true); 227 CHECK_SIMPLE("\\x60", false);
224 CHECK_ESCAPES("\\u0060", true); 228 CHECK_SIMPLE("\\u0060", false);
225 CHECK_ESCAPES("\\cA", true); 229 CHECK_SIMPLE("\\cA", false);
226 CHECK_ESCAPES("\\q", true); 230 CHECK_SIMPLE("\\q", false);
227 CHECK_ESCAPES("\\1112", true); 231 CHECK_SIMPLE("\\1112", false);
228 CHECK_ESCAPES("\\0", true); 232 CHECK_SIMPLE("\\0", false);
229 CHECK_ESCAPES("(a)\\1", false); 233 CHECK_SIMPLE("(a)\\1", false);
234 CHECK_SIMPLE("(?=a)?a", false);
235 CHECK_SIMPLE("(?!a)?a\\1", false);
236 CHECK_SIMPLE("(?:(?=a))a\\1", false);
230 237
231 CHECK_PARSE_EQ("a{}", "'a{}'"); 238 CHECK_PARSE_EQ("a{}", "'a{}'");
232 CHECK_PARSE_EQ("a{,}", "'a{,}'"); 239 CHECK_PARSE_EQ("a{,}", "'a{,}'");
233 CHECK_PARSE_EQ("a{", "'a{'"); 240 CHECK_PARSE_EQ("a{", "'a{'");
234 CHECK_PARSE_EQ("a{z}", "'a{z}'"); 241 CHECK_PARSE_EQ("a{z}", "'a{z}'");
235 CHECK_PARSE_EQ("a{1z}", "'a{1z}'"); 242 CHECK_PARSE_EQ("a{1z}", "'a{1z}'");
236 CHECK_PARSE_EQ("a{12z}", "'a{12z}'"); 243 CHECK_PARSE_EQ("a{12z}", "'a{12z}'");
237 CHECK_PARSE_EQ("a{12,", "'a{12,'"); 244 CHECK_PARSE_EQ("a{12,", "'a{12,'");
238 CHECK_PARSE_EQ("a{12,3b", "'a{12,3b'"); 245 CHECK_PARSE_EQ("a{12,3b", "'a{12,3b'");
239 CHECK_PARSE_EQ("{}", "'{}'"); 246 CHECK_PARSE_EQ("{}", "'{}'");
(...skipping 12 matching lines...) Expand all
252 CHECK_PARSE_EQ("{", "'{'"); 259 CHECK_PARSE_EQ("{", "'{'");
253 CHECK_PARSE_EQ("a|", "(| 'a' %)"); 260 CHECK_PARSE_EQ("a|", "(| 'a' %)");
254 } 261 }
255 262
256 static void ExpectError(const char* input, 263 static void ExpectError(const char* input,
257 const char* expected) { 264 const char* expected) {
258 V8::Initialize(NULL); 265 V8::Initialize(NULL);
259 v8::HandleScope scope; 266 v8::HandleScope scope;
260 ZoneScope zone_scope(DELETE_ON_EXIT); 267 ZoneScope zone_scope(DELETE_ON_EXIT);
261 FlatStringReader reader(CStrVector(input)); 268 FlatStringReader reader(CStrVector(input));
262 RegExpParseResult result; 269 RegExpCompileData result;
263 CHECK_EQ(false, v8::internal::ParseRegExp(&reader, false, &result)); 270 CHECK_EQ(false, v8::internal::ParseRegExp(&reader, false, &result));
264 CHECK(result.tree == NULL); 271 CHECK(result.tree == NULL);
265 CHECK(!result.error.is_null()); 272 CHECK(!result.error.is_null());
266 SmartPointer<char> str = result.error->ToCString(ALLOW_NULLS); 273 SmartPointer<char> str = result.error->ToCString(ALLOW_NULLS);
267 CHECK_EQ(expected, *str); 274 CHECK_EQ(expected, *str);
268 } 275 }
269 276
270 277
271 TEST(Errors) { 278 TEST(Errors) {
272 V8::Initialize(NULL); 279 V8::Initialize(NULL);
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 TestCharacterClassEscapes('s', IsWhiteSpace); 358 TestCharacterClassEscapes('s', IsWhiteSpace);
352 TestCharacterClassEscapes('S', NotWhiteSpace); 359 TestCharacterClassEscapes('S', NotWhiteSpace);
353 TestCharacterClassEscapes('w', IsRegExpWord); 360 TestCharacterClassEscapes('w', IsRegExpWord);
354 TestCharacterClassEscapes('W', NotWord); 361 TestCharacterClassEscapes('W', NotWord);
355 } 362 }
356 363
357 364
358 static RegExpNode* Compile(const char* input, bool multiline, bool is_ascii) { 365 static RegExpNode* Compile(const char* input, bool multiline, bool is_ascii) {
359 V8::Initialize(NULL); 366 V8::Initialize(NULL);
360 FlatStringReader reader(CStrVector(input)); 367 FlatStringReader reader(CStrVector(input));
361 RegExpParseResult result; 368 RegExpCompileData compile_data;
362 if (!v8::internal::ParseRegExp(&reader, multiline, &result)) 369 if (!v8::internal::ParseRegExp(&reader, multiline, &compile_data))
363 return NULL; 370 return NULL;
364 RegExpNode* node = NULL;
365 Handle<String> pattern = Factory::NewStringFromUtf8(CStrVector(input)); 371 Handle<String> pattern = Factory::NewStringFromUtf8(CStrVector(input));
366 RegExpEngine::Compile(&result, &node, false, multiline, pattern, is_ascii); 372 RegExpEngine::Compile(&compile_data, false, multiline, pattern, is_ascii);
367 return node; 373 return compile_data.node;
368 } 374 }
369 375
370 376
371 static void Execute(const char* input, 377 static void Execute(const char* input,
372 bool multiline, 378 bool multiline,
373 bool is_ascii, 379 bool is_ascii,
374 bool dot_output = false) { 380 bool dot_output = false) {
375 v8::HandleScope scope; 381 v8::HandleScope scope;
376 ZoneScope zone_scope(DELETE_ON_EXIT); 382 ZoneScope zone_scope(DELETE_ON_EXIT);
377 RegExpNode* node = Compile(input, multiline, is_ascii); 383 RegExpNode* node = Compile(input, multiline, is_ascii);
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 Handle<String> f2 = 567 Handle<String> f2 =
562 Factory::NewStringFromAscii(CStrVector("barfoo")); 568 Factory::NewStringFromAscii(CStrVector("barfoo"));
563 Handle<String> f2_16 = RegExpImpl::StringToTwoByte(f2); 569 Handle<String> f2_16 = RegExpImpl::StringToTwoByte(f2);
564 CHECK(!IrregexpInterpreter::Match(array, f2_16, captures, 0)); 570 CHECK(!IrregexpInterpreter::Match(array, f2_16, captures, 0));
565 CHECK_EQ(42, captures[0]); 571 CHECK_EQ(42, captures[0]);
566 } 572 }
567 573
568 574
569 #ifndef ARM // IA32 only tests. 575 #ifndef ARM // IA32 only tests.
570 576
577 class ContextInitializer {
578 public:
579 ContextInitializer() : env_(), scope_(), stack_guard_() {
580 env_ = v8::Context::New();
581 env_->Enter();
582 }
583 ~ContextInitializer() {
584 env_->Exit();
585 env_.Dispose();
586 }
587 private:
588 v8::Persistent<v8::Context> env_;
589 v8::HandleScope scope_;
590 v8::internal::StackGuard stack_guard_;
591 };
592
593
571 TEST(MacroAssemblerIA32Success) { 594 TEST(MacroAssemblerIA32Success) {
572 V8::Initialize(NULL); 595 v8::V8::Initialize();
573 596 ContextInitializer initializer;
574 // regexp-macro-assembler-ia32 needs a handle scope to allocate
575 // byte-arrays for constants.
576 v8::HandleScope scope;
577 597
578 RegExpMacroAssemblerIA32 m(RegExpMacroAssemblerIA32::ASCII, 4); 598 RegExpMacroAssemblerIA32 m(RegExpMacroAssemblerIA32::ASCII, 4);
579 599
580 m.Succeed(); 600 m.Succeed();
581 601
582 Handle<String> source = Factory::NewStringFromAscii(CStrVector("")); 602 Handle<String> source = Factory::NewStringFromAscii(CStrVector(""));
583 Handle<Object> code_object = m.GetCode(source); 603 Handle<Object> code_object = m.GetCode(source);
584 Handle<Code> code = Handle<Code>::cast(code_object); 604 Handle<Code> code = Handle<Code>::cast(code_object);
585 605
586 int captures[4] = {42, 37, 87, 117}; 606 int captures[4] = {42, 37, 87, 117};
587 Handle<String> input = Factory::NewStringFromAscii(CStrVector("foofoo")); 607 Handle<String> input = Factory::NewStringFromAscii(CStrVector("foofoo"));
588 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input); 608 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input);
589 Address start_adr = seq_input->GetCharsAddress(); 609 Address start_adr = seq_input->GetCharsAddress();
590 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input); 610 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input);
591 int end_offset = start_offset + seq_input->length(); 611 int end_offset = start_offset + seq_input->length();
592 612
593 bool success = RegExpMacroAssemblerIA32::Execute(*code, 613 RegExpMacroAssemblerIA32::Result result =
594 seq_input.location(), 614 RegExpMacroAssemblerIA32::Execute(*code,
595 start_offset, 615 seq_input.location(),
596 end_offset, 616 start_offset,
597 captures, 617 end_offset,
598 true); 618 captures,
619 true);
599 620
600 CHECK(success); 621 CHECK_EQ(RegExpMacroAssemblerIA32::SUCCESS, result);
601 CHECK_EQ(-1, captures[0]); 622 CHECK_EQ(-1, captures[0]);
602 CHECK_EQ(-1, captures[1]); 623 CHECK_EQ(-1, captures[1]);
603 CHECK_EQ(-1, captures[2]); 624 CHECK_EQ(-1, captures[2]);
604 CHECK_EQ(-1, captures[3]); 625 CHECK_EQ(-1, captures[3]);
605 } 626 }
606 627
607 628
608 TEST(MacroAssemblerIA32Simple) { 629 TEST(MacroAssemblerIA32Simple) {
609 V8::Initialize(NULL); 630 v8::V8::Initialize();
610 631 ContextInitializer initializer;
611 // regexp-macro-assembler-ia32 needs a handle scope to allocate
612 // byte-arrays for constants.
613 v8::HandleScope scope;
614 632
615 RegExpMacroAssemblerIA32 m(RegExpMacroAssemblerIA32::ASCII, 4); 633 RegExpMacroAssemblerIA32 m(RegExpMacroAssemblerIA32::ASCII, 4);
616 634
617 uc16 foo_chars[3] = {'f', 'o', 'o'}; 635 uc16 foo_chars[3] = {'f', 'o', 'o'};
618 Vector<const uc16> foo(foo_chars, 3); 636 Vector<const uc16> foo(foo_chars, 3);
619 637
620 Label fail; 638 Label fail;
621 m.CheckCharacters(foo, 0, &fail, true); 639 m.CheckCharacters(foo, 0, &fail, true);
622 m.WriteCurrentPositionToRegister(0, 0); 640 m.WriteCurrentPositionToRegister(0, 0);
623 m.AdvanceCurrentPosition(3); 641 m.AdvanceCurrentPosition(3);
624 m.WriteCurrentPositionToRegister(1, 0); 642 m.WriteCurrentPositionToRegister(1, 0);
625 m.Succeed(); 643 m.Succeed();
626 m.Bind(&fail); 644 m.Bind(&fail);
627 m.Fail(); 645 m.Fail();
628 646
629 Handle<String> source = Factory::NewStringFromAscii(CStrVector("^foo")); 647 Handle<String> source = Factory::NewStringFromAscii(CStrVector("^foo"));
630 Handle<Object> code_object = m.GetCode(source); 648 Handle<Object> code_object = m.GetCode(source);
631 Handle<Code> code = Handle<Code>::cast(code_object); 649 Handle<Code> code = Handle<Code>::cast(code_object);
632 650
633 int captures[4] = {42, 37, 87, 117}; 651 int captures[4] = {42, 37, 87, 117};
634 Handle<String> input = Factory::NewStringFromAscii(CStrVector("foofoo")); 652 Handle<String> input = Factory::NewStringFromAscii(CStrVector("foofoo"));
635 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input); 653 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input);
636 Address start_adr = seq_input->GetCharsAddress(); 654 Address start_adr = seq_input->GetCharsAddress();
637 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input); 655 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input);
638 int end_offset = start_offset + seq_input->length(); 656 int end_offset = start_offset + seq_input->length();
639 657
640 bool success = RegExpMacroAssemblerIA32::Execute(*code, 658 RegExpMacroAssemblerIA32::Result result =
641 seq_input.location(), 659 RegExpMacroAssemblerIA32::Execute(*code,
642 start_offset, 660 seq_input.location(),
643 end_offset, 661 start_offset,
644 captures, 662 end_offset,
645 true); 663 captures,
664 true);
646 665
647 CHECK(success); 666 CHECK_EQ(RegExpMacroAssemblerIA32::SUCCESS, result);
648 CHECK_EQ(0, captures[0]); 667 CHECK_EQ(0, captures[0]);
649 CHECK_EQ(3, captures[1]); 668 CHECK_EQ(3, captures[1]);
650 CHECK_EQ(-1, captures[2]); 669 CHECK_EQ(-1, captures[2]);
651 CHECK_EQ(-1, captures[3]); 670 CHECK_EQ(-1, captures[3]);
652 671
653 input = Factory::NewStringFromAscii(CStrVector("barbarbar")); 672 input = Factory::NewStringFromAscii(CStrVector("barbarbar"));
654 seq_input = Handle<SeqAsciiString>::cast(input); 673 seq_input = Handle<SeqAsciiString>::cast(input);
655 start_adr = seq_input->GetCharsAddress(); 674 start_adr = seq_input->GetCharsAddress();
656 start_offset = start_adr - reinterpret_cast<Address>(*seq_input); 675 start_offset = start_adr - reinterpret_cast<Address>(*seq_input);
657 end_offset = start_offset + seq_input->length(); 676 end_offset = start_offset + seq_input->length();
658 677
659 success = RegExpMacroAssemblerIA32::Execute(*code, 678 result = RegExpMacroAssemblerIA32::Execute(*code,
660 seq_input.location(), 679 seq_input.location(),
661 start_offset, 680 start_offset,
662 end_offset, 681 end_offset,
663 captures, 682 captures,
664 true); 683 true);
665 684
666 CHECK(!success); 685 CHECK_EQ(RegExpMacroAssemblerIA32::FAILURE, result);
667 } 686 }
668 687
669 688
670 TEST(MacroAssemblerIA32SimpleUC16) { 689 TEST(MacroAssemblerIA32SimpleUC16) {
671 V8::Initialize(NULL); 690 v8::V8::Initialize();
672 691 ContextInitializer initializer;
673 // regexp-macro-assembler-ia32 needs a handle scope to allocate
674 // byte-arrays for constants.
675 v8::HandleScope scope;
676 692
677 RegExpMacroAssemblerIA32 m(RegExpMacroAssemblerIA32::UC16, 4); 693 RegExpMacroAssemblerIA32 m(RegExpMacroAssemblerIA32::UC16, 4);
678 694
679 uc16 foo_chars[3] = {'f', 'o', 'o'}; 695 uc16 foo_chars[3] = {'f', 'o', 'o'};
680 Vector<const uc16> foo(foo_chars, 3); 696 Vector<const uc16> foo(foo_chars, 3);
681 697
682 Label fail; 698 Label fail;
683 m.CheckCharacters(foo, 0, &fail, true); 699 m.CheckCharacters(foo, 0, &fail, true);
684 m.WriteCurrentPositionToRegister(0, 0); 700 m.WriteCurrentPositionToRegister(0, 0);
685 m.AdvanceCurrentPosition(3); 701 m.AdvanceCurrentPosition(3);
686 m.WriteCurrentPositionToRegister(1, 0); 702 m.WriteCurrentPositionToRegister(1, 0);
687 m.Succeed(); 703 m.Succeed();
688 m.Bind(&fail); 704 m.Bind(&fail);
689 m.Fail(); 705 m.Fail();
690 706
691 Handle<String> source = Factory::NewStringFromAscii(CStrVector("^foo")); 707 Handle<String> source = Factory::NewStringFromAscii(CStrVector("^foo"));
692 Handle<Object> code_object = m.GetCode(source); 708 Handle<Object> code_object = m.GetCode(source);
693 Handle<Code> code = Handle<Code>::cast(code_object); 709 Handle<Code> code = Handle<Code>::cast(code_object);
694 710
695 int captures[4] = {42, 37, 87, 117}; 711 int captures[4] = {42, 37, 87, 117};
696 const uc16 input_data[6] = {'f', 'o', 'o', 'f', 'o', '\xa0'}; 712 const uc16 input_data[6] = {'f', 'o', 'o', 'f', 'o', '\xa0'};
697 Handle<String> input = 713 Handle<String> input =
698 Factory::NewStringFromTwoByte(Vector<const uc16>(input_data, 6)); 714 Factory::NewStringFromTwoByte(Vector<const uc16>(input_data, 6));
699 Handle<SeqTwoByteString> seq_input = Handle<SeqTwoByteString>::cast(input); 715 Handle<SeqTwoByteString> seq_input = Handle<SeqTwoByteString>::cast(input);
700 Address start_adr = seq_input->GetCharsAddress(); 716 Address start_adr = seq_input->GetCharsAddress();
701 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input); 717 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input);
702 int end_offset = start_offset + seq_input->length() * sizeof(uc16); 718 int end_offset = start_offset + seq_input->length() * sizeof(uc16);
703 719
704 bool success = RegExpMacroAssemblerIA32::Execute(*code, 720 RegExpMacroAssemblerIA32::Result result =
705 seq_input.location(), 721 RegExpMacroAssemblerIA32::Execute(*code,
706 start_offset, 722 seq_input.location(),
707 end_offset, 723 start_offset,
708 captures, 724 end_offset,
709 true); 725 captures,
726 true);
710 727
711 CHECK(success); 728 CHECK_EQ(RegExpMacroAssemblerIA32::SUCCESS, result);
712 CHECK_EQ(0, captures[0]); 729 CHECK_EQ(0, captures[0]);
713 CHECK_EQ(3, captures[1]); 730 CHECK_EQ(3, captures[1]);
714 CHECK_EQ(-1, captures[2]); 731 CHECK_EQ(-1, captures[2]);
715 CHECK_EQ(-1, captures[3]); 732 CHECK_EQ(-1, captures[3]);
716 733
717 const uc16 input_data2[9] = {'b', 'a', 'r', 'b', 'a', 'r', 'b', 'a', '\xa0'}; 734 const uc16 input_data2[9] = {'b', 'a', 'r', 'b', 'a', 'r', 'b', 'a', '\xa0'};
718 input = Factory::NewStringFromTwoByte(Vector<const uc16>(input_data2, 9)); 735 input = Factory::NewStringFromTwoByte(Vector<const uc16>(input_data2, 9));
719 seq_input = Handle<SeqTwoByteString>::cast(input); 736 seq_input = Handle<SeqTwoByteString>::cast(input);
720 start_adr = seq_input->GetCharsAddress(); 737 start_adr = seq_input->GetCharsAddress();
721 start_offset = start_adr - reinterpret_cast<Address>(*seq_input); 738 start_offset = start_adr - reinterpret_cast<Address>(*seq_input);
722 end_offset = start_offset + seq_input->length() * sizeof(uc16); 739 end_offset = start_offset + seq_input->length() * sizeof(uc16);
723 740
724 success = RegExpMacroAssemblerIA32::Execute(*code, 741 result = RegExpMacroAssemblerIA32::Execute(*code,
725 seq_input.location(), 742 seq_input.location(),
726 start_offset, 743 start_offset,
727 end_offset, 744 end_offset,
728 captures, 745 captures,
729 true); 746 true);
730 747
731 CHECK(!success); 748 CHECK_EQ(RegExpMacroAssemblerIA32::FAILURE, result);
732 } 749 }
733 750
734 751
735 TEST(MacroAssemblerIA32Backtrack) { 752 TEST(MacroAssemblerIA32Backtrack) {
736 V8::Initialize(NULL); 753 v8::V8::Initialize();
737 754 ContextInitializer initializer;
738 // regexp-macro-assembler-ia32 needs a handle scope to allocate
739 // byte-arrays for constants.
740 v8::HandleScope scope;
741 755
742 RegExpMacroAssemblerIA32 m(RegExpMacroAssemblerIA32::ASCII, 0); 756 RegExpMacroAssemblerIA32 m(RegExpMacroAssemblerIA32::ASCII, 0);
743 757
744 Label fail; 758 Label fail;
745 Label backtrack; 759 Label backtrack;
746 m.LoadCurrentCharacter(10, &fail); 760 m.LoadCurrentCharacter(10, &fail);
747 m.Succeed(); 761 m.Succeed();
748 m.Bind(&fail); 762 m.Bind(&fail);
749 m.PushBacktrack(&backtrack); 763 m.PushBacktrack(&backtrack);
750 m.LoadCurrentCharacter(10, NULL); 764 m.LoadCurrentCharacter(10, NULL);
751 m.Succeed(); 765 m.Succeed();
752 m.Bind(&backtrack); 766 m.Bind(&backtrack);
753 m.Fail(); 767 m.Fail();
754 768
755 Handle<String> source = Factory::NewStringFromAscii(CStrVector("..........")); 769 Handle<String> source = Factory::NewStringFromAscii(CStrVector(".........."));
756 Handle<Object> code_object = m.GetCode(source); 770 Handle<Object> code_object = m.GetCode(source);
757 Handle<Code> code = Handle<Code>::cast(code_object); 771 Handle<Code> code = Handle<Code>::cast(code_object);
758 772
759 Handle<String> input = Factory::NewStringFromAscii(CStrVector("foofoo")); 773 Handle<String> input = Factory::NewStringFromAscii(CStrVector("foofoo"));
760 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input); 774 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input);
761 Address start_adr = seq_input->GetCharsAddress(); 775 Address start_adr = seq_input->GetCharsAddress();
762 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input); 776 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input);
763 int end_offset = start_offset + seq_input->length(); 777 int end_offset = start_offset + seq_input->length();
764 778
765 bool success = RegExpMacroAssemblerIA32::Execute(*code, 779 RegExpMacroAssemblerIA32::Result result =
766 seq_input.location(), 780 RegExpMacroAssemblerIA32::Execute(*code,
767 start_offset, 781 seq_input.location(),
768 end_offset, 782 start_offset,
769 NULL, 783 end_offset,
770 true); 784 NULL,
785 true);
771 786
772 CHECK(!success); 787 CHECK_EQ(RegExpMacroAssemblerIA32::FAILURE, result);
773 } 788 }
774 789
775 790
776 TEST(MacroAssemblerIA32BackReference) { 791 TEST(MacroAssemblerIA32BackReferenceASCII) {
777 V8::Initialize(NULL); 792 v8::V8::Initialize();
778 793 ContextInitializer initializer;
779 // regexp-macro-assembler-ia32 needs a handle scope to allocate
780 // byte-arrays for constants.
781 v8::HandleScope scope;
782 794
783 RegExpMacroAssemblerIA32 m(RegExpMacroAssemblerIA32::ASCII, 3); 795 RegExpMacroAssemblerIA32 m(RegExpMacroAssemblerIA32::ASCII, 3);
784 796
785 m.WriteCurrentPositionToRegister(0, 0); 797 m.WriteCurrentPositionToRegister(0, 0);
786 m.AdvanceCurrentPosition(2); 798 m.AdvanceCurrentPosition(2);
787 m.WriteCurrentPositionToRegister(1, 0); 799 m.WriteCurrentPositionToRegister(1, 0);
788 Label nomatch; 800 Label nomatch;
789 m.CheckNotBackReference(0, &nomatch); 801 m.CheckNotBackReference(0, &nomatch);
790 m.Fail(); 802 m.Fail();
791 m.Bind(&nomatch); 803 m.Bind(&nomatch);
792 m.AdvanceCurrentPosition(2); 804 m.AdvanceCurrentPosition(2);
793 Label missing_match; 805 Label missing_match;
794 m.CheckNotBackReference(0, &missing_match); 806 m.CheckNotBackReference(0, &missing_match);
795 m.WriteCurrentPositionToRegister(2, 0); 807 m.WriteCurrentPositionToRegister(2, 0);
796 m.Succeed(); 808 m.Succeed();
797 m.Bind(&missing_match); 809 m.Bind(&missing_match);
798 m.Fail(); 810 m.Fail();
799 811
800 Handle<String> source = Factory::NewStringFromAscii(CStrVector("^(..)..\1")); 812 Handle<String> source = Factory::NewStringFromAscii(CStrVector("^(..)..\1"));
801 Handle<Object> code_object = m.GetCode(source); 813 Handle<Object> code_object = m.GetCode(source);
802 Handle<Code> code = Handle<Code>::cast(code_object); 814 Handle<Code> code = Handle<Code>::cast(code_object);
803 815
804 Handle<String> input = Factory::NewStringFromAscii(CStrVector("fooofo")); 816 Handle<String> input = Factory::NewStringFromAscii(CStrVector("fooofo"));
805 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input); 817 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input);
806 Address start_adr = seq_input->GetCharsAddress(); 818 Address start_adr = seq_input->GetCharsAddress();
807 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input); 819 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input);
808 int end_offset = start_offset + seq_input->length(); 820 int end_offset = start_offset + seq_input->length();
809 821
810 int output[3]; 822 int output[3];
811 bool success = RegExpMacroAssemblerIA32::Execute(*code, 823 RegExpMacroAssemblerIA32::Result result =
812 seq_input.location(), 824 RegExpMacroAssemblerIA32::Execute(*code,
813 start_offset, 825 seq_input.location(),
814 end_offset, 826 start_offset,
815 output, 827 end_offset,
816 true); 828 output,
829 true);
817 830
818 CHECK(success); 831 CHECK_EQ(RegExpMacroAssemblerIA32::SUCCESS, result);
819 CHECK_EQ(0, output[0]); 832 CHECK_EQ(0, output[0]);
820 CHECK_EQ(2, output[1]); 833 CHECK_EQ(2, output[1]);
821 CHECK_EQ(6, output[2]); 834 CHECK_EQ(6, output[2]);
822 } 835 }
823 836
824 837
838 TEST(MacroAssemblerIA32BackReferenceUC16) {
839 v8::V8::Initialize();
840 ContextInitializer initializer;
841
842 RegExpMacroAssemblerIA32 m(RegExpMacroAssemblerIA32::UC16, 3);
843
844 m.WriteCurrentPositionToRegister(0, 0);
845 m.AdvanceCurrentPosition(2);
846 m.WriteCurrentPositionToRegister(1, 0);
847 Label nomatch;
848 m.CheckNotBackReference(0, &nomatch);
849 m.Fail();
850 m.Bind(&nomatch);
851 m.AdvanceCurrentPosition(2);
852 Label missing_match;
853 m.CheckNotBackReference(0, &missing_match);
854 m.WriteCurrentPositionToRegister(2, 0);
855 m.Succeed();
856 m.Bind(&missing_match);
857 m.Fail();
858
859 Handle<String> source = Factory::NewStringFromAscii(CStrVector("^(..)..\1"));
860 Handle<Object> code_object = m.GetCode(source);
861 Handle<Code> code = Handle<Code>::cast(code_object);
862
863 const uc16 input_data[6] = {'f', 0x2028, 'o', 'o', 'f', 0x2028};
864 Handle<String> input =
865 Factory::NewStringFromTwoByte(Vector<const uc16>(input_data, 6));
866 Handle<SeqTwoByteString> seq_input = Handle<SeqTwoByteString>::cast(input);
867 Address start_adr = seq_input->GetCharsAddress();
868
869 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input);
870 int end_offset = start_offset + seq_input->length() * sizeof(input_data[0]);
871
872 int output[3];
873 RegExpMacroAssemblerIA32::Result result =
874 RegExpMacroAssemblerIA32::Execute(*code,
875 seq_input.location(),
876 start_offset,
877 end_offset,
878 output,
879 true);
880
881 CHECK_EQ(RegExpMacroAssemblerIA32::SUCCESS, result);
882 CHECK_EQ(0, output[0]);
883 CHECK_EQ(2, output[1]);
884 CHECK_EQ(6, output[2]);
885 }
886
887
888
825 TEST(MacroAssemblerIA32AtStart) { 889 TEST(MacroAssemblerIA32AtStart) {
826 V8::Initialize(NULL); 890 v8::V8::Initialize();
827 891 ContextInitializer initializer;
828 // regexp-macro-assembler-ia32 needs a handle scope to allocate
829 // byte-arrays for constants.
830 v8::HandleScope scope;
831 892
832 RegExpMacroAssemblerIA32 m(RegExpMacroAssemblerIA32::ASCII, 0); 893 RegExpMacroAssemblerIA32 m(RegExpMacroAssemblerIA32::ASCII, 0);
833 894
834 Label not_at_start, newline, fail; 895 Label not_at_start, newline, fail;
835 m.CheckNotAtStart(&not_at_start); 896 m.CheckNotAtStart(&not_at_start);
836 // Check that prevchar = '\n' and current = 'f'. 897 // Check that prevchar = '\n' and current = 'f'.
837 m.CheckCharacter('\n', &newline); 898 m.CheckCharacter('\n', &newline);
838 m.Bind(&fail); 899 m.Bind(&fail);
839 m.Fail(); 900 m.Fail();
840 m.Bind(&newline); 901 m.Bind(&newline);
(...skipping 14 matching lines...) Expand all
855 Handle<String> source = Factory::NewStringFromAscii(CStrVector("(^f|ob)")); 916 Handle<String> source = Factory::NewStringFromAscii(CStrVector("(^f|ob)"));
856 Handle<Object> code_object = m.GetCode(source); 917 Handle<Object> code_object = m.GetCode(source);
857 Handle<Code> code = Handle<Code>::cast(code_object); 918 Handle<Code> code = Handle<Code>::cast(code_object);
858 919
859 Handle<String> input = Factory::NewStringFromAscii(CStrVector("foobar")); 920 Handle<String> input = Factory::NewStringFromAscii(CStrVector("foobar"));
860 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input); 921 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input);
861 Address start_adr = seq_input->GetCharsAddress(); 922 Address start_adr = seq_input->GetCharsAddress();
862 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input); 923 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input);
863 int end_offset = start_offset + seq_input->length(); 924 int end_offset = start_offset + seq_input->length();
864 925
865 bool success = RegExpMacroAssemblerIA32::Execute(*code, 926 RegExpMacroAssemblerIA32::Result result =
866 seq_input.location(), 927 RegExpMacroAssemblerIA32::Execute(*code,
867 start_offset, 928 seq_input.location(),
868 end_offset, 929 start_offset,
869 NULL, 930 end_offset,
870 true); 931 NULL,
932 true);
871 933
872 CHECK(success); 934 CHECK_EQ(RegExpMacroAssemblerIA32::SUCCESS, result);
873 935
874 start_offset += 3; 936 start_offset += 3;
875 success = RegExpMacroAssemblerIA32::Execute(*code, 937 result = RegExpMacroAssemblerIA32::Execute(*code,
876 seq_input.location(), 938 seq_input.location(),
877 start_offset, 939 start_offset,
878 end_offset, 940 end_offset,
879 NULL, 941 NULL,
880 false); 942 false);
881 943
882 CHECK(success); 944 CHECK_EQ(RegExpMacroAssemblerIA32::SUCCESS, result);
883 } 945 }
884 946
885 947
886 948
887 949
888 TEST(MacroAssemblerIA32BackRefNoCase) { 950 TEST(MacroAssemblerIA32BackRefNoCase) {
889 V8::Initialize(NULL); 951 v8::V8::Initialize();
890 952 ContextInitializer initializer;
891 // regexp-macro-assembler-ia32 needs a handle scope to allocate
892 // byte-arrays for constants.
893 v8::HandleScope scope;
894 953
895 RegExpMacroAssemblerIA32 m(RegExpMacroAssemblerIA32::ASCII, 4); 954 RegExpMacroAssemblerIA32 m(RegExpMacroAssemblerIA32::ASCII, 4);
896 955
897 Label fail, succ; 956 Label fail, succ;
898 957
899 m.WriteCurrentPositionToRegister(0, 0); 958 m.WriteCurrentPositionToRegister(0, 0);
900 m.WriteCurrentPositionToRegister(2, 0); 959 m.WriteCurrentPositionToRegister(2, 0);
901 m.AdvanceCurrentPosition(3); 960 m.AdvanceCurrentPosition(3);
902 m.WriteCurrentPositionToRegister(3, 0); 961 m.WriteCurrentPositionToRegister(3, 0);
903 m.CheckNotBackReferenceIgnoreCase(2, &fail); // Match "AbC". 962 m.CheckNotBackReferenceIgnoreCase(2, &fail); // Match "AbC".
(...skipping 18 matching lines...) Expand all
922 Handle<Code> code = Handle<Code>::cast(code_object); 981 Handle<Code> code = Handle<Code>::cast(code_object);
923 982
924 Handle<String> input = 983 Handle<String> input =
925 Factory::NewStringFromAscii(CStrVector("aBcAbCABCxYzab")); 984 Factory::NewStringFromAscii(CStrVector("aBcAbCABCxYzab"));
926 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input); 985 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input);
927 Address start_adr = seq_input->GetCharsAddress(); 986 Address start_adr = seq_input->GetCharsAddress();
928 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input); 987 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input);
929 int end_offset = start_offset + seq_input->length(); 988 int end_offset = start_offset + seq_input->length();
930 989
931 int output[4]; 990 int output[4];
932 bool success = RegExpMacroAssemblerIA32::Execute(*code, 991 RegExpMacroAssemblerIA32::Result result =
933 seq_input.location(), 992 RegExpMacroAssemblerIA32::Execute(*code,
934 start_offset, 993 seq_input.location(),
935 end_offset, 994 start_offset,
936 output, 995 end_offset,
937 true); 996 output,
997 true);
938 998
939 CHECK(success); 999 CHECK_EQ(RegExpMacroAssemblerIA32::SUCCESS, result);
940 CHECK_EQ(0, output[0]); 1000 CHECK_EQ(0, output[0]);
941 CHECK_EQ(12, output[1]); 1001 CHECK_EQ(12, output[1]);
942 CHECK_EQ(0, output[2]); 1002 CHECK_EQ(0, output[2]);
943 CHECK_EQ(3, output[3]); 1003 CHECK_EQ(3, output[3]);
944 } 1004 }
945 1005
946 1006
947 1007
948 TEST(MacroAssemblerIA32Registers) { 1008 TEST(MacroAssemblerIA32Registers) {
949 V8::Initialize(NULL); 1009 v8::V8::Initialize();
950 1010 ContextInitializer initializer;
951 // regexp-macro-assembler-ia32 needs a handle scope to allocate
952 // byte-arrays for constants.
953 v8::HandleScope scope;
954 1011
955 RegExpMacroAssemblerIA32 m(RegExpMacroAssemblerIA32::ASCII, 5); 1012 RegExpMacroAssemblerIA32 m(RegExpMacroAssemblerIA32::ASCII, 5);
956 1013
957 uc16 foo_chars[3] = {'f', 'o', 'o'}; 1014 uc16 foo_chars[3] = {'f', 'o', 'o'};
958 Vector<const uc16> foo(foo_chars, 3); 1015 Vector<const uc16> foo(foo_chars, 3);
959 1016
960 enum registers { out1, out2, out3, out4, out5, sp, loop_cnt }; 1017 enum registers { out1, out2, out3, out4, out5, sp, loop_cnt };
961 Label fail; 1018 Label fail;
962 Label backtrack; 1019 Label backtrack;
963 m.WriteCurrentPositionToRegister(out1, 0); // Output: [0] 1020 m.WriteCurrentPositionToRegister(out1, 0); // Output: [0]
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1025 1082
1026 // String long enough for test (content doesn't matter). 1083 // String long enough for test (content doesn't matter).
1027 Handle<String> input = 1084 Handle<String> input =
1028 Factory::NewStringFromAscii(CStrVector("foofoofoofoofoo")); 1085 Factory::NewStringFromAscii(CStrVector("foofoofoofoofoo"));
1029 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input); 1086 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input);
1030 Address start_adr = seq_input->GetCharsAddress(); 1087 Address start_adr = seq_input->GetCharsAddress();
1031 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input); 1088 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input);
1032 int end_offset = start_offset + seq_input->length(); 1089 int end_offset = start_offset + seq_input->length();
1033 1090
1034 int output[5]; 1091 int output[5];
1035 bool success = RegExpMacroAssemblerIA32::Execute(*code, 1092 RegExpMacroAssemblerIA32::Result result =
1036 seq_input.location(), 1093 RegExpMacroAssemblerIA32::Execute(*code,
1037 start_offset, 1094 seq_input.location(),
1038 end_offset, 1095 start_offset,
1039 output, 1096 end_offset,
1040 true); 1097 output,
1098 true);
1041 1099
1042 CHECK(success); 1100 CHECK_EQ(RegExpMacroAssemblerIA32::SUCCESS, result);
1043 CHECK_EQ(0, output[0]); 1101 CHECK_EQ(0, output[0]);
1044 CHECK_EQ(3, output[1]); 1102 CHECK_EQ(3, output[1]);
1045 CHECK_EQ(6, output[2]); 1103 CHECK_EQ(6, output[2]);
1046 CHECK_EQ(9, output[3]); 1104 CHECK_EQ(9, output[3]);
1047 CHECK_EQ(9, output[4]); 1105 CHECK_EQ(9, output[4]);
1048 } 1106 }
1049 1107
1108
1109 TEST(MacroAssemblerIA32StackOverflow) {
1110 v8::V8::Initialize();
1111 ContextInitializer initializer;
1112
1113 RegExpMacroAssemblerIA32 m(RegExpMacroAssemblerIA32::ASCII, 0);
1114
1115 Label loop;
1116 m.Bind(&loop);
1117 m.PushBacktrack(&loop);
1118 m.GoTo(&loop);
1119
1120 Handle<String> source =
1121 Factory::NewStringFromAscii(CStrVector("<stack overflow test>"));
1122 Handle<Object> code_object = m.GetCode(source);
1123 Handle<Code> code = Handle<Code>::cast(code_object);
1124
1125 // String long enough for test (content doesn't matter).
1126 Handle<String> input =
1127 Factory::NewStringFromAscii(CStrVector("dummy"));
1128 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input);
1129 Address start_adr = seq_input->GetCharsAddress();
1130 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input);
1131 int end_offset = start_offset + seq_input->length();
1132
1133 RegExpMacroAssemblerIA32::Result result =
1134 RegExpMacroAssemblerIA32::Execute(*code,
1135 seq_input.location(),
1136 start_offset,
1137 end_offset,
1138 NULL,
1139 true);
1140
1141 CHECK_EQ(RegExpMacroAssemblerIA32::EXCEPTION, result);
1142 CHECK(Top::has_pending_exception());
1143 Top::clear_pending_exception();
1144 }
1145
1146
1050 #endif // !defined ARM 1147 #endif // !defined ARM
1051 1148
1052 TEST(AddInverseToTable) { 1149 TEST(AddInverseToTable) {
1053 static const int kLimit = 1000; 1150 static const int kLimit = 1000;
1054 static const int kRangeCount = 16; 1151 static const int kRangeCount = 16;
1055 for (int t = 0; t < 10; t++) { 1152 for (int t = 0; t < 10; t++) {
1056 ZoneScope zone_scope(DELETE_ON_EXIT); 1153 ZoneScope zone_scope(DELETE_ON_EXIT);
1057 ZoneList<CharacterRange>* ranges = 1154 ZoneList<CharacterRange>* ranges =
1058 new ZoneList<CharacterRange>(kRangeCount); 1155 new ZoneList<CharacterRange>(kRangeCount);
1059 for (int i = 0; i < kRangeCount; i++) { 1156 for (int i = 0; i < kRangeCount; i++) {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1121 upper[0] = c; 1218 upper[0] = c;
1122 } 1219 }
1123 uc32 u = upper[0]; 1220 uc32 u = upper[0];
1124 if (length > 1 || (c >= 128 && u < 128)) 1221 if (length > 1 || (c >= 128 && u < 128))
1125 u = c; 1222 u = c;
1126 CHECK_EQ(u, canonicalize(c)); 1223 CHECK_EQ(u, canonicalize(c));
1127 } 1224 }
1128 } 1225 }
1129 1226
1130 1227
1131 TEST(SimplePropagation) {
1132 v8::HandleScope scope;
1133 ZoneScope zone_scope(DELETE_ON_EXIT);
1134 RegExpNode* node = Compile("(a|^b|c)", false, true);
1135 CHECK(node->info()->follows_start_interest);
1136 }
1137
1138
1139 static uc32 CanonRange(uc32 c) { 1228 static uc32 CanonRange(uc32 c) {
1140 unibrow::uchar canon[unibrow::CanonicalizationRange::kMaxWidth]; 1229 unibrow::uchar canon[unibrow::CanonicalizationRange::kMaxWidth];
1141 int count = unibrow::CanonicalizationRange::Convert(c, '\0', canon, NULL); 1230 int count = unibrow::CanonicalizationRange::Convert(c, '\0', canon, NULL);
1142 if (count == 0) { 1231 if (count == 0) {
1143 return c; 1232 return c;
1144 } else { 1233 } else {
1145 CHECK_EQ(1, count); 1234 CHECK_EQ(1, count);
1146 return canon[0]; 1235 return canon[0];
1147 } 1236 }
1148 } 1237 }
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
1294 } else { 1383 } else {
1295 CHECK(!InClass(i, included)); 1384 CHECK(!InClass(i, included));
1296 CHECK(!InClass(i, excluded)); 1385 CHECK(!InClass(i, excluded));
1297 } 1386 }
1298 } 1387 }
1299 } 1388 }
1300 1389
1301 1390
1302 TEST(Graph) { 1391 TEST(Graph) {
1303 V8::Initialize(NULL); 1392 V8::Initialize(NULL);
1304 Execute("(?=[d#.])", false, true, true); 1393 Execute("\\bboy\\b", false, true, true);
1305 } 1394 }
OLDNEW
« no previous file with comments | « test/cctest/test-mark-compact.cc ('k') | test/mjsunit/switch.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698