OLD | NEW |
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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 #endif | 55 #endif |
56 #endif // V8_INTERPRETED_REGEXP | 56 #endif // V8_INTERPRETED_REGEXP |
57 | 57 |
58 using namespace v8::internal; | 58 using namespace v8::internal; |
59 | 59 |
60 | 60 |
61 static bool CheckParse(const char* input) { | 61 static bool CheckParse(const char* input) { |
62 V8::Initialize(NULL); | 62 V8::Initialize(NULL); |
63 v8::HandleScope scope; | 63 v8::HandleScope scope; |
64 ZoneScope zone_scope(DELETE_ON_EXIT); | 64 ZoneScope zone_scope(DELETE_ON_EXIT); |
65 FlatStringReader reader(CStrVector(input)); | 65 FlatStringReader reader(Isolate::Current(), CStrVector(input)); |
66 RegExpCompileData result; | 66 RegExpCompileData result; |
67 return v8::internal::RegExpParser::ParseRegExp(&reader, false, &result); | 67 return v8::internal::RegExpParser::ParseRegExp(&reader, false, &result); |
68 } | 68 } |
69 | 69 |
70 | 70 |
71 static SmartPointer<const char> Parse(const char* input) { | 71 static SmartPointer<const char> Parse(const char* input) { |
72 V8::Initialize(NULL); | 72 V8::Initialize(NULL); |
73 v8::HandleScope scope; | 73 v8::HandleScope scope; |
74 ZoneScope zone_scope(DELETE_ON_EXIT); | 74 ZoneScope zone_scope(DELETE_ON_EXIT); |
75 FlatStringReader reader(CStrVector(input)); | 75 FlatStringReader reader(Isolate::Current(), CStrVector(input)); |
76 RegExpCompileData result; | 76 RegExpCompileData result; |
77 CHECK(v8::internal::RegExpParser::ParseRegExp(&reader, false, &result)); | 77 CHECK(v8::internal::RegExpParser::ParseRegExp(&reader, false, &result)); |
78 CHECK(result.tree != NULL); | 78 CHECK(result.tree != NULL); |
79 CHECK(result.error.is_null()); | 79 CHECK(result.error.is_null()); |
80 SmartPointer<const char> output = result.tree->ToString(); | 80 SmartPointer<const char> output = result.tree->ToString(); |
81 return output; | 81 return output; |
82 } | 82 } |
83 | 83 |
84 static bool CheckSimple(const char* input) { | 84 static bool CheckSimple(const char* input) { |
85 V8::Initialize(NULL); | 85 V8::Initialize(NULL); |
86 v8::HandleScope scope; | 86 v8::HandleScope scope; |
87 unibrow::Utf8InputBuffer<> buffer(input, StrLength(input)); | 87 unibrow::Utf8InputBuffer<> buffer(input, StrLength(input)); |
88 ZoneScope zone_scope(DELETE_ON_EXIT); | 88 ZoneScope zone_scope(DELETE_ON_EXIT); |
89 FlatStringReader reader(CStrVector(input)); | 89 FlatStringReader reader(Isolate::Current(), CStrVector(input)); |
90 RegExpCompileData result; | 90 RegExpCompileData result; |
91 CHECK(v8::internal::RegExpParser::ParseRegExp(&reader, false, &result)); | 91 CHECK(v8::internal::RegExpParser::ParseRegExp(&reader, false, &result)); |
92 CHECK(result.tree != NULL); | 92 CHECK(result.tree != NULL); |
93 CHECK(result.error.is_null()); | 93 CHECK(result.error.is_null()); |
94 return result.simple; | 94 return result.simple; |
95 } | 95 } |
96 | 96 |
97 struct MinMaxPair { | 97 struct MinMaxPair { |
98 int min_match; | 98 int min_match; |
99 int max_match; | 99 int max_match; |
100 }; | 100 }; |
101 | 101 |
102 static MinMaxPair CheckMinMaxMatch(const char* input) { | 102 static MinMaxPair CheckMinMaxMatch(const char* input) { |
103 V8::Initialize(NULL); | 103 V8::Initialize(NULL); |
104 v8::HandleScope scope; | 104 v8::HandleScope scope; |
105 unibrow::Utf8InputBuffer<> buffer(input, StrLength(input)); | 105 unibrow::Utf8InputBuffer<> buffer(input, StrLength(input)); |
106 ZoneScope zone_scope(DELETE_ON_EXIT); | 106 ZoneScope zone_scope(DELETE_ON_EXIT); |
107 FlatStringReader reader(CStrVector(input)); | 107 FlatStringReader reader(Isolate::Current(), CStrVector(input)); |
108 RegExpCompileData result; | 108 RegExpCompileData result; |
109 CHECK(v8::internal::RegExpParser::ParseRegExp(&reader, false, &result)); | 109 CHECK(v8::internal::RegExpParser::ParseRegExp(&reader, false, &result)); |
110 CHECK(result.tree != NULL); | 110 CHECK(result.tree != NULL); |
111 CHECK(result.error.is_null()); | 111 CHECK(result.error.is_null()); |
112 int min_match = result.tree->min_match(); | 112 int min_match = result.tree->min_match(); |
113 int max_match = result.tree->max_match(); | 113 int max_match = result.tree->max_match(); |
114 MinMaxPair pair = { min_match, max_match }; | 114 MinMaxPair pair = { min_match, max_match }; |
115 return pair; | 115 return pair; |
116 } | 116 } |
117 | 117 |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 CHECK_PARSE_EQ("a{3,4*}", "(: 'a{3,' (# 0 - g '4') '}')"); | 368 CHECK_PARSE_EQ("a{3,4*}", "(: 'a{3,' (# 0 - g '4') '}')"); |
369 CHECK_PARSE_EQ("{", "'{'"); | 369 CHECK_PARSE_EQ("{", "'{'"); |
370 CHECK_PARSE_EQ("a|", "(| 'a' %)"); | 370 CHECK_PARSE_EQ("a|", "(| 'a' %)"); |
371 } | 371 } |
372 | 372 |
373 static void ExpectError(const char* input, | 373 static void ExpectError(const char* input, |
374 const char* expected) { | 374 const char* expected) { |
375 V8::Initialize(NULL); | 375 V8::Initialize(NULL); |
376 v8::HandleScope scope; | 376 v8::HandleScope scope; |
377 ZoneScope zone_scope(DELETE_ON_EXIT); | 377 ZoneScope zone_scope(DELETE_ON_EXIT); |
378 FlatStringReader reader(CStrVector(input)); | 378 FlatStringReader reader(Isolate::Current(), CStrVector(input)); |
379 RegExpCompileData result; | 379 RegExpCompileData result; |
380 CHECK(!v8::internal::RegExpParser::ParseRegExp(&reader, false, &result)); | 380 CHECK(!v8::internal::RegExpParser::ParseRegExp(&reader, false, &result)); |
381 CHECK(result.tree == NULL); | 381 CHECK(result.tree == NULL); |
382 CHECK(!result.error.is_null()); | 382 CHECK(!result.error.is_null()); |
383 SmartPointer<char> str = result.error->ToCString(ALLOW_NULLS); | 383 SmartPointer<char> str = result.error->ToCString(ALLOW_NULLS); |
384 CHECK_EQ(expected, *str); | 384 CHECK_EQ(expected, *str); |
385 } | 385 } |
386 | 386 |
387 | 387 |
388 TEST(Errors) { | 388 TEST(Errors) { |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 for (int j = 0; !in_class && j < ranges->length(); j++) { | 464 for (int j = 0; !in_class && j < ranges->length(); j++) { |
465 CharacterRange& range = ranges->at(j); | 465 CharacterRange& range = ranges->at(j); |
466 in_class = (range.from() <= i && i <= range.to()); | 466 in_class = (range.from() <= i && i <= range.to()); |
467 } | 467 } |
468 CHECK_EQ(pred(i), in_class); | 468 CHECK_EQ(pred(i), in_class); |
469 } | 469 } |
470 } | 470 } |
471 | 471 |
472 | 472 |
473 TEST(CharacterClassEscapes) { | 473 TEST(CharacterClassEscapes) { |
| 474 v8::internal::V8::Initialize(NULL); |
474 TestCharacterClassEscapes('.', IsRegExpNewline); | 475 TestCharacterClassEscapes('.', IsRegExpNewline); |
475 TestCharacterClassEscapes('d', IsDigit); | 476 TestCharacterClassEscapes('d', IsDigit); |
476 TestCharacterClassEscapes('D', NotDigit); | 477 TestCharacterClassEscapes('D', NotDigit); |
477 TestCharacterClassEscapes('s', IsWhiteSpace); | 478 TestCharacterClassEscapes('s', IsWhiteSpace); |
478 TestCharacterClassEscapes('S', NotWhiteSpace); | 479 TestCharacterClassEscapes('S', NotWhiteSpace); |
479 TestCharacterClassEscapes('w', IsRegExpWord); | 480 TestCharacterClassEscapes('w', IsRegExpWord); |
480 TestCharacterClassEscapes('W', NotWord); | 481 TestCharacterClassEscapes('W', NotWord); |
481 } | 482 } |
482 | 483 |
483 | 484 |
484 static RegExpNode* Compile(const char* input, bool multiline, bool is_ascii) { | 485 static RegExpNode* Compile(const char* input, bool multiline, bool is_ascii) { |
485 V8::Initialize(NULL); | 486 V8::Initialize(NULL); |
486 FlatStringReader reader(CStrVector(input)); | 487 FlatStringReader reader(Isolate::Current(), CStrVector(input)); |
487 RegExpCompileData compile_data; | 488 RegExpCompileData compile_data; |
488 if (!v8::internal::RegExpParser::ParseRegExp(&reader, multiline, | 489 if (!v8::internal::RegExpParser::ParseRegExp(&reader, multiline, |
489 &compile_data)) | 490 &compile_data)) |
490 return NULL; | 491 return NULL; |
491 Handle<String> pattern = Factory::NewStringFromUtf8(CStrVector(input)); | 492 Handle<String> pattern = FACTORY->NewStringFromUtf8(CStrVector(input)); |
492 RegExpEngine::Compile(&compile_data, false, multiline, pattern, is_ascii); | 493 RegExpEngine::Compile(&compile_data, false, multiline, pattern, is_ascii); |
493 return compile_data.node; | 494 return compile_data.node; |
494 } | 495 } |
495 | 496 |
496 | 497 |
497 static void Execute(const char* input, | 498 static void Execute(const char* input, |
498 bool multiline, | 499 bool multiline, |
499 bool is_ascii, | 500 bool is_ascii, |
500 bool dot_output = false) { | 501 bool dot_output = false) { |
501 v8::HandleScope scope; | 502 v8::HandleScope scope; |
(...skipping 29 matching lines...) Expand all Loading... |
531 const int TestConfig::kNoKey = 0; | 532 const int TestConfig::kNoKey = 0; |
532 const int TestConfig::kNoValue = 0; | 533 const int TestConfig::kNoValue = 0; |
533 | 534 |
534 | 535 |
535 static unsigned PseudoRandom(int i, int j) { | 536 static unsigned PseudoRandom(int i, int j) { |
536 return ~(~((i * 781) ^ (j * 329))); | 537 return ~(~((i * 781) ^ (j * 329))); |
537 } | 538 } |
538 | 539 |
539 | 540 |
540 TEST(SplayTreeSimple) { | 541 TEST(SplayTreeSimple) { |
| 542 v8::internal::V8::Initialize(NULL); |
541 static const unsigned kLimit = 1000; | 543 static const unsigned kLimit = 1000; |
542 ZoneScope zone_scope(DELETE_ON_EXIT); | 544 ZoneScope zone_scope(DELETE_ON_EXIT); |
543 ZoneSplayTree<TestConfig> tree; | 545 ZoneSplayTree<TestConfig> tree; |
544 bool seen[kLimit]; | 546 bool seen[kLimit]; |
545 for (unsigned i = 0; i < kLimit; i++) seen[i] = false; | 547 for (unsigned i = 0; i < kLimit; i++) seen[i] = false; |
546 #define CHECK_MAPS_EQUAL() do { \ | 548 #define CHECK_MAPS_EQUAL() do { \ |
547 for (unsigned k = 0; k < kLimit; k++) \ | 549 for (unsigned k = 0; k < kLimit; k++) \ |
548 CHECK_EQ(seen[k], tree.Find(k, &loc)); \ | 550 CHECK_EQ(seen[k], tree.Find(k, &loc)); \ |
549 } while (false) | 551 } while (false) |
550 for (int i = 0; i < 50; i++) { | 552 for (int i = 0; i < 50; i++) { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
583 CHECK(tree.FindLeastGreaterThan(val, &loc)); | 585 CHECK(tree.FindLeastGreaterThan(val, &loc)); |
584 CHECK_EQ(loc.key(), val); | 586 CHECK_EQ(loc.key(), val); |
585 break; | 587 break; |
586 } | 588 } |
587 } | 589 } |
588 } | 590 } |
589 } | 591 } |
590 | 592 |
591 | 593 |
592 TEST(DispatchTableConstruction) { | 594 TEST(DispatchTableConstruction) { |
| 595 v8::internal::V8::Initialize(NULL); |
593 // Initialize test data. | 596 // Initialize test data. |
594 static const int kLimit = 1000; | 597 static const int kLimit = 1000; |
595 static const int kRangeCount = 8; | 598 static const int kRangeCount = 8; |
596 static const int kRangeSize = 16; | 599 static const int kRangeSize = 16; |
597 uc16 ranges[kRangeCount][2 * kRangeSize]; | 600 uc16 ranges[kRangeCount][2 * kRangeSize]; |
598 for (int i = 0; i < kRangeCount; i++) { | 601 for (int i = 0; i < kRangeCount; i++) { |
599 Vector<uc16> range(ranges[i], 2 * kRangeSize); | 602 Vector<uc16> range(ranges[i], 2 * kRangeSize); |
600 for (int j = 0; j < 2 * kRangeSize; j++) { | 603 for (int j = 0; j < 2 * kRangeSize; j++) { |
601 range[j] = PseudoRandom(i + 25, j + 87) % kLimit; | 604 range[j] = PseudoRandom(i + 25, j + 87) % kLimit; |
602 } | 605 } |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
666 typedef RegExpMacroAssemblerX64 ArchRegExpMacroAssembler; | 669 typedef RegExpMacroAssemblerX64 ArchRegExpMacroAssembler; |
667 #elif V8_TARGET_ARCH_ARM | 670 #elif V8_TARGET_ARCH_ARM |
668 typedef RegExpMacroAssemblerARM ArchRegExpMacroAssembler; | 671 typedef RegExpMacroAssemblerARM ArchRegExpMacroAssembler; |
669 #elif V8_TARGET_ARCH_MIPS | 672 #elif V8_TARGET_ARCH_MIPS |
670 typedef RegExpMacroAssembler ArchRegExpMacroAssembler; | 673 typedef RegExpMacroAssembler ArchRegExpMacroAssembler; |
671 #endif | 674 #endif |
672 | 675 |
673 class ContextInitializer { | 676 class ContextInitializer { |
674 public: | 677 public: |
675 ContextInitializer() | 678 ContextInitializer() |
676 : env_(), scope_(), zone_(DELETE_ON_EXIT), stack_guard_() { | 679 : env_(), scope_(), zone_(DELETE_ON_EXIT) { |
677 env_ = v8::Context::New(); | 680 env_ = v8::Context::New(); |
678 env_->Enter(); | 681 env_->Enter(); |
679 } | 682 } |
680 ~ContextInitializer() { | 683 ~ContextInitializer() { |
681 env_->Exit(); | 684 env_->Exit(); |
682 env_.Dispose(); | 685 env_.Dispose(); |
683 } | 686 } |
684 private: | 687 private: |
685 v8::Persistent<v8::Context> env_; | 688 v8::Persistent<v8::Context> env_; |
686 v8::HandleScope scope_; | 689 v8::HandleScope scope_; |
687 v8::internal::ZoneScope zone_; | 690 v8::internal::ZoneScope zone_; |
688 v8::internal::StackGuard stack_guard_; | |
689 }; | 691 }; |
690 | 692 |
691 | 693 |
692 static ArchRegExpMacroAssembler::Result Execute(Code* code, | 694 static ArchRegExpMacroAssembler::Result Execute(Code* code, |
693 String* input, | 695 String* input, |
694 int start_offset, | 696 int start_offset, |
695 const byte* input_start, | 697 const byte* input_start, |
696 const byte* input_end, | 698 const byte* input_end, |
697 int* captures) { | 699 int* captures) { |
698 return NativeRegExpMacroAssembler::Execute( | 700 return NativeRegExpMacroAssembler::Execute( |
699 code, | 701 code, |
700 input, | 702 input, |
701 start_offset, | 703 start_offset, |
702 input_start, | 704 input_start, |
703 input_end, | 705 input_end, |
704 captures); | 706 captures, |
| 707 Isolate::Current()); |
705 } | 708 } |
706 | 709 |
707 | 710 |
708 TEST(MacroAssemblerNativeSuccess) { | 711 TEST(MacroAssemblerNativeSuccess) { |
709 v8::V8::Initialize(); | 712 v8::V8::Initialize(); |
710 ContextInitializer initializer; | 713 ContextInitializer initializer; |
711 | 714 |
712 ArchRegExpMacroAssembler m(NativeRegExpMacroAssembler::ASCII, 4); | 715 ArchRegExpMacroAssembler m(NativeRegExpMacroAssembler::ASCII, 4); |
713 | 716 |
714 m.Succeed(); | 717 m.Succeed(); |
715 | 718 |
716 Handle<String> source = Factory::NewStringFromAscii(CStrVector("")); | 719 Handle<String> source = FACTORY->NewStringFromAscii(CStrVector("")); |
717 Handle<Object> code_object = m.GetCode(source); | 720 Handle<Object> code_object = m.GetCode(source); |
718 Handle<Code> code = Handle<Code>::cast(code_object); | 721 Handle<Code> code = Handle<Code>::cast(code_object); |
719 | 722 |
720 int captures[4] = {42, 37, 87, 117}; | 723 int captures[4] = {42, 37, 87, 117}; |
721 Handle<String> input = Factory::NewStringFromAscii(CStrVector("foofoo")); | 724 Handle<String> input = FACTORY->NewStringFromAscii(CStrVector("foofoo")); |
722 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input); | 725 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input); |
723 const byte* start_adr = | 726 const byte* start_adr = |
724 reinterpret_cast<const byte*>(seq_input->GetCharsAddress()); | 727 reinterpret_cast<const byte*>(seq_input->GetCharsAddress()); |
725 | 728 |
726 NativeRegExpMacroAssembler::Result result = | 729 NativeRegExpMacroAssembler::Result result = |
727 Execute(*code, | 730 Execute(*code, |
728 *input, | 731 *input, |
729 0, | 732 0, |
730 start_adr, | 733 start_adr, |
731 start_adr + seq_input->length(), | 734 start_adr + seq_input->length(), |
(...skipping 18 matching lines...) Expand all Loading... |
750 | 753 |
751 Label fail; | 754 Label fail; |
752 m.CheckCharacters(foo, 0, &fail, true); | 755 m.CheckCharacters(foo, 0, &fail, true); |
753 m.WriteCurrentPositionToRegister(0, 0); | 756 m.WriteCurrentPositionToRegister(0, 0); |
754 m.AdvanceCurrentPosition(3); | 757 m.AdvanceCurrentPosition(3); |
755 m.WriteCurrentPositionToRegister(1, 0); | 758 m.WriteCurrentPositionToRegister(1, 0); |
756 m.Succeed(); | 759 m.Succeed(); |
757 m.Bind(&fail); | 760 m.Bind(&fail); |
758 m.Fail(); | 761 m.Fail(); |
759 | 762 |
760 Handle<String> source = Factory::NewStringFromAscii(CStrVector("^foo")); | 763 Handle<String> source = FACTORY->NewStringFromAscii(CStrVector("^foo")); |
761 Handle<Object> code_object = m.GetCode(source); | 764 Handle<Object> code_object = m.GetCode(source); |
762 Handle<Code> code = Handle<Code>::cast(code_object); | 765 Handle<Code> code = Handle<Code>::cast(code_object); |
763 | 766 |
764 int captures[4] = {42, 37, 87, 117}; | 767 int captures[4] = {42, 37, 87, 117}; |
765 Handle<String> input = Factory::NewStringFromAscii(CStrVector("foofoo")); | 768 Handle<String> input = FACTORY->NewStringFromAscii(CStrVector("foofoo")); |
766 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input); | 769 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input); |
767 Address start_adr = seq_input->GetCharsAddress(); | 770 Address start_adr = seq_input->GetCharsAddress(); |
768 | 771 |
769 NativeRegExpMacroAssembler::Result result = | 772 NativeRegExpMacroAssembler::Result result = |
770 Execute(*code, | 773 Execute(*code, |
771 *input, | 774 *input, |
772 0, | 775 0, |
773 start_adr, | 776 start_adr, |
774 start_adr + input->length(), | 777 start_adr + input->length(), |
775 captures); | 778 captures); |
776 | 779 |
777 CHECK_EQ(NativeRegExpMacroAssembler::SUCCESS, result); | 780 CHECK_EQ(NativeRegExpMacroAssembler::SUCCESS, result); |
778 CHECK_EQ(0, captures[0]); | 781 CHECK_EQ(0, captures[0]); |
779 CHECK_EQ(3, captures[1]); | 782 CHECK_EQ(3, captures[1]); |
780 CHECK_EQ(-1, captures[2]); | 783 CHECK_EQ(-1, captures[2]); |
781 CHECK_EQ(-1, captures[3]); | 784 CHECK_EQ(-1, captures[3]); |
782 | 785 |
783 input = Factory::NewStringFromAscii(CStrVector("barbarbar")); | 786 input = FACTORY->NewStringFromAscii(CStrVector("barbarbar")); |
784 seq_input = Handle<SeqAsciiString>::cast(input); | 787 seq_input = Handle<SeqAsciiString>::cast(input); |
785 start_adr = seq_input->GetCharsAddress(); | 788 start_adr = seq_input->GetCharsAddress(); |
786 | 789 |
787 result = Execute(*code, | 790 result = Execute(*code, |
788 *input, | 791 *input, |
789 0, | 792 0, |
790 start_adr, | 793 start_adr, |
791 start_adr + input->length(), | 794 start_adr + input->length(), |
792 captures); | 795 captures); |
793 | 796 |
(...skipping 12 matching lines...) Expand all Loading... |
806 | 809 |
807 Label fail; | 810 Label fail; |
808 m.CheckCharacters(foo, 0, &fail, true); | 811 m.CheckCharacters(foo, 0, &fail, true); |
809 m.WriteCurrentPositionToRegister(0, 0); | 812 m.WriteCurrentPositionToRegister(0, 0); |
810 m.AdvanceCurrentPosition(3); | 813 m.AdvanceCurrentPosition(3); |
811 m.WriteCurrentPositionToRegister(1, 0); | 814 m.WriteCurrentPositionToRegister(1, 0); |
812 m.Succeed(); | 815 m.Succeed(); |
813 m.Bind(&fail); | 816 m.Bind(&fail); |
814 m.Fail(); | 817 m.Fail(); |
815 | 818 |
816 Handle<String> source = Factory::NewStringFromAscii(CStrVector("^foo")); | 819 Handle<String> source = FACTORY->NewStringFromAscii(CStrVector("^foo")); |
817 Handle<Object> code_object = m.GetCode(source); | 820 Handle<Object> code_object = m.GetCode(source); |
818 Handle<Code> code = Handle<Code>::cast(code_object); | 821 Handle<Code> code = Handle<Code>::cast(code_object); |
819 | 822 |
820 int captures[4] = {42, 37, 87, 117}; | 823 int captures[4] = {42, 37, 87, 117}; |
821 const uc16 input_data[6] = {'f', 'o', 'o', 'f', 'o', '\xa0'}; | 824 const uc16 input_data[6] = {'f', 'o', 'o', 'f', 'o', '\xa0'}; |
822 Handle<String> input = | 825 Handle<String> input = |
823 Factory::NewStringFromTwoByte(Vector<const uc16>(input_data, 6)); | 826 FACTORY->NewStringFromTwoByte(Vector<const uc16>(input_data, 6)); |
824 Handle<SeqTwoByteString> seq_input = Handle<SeqTwoByteString>::cast(input); | 827 Handle<SeqTwoByteString> seq_input = Handle<SeqTwoByteString>::cast(input); |
825 Address start_adr = seq_input->GetCharsAddress(); | 828 Address start_adr = seq_input->GetCharsAddress(); |
826 | 829 |
827 NativeRegExpMacroAssembler::Result result = | 830 NativeRegExpMacroAssembler::Result result = |
828 Execute(*code, | 831 Execute(*code, |
829 *input, | 832 *input, |
830 0, | 833 0, |
831 start_adr, | 834 start_adr, |
832 start_adr + input->length(), | 835 start_adr + input->length(), |
833 captures); | 836 captures); |
834 | 837 |
835 CHECK_EQ(NativeRegExpMacroAssembler::SUCCESS, result); | 838 CHECK_EQ(NativeRegExpMacroAssembler::SUCCESS, result); |
836 CHECK_EQ(0, captures[0]); | 839 CHECK_EQ(0, captures[0]); |
837 CHECK_EQ(3, captures[1]); | 840 CHECK_EQ(3, captures[1]); |
838 CHECK_EQ(-1, captures[2]); | 841 CHECK_EQ(-1, captures[2]); |
839 CHECK_EQ(-1, captures[3]); | 842 CHECK_EQ(-1, captures[3]); |
840 | 843 |
841 const uc16 input_data2[9] = {'b', 'a', 'r', 'b', 'a', 'r', 'b', 'a', '\xa0'}; | 844 const uc16 input_data2[9] = {'b', 'a', 'r', 'b', 'a', 'r', 'b', 'a', '\xa0'}; |
842 input = Factory::NewStringFromTwoByte(Vector<const uc16>(input_data2, 9)); | 845 input = FACTORY->NewStringFromTwoByte(Vector<const uc16>(input_data2, 9)); |
843 seq_input = Handle<SeqTwoByteString>::cast(input); | 846 seq_input = Handle<SeqTwoByteString>::cast(input); |
844 start_adr = seq_input->GetCharsAddress(); | 847 start_adr = seq_input->GetCharsAddress(); |
845 | 848 |
846 result = Execute(*code, | 849 result = Execute(*code, |
847 *input, | 850 *input, |
848 0, | 851 0, |
849 start_adr, | 852 start_adr, |
850 start_adr + input->length() * 2, | 853 start_adr + input->length() * 2, |
851 captures); | 854 captures); |
852 | 855 |
(...skipping 11 matching lines...) Expand all Loading... |
864 Label backtrack; | 867 Label backtrack; |
865 m.LoadCurrentCharacter(10, &fail); | 868 m.LoadCurrentCharacter(10, &fail); |
866 m.Succeed(); | 869 m.Succeed(); |
867 m.Bind(&fail); | 870 m.Bind(&fail); |
868 m.PushBacktrack(&backtrack); | 871 m.PushBacktrack(&backtrack); |
869 m.LoadCurrentCharacter(10, NULL); | 872 m.LoadCurrentCharacter(10, NULL); |
870 m.Succeed(); | 873 m.Succeed(); |
871 m.Bind(&backtrack); | 874 m.Bind(&backtrack); |
872 m.Fail(); | 875 m.Fail(); |
873 | 876 |
874 Handle<String> source = Factory::NewStringFromAscii(CStrVector("..........")); | 877 Handle<String> source = FACTORY->NewStringFromAscii(CStrVector("..........")); |
875 Handle<Object> code_object = m.GetCode(source); | 878 Handle<Object> code_object = m.GetCode(source); |
876 Handle<Code> code = Handle<Code>::cast(code_object); | 879 Handle<Code> code = Handle<Code>::cast(code_object); |
877 | 880 |
878 Handle<String> input = Factory::NewStringFromAscii(CStrVector("foofoo")); | 881 Handle<String> input = FACTORY->NewStringFromAscii(CStrVector("foofoo")); |
879 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input); | 882 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input); |
880 Address start_adr = seq_input->GetCharsAddress(); | 883 Address start_adr = seq_input->GetCharsAddress(); |
881 | 884 |
882 NativeRegExpMacroAssembler::Result result = | 885 NativeRegExpMacroAssembler::Result result = |
883 Execute(*code, | 886 Execute(*code, |
884 *input, | 887 *input, |
885 0, | 888 0, |
886 start_adr, | 889 start_adr, |
887 start_adr + input->length(), | 890 start_adr + input->length(), |
888 NULL); | 891 NULL); |
(...skipping 16 matching lines...) Expand all Loading... |
905 m.Fail(); | 908 m.Fail(); |
906 m.Bind(&nomatch); | 909 m.Bind(&nomatch); |
907 m.AdvanceCurrentPosition(2); | 910 m.AdvanceCurrentPosition(2); |
908 Label missing_match; | 911 Label missing_match; |
909 m.CheckNotBackReference(0, &missing_match); | 912 m.CheckNotBackReference(0, &missing_match); |
910 m.WriteCurrentPositionToRegister(2, 0); | 913 m.WriteCurrentPositionToRegister(2, 0); |
911 m.Succeed(); | 914 m.Succeed(); |
912 m.Bind(&missing_match); | 915 m.Bind(&missing_match); |
913 m.Fail(); | 916 m.Fail(); |
914 | 917 |
915 Handle<String> source = Factory::NewStringFromAscii(CStrVector("^(..)..\1")); | 918 Handle<String> source = FACTORY->NewStringFromAscii(CStrVector("^(..)..\1")); |
916 Handle<Object> code_object = m.GetCode(source); | 919 Handle<Object> code_object = m.GetCode(source); |
917 Handle<Code> code = Handle<Code>::cast(code_object); | 920 Handle<Code> code = Handle<Code>::cast(code_object); |
918 | 921 |
919 Handle<String> input = Factory::NewStringFromAscii(CStrVector("fooofo")); | 922 Handle<String> input = FACTORY->NewStringFromAscii(CStrVector("fooofo")); |
920 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input); | 923 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input); |
921 Address start_adr = seq_input->GetCharsAddress(); | 924 Address start_adr = seq_input->GetCharsAddress(); |
922 | 925 |
923 int output[4]; | 926 int output[4]; |
924 NativeRegExpMacroAssembler::Result result = | 927 NativeRegExpMacroAssembler::Result result = |
925 Execute(*code, | 928 Execute(*code, |
926 *input, | 929 *input, |
927 0, | 930 0, |
928 start_adr, | 931 start_adr, |
929 start_adr + input->length(), | 932 start_adr + input->length(), |
(...skipping 21 matching lines...) Expand all Loading... |
951 m.Fail(); | 954 m.Fail(); |
952 m.Bind(&nomatch); | 955 m.Bind(&nomatch); |
953 m.AdvanceCurrentPosition(2); | 956 m.AdvanceCurrentPosition(2); |
954 Label missing_match; | 957 Label missing_match; |
955 m.CheckNotBackReference(0, &missing_match); | 958 m.CheckNotBackReference(0, &missing_match); |
956 m.WriteCurrentPositionToRegister(2, 0); | 959 m.WriteCurrentPositionToRegister(2, 0); |
957 m.Succeed(); | 960 m.Succeed(); |
958 m.Bind(&missing_match); | 961 m.Bind(&missing_match); |
959 m.Fail(); | 962 m.Fail(); |
960 | 963 |
961 Handle<String> source = Factory::NewStringFromAscii(CStrVector("^(..)..\1")); | 964 Handle<String> source = FACTORY->NewStringFromAscii(CStrVector("^(..)..\1")); |
962 Handle<Object> code_object = m.GetCode(source); | 965 Handle<Object> code_object = m.GetCode(source); |
963 Handle<Code> code = Handle<Code>::cast(code_object); | 966 Handle<Code> code = Handle<Code>::cast(code_object); |
964 | 967 |
965 const uc16 input_data[6] = {'f', 0x2028, 'o', 'o', 'f', 0x2028}; | 968 const uc16 input_data[6] = {'f', 0x2028, 'o', 'o', 'f', 0x2028}; |
966 Handle<String> input = | 969 Handle<String> input = |
967 Factory::NewStringFromTwoByte(Vector<const uc16>(input_data, 6)); | 970 FACTORY->NewStringFromTwoByte(Vector<const uc16>(input_data, 6)); |
968 Handle<SeqTwoByteString> seq_input = Handle<SeqTwoByteString>::cast(input); | 971 Handle<SeqTwoByteString> seq_input = Handle<SeqTwoByteString>::cast(input); |
969 Address start_adr = seq_input->GetCharsAddress(); | 972 Address start_adr = seq_input->GetCharsAddress(); |
970 | 973 |
971 int output[4]; | 974 int output[4]; |
972 NativeRegExpMacroAssembler::Result result = | 975 NativeRegExpMacroAssembler::Result result = |
973 Execute(*code, | 976 Execute(*code, |
974 *input, | 977 *input, |
975 0, | 978 0, |
976 start_adr, | 979 start_adr, |
977 start_adr + input->length() * 2, | 980 start_adr + input->length() * 2, |
(...skipping 28 matching lines...) Expand all Loading... |
1006 m.Bind(¬_at_start); | 1009 m.Bind(¬_at_start); |
1007 // Check that prevchar = 'o' and current = 'b'. | 1010 // Check that prevchar = 'o' and current = 'b'. |
1008 Label prevo; | 1011 Label prevo; |
1009 m.CheckCharacter('o', &prevo); | 1012 m.CheckCharacter('o', &prevo); |
1010 m.Fail(); | 1013 m.Fail(); |
1011 m.Bind(&prevo); | 1014 m.Bind(&prevo); |
1012 m.LoadCurrentCharacter(0, &fail); | 1015 m.LoadCurrentCharacter(0, &fail); |
1013 m.CheckNotCharacter('b', &fail); | 1016 m.CheckNotCharacter('b', &fail); |
1014 m.Succeed(); | 1017 m.Succeed(); |
1015 | 1018 |
1016 Handle<String> source = Factory::NewStringFromAscii(CStrVector("(^f|ob)")); | 1019 Handle<String> source = FACTORY->NewStringFromAscii(CStrVector("(^f|ob)")); |
1017 Handle<Object> code_object = m.GetCode(source); | 1020 Handle<Object> code_object = m.GetCode(source); |
1018 Handle<Code> code = Handle<Code>::cast(code_object); | 1021 Handle<Code> code = Handle<Code>::cast(code_object); |
1019 | 1022 |
1020 Handle<String> input = Factory::NewStringFromAscii(CStrVector("foobar")); | 1023 Handle<String> input = FACTORY->NewStringFromAscii(CStrVector("foobar")); |
1021 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input); | 1024 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input); |
1022 Address start_adr = seq_input->GetCharsAddress(); | 1025 Address start_adr = seq_input->GetCharsAddress(); |
1023 | 1026 |
1024 NativeRegExpMacroAssembler::Result result = | 1027 NativeRegExpMacroAssembler::Result result = |
1025 Execute(*code, | 1028 Execute(*code, |
1026 *input, | 1029 *input, |
1027 0, | 1030 0, |
1028 start_adr, | 1031 start_adr, |
1029 start_adr + input->length(), | 1032 start_adr + input->length(), |
1030 NULL); | 1033 NULL); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1064 m.Bind(&expected_fail); | 1067 m.Bind(&expected_fail); |
1065 m.AdvanceCurrentPosition(3); // Skip "xYz" | 1068 m.AdvanceCurrentPosition(3); // Skip "xYz" |
1066 m.CheckNotBackReferenceIgnoreCase(2, &succ); | 1069 m.CheckNotBackReferenceIgnoreCase(2, &succ); |
1067 m.Fail(); | 1070 m.Fail(); |
1068 | 1071 |
1069 m.Bind(&succ); | 1072 m.Bind(&succ); |
1070 m.WriteCurrentPositionToRegister(1, 0); | 1073 m.WriteCurrentPositionToRegister(1, 0); |
1071 m.Succeed(); | 1074 m.Succeed(); |
1072 | 1075 |
1073 Handle<String> source = | 1076 Handle<String> source = |
1074 Factory::NewStringFromAscii(CStrVector("^(abc)\1\1(?!\1)...(?!\1)")); | 1077 FACTORY->NewStringFromAscii(CStrVector("^(abc)\1\1(?!\1)...(?!\1)")); |
1075 Handle<Object> code_object = m.GetCode(source); | 1078 Handle<Object> code_object = m.GetCode(source); |
1076 Handle<Code> code = Handle<Code>::cast(code_object); | 1079 Handle<Code> code = Handle<Code>::cast(code_object); |
1077 | 1080 |
1078 Handle<String> input = | 1081 Handle<String> input = |
1079 Factory::NewStringFromAscii(CStrVector("aBcAbCABCxYzab")); | 1082 FACTORY->NewStringFromAscii(CStrVector("aBcAbCABCxYzab")); |
1080 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input); | 1083 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input); |
1081 Address start_adr = seq_input->GetCharsAddress(); | 1084 Address start_adr = seq_input->GetCharsAddress(); |
1082 | 1085 |
1083 int output[4]; | 1086 int output[4]; |
1084 NativeRegExpMacroAssembler::Result result = | 1087 NativeRegExpMacroAssembler::Result result = |
1085 Execute(*code, | 1088 Execute(*code, |
1086 *input, | 1089 *input, |
1087 0, | 1090 0, |
1088 start_adr, | 1091 start_adr, |
1089 start_adr + input->length(), | 1092 start_adr + input->length(), |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1162 m.Bind(&exit_loop3); | 1165 m.Bind(&exit_loop3); |
1163 m.PopCurrentPosition(); | 1166 m.PopCurrentPosition(); |
1164 m.WriteCurrentPositionToRegister(out5, 0); // [0,3,6,9,9,-1] | 1167 m.WriteCurrentPositionToRegister(out5, 0); // [0,3,6,9,9,-1] |
1165 | 1168 |
1166 m.Succeed(); | 1169 m.Succeed(); |
1167 | 1170 |
1168 m.Bind(&fail); | 1171 m.Bind(&fail); |
1169 m.Fail(); | 1172 m.Fail(); |
1170 | 1173 |
1171 Handle<String> source = | 1174 Handle<String> source = |
1172 Factory::NewStringFromAscii(CStrVector("<loop test>")); | 1175 FACTORY->NewStringFromAscii(CStrVector("<loop test>")); |
1173 Handle<Object> code_object = m.GetCode(source); | 1176 Handle<Object> code_object = m.GetCode(source); |
1174 Handle<Code> code = Handle<Code>::cast(code_object); | 1177 Handle<Code> code = Handle<Code>::cast(code_object); |
1175 | 1178 |
1176 // String long enough for test (content doesn't matter). | 1179 // String long enough for test (content doesn't matter). |
1177 Handle<String> input = | 1180 Handle<String> input = |
1178 Factory::NewStringFromAscii(CStrVector("foofoofoofoofoo")); | 1181 FACTORY->NewStringFromAscii(CStrVector("foofoofoofoofoo")); |
1179 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input); | 1182 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input); |
1180 Address start_adr = seq_input->GetCharsAddress(); | 1183 Address start_adr = seq_input->GetCharsAddress(); |
1181 | 1184 |
1182 int output[6]; | 1185 int output[6]; |
1183 NativeRegExpMacroAssembler::Result result = | 1186 NativeRegExpMacroAssembler::Result result = |
1184 Execute(*code, | 1187 Execute(*code, |
1185 *input, | 1188 *input, |
1186 0, | 1189 0, |
1187 start_adr, | 1190 start_adr, |
1188 start_adr + input->length(), | 1191 start_adr + input->length(), |
(...skipping 14 matching lines...) Expand all Loading... |
1203 ContextInitializer initializer; | 1206 ContextInitializer initializer; |
1204 | 1207 |
1205 ArchRegExpMacroAssembler m(NativeRegExpMacroAssembler::ASCII, 0); | 1208 ArchRegExpMacroAssembler m(NativeRegExpMacroAssembler::ASCII, 0); |
1206 | 1209 |
1207 Label loop; | 1210 Label loop; |
1208 m.Bind(&loop); | 1211 m.Bind(&loop); |
1209 m.PushBacktrack(&loop); | 1212 m.PushBacktrack(&loop); |
1210 m.GoTo(&loop); | 1213 m.GoTo(&loop); |
1211 | 1214 |
1212 Handle<String> source = | 1215 Handle<String> source = |
1213 Factory::NewStringFromAscii(CStrVector("<stack overflow test>")); | 1216 FACTORY->NewStringFromAscii(CStrVector("<stack overflow test>")); |
1214 Handle<Object> code_object = m.GetCode(source); | 1217 Handle<Object> code_object = m.GetCode(source); |
1215 Handle<Code> code = Handle<Code>::cast(code_object); | 1218 Handle<Code> code = Handle<Code>::cast(code_object); |
1216 | 1219 |
1217 // String long enough for test (content doesn't matter). | 1220 // String long enough for test (content doesn't matter). |
1218 Handle<String> input = | 1221 Handle<String> input = |
1219 Factory::NewStringFromAscii(CStrVector("dummy")); | 1222 FACTORY->NewStringFromAscii(CStrVector("dummy")); |
1220 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input); | 1223 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input); |
1221 Address start_adr = seq_input->GetCharsAddress(); | 1224 Address start_adr = seq_input->GetCharsAddress(); |
1222 | 1225 |
1223 NativeRegExpMacroAssembler::Result result = | 1226 NativeRegExpMacroAssembler::Result result = |
1224 Execute(*code, | 1227 Execute(*code, |
1225 *input, | 1228 *input, |
1226 0, | 1229 0, |
1227 start_adr, | 1230 start_adr, |
1228 start_adr + input->length(), | 1231 start_adr + input->length(), |
1229 NULL); | 1232 NULL); |
1230 | 1233 |
1231 CHECK_EQ(NativeRegExpMacroAssembler::EXCEPTION, result); | 1234 CHECK_EQ(NativeRegExpMacroAssembler::EXCEPTION, result); |
1232 CHECK(Top::has_pending_exception()); | 1235 CHECK(Isolate::Current()->has_pending_exception()); |
1233 Top::clear_pending_exception(); | 1236 Isolate::Current()->clear_pending_exception(); |
1234 } | 1237 } |
1235 | 1238 |
1236 | 1239 |
1237 TEST(MacroAssemblerNativeLotsOfRegisters) { | 1240 TEST(MacroAssemblerNativeLotsOfRegisters) { |
1238 v8::V8::Initialize(); | 1241 v8::V8::Initialize(); |
1239 ContextInitializer initializer; | 1242 ContextInitializer initializer; |
1240 | 1243 |
1241 ArchRegExpMacroAssembler m(NativeRegExpMacroAssembler::ASCII, 2); | 1244 ArchRegExpMacroAssembler m(NativeRegExpMacroAssembler::ASCII, 2); |
1242 | 1245 |
1243 // At least 2048, to ensure the allocated space for registers | 1246 // At least 2048, to ensure the allocated space for registers |
1244 // span one full page. | 1247 // span one full page. |
1245 const int large_number = 8000; | 1248 const int large_number = 8000; |
1246 m.WriteCurrentPositionToRegister(large_number, 42); | 1249 m.WriteCurrentPositionToRegister(large_number, 42); |
1247 m.WriteCurrentPositionToRegister(0, 0); | 1250 m.WriteCurrentPositionToRegister(0, 0); |
1248 m.WriteCurrentPositionToRegister(1, 1); | 1251 m.WriteCurrentPositionToRegister(1, 1); |
1249 Label done; | 1252 Label done; |
1250 m.CheckNotBackReference(0, &done); // Performs a system-stack push. | 1253 m.CheckNotBackReference(0, &done); // Performs a system-stack push. |
1251 m.Bind(&done); | 1254 m.Bind(&done); |
1252 m.PushRegister(large_number, RegExpMacroAssembler::kNoStackLimitCheck); | 1255 m.PushRegister(large_number, RegExpMacroAssembler::kNoStackLimitCheck); |
1253 m.PopRegister(1); | 1256 m.PopRegister(1); |
1254 m.Succeed(); | 1257 m.Succeed(); |
1255 | 1258 |
1256 Handle<String> source = | 1259 Handle<String> source = |
1257 Factory::NewStringFromAscii(CStrVector("<huge register space test>")); | 1260 FACTORY->NewStringFromAscii(CStrVector("<huge register space test>")); |
1258 Handle<Object> code_object = m.GetCode(source); | 1261 Handle<Object> code_object = m.GetCode(source); |
1259 Handle<Code> code = Handle<Code>::cast(code_object); | 1262 Handle<Code> code = Handle<Code>::cast(code_object); |
1260 | 1263 |
1261 // String long enough for test (content doesn't matter). | 1264 // String long enough for test (content doesn't matter). |
1262 Handle<String> input = | 1265 Handle<String> input = |
1263 Factory::NewStringFromAscii(CStrVector("sample text")); | 1266 FACTORY->NewStringFromAscii(CStrVector("sample text")); |
1264 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input); | 1267 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input); |
1265 Address start_adr = seq_input->GetCharsAddress(); | 1268 Address start_adr = seq_input->GetCharsAddress(); |
1266 | 1269 |
1267 int captures[2]; | 1270 int captures[2]; |
1268 NativeRegExpMacroAssembler::Result result = | 1271 NativeRegExpMacroAssembler::Result result = |
1269 Execute(*code, | 1272 Execute(*code, |
1270 *input, | 1273 *input, |
1271 0, | 1274 0, |
1272 start_adr, | 1275 start_adr, |
1273 start_adr + input->length(), | 1276 start_adr + input->length(), |
1274 captures); | 1277 captures); |
1275 | 1278 |
1276 CHECK_EQ(NativeRegExpMacroAssembler::SUCCESS, result); | 1279 CHECK_EQ(NativeRegExpMacroAssembler::SUCCESS, result); |
1277 CHECK_EQ(0, captures[0]); | 1280 CHECK_EQ(0, captures[0]); |
1278 CHECK_EQ(42, captures[1]); | 1281 CHECK_EQ(42, captures[1]); |
1279 | 1282 |
1280 Top::clear_pending_exception(); | 1283 Isolate::Current()->clear_pending_exception(); |
1281 } | 1284 } |
1282 | 1285 |
1283 #else // V8_INTERPRETED_REGEXP | 1286 #else // V8_INTERPRETED_REGEXP |
1284 | 1287 |
1285 TEST(MacroAssembler) { | 1288 TEST(MacroAssembler) { |
1286 V8::Initialize(NULL); | 1289 V8::Initialize(NULL); |
1287 byte codes[1024]; | 1290 byte codes[1024]; |
1288 RegExpMacroAssemblerIrregexp m(Vector<byte>(codes, 1024)); | 1291 RegExpMacroAssemblerIrregexp m(Vector<byte>(codes, 1024)); |
1289 // ^f(o)o. | 1292 // ^f(o)o. |
1290 Label fail, fail2, start; | 1293 Label fail, fail2, start; |
(...skipping 24 matching lines...) Expand all Loading... |
1315 m.Bind(&fail); | 1318 m.Bind(&fail); |
1316 m.Backtrack(); | 1319 m.Backtrack(); |
1317 m.Succeed(); | 1320 m.Succeed(); |
1318 | 1321 |
1319 m.Bind(&fail2); | 1322 m.Bind(&fail2); |
1320 m.PopRegister(0); | 1323 m.PopRegister(0); |
1321 m.Fail(); | 1324 m.Fail(); |
1322 | 1325 |
1323 v8::HandleScope scope; | 1326 v8::HandleScope scope; |
1324 | 1327 |
1325 Handle<String> source = Factory::NewStringFromAscii(CStrVector("^f(o)o")); | 1328 Handle<String> source = FACTORY->NewStringFromAscii(CStrVector("^f(o)o")); |
1326 Handle<ByteArray> array = Handle<ByteArray>::cast(m.GetCode(source)); | 1329 Handle<ByteArray> array = Handle<ByteArray>::cast(m.GetCode(source)); |
1327 int captures[5]; | 1330 int captures[5]; |
1328 | 1331 |
1329 const uc16 str1[] = {'f', 'o', 'o', 'b', 'a', 'r'}; | 1332 const uc16 str1[] = {'f', 'o', 'o', 'b', 'a', 'r'}; |
1330 Handle<String> f1_16 = | 1333 Handle<String> f1_16 = |
1331 Factory::NewStringFromTwoByte(Vector<const uc16>(str1, 6)); | 1334 FACTORY->NewStringFromTwoByte(Vector<const uc16>(str1, 6)); |
1332 | 1335 |
1333 CHECK(IrregexpInterpreter::Match(array, f1_16, captures, 0)); | 1336 CHECK(IrregexpInterpreter::Match(array, f1_16, captures, 0)); |
1334 CHECK_EQ(0, captures[0]); | 1337 CHECK_EQ(0, captures[0]); |
1335 CHECK_EQ(3, captures[1]); | 1338 CHECK_EQ(3, captures[1]); |
1336 CHECK_EQ(1, captures[2]); | 1339 CHECK_EQ(1, captures[2]); |
1337 CHECK_EQ(2, captures[3]); | 1340 CHECK_EQ(2, captures[3]); |
1338 CHECK_EQ(84, captures[4]); | 1341 CHECK_EQ(84, captures[4]); |
1339 | 1342 |
1340 const uc16 str2[] = {'b', 'a', 'r', 'f', 'o', 'o'}; | 1343 const uc16 str2[] = {'b', 'a', 'r', 'f', 'o', 'o'}; |
1341 Handle<String> f2_16 = | 1344 Handle<String> f2_16 = |
1342 Factory::NewStringFromTwoByte(Vector<const uc16>(str2, 6)); | 1345 FACTORY->NewStringFromTwoByte(Vector<const uc16>(str2, 6)); |
1343 | 1346 |
1344 CHECK(!IrregexpInterpreter::Match(array, f2_16, captures, 0)); | 1347 CHECK(!IrregexpInterpreter::Match(array, f2_16, captures, 0)); |
1345 CHECK_EQ(42, captures[0]); | 1348 CHECK_EQ(42, captures[0]); |
1346 } | 1349 } |
1347 | 1350 |
1348 #endif // V8_INTERPRETED_REGEXP | 1351 #endif // V8_INTERPRETED_REGEXP |
1349 | 1352 |
1350 | 1353 |
1351 TEST(AddInverseToTable) { | 1354 TEST(AddInverseToTable) { |
| 1355 v8::internal::V8::Initialize(NULL); |
1352 static const int kLimit = 1000; | 1356 static const int kLimit = 1000; |
1353 static const int kRangeCount = 16; | 1357 static const int kRangeCount = 16; |
1354 for (int t = 0; t < 10; t++) { | 1358 for (int t = 0; t < 10; t++) { |
1355 ZoneScope zone_scope(DELETE_ON_EXIT); | 1359 ZoneScope zone_scope(DELETE_ON_EXIT); |
1356 ZoneList<CharacterRange>* ranges = | 1360 ZoneList<CharacterRange>* ranges = |
1357 new ZoneList<CharacterRange>(kRangeCount); | 1361 new ZoneList<CharacterRange>(kRangeCount); |
1358 for (int i = 0; i < kRangeCount; i++) { | 1362 for (int i = 0; i < kRangeCount; i++) { |
1359 int from = PseudoRandom(t + 87, i + 25) % kLimit; | 1363 int from = PseudoRandom(t + 87, i + 25) % kLimit; |
1360 int to = from + (PseudoRandom(i + 87, t + 25) % (kLimit / 20)); | 1364 int to = from + (PseudoRandom(i + 87, t + 25) % (kLimit / 20)); |
1361 if (to > kLimit) to = kLimit; | 1365 if (to > kLimit) to = kLimit; |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1500 | 1504 |
1501 static void TestSimpleRangeCaseIndependence(CharacterRange input, | 1505 static void TestSimpleRangeCaseIndependence(CharacterRange input, |
1502 CharacterRange expected) { | 1506 CharacterRange expected) { |
1503 EmbeddedVector<CharacterRange, 1> vector; | 1507 EmbeddedVector<CharacterRange, 1> vector; |
1504 vector[0] = expected; | 1508 vector[0] = expected; |
1505 TestRangeCaseIndependence(input, vector); | 1509 TestRangeCaseIndependence(input, vector); |
1506 } | 1510 } |
1507 | 1511 |
1508 | 1512 |
1509 TEST(CharacterRangeCaseIndependence) { | 1513 TEST(CharacterRangeCaseIndependence) { |
| 1514 v8::internal::V8::Initialize(NULL); |
1510 TestSimpleRangeCaseIndependence(CharacterRange::Singleton('a'), | 1515 TestSimpleRangeCaseIndependence(CharacterRange::Singleton('a'), |
1511 CharacterRange::Singleton('A')); | 1516 CharacterRange::Singleton('A')); |
1512 TestSimpleRangeCaseIndependence(CharacterRange::Singleton('z'), | 1517 TestSimpleRangeCaseIndependence(CharacterRange::Singleton('z'), |
1513 CharacterRange::Singleton('Z')); | 1518 CharacterRange::Singleton('Z')); |
1514 TestSimpleRangeCaseIndependence(CharacterRange('a', 'z'), | 1519 TestSimpleRangeCaseIndependence(CharacterRange('a', 'z'), |
1515 CharacterRange('A', 'Z')); | 1520 CharacterRange('A', 'Z')); |
1516 TestSimpleRangeCaseIndependence(CharacterRange('c', 'f'), | 1521 TestSimpleRangeCaseIndependence(CharacterRange('c', 'f'), |
1517 CharacterRange('C', 'F')); | 1522 CharacterRange('C', 'F')); |
1518 TestSimpleRangeCaseIndependence(CharacterRange('a', 'b'), | 1523 TestSimpleRangeCaseIndependence(CharacterRange('a', 'b'), |
1519 CharacterRange('A', 'B')); | 1524 CharacterRange('A', 'B')); |
(...skipping 21 matching lines...) Expand all Loading... |
1541 for (int i = 0; i < ranges->length(); i++) { | 1546 for (int i = 0; i < ranges->length(); i++) { |
1542 CharacterRange range = ranges->at(i); | 1547 CharacterRange range = ranges->at(i); |
1543 if (range.from() <= c && c <= range.to()) | 1548 if (range.from() <= c && c <= range.to()) |
1544 return true; | 1549 return true; |
1545 } | 1550 } |
1546 return false; | 1551 return false; |
1547 } | 1552 } |
1548 | 1553 |
1549 | 1554 |
1550 TEST(CharClassDifference) { | 1555 TEST(CharClassDifference) { |
| 1556 v8::internal::V8::Initialize(NULL); |
1551 ZoneScope zone_scope(DELETE_ON_EXIT); | 1557 ZoneScope zone_scope(DELETE_ON_EXIT); |
1552 ZoneList<CharacterRange>* base = new ZoneList<CharacterRange>(1); | 1558 ZoneList<CharacterRange>* base = new ZoneList<CharacterRange>(1); |
1553 base->Add(CharacterRange::Everything()); | 1559 base->Add(CharacterRange::Everything()); |
1554 Vector<const uc16> overlay = CharacterRange::GetWordBounds(); | 1560 Vector<const uc16> overlay = CharacterRange::GetWordBounds(); |
1555 ZoneList<CharacterRange>* included = NULL; | 1561 ZoneList<CharacterRange>* included = NULL; |
1556 ZoneList<CharacterRange>* excluded = NULL; | 1562 ZoneList<CharacterRange>* excluded = NULL; |
1557 CharacterRange::Split(base, overlay, &included, &excluded); | 1563 CharacterRange::Split(base, overlay, &included, &excluded); |
1558 for (int i = 0; i < (1 << 16); i++) { | 1564 for (int i = 0; i < (1 << 16); i++) { |
1559 bool in_base = InClass(i, base); | 1565 bool in_base = InClass(i, base); |
1560 if (in_base) { | 1566 if (in_base) { |
1561 bool in_overlay = false; | 1567 bool in_overlay = false; |
1562 for (int j = 0; !in_overlay && j < overlay.length(); j += 2) { | 1568 for (int j = 0; !in_overlay && j < overlay.length(); j += 2) { |
1563 if (overlay[j] <= i && i <= overlay[j+1]) | 1569 if (overlay[j] <= i && i <= overlay[j+1]) |
1564 in_overlay = true; | 1570 in_overlay = true; |
1565 } | 1571 } |
1566 CHECK_EQ(in_overlay, InClass(i, included)); | 1572 CHECK_EQ(in_overlay, InClass(i, included)); |
1567 CHECK_EQ(!in_overlay, InClass(i, excluded)); | 1573 CHECK_EQ(!in_overlay, InClass(i, excluded)); |
1568 } else { | 1574 } else { |
1569 CHECK(!InClass(i, included)); | 1575 CHECK(!InClass(i, included)); |
1570 CHECK(!InClass(i, excluded)); | 1576 CHECK(!InClass(i, excluded)); |
1571 } | 1577 } |
1572 } | 1578 } |
1573 } | 1579 } |
1574 | 1580 |
1575 | 1581 |
1576 TEST(CanonicalizeCharacterSets) { | 1582 TEST(CanonicalizeCharacterSets) { |
| 1583 v8::internal::V8::Initialize(NULL); |
1577 ZoneScope scope(DELETE_ON_EXIT); | 1584 ZoneScope scope(DELETE_ON_EXIT); |
1578 ZoneList<CharacterRange>* list = new ZoneList<CharacterRange>(4); | 1585 ZoneList<CharacterRange>* list = new ZoneList<CharacterRange>(4); |
1579 CharacterSet set(list); | 1586 CharacterSet set(list); |
1580 | 1587 |
1581 list->Add(CharacterRange(10, 20)); | 1588 list->Add(CharacterRange(10, 20)); |
1582 list->Add(CharacterRange(30, 40)); | 1589 list->Add(CharacterRange(30, 40)); |
1583 list->Add(CharacterRange(50, 60)); | 1590 list->Add(CharacterRange(50, 60)); |
1584 set.Canonicalize(); | 1591 set.Canonicalize(); |
1585 ASSERT_EQ(3, list->length()); | 1592 ASSERT_EQ(3, list->length()); |
1586 ASSERT_EQ(10, list->at(0).from()); | 1593 ASSERT_EQ(10, list->at(0).from()); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1637 for (int i = 0; i < set->length(); i++) { | 1644 for (int i = 0; i < set->length(); i++) { |
1638 CharacterRange range = set->at(i); | 1645 CharacterRange range = set->at(i); |
1639 if (range.from() <= value && value <= range.to()) { | 1646 if (range.from() <= value && value <= range.to()) { |
1640 return true; | 1647 return true; |
1641 } | 1648 } |
1642 } | 1649 } |
1643 return false; | 1650 return false; |
1644 } | 1651 } |
1645 | 1652 |
1646 TEST(CharacterRangeMerge) { | 1653 TEST(CharacterRangeMerge) { |
| 1654 v8::internal::V8::Initialize(NULL); |
1647 ZoneScope zone_scope(DELETE_ON_EXIT); | 1655 ZoneScope zone_scope(DELETE_ON_EXIT); |
1648 ZoneList<CharacterRange> l1(4); | 1656 ZoneList<CharacterRange> l1(4); |
1649 ZoneList<CharacterRange> l2(4); | 1657 ZoneList<CharacterRange> l2(4); |
1650 // Create all combinations of intersections of ranges, both singletons and | 1658 // Create all combinations of intersections of ranges, both singletons and |
1651 // longer. | 1659 // longer. |
1652 | 1660 |
1653 int offset = 0; | 1661 int offset = 0; |
1654 | 1662 |
1655 // The five kinds of singleton intersections: | 1663 // The five kinds of singleton intersections: |
1656 // X | 1664 // X |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1788 bool in_second = CharacterInSet(&l2, i); | 1796 bool in_second = CharacterInSet(&l2, i); |
1789 CHECK((in_first || in_second) == CharacterInSet(&all, i)); | 1797 CHECK((in_first || in_second) == CharacterInSet(&all, i)); |
1790 } | 1798 } |
1791 } | 1799 } |
1792 | 1800 |
1793 | 1801 |
1794 TEST(Graph) { | 1802 TEST(Graph) { |
1795 V8::Initialize(NULL); | 1803 V8::Initialize(NULL); |
1796 Execute("\\b\\w+\\b", false, true, true); | 1804 Execute("\\b\\w+\\b", false, true, true); |
1797 } | 1805 } |
OLD | NEW |