| 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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 }; | 130 }; |
| 131 | 131 |
| 132 | 132 |
| 133 static void InitializeBuildingBlocks(Handle<String>* building_blocks, | 133 static void InitializeBuildingBlocks(Handle<String>* building_blocks, |
| 134 int bb_length, | 134 int bb_length, |
| 135 bool long_blocks, | 135 bool long_blocks, |
| 136 MyRandomNumberGenerator* rng, | 136 MyRandomNumberGenerator* rng, |
| 137 Zone* zone) { | 137 Zone* zone) { |
| 138 // A list of pointers that we don't have any interest in cleaning up. | 138 // A list of pointers that we don't have any interest in cleaning up. |
| 139 // If they are reachable from a root then leak detection won't complain. | 139 // If they are reachable from a root then leak detection won't complain. |
| 140 Isolate* isolate = Isolate::Current(); | 140 Isolate* isolate = CcTest::i_isolate(); |
| 141 Factory* factory = isolate->factory(); | 141 Factory* factory = isolate->factory(); |
| 142 for (int i = 0; i < bb_length; i++) { | 142 for (int i = 0; i < bb_length; i++) { |
| 143 int len = rng->next(16); | 143 int len = rng->next(16); |
| 144 int slice_head_chars = 0; | 144 int slice_head_chars = 0; |
| 145 int slice_tail_chars = 0; | 145 int slice_tail_chars = 0; |
| 146 int slice_depth = 0; | 146 int slice_depth = 0; |
| 147 for (int j = 0; j < 3; j++) { | 147 for (int j = 0; j < 3; j++) { |
| 148 if (rng->next(0.35)) slice_depth++; | 148 if (rng->next(0.35)) slice_depth++; |
| 149 } | 149 } |
| 150 // Must truncate something for a slice string. Loop until | 150 // Must truncate something for a slice string. Loop until |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 private: | 283 private: |
| 284 DISALLOW_COPY_AND_ASSIGN(ConsStringGenerationData); | 284 DISALLOW_COPY_AND_ASSIGN(ConsStringGenerationData); |
| 285 }; | 285 }; |
| 286 | 286 |
| 287 | 287 |
| 288 ConsStringGenerationData::ConsStringGenerationData(bool long_blocks, | 288 ConsStringGenerationData::ConsStringGenerationData(bool long_blocks, |
| 289 Zone* zone) { | 289 Zone* zone) { |
| 290 rng_.init(); | 290 rng_.init(); |
| 291 InitializeBuildingBlocks( | 291 InitializeBuildingBlocks( |
| 292 building_blocks_, kNumberOfBuildingBlocks, long_blocks, &rng_, zone); | 292 building_blocks_, kNumberOfBuildingBlocks, long_blocks, &rng_, zone); |
| 293 empty_string_ = Isolate::Current()->heap()->empty_string(); | 293 empty_string_ = CcTest::i_isolate()->heap()->empty_string(); |
| 294 Reset(); | 294 Reset(); |
| 295 } | 295 } |
| 296 | 296 |
| 297 | 297 |
| 298 Handle<String> ConsStringGenerationData::block(uint32_t offset) { | 298 Handle<String> ConsStringGenerationData::block(uint32_t offset) { |
| 299 return building_blocks_[offset % kNumberOfBuildingBlocks ]; | 299 return building_blocks_[offset % kNumberOfBuildingBlocks ]; |
| 300 } | 300 } |
| 301 | 301 |
| 302 | 302 |
| 303 Handle<String> ConsStringGenerationData::block(int offset) { | 303 Handle<String> ConsStringGenerationData::block(int offset) { |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 stats.left_traversals_ = data->stats_.left_traversals_; | 396 stats.left_traversals_ = data->stats_.left_traversals_; |
| 397 stats.right_traversals_ = data->stats_.right_traversals_; | 397 stats.right_traversals_ = data->stats_.right_traversals_; |
| 398 // Adjust total leaves to compensate. | 398 // Adjust total leaves to compensate. |
| 399 stats.leaves_ += stats.empty_leaves_; | 399 stats.leaves_ += stats.empty_leaves_; |
| 400 stats.VerifyEqual(data->stats_); | 400 stats.VerifyEqual(data->stats_); |
| 401 } | 401 } |
| 402 | 402 |
| 403 | 403 |
| 404 static Handle<String> ConstructRandomString(ConsStringGenerationData* data, | 404 static Handle<String> ConstructRandomString(ConsStringGenerationData* data, |
| 405 unsigned max_recursion) { | 405 unsigned max_recursion) { |
| 406 Factory* factory = Isolate::Current()->factory(); | 406 Factory* factory = CcTest::i_isolate()->factory(); |
| 407 // Compute termination characteristics. | 407 // Compute termination characteristics. |
| 408 bool terminate = false; | 408 bool terminate = false; |
| 409 bool flat = data->rng_.next(data->empty_leaf_threshold_); | 409 bool flat = data->rng_.next(data->empty_leaf_threshold_); |
| 410 bool terminate_early = data->rng_.next(data->early_termination_threshold_); | 410 bool terminate_early = data->rng_.next(data->early_termination_threshold_); |
| 411 if (terminate_early) data->early_terminations_++; | 411 if (terminate_early) data->early_terminations_++; |
| 412 // The obvious condition. | 412 // The obvious condition. |
| 413 terminate |= max_recursion == 0; | 413 terminate |= max_recursion == 0; |
| 414 // Flat cons string terminate by definition. | 414 // Flat cons string terminate by definition. |
| 415 terminate |= flat; | 415 terminate |= flat; |
| 416 // Cap for max leaves. | 416 // Cap for max leaves. |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 FlattenString(root); | 458 FlattenString(root); |
| 459 CHECK(root->IsConsString() && root->IsFlat()); | 459 CHECK(root->IsConsString() && root->IsFlat()); |
| 460 } | 460 } |
| 461 return root; | 461 return root; |
| 462 } | 462 } |
| 463 | 463 |
| 464 | 464 |
| 465 static Handle<String> ConstructLeft( | 465 static Handle<String> ConstructLeft( |
| 466 ConsStringGenerationData* data, | 466 ConsStringGenerationData* data, |
| 467 int depth) { | 467 int depth) { |
| 468 Factory* factory = Isolate::Current()->factory(); | 468 Factory* factory = CcTest::i_isolate()->factory(); |
| 469 Handle<String> answer = factory->NewStringFromAscii(CStrVector("")); | 469 Handle<String> answer = factory->NewStringFromAscii(CStrVector("")); |
| 470 data->stats_.leaves_++; | 470 data->stats_.leaves_++; |
| 471 for (int i = 0; i < depth; i++) { | 471 for (int i = 0; i < depth; i++) { |
| 472 Handle<String> block = data->block(i); | 472 Handle<String> block = data->block(i); |
| 473 Handle<String> next = factory->NewConsString(answer, block); | 473 Handle<String> next = factory->NewConsString(answer, block); |
| 474 if (next->IsConsString()) data->stats_.leaves_++; | 474 if (next->IsConsString()) data->stats_.leaves_++; |
| 475 data->stats_.chars_ += block->length(); | 475 data->stats_.chars_ += block->length(); |
| 476 answer = next; | 476 answer = next; |
| 477 } | 477 } |
| 478 data->stats_.left_traversals_ = data->stats_.leaves_ - 2; | 478 data->stats_.left_traversals_ = data->stats_.leaves_ - 2; |
| 479 return answer; | 479 return answer; |
| 480 } | 480 } |
| 481 | 481 |
| 482 | 482 |
| 483 static Handle<String> ConstructRight( | 483 static Handle<String> ConstructRight( |
| 484 ConsStringGenerationData* data, | 484 ConsStringGenerationData* data, |
| 485 int depth) { | 485 int depth) { |
| 486 Factory* factory = Isolate::Current()->factory(); | 486 Factory* factory = CcTest::i_isolate()->factory(); |
| 487 Handle<String> answer = factory->NewStringFromAscii(CStrVector("")); | 487 Handle<String> answer = factory->NewStringFromAscii(CStrVector("")); |
| 488 data->stats_.leaves_++; | 488 data->stats_.leaves_++; |
| 489 for (int i = depth - 1; i >= 0; i--) { | 489 for (int i = depth - 1; i >= 0; i--) { |
| 490 Handle<String> block = data->block(i); | 490 Handle<String> block = data->block(i); |
| 491 Handle<String> next = factory->NewConsString(block, answer); | 491 Handle<String> next = factory->NewConsString(block, answer); |
| 492 if (next->IsConsString()) data->stats_.leaves_++; | 492 if (next->IsConsString()) data->stats_.leaves_++; |
| 493 data->stats_.chars_ += block->length(); | 493 data->stats_.chars_ += block->length(); |
| 494 answer = next; | 494 answer = next; |
| 495 } | 495 } |
| 496 data->stats_.right_traversals_ = data->stats_.leaves_ - 2; | 496 data->stats_.right_traversals_ = data->stats_.leaves_ - 2; |
| 497 return answer; | 497 return answer; |
| 498 } | 498 } |
| 499 | 499 |
| 500 | 500 |
| 501 static Handle<String> ConstructBalancedHelper( | 501 static Handle<String> ConstructBalancedHelper( |
| 502 ConsStringGenerationData* data, | 502 ConsStringGenerationData* data, |
| 503 int from, | 503 int from, |
| 504 int to) { | 504 int to) { |
| 505 Factory* factory = Isolate::Current()->factory(); | 505 Factory* factory = CcTest::i_isolate()->factory(); |
| 506 CHECK(to > from); | 506 CHECK(to > from); |
| 507 if (to - from == 1) { | 507 if (to - from == 1) { |
| 508 data->stats_.chars_ += data->block(from)->length(); | 508 data->stats_.chars_ += data->block(from)->length(); |
| 509 return data->block(from); | 509 return data->block(from); |
| 510 } | 510 } |
| 511 if (to - from == 2) { | 511 if (to - from == 2) { |
| 512 data->stats_.chars_ += data->block(from)->length(); | 512 data->stats_.chars_ += data->block(from)->length(); |
| 513 data->stats_.chars_ += data->block(from+1)->length(); | 513 data->stats_.chars_ += data->block(from+1)->length(); |
| 514 return factory->NewConsString(data->block(from), data->block(from+1)); | 514 return factory->NewConsString(data->block(from), data->block(from+1)); |
| 515 } | 515 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 564 } | 564 } |
| 565 s1->Get(s1->length() - 1); | 565 s1->Get(s1->length() - 1); |
| 566 s2->Get(s2->length() - 1); | 566 s2->Get(s2->length() - 1); |
| 567 } | 567 } |
| 568 | 568 |
| 569 | 569 |
| 570 TEST(Traverse) { | 570 TEST(Traverse) { |
| 571 printf("TestTraverse\n"); | 571 printf("TestTraverse\n"); |
| 572 CcTest::InitializeVM(); | 572 CcTest::InitializeVM(); |
| 573 v8::HandleScope scope(CcTest::isolate()); | 573 v8::HandleScope scope(CcTest::isolate()); |
| 574 Zone zone(Isolate::Current()); | 574 Zone zone(CcTest::i_isolate()); |
| 575 ConsStringGenerationData data(false, &zone); | 575 ConsStringGenerationData data(false, &zone); |
| 576 Handle<String> flat = ConstructBalanced(&data); | 576 Handle<String> flat = ConstructBalanced(&data); |
| 577 FlattenString(flat); | 577 FlattenString(flat); |
| 578 Handle<String> left_asymmetric = ConstructLeft(&data, DEEP_DEPTH); | 578 Handle<String> left_asymmetric = ConstructLeft(&data, DEEP_DEPTH); |
| 579 Handle<String> right_asymmetric = ConstructRight(&data, DEEP_DEPTH); | 579 Handle<String> right_asymmetric = ConstructRight(&data, DEEP_DEPTH); |
| 580 Handle<String> symmetric = ConstructBalanced(&data); | 580 Handle<String> symmetric = ConstructBalanced(&data); |
| 581 printf("1\n"); | 581 printf("1\n"); |
| 582 Traverse(flat, symmetric); | 582 Traverse(flat, symmetric); |
| 583 printf("2\n"); | 583 printf("2\n"); |
| 584 Traverse(flat, left_asymmetric); | 584 Traverse(flat, left_asymmetric); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 652 "lefts", data.stats_.left_traversals_, | 652 "lefts", data.stats_.left_traversals_, |
| 653 "rights", data.stats_.right_traversals_, | 653 "rights", data.stats_.right_traversals_, |
| 654 "early_terminations", data.early_terminations_); | 654 "early_terminations", data.early_terminations_); |
| 655 #endif | 655 #endif |
| 656 } | 656 } |
| 657 | 657 |
| 658 | 658 |
| 659 template<typename BuildString> | 659 template<typename BuildString> |
| 660 void TestStringCharacterStream(BuildString build, int test_cases) { | 660 void TestStringCharacterStream(BuildString build, int test_cases) { |
| 661 CcTest::InitializeVM(); | 661 CcTest::InitializeVM(); |
| 662 Isolate* isolate = Isolate::Current(); | 662 Isolate* isolate = CcTest::i_isolate(); |
| 663 HandleScope outer_scope(isolate); | 663 HandleScope outer_scope(isolate); |
| 664 Zone zone(isolate); | 664 Zone zone(isolate); |
| 665 ConsStringGenerationData data(true, &zone); | 665 ConsStringGenerationData data(true, &zone); |
| 666 for (int i = 0; i < test_cases; i++) { | 666 for (int i = 0; i < test_cases; i++) { |
| 667 printf("%d\n", i); | 667 printf("%d\n", i); |
| 668 HandleScope inner_scope(isolate); | 668 HandleScope inner_scope(isolate); |
| 669 AlwaysAllocateScope always_allocate; | 669 AlwaysAllocateScope always_allocate; |
| 670 // Build flat version of cons string. | 670 // Build flat version of cons string. |
| 671 Handle<String> flat_string = build(i, &data); | 671 Handle<String> flat_string = build(i, &data); |
| 672 ConsStringStats flat_string_stats; | 672 ConsStringStats flat_string_stats; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 690 VerifyCharacterStream(flat_string_ptr, *cons_string); | 690 VerifyCharacterStream(flat_string_ptr, *cons_string); |
| 691 } | 691 } |
| 692 } | 692 } |
| 693 | 693 |
| 694 | 694 |
| 695 static const int kCharacterStreamNonRandomCases = 8; | 695 static const int kCharacterStreamNonRandomCases = 8; |
| 696 | 696 |
| 697 | 697 |
| 698 static Handle<String> BuildEdgeCaseConsString( | 698 static Handle<String> BuildEdgeCaseConsString( |
| 699 int test_case, ConsStringGenerationData* data) { | 699 int test_case, ConsStringGenerationData* data) { |
| 700 Factory* factory = Isolate::Current()->factory(); | 700 Factory* factory = CcTest::i_isolate()->factory(); |
| 701 data->Reset(); | 701 data->Reset(); |
| 702 switch (test_case) { | 702 switch (test_case) { |
| 703 case 0: | 703 case 0: |
| 704 return ConstructBalanced(data, 71); | 704 return ConstructBalanced(data, 71); |
| 705 case 1: | 705 case 1: |
| 706 return ConstructLeft(data, 71); | 706 return ConstructLeft(data, 71); |
| 707 case 2: | 707 case 2: |
| 708 return ConstructRight(data, 71); | 708 return ConstructRight(data, 71); |
| 709 case 3: | 709 case 3: |
| 710 return ConstructLeft(data, 10); | 710 return ConstructLeft(data, 10); |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 853 TestStringCharacterStream(BuildRandomConsString, kUniqueRandomParameters*7); | 853 TestStringCharacterStream(BuildRandomConsString, kUniqueRandomParameters*7); |
| 854 } | 854 } |
| 855 | 855 |
| 856 | 856 |
| 857 static const int DEEP_ASCII_DEPTH = 100000; | 857 static const int DEEP_ASCII_DEPTH = 100000; |
| 858 | 858 |
| 859 | 859 |
| 860 TEST(DeepAscii) { | 860 TEST(DeepAscii) { |
| 861 printf("TestDeepAscii\n"); | 861 printf("TestDeepAscii\n"); |
| 862 CcTest::InitializeVM(); | 862 CcTest::InitializeVM(); |
| 863 Factory* factory = Isolate::Current()->factory(); | 863 Factory* factory = CcTest::i_isolate()->factory(); |
| 864 v8::HandleScope scope(CcTest::isolate()); | 864 v8::HandleScope scope(CcTest::isolate()); |
| 865 | 865 |
| 866 char* foo = NewArray<char>(DEEP_ASCII_DEPTH); | 866 char* foo = NewArray<char>(DEEP_ASCII_DEPTH); |
| 867 for (int i = 0; i < DEEP_ASCII_DEPTH; i++) { | 867 for (int i = 0; i < DEEP_ASCII_DEPTH; i++) { |
| 868 foo[i] = "foo "[i % 4]; | 868 foo[i] = "foo "[i % 4]; |
| 869 } | 869 } |
| 870 Handle<String> string = | 870 Handle<String> string = |
| 871 factory->NewStringFromAscii(Vector<const char>(foo, DEEP_ASCII_DEPTH)); | 871 factory->NewStringFromAscii(Vector<const char>(foo, DEEP_ASCII_DEPTH)); |
| 872 Handle<String> foo_string = factory->NewStringFromAscii(CStrVector("foo")); | 872 Handle<String> foo_string = factory->NewStringFromAscii(CStrVector("foo")); |
| 873 for (int i = 0; i < DEEP_ASCII_DEPTH; i += 10) { | 873 for (int i = 0; i < DEEP_ASCII_DEPTH; i += 10) { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 923 for (int j = 0; j < lengths[i]; j++) | 923 for (int j = 0; j < lengths[i]; j++) |
| 924 CHECK_EQ(as_utf8[j], static_cast<unsigned char>(buffer[j])); | 924 CHECK_EQ(as_utf8[j], static_cast<unsigned char>(buffer[j])); |
| 925 // Check that the rest of the buffer hasn't been touched | 925 // Check that the rest of the buffer hasn't been touched |
| 926 for (int j = lengths[i]; j < 11; j++) | 926 for (int j = lengths[i]; j < 11; j++) |
| 927 CHECK_EQ(kNoChar, buffer[j]); | 927 CHECK_EQ(kNoChar, buffer[j]); |
| 928 } | 928 } |
| 929 } | 929 } |
| 930 | 930 |
| 931 | 931 |
| 932 TEST(ExternalShortStringAdd) { | 932 TEST(ExternalShortStringAdd) { |
| 933 Isolate* isolate = Isolate::Current(); | 933 Isolate* isolate = CcTest::i_isolate(); |
| 934 Zone zone(isolate); | 934 Zone zone(isolate); |
| 935 | 935 |
| 936 CcTest::InitializeVM(); | 936 CcTest::InitializeVM(); |
| 937 v8::HandleScope handle_scope(CcTest::isolate()); | 937 v8::HandleScope handle_scope(CcTest::isolate()); |
| 938 | 938 |
| 939 // Make sure we cover all always-flat lengths and at least one above. | 939 // Make sure we cover all always-flat lengths and at least one above. |
| 940 static const int kMaxLength = 20; | 940 static const int kMaxLength = 20; |
| 941 CHECK_GT(kMaxLength, i::ConsString::kMinLength); | 941 CHECK_GT(kMaxLength, i::ConsString::kMinLength); |
| 942 | 942 |
| 943 // Allocate two JavaScript arrays for holding short strings. | 943 // Allocate two JavaScript arrays for holding short strings. |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1011 " }" | 1011 " }" |
| 1012 " }" | 1012 " }" |
| 1013 " return 0;" | 1013 " return 0;" |
| 1014 "};" | 1014 "};" |
| 1015 "test()"; | 1015 "test()"; |
| 1016 CHECK_EQ(0, CompileRun(source)->Int32Value()); | 1016 CHECK_EQ(0, CompileRun(source)->Int32Value()); |
| 1017 } | 1017 } |
| 1018 | 1018 |
| 1019 | 1019 |
| 1020 TEST(JSONStringifySliceMadeExternal) { | 1020 TEST(JSONStringifySliceMadeExternal) { |
| 1021 Isolate* isolate = Isolate::Current(); | 1021 Isolate* isolate = CcTest::i_isolate(); |
| 1022 Zone zone(isolate); | 1022 Zone zone(isolate); |
| 1023 CcTest::InitializeVM(); | 1023 CcTest::InitializeVM(); |
| 1024 // Create a sliced string from a one-byte string. The latter is turned | 1024 // Create a sliced string from a one-byte string. The latter is turned |
| 1025 // into a two-byte external string. Check that JSON.stringify works. | 1025 // into a two-byte external string. Check that JSON.stringify works. |
| 1026 v8::HandleScope handle_scope(CcTest::isolate()); | 1026 v8::HandleScope handle_scope(CcTest::isolate()); |
| 1027 v8::Handle<v8::String> underlying = | 1027 v8::Handle<v8::String> underlying = |
| 1028 CompileRun("var underlying = 'abcdefghijklmnopqrstuvwxyz';" | 1028 CompileRun("var underlying = 'abcdefghijklmnopqrstuvwxyz';" |
| 1029 "underlying")->ToString(); | 1029 "underlying")->ToString(); |
| 1030 v8::Handle<v8::String> slice = | 1030 v8::Handle<v8::String> slice = |
| 1031 CompileRun("var slice = underlying.slice(1);" | 1031 CompileRun("var slice = underlying.slice(1);" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1044 | 1044 |
| 1045 CHECK_EQ("\"bcdefghijklmnopqrstuvwxyz\"", | 1045 CHECK_EQ("\"bcdefghijklmnopqrstuvwxyz\"", |
| 1046 *v8::String::Utf8Value(CompileRun("JSON.stringify(slice)"))); | 1046 *v8::String::Utf8Value(CompileRun("JSON.stringify(slice)"))); |
| 1047 } | 1047 } |
| 1048 | 1048 |
| 1049 | 1049 |
| 1050 TEST(CachedHashOverflow) { | 1050 TEST(CachedHashOverflow) { |
| 1051 // We incorrectly allowed strings to be tagged as array indices even if their | 1051 // We incorrectly allowed strings to be tagged as array indices even if their |
| 1052 // values didn't fit in the hash field. | 1052 // values didn't fit in the hash field. |
| 1053 // See http://code.google.com/p/v8/issues/detail?id=728 | 1053 // See http://code.google.com/p/v8/issues/detail?id=728 |
| 1054 Isolate* isolate = Isolate::Current(); | 1054 Isolate* isolate = CcTest::i_isolate(); |
| 1055 Zone zone(isolate); | 1055 Zone zone(isolate); |
| 1056 | 1056 |
| 1057 CcTest::InitializeVM(); | 1057 CcTest::InitializeVM(); |
| 1058 v8::HandleScope handle_scope(CcTest::isolate()); | 1058 v8::HandleScope handle_scope(CcTest::isolate()); |
| 1059 // Lines must be executed sequentially. Combining them into one script | 1059 // Lines must be executed sequentially. Combining them into one script |
| 1060 // makes the bug go away. | 1060 // makes the bug go away. |
| 1061 const char* lines[] = { | 1061 const char* lines[] = { |
| 1062 "var x = [];", | 1062 "var x = [];", |
| 1063 "x[4] = 42;", | 1063 "x[4] = 42;", |
| 1064 "var s = \"1073741828\";", | 1064 "var s = \"1073741828\";", |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1091 CHECK_EQ(Smi::cast(results[i]->ToSmi()->ToObjectChecked())->value(), | 1091 CHECK_EQ(Smi::cast(results[i]->ToSmi()->ToObjectChecked())->value(), |
| 1092 result->ToInt32()->Value()); | 1092 result->ToInt32()->Value()); |
| 1093 } | 1093 } |
| 1094 } | 1094 } |
| 1095 } | 1095 } |
| 1096 | 1096 |
| 1097 | 1097 |
| 1098 TEST(SliceFromCons) { | 1098 TEST(SliceFromCons) { |
| 1099 FLAG_string_slices = true; | 1099 FLAG_string_slices = true; |
| 1100 CcTest::InitializeVM(); | 1100 CcTest::InitializeVM(); |
| 1101 Factory* factory = Isolate::Current()->factory(); | 1101 Factory* factory = CcTest::i_isolate()->factory(); |
| 1102 v8::HandleScope scope(CcTest::isolate()); | 1102 v8::HandleScope scope(CcTest::isolate()); |
| 1103 Handle<String> string = | 1103 Handle<String> string = |
| 1104 factory->NewStringFromAscii(CStrVector("parentparentparent")); | 1104 factory->NewStringFromAscii(CStrVector("parentparentparent")); |
| 1105 Handle<String> parent = factory->NewConsString(string, string); | 1105 Handle<String> parent = factory->NewConsString(string, string); |
| 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()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1126 virtual size_t length() const { return data_.length(); } | 1126 virtual size_t length() const { return data_.length(); } |
| 1127 virtual const char* data() const { return data_.start(); } | 1127 virtual const char* data() const { return data_.start(); } |
| 1128 private: | 1128 private: |
| 1129 i::Vector<const char> data_; | 1129 i::Vector<const char> data_; |
| 1130 }; | 1130 }; |
| 1131 | 1131 |
| 1132 | 1132 |
| 1133 TEST(SliceFromExternal) { | 1133 TEST(SliceFromExternal) { |
| 1134 FLAG_string_slices = true; | 1134 FLAG_string_slices = true; |
| 1135 CcTest::InitializeVM(); | 1135 CcTest::InitializeVM(); |
| 1136 Factory* factory = Isolate::Current()->factory(); | 1136 Factory* factory = CcTest::i_isolate()->factory(); |
| 1137 v8::HandleScope scope(CcTest::isolate()); | 1137 v8::HandleScope scope(CcTest::isolate()); |
| 1138 AsciiVectorResource resource( | 1138 AsciiVectorResource resource( |
| 1139 i::Vector<const char>("abcdefghijklmnopqrstuvwxyz", 26)); | 1139 i::Vector<const char>("abcdefghijklmnopqrstuvwxyz", 26)); |
| 1140 Handle<String> string = factory->NewExternalStringFromAscii(&resource); | 1140 Handle<String> string = factory->NewExternalStringFromAscii(&resource); |
| 1141 CHECK(string->IsExternalString()); | 1141 CHECK(string->IsExternalString()); |
| 1142 Handle<String> slice = factory->NewSubString(string, 1, 25); | 1142 Handle<String> slice = factory->NewSubString(string, 1, 25); |
| 1143 CHECK(slice->IsSlicedString()); | 1143 CHECK(slice->IsSlicedString()); |
| 1144 CHECK(string->IsExternalString()); | 1144 CHECK(string->IsExternalString()); |
| 1145 CHECK_EQ(SlicedString::cast(*slice)->parent(), *string); | 1145 CHECK_EQ(SlicedString::cast(*slice)->parent(), *string); |
| 1146 CHECK(SlicedString::cast(*slice)->parent()->IsExternalString()); | 1146 CHECK(SlicedString::cast(*slice)->parent()->IsExternalString()); |
| 1147 CHECK(slice->IsFlat()); | 1147 CHECK(slice->IsFlat()); |
| 1148 } | 1148 } |
| 1149 | 1149 |
| 1150 | 1150 |
| 1151 TEST(TrivialSlice) { | 1151 TEST(TrivialSlice) { |
| 1152 // This tests whether a slice that contains the entire parent string | 1152 // This tests whether a slice that contains the entire parent string |
| 1153 // actually creates a new string (it should not). | 1153 // actually creates a new string (it should not). |
| 1154 FLAG_string_slices = true; | 1154 FLAG_string_slices = true; |
| 1155 CcTest::InitializeVM(); | 1155 CcTest::InitializeVM(); |
| 1156 Factory* factory = Isolate::Current()->factory(); | 1156 Factory* factory = CcTest::i_isolate()->factory(); |
| 1157 v8::HandleScope scope(CcTest::isolate()); | 1157 v8::HandleScope scope(CcTest::isolate()); |
| 1158 v8::Local<v8::Value> result; | 1158 v8::Local<v8::Value> result; |
| 1159 Handle<String> string; | 1159 Handle<String> string; |
| 1160 const char* init = "var str = 'abcdefghijklmnopqrstuvwxyz';"; | 1160 const char* init = "var str = 'abcdefghijklmnopqrstuvwxyz';"; |
| 1161 const char* check = "str.slice(0,26)"; | 1161 const char* check = "str.slice(0,26)"; |
| 1162 const char* crosscheck = "str.slice(1,25)"; | 1162 const char* crosscheck = "str.slice(1,25)"; |
| 1163 | 1163 |
| 1164 CompileRun(init); | 1164 CompileRun(init); |
| 1165 | 1165 |
| 1166 result = CompileRun(check); | 1166 result = CompileRun(check); |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1379 CheckCanonicalEquivalence(c, test); | 1379 CheckCanonicalEquivalence(c, test); |
| 1380 continue; | 1380 continue; |
| 1381 } | 1381 } |
| 1382 if (upper != c && lower != c) { | 1382 if (upper != c && lower != c) { |
| 1383 CheckCanonicalEquivalence(c, test); | 1383 CheckCanonicalEquivalence(c, test); |
| 1384 continue; | 1384 continue; |
| 1385 } | 1385 } |
| 1386 CHECK_EQ(Min(upper, lower), test); | 1386 CHECK_EQ(Min(upper, lower), test); |
| 1387 } | 1387 } |
| 1388 } | 1388 } |
| OLD | NEW |