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

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

Issue 223593004: Revert "Return MaybeHandle from NewConsString." (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « test/cctest/test-heap-profiler.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 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 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 // Need to balance generation fairly. 440 // Need to balance generation fairly.
441 if (!terminate_left && data->rng_.next(0.5)) { 441 if (!terminate_left && data->rng_.next(0.5)) {
442 left = ConstructRandomString(data, max_recursion - 1); 442 left = ConstructRandomString(data, max_recursion - 1);
443 } 443 }
444 right = ConstructRandomString(data, max_recursion - 1); 444 right = ConstructRandomString(data, max_recursion - 1);
445 } 445 }
446 if (!terminate_left && left.is_null()) { 446 if (!terminate_left && left.is_null()) {
447 left = ConstructRandomString(data, max_recursion - 1); 447 left = ConstructRandomString(data, max_recursion - 1);
448 } 448 }
449 // Build the cons string. 449 // Build the cons string.
450 Handle<String> root = factory->NewConsString(left, right).ToHandleChecked(); 450 Handle<String> root = factory->NewConsString(left, right);
451 CHECK(root->IsConsString() && !root->IsFlat()); 451 CHECK(root->IsConsString() && !root->IsFlat());
452 // Special work needed for flat string. 452 // Special work needed for flat string.
453 if (flat) { 453 if (flat) {
454 data->stats_.empty_leaves_++; 454 data->stats_.empty_leaves_++;
455 FlattenString(root); 455 FlattenString(root);
456 CHECK(root->IsConsString() && root->IsFlat()); 456 CHECK(root->IsConsString() && root->IsFlat());
457 } 457 }
458 return root; 458 return root;
459 } 459 }
460 460
461 461
462 static Handle<String> ConstructLeft( 462 static Handle<String> ConstructLeft(
463 ConsStringGenerationData* data, 463 ConsStringGenerationData* data,
464 int depth) { 464 int depth) {
465 Factory* factory = CcTest::i_isolate()->factory(); 465 Factory* factory = CcTest::i_isolate()->factory();
466 Handle<String> answer = factory->NewStringFromAscii(CStrVector("")); 466 Handle<String> answer = factory->NewStringFromAscii(CStrVector(""));
467 data->stats_.leaves_++; 467 data->stats_.leaves_++;
468 for (int i = 0; i < depth; i++) { 468 for (int i = 0; i < depth; i++) {
469 Handle<String> block = data->block(i); 469 Handle<String> block = data->block(i);
470 Handle<String> next = 470 Handle<String> next = factory->NewConsString(answer, block);
471 factory->NewConsString(answer, block).ToHandleChecked();
472 if (next->IsConsString()) data->stats_.leaves_++; 471 if (next->IsConsString()) data->stats_.leaves_++;
473 data->stats_.chars_ += block->length(); 472 data->stats_.chars_ += block->length();
474 answer = next; 473 answer = next;
475 } 474 }
476 data->stats_.left_traversals_ = data->stats_.leaves_ - 2; 475 data->stats_.left_traversals_ = data->stats_.leaves_ - 2;
477 return answer; 476 return answer;
478 } 477 }
479 478
480 479
481 static Handle<String> ConstructRight( 480 static Handle<String> ConstructRight(
482 ConsStringGenerationData* data, 481 ConsStringGenerationData* data,
483 int depth) { 482 int depth) {
484 Factory* factory = CcTest::i_isolate()->factory(); 483 Factory* factory = CcTest::i_isolate()->factory();
485 Handle<String> answer = factory->NewStringFromAscii(CStrVector("")); 484 Handle<String> answer = factory->NewStringFromAscii(CStrVector(""));
486 data->stats_.leaves_++; 485 data->stats_.leaves_++;
487 for (int i = depth - 1; i >= 0; i--) { 486 for (int i = depth - 1; i >= 0; i--) {
488 Handle<String> block = data->block(i); 487 Handle<String> block = data->block(i);
489 Handle<String> next = 488 Handle<String> next = factory->NewConsString(block, answer);
490 factory->NewConsString(block, answer).ToHandleChecked();
491 if (next->IsConsString()) data->stats_.leaves_++; 489 if (next->IsConsString()) data->stats_.leaves_++;
492 data->stats_.chars_ += block->length(); 490 data->stats_.chars_ += block->length();
493 answer = next; 491 answer = next;
494 } 492 }
495 data->stats_.right_traversals_ = data->stats_.leaves_ - 2; 493 data->stats_.right_traversals_ = data->stats_.leaves_ - 2;
496 return answer; 494 return answer;
497 } 495 }
498 496
499 497
500 static Handle<String> ConstructBalancedHelper( 498 static Handle<String> ConstructBalancedHelper(
501 ConsStringGenerationData* data, 499 ConsStringGenerationData* data,
502 int from, 500 int from,
503 int to) { 501 int to) {
504 Factory* factory = CcTest::i_isolate()->factory(); 502 Factory* factory = CcTest::i_isolate()->factory();
505 CHECK(to > from); 503 CHECK(to > from);
506 if (to - from == 1) { 504 if (to - from == 1) {
507 data->stats_.chars_ += data->block(from)->length(); 505 data->stats_.chars_ += data->block(from)->length();
508 return data->block(from); 506 return data->block(from);
509 } 507 }
510 if (to - from == 2) { 508 if (to - from == 2) {
511 data->stats_.chars_ += data->block(from)->length(); 509 data->stats_.chars_ += data->block(from)->length();
512 data->stats_.chars_ += data->block(from+1)->length(); 510 data->stats_.chars_ += data->block(from+1)->length();
513 return factory->NewConsString(data->block(from), data->block(from+1)) 511 return factory->NewConsString(data->block(from), data->block(from+1));
514 .ToHandleChecked();
515 } 512 }
516 Handle<String> part1 = 513 Handle<String> part1 =
517 ConstructBalancedHelper(data, from, from + ((to - from) / 2)); 514 ConstructBalancedHelper(data, from, from + ((to - from) / 2));
518 Handle<String> part2 = 515 Handle<String> part2 =
519 ConstructBalancedHelper(data, from + ((to - from) / 2), to); 516 ConstructBalancedHelper(data, from + ((to - from) / 2), to);
520 if (part1->IsConsString()) data->stats_.left_traversals_++; 517 if (part1->IsConsString()) data->stats_.left_traversals_++;
521 if (part2->IsConsString()) data->stats_.right_traversals_++; 518 if (part2->IsConsString()) data->stats_.right_traversals_++;
522 return factory->NewConsString(part1, part2).ToHandleChecked(); 519 return factory->NewConsString(part1, part2);
523 } 520 }
524 521
525 522
526 static Handle<String> ConstructBalanced( 523 static Handle<String> ConstructBalanced(
527 ConsStringGenerationData* data, int depth = DEEP_DEPTH) { 524 ConsStringGenerationData* data, int depth = DEEP_DEPTH) {
528 Handle<String> string = ConstructBalancedHelper(data, 0, depth); 525 Handle<String> string = ConstructBalancedHelper(data, 0, depth);
529 data->stats_.leaves_ = 526 data->stats_.leaves_ =
530 data->stats_.left_traversals_ + data->stats_.right_traversals_ + 2; 527 data->stats_.left_traversals_ + data->stats_.right_traversals_ + 2;
531 return string; 528 return string;
532 } 529 }
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
706 return ConstructRight(data, 71); 703 return ConstructRight(data, 71);
707 case 3: 704 case 3:
708 return ConstructLeft(data, 10); 705 return ConstructLeft(data, 10);
709 case 4: 706 case 4:
710 return ConstructRight(data, 10); 707 return ConstructRight(data, 10);
711 case 5: 708 case 5:
712 // 2 element balanced tree. 709 // 2 element balanced tree.
713 data->stats_.chars_ += data->block(0)->length(); 710 data->stats_.chars_ += data->block(0)->length();
714 data->stats_.chars_ += data->block(1)->length(); 711 data->stats_.chars_ += data->block(1)->length();
715 data->stats_.leaves_ += 2; 712 data->stats_.leaves_ += 2;
716 return factory->NewConsString(data->block(0), data->block(1)) 713 return factory->NewConsString(data->block(0), data->block(1));
717 .ToHandleChecked();
718 case 6: 714 case 6:
719 // Simple flattened tree. 715 // Simple flattened tree.
720 data->stats_.chars_ += data->block(0)->length(); 716 data->stats_.chars_ += data->block(0)->length();
721 data->stats_.chars_ += data->block(1)->length(); 717 data->stats_.chars_ += data->block(1)->length();
722 data->stats_.leaves_ += 2; 718 data->stats_.leaves_ += 2;
723 data->stats_.empty_leaves_ += 1; 719 data->stats_.empty_leaves_ += 1;
724 { 720 {
725 Handle<String> string = 721 Handle<String> string =
726 factory->NewConsString(data->block(0), data->block(1)) 722 factory->NewConsString(data->block(0), data->block(1));
727 .ToHandleChecked();
728 FlattenString(string); 723 FlattenString(string);
729 return string; 724 return string;
730 } 725 }
731 case 7: 726 case 7:
732 // Left node flattened. 727 // Left node flattened.
733 data->stats_.chars_ += data->block(0)->length(); 728 data->stats_.chars_ += data->block(0)->length();
734 data->stats_.chars_ += data->block(1)->length(); 729 data->stats_.chars_ += data->block(1)->length();
735 data->stats_.chars_ += data->block(2)->length(); 730 data->stats_.chars_ += data->block(2)->length();
736 data->stats_.leaves_ += 3; 731 data->stats_.leaves_ += 3;
737 data->stats_.empty_leaves_ += 1; 732 data->stats_.empty_leaves_ += 1;
738 data->stats_.left_traversals_ += 1; 733 data->stats_.left_traversals_ += 1;
739 { 734 {
740 Handle<String> left = 735 Handle<String> left =
741 factory->NewConsString(data->block(0), data->block(1)) 736 factory->NewConsString(data->block(0), data->block(1));
742 .ToHandleChecked();
743 FlattenString(left); 737 FlattenString(left);
744 return factory->NewConsString(left, data->block(2)).ToHandleChecked(); 738 return factory->NewConsString(left, data->block(2));
745 } 739 }
746 case 8: 740 case 8:
747 // Left node and right node flattened. 741 // Left node and right node flattened.
748 data->stats_.chars_ += data->block(0)->length(); 742 data->stats_.chars_ += data->block(0)->length();
749 data->stats_.chars_ += data->block(1)->length(); 743 data->stats_.chars_ += data->block(1)->length();
750 data->stats_.chars_ += data->block(2)->length(); 744 data->stats_.chars_ += data->block(2)->length();
751 data->stats_.chars_ += data->block(3)->length(); 745 data->stats_.chars_ += data->block(3)->length();
752 data->stats_.leaves_ += 4; 746 data->stats_.leaves_ += 4;
753 data->stats_.empty_leaves_ += 2; 747 data->stats_.empty_leaves_ += 2;
754 data->stats_.left_traversals_ += 1; 748 data->stats_.left_traversals_ += 1;
755 data->stats_.right_traversals_ += 1; 749 data->stats_.right_traversals_ += 1;
756 { 750 {
757 Handle<String> left = 751 Handle<String> left =
758 factory->NewConsString(data->block(0), data->block(1)) 752 factory->NewConsString(data->block(0), data->block(1));
759 .ToHandleChecked();
760 FlattenString(left); 753 FlattenString(left);
761 Handle<String> right = 754 Handle<String> right =
762 factory->NewConsString(data->block(2), data->block(2)) 755 factory->NewConsString(data->block(2), data->block(2));
763 .ToHandleChecked();
764 FlattenString(right); 756 FlattenString(right);
765 return factory->NewConsString(left, right).ToHandleChecked(); 757 return factory->NewConsString(left, right);
766 } 758 }
767 } 759 }
768 UNREACHABLE(); 760 UNREACHABLE();
769 return Handle<String>(); 761 return Handle<String>();
770 } 762 }
771 763
772 764
773 TEST(StringCharacterStreamEdgeCases) { 765 TEST(StringCharacterStreamEdgeCases) {
774 printf("TestStringCharacterStreamEdgeCases\n"); 766 printf("TestStringCharacterStreamEdgeCases\n");
775 TestStringCharacterStream( 767 TestStringCharacterStream(
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
867 v8::HandleScope scope(CcTest::isolate()); 859 v8::HandleScope scope(CcTest::isolate());
868 860
869 char* foo = NewArray<char>(DEEP_ASCII_DEPTH); 861 char* foo = NewArray<char>(DEEP_ASCII_DEPTH);
870 for (int i = 0; i < DEEP_ASCII_DEPTH; i++) { 862 for (int i = 0; i < DEEP_ASCII_DEPTH; i++) {
871 foo[i] = "foo "[i % 4]; 863 foo[i] = "foo "[i % 4];
872 } 864 }
873 Handle<String> string = 865 Handle<String> string =
874 factory->NewStringFromAscii(Vector<const char>(foo, DEEP_ASCII_DEPTH)); 866 factory->NewStringFromAscii(Vector<const char>(foo, DEEP_ASCII_DEPTH));
875 Handle<String> foo_string = factory->NewStringFromAscii(CStrVector("foo")); 867 Handle<String> foo_string = factory->NewStringFromAscii(CStrVector("foo"));
876 for (int i = 0; i < DEEP_ASCII_DEPTH; i += 10) { 868 for (int i = 0; i < DEEP_ASCII_DEPTH; i += 10) {
877 string = factory->NewConsString(string, foo_string).ToHandleChecked(); 869 string = factory->NewConsString(string, foo_string);
878 } 870 }
879 Handle<String> flat_string = 871 Handle<String> flat_string = factory->NewConsString(string, foo_string);
880 factory->NewConsString(string, foo_string).ToHandleChecked();
881 FlattenString(flat_string); 872 FlattenString(flat_string);
882 873
883 for (int i = 0; i < 500; i++) { 874 for (int i = 0; i < 500; i++) {
884 TraverseFirst(flat_string, string, DEEP_ASCII_DEPTH); 875 TraverseFirst(flat_string, string, DEEP_ASCII_DEPTH);
885 } 876 }
886 DeleteArray<char>(foo); 877 DeleteArray<char>(foo);
887 } 878 }
888 879
889 880
890 TEST(Utf8Conversion) { 881 TEST(Utf8Conversion) {
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
1094 } 1085 }
1095 1086
1096 1087
1097 TEST(SliceFromCons) { 1088 TEST(SliceFromCons) {
1098 FLAG_string_slices = true; 1089 FLAG_string_slices = true;
1099 CcTest::InitializeVM(); 1090 CcTest::InitializeVM();
1100 Factory* factory = CcTest::i_isolate()->factory(); 1091 Factory* factory = CcTest::i_isolate()->factory();
1101 v8::HandleScope scope(CcTest::isolate()); 1092 v8::HandleScope scope(CcTest::isolate());
1102 Handle<String> string = 1093 Handle<String> string =
1103 factory->NewStringFromAscii(CStrVector("parentparentparent")); 1094 factory->NewStringFromAscii(CStrVector("parentparentparent"));
1104 Handle<String> parent = 1095 Handle<String> parent = factory->NewConsString(string, string);
1105 factory->NewConsString(string, string).ToHandleChecked();
1106 CHECK(parent->IsConsString()); 1096 CHECK(parent->IsConsString());
1107 CHECK(!parent->IsFlat()); 1097 CHECK(!parent->IsFlat());
1108 Handle<String> slice = factory->NewSubString(parent, 1, 25); 1098 Handle<String> slice = factory->NewSubString(parent, 1, 25);
1109 // After slicing, the original string becomes a flat cons. 1099 // After slicing, the original string becomes a flat cons.
1110 CHECK(parent->IsFlat()); 1100 CHECK(parent->IsFlat());
1111 CHECK(slice->IsSlicedString()); 1101 CHECK(slice->IsSlicedString());
1112 CHECK_EQ(SlicedString::cast(*slice)->parent(), 1102 CHECK_EQ(SlicedString::cast(*slice)->parent(),
1113 // Parent could have been short-circuited. 1103 // Parent could have been short-circuited.
1114 parent->IsConsString() ? ConsString::cast(*parent)->first() 1104 parent->IsConsString() ? ConsString::cast(*parent)->first()
1115 : *parent); 1105 : *parent);
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
1414 dummy.Dispose(); \ 1404 dummy.Dispose(); \
1415 } 1405 }
1416 1406
1417 INVALID_STRING_TEST(NewStringFromAscii, char) 1407 INVALID_STRING_TEST(NewStringFromAscii, char)
1418 INVALID_STRING_TEST(NewStringFromUtf8, char) 1408 INVALID_STRING_TEST(NewStringFromUtf8, char)
1419 INVALID_STRING_TEST(NewStringFromOneByte, uint8_t) 1409 INVALID_STRING_TEST(NewStringFromOneByte, uint8_t)
1420 INVALID_STRING_TEST(InternalizeOneByteString, uint8_t) 1410 INVALID_STRING_TEST(InternalizeOneByteString, uint8_t)
1421 INVALID_STRING_TEST(InternalizeUtf8String, char) 1411 INVALID_STRING_TEST(InternalizeUtf8String, char)
1422 1412
1423 #undef INVALID_STRING_TEST 1413 #undef INVALID_STRING_TEST
OLDNEW
« no previous file with comments | « test/cctest/test-heap-profiler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698