OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 | 2 |
3 // Check that we can traverse very deep stacks of ConsStrings using | 3 // Check that we can traverse very deep stacks of ConsStrings using |
4 // StringInputBuffer. Check that Get(int) works on very deep stacks | 4 // StringCharacterStram. Check that Get(int) works on very deep stacks |
5 // of ConsStrings. These operations may not be very fast, but they | 5 // of ConsStrings. These operations may not be very fast, but they |
6 // should be possible without getting errors due to too deep recursion. | 6 // should be possible without getting errors due to too deep recursion. |
7 | 7 |
8 #include <stdlib.h> | 8 #include <stdlib.h> |
9 | 9 |
10 #include "v8.h" | 10 #include "v8.h" |
11 | 11 |
12 #include "api.h" | 12 #include "api.h" |
13 #include "factory.h" | 13 #include "factory.h" |
14 #include "objects.h" | 14 #include "objects.h" |
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
507 | 507 |
508 static Handle<String> ConstructBalanced( | 508 static Handle<String> ConstructBalanced( |
509 ConsStringGenerationData* data, int depth = DEEP_DEPTH) { | 509 ConsStringGenerationData* data, int depth = DEEP_DEPTH) { |
510 Handle<String> string = ConstructBalancedHelper(data, 0, depth); | 510 Handle<String> string = ConstructBalancedHelper(data, 0, depth); |
511 data->stats_.leaves_ = | 511 data->stats_.leaves_ = |
512 data->stats_.left_traversals_ + data->stats_.right_traversals_ + 2; | 512 data->stats_.left_traversals_ + data->stats_.right_traversals_ + 2; |
513 return string; | 513 return string; |
514 } | 514 } |
515 | 515 |
516 | 516 |
517 static StringInputBuffer buffer; | |
518 static ConsStringIteratorOp cons_string_iterator_op_1; | 517 static ConsStringIteratorOp cons_string_iterator_op_1; |
519 static ConsStringIteratorOp cons_string_iterator_op_2; | 518 static ConsStringIteratorOp cons_string_iterator_op_2; |
520 | 519 |
521 static void Traverse(Handle<String> s1, Handle<String> s2) { | 520 static void Traverse(Handle<String> s1, Handle<String> s2) { |
522 int i = 0; | 521 int i = 0; |
523 buffer.Reset(*s1); | |
524 StringCharacterStream character_stream_1(*s1, &cons_string_iterator_op_1); | 522 StringCharacterStream character_stream_1(*s1, &cons_string_iterator_op_1); |
525 StringCharacterStream character_stream_2(*s2, &cons_string_iterator_op_2); | 523 StringCharacterStream character_stream_2(*s2, &cons_string_iterator_op_2); |
526 StringInputBuffer buffer2(*s2); | 524 while (character_stream_1.HasMore()) { |
527 while (buffer.has_more()) { | |
528 CHECK(buffer2.has_more()); | |
529 CHECK(character_stream_1.HasMore()); | |
530 CHECK(character_stream_2.HasMore()); | 525 CHECK(character_stream_2.HasMore()); |
531 uint16_t c = buffer.GetNext(); | 526 uint16_t c = character_stream_1.GetNext(); |
532 CHECK_EQ(c, buffer2.GetNext()); | |
533 CHECK_EQ(c, character_stream_1.GetNext()); | |
534 CHECK_EQ(c, character_stream_2.GetNext()); | 527 CHECK_EQ(c, character_stream_2.GetNext()); |
535 i++; | 528 i++; |
536 } | 529 } |
537 CHECK(!character_stream_1.HasMore()); | 530 CHECK(!character_stream_1.HasMore()); |
538 CHECK(!character_stream_2.HasMore()); | 531 CHECK(!character_stream_2.HasMore()); |
539 CHECK_EQ(s1->length(), i); | 532 CHECK_EQ(s1->length(), i); |
540 CHECK_EQ(s2->length(), i); | 533 CHECK_EQ(s2->length(), i); |
541 } | 534 } |
542 | 535 |
543 | 536 |
544 static void TraverseFirst(Handle<String> s1, Handle<String> s2, int chars) { | 537 static void TraverseFirst(Handle<String> s1, Handle<String> s2, int chars) { |
545 int i = 0; | 538 int i = 0; |
546 buffer.Reset(*s1); | |
547 StringInputBuffer buffer2(*s2); | |
548 StringCharacterStream character_stream_1(*s1, &cons_string_iterator_op_1); | 539 StringCharacterStream character_stream_1(*s1, &cons_string_iterator_op_1); |
549 StringCharacterStream character_stream_2(*s2, &cons_string_iterator_op_2); | 540 StringCharacterStream character_stream_2(*s2, &cons_string_iterator_op_2); |
550 while (buffer.has_more() && i < chars) { | 541 while (character_stream_1.HasMore() && i < chars) { |
551 CHECK(buffer2.has_more()); | |
552 CHECK(character_stream_1.HasMore()); | |
553 CHECK(character_stream_2.HasMore()); | 542 CHECK(character_stream_2.HasMore()); |
554 uint16_t c = buffer.GetNext(); | 543 uint16_t c = character_stream_1.GetNext(); |
555 CHECK_EQ(c, buffer2.GetNext()); | |
556 CHECK_EQ(c, character_stream_1.GetNext()); | |
557 CHECK_EQ(c, character_stream_2.GetNext()); | 544 CHECK_EQ(c, character_stream_2.GetNext()); |
558 i++; | 545 i++; |
559 } | 546 } |
560 s1->Get(s1->length() - 1); | 547 s1->Get(s1->length() - 1); |
561 s2->Get(s2->length() - 1); | 548 s2->Get(s2->length() - 1); |
562 } | 549 } |
563 | 550 |
564 | 551 |
565 TEST(Traverse) { | 552 TEST(Traverse) { |
566 printf("TestTraverse\n"); | 553 printf("TestTraverse\n"); |
(...skipping 714 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1281 | 1268 |
1282 v8::Local<v8::String> expected = v8_str("ascii\x80only\x80string\x80"); | 1269 v8::Local<v8::String> expected = v8_str("ascii\x80only\x80string\x80"); |
1283 CHECK(expected->Equals(result)); | 1270 CHECK(expected->Equals(result)); |
1284 } | 1271 } |
1285 | 1272 |
1286 | 1273 |
1287 TEST(IsAscii) { | 1274 TEST(IsAscii) { |
1288 CHECK(String::IsAscii(static_cast<char*>(NULL), 0)); | 1275 CHECK(String::IsAscii(static_cast<char*>(NULL), 0)); |
1289 CHECK(String::IsAscii(static_cast<uc16*>(NULL), 0)); | 1276 CHECK(String::IsAscii(static_cast<uc16*>(NULL), 0)); |
1290 } | 1277 } |
OLD | NEW |