| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 | 81 |
| 82 static SmartArrayPointer<const char> Parse(const char* input) { | 82 static SmartArrayPointer<const char> Parse(const char* input) { |
| 83 V8::Initialize(NULL); | 83 V8::Initialize(NULL); |
| 84 v8::HandleScope scope; | 84 v8::HandleScope scope; |
| 85 ZoneScope zone_scope(Isolate::Current(), DELETE_ON_EXIT); | 85 ZoneScope zone_scope(Isolate::Current(), DELETE_ON_EXIT); |
| 86 FlatStringReader reader(Isolate::Current(), CStrVector(input)); | 86 FlatStringReader reader(Isolate::Current(), CStrVector(input)); |
| 87 RegExpCompileData result; | 87 RegExpCompileData result; |
| 88 CHECK(v8::internal::RegExpParser::ParseRegExp(&reader, false, &result)); | 88 CHECK(v8::internal::RegExpParser::ParseRegExp(&reader, false, &result)); |
| 89 CHECK(result.tree != NULL); | 89 CHECK(result.tree != NULL); |
| 90 CHECK(result.error.is_null()); | 90 CHECK(result.error.is_null()); |
| 91 SmartArrayPointer<const char> output = result.tree->ToString(); | 91 SmartArrayPointer<const char> output = |
| 92 result.tree->ToString(Isolate::Current()->zone()); |
| 92 return output; | 93 return output; |
| 93 } | 94 } |
| 94 | 95 |
| 95 static bool CheckSimple(const char* input) { | 96 static bool CheckSimple(const char* input) { |
| 96 V8::Initialize(NULL); | 97 V8::Initialize(NULL); |
| 97 v8::HandleScope scope; | 98 v8::HandleScope scope; |
| 98 unibrow::Utf8InputBuffer<> buffer(input, StrLength(input)); | 99 unibrow::Utf8InputBuffer<> buffer(input, StrLength(input)); |
| 99 ZoneScope zone_scope(Isolate::Current(), DELETE_ON_EXIT); | 100 ZoneScope zone_scope(Isolate::Current(), DELETE_ON_EXIT); |
| 100 FlatStringReader reader(Isolate::Current(), CStrVector(input)); | 101 FlatStringReader reader(Isolate::Current(), CStrVector(input)); |
| 101 RegExpCompileData result; | 102 RegExpCompileData result; |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 } | 463 } |
| 463 | 464 |
| 464 | 465 |
| 465 static bool NotWord(uc16 c) { | 466 static bool NotWord(uc16 c) { |
| 466 return !IsRegExpWord(c); | 467 return !IsRegExpWord(c); |
| 467 } | 468 } |
| 468 | 469 |
| 469 | 470 |
| 470 static void TestCharacterClassEscapes(uc16 c, bool (pred)(uc16 c)) { | 471 static void TestCharacterClassEscapes(uc16 c, bool (pred)(uc16 c)) { |
| 471 ZoneScope scope(Isolate::Current(), DELETE_ON_EXIT); | 472 ZoneScope scope(Isolate::Current(), DELETE_ON_EXIT); |
| 472 ZoneList<CharacterRange>* ranges = new ZoneList<CharacterRange>(2); | 473 Zone* zone = Isolate::Current()->zone(); |
| 473 CharacterRange::AddClassEscape(c, ranges); | 474 ZoneList<CharacterRange>* ranges = |
| 475 new(zone) ZoneList<CharacterRange>(2, zone); |
| 476 CharacterRange::AddClassEscape(c, ranges, zone); |
| 474 for (unsigned i = 0; i < (1 << 16); i++) { | 477 for (unsigned i = 0; i < (1 << 16); i++) { |
| 475 bool in_class = false; | 478 bool in_class = false; |
| 476 for (int j = 0; !in_class && j < ranges->length(); j++) { | 479 for (int j = 0; !in_class && j < ranges->length(); j++) { |
| 477 CharacterRange& range = ranges->at(j); | 480 CharacterRange& range = ranges->at(j); |
| 478 in_class = (range.from() <= i && i <= range.to()); | 481 in_class = (range.from() <= i && i <= range.to()); |
| 479 } | 482 } |
| 480 CHECK_EQ(pred(i), in_class); | 483 CHECK_EQ(pred(i), in_class); |
| 481 } | 484 } |
| 482 } | 485 } |
| 483 | 486 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 static unsigned PseudoRandom(int i, int j) { | 561 static unsigned PseudoRandom(int i, int j) { |
| 559 return ~(~((i * 781) ^ (j * 329))); | 562 return ~(~((i * 781) ^ (j * 329))); |
| 560 } | 563 } |
| 561 | 564 |
| 562 | 565 |
| 563 TEST(SplayTreeSimple) { | 566 TEST(SplayTreeSimple) { |
| 564 v8::internal::V8::Initialize(NULL); | 567 v8::internal::V8::Initialize(NULL); |
| 565 static const unsigned kLimit = 1000; | 568 static const unsigned kLimit = 1000; |
| 566 ZoneScope zone_scope(Isolate::Current(), DELETE_ON_EXIT); | 569 ZoneScope zone_scope(Isolate::Current(), DELETE_ON_EXIT); |
| 567 ZoneSplayTree<TestConfig> tree; | 570 ZoneSplayTree<TestConfig> tree; |
| 571 ZoneAllocationPolicy allocator(Isolate::Current()->zone()); |
| 568 bool seen[kLimit]; | 572 bool seen[kLimit]; |
| 569 for (unsigned i = 0; i < kLimit; i++) seen[i] = false; | 573 for (unsigned i = 0; i < kLimit; i++) seen[i] = false; |
| 570 #define CHECK_MAPS_EQUAL() do { \ | 574 #define CHECK_MAPS_EQUAL() do { \ |
| 571 for (unsigned k = 0; k < kLimit; k++) \ | 575 for (unsigned k = 0; k < kLimit; k++) \ |
| 572 CHECK_EQ(seen[k], tree.Find(k, &loc)); \ | 576 CHECK_EQ(seen[k], tree.Find(k, &loc)); \ |
| 573 } while (false) | 577 } while (false) |
| 574 for (int i = 0; i < 50; i++) { | 578 for (int i = 0; i < 50; i++) { |
| 575 for (int j = 0; j < 50; j++) { | 579 for (int j = 0; j < 50; j++) { |
| 576 unsigned next = PseudoRandom(i, j) % kLimit; | 580 unsigned next = PseudoRandom(i, j) % kLimit; |
| 577 if (seen[next]) { | 581 if (seen[next]) { |
| 578 // We've already seen this one. Check the value and remove | 582 // We've already seen this one. Check the value and remove |
| 579 // it. | 583 // it. |
| 580 ZoneSplayTree<TestConfig>::Locator loc; | 584 ZoneSplayTree<TestConfig>::Locator loc; |
| 581 CHECK(tree.Find(next, &loc)); | 585 CHECK(tree.Find(next, &loc)); |
| 582 CHECK_EQ(next, loc.key()); | 586 CHECK_EQ(next, loc.key()); |
| 583 CHECK_EQ(3 * next, loc.value()); | 587 CHECK_EQ(3 * next, loc.value()); |
| 584 tree.Remove(next); | 588 tree.Remove(next); |
| 585 seen[next] = false; | 589 seen[next] = false; |
| 586 CHECK_MAPS_EQUAL(); | 590 CHECK_MAPS_EQUAL(); |
| 587 } else { | 591 } else { |
| 588 // Check that it wasn't there already and then add it. | 592 // Check that it wasn't there already and then add it. |
| 589 ZoneSplayTree<TestConfig>::Locator loc; | 593 ZoneSplayTree<TestConfig>::Locator loc; |
| 590 CHECK(!tree.Find(next, &loc)); | 594 CHECK(!tree.Find(next, &loc)); |
| 591 CHECK(tree.Insert(next, &loc)); | 595 CHECK(tree.Insert(next, &loc, allocator)); |
| 592 CHECK_EQ(next, loc.key()); | 596 CHECK_EQ(next, loc.key()); |
| 593 loc.set_value(3 * next); | 597 loc.set_value(3 * next); |
| 594 seen[next] = true; | 598 seen[next] = true; |
| 595 CHECK_MAPS_EQUAL(); | 599 CHECK_MAPS_EQUAL(); |
| 596 } | 600 } |
| 597 int val = PseudoRandom(j, i) % kLimit; | 601 int val = PseudoRandom(j, i) % kLimit; |
| 598 if (seen[val]) { | 602 if (seen[val]) { |
| 599 ZoneSplayTree<TestConfig>::Locator loc; | 603 ZoneSplayTree<TestConfig>::Locator loc; |
| 600 CHECK(tree.FindGreatestLessThan(val, &loc)); | 604 CHECK(tree.FindGreatestLessThan(val, &loc)); |
| 601 CHECK_EQ(loc.key(), val); | 605 CHECK_EQ(loc.key(), val); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 629 for (int j = 1; j < 2 * kRangeSize; j++) { | 633 for (int j = 1; j < 2 * kRangeSize; j++) { |
| 630 CHECK(range[j-1] <= range[j]); | 634 CHECK(range[j-1] <= range[j]); |
| 631 } | 635 } |
| 632 } | 636 } |
| 633 // Enter test data into dispatch table. | 637 // Enter test data into dispatch table. |
| 634 ZoneScope zone_scope(Isolate::Current(), DELETE_ON_EXIT); | 638 ZoneScope zone_scope(Isolate::Current(), DELETE_ON_EXIT); |
| 635 DispatchTable table; | 639 DispatchTable table; |
| 636 for (int i = 0; i < kRangeCount; i++) { | 640 for (int i = 0; i < kRangeCount; i++) { |
| 637 uc16* range = ranges[i]; | 641 uc16* range = ranges[i]; |
| 638 for (int j = 0; j < 2 * kRangeSize; j += 2) | 642 for (int j = 0; j < 2 * kRangeSize; j += 2) |
| 639 table.AddRange(CharacterRange(range[j], range[j + 1]), i); | 643 table.AddRange(CharacterRange(range[j], range[j + 1]), i, |
| 644 Isolate::Current()->zone()); |
| 640 } | 645 } |
| 641 // Check that the table looks as we would expect | 646 // Check that the table looks as we would expect |
| 642 for (int p = 0; p < kLimit; p++) { | 647 for (int p = 0; p < kLimit; p++) { |
| 643 OutSet* outs = table.Get(p); | 648 OutSet* outs = table.Get(p); |
| 644 for (int j = 0; j < kRangeCount; j++) { | 649 for (int j = 0; j < kRangeCount; j++) { |
| 645 uc16* range = ranges[j]; | 650 uc16* range = ranges[j]; |
| 646 bool is_on = false; | 651 bool is_on = false; |
| 647 for (int k = 0; !is_on && (k < 2 * kRangeSize); k += 2) | 652 for (int k = 0; !is_on && (k < 2 * kRangeSize); k += 2) |
| 648 is_on = (range[k] <= p && p <= range[k + 1]); | 653 is_on = (range[k] <= p && p <= range[k + 1]); |
| 649 CHECK_EQ(is_on, outs->Get(j)); | 654 CHECK_EQ(is_on, outs->Get(j)); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 729 0, | 734 0, |
| 730 Isolate::Current()); | 735 Isolate::Current()); |
| 731 } | 736 } |
| 732 | 737 |
| 733 | 738 |
| 734 TEST(MacroAssemblerNativeSuccess) { | 739 TEST(MacroAssemblerNativeSuccess) { |
| 735 v8::V8::Initialize(); | 740 v8::V8::Initialize(); |
| 736 ContextInitializer initializer; | 741 ContextInitializer initializer; |
| 737 Factory* factory = Isolate::Current()->factory(); | 742 Factory* factory = Isolate::Current()->factory(); |
| 738 | 743 |
| 739 ArchRegExpMacroAssembler m(NativeRegExpMacroAssembler::ASCII, 4); | 744 ArchRegExpMacroAssembler m(NativeRegExpMacroAssembler::ASCII, 4, |
| 745 Isolate::Current()->zone()); |
| 740 | 746 |
| 741 m.Succeed(); | 747 m.Succeed(); |
| 742 | 748 |
| 743 Handle<String> source = factory->NewStringFromAscii(CStrVector("")); | 749 Handle<String> source = factory->NewStringFromAscii(CStrVector("")); |
| 744 Handle<Object> code_object = m.GetCode(source); | 750 Handle<Object> code_object = m.GetCode(source); |
| 745 Handle<Code> code = Handle<Code>::cast(code_object); | 751 Handle<Code> code = Handle<Code>::cast(code_object); |
| 746 | 752 |
| 747 int captures[4] = {42, 37, 87, 117}; | 753 int captures[4] = {42, 37, 87, 117}; |
| 748 Handle<String> input = factory->NewStringFromAscii(CStrVector("foofoo")); | 754 Handle<String> input = factory->NewStringFromAscii(CStrVector("foofoo")); |
| 749 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input); | 755 Handle<SeqAsciiString> seq_input = Handle<SeqAsciiString>::cast(input); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 764 CHECK_EQ(-1, captures[2]); | 770 CHECK_EQ(-1, captures[2]); |
| 765 CHECK_EQ(-1, captures[3]); | 771 CHECK_EQ(-1, captures[3]); |
| 766 } | 772 } |
| 767 | 773 |
| 768 | 774 |
| 769 TEST(MacroAssemblerNativeSimple) { | 775 TEST(MacroAssemblerNativeSimple) { |
| 770 v8::V8::Initialize(); | 776 v8::V8::Initialize(); |
| 771 ContextInitializer initializer; | 777 ContextInitializer initializer; |
| 772 Factory* factory = Isolate::Current()->factory(); | 778 Factory* factory = Isolate::Current()->factory(); |
| 773 | 779 |
| 774 ArchRegExpMacroAssembler m(NativeRegExpMacroAssembler::ASCII, 4); | 780 ArchRegExpMacroAssembler m(NativeRegExpMacroAssembler::ASCII, 4, |
| 781 Isolate::Current()->zone()); |
| 775 | 782 |
| 776 uc16 foo_chars[3] = {'f', 'o', 'o'}; | 783 uc16 foo_chars[3] = {'f', 'o', 'o'}; |
| 777 Vector<const uc16> foo(foo_chars, 3); | 784 Vector<const uc16> foo(foo_chars, 3); |
| 778 | 785 |
| 779 Label fail; | 786 Label fail; |
| 780 m.CheckCharacters(foo, 0, &fail, true); | 787 m.CheckCharacters(foo, 0, &fail, true); |
| 781 m.WriteCurrentPositionToRegister(0, 0); | 788 m.WriteCurrentPositionToRegister(0, 0); |
| 782 m.AdvanceCurrentPosition(3); | 789 m.AdvanceCurrentPosition(3); |
| 783 m.WriteCurrentPositionToRegister(1, 0); | 790 m.WriteCurrentPositionToRegister(1, 0); |
| 784 m.Succeed(); | 791 m.Succeed(); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 821 | 828 |
| 822 CHECK_EQ(NativeRegExpMacroAssembler::FAILURE, result); | 829 CHECK_EQ(NativeRegExpMacroAssembler::FAILURE, result); |
| 823 } | 830 } |
| 824 | 831 |
| 825 | 832 |
| 826 TEST(MacroAssemblerNativeSimpleUC16) { | 833 TEST(MacroAssemblerNativeSimpleUC16) { |
| 827 v8::V8::Initialize(); | 834 v8::V8::Initialize(); |
| 828 ContextInitializer initializer; | 835 ContextInitializer initializer; |
| 829 Factory* factory = Isolate::Current()->factory(); | 836 Factory* factory = Isolate::Current()->factory(); |
| 830 | 837 |
| 831 ArchRegExpMacroAssembler m(NativeRegExpMacroAssembler::UC16, 4); | 838 ArchRegExpMacroAssembler m(NativeRegExpMacroAssembler::UC16, 4, |
| 839 Isolate::Current()->zone()); |
| 832 | 840 |
| 833 uc16 foo_chars[3] = {'f', 'o', 'o'}; | 841 uc16 foo_chars[3] = {'f', 'o', 'o'}; |
| 834 Vector<const uc16> foo(foo_chars, 3); | 842 Vector<const uc16> foo(foo_chars, 3); |
| 835 | 843 |
| 836 Label fail; | 844 Label fail; |
| 837 m.CheckCharacters(foo, 0, &fail, true); | 845 m.CheckCharacters(foo, 0, &fail, true); |
| 838 m.WriteCurrentPositionToRegister(0, 0); | 846 m.WriteCurrentPositionToRegister(0, 0); |
| 839 m.AdvanceCurrentPosition(3); | 847 m.AdvanceCurrentPosition(3); |
| 840 m.WriteCurrentPositionToRegister(1, 0); | 848 m.WriteCurrentPositionToRegister(1, 0); |
| 841 m.Succeed(); | 849 m.Succeed(); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 883 | 891 |
| 884 CHECK_EQ(NativeRegExpMacroAssembler::FAILURE, result); | 892 CHECK_EQ(NativeRegExpMacroAssembler::FAILURE, result); |
| 885 } | 893 } |
| 886 | 894 |
| 887 | 895 |
| 888 TEST(MacroAssemblerNativeBacktrack) { | 896 TEST(MacroAssemblerNativeBacktrack) { |
| 889 v8::V8::Initialize(); | 897 v8::V8::Initialize(); |
| 890 ContextInitializer initializer; | 898 ContextInitializer initializer; |
| 891 Factory* factory = Isolate::Current()->factory(); | 899 Factory* factory = Isolate::Current()->factory(); |
| 892 | 900 |
| 893 ArchRegExpMacroAssembler m(NativeRegExpMacroAssembler::ASCII, 0); | 901 ArchRegExpMacroAssembler m(NativeRegExpMacroAssembler::ASCII, 0, |
| 902 Isolate::Current()->zone()); |
| 894 | 903 |
| 895 Label fail; | 904 Label fail; |
| 896 Label backtrack; | 905 Label backtrack; |
| 897 m.LoadCurrentCharacter(10, &fail); | 906 m.LoadCurrentCharacter(10, &fail); |
| 898 m.Succeed(); | 907 m.Succeed(); |
| 899 m.Bind(&fail); | 908 m.Bind(&fail); |
| 900 m.PushBacktrack(&backtrack); | 909 m.PushBacktrack(&backtrack); |
| 901 m.LoadCurrentCharacter(10, NULL); | 910 m.LoadCurrentCharacter(10, NULL); |
| 902 m.Succeed(); | 911 m.Succeed(); |
| 903 m.Bind(&backtrack); | 912 m.Bind(&backtrack); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 921 | 930 |
| 922 CHECK_EQ(NativeRegExpMacroAssembler::FAILURE, result); | 931 CHECK_EQ(NativeRegExpMacroAssembler::FAILURE, result); |
| 923 } | 932 } |
| 924 | 933 |
| 925 | 934 |
| 926 TEST(MacroAssemblerNativeBackReferenceASCII) { | 935 TEST(MacroAssemblerNativeBackReferenceASCII) { |
| 927 v8::V8::Initialize(); | 936 v8::V8::Initialize(); |
| 928 ContextInitializer initializer; | 937 ContextInitializer initializer; |
| 929 Factory* factory = Isolate::Current()->factory(); | 938 Factory* factory = Isolate::Current()->factory(); |
| 930 | 939 |
| 931 ArchRegExpMacroAssembler m(NativeRegExpMacroAssembler::ASCII, 4); | 940 ArchRegExpMacroAssembler m(NativeRegExpMacroAssembler::ASCII, 4, |
| 941 Isolate::Current()->zone()); |
| 932 | 942 |
| 933 m.WriteCurrentPositionToRegister(0, 0); | 943 m.WriteCurrentPositionToRegister(0, 0); |
| 934 m.AdvanceCurrentPosition(2); | 944 m.AdvanceCurrentPosition(2); |
| 935 m.WriteCurrentPositionToRegister(1, 0); | 945 m.WriteCurrentPositionToRegister(1, 0); |
| 936 Label nomatch; | 946 Label nomatch; |
| 937 m.CheckNotBackReference(0, &nomatch); | 947 m.CheckNotBackReference(0, &nomatch); |
| 938 m.Fail(); | 948 m.Fail(); |
| 939 m.Bind(&nomatch); | 949 m.Bind(&nomatch); |
| 940 m.AdvanceCurrentPosition(2); | 950 m.AdvanceCurrentPosition(2); |
| 941 Label missing_match; | 951 Label missing_match; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 968 CHECK_EQ(6, output[2]); | 978 CHECK_EQ(6, output[2]); |
| 969 CHECK_EQ(-1, output[3]); | 979 CHECK_EQ(-1, output[3]); |
| 970 } | 980 } |
| 971 | 981 |
| 972 | 982 |
| 973 TEST(MacroAssemblerNativeBackReferenceUC16) { | 983 TEST(MacroAssemblerNativeBackReferenceUC16) { |
| 974 v8::V8::Initialize(); | 984 v8::V8::Initialize(); |
| 975 ContextInitializer initializer; | 985 ContextInitializer initializer; |
| 976 Factory* factory = Isolate::Current()->factory(); | 986 Factory* factory = Isolate::Current()->factory(); |
| 977 | 987 |
| 978 ArchRegExpMacroAssembler m(NativeRegExpMacroAssembler::UC16, 4); | 988 ArchRegExpMacroAssembler m(NativeRegExpMacroAssembler::UC16, 4, |
| 989 Isolate::Current()->zone()); |
| 979 | 990 |
| 980 m.WriteCurrentPositionToRegister(0, 0); | 991 m.WriteCurrentPositionToRegister(0, 0); |
| 981 m.AdvanceCurrentPosition(2); | 992 m.AdvanceCurrentPosition(2); |
| 982 m.WriteCurrentPositionToRegister(1, 0); | 993 m.WriteCurrentPositionToRegister(1, 0); |
| 983 Label nomatch; | 994 Label nomatch; |
| 984 m.CheckNotBackReference(0, &nomatch); | 995 m.CheckNotBackReference(0, &nomatch); |
| 985 m.Fail(); | 996 m.Fail(); |
| 986 m.Bind(&nomatch); | 997 m.Bind(&nomatch); |
| 987 m.AdvanceCurrentPosition(2); | 998 m.AdvanceCurrentPosition(2); |
| 988 Label missing_match; | 999 Label missing_match; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1018 CHECK_EQ(-1, output[3]); | 1029 CHECK_EQ(-1, output[3]); |
| 1019 } | 1030 } |
| 1020 | 1031 |
| 1021 | 1032 |
| 1022 | 1033 |
| 1023 TEST(MacroAssemblernativeAtStart) { | 1034 TEST(MacroAssemblernativeAtStart) { |
| 1024 v8::V8::Initialize(); | 1035 v8::V8::Initialize(); |
| 1025 ContextInitializer initializer; | 1036 ContextInitializer initializer; |
| 1026 Factory* factory = Isolate::Current()->factory(); | 1037 Factory* factory = Isolate::Current()->factory(); |
| 1027 | 1038 |
| 1028 ArchRegExpMacroAssembler m(NativeRegExpMacroAssembler::ASCII, 0); | 1039 ArchRegExpMacroAssembler m(NativeRegExpMacroAssembler::ASCII, 0, |
| 1040 Isolate::Current()->zone()); |
| 1029 | 1041 |
| 1030 Label not_at_start, newline, fail; | 1042 Label not_at_start, newline, fail; |
| 1031 m.CheckNotAtStart(¬_at_start); | 1043 m.CheckNotAtStart(¬_at_start); |
| 1032 // Check that prevchar = '\n' and current = 'f'. | 1044 // Check that prevchar = '\n' and current = 'f'. |
| 1033 m.CheckCharacter('\n', &newline); | 1045 m.CheckCharacter('\n', &newline); |
| 1034 m.Bind(&fail); | 1046 m.Bind(&fail); |
| 1035 m.Fail(); | 1047 m.Fail(); |
| 1036 m.Bind(&newline); | 1048 m.Bind(&newline); |
| 1037 m.LoadCurrentCharacter(0, &fail); | 1049 m.LoadCurrentCharacter(0, &fail); |
| 1038 m.CheckNotCharacter('f', &fail); | 1050 m.CheckNotCharacter('f', &fail); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1075 | 1087 |
| 1076 CHECK_EQ(NativeRegExpMacroAssembler::SUCCESS, result); | 1088 CHECK_EQ(NativeRegExpMacroAssembler::SUCCESS, result); |
| 1077 } | 1089 } |
| 1078 | 1090 |
| 1079 | 1091 |
| 1080 TEST(MacroAssemblerNativeBackRefNoCase) { | 1092 TEST(MacroAssemblerNativeBackRefNoCase) { |
| 1081 v8::V8::Initialize(); | 1093 v8::V8::Initialize(); |
| 1082 ContextInitializer initializer; | 1094 ContextInitializer initializer; |
| 1083 Factory* factory = Isolate::Current()->factory(); | 1095 Factory* factory = Isolate::Current()->factory(); |
| 1084 | 1096 |
| 1085 ArchRegExpMacroAssembler m(NativeRegExpMacroAssembler::ASCII, 4); | 1097 ArchRegExpMacroAssembler m(NativeRegExpMacroAssembler::ASCII, 4, |
| 1098 Isolate::Current()->zone()); |
| 1086 | 1099 |
| 1087 Label fail, succ; | 1100 Label fail, succ; |
| 1088 | 1101 |
| 1089 m.WriteCurrentPositionToRegister(0, 0); | 1102 m.WriteCurrentPositionToRegister(0, 0); |
| 1090 m.WriteCurrentPositionToRegister(2, 0); | 1103 m.WriteCurrentPositionToRegister(2, 0); |
| 1091 m.AdvanceCurrentPosition(3); | 1104 m.AdvanceCurrentPosition(3); |
| 1092 m.WriteCurrentPositionToRegister(3, 0); | 1105 m.WriteCurrentPositionToRegister(3, 0); |
| 1093 m.CheckNotBackReferenceIgnoreCase(2, &fail); // Match "AbC". | 1106 m.CheckNotBackReferenceIgnoreCase(2, &fail); // Match "AbC". |
| 1094 m.CheckNotBackReferenceIgnoreCase(2, &fail); // Match "ABC". | 1107 m.CheckNotBackReferenceIgnoreCase(2, &fail); // Match "ABC". |
| 1095 Label expected_fail; | 1108 Label expected_fail; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1132 CHECK_EQ(3, output[3]); | 1145 CHECK_EQ(3, output[3]); |
| 1133 } | 1146 } |
| 1134 | 1147 |
| 1135 | 1148 |
| 1136 | 1149 |
| 1137 TEST(MacroAssemblerNativeRegisters) { | 1150 TEST(MacroAssemblerNativeRegisters) { |
| 1138 v8::V8::Initialize(); | 1151 v8::V8::Initialize(); |
| 1139 ContextInitializer initializer; | 1152 ContextInitializer initializer; |
| 1140 Factory* factory = Isolate::Current()->factory(); | 1153 Factory* factory = Isolate::Current()->factory(); |
| 1141 | 1154 |
| 1142 ArchRegExpMacroAssembler m(NativeRegExpMacroAssembler::ASCII, 6); | 1155 ArchRegExpMacroAssembler m(NativeRegExpMacroAssembler::ASCII, 6, |
| 1156 Isolate::Current()->zone()); |
| 1143 | 1157 |
| 1144 uc16 foo_chars[3] = {'f', 'o', 'o'}; | 1158 uc16 foo_chars[3] = {'f', 'o', 'o'}; |
| 1145 Vector<const uc16> foo(foo_chars, 3); | 1159 Vector<const uc16> foo(foo_chars, 3); |
| 1146 | 1160 |
| 1147 enum registers { out1, out2, out3, out4, out5, out6, sp, loop_cnt }; | 1161 enum registers { out1, out2, out3, out4, out5, out6, sp, loop_cnt }; |
| 1148 Label fail; | 1162 Label fail; |
| 1149 Label backtrack; | 1163 Label backtrack; |
| 1150 m.WriteCurrentPositionToRegister(out1, 0); // Output: [0] | 1164 m.WriteCurrentPositionToRegister(out1, 0); // Output: [0] |
| 1151 m.PushRegister(out1, RegExpMacroAssembler::kNoStackLimitCheck); | 1165 m.PushRegister(out1, RegExpMacroAssembler::kNoStackLimitCheck); |
| 1152 m.PushBacktrack(&backtrack); | 1166 m.PushBacktrack(&backtrack); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1234 CHECK_EQ(-1, output[5]); | 1248 CHECK_EQ(-1, output[5]); |
| 1235 } | 1249 } |
| 1236 | 1250 |
| 1237 | 1251 |
| 1238 TEST(MacroAssemblerStackOverflow) { | 1252 TEST(MacroAssemblerStackOverflow) { |
| 1239 v8::V8::Initialize(); | 1253 v8::V8::Initialize(); |
| 1240 ContextInitializer initializer; | 1254 ContextInitializer initializer; |
| 1241 Isolate* isolate = Isolate::Current(); | 1255 Isolate* isolate = Isolate::Current(); |
| 1242 Factory* factory = isolate->factory(); | 1256 Factory* factory = isolate->factory(); |
| 1243 | 1257 |
| 1244 ArchRegExpMacroAssembler m(NativeRegExpMacroAssembler::ASCII, 0); | 1258 ArchRegExpMacroAssembler m(NativeRegExpMacroAssembler::ASCII, 0, |
| 1259 Isolate::Current()->zone()); |
| 1245 | 1260 |
| 1246 Label loop; | 1261 Label loop; |
| 1247 m.Bind(&loop); | 1262 m.Bind(&loop); |
| 1248 m.PushBacktrack(&loop); | 1263 m.PushBacktrack(&loop); |
| 1249 m.GoTo(&loop); | 1264 m.GoTo(&loop); |
| 1250 | 1265 |
| 1251 Handle<String> source = | 1266 Handle<String> source = |
| 1252 factory->NewStringFromAscii(CStrVector("<stack overflow test>")); | 1267 factory->NewStringFromAscii(CStrVector("<stack overflow test>")); |
| 1253 Handle<Object> code_object = m.GetCode(source); | 1268 Handle<Object> code_object = m.GetCode(source); |
| 1254 Handle<Code> code = Handle<Code>::cast(code_object); | 1269 Handle<Code> code = Handle<Code>::cast(code_object); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1272 isolate->clear_pending_exception(); | 1287 isolate->clear_pending_exception(); |
| 1273 } | 1288 } |
| 1274 | 1289 |
| 1275 | 1290 |
| 1276 TEST(MacroAssemblerNativeLotsOfRegisters) { | 1291 TEST(MacroAssemblerNativeLotsOfRegisters) { |
| 1277 v8::V8::Initialize(); | 1292 v8::V8::Initialize(); |
| 1278 ContextInitializer initializer; | 1293 ContextInitializer initializer; |
| 1279 Isolate* isolate = Isolate::Current(); | 1294 Isolate* isolate = Isolate::Current(); |
| 1280 Factory* factory = isolate->factory(); | 1295 Factory* factory = isolate->factory(); |
| 1281 | 1296 |
| 1282 ArchRegExpMacroAssembler m(NativeRegExpMacroAssembler::ASCII, 2); | 1297 ArchRegExpMacroAssembler m(NativeRegExpMacroAssembler::ASCII, 2, |
| 1298 Isolate::Current()->zone()); |
| 1283 | 1299 |
| 1284 // At least 2048, to ensure the allocated space for registers | 1300 // At least 2048, to ensure the allocated space for registers |
| 1285 // span one full page. | 1301 // span one full page. |
| 1286 const int large_number = 8000; | 1302 const int large_number = 8000; |
| 1287 m.WriteCurrentPositionToRegister(large_number, 42); | 1303 m.WriteCurrentPositionToRegister(large_number, 42); |
| 1288 m.WriteCurrentPositionToRegister(0, 0); | 1304 m.WriteCurrentPositionToRegister(0, 0); |
| 1289 m.WriteCurrentPositionToRegister(1, 1); | 1305 m.WriteCurrentPositionToRegister(1, 1); |
| 1290 Label done; | 1306 Label done; |
| 1291 m.CheckNotBackReference(0, &done); // Performs a system-stack push. | 1307 m.CheckNotBackReference(0, &done); // Performs a system-stack push. |
| 1292 m.Bind(&done); | 1308 m.Bind(&done); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1390 | 1406 |
| 1391 #endif // V8_INTERPRETED_REGEXP | 1407 #endif // V8_INTERPRETED_REGEXP |
| 1392 | 1408 |
| 1393 | 1409 |
| 1394 TEST(AddInverseToTable) { | 1410 TEST(AddInverseToTable) { |
| 1395 v8::internal::V8::Initialize(NULL); | 1411 v8::internal::V8::Initialize(NULL); |
| 1396 static const int kLimit = 1000; | 1412 static const int kLimit = 1000; |
| 1397 static const int kRangeCount = 16; | 1413 static const int kRangeCount = 16; |
| 1398 for (int t = 0; t < 10; t++) { | 1414 for (int t = 0; t < 10; t++) { |
| 1399 ZoneScope zone_scope(Isolate::Current(), DELETE_ON_EXIT); | 1415 ZoneScope zone_scope(Isolate::Current(), DELETE_ON_EXIT); |
| 1416 Zone* zone = Isolate::Current()->zone(); |
| 1400 ZoneList<CharacterRange>* ranges = | 1417 ZoneList<CharacterRange>* ranges = |
| 1401 new ZoneList<CharacterRange>(kRangeCount); | 1418 new(zone) |
| 1419 ZoneList<CharacterRange>(kRangeCount, zone); |
| 1402 for (int i = 0; i < kRangeCount; i++) { | 1420 for (int i = 0; i < kRangeCount; i++) { |
| 1403 int from = PseudoRandom(t + 87, i + 25) % kLimit; | 1421 int from = PseudoRandom(t + 87, i + 25) % kLimit; |
| 1404 int to = from + (PseudoRandom(i + 87, t + 25) % (kLimit / 20)); | 1422 int to = from + (PseudoRandom(i + 87, t + 25) % (kLimit / 20)); |
| 1405 if (to > kLimit) to = kLimit; | 1423 if (to > kLimit) to = kLimit; |
| 1406 ranges->Add(CharacterRange(from, to)); | 1424 ranges->Add(CharacterRange(from, to), zone); |
| 1407 } | 1425 } |
| 1408 DispatchTable table; | 1426 DispatchTable table; |
| 1409 DispatchTableConstructor cons(&table, false); | 1427 DispatchTableConstructor cons(&table, false, Isolate::Current()->zone()); |
| 1410 cons.set_choice_index(0); | 1428 cons.set_choice_index(0); |
| 1411 cons.AddInverse(ranges); | 1429 cons.AddInverse(ranges); |
| 1412 for (int i = 0; i < kLimit; i++) { | 1430 for (int i = 0; i < kLimit; i++) { |
| 1413 bool is_on = false; | 1431 bool is_on = false; |
| 1414 for (int j = 0; !is_on && j < kRangeCount; j++) | 1432 for (int j = 0; !is_on && j < kRangeCount; j++) |
| 1415 is_on = ranges->at(j).Contains(i); | 1433 is_on = ranges->at(j).Contains(i); |
| 1416 OutSet* set = table.Get(i); | 1434 OutSet* set = table.Get(i); |
| 1417 CHECK_EQ(is_on, set->Get(0) == false); | 1435 CHECK_EQ(is_on, set->Get(0) == false); |
| 1418 } | 1436 } |
| 1419 } | 1437 } |
| 1420 ZoneScope zone_scope(Isolate::Current(), DELETE_ON_EXIT); | 1438 ZoneScope zone_scope(Isolate::Current(), DELETE_ON_EXIT); |
| 1439 Zone* zone = Isolate::Current()->zone(); |
| 1421 ZoneList<CharacterRange>* ranges = | 1440 ZoneList<CharacterRange>* ranges = |
| 1422 new ZoneList<CharacterRange>(1); | 1441 new(zone) ZoneList<CharacterRange>(1, zone); |
| 1423 ranges->Add(CharacterRange(0xFFF0, 0xFFFE)); | 1442 ranges->Add(CharacterRange(0xFFF0, 0xFFFE), zone); |
| 1424 DispatchTable table; | 1443 DispatchTable table; |
| 1425 DispatchTableConstructor cons(&table, false); | 1444 DispatchTableConstructor cons(&table, false, Isolate::Current()->zone()); |
| 1426 cons.set_choice_index(0); | 1445 cons.set_choice_index(0); |
| 1427 cons.AddInverse(ranges); | 1446 cons.AddInverse(ranges); |
| 1428 CHECK(!table.Get(0xFFFE)->Get(0)); | 1447 CHECK(!table.Get(0xFFFE)->Get(0)); |
| 1429 CHECK(table.Get(0xFFFF)->Get(0)); | 1448 CHECK(table.Get(0xFFFF)->Get(0)); |
| 1430 } | 1449 } |
| 1431 | 1450 |
| 1432 | 1451 |
| 1433 static uc32 canonicalize(uc32 c) { | 1452 static uc32 canonicalize(uc32 c) { |
| 1434 unibrow::uchar canon[unibrow::Ecma262Canonicalize::kMaxWidth]; | 1453 unibrow::uchar canon[unibrow::Ecma262Canonicalize::kMaxWidth]; |
| 1435 int count = unibrow::Ecma262Canonicalize::Convert(c, '\0', canon, NULL); | 1454 int count = unibrow::Ecma262Canonicalize::Convert(c, '\0', canon, NULL); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1524 for (int k = 0; k < length; k++) | 1543 for (int k = 0; k < length; k++) |
| 1525 CHECK_EQ(static_cast<int>(chars[k]), static_cast<int>(chars2[k])); | 1544 CHECK_EQ(static_cast<int>(chars[k]), static_cast<int>(chars2[k])); |
| 1526 } | 1545 } |
| 1527 } | 1546 } |
| 1528 } | 1547 } |
| 1529 | 1548 |
| 1530 | 1549 |
| 1531 static void TestRangeCaseIndependence(CharacterRange input, | 1550 static void TestRangeCaseIndependence(CharacterRange input, |
| 1532 Vector<CharacterRange> expected) { | 1551 Vector<CharacterRange> expected) { |
| 1533 ZoneScope zone_scope(Isolate::Current(), DELETE_ON_EXIT); | 1552 ZoneScope zone_scope(Isolate::Current(), DELETE_ON_EXIT); |
| 1553 Zone* zone = Isolate::Current()->zone(); |
| 1534 int count = expected.length(); | 1554 int count = expected.length(); |
| 1535 ZoneList<CharacterRange>* list = new ZoneList<CharacterRange>(count); | 1555 ZoneList<CharacterRange>* list = |
| 1536 input.AddCaseEquivalents(list, false); | 1556 new(zone) ZoneList<CharacterRange>(count, zone); |
| 1557 input.AddCaseEquivalents(list, false, zone); |
| 1537 CHECK_EQ(count, list->length()); | 1558 CHECK_EQ(count, list->length()); |
| 1538 for (int i = 0; i < list->length(); i++) { | 1559 for (int i = 0; i < list->length(); i++) { |
| 1539 CHECK_EQ(expected[i].from(), list->at(i).from()); | 1560 CHECK_EQ(expected[i].from(), list->at(i).from()); |
| 1540 CHECK_EQ(expected[i].to(), list->at(i).to()); | 1561 CHECK_EQ(expected[i].to(), list->at(i).to()); |
| 1541 } | 1562 } |
| 1542 } | 1563 } |
| 1543 | 1564 |
| 1544 | 1565 |
| 1545 static void TestSimpleRangeCaseIndependence(CharacterRange input, | 1566 static void TestSimpleRangeCaseIndependence(CharacterRange input, |
| 1546 CharacterRange expected) { | 1567 CharacterRange expected) { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1588 if (range.from() <= c && c <= range.to()) | 1609 if (range.from() <= c && c <= range.to()) |
| 1589 return true; | 1610 return true; |
| 1590 } | 1611 } |
| 1591 return false; | 1612 return false; |
| 1592 } | 1613 } |
| 1593 | 1614 |
| 1594 | 1615 |
| 1595 TEST(CharClassDifference) { | 1616 TEST(CharClassDifference) { |
| 1596 v8::internal::V8::Initialize(NULL); | 1617 v8::internal::V8::Initialize(NULL); |
| 1597 ZoneScope zone_scope(Isolate::Current(), DELETE_ON_EXIT); | 1618 ZoneScope zone_scope(Isolate::Current(), DELETE_ON_EXIT); |
| 1598 ZoneList<CharacterRange>* base = new ZoneList<CharacterRange>(1); | 1619 Zone* zone = Isolate::Current()->zone(); |
| 1599 base->Add(CharacterRange::Everything()); | 1620 ZoneList<CharacterRange>* base = |
| 1621 new(zone) ZoneList<CharacterRange>(1, zone); |
| 1622 base->Add(CharacterRange::Everything(), zone); |
| 1600 Vector<const int> overlay = CharacterRange::GetWordBounds(); | 1623 Vector<const int> overlay = CharacterRange::GetWordBounds(); |
| 1601 ZoneList<CharacterRange>* included = NULL; | 1624 ZoneList<CharacterRange>* included = NULL; |
| 1602 ZoneList<CharacterRange>* excluded = NULL; | 1625 ZoneList<CharacterRange>* excluded = NULL; |
| 1603 CharacterRange::Split(base, overlay, &included, &excluded); | 1626 CharacterRange::Split(base, overlay, &included, &excluded, |
| 1627 Isolate::Current()->zone()); |
| 1604 for (int i = 0; i < (1 << 16); i++) { | 1628 for (int i = 0; i < (1 << 16); i++) { |
| 1605 bool in_base = InClass(i, base); | 1629 bool in_base = InClass(i, base); |
| 1606 if (in_base) { | 1630 if (in_base) { |
| 1607 bool in_overlay = false; | 1631 bool in_overlay = false; |
| 1608 for (int j = 0; !in_overlay && j < overlay.length(); j += 2) { | 1632 for (int j = 0; !in_overlay && j < overlay.length(); j += 2) { |
| 1609 if (overlay[j] <= i && i < overlay[j+1]) | 1633 if (overlay[j] <= i && i < overlay[j+1]) |
| 1610 in_overlay = true; | 1634 in_overlay = true; |
| 1611 } | 1635 } |
| 1612 CHECK_EQ(in_overlay, InClass(i, included)); | 1636 CHECK_EQ(in_overlay, InClass(i, included)); |
| 1613 CHECK_EQ(!in_overlay, InClass(i, excluded)); | 1637 CHECK_EQ(!in_overlay, InClass(i, excluded)); |
| 1614 } else { | 1638 } else { |
| 1615 CHECK(!InClass(i, included)); | 1639 CHECK(!InClass(i, included)); |
| 1616 CHECK(!InClass(i, excluded)); | 1640 CHECK(!InClass(i, excluded)); |
| 1617 } | 1641 } |
| 1618 } | 1642 } |
| 1619 } | 1643 } |
| 1620 | 1644 |
| 1621 | 1645 |
| 1622 TEST(CanonicalizeCharacterSets) { | 1646 TEST(CanonicalizeCharacterSets) { |
| 1623 v8::internal::V8::Initialize(NULL); | 1647 v8::internal::V8::Initialize(NULL); |
| 1624 ZoneScope scope(Isolate::Current(), DELETE_ON_EXIT); | 1648 ZoneScope scope(Isolate::Current(), DELETE_ON_EXIT); |
| 1625 ZoneList<CharacterRange>* list = new ZoneList<CharacterRange>(4); | 1649 Zone* zone = Isolate::Current()->zone(); |
| 1650 ZoneList<CharacterRange>* list = |
| 1651 new(zone) ZoneList<CharacterRange>(4, zone); |
| 1626 CharacterSet set(list); | 1652 CharacterSet set(list); |
| 1627 | 1653 |
| 1628 list->Add(CharacterRange(10, 20)); | 1654 list->Add(CharacterRange(10, 20), zone); |
| 1629 list->Add(CharacterRange(30, 40)); | 1655 list->Add(CharacterRange(30, 40), zone); |
| 1630 list->Add(CharacterRange(50, 60)); | 1656 list->Add(CharacterRange(50, 60), zone); |
| 1631 set.Canonicalize(); | 1657 set.Canonicalize(); |
| 1632 ASSERT_EQ(3, list->length()); | 1658 ASSERT_EQ(3, list->length()); |
| 1633 ASSERT_EQ(10, list->at(0).from()); | 1659 ASSERT_EQ(10, list->at(0).from()); |
| 1634 ASSERT_EQ(20, list->at(0).to()); | 1660 ASSERT_EQ(20, list->at(0).to()); |
| 1635 ASSERT_EQ(30, list->at(1).from()); | 1661 ASSERT_EQ(30, list->at(1).from()); |
| 1636 ASSERT_EQ(40, list->at(1).to()); | 1662 ASSERT_EQ(40, list->at(1).to()); |
| 1637 ASSERT_EQ(50, list->at(2).from()); | 1663 ASSERT_EQ(50, list->at(2).from()); |
| 1638 ASSERT_EQ(60, list->at(2).to()); | 1664 ASSERT_EQ(60, list->at(2).to()); |
| 1639 | 1665 |
| 1640 list->Rewind(0); | 1666 list->Rewind(0); |
| 1641 list->Add(CharacterRange(10, 20)); | 1667 list->Add(CharacterRange(10, 20), zone); |
| 1642 list->Add(CharacterRange(50, 60)); | 1668 list->Add(CharacterRange(50, 60), zone); |
| 1643 list->Add(CharacterRange(30, 40)); | 1669 list->Add(CharacterRange(30, 40), zone); |
| 1644 set.Canonicalize(); | 1670 set.Canonicalize(); |
| 1645 ASSERT_EQ(3, list->length()); | 1671 ASSERT_EQ(3, list->length()); |
| 1646 ASSERT_EQ(10, list->at(0).from()); | 1672 ASSERT_EQ(10, list->at(0).from()); |
| 1647 ASSERT_EQ(20, list->at(0).to()); | 1673 ASSERT_EQ(20, list->at(0).to()); |
| 1648 ASSERT_EQ(30, list->at(1).from()); | 1674 ASSERT_EQ(30, list->at(1).from()); |
| 1649 ASSERT_EQ(40, list->at(1).to()); | 1675 ASSERT_EQ(40, list->at(1).to()); |
| 1650 ASSERT_EQ(50, list->at(2).from()); | 1676 ASSERT_EQ(50, list->at(2).from()); |
| 1651 ASSERT_EQ(60, list->at(2).to()); | 1677 ASSERT_EQ(60, list->at(2).to()); |
| 1652 | 1678 |
| 1653 list->Rewind(0); | 1679 list->Rewind(0); |
| 1654 list->Add(CharacterRange(30, 40)); | 1680 list->Add(CharacterRange(30, 40), zone); |
| 1655 list->Add(CharacterRange(10, 20)); | 1681 list->Add(CharacterRange(10, 20), zone); |
| 1656 list->Add(CharacterRange(25, 25)); | 1682 list->Add(CharacterRange(25, 25), zone); |
| 1657 list->Add(CharacterRange(100, 100)); | 1683 list->Add(CharacterRange(100, 100), zone); |
| 1658 list->Add(CharacterRange(1, 1)); | 1684 list->Add(CharacterRange(1, 1), zone); |
| 1659 set.Canonicalize(); | 1685 set.Canonicalize(); |
| 1660 ASSERT_EQ(5, list->length()); | 1686 ASSERT_EQ(5, list->length()); |
| 1661 ASSERT_EQ(1, list->at(0).from()); | 1687 ASSERT_EQ(1, list->at(0).from()); |
| 1662 ASSERT_EQ(1, list->at(0).to()); | 1688 ASSERT_EQ(1, list->at(0).to()); |
| 1663 ASSERT_EQ(10, list->at(1).from()); | 1689 ASSERT_EQ(10, list->at(1).from()); |
| 1664 ASSERT_EQ(20, list->at(1).to()); | 1690 ASSERT_EQ(20, list->at(1).to()); |
| 1665 ASSERT_EQ(25, list->at(2).from()); | 1691 ASSERT_EQ(25, list->at(2).from()); |
| 1666 ASSERT_EQ(25, list->at(2).to()); | 1692 ASSERT_EQ(25, list->at(2).to()); |
| 1667 ASSERT_EQ(30, list->at(3).from()); | 1693 ASSERT_EQ(30, list->at(3).from()); |
| 1668 ASSERT_EQ(40, list->at(3).to()); | 1694 ASSERT_EQ(40, list->at(3).to()); |
| 1669 ASSERT_EQ(100, list->at(4).from()); | 1695 ASSERT_EQ(100, list->at(4).from()); |
| 1670 ASSERT_EQ(100, list->at(4).to()); | 1696 ASSERT_EQ(100, list->at(4).to()); |
| 1671 | 1697 |
| 1672 list->Rewind(0); | 1698 list->Rewind(0); |
| 1673 list->Add(CharacterRange(10, 19)); | 1699 list->Add(CharacterRange(10, 19), zone); |
| 1674 list->Add(CharacterRange(21, 30)); | 1700 list->Add(CharacterRange(21, 30), zone); |
| 1675 list->Add(CharacterRange(20, 20)); | 1701 list->Add(CharacterRange(20, 20), zone); |
| 1676 set.Canonicalize(); | 1702 set.Canonicalize(); |
| 1677 ASSERT_EQ(1, list->length()); | 1703 ASSERT_EQ(1, list->length()); |
| 1678 ASSERT_EQ(10, list->at(0).from()); | 1704 ASSERT_EQ(10, list->at(0).from()); |
| 1679 ASSERT_EQ(30, list->at(0).to()); | 1705 ASSERT_EQ(30, list->at(0).to()); |
| 1680 } | 1706 } |
| 1681 | 1707 |
| 1682 | 1708 |
| 1683 TEST(CharacterRangeMerge) { | 1709 TEST(CharacterRangeMerge) { |
| 1684 v8::internal::V8::Initialize(NULL); | 1710 v8::internal::V8::Initialize(NULL); |
| 1685 ZoneScope zone_scope(Isolate::Current(), DELETE_ON_EXIT); | 1711 ZoneScope zone_scope(Isolate::Current(), DELETE_ON_EXIT); |
| 1686 ZoneList<CharacterRange> l1(4); | 1712 ZoneList<CharacterRange> l1(4, Isolate::Current()->zone()); |
| 1687 ZoneList<CharacterRange> l2(4); | 1713 ZoneList<CharacterRange> l2(4, Isolate::Current()->zone()); |
| 1714 Zone* zone = Isolate::Current()->zone(); |
| 1688 // Create all combinations of intersections of ranges, both singletons and | 1715 // Create all combinations of intersections of ranges, both singletons and |
| 1689 // longer. | 1716 // longer. |
| 1690 | 1717 |
| 1691 int offset = 0; | 1718 int offset = 0; |
| 1692 | 1719 |
| 1693 // The five kinds of singleton intersections: | 1720 // The five kinds of singleton intersections: |
| 1694 // X | 1721 // X |
| 1695 // Y - outside before | 1722 // Y - outside before |
| 1696 // Y - outside touching start | 1723 // Y - outside touching start |
| 1697 // Y - overlap | 1724 // Y - overlap |
| 1698 // Y - outside touching end | 1725 // Y - outside touching end |
| 1699 // Y - outside after | 1726 // Y - outside after |
| 1700 | 1727 |
| 1701 for (int i = 0; i < 5; i++) { | 1728 for (int i = 0; i < 5; i++) { |
| 1702 l1.Add(CharacterRange::Singleton(offset + 2)); | 1729 l1.Add(CharacterRange::Singleton(offset + 2), zone); |
| 1703 l2.Add(CharacterRange::Singleton(offset + i)); | 1730 l2.Add(CharacterRange::Singleton(offset + i), zone); |
| 1704 offset += 6; | 1731 offset += 6; |
| 1705 } | 1732 } |
| 1706 | 1733 |
| 1707 // The seven kinds of singleton/non-singleton intersections: | 1734 // The seven kinds of singleton/non-singleton intersections: |
| 1708 // XXX | 1735 // XXX |
| 1709 // Y - outside before | 1736 // Y - outside before |
| 1710 // Y - outside touching start | 1737 // Y - outside touching start |
| 1711 // Y - inside touching start | 1738 // Y - inside touching start |
| 1712 // Y - entirely inside | 1739 // Y - entirely inside |
| 1713 // Y - inside touching end | 1740 // Y - inside touching end |
| 1714 // Y - outside touching end | 1741 // Y - outside touching end |
| 1715 // Y - disjoint after | 1742 // Y - disjoint after |
| 1716 | 1743 |
| 1717 for (int i = 0; i < 7; i++) { | 1744 for (int i = 0; i < 7; i++) { |
| 1718 l1.Add(CharacterRange::Range(offset + 2, offset + 4)); | 1745 l1.Add(CharacterRange::Range(offset + 2, offset + 4), zone); |
| 1719 l2.Add(CharacterRange::Singleton(offset + i)); | 1746 l2.Add(CharacterRange::Singleton(offset + i), zone); |
| 1720 offset += 8; | 1747 offset += 8; |
| 1721 } | 1748 } |
| 1722 | 1749 |
| 1723 // The eleven kinds of non-singleton intersections: | 1750 // The eleven kinds of non-singleton intersections: |
| 1724 // | 1751 // |
| 1725 // XXXXXXXX | 1752 // XXXXXXXX |
| 1726 // YYYY - outside before. | 1753 // YYYY - outside before. |
| 1727 // YYYY - outside touching start. | 1754 // YYYY - outside touching start. |
| 1728 // YYYY - overlapping start | 1755 // YYYY - overlapping start |
| 1729 // YYYY - inside touching start | 1756 // YYYY - inside touching start |
| 1730 // YYYY - entirely inside | 1757 // YYYY - entirely inside |
| 1731 // YYYY - inside touching end | 1758 // YYYY - inside touching end |
| 1732 // YYYY - overlapping end | 1759 // YYYY - overlapping end |
| 1733 // YYYY - outside touching end | 1760 // YYYY - outside touching end |
| 1734 // YYYY - outside after | 1761 // YYYY - outside after |
| 1735 // YYYYYYYY - identical | 1762 // YYYYYYYY - identical |
| 1736 // YYYYYYYYYYYY - containing entirely. | 1763 // YYYYYYYYYYYY - containing entirely. |
| 1737 | 1764 |
| 1738 for (int i = 0; i < 9; i++) { | 1765 for (int i = 0; i < 9; i++) { |
| 1739 l1.Add(CharacterRange::Range(offset + 6, offset + 15)); // Length 8. | 1766 l1.Add(CharacterRange::Range(offset + 6, offset + 15), zone); // Length 8. |
| 1740 l2.Add(CharacterRange::Range(offset + 2 * i, offset + 2 * i + 3)); | 1767 l2.Add(CharacterRange::Range(offset + 2 * i, offset + 2 * i + 3), zone); |
| 1741 offset += 22; | 1768 offset += 22; |
| 1742 } | 1769 } |
| 1743 l1.Add(CharacterRange::Range(offset + 6, offset + 15)); | 1770 l1.Add(CharacterRange::Range(offset + 6, offset + 15), zone); |
| 1744 l2.Add(CharacterRange::Range(offset + 6, offset + 15)); | 1771 l2.Add(CharacterRange::Range(offset + 6, offset + 15), zone); |
| 1745 offset += 22; | 1772 offset += 22; |
| 1746 l1.Add(CharacterRange::Range(offset + 6, offset + 15)); | 1773 l1.Add(CharacterRange::Range(offset + 6, offset + 15), zone); |
| 1747 l2.Add(CharacterRange::Range(offset + 4, offset + 17)); | 1774 l2.Add(CharacterRange::Range(offset + 4, offset + 17), zone); |
| 1748 offset += 22; | 1775 offset += 22; |
| 1749 | 1776 |
| 1750 // Different kinds of multi-range overlap: | 1777 // Different kinds of multi-range overlap: |
| 1751 // XXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXX | 1778 // XXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXX |
| 1752 // YYYY Y YYYY Y YYYY Y YYYY Y YYYY Y YYYY Y | 1779 // YYYY Y YYYY Y YYYY Y YYYY Y YYYY Y YYYY Y |
| 1753 | 1780 |
| 1754 l1.Add(CharacterRange::Range(offset, offset + 21)); | 1781 l1.Add(CharacterRange::Range(offset, offset + 21), zone); |
| 1755 l1.Add(CharacterRange::Range(offset + 31, offset + 52)); | 1782 l1.Add(CharacterRange::Range(offset + 31, offset + 52), zone); |
| 1756 for (int i = 0; i < 6; i++) { | 1783 for (int i = 0; i < 6; i++) { |
| 1757 l2.Add(CharacterRange::Range(offset + 2, offset + 5)); | 1784 l2.Add(CharacterRange::Range(offset + 2, offset + 5), zone); |
| 1758 l2.Add(CharacterRange::Singleton(offset + 8)); | 1785 l2.Add(CharacterRange::Singleton(offset + 8), zone); |
| 1759 offset += 9; | 1786 offset += 9; |
| 1760 } | 1787 } |
| 1761 | 1788 |
| 1762 ASSERT(CharacterRange::IsCanonical(&l1)); | 1789 ASSERT(CharacterRange::IsCanonical(&l1)); |
| 1763 ASSERT(CharacterRange::IsCanonical(&l2)); | 1790 ASSERT(CharacterRange::IsCanonical(&l2)); |
| 1764 | 1791 |
| 1765 ZoneList<CharacterRange> first_only(4); | 1792 ZoneList<CharacterRange> first_only(4, Isolate::Current()->zone()); |
| 1766 ZoneList<CharacterRange> second_only(4); | 1793 ZoneList<CharacterRange> second_only(4, Isolate::Current()->zone()); |
| 1767 ZoneList<CharacterRange> both(4); | 1794 ZoneList<CharacterRange> both(4, Isolate::Current()->zone()); |
| 1768 } | 1795 } |
| 1769 | 1796 |
| 1770 | 1797 |
| 1771 TEST(Graph) { | 1798 TEST(Graph) { |
| 1772 V8::Initialize(NULL); | 1799 V8::Initialize(NULL); |
| 1773 Execute("\\b\\w+\\b", false, true, true); | 1800 Execute("\\b\\w+\\b", false, true, true); |
| 1774 } | 1801 } |
| OLD | NEW |