| 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 668 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 679 for (int j = 1; j < 2 * kRangeSize; j++) { | 679 for (int j = 1; j < 2 * kRangeSize; j++) { |
| 680 CHECK(range[j-1] <= range[j]); | 680 CHECK(range[j-1] <= range[j]); |
| 681 } | 681 } |
| 682 } | 682 } |
| 683 // Enter test data into dispatch table. | 683 // Enter test data into dispatch table. |
| 684 Zone zone; | 684 Zone zone; |
| 685 DispatchTable table(&zone); | 685 DispatchTable table(&zone); |
| 686 for (int i = 0; i < kRangeCount; i++) { | 686 for (int i = 0; i < kRangeCount; i++) { |
| 687 uc16* range = ranges[i]; | 687 uc16* range = ranges[i]; |
| 688 for (int j = 0; j < 2 * kRangeSize; j += 2) | 688 for (int j = 0; j < 2 * kRangeSize; j += 2) |
| 689 table.AddRange(CharacterRange(range[j], range[j + 1]), i, &zone); | 689 table.AddRange(CharacterRange::Range(range[j], range[j + 1]), i, &zone); |
| 690 } | 690 } |
| 691 // Check that the table looks as we would expect | 691 // Check that the table looks as we would expect |
| 692 for (int p = 0; p < kLimit; p++) { | 692 for (int p = 0; p < kLimit; p++) { |
| 693 OutSet* outs = table.Get(p); | 693 OutSet* outs = table.Get(p); |
| 694 for (int j = 0; j < kRangeCount; j++) { | 694 for (int j = 0; j < kRangeCount; j++) { |
| 695 uc16* range = ranges[j]; | 695 uc16* range = ranges[j]; |
| 696 bool is_on = false; | 696 bool is_on = false; |
| 697 for (int k = 0; !is_on && (k < 2 * kRangeSize); k += 2) | 697 for (int k = 0; !is_on && (k < 2 * kRangeSize); k += 2) |
| 698 is_on = (range[k] <= p && p <= range[k + 1]); | 698 is_on = (range[k] <= p && p <= range[k + 1]); |
| 699 CHECK_EQ(is_on, outs->Get(j)); | 699 CHECK_EQ(is_on, outs->Get(j)); |
| (...skipping 791 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1491 static const int kLimit = 1000; | 1491 static const int kLimit = 1000; |
| 1492 static const int kRangeCount = 16; | 1492 static const int kRangeCount = 16; |
| 1493 for (int t = 0; t < 10; t++) { | 1493 for (int t = 0; t < 10; t++) { |
| 1494 Zone zone; | 1494 Zone zone; |
| 1495 ZoneList<CharacterRange>* ranges = | 1495 ZoneList<CharacterRange>* ranges = |
| 1496 new(&zone) ZoneList<CharacterRange>(kRangeCount, &zone); | 1496 new(&zone) ZoneList<CharacterRange>(kRangeCount, &zone); |
| 1497 for (int i = 0; i < kRangeCount; i++) { | 1497 for (int i = 0; i < kRangeCount; i++) { |
| 1498 int from = PseudoRandom(t + 87, i + 25) % kLimit; | 1498 int from = PseudoRandom(t + 87, i + 25) % kLimit; |
| 1499 int to = from + (PseudoRandom(i + 87, t + 25) % (kLimit / 20)); | 1499 int to = from + (PseudoRandom(i + 87, t + 25) % (kLimit / 20)); |
| 1500 if (to > kLimit) to = kLimit; | 1500 if (to > kLimit) to = kLimit; |
| 1501 ranges->Add(CharacterRange(from, to), &zone); | 1501 ranges->Add(CharacterRange::Range(from, to), &zone); |
| 1502 } | 1502 } |
| 1503 DispatchTable table(&zone); | 1503 DispatchTable table(&zone); |
| 1504 DispatchTableConstructor cons(&table, false, &zone); | 1504 DispatchTableConstructor cons(&table, false, &zone); |
| 1505 cons.set_choice_index(0); | 1505 cons.set_choice_index(0); |
| 1506 cons.AddInverse(ranges); | 1506 cons.AddInverse(ranges); |
| 1507 for (int i = 0; i < kLimit; i++) { | 1507 for (int i = 0; i < kLimit; i++) { |
| 1508 bool is_on = false; | 1508 bool is_on = false; |
| 1509 for (int j = 0; !is_on && j < kRangeCount; j++) | 1509 for (int j = 0; !is_on && j < kRangeCount; j++) |
| 1510 is_on = ranges->at(j).Contains(i); | 1510 is_on = ranges->at(j).Contains(i); |
| 1511 OutSet* set = table.Get(i); | 1511 OutSet* set = table.Get(i); |
| 1512 CHECK_EQ(is_on, set->Get(0) == false); | 1512 CHECK_EQ(is_on, set->Get(0) == false); |
| 1513 } | 1513 } |
| 1514 } | 1514 } |
| 1515 Zone zone; | 1515 Zone zone; |
| 1516 ZoneList<CharacterRange>* ranges = | 1516 ZoneList<CharacterRange>* ranges = |
| 1517 new(&zone) ZoneList<CharacterRange>(1, &zone); | 1517 new(&zone) ZoneList<CharacterRange>(1, &zone); |
| 1518 ranges->Add(CharacterRange(0xFFF0, 0xFFFE), &zone); | 1518 ranges->Add(CharacterRange::Range(0xFFF0, 0xFFFE), &zone); |
| 1519 DispatchTable table(&zone); | 1519 DispatchTable table(&zone); |
| 1520 DispatchTableConstructor cons(&table, false, &zone); | 1520 DispatchTableConstructor cons(&table, false, &zone); |
| 1521 cons.set_choice_index(0); | 1521 cons.set_choice_index(0); |
| 1522 cons.AddInverse(ranges); | 1522 cons.AddInverse(ranges); |
| 1523 CHECK(!table.Get(0xFFFE)->Get(0)); | 1523 CHECK(!table.Get(0xFFFE)->Get(0)); |
| 1524 CHECK(table.Get(0xFFFF)->Get(0)); | 1524 CHECK(table.Get(0xFFFF)->Get(0)); |
| 1525 } | 1525 } |
| 1526 | 1526 |
| 1527 | 1527 |
| 1528 static uc32 canonicalize(uc32 c) { | 1528 static uc32 canonicalize(uc32 c) { |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1648 TestRangeCaseIndependence(isolate, input, vector); | 1648 TestRangeCaseIndependence(isolate, input, vector); |
| 1649 } | 1649 } |
| 1650 | 1650 |
| 1651 | 1651 |
| 1652 TEST(CharacterRangeCaseIndependence) { | 1652 TEST(CharacterRangeCaseIndependence) { |
| 1653 Isolate* isolate = CcTest::i_isolate(); | 1653 Isolate* isolate = CcTest::i_isolate(); |
| 1654 TestSimpleRangeCaseIndependence(isolate, CharacterRange::Singleton('a'), | 1654 TestSimpleRangeCaseIndependence(isolate, CharacterRange::Singleton('a'), |
| 1655 CharacterRange::Singleton('A')); | 1655 CharacterRange::Singleton('A')); |
| 1656 TestSimpleRangeCaseIndependence(isolate, CharacterRange::Singleton('z'), | 1656 TestSimpleRangeCaseIndependence(isolate, CharacterRange::Singleton('z'), |
| 1657 CharacterRange::Singleton('Z')); | 1657 CharacterRange::Singleton('Z')); |
| 1658 TestSimpleRangeCaseIndependence(isolate, CharacterRange('a', 'z'), | 1658 TestSimpleRangeCaseIndependence(isolate, CharacterRange::Range('a', 'z'), |
| 1659 CharacterRange('A', 'Z')); | 1659 CharacterRange::Range('A', 'Z')); |
| 1660 TestSimpleRangeCaseIndependence(isolate, CharacterRange('c', 'f'), | 1660 TestSimpleRangeCaseIndependence(isolate, CharacterRange::Range('c', 'f'), |
| 1661 CharacterRange('C', 'F')); | 1661 CharacterRange::Range('C', 'F')); |
| 1662 TestSimpleRangeCaseIndependence(isolate, CharacterRange('a', 'b'), | 1662 TestSimpleRangeCaseIndependence(isolate, CharacterRange::Range('a', 'b'), |
| 1663 CharacterRange('A', 'B')); | 1663 CharacterRange::Range('A', 'B')); |
| 1664 TestSimpleRangeCaseIndependence(isolate, CharacterRange('y', 'z'), | 1664 TestSimpleRangeCaseIndependence(isolate, CharacterRange::Range('y', 'z'), |
| 1665 CharacterRange('Y', 'Z')); | 1665 CharacterRange::Range('Y', 'Z')); |
| 1666 TestSimpleRangeCaseIndependence(isolate, CharacterRange('a' - 1, 'z' + 1), | 1666 TestSimpleRangeCaseIndependence(isolate, |
| 1667 CharacterRange('A', 'Z')); | 1667 CharacterRange::Range('a' - 1, 'z' + 1), |
| 1668 TestSimpleRangeCaseIndependence(isolate, CharacterRange('A', 'Z'), | 1668 CharacterRange::Range('A', 'Z')); |
| 1669 CharacterRange('a', 'z')); | 1669 TestSimpleRangeCaseIndependence(isolate, CharacterRange::Range('A', 'Z'), |
| 1670 TestSimpleRangeCaseIndependence(isolate, CharacterRange('C', 'F'), | 1670 CharacterRange::Range('a', 'z')); |
| 1671 CharacterRange('c', 'f')); | 1671 TestSimpleRangeCaseIndependence(isolate, CharacterRange::Range('C', 'F'), |
| 1672 TestSimpleRangeCaseIndependence(isolate, CharacterRange('A' - 1, 'Z' + 1), | 1672 CharacterRange::Range('c', 'f')); |
| 1673 CharacterRange('a', 'z')); | 1673 TestSimpleRangeCaseIndependence(isolate, |
| 1674 CharacterRange::Range('A' - 1, 'Z' + 1), |
| 1675 CharacterRange::Range('a', 'z')); |
| 1674 // Here we need to add [l-z] to complete the case independence of | 1676 // Here we need to add [l-z] to complete the case independence of |
| 1675 // [A-Za-z] but we expect [a-z] to be added since we always add a | 1677 // [A-Za-z] but we expect [a-z] to be added since we always add a |
| 1676 // whole block at a time. | 1678 // whole block at a time. |
| 1677 TestSimpleRangeCaseIndependence(isolate, CharacterRange('A', 'k'), | 1679 TestSimpleRangeCaseIndependence(isolate, CharacterRange::Range('A', 'k'), |
| 1678 CharacterRange('a', 'z')); | 1680 CharacterRange::Range('a', 'z')); |
| 1679 } | 1681 } |
| 1680 | 1682 |
| 1681 | 1683 |
| 1682 static bool InClass(uc32 c, ZoneList<CharacterRange>* ranges) { | 1684 static bool InClass(uc32 c, ZoneList<CharacterRange>* ranges) { |
| 1683 if (ranges == NULL) | 1685 if (ranges == NULL) |
| 1684 return false; | 1686 return false; |
| 1685 for (int i = 0; i < ranges->length(); i++) { | 1687 for (int i = 0; i < ranges->length(); i++) { |
| 1686 CharacterRange range = ranges->at(i); | 1688 CharacterRange range = ranges->at(i); |
| 1687 if (range.from() <= c && c <= range.to()) | 1689 if (range.from() <= c && c <= range.to()) |
| 1688 return true; | 1690 return true; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1734 } | 1736 } |
| 1735 } | 1737 } |
| 1736 | 1738 |
| 1737 | 1739 |
| 1738 TEST(CanonicalizeCharacterSets) { | 1740 TEST(CanonicalizeCharacterSets) { |
| 1739 Zone zone; | 1741 Zone zone; |
| 1740 ZoneList<CharacterRange>* list = | 1742 ZoneList<CharacterRange>* list = |
| 1741 new(&zone) ZoneList<CharacterRange>(4, &zone); | 1743 new(&zone) ZoneList<CharacterRange>(4, &zone); |
| 1742 CharacterSet set(list); | 1744 CharacterSet set(list); |
| 1743 | 1745 |
| 1744 list->Add(CharacterRange(10, 20), &zone); | 1746 list->Add(CharacterRange::Range(10, 20), &zone); |
| 1745 list->Add(CharacterRange(30, 40), &zone); | 1747 list->Add(CharacterRange::Range(30, 40), &zone); |
| 1746 list->Add(CharacterRange(50, 60), &zone); | 1748 list->Add(CharacterRange::Range(50, 60), &zone); |
| 1747 set.Canonicalize(); | 1749 set.Canonicalize(); |
| 1748 CHECK_EQ(3, list->length()); | 1750 CHECK_EQ(3, list->length()); |
| 1749 CHECK_EQ(10, list->at(0).from()); | 1751 CHECK_EQ(10, list->at(0).from()); |
| 1750 CHECK_EQ(20, list->at(0).to()); | 1752 CHECK_EQ(20, list->at(0).to()); |
| 1751 CHECK_EQ(30, list->at(1).from()); | 1753 CHECK_EQ(30, list->at(1).from()); |
| 1752 CHECK_EQ(40, list->at(1).to()); | 1754 CHECK_EQ(40, list->at(1).to()); |
| 1753 CHECK_EQ(50, list->at(2).from()); | 1755 CHECK_EQ(50, list->at(2).from()); |
| 1754 CHECK_EQ(60, list->at(2).to()); | 1756 CHECK_EQ(60, list->at(2).to()); |
| 1755 | 1757 |
| 1756 list->Rewind(0); | 1758 list->Rewind(0); |
| 1757 list->Add(CharacterRange(10, 20), &zone); | 1759 list->Add(CharacterRange::Range(10, 20), &zone); |
| 1758 list->Add(CharacterRange(50, 60), &zone); | 1760 list->Add(CharacterRange::Range(50, 60), &zone); |
| 1759 list->Add(CharacterRange(30, 40), &zone); | 1761 list->Add(CharacterRange::Range(30, 40), &zone); |
| 1760 set.Canonicalize(); | 1762 set.Canonicalize(); |
| 1761 CHECK_EQ(3, list->length()); | 1763 CHECK_EQ(3, list->length()); |
| 1762 CHECK_EQ(10, list->at(0).from()); | 1764 CHECK_EQ(10, list->at(0).from()); |
| 1763 CHECK_EQ(20, list->at(0).to()); | 1765 CHECK_EQ(20, list->at(0).to()); |
| 1764 CHECK_EQ(30, list->at(1).from()); | 1766 CHECK_EQ(30, list->at(1).from()); |
| 1765 CHECK_EQ(40, list->at(1).to()); | 1767 CHECK_EQ(40, list->at(1).to()); |
| 1766 CHECK_EQ(50, list->at(2).from()); | 1768 CHECK_EQ(50, list->at(2).from()); |
| 1767 CHECK_EQ(60, list->at(2).to()); | 1769 CHECK_EQ(60, list->at(2).to()); |
| 1768 | 1770 |
| 1769 list->Rewind(0); | 1771 list->Rewind(0); |
| 1770 list->Add(CharacterRange(30, 40), &zone); | 1772 list->Add(CharacterRange::Range(30, 40), &zone); |
| 1771 list->Add(CharacterRange(10, 20), &zone); | 1773 list->Add(CharacterRange::Range(10, 20), &zone); |
| 1772 list->Add(CharacterRange(25, 25), &zone); | 1774 list->Add(CharacterRange::Range(25, 25), &zone); |
| 1773 list->Add(CharacterRange(100, 100), &zone); | 1775 list->Add(CharacterRange::Range(100, 100), &zone); |
| 1774 list->Add(CharacterRange(1, 1), &zone); | 1776 list->Add(CharacterRange::Range(1, 1), &zone); |
| 1775 set.Canonicalize(); | 1777 set.Canonicalize(); |
| 1776 CHECK_EQ(5, list->length()); | 1778 CHECK_EQ(5, list->length()); |
| 1777 CHECK_EQ(1, list->at(0).from()); | 1779 CHECK_EQ(1, list->at(0).from()); |
| 1778 CHECK_EQ(1, list->at(0).to()); | 1780 CHECK_EQ(1, list->at(0).to()); |
| 1779 CHECK_EQ(10, list->at(1).from()); | 1781 CHECK_EQ(10, list->at(1).from()); |
| 1780 CHECK_EQ(20, list->at(1).to()); | 1782 CHECK_EQ(20, list->at(1).to()); |
| 1781 CHECK_EQ(25, list->at(2).from()); | 1783 CHECK_EQ(25, list->at(2).from()); |
| 1782 CHECK_EQ(25, list->at(2).to()); | 1784 CHECK_EQ(25, list->at(2).to()); |
| 1783 CHECK_EQ(30, list->at(3).from()); | 1785 CHECK_EQ(30, list->at(3).from()); |
| 1784 CHECK_EQ(40, list->at(3).to()); | 1786 CHECK_EQ(40, list->at(3).to()); |
| 1785 CHECK_EQ(100, list->at(4).from()); | 1787 CHECK_EQ(100, list->at(4).from()); |
| 1786 CHECK_EQ(100, list->at(4).to()); | 1788 CHECK_EQ(100, list->at(4).to()); |
| 1787 | 1789 |
| 1788 list->Rewind(0); | 1790 list->Rewind(0); |
| 1789 list->Add(CharacterRange(10, 19), &zone); | 1791 list->Add(CharacterRange::Range(10, 19), &zone); |
| 1790 list->Add(CharacterRange(21, 30), &zone); | 1792 list->Add(CharacterRange::Range(21, 30), &zone); |
| 1791 list->Add(CharacterRange(20, 20), &zone); | 1793 list->Add(CharacterRange::Range(20, 20), &zone); |
| 1792 set.Canonicalize(); | 1794 set.Canonicalize(); |
| 1793 CHECK_EQ(1, list->length()); | 1795 CHECK_EQ(1, list->length()); |
| 1794 CHECK_EQ(10, list->at(0).from()); | 1796 CHECK_EQ(10, list->at(0).from()); |
| 1795 CHECK_EQ(30, list->at(0).to()); | 1797 CHECK_EQ(30, list->at(0).to()); |
| 1796 } | 1798 } |
| 1797 | 1799 |
| 1798 | 1800 |
| 1799 TEST(CharacterRangeMerge) { | 1801 TEST(CharacterRangeMerge) { |
| 1800 Zone zone; | 1802 Zone zone; |
| 1801 ZoneList<CharacterRange> l1(4, &zone); | 1803 ZoneList<CharacterRange> l1(4, &zone); |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1958 // .toString() throws on non-RegExps that aren't RegExp.prototype | 1960 // .toString() throws on non-RegExps that aren't RegExp.prototype |
| 1959 v8::Local<v8::Value> resultToStringError = CompileRun( | 1961 v8::Local<v8::Value> resultToStringError = CompileRun( |
| 1960 "var exception;" | 1962 "var exception;" |
| 1961 "try { RegExp.prototype.toString.call(null) }" | 1963 "try { RegExp.prototype.toString.call(null) }" |
| 1962 "catch (e) { exception = e; }" | 1964 "catch (e) { exception = e; }" |
| 1963 "exception"); | 1965 "exception"); |
| 1964 CHECK_EQ(1, use_counts[v8::Isolate::kRegExpPrototypeStickyGetter]); | 1966 CHECK_EQ(1, use_counts[v8::Isolate::kRegExpPrototypeStickyGetter]); |
| 1965 CHECK_EQ(1, use_counts[v8::Isolate::kRegExpPrototypeToString]); | 1967 CHECK_EQ(1, use_counts[v8::Isolate::kRegExpPrototypeToString]); |
| 1966 CHECK(resultToStringError->IsObject()); | 1968 CHECK(resultToStringError->IsObject()); |
| 1967 } | 1969 } |
| OLD | NEW |