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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 // Don't slice 0 length strings. | 157 // Don't slice 0 length strings. |
158 if (len == 0) slice_depth = 0; | 158 if (len == 0) slice_depth = 0; |
159 int slice_length = slice_depth*(slice_head_chars + slice_tail_chars); | 159 int slice_length = slice_depth*(slice_head_chars + slice_tail_chars); |
160 len += slice_length; | 160 len += slice_length; |
161 switch (rng->next(4)) { | 161 switch (rng->next(4)) { |
162 case 0: { | 162 case 0: { |
163 uc16 buf[2000]; | 163 uc16 buf[2000]; |
164 for (int j = 0; j < len; j++) { | 164 for (int j = 0; j < len; j++) { |
165 buf[j] = rng->next(0x10000); | 165 buf[j] = rng->next(0x10000); |
166 } | 166 } |
167 building_blocks[i] = | 167 building_blocks[i] = factory->NewStringFromTwoByte( |
168 factory->NewStringFromTwoByte(Vector<const uc16>(buf, len)); | 168 Vector<const uc16>(buf, len)).ToHandleChecked(); |
169 for (int j = 0; j < len; j++) { | 169 for (int j = 0; j < len; j++) { |
170 CHECK_EQ(buf[j], building_blocks[i]->Get(j)); | 170 CHECK_EQ(buf[j], building_blocks[i]->Get(j)); |
171 } | 171 } |
172 break; | 172 break; |
173 } | 173 } |
174 case 1: { | 174 case 1: { |
175 char buf[2000]; | 175 char buf[2000]; |
176 for (int j = 0; j < len; j++) { | 176 for (int j = 0; j < len; j++) { |
177 buf[j] = rng->next(0x80); | 177 buf[j] = rng->next(0x80); |
178 } | 178 } |
179 building_blocks[i] = | 179 building_blocks[i] = factory->NewStringFromAscii( |
180 factory->NewStringFromAscii(Vector<const char>(buf, len)); | 180 Vector<const char>(buf, len)).ToHandleChecked(); |
181 for (int j = 0; j < len; j++) { | 181 for (int j = 0; j < len; j++) { |
182 CHECK_EQ(buf[j], building_blocks[i]->Get(j)); | 182 CHECK_EQ(buf[j], building_blocks[i]->Get(j)); |
183 } | 183 } |
184 break; | 184 break; |
185 } | 185 } |
186 case 2: { | 186 case 2: { |
187 uc16* buf = NewArray<uc16>(len); | 187 uc16* buf = NewArray<uc16>(len); |
188 for (int j = 0; j < len; j++) { | 188 for (int j = 0; j < len; j++) { |
189 buf[j] = rng->next(0x10000); | 189 buf[j] = rng->next(0x10000); |
190 } | 190 } |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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->NewStringFromStaticAscii(""); |
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 = |
471 factory->NewConsString(answer, block).ToHandleChecked(); | 471 factory->NewConsString(answer, block).ToHandleChecked(); |
472 if (next->IsConsString()) data->stats_.leaves_++; | 472 if (next->IsConsString()) data->stats_.leaves_++; |
473 data->stats_.chars_ += block->length(); | 473 data->stats_.chars_ += block->length(); |
474 answer = next; | 474 answer = next; |
475 } | 475 } |
476 data->stats_.left_traversals_ = data->stats_.leaves_ - 2; | 476 data->stats_.left_traversals_ = data->stats_.leaves_ - 2; |
477 return answer; | 477 return answer; |
478 } | 478 } |
479 | 479 |
480 | 480 |
481 static Handle<String> ConstructRight( | 481 static Handle<String> ConstructRight( |
482 ConsStringGenerationData* data, | 482 ConsStringGenerationData* data, |
483 int depth) { | 483 int depth) { |
484 Factory* factory = CcTest::i_isolate()->factory(); | 484 Factory* factory = CcTest::i_isolate()->factory(); |
485 Handle<String> answer = factory->NewStringFromAscii(CStrVector("")); | 485 Handle<String> answer = factory->NewStringFromStaticAscii(""); |
486 data->stats_.leaves_++; | 486 data->stats_.leaves_++; |
487 for (int i = depth - 1; i >= 0; i--) { | 487 for (int i = depth - 1; i >= 0; i--) { |
488 Handle<String> block = data->block(i); | 488 Handle<String> block = data->block(i); |
489 Handle<String> next = | 489 Handle<String> next = |
490 factory->NewConsString(block, answer).ToHandleChecked(); | 490 factory->NewConsString(block, answer).ToHandleChecked(); |
491 if (next->IsConsString()) data->stats_.leaves_++; | 491 if (next->IsConsString()) data->stats_.leaves_++; |
492 data->stats_.chars_ += block->length(); | 492 data->stats_.chars_ += block->length(); |
493 answer = next; | 493 answer = next; |
494 } | 494 } |
495 data->stats_.right_traversals_ = data->stats_.leaves_ - 2; | 495 data->stats_.right_traversals_ = data->stats_.leaves_ - 2; |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
863 TEST(DeepAscii) { | 863 TEST(DeepAscii) { |
864 printf("TestDeepAscii\n"); | 864 printf("TestDeepAscii\n"); |
865 CcTest::InitializeVM(); | 865 CcTest::InitializeVM(); |
866 Factory* factory = CcTest::i_isolate()->factory(); | 866 Factory* factory = CcTest::i_isolate()->factory(); |
867 v8::HandleScope scope(CcTest::isolate()); | 867 v8::HandleScope scope(CcTest::isolate()); |
868 | 868 |
869 char* foo = NewArray<char>(DEEP_ASCII_DEPTH); | 869 char* foo = NewArray<char>(DEEP_ASCII_DEPTH); |
870 for (int i = 0; i < DEEP_ASCII_DEPTH; i++) { | 870 for (int i = 0; i < DEEP_ASCII_DEPTH; i++) { |
871 foo[i] = "foo "[i % 4]; | 871 foo[i] = "foo "[i % 4]; |
872 } | 872 } |
873 Handle<String> string = | 873 Handle<String> string = factory->NewStringFromOneByte( |
874 factory->NewStringFromAscii(Vector<const char>(foo, DEEP_ASCII_DEPTH)); | 874 OneByteVector(foo, DEEP_ASCII_DEPTH)).ToHandleChecked(); |
875 Handle<String> foo_string = factory->NewStringFromAscii(CStrVector("foo")); | 875 Handle<String> foo_string = factory->NewStringFromStaticAscii("foo"); |
876 for (int i = 0; i < DEEP_ASCII_DEPTH; i += 10) { | 876 for (int i = 0; i < DEEP_ASCII_DEPTH; i += 10) { |
877 string = factory->NewConsString(string, foo_string).ToHandleChecked(); | 877 string = factory->NewConsString(string, foo_string).ToHandleChecked(); |
878 } | 878 } |
879 Handle<String> flat_string = | 879 Handle<String> flat_string = |
880 factory->NewConsString(string, foo_string).ToHandleChecked(); | 880 factory->NewConsString(string, foo_string).ToHandleChecked(); |
881 String::Flatten(flat_string); | 881 String::Flatten(flat_string); |
882 | 882 |
883 for (int i = 0; i < 500; i++) { | 883 for (int i = 0; i < 500; i++) { |
884 TraverseFirst(flat_string, string, DEEP_ASCII_DEPTH); | 884 TraverseFirst(flat_string, string, DEEP_ASCII_DEPTH); |
885 } | 885 } |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1093 } | 1093 } |
1094 } | 1094 } |
1095 | 1095 |
1096 | 1096 |
1097 TEST(SliceFromCons) { | 1097 TEST(SliceFromCons) { |
1098 FLAG_string_slices = true; | 1098 FLAG_string_slices = true; |
1099 CcTest::InitializeVM(); | 1099 CcTest::InitializeVM(); |
1100 Factory* factory = CcTest::i_isolate()->factory(); | 1100 Factory* factory = CcTest::i_isolate()->factory(); |
1101 v8::HandleScope scope(CcTest::isolate()); | 1101 v8::HandleScope scope(CcTest::isolate()); |
1102 Handle<String> string = | 1102 Handle<String> string = |
1103 factory->NewStringFromAscii(CStrVector("parentparentparent")); | 1103 factory->NewStringFromStaticAscii("parentparentparent"); |
1104 Handle<String> parent = | 1104 Handle<String> parent = |
1105 factory->NewConsString(string, string).ToHandleChecked(); | 1105 factory->NewConsString(string, string).ToHandleChecked(); |
1106 CHECK(parent->IsConsString()); | 1106 CHECK(parent->IsConsString()); |
1107 CHECK(!parent->IsFlat()); | 1107 CHECK(!parent->IsFlat()); |
1108 Handle<String> slice = factory->NewSubString(parent, 1, 25); | 1108 Handle<String> slice = factory->NewSubString(parent, 1, 25); |
1109 // After slicing, the original string becomes a flat cons. | 1109 // After slicing, the original string becomes a flat cons. |
1110 CHECK(parent->IsFlat()); | 1110 CHECK(parent->IsFlat()); |
1111 CHECK(slice->IsSlicedString()); | 1111 CHECK(slice->IsSlicedString()); |
1112 CHECK_EQ(SlicedString::cast(*slice)->parent(), | 1112 CHECK_EQ(SlicedString::cast(*slice)->parent(), |
1113 // Parent could have been short-circuited. | 1113 // Parent could have been short-circuited. |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1415 dummy.Dispose(); \ | 1415 dummy.Dispose(); \ |
1416 } | 1416 } |
1417 | 1417 |
1418 INVALID_STRING_TEST(NewStringFromAscii, char) | 1418 INVALID_STRING_TEST(NewStringFromAscii, char) |
1419 INVALID_STRING_TEST(NewStringFromUtf8, char) | 1419 INVALID_STRING_TEST(NewStringFromUtf8, char) |
1420 INVALID_STRING_TEST(NewStringFromOneByte, uint8_t) | 1420 INVALID_STRING_TEST(NewStringFromOneByte, uint8_t) |
1421 INVALID_STRING_TEST(InternalizeOneByteString, uint8_t) | 1421 INVALID_STRING_TEST(InternalizeOneByteString, uint8_t) |
1422 INVALID_STRING_TEST(InternalizeUtf8String, char) | 1422 INVALID_STRING_TEST(InternalizeUtf8String, char) |
1423 | 1423 |
1424 #undef INVALID_STRING_TEST | 1424 #undef INVALID_STRING_TEST |
OLD | NEW |