| 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 #include "ia32/regexp-macro-assembler-ia32.h" | 58 #include "ia32/regexp-macro-assembler-ia32.h" |
| 59 #endif | 59 #endif |
| 60 #endif // V8_INTERPRETED_REGEXP | 60 #endif // V8_INTERPRETED_REGEXP |
| 61 | 61 |
| 62 using namespace v8::internal; | 62 using namespace v8::internal; |
| 63 | 63 |
| 64 | 64 |
| 65 static bool CheckParse(const char* input) { | 65 static bool CheckParse(const char* input) { |
| 66 V8::Initialize(NULL); | 66 V8::Initialize(NULL); |
| 67 v8::HandleScope scope; | 67 v8::HandleScope scope; |
| 68 ZoneScope zone_scope(DELETE_ON_EXIT); | 68 ZoneScope zone_scope(Isolate::Current(), DELETE_ON_EXIT); |
| 69 FlatStringReader reader(Isolate::Current(), CStrVector(input)); | 69 FlatStringReader reader(Isolate::Current(), CStrVector(input)); |
| 70 RegExpCompileData result; | 70 RegExpCompileData result; |
| 71 return v8::internal::RegExpParser::ParseRegExp(&reader, false, &result); | 71 return v8::internal::RegExpParser::ParseRegExp(&reader, false, &result); |
| 72 } | 72 } |
| 73 | 73 |
| 74 | 74 |
| 75 static SmartPointer<const char> Parse(const char* input) { | 75 static SmartPointer<const char> Parse(const char* input) { |
| 76 V8::Initialize(NULL); | 76 V8::Initialize(NULL); |
| 77 v8::HandleScope scope; | 77 v8::HandleScope scope; |
| 78 ZoneScope zone_scope(DELETE_ON_EXIT); | 78 ZoneScope zone_scope(Isolate::Current(), DELETE_ON_EXIT); |
| 79 FlatStringReader reader(Isolate::Current(), CStrVector(input)); | 79 FlatStringReader reader(Isolate::Current(), CStrVector(input)); |
| 80 RegExpCompileData result; | 80 RegExpCompileData result; |
| 81 CHECK(v8::internal::RegExpParser::ParseRegExp(&reader, false, &result)); | 81 CHECK(v8::internal::RegExpParser::ParseRegExp(&reader, false, &result)); |
| 82 CHECK(result.tree != NULL); | 82 CHECK(result.tree != NULL); |
| 83 CHECK(result.error.is_null()); | 83 CHECK(result.error.is_null()); |
| 84 SmartPointer<const char> output = result.tree->ToString(); | 84 SmartPointer<const char> output = result.tree->ToString(); |
| 85 return output; | 85 return output; |
| 86 } | 86 } |
| 87 | 87 |
| 88 static bool CheckSimple(const char* input) { | 88 static bool CheckSimple(const char* input) { |
| 89 V8::Initialize(NULL); | 89 V8::Initialize(NULL); |
| 90 v8::HandleScope scope; | 90 v8::HandleScope scope; |
| 91 unibrow::Utf8InputBuffer<> buffer(input, StrLength(input)); | 91 unibrow::Utf8InputBuffer<> buffer(input, StrLength(input)); |
| 92 ZoneScope zone_scope(DELETE_ON_EXIT); | 92 ZoneScope zone_scope(Isolate::Current(), DELETE_ON_EXIT); |
| 93 FlatStringReader reader(Isolate::Current(), CStrVector(input)); | 93 FlatStringReader reader(Isolate::Current(), CStrVector(input)); |
| 94 RegExpCompileData result; | 94 RegExpCompileData result; |
| 95 CHECK(v8::internal::RegExpParser::ParseRegExp(&reader, false, &result)); | 95 CHECK(v8::internal::RegExpParser::ParseRegExp(&reader, false, &result)); |
| 96 CHECK(result.tree != NULL); | 96 CHECK(result.tree != NULL); |
| 97 CHECK(result.error.is_null()); | 97 CHECK(result.error.is_null()); |
| 98 return result.simple; | 98 return result.simple; |
| 99 } | 99 } |
| 100 | 100 |
| 101 struct MinMaxPair { | 101 struct MinMaxPair { |
| 102 int min_match; | 102 int min_match; |
| 103 int max_match; | 103 int max_match; |
| 104 }; | 104 }; |
| 105 | 105 |
| 106 static MinMaxPair CheckMinMaxMatch(const char* input) { | 106 static MinMaxPair CheckMinMaxMatch(const char* input) { |
| 107 V8::Initialize(NULL); | 107 V8::Initialize(NULL); |
| 108 v8::HandleScope scope; | 108 v8::HandleScope scope; |
| 109 unibrow::Utf8InputBuffer<> buffer(input, StrLength(input)); | 109 unibrow::Utf8InputBuffer<> buffer(input, StrLength(input)); |
| 110 ZoneScope zone_scope(DELETE_ON_EXIT); | 110 ZoneScope zone_scope(Isolate::Current(), DELETE_ON_EXIT); |
| 111 FlatStringReader reader(Isolate::Current(), CStrVector(input)); | 111 FlatStringReader reader(Isolate::Current(), CStrVector(input)); |
| 112 RegExpCompileData result; | 112 RegExpCompileData result; |
| 113 CHECK(v8::internal::RegExpParser::ParseRegExp(&reader, false, &result)); | 113 CHECK(v8::internal::RegExpParser::ParseRegExp(&reader, false, &result)); |
| 114 CHECK(result.tree != NULL); | 114 CHECK(result.tree != NULL); |
| 115 CHECK(result.error.is_null()); | 115 CHECK(result.error.is_null()); |
| 116 int min_match = result.tree->min_match(); | 116 int min_match = result.tree->min_match(); |
| 117 int max_match = result.tree->max_match(); | 117 int max_match = result.tree->max_match(); |
| 118 MinMaxPair pair = { min_match, max_match }; | 118 MinMaxPair pair = { min_match, max_match }; |
| 119 return pair; | 119 return pair; |
| 120 } | 120 } |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 CHECK_PARSE_EQ("[A-Z$-][x]", "(! [A-Z $ -] [x])"); | 371 CHECK_PARSE_EQ("[A-Z$-][x]", "(! [A-Z $ -] [x])"); |
| 372 CHECK_PARSE_EQ("a{3,4*}", "(: 'a{3,' (# 0 - g '4') '}')"); | 372 CHECK_PARSE_EQ("a{3,4*}", "(: 'a{3,' (# 0 - g '4') '}')"); |
| 373 CHECK_PARSE_EQ("{", "'{'"); | 373 CHECK_PARSE_EQ("{", "'{'"); |
| 374 CHECK_PARSE_EQ("a|", "(| 'a' %)"); | 374 CHECK_PARSE_EQ("a|", "(| 'a' %)"); |
| 375 } | 375 } |
| 376 | 376 |
| 377 static void ExpectError(const char* input, | 377 static void ExpectError(const char* input, |
| 378 const char* expected) { | 378 const char* expected) { |
| 379 V8::Initialize(NULL); | 379 V8::Initialize(NULL); |
| 380 v8::HandleScope scope; | 380 v8::HandleScope scope; |
| 381 ZoneScope zone_scope(DELETE_ON_EXIT); | 381 ZoneScope zone_scope(Isolate::Current(), DELETE_ON_EXIT); |
| 382 FlatStringReader reader(Isolate::Current(), CStrVector(input)); | 382 FlatStringReader reader(Isolate::Current(), CStrVector(input)); |
| 383 RegExpCompileData result; | 383 RegExpCompileData result; |
| 384 CHECK(!v8::internal::RegExpParser::ParseRegExp(&reader, false, &result)); | 384 CHECK(!v8::internal::RegExpParser::ParseRegExp(&reader, false, &result)); |
| 385 CHECK(result.tree == NULL); | 385 CHECK(result.tree == NULL); |
| 386 CHECK(!result.error.is_null()); | 386 CHECK(!result.error.is_null()); |
| 387 SmartPointer<char> str = result.error->ToCString(ALLOW_NULLS); | 387 SmartPointer<char> str = result.error->ToCString(ALLOW_NULLS); |
| 388 CHECK_EQ(expected, *str); | 388 CHECK_EQ(expected, *str); |
| 389 } | 389 } |
| 390 | 390 |
| 391 | 391 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 return !IsWhiteSpace(c); | 453 return !IsWhiteSpace(c); |
| 454 } | 454 } |
| 455 | 455 |
| 456 | 456 |
| 457 static bool NotWord(uc16 c) { | 457 static bool NotWord(uc16 c) { |
| 458 return !IsRegExpWord(c); | 458 return !IsRegExpWord(c); |
| 459 } | 459 } |
| 460 | 460 |
| 461 | 461 |
| 462 static void TestCharacterClassEscapes(uc16 c, bool (pred)(uc16 c)) { | 462 static void TestCharacterClassEscapes(uc16 c, bool (pred)(uc16 c)) { |
| 463 ZoneScope scope(DELETE_ON_EXIT); | 463 ZoneScope scope(Isolate::Current(), DELETE_ON_EXIT); |
| 464 ZoneList<CharacterRange>* ranges = new ZoneList<CharacterRange>(2); | 464 ZoneList<CharacterRange>* ranges = new ZoneList<CharacterRange>(2); |
| 465 CharacterRange::AddClassEscape(c, ranges); | 465 CharacterRange::AddClassEscape(c, ranges); |
| 466 for (unsigned i = 0; i < (1 << 16); i++) { | 466 for (unsigned i = 0; i < (1 << 16); i++) { |
| 467 bool in_class = false; | 467 bool in_class = false; |
| 468 for (int j = 0; !in_class && j < ranges->length(); j++) { | 468 for (int j = 0; !in_class && j < ranges->length(); j++) { |
| 469 CharacterRange& range = ranges->at(j); | 469 CharacterRange& range = ranges->at(j); |
| 470 in_class = (range.from() <= i && i <= range.to()); | 470 in_class = (range.from() <= i && i <= range.to()); |
| 471 } | 471 } |
| 472 CHECK_EQ(pred(i), in_class); | 472 CHECK_EQ(pred(i), in_class); |
| 473 } | 473 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 499 RegExpEngine::Compile(&compile_data, false, multiline, pattern, is_ascii); | 499 RegExpEngine::Compile(&compile_data, false, multiline, pattern, is_ascii); |
| 500 return compile_data.node; | 500 return compile_data.node; |
| 501 } | 501 } |
| 502 | 502 |
| 503 | 503 |
| 504 static void Execute(const char* input, | 504 static void Execute(const char* input, |
| 505 bool multiline, | 505 bool multiline, |
| 506 bool is_ascii, | 506 bool is_ascii, |
| 507 bool dot_output = false) { | 507 bool dot_output = false) { |
| 508 v8::HandleScope scope; | 508 v8::HandleScope scope; |
| 509 ZoneScope zone_scope(DELETE_ON_EXIT); | 509 ZoneScope zone_scope(Isolate::Current(), DELETE_ON_EXIT); |
| 510 RegExpNode* node = Compile(input, multiline, is_ascii); | 510 RegExpNode* node = Compile(input, multiline, is_ascii); |
| 511 USE(node); | 511 USE(node); |
| 512 #ifdef DEBUG | 512 #ifdef DEBUG |
| 513 if (dot_output) { | 513 if (dot_output) { |
| 514 RegExpEngine::DotPrint(input, node, false); | 514 RegExpEngine::DotPrint(input, node, false); |
| 515 exit(0); | 515 exit(0); |
| 516 } | 516 } |
| 517 #endif // DEBUG | 517 #endif // DEBUG |
| 518 } | 518 } |
| 519 | 519 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 540 | 540 |
| 541 | 541 |
| 542 static unsigned PseudoRandom(int i, int j) { | 542 static unsigned PseudoRandom(int i, int j) { |
| 543 return ~(~((i * 781) ^ (j * 329))); | 543 return ~(~((i * 781) ^ (j * 329))); |
| 544 } | 544 } |
| 545 | 545 |
| 546 | 546 |
| 547 TEST(SplayTreeSimple) { | 547 TEST(SplayTreeSimple) { |
| 548 v8::internal::V8::Initialize(NULL); | 548 v8::internal::V8::Initialize(NULL); |
| 549 static const unsigned kLimit = 1000; | 549 static const unsigned kLimit = 1000; |
| 550 ZoneScope zone_scope(DELETE_ON_EXIT); | 550 ZoneScope zone_scope(Isolate::Current(), DELETE_ON_EXIT); |
| 551 ZoneSplayTree<TestConfig> tree; | 551 ZoneSplayTree<TestConfig> tree; |
| 552 bool seen[kLimit]; | 552 bool seen[kLimit]; |
| 553 for (unsigned i = 0; i < kLimit; i++) seen[i] = false; | 553 for (unsigned i = 0; i < kLimit; i++) seen[i] = false; |
| 554 #define CHECK_MAPS_EQUAL() do { \ | 554 #define CHECK_MAPS_EQUAL() do { \ |
| 555 for (unsigned k = 0; k < kLimit; k++) \ | 555 for (unsigned k = 0; k < kLimit; k++) \ |
| 556 CHECK_EQ(seen[k], tree.Find(k, &loc)); \ | 556 CHECK_EQ(seen[k], tree.Find(k, &loc)); \ |
| 557 } while (false) | 557 } while (false) |
| 558 for (int i = 0; i < 50; i++) { | 558 for (int i = 0; i < 50; i++) { |
| 559 for (int j = 0; j < 50; j++) { | 559 for (int j = 0; j < 50; j++) { |
| 560 unsigned next = PseudoRandom(i, j) % kLimit; | 560 unsigned next = PseudoRandom(i, j) % kLimit; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 608 Vector<uc16> range(ranges[i], 2 * kRangeSize); | 608 Vector<uc16> range(ranges[i], 2 * kRangeSize); |
| 609 for (int j = 0; j < 2 * kRangeSize; j++) { | 609 for (int j = 0; j < 2 * kRangeSize; j++) { |
| 610 range[j] = PseudoRandom(i + 25, j + 87) % kLimit; | 610 range[j] = PseudoRandom(i + 25, j + 87) % kLimit; |
| 611 } | 611 } |
| 612 range.Sort(); | 612 range.Sort(); |
| 613 for (int j = 1; j < 2 * kRangeSize; j++) { | 613 for (int j = 1; j < 2 * kRangeSize; j++) { |
| 614 CHECK(range[j-1] <= range[j]); | 614 CHECK(range[j-1] <= range[j]); |
| 615 } | 615 } |
| 616 } | 616 } |
| 617 // Enter test data into dispatch table. | 617 // Enter test data into dispatch table. |
| 618 ZoneScope zone_scope(DELETE_ON_EXIT); | 618 ZoneScope zone_scope(Isolate::Current(), DELETE_ON_EXIT); |
| 619 DispatchTable table; | 619 DispatchTable table; |
| 620 for (int i = 0; i < kRangeCount; i++) { | 620 for (int i = 0; i < kRangeCount; i++) { |
| 621 uc16* range = ranges[i]; | 621 uc16* range = ranges[i]; |
| 622 for (int j = 0; j < 2 * kRangeSize; j += 2) | 622 for (int j = 0; j < 2 * kRangeSize; j += 2) |
| 623 table.AddRange(CharacterRange(range[j], range[j + 1]), i); | 623 table.AddRange(CharacterRange(range[j], range[j + 1]), i); |
| 624 } | 624 } |
| 625 // Check that the table looks as we would expect | 625 // Check that the table looks as we would expect |
| 626 for (int p = 0; p < kLimit; p++) { | 626 for (int p = 0; p < kLimit; p++) { |
| 627 OutSet* outs = table.Get(p); | 627 OutSet* outs = table.Get(p); |
| 628 for (int j = 0; j < kRangeCount; j++) { | 628 for (int j = 0; j < kRangeCount; j++) { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 675 typedef RegExpMacroAssemblerX64 ArchRegExpMacroAssembler; | 675 typedef RegExpMacroAssemblerX64 ArchRegExpMacroAssembler; |
| 676 #elif V8_TARGET_ARCH_ARM | 676 #elif V8_TARGET_ARCH_ARM |
| 677 typedef RegExpMacroAssemblerARM ArchRegExpMacroAssembler; | 677 typedef RegExpMacroAssemblerARM ArchRegExpMacroAssembler; |
| 678 #elif V8_TARGET_ARCH_MIPS | 678 #elif V8_TARGET_ARCH_MIPS |
| 679 typedef RegExpMacroAssemblerMIPS ArchRegExpMacroAssembler; | 679 typedef RegExpMacroAssemblerMIPS ArchRegExpMacroAssembler; |
| 680 #endif | 680 #endif |
| 681 | 681 |
| 682 class ContextInitializer { | 682 class ContextInitializer { |
| 683 public: | 683 public: |
| 684 ContextInitializer() | 684 ContextInitializer() |
| 685 : env_(), scope_(), zone_(DELETE_ON_EXIT) { | 685 : env_(), scope_(), zone_(Isolate::Current(), DELETE_ON_EXIT) { |
| 686 env_ = v8::Context::New(); | 686 env_ = v8::Context::New(); |
| 687 env_->Enter(); | 687 env_->Enter(); |
| 688 } | 688 } |
| 689 ~ContextInitializer() { | 689 ~ContextInitializer() { |
| 690 env_->Exit(); | 690 env_->Exit(); |
| 691 env_.Dispose(); | 691 env_.Dispose(); |
| 692 } | 692 } |
| 693 private: | 693 private: |
| 694 v8::Persistent<v8::Context> env_; | 694 v8::Persistent<v8::Context> env_; |
| 695 v8::HandleScope scope_; | 695 v8::HandleScope scope_; |
| (...skipping 674 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1370 } | 1370 } |
| 1371 | 1371 |
| 1372 #endif // V8_INTERPRETED_REGEXP | 1372 #endif // V8_INTERPRETED_REGEXP |
| 1373 | 1373 |
| 1374 | 1374 |
| 1375 TEST(AddInverseToTable) { | 1375 TEST(AddInverseToTable) { |
| 1376 v8::internal::V8::Initialize(NULL); | 1376 v8::internal::V8::Initialize(NULL); |
| 1377 static const int kLimit = 1000; | 1377 static const int kLimit = 1000; |
| 1378 static const int kRangeCount = 16; | 1378 static const int kRangeCount = 16; |
| 1379 for (int t = 0; t < 10; t++) { | 1379 for (int t = 0; t < 10; t++) { |
| 1380 ZoneScope zone_scope(DELETE_ON_EXIT); | 1380 ZoneScope zone_scope(Isolate::Current(), DELETE_ON_EXIT); |
| 1381 ZoneList<CharacterRange>* ranges = | 1381 ZoneList<CharacterRange>* ranges = |
| 1382 new ZoneList<CharacterRange>(kRangeCount); | 1382 new ZoneList<CharacterRange>(kRangeCount); |
| 1383 for (int i = 0; i < kRangeCount; i++) { | 1383 for (int i = 0; i < kRangeCount; i++) { |
| 1384 int from = PseudoRandom(t + 87, i + 25) % kLimit; | 1384 int from = PseudoRandom(t + 87, i + 25) % kLimit; |
| 1385 int to = from + (PseudoRandom(i + 87, t + 25) % (kLimit / 20)); | 1385 int to = from + (PseudoRandom(i + 87, t + 25) % (kLimit / 20)); |
| 1386 if (to > kLimit) to = kLimit; | 1386 if (to > kLimit) to = kLimit; |
| 1387 ranges->Add(CharacterRange(from, to)); | 1387 ranges->Add(CharacterRange(from, to)); |
| 1388 } | 1388 } |
| 1389 DispatchTable table; | 1389 DispatchTable table; |
| 1390 DispatchTableConstructor cons(&table, false); | 1390 DispatchTableConstructor cons(&table, false); |
| 1391 cons.set_choice_index(0); | 1391 cons.set_choice_index(0); |
| 1392 cons.AddInverse(ranges); | 1392 cons.AddInverse(ranges); |
| 1393 for (int i = 0; i < kLimit; i++) { | 1393 for (int i = 0; i < kLimit; i++) { |
| 1394 bool is_on = false; | 1394 bool is_on = false; |
| 1395 for (int j = 0; !is_on && j < kRangeCount; j++) | 1395 for (int j = 0; !is_on && j < kRangeCount; j++) |
| 1396 is_on = ranges->at(j).Contains(i); | 1396 is_on = ranges->at(j).Contains(i); |
| 1397 OutSet* set = table.Get(i); | 1397 OutSet* set = table.Get(i); |
| 1398 CHECK_EQ(is_on, set->Get(0) == false); | 1398 CHECK_EQ(is_on, set->Get(0) == false); |
| 1399 } | 1399 } |
| 1400 } | 1400 } |
| 1401 ZoneScope zone_scope(DELETE_ON_EXIT); | 1401 ZoneScope zone_scope(Isolate::Current(), DELETE_ON_EXIT); |
| 1402 ZoneList<CharacterRange>* ranges = | 1402 ZoneList<CharacterRange>* ranges = |
| 1403 new ZoneList<CharacterRange>(1); | 1403 new ZoneList<CharacterRange>(1); |
| 1404 ranges->Add(CharacterRange(0xFFF0, 0xFFFE)); | 1404 ranges->Add(CharacterRange(0xFFF0, 0xFFFE)); |
| 1405 DispatchTable table; | 1405 DispatchTable table; |
| 1406 DispatchTableConstructor cons(&table, false); | 1406 DispatchTableConstructor cons(&table, false); |
| 1407 cons.set_choice_index(0); | 1407 cons.set_choice_index(0); |
| 1408 cons.AddInverse(ranges); | 1408 cons.AddInverse(ranges); |
| 1409 CHECK(!table.Get(0xFFFE)->Get(0)); | 1409 CHECK(!table.Get(0xFFFE)->Get(0)); |
| 1410 CHECK(table.Get(0xFFFF)->Get(0)); | 1410 CHECK(table.Get(0xFFFF)->Get(0)); |
| 1411 } | 1411 } |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1504 CHECK_EQ(length, length2); | 1504 CHECK_EQ(length, length2); |
| 1505 for (int k = 0; k < length; k++) | 1505 for (int k = 0; k < length; k++) |
| 1506 CHECK_EQ(static_cast<int>(chars[k]), static_cast<int>(chars2[k])); | 1506 CHECK_EQ(static_cast<int>(chars[k]), static_cast<int>(chars2[k])); |
| 1507 } | 1507 } |
| 1508 } | 1508 } |
| 1509 } | 1509 } |
| 1510 | 1510 |
| 1511 | 1511 |
| 1512 static void TestRangeCaseIndependence(CharacterRange input, | 1512 static void TestRangeCaseIndependence(CharacterRange input, |
| 1513 Vector<CharacterRange> expected) { | 1513 Vector<CharacterRange> expected) { |
| 1514 ZoneScope zone_scope(DELETE_ON_EXIT); | 1514 ZoneScope zone_scope(Isolate::Current(), DELETE_ON_EXIT); |
| 1515 int count = expected.length(); | 1515 int count = expected.length(); |
| 1516 ZoneList<CharacterRange>* list = new ZoneList<CharacterRange>(count); | 1516 ZoneList<CharacterRange>* list = new ZoneList<CharacterRange>(count); |
| 1517 input.AddCaseEquivalents(list, false); | 1517 input.AddCaseEquivalents(list, false); |
| 1518 CHECK_EQ(count, list->length()); | 1518 CHECK_EQ(count, list->length()); |
| 1519 for (int i = 0; i < list->length(); i++) { | 1519 for (int i = 0; i < list->length(); i++) { |
| 1520 CHECK_EQ(expected[i].from(), list->at(i).from()); | 1520 CHECK_EQ(expected[i].from(), list->at(i).from()); |
| 1521 CHECK_EQ(expected[i].to(), list->at(i).to()); | 1521 CHECK_EQ(expected[i].to(), list->at(i).to()); |
| 1522 } | 1522 } |
| 1523 } | 1523 } |
| 1524 | 1524 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1568 CharacterRange range = ranges->at(i); | 1568 CharacterRange range = ranges->at(i); |
| 1569 if (range.from() <= c && c <= range.to()) | 1569 if (range.from() <= c && c <= range.to()) |
| 1570 return true; | 1570 return true; |
| 1571 } | 1571 } |
| 1572 return false; | 1572 return false; |
| 1573 } | 1573 } |
| 1574 | 1574 |
| 1575 | 1575 |
| 1576 TEST(CharClassDifference) { | 1576 TEST(CharClassDifference) { |
| 1577 v8::internal::V8::Initialize(NULL); | 1577 v8::internal::V8::Initialize(NULL); |
| 1578 ZoneScope zone_scope(DELETE_ON_EXIT); | 1578 ZoneScope zone_scope(Isolate::Current(), DELETE_ON_EXIT); |
| 1579 ZoneList<CharacterRange>* base = new ZoneList<CharacterRange>(1); | 1579 ZoneList<CharacterRange>* base = new ZoneList<CharacterRange>(1); |
| 1580 base->Add(CharacterRange::Everything()); | 1580 base->Add(CharacterRange::Everything()); |
| 1581 Vector<const uc16> overlay = CharacterRange::GetWordBounds(); | 1581 Vector<const uc16> overlay = CharacterRange::GetWordBounds(); |
| 1582 ZoneList<CharacterRange>* included = NULL; | 1582 ZoneList<CharacterRange>* included = NULL; |
| 1583 ZoneList<CharacterRange>* excluded = NULL; | 1583 ZoneList<CharacterRange>* excluded = NULL; |
| 1584 CharacterRange::Split(base, overlay, &included, &excluded); | 1584 CharacterRange::Split(base, overlay, &included, &excluded); |
| 1585 for (int i = 0; i < (1 << 16); i++) { | 1585 for (int i = 0; i < (1 << 16); i++) { |
| 1586 bool in_base = InClass(i, base); | 1586 bool in_base = InClass(i, base); |
| 1587 if (in_base) { | 1587 if (in_base) { |
| 1588 bool in_overlay = false; | 1588 bool in_overlay = false; |
| 1589 for (int j = 0; !in_overlay && j < overlay.length(); j += 2) { | 1589 for (int j = 0; !in_overlay && j < overlay.length(); j += 2) { |
| 1590 if (overlay[j] <= i && i <= overlay[j+1]) | 1590 if (overlay[j] <= i && i <= overlay[j+1]) |
| 1591 in_overlay = true; | 1591 in_overlay = true; |
| 1592 } | 1592 } |
| 1593 CHECK_EQ(in_overlay, InClass(i, included)); | 1593 CHECK_EQ(in_overlay, InClass(i, included)); |
| 1594 CHECK_EQ(!in_overlay, InClass(i, excluded)); | 1594 CHECK_EQ(!in_overlay, InClass(i, excluded)); |
| 1595 } else { | 1595 } else { |
| 1596 CHECK(!InClass(i, included)); | 1596 CHECK(!InClass(i, included)); |
| 1597 CHECK(!InClass(i, excluded)); | 1597 CHECK(!InClass(i, excluded)); |
| 1598 } | 1598 } |
| 1599 } | 1599 } |
| 1600 } | 1600 } |
| 1601 | 1601 |
| 1602 | 1602 |
| 1603 TEST(CanonicalizeCharacterSets) { | 1603 TEST(CanonicalizeCharacterSets) { |
| 1604 v8::internal::V8::Initialize(NULL); | 1604 v8::internal::V8::Initialize(NULL); |
| 1605 ZoneScope scope(DELETE_ON_EXIT); | 1605 ZoneScope scope(Isolate::Current(), DELETE_ON_EXIT); |
| 1606 ZoneList<CharacterRange>* list = new ZoneList<CharacterRange>(4); | 1606 ZoneList<CharacterRange>* list = new ZoneList<CharacterRange>(4); |
| 1607 CharacterSet set(list); | 1607 CharacterSet set(list); |
| 1608 | 1608 |
| 1609 list->Add(CharacterRange(10, 20)); | 1609 list->Add(CharacterRange(10, 20)); |
| 1610 list->Add(CharacterRange(30, 40)); | 1610 list->Add(CharacterRange(30, 40)); |
| 1611 list->Add(CharacterRange(50, 60)); | 1611 list->Add(CharacterRange(50, 60)); |
| 1612 set.Canonicalize(); | 1612 set.Canonicalize(); |
| 1613 ASSERT_EQ(3, list->length()); | 1613 ASSERT_EQ(3, list->length()); |
| 1614 ASSERT_EQ(10, list->at(0).from()); | 1614 ASSERT_EQ(10, list->at(0).from()); |
| 1615 ASSERT_EQ(20, list->at(0).to()); | 1615 ASSERT_EQ(20, list->at(0).to()); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1666 CharacterRange range = set->at(i); | 1666 CharacterRange range = set->at(i); |
| 1667 if (range.from() <= value && value <= range.to()) { | 1667 if (range.from() <= value && value <= range.to()) { |
| 1668 return true; | 1668 return true; |
| 1669 } | 1669 } |
| 1670 } | 1670 } |
| 1671 return false; | 1671 return false; |
| 1672 } | 1672 } |
| 1673 | 1673 |
| 1674 TEST(CharacterRangeMerge) { | 1674 TEST(CharacterRangeMerge) { |
| 1675 v8::internal::V8::Initialize(NULL); | 1675 v8::internal::V8::Initialize(NULL); |
| 1676 ZoneScope zone_scope(DELETE_ON_EXIT); | 1676 ZoneScope zone_scope(Isolate::Current(), DELETE_ON_EXIT); |
| 1677 ZoneList<CharacterRange> l1(4); | 1677 ZoneList<CharacterRange> l1(4); |
| 1678 ZoneList<CharacterRange> l2(4); | 1678 ZoneList<CharacterRange> l2(4); |
| 1679 // Create all combinations of intersections of ranges, both singletons and | 1679 // Create all combinations of intersections of ranges, both singletons and |
| 1680 // longer. | 1680 // longer. |
| 1681 | 1681 |
| 1682 int offset = 0; | 1682 int offset = 0; |
| 1683 | 1683 |
| 1684 // The five kinds of singleton intersections: | 1684 // The five kinds of singleton intersections: |
| 1685 // X | 1685 // X |
| 1686 // Y - outside before | 1686 // Y - outside before |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1817 bool in_second = CharacterInSet(&l2, i); | 1817 bool in_second = CharacterInSet(&l2, i); |
| 1818 CHECK((in_first || in_second) == CharacterInSet(&all, i)); | 1818 CHECK((in_first || in_second) == CharacterInSet(&all, i)); |
| 1819 } | 1819 } |
| 1820 } | 1820 } |
| 1821 | 1821 |
| 1822 | 1822 |
| 1823 TEST(Graph) { | 1823 TEST(Graph) { |
| 1824 V8::Initialize(NULL); | 1824 V8::Initialize(NULL); |
| 1825 Execute("\\b\\w+\\b", false, true, true); | 1825 Execute("\\b\\w+\\b", false, true, true); |
| 1826 } | 1826 } |
| OLD | NEW |