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

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

Issue 13783: * Made preemption work in Irregexp-native-ia32 (Closed)
Patch Set: Addressed review comments 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
« no previous file with comments | « src/runtime.cc ('k') | no next file » | 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 556 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 Handle<String> f2 = 567 Handle<String> f2 =
568 Factory::NewStringFromAscii(CStrVector("barfoo")); 568 Factory::NewStringFromAscii(CStrVector("barfoo"));
569 Handle<String> f2_16 = RegExpImpl::StringToTwoByte(f2); 569 Handle<String> f2_16 = RegExpImpl::StringToTwoByte(f2);
570 CHECK(!IrregexpInterpreter::Match(array, f2_16, captures, 0)); 570 CHECK(!IrregexpInterpreter::Match(array, f2_16, captures, 0));
571 CHECK_EQ(42, captures[0]); 571 CHECK_EQ(42, captures[0]);
572 } 572 }
573 573
574 574
575 #ifndef ARM // IA32 only tests. 575 #ifndef ARM // IA32 only tests.
576 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
577 TEST(MacroAssemblerIA32Success) { 594 TEST(MacroAssemblerIA32Success) {
578 V8::Initialize(NULL); 595 V8::Initialize(NULL);
579 596 ContextInitializer initializer;
580 // regexp-macro-assembler-ia32 needs a handle scope to allocate
581 // byte-arrays for constants.
582 v8::HandleScope scope;
583 597
584 RegExpMacroAssemblerIA32 m(RegExpMacroAssemblerIA32::ASCII, 4); 598 RegExpMacroAssemblerIA32 m(RegExpMacroAssemblerIA32::ASCII, 4);
585 599
586 m.Succeed(); 600 m.Succeed();
587 601
588 Handle<String> source = Factory::NewStringFromAscii(CStrVector("")); 602 Handle<String> source = Factory::NewStringFromAscii(CStrVector(""));
589 Handle<Object> code_object = m.GetCode(source); 603 Handle<Object> code_object = m.GetCode(source);
590 Handle<Code> code = Handle<Code>::cast(code_object); 604 Handle<Code> code = Handle<Code>::cast(code_object);
591 605
592 int captures[4] = {42, 37, 87, 117}; 606 int captures[4] = {42, 37, 87, 117};
593 Handle<String> input = Factory::NewStringFromAscii(CStrVector("foofoo")); 607 Handle<String> input = Factory::NewStringFromAscii(CStrVector("foofoo"));
594 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input); 608 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input);
595 Address start_adr = seq_input->GetCharsAddress(); 609 Address start_adr = seq_input->GetCharsAddress();
596 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input); 610 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input);
597 int end_offset = start_offset + seq_input->length(); 611 int end_offset = start_offset + seq_input->length();
598 612
599 bool success = RegExpMacroAssemblerIA32::Execute(*code, 613 RegExpMacroAssemblerIA32::Result result =
600 seq_input.location(), 614 RegExpMacroAssemblerIA32::Execute(*code,
601 start_offset, 615 seq_input.location(),
602 end_offset, 616 start_offset,
603 captures, 617 end_offset,
604 true); 618 captures,
619 true);
605 620
606 CHECK(success); 621 CHECK_EQ(RegExpMacroAssemblerIA32::SUCCESS, result);
607 CHECK_EQ(-1, captures[0]); 622 CHECK_EQ(-1, captures[0]);
608 CHECK_EQ(-1, captures[1]); 623 CHECK_EQ(-1, captures[1]);
609 CHECK_EQ(-1, captures[2]); 624 CHECK_EQ(-1, captures[2]);
610 CHECK_EQ(-1, captures[3]); 625 CHECK_EQ(-1, captures[3]);
611 } 626 }
612 627
613 628
614 TEST(MacroAssemblerIA32Simple) { 629 TEST(MacroAssemblerIA32Simple) {
615 V8::Initialize(NULL); 630 V8::Initialize(NULL);
616 631 ContextInitializer initializer;
617 // regexp-macro-assembler-ia32 needs a handle scope to allocate
618 // byte-arrays for constants.
619 v8::HandleScope scope;
620 632
621 RegExpMacroAssemblerIA32 m(RegExpMacroAssemblerIA32::ASCII, 4); 633 RegExpMacroAssemblerIA32 m(RegExpMacroAssemblerIA32::ASCII, 4);
622 634
623 uc16 foo_chars[3] = {'f', 'o', 'o'}; 635 uc16 foo_chars[3] = {'f', 'o', 'o'};
624 Vector<const uc16> foo(foo_chars, 3); 636 Vector<const uc16> foo(foo_chars, 3);
625 637
626 Label fail; 638 Label fail;
627 m.CheckCharacters(foo, 0, &fail, true); 639 m.CheckCharacters(foo, 0, &fail, true);
628 m.WriteCurrentPositionToRegister(0, 0); 640 m.WriteCurrentPositionToRegister(0, 0);
629 m.AdvanceCurrentPosition(3); 641 m.AdvanceCurrentPosition(3);
630 m.WriteCurrentPositionToRegister(1, 0); 642 m.WriteCurrentPositionToRegister(1, 0);
631 m.Succeed(); 643 m.Succeed();
632 m.Bind(&fail); 644 m.Bind(&fail);
633 m.Fail(); 645 m.Fail();
634 646
635 Handle<String> source = Factory::NewStringFromAscii(CStrVector("^foo")); 647 Handle<String> source = Factory::NewStringFromAscii(CStrVector("^foo"));
636 Handle<Object> code_object = m.GetCode(source); 648 Handle<Object> code_object = m.GetCode(source);
637 Handle<Code> code = Handle<Code>::cast(code_object); 649 Handle<Code> code = Handle<Code>::cast(code_object);
638 650
639 int captures[4] = {42, 37, 87, 117}; 651 int captures[4] = {42, 37, 87, 117};
640 Handle<String> input = Factory::NewStringFromAscii(CStrVector("foofoo")); 652 Handle<String> input = Factory::NewStringFromAscii(CStrVector("foofoo"));
641 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input); 653 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input);
642 Address start_adr = seq_input->GetCharsAddress(); 654 Address start_adr = seq_input->GetCharsAddress();
643 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input); 655 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input);
644 int end_offset = start_offset + seq_input->length(); 656 int end_offset = start_offset + seq_input->length();
645 657
646 bool success = RegExpMacroAssemblerIA32::Execute(*code, 658 RegExpMacroAssemblerIA32::Result result = RegExpMacroAssemblerIA32::Execute(*c ode,
647 seq_input.location(), 659 seq_input.location(),
648 start_offset, 660 start_offset,
649 end_offset, 661 end_offset,
650 captures, 662 captures,
651 true); 663 true);
652 664
653 CHECK(success); 665 CHECK_EQ(RegExpMacroAssemblerIA32::SUCCESS, result);
654 CHECK_EQ(0, captures[0]); 666 CHECK_EQ(0, captures[0]);
655 CHECK_EQ(3, captures[1]); 667 CHECK_EQ(3, captures[1]);
656 CHECK_EQ(-1, captures[2]); 668 CHECK_EQ(-1, captures[2]);
657 CHECK_EQ(-1, captures[3]); 669 CHECK_EQ(-1, captures[3]);
658 670
659 input = Factory::NewStringFromAscii(CStrVector("barbarbar")); 671 input = Factory::NewStringFromAscii(CStrVector("barbarbar"));
660 seq_input = Handle<SeqAsciiString>::cast(input); 672 seq_input = Handle<SeqAsciiString>::cast(input);
661 start_adr = seq_input->GetCharsAddress(); 673 start_adr = seq_input->GetCharsAddress();
662 start_offset = start_adr - reinterpret_cast<Address>(*seq_input); 674 start_offset = start_adr - reinterpret_cast<Address>(*seq_input);
663 end_offset = start_offset + seq_input->length(); 675 end_offset = start_offset + seq_input->length();
664 676
665 success = RegExpMacroAssemblerIA32::Execute(*code, 677 result = RegExpMacroAssemblerIA32::Execute(*code,
666 seq_input.location(), 678 seq_input.location(),
667 start_offset, 679 start_offset,
668 end_offset, 680 end_offset,
669 captures, 681 captures,
670 true); 682 true);
671 683
672 CHECK(!success); 684 CHECK_EQ(RegExpMacroAssemblerIA32::FAILURE, result);
673 } 685 }
674 686
675 687
676 TEST(MacroAssemblerIA32SimpleUC16) { 688 TEST(MacroAssemblerIA32SimpleUC16) {
677 V8::Initialize(NULL); 689 V8::Initialize(NULL);
678 690 ContextInitializer initializer;
679 // regexp-macro-assembler-ia32 needs a handle scope to allocate
680 // byte-arrays for constants.
681 v8::HandleScope scope;
682 691
683 RegExpMacroAssemblerIA32 m(RegExpMacroAssemblerIA32::UC16, 4); 692 RegExpMacroAssemblerIA32 m(RegExpMacroAssemblerIA32::UC16, 4);
684 693
685 uc16 foo_chars[3] = {'f', 'o', 'o'}; 694 uc16 foo_chars[3] = {'f', 'o', 'o'};
686 Vector<const uc16> foo(foo_chars, 3); 695 Vector<const uc16> foo(foo_chars, 3);
687 696
688 Label fail; 697 Label fail;
689 m.CheckCharacters(foo, 0, &fail, true); 698 m.CheckCharacters(foo, 0, &fail, true);
690 m.WriteCurrentPositionToRegister(0, 0); 699 m.WriteCurrentPositionToRegister(0, 0);
691 m.AdvanceCurrentPosition(3); 700 m.AdvanceCurrentPosition(3);
692 m.WriteCurrentPositionToRegister(1, 0); 701 m.WriteCurrentPositionToRegister(1, 0);
693 m.Succeed(); 702 m.Succeed();
694 m.Bind(&fail); 703 m.Bind(&fail);
695 m.Fail(); 704 m.Fail();
696 705
697 Handle<String> source = Factory::NewStringFromAscii(CStrVector("^foo")); 706 Handle<String> source = Factory::NewStringFromAscii(CStrVector("^foo"));
698 Handle<Object> code_object = m.GetCode(source); 707 Handle<Object> code_object = m.GetCode(source);
699 Handle<Code> code = Handle<Code>::cast(code_object); 708 Handle<Code> code = Handle<Code>::cast(code_object);
700 709
701 int captures[4] = {42, 37, 87, 117}; 710 int captures[4] = {42, 37, 87, 117};
702 const uc16 input_data[6] = {'f', 'o', 'o', 'f', 'o', '\xa0'}; 711 const uc16 input_data[6] = {'f', 'o', 'o', 'f', 'o', '\xa0'};
703 Handle<String> input = 712 Handle<String> input =
704 Factory::NewStringFromTwoByte(Vector<const uc16>(input_data, 6)); 713 Factory::NewStringFromTwoByte(Vector<const uc16>(input_data, 6));
705 Handle<SeqTwoByteString> seq_input = Handle<SeqTwoByteString>::cast(input); 714 Handle<SeqTwoByteString> seq_input = Handle<SeqTwoByteString>::cast(input);
706 Address start_adr = seq_input->GetCharsAddress(); 715 Address start_adr = seq_input->GetCharsAddress();
707 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input); 716 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input);
708 int end_offset = start_offset + seq_input->length() * sizeof(uc16); 717 int end_offset = start_offset + seq_input->length() * sizeof(uc16);
709 718
710 bool success = RegExpMacroAssemblerIA32::Execute(*code, 719 RegExpMacroAssemblerIA32::Result result =
711 seq_input.location(), 720 RegExpMacroAssemblerIA32::Execute(*code,
712 start_offset, 721 seq_input.location(),
713 end_offset, 722 start_offset,
714 captures, 723 end_offset,
715 true); 724 captures,
725 true);
716 726
717 CHECK(success); 727 CHECK_EQ(RegExpMacroAssemblerIA32::SUCCESS, result);
718 CHECK_EQ(0, captures[0]); 728 CHECK_EQ(0, captures[0]);
719 CHECK_EQ(3, captures[1]); 729 CHECK_EQ(3, captures[1]);
720 CHECK_EQ(-1, captures[2]); 730 CHECK_EQ(-1, captures[2]);
721 CHECK_EQ(-1, captures[3]); 731 CHECK_EQ(-1, captures[3]);
722 732
723 const uc16 input_data2[9] = {'b', 'a', 'r', 'b', 'a', 'r', 'b', 'a', '\xa0'}; 733 const uc16 input_data2[9] = {'b', 'a', 'r', 'b', 'a', 'r', 'b', 'a', '\xa0'};
724 input = Factory::NewStringFromTwoByte(Vector<const uc16>(input_data2, 9)); 734 input = Factory::NewStringFromTwoByte(Vector<const uc16>(input_data2, 9));
725 seq_input = Handle<SeqTwoByteString>::cast(input); 735 seq_input = Handle<SeqTwoByteString>::cast(input);
726 start_adr = seq_input->GetCharsAddress(); 736 start_adr = seq_input->GetCharsAddress();
727 start_offset = start_adr - reinterpret_cast<Address>(*seq_input); 737 start_offset = start_adr - reinterpret_cast<Address>(*seq_input);
728 end_offset = start_offset + seq_input->length() * sizeof(uc16); 738 end_offset = start_offset + seq_input->length() * sizeof(uc16);
729 739
730 success = RegExpMacroAssemblerIA32::Execute(*code, 740 result = RegExpMacroAssemblerIA32::Execute(*code,
731 seq_input.location(), 741 seq_input.location(),
732 start_offset, 742 start_offset,
733 end_offset, 743 end_offset,
734 captures, 744 captures,
735 true); 745 true);
736 746
737 CHECK(!success); 747 CHECK_EQ(RegExpMacroAssemblerIA32::FAILURE, result);
738 } 748 }
739 749
740 750
741 TEST(MacroAssemblerIA32Backtrack) { 751 TEST(MacroAssemblerIA32Backtrack) {
742 V8::Initialize(NULL); 752 V8::Initialize(NULL);
743 753 ContextInitializer initializer;
744 // regexp-macro-assembler-ia32 needs a handle scope to allocate
745 // byte-arrays for constants.
746 v8::HandleScope scope;
747 754
748 RegExpMacroAssemblerIA32 m(RegExpMacroAssemblerIA32::ASCII, 0); 755 RegExpMacroAssemblerIA32 m(RegExpMacroAssemblerIA32::ASCII, 0);
749 756
750 Label fail; 757 Label fail;
751 Label backtrack; 758 Label backtrack;
752 m.LoadCurrentCharacter(10, &fail); 759 m.LoadCurrentCharacter(10, &fail);
753 m.Succeed(); 760 m.Succeed();
754 m.Bind(&fail); 761 m.Bind(&fail);
755 m.PushBacktrack(&backtrack); 762 m.PushBacktrack(&backtrack);
756 m.LoadCurrentCharacter(10, NULL); 763 m.LoadCurrentCharacter(10, NULL);
757 m.Succeed(); 764 m.Succeed();
758 m.Bind(&backtrack); 765 m.Bind(&backtrack);
759 m.Fail(); 766 m.Fail();
760 767
761 Handle<String> source = Factory::NewStringFromAscii(CStrVector("..........")); 768 Handle<String> source = Factory::NewStringFromAscii(CStrVector(".........."));
762 Handle<Object> code_object = m.GetCode(source); 769 Handle<Object> code_object = m.GetCode(source);
763 Handle<Code> code = Handle<Code>::cast(code_object); 770 Handle<Code> code = Handle<Code>::cast(code_object);
764 771
765 Handle<String> input = Factory::NewStringFromAscii(CStrVector("foofoo")); 772 Handle<String> input = Factory::NewStringFromAscii(CStrVector("foofoo"));
766 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input); 773 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input);
767 Address start_adr = seq_input->GetCharsAddress(); 774 Address start_adr = seq_input->GetCharsAddress();
768 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input); 775 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input);
769 int end_offset = start_offset + seq_input->length(); 776 int end_offset = start_offset + seq_input->length();
770 777
771 bool success = RegExpMacroAssemblerIA32::Execute(*code, 778 RegExpMacroAssemblerIA32::Result result =
772 seq_input.location(), 779 RegExpMacroAssemblerIA32::Execute(*code,
773 start_offset, 780 seq_input.location(),
774 end_offset, 781 start_offset,
775 NULL, 782 end_offset,
776 true); 783 NULL,
784 true);
777 785
778 CHECK(!success); 786 CHECK_EQ(RegExpMacroAssemblerIA32::FAILURE, result);
779 } 787 }
780 788
781 789
782 TEST(MacroAssemblerIA32BackReference) { 790 TEST(MacroAssemblerIA32BackReference) {
783 V8::Initialize(NULL); 791 V8::Initialize(NULL);
784 792 ContextInitializer initializer;
785 // regexp-macro-assembler-ia32 needs a handle scope to allocate
786 // byte-arrays for constants.
787 v8::HandleScope scope;
788 793
789 RegExpMacroAssemblerIA32 m(RegExpMacroAssemblerIA32::ASCII, 3); 794 RegExpMacroAssemblerIA32 m(RegExpMacroAssemblerIA32::ASCII, 3);
790 795
791 m.WriteCurrentPositionToRegister(0, 0); 796 m.WriteCurrentPositionToRegister(0, 0);
792 m.AdvanceCurrentPosition(2); 797 m.AdvanceCurrentPosition(2);
793 m.WriteCurrentPositionToRegister(1, 0); 798 m.WriteCurrentPositionToRegister(1, 0);
794 Label nomatch; 799 Label nomatch;
795 m.CheckNotBackReference(0, &nomatch); 800 m.CheckNotBackReference(0, &nomatch);
796 m.Fail(); 801 m.Fail();
797 m.Bind(&nomatch); 802 m.Bind(&nomatch);
798 m.AdvanceCurrentPosition(2); 803 m.AdvanceCurrentPosition(2);
799 Label missing_match; 804 Label missing_match;
800 m.CheckNotBackReference(0, &missing_match); 805 m.CheckNotBackReference(0, &missing_match);
801 m.WriteCurrentPositionToRegister(2, 0); 806 m.WriteCurrentPositionToRegister(2, 0);
802 m.Succeed(); 807 m.Succeed();
803 m.Bind(&missing_match); 808 m.Bind(&missing_match);
804 m.Fail(); 809 m.Fail();
805 810
806 Handle<String> source = Factory::NewStringFromAscii(CStrVector("^(..)..\1")); 811 Handle<String> source = Factory::NewStringFromAscii(CStrVector("^(..)..\1"));
807 Handle<Object> code_object = m.GetCode(source); 812 Handle<Object> code_object = m.GetCode(source);
808 Handle<Code> code = Handle<Code>::cast(code_object); 813 Handle<Code> code = Handle<Code>::cast(code_object);
809 814
810 Handle<String> input = Factory::NewStringFromAscii(CStrVector("fooofo")); 815 Handle<String> input = Factory::NewStringFromAscii(CStrVector("fooofo"));
811 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input); 816 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input);
812 Address start_adr = seq_input->GetCharsAddress(); 817 Address start_adr = seq_input->GetCharsAddress();
813 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input); 818 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input);
814 int end_offset = start_offset + seq_input->length(); 819 int end_offset = start_offset + seq_input->length();
815 820
816 int output[3]; 821 int output[3];
817 bool success = RegExpMacroAssemblerIA32::Execute(*code, 822 RegExpMacroAssemblerIA32::Result result =
818 seq_input.location(), 823 RegExpMacroAssemblerIA32::Execute(*code,
819 start_offset, 824 seq_input.location(),
820 end_offset, 825 start_offset,
821 output, 826 end_offset,
822 true); 827 output,
828 true);
823 829
824 CHECK(success); 830 CHECK_EQ(RegExpMacroAssemblerIA32::SUCCESS, result);
825 CHECK_EQ(0, output[0]); 831 CHECK_EQ(0, output[0]);
826 CHECK_EQ(2, output[1]); 832 CHECK_EQ(2, output[1]);
827 CHECK_EQ(6, output[2]); 833 CHECK_EQ(6, output[2]);
828 } 834 }
829 835
830 836
831 TEST(MacroAssemblerIA32AtStart) { 837 TEST(MacroAssemblerIA32AtStart) {
832 V8::Initialize(NULL); 838 V8::Initialize(NULL);
833 839 ContextInitializer initializer;
834 // regexp-macro-assembler-ia32 needs a handle scope to allocate
835 // byte-arrays for constants.
836 v8::HandleScope scope;
837 840
838 RegExpMacroAssemblerIA32 m(RegExpMacroAssemblerIA32::ASCII, 0); 841 RegExpMacroAssemblerIA32 m(RegExpMacroAssemblerIA32::ASCII, 0);
839 842
840 Label not_at_start, newline, fail; 843 Label not_at_start, newline, fail;
841 m.CheckNotAtStart(&not_at_start); 844 m.CheckNotAtStart(&not_at_start);
842 // Check that prevchar = '\n' and current = 'f'. 845 // Check that prevchar = '\n' and current = 'f'.
843 m.CheckCharacter('\n', &newline); 846 m.CheckCharacter('\n', &newline);
844 m.Bind(&fail); 847 m.Bind(&fail);
845 m.Fail(); 848 m.Fail();
846 m.Bind(&newline); 849 m.Bind(&newline);
(...skipping 14 matching lines...) Expand all
861 Handle<String> source = Factory::NewStringFromAscii(CStrVector("(^f|ob)")); 864 Handle<String> source = Factory::NewStringFromAscii(CStrVector("(^f|ob)"));
862 Handle<Object> code_object = m.GetCode(source); 865 Handle<Object> code_object = m.GetCode(source);
863 Handle<Code> code = Handle<Code>::cast(code_object); 866 Handle<Code> code = Handle<Code>::cast(code_object);
864 867
865 Handle<String> input = Factory::NewStringFromAscii(CStrVector("foobar")); 868 Handle<String> input = Factory::NewStringFromAscii(CStrVector("foobar"));
866 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input); 869 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input);
867 Address start_adr = seq_input->GetCharsAddress(); 870 Address start_adr = seq_input->GetCharsAddress();
868 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input); 871 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input);
869 int end_offset = start_offset + seq_input->length(); 872 int end_offset = start_offset + seq_input->length();
870 873
871 bool success = RegExpMacroAssemblerIA32::Execute(*code, 874 RegExpMacroAssemblerIA32::Result result =
872 seq_input.location(), 875 RegExpMacroAssemblerIA32::Execute(*code,
873 start_offset, 876 seq_input.location(),
874 end_offset, 877 start_offset,
875 NULL, 878 end_offset,
876 true); 879 NULL,
880 true);
877 881
878 CHECK(success); 882 CHECK_EQ(RegExpMacroAssemblerIA32::SUCCESS, result);
879 883
880 start_offset += 3; 884 start_offset += 3;
881 success = RegExpMacroAssemblerIA32::Execute(*code, 885 result = RegExpMacroAssemblerIA32::Execute(*code,
882 seq_input.location(), 886 seq_input.location(),
883 start_offset, 887 start_offset,
884 end_offset, 888 end_offset,
885 NULL, 889 NULL,
886 false); 890 false);
887 891
888 CHECK(success); 892 CHECK_EQ(RegExpMacroAssemblerIA32::SUCCESS, result);
889 } 893 }
890 894
891 895
892 896
893 897
894 TEST(MacroAssemblerIA32BackRefNoCase) { 898 TEST(MacroAssemblerIA32BackRefNoCase) {
895 V8::Initialize(NULL); 899 V8::Initialize(NULL);
896 900 ContextInitializer initializer;
897 // regexp-macro-assembler-ia32 needs a handle scope to allocate
898 // byte-arrays for constants.
899 v8::HandleScope scope;
900 901
901 RegExpMacroAssemblerIA32 m(RegExpMacroAssemblerIA32::ASCII, 4); 902 RegExpMacroAssemblerIA32 m(RegExpMacroAssemblerIA32::ASCII, 4);
902 903
903 Label fail, succ; 904 Label fail, succ;
904 905
905 m.WriteCurrentPositionToRegister(0, 0); 906 m.WriteCurrentPositionToRegister(0, 0);
906 m.WriteCurrentPositionToRegister(2, 0); 907 m.WriteCurrentPositionToRegister(2, 0);
907 m.AdvanceCurrentPosition(3); 908 m.AdvanceCurrentPosition(3);
908 m.WriteCurrentPositionToRegister(3, 0); 909 m.WriteCurrentPositionToRegister(3, 0);
909 m.CheckNotBackReferenceIgnoreCase(2, &fail); // Match "AbC". 910 m.CheckNotBackReferenceIgnoreCase(2, &fail); // Match "AbC".
(...skipping 18 matching lines...) Expand all
928 Handle<Code> code = Handle<Code>::cast(code_object); 929 Handle<Code> code = Handle<Code>::cast(code_object);
929 930
930 Handle<String> input = 931 Handle<String> input =
931 Factory::NewStringFromAscii(CStrVector("aBcAbCABCxYzab")); 932 Factory::NewStringFromAscii(CStrVector("aBcAbCABCxYzab"));
932 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input); 933 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input);
933 Address start_adr = seq_input->GetCharsAddress(); 934 Address start_adr = seq_input->GetCharsAddress();
934 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input); 935 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input);
935 int end_offset = start_offset + seq_input->length(); 936 int end_offset = start_offset + seq_input->length();
936 937
937 int output[4]; 938 int output[4];
938 bool success = RegExpMacroAssemblerIA32::Execute(*code, 939 RegExpMacroAssemblerIA32::Result result =
939 seq_input.location(), 940 RegExpMacroAssemblerIA32::Execute(*code,
940 start_offset, 941 seq_input.location(),
941 end_offset, 942 start_offset,
942 output, 943 end_offset,
943 true); 944 output,
945 true);
944 946
945 CHECK(success); 947 CHECK_EQ(RegExpMacroAssemblerIA32::SUCCESS, result);
946 CHECK_EQ(0, output[0]); 948 CHECK_EQ(0, output[0]);
947 CHECK_EQ(12, output[1]); 949 CHECK_EQ(12, output[1]);
948 CHECK_EQ(0, output[2]); 950 CHECK_EQ(0, output[2]);
949 CHECK_EQ(3, output[3]); 951 CHECK_EQ(3, output[3]);
950 } 952 }
951 953
952 954
953 955
954 TEST(MacroAssemblerIA32Registers) { 956 TEST(MacroAssemblerIA32Registers) {
955 V8::Initialize(NULL); 957 V8::Initialize(NULL);
956 958 ContextInitializer initializer;
957 // regexp-macro-assembler-ia32 needs a handle scope to allocate
958 // byte-arrays for constants.
959 v8::HandleScope scope;
960 959
961 RegExpMacroAssemblerIA32 m(RegExpMacroAssemblerIA32::ASCII, 5); 960 RegExpMacroAssemblerIA32 m(RegExpMacroAssemblerIA32::ASCII, 5);
962 961
963 uc16 foo_chars[3] = {'f', 'o', 'o'}; 962 uc16 foo_chars[3] = {'f', 'o', 'o'};
964 Vector<const uc16> foo(foo_chars, 3); 963 Vector<const uc16> foo(foo_chars, 3);
965 964
966 enum registers { out1, out2, out3, out4, out5, sp, loop_cnt }; 965 enum registers { out1, out2, out3, out4, out5, sp, loop_cnt };
967 Label fail; 966 Label fail;
968 Label backtrack; 967 Label backtrack;
969 m.WriteCurrentPositionToRegister(out1, 0); // Output: [0] 968 m.WriteCurrentPositionToRegister(out1, 0); // Output: [0]
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1031 1030
1032 // String long enough for test (content doesn't matter). 1031 // String long enough for test (content doesn't matter).
1033 Handle<String> input = 1032 Handle<String> input =
1034 Factory::NewStringFromAscii(CStrVector("foofoofoofoofoo")); 1033 Factory::NewStringFromAscii(CStrVector("foofoofoofoofoo"));
1035 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input); 1034 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input);
1036 Address start_adr = seq_input->GetCharsAddress(); 1035 Address start_adr = seq_input->GetCharsAddress();
1037 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input); 1036 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input);
1038 int end_offset = start_offset + seq_input->length(); 1037 int end_offset = start_offset + seq_input->length();
1039 1038
1040 int output[5]; 1039 int output[5];
1041 bool success = RegExpMacroAssemblerIA32::Execute(*code, 1040 RegExpMacroAssemblerIA32::Result result =
1042 seq_input.location(), 1041 RegExpMacroAssemblerIA32::Execute(*code,
1043 start_offset, 1042 seq_input.location(),
1044 end_offset, 1043 start_offset,
1045 output, 1044 end_offset,
1046 true); 1045 output,
1046 true);
1047 1047
1048 CHECK(success); 1048 CHECK_EQ(RegExpMacroAssemblerIA32::SUCCESS, result);
1049 CHECK_EQ(0, output[0]); 1049 CHECK_EQ(0, output[0]);
1050 CHECK_EQ(3, output[1]); 1050 CHECK_EQ(3, output[1]);
1051 CHECK_EQ(6, output[2]); 1051 CHECK_EQ(6, output[2]);
1052 CHECK_EQ(9, output[3]); 1052 CHECK_EQ(9, output[3]);
1053 CHECK_EQ(9, output[4]); 1053 CHECK_EQ(9, output[4]);
1054 } 1054 }
1055 1055
1056
1057 TEST(MacroAssemblerIA32StackOverflow) {
1058 V8::Initialize(NULL);
1059 ContextInitializer initializer;
1060
1061 RegExpMacroAssemblerIA32 m(RegExpMacroAssemblerIA32::ASCII, 0);
1062
1063 Label loop;
1064 m.Bind(&loop);
1065 m.PushBacktrack(&loop);
1066 m.GoTo(&loop);
1067
1068 Handle<String> source =
1069 Factory::NewStringFromAscii(CStrVector("<stack overflow test>"));
1070 Handle<Object> code_object = m.GetCode(source);
1071 Handle<Code> code = Handle<Code>::cast(code_object);
1072
1073 // String long enough for test (content doesn't matter).
1074 Handle<String> input =
1075 Factory::NewStringFromAscii(CStrVector("dummy"));
1076 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input);
1077 Address start_adr = seq_input->GetCharsAddress();
1078 int start_offset = start_adr - reinterpret_cast<Address>(*seq_input);
1079 int end_offset = start_offset + seq_input->length();
1080
1081 RegExpMacroAssemblerIA32::Result result =
1082 RegExpMacroAssemblerIA32::Execute(*code,
1083 seq_input.location(),
1084 start_offset,
1085 end_offset,
1086 NULL,
1087 true);
1088
1089 CHECK_EQ(RegExpMacroAssemblerIA32::EXCEPTION, result);
1090 CHECK(Top::has_pending_exception());
1091 Top::clear_pending_exception();
1092 }
1093
1094
1056 #endif // !defined ARM 1095 #endif // !defined ARM
1057 1096
1058 TEST(AddInverseToTable) { 1097 TEST(AddInverseToTable) {
1059 static const int kLimit = 1000; 1098 static const int kLimit = 1000;
1060 static const int kRangeCount = 16; 1099 static const int kRangeCount = 16;
1061 for (int t = 0; t < 10; t++) { 1100 for (int t = 0; t < 10; t++) {
1062 ZoneScope zone_scope(DELETE_ON_EXIT); 1101 ZoneScope zone_scope(DELETE_ON_EXIT);
1063 ZoneList<CharacterRange>* ranges = 1102 ZoneList<CharacterRange>* ranges =
1064 new ZoneList<CharacterRange>(kRangeCount); 1103 new ZoneList<CharacterRange>(kRangeCount);
1065 for (int i = 0; i < kRangeCount; i++) { 1104 for (int i = 0; i < kRangeCount; i++) {
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
1294 CHECK(!InClass(i, excluded)); 1333 CHECK(!InClass(i, excluded));
1295 } 1334 }
1296 } 1335 }
1297 } 1336 }
1298 1337
1299 1338
1300 TEST(Graph) { 1339 TEST(Graph) {
1301 V8::Initialize(NULL); 1340 V8::Initialize(NULL);
1302 Execute("\\bboy\\b", false, true, true); 1341 Execute("\\bboy\\b", false, true, true);
1303 } 1342 }
OLDNEW
« no previous file with comments | « src/runtime.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698