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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 private: | 88 private: |
89 static const uint32_t kQSize = 4096; | 89 static const uint32_t kQSize = 4096; |
90 uint32_t Q[kQSize]; | 90 uint32_t Q[kQSize]; |
91 uint32_t c; | 91 uint32_t c; |
92 uint32_t i; | 92 uint32_t i; |
93 }; | 93 }; |
94 | 94 |
95 | 95 |
96 using namespace v8::internal; | 96 using namespace v8::internal; |
97 | 97 |
98 static v8::Persistent<v8::Context> env; | |
99 | |
100 | |
101 static void InitializeVM() { | |
102 if (env.IsEmpty()) { | |
103 const char* extensions[] = { "v8/print" }; | |
104 v8::ExtensionConfiguration config(1, extensions); | |
105 env = v8::Context::New(&config); | |
106 } | |
107 env->Enter(); | |
108 } | |
109 | |
110 | 98 |
111 static const int DEEP_DEPTH = 8 * 1024; | 99 static const int DEEP_DEPTH = 8 * 1024; |
112 static const int SUPER_DEEP_DEPTH = 80 * 1024; | 100 static const int SUPER_DEEP_DEPTH = 80 * 1024; |
113 | 101 |
114 | 102 |
115 class Resource: public v8::String::ExternalStringResource, | 103 class Resource: public v8::String::ExternalStringResource, |
116 public ZoneObject { | 104 public ZoneObject { |
117 public: | 105 public: |
118 explicit Resource(Vector<const uc16> string): data_(string.start()) { | 106 explicit Resource(Vector<const uc16> string): data_(string.start()) { |
119 length_ = string.length(); | 107 length_ = string.length(); |
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
567 CHECK_EQ(c, character_stream_2.GetNext()); | 555 CHECK_EQ(c, character_stream_2.GetNext()); |
568 i++; | 556 i++; |
569 } | 557 } |
570 s1->Get(s1->length() - 1); | 558 s1->Get(s1->length() - 1); |
571 s2->Get(s2->length() - 1); | 559 s2->Get(s2->length() - 1); |
572 } | 560 } |
573 | 561 |
574 | 562 |
575 TEST(Traverse) { | 563 TEST(Traverse) { |
576 printf("TestTraverse\n"); | 564 printf("TestTraverse\n"); |
577 InitializeVM(); | 565 CcTest::InitializeVM(); |
578 v8::HandleScope scope(env->GetIsolate()); | 566 v8::HandleScope scope(CcTest::isolate()); |
579 ZoneScope zone(Isolate::Current()->runtime_zone(), DELETE_ON_EXIT); | 567 ZoneScope zone(Isolate::Current()->runtime_zone(), DELETE_ON_EXIT); |
580 ConsStringGenerationData data(false); | 568 ConsStringGenerationData data(false); |
581 Handle<String> flat = ConstructBalanced(&data); | 569 Handle<String> flat = ConstructBalanced(&data); |
582 FlattenString(flat); | 570 FlattenString(flat); |
583 Handle<String> left_asymmetric = ConstructLeft(&data, DEEP_DEPTH); | 571 Handle<String> left_asymmetric = ConstructLeft(&data, DEEP_DEPTH); |
584 Handle<String> right_asymmetric = ConstructRight(&data, DEEP_DEPTH); | 572 Handle<String> right_asymmetric = ConstructRight(&data, DEEP_DEPTH); |
585 Handle<String> symmetric = ConstructBalanced(&data); | 573 Handle<String> symmetric = ConstructBalanced(&data); |
586 printf("1\n"); | 574 printf("1\n"); |
587 Traverse(flat, symmetric); | 575 Traverse(flat, symmetric); |
588 printf("2\n"); | 576 printf("2\n"); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
656 "chars", data.stats_.chars_, | 644 "chars", data.stats_.chars_, |
657 "lefts", data.stats_.left_traversals_, | 645 "lefts", data.stats_.left_traversals_, |
658 "rights", data.stats_.right_traversals_, | 646 "rights", data.stats_.right_traversals_, |
659 "early_terminations", data.early_terminations_); | 647 "early_terminations", data.early_terminations_); |
660 #endif | 648 #endif |
661 } | 649 } |
662 | 650 |
663 | 651 |
664 template<typename BuildString> | 652 template<typename BuildString> |
665 void TestStringCharacterStream(BuildString build, int test_cases) { | 653 void TestStringCharacterStream(BuildString build, int test_cases) { |
666 InitializeVM(); | 654 CcTest::InitializeVM(); |
667 Isolate* isolate = Isolate::Current(); | 655 Isolate* isolate = Isolate::Current(); |
668 HandleScope outer_scope(isolate); | 656 HandleScope outer_scope(isolate); |
669 ZoneScope zone(Isolate::Current()->runtime_zone(), DELETE_ON_EXIT); | 657 ZoneScope zone(Isolate::Current()->runtime_zone(), DELETE_ON_EXIT); |
670 ConsStringGenerationData data(true); | 658 ConsStringGenerationData data(true); |
671 for (int i = 0; i < test_cases; i++) { | 659 for (int i = 0; i < test_cases; i++) { |
672 printf("%d\n", i); | 660 printf("%d\n", i); |
673 HandleScope inner_scope(isolate); | 661 HandleScope inner_scope(isolate); |
674 AlwaysAllocateScope always_allocate; | 662 AlwaysAllocateScope always_allocate; |
675 // Build flat version of cons string. | 663 // Build flat version of cons string. |
676 Handle<String> flat_string = build(i, &data); | 664 Handle<String> flat_string = build(i, &data); |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
856 printf("StringCharacterStreamRandom\n"); | 844 printf("StringCharacterStreamRandom\n"); |
857 TestStringCharacterStream(BuildRandomConsString, kUniqueRandomParameters*7); | 845 TestStringCharacterStream(BuildRandomConsString, kUniqueRandomParameters*7); |
858 } | 846 } |
859 | 847 |
860 | 848 |
861 static const int DEEP_ASCII_DEPTH = 100000; | 849 static const int DEEP_ASCII_DEPTH = 100000; |
862 | 850 |
863 | 851 |
864 TEST(DeepAscii) { | 852 TEST(DeepAscii) { |
865 printf("TestDeepAscii\n"); | 853 printf("TestDeepAscii\n"); |
866 InitializeVM(); | 854 CcTest::InitializeVM(); |
867 v8::HandleScope scope(env->GetIsolate()); | 855 v8::HandleScope scope(CcTest::isolate()); |
868 | 856 |
869 char* foo = NewArray<char>(DEEP_ASCII_DEPTH); | 857 char* foo = NewArray<char>(DEEP_ASCII_DEPTH); |
870 for (int i = 0; i < DEEP_ASCII_DEPTH; i++) { | 858 for (int i = 0; i < DEEP_ASCII_DEPTH; i++) { |
871 foo[i] = "foo "[i % 4]; | 859 foo[i] = "foo "[i % 4]; |
872 } | 860 } |
873 Handle<String> string = | 861 Handle<String> string = |
874 FACTORY->NewStringFromAscii(Vector<const char>(foo, DEEP_ASCII_DEPTH)); | 862 FACTORY->NewStringFromAscii(Vector<const char>(foo, DEEP_ASCII_DEPTH)); |
875 Handle<String> foo_string = FACTORY->NewStringFromAscii(CStrVector("foo")); | 863 Handle<String> foo_string = FACTORY->NewStringFromAscii(CStrVector("foo")); |
876 for (int i = 0; i < DEEP_ASCII_DEPTH; i += 10) { | 864 for (int i = 0; i < DEEP_ASCII_DEPTH; i += 10) { |
877 string = FACTORY->NewConsString(string, foo_string); | 865 string = FACTORY->NewConsString(string, foo_string); |
878 } | 866 } |
879 Handle<String> flat_string = FACTORY->NewConsString(string, foo_string); | 867 Handle<String> flat_string = FACTORY->NewConsString(string, foo_string); |
880 FlattenString(flat_string); | 868 FlattenString(flat_string); |
881 | 869 |
882 for (int i = 0; i < 500; i++) { | 870 for (int i = 0; i < 500; i++) { |
883 TraverseFirst(flat_string, string, DEEP_ASCII_DEPTH); | 871 TraverseFirst(flat_string, string, DEEP_ASCII_DEPTH); |
884 } | 872 } |
885 DeleteArray<char>(foo); | 873 DeleteArray<char>(foo); |
886 } | 874 } |
887 | 875 |
888 | 876 |
889 TEST(Utf8Conversion) { | 877 TEST(Utf8Conversion) { |
890 // Smoke test for converting strings to utf-8. | 878 // Smoke test for converting strings to utf-8. |
891 InitializeVM(); | 879 CcTest::InitializeVM(); |
892 v8::HandleScope handle_scope(env->GetIsolate()); | 880 v8::HandleScope handle_scope(CcTest::isolate()); |
893 // A simple ascii string | 881 // A simple ascii string |
894 const char* ascii_string = "abcdef12345"; | 882 const char* ascii_string = "abcdef12345"; |
895 int len = | 883 int len = |
896 v8::String::New(ascii_string, | 884 v8::String::New(ascii_string, |
897 StrLength(ascii_string))->Utf8Length(); | 885 StrLength(ascii_string))->Utf8Length(); |
898 CHECK_EQ(StrLength(ascii_string), len); | 886 CHECK_EQ(StrLength(ascii_string), len); |
899 // A mixed ascii and non-ascii string | 887 // A mixed ascii and non-ascii string |
900 // U+02E4 -> CB A4 | 888 // U+02E4 -> CB A4 |
901 // U+0064 -> 64 | 889 // U+0064 -> 64 |
902 // U+12E4 -> E1 8B A4 | 890 // U+12E4 -> E1 8B A4 |
(...skipping 25 matching lines...) Expand all Loading... |
928 // Check that the rest of the buffer hasn't been touched | 916 // Check that the rest of the buffer hasn't been touched |
929 for (int j = lengths[i]; j < 11; j++) | 917 for (int j = lengths[i]; j < 11; j++) |
930 CHECK_EQ(kNoChar, buffer[j]); | 918 CHECK_EQ(kNoChar, buffer[j]); |
931 } | 919 } |
932 } | 920 } |
933 | 921 |
934 | 922 |
935 TEST(ExternalShortStringAdd) { | 923 TEST(ExternalShortStringAdd) { |
936 ZoneScope zonescope(Isolate::Current()->runtime_zone(), DELETE_ON_EXIT); | 924 ZoneScope zonescope(Isolate::Current()->runtime_zone(), DELETE_ON_EXIT); |
937 | 925 |
938 InitializeVM(); | 926 CcTest::InitializeVM(); |
939 v8::HandleScope handle_scope(env->GetIsolate()); | 927 v8::HandleScope handle_scope(CcTest::isolate()); |
940 Zone* zone = Isolate::Current()->runtime_zone(); | 928 Zone* zone = Isolate::Current()->runtime_zone(); |
941 | 929 |
942 // Make sure we cover all always-flat lengths and at least one above. | 930 // Make sure we cover all always-flat lengths and at least one above. |
943 static const int kMaxLength = 20; | 931 static const int kMaxLength = 20; |
944 CHECK_GT(kMaxLength, i::ConsString::kMinLength); | 932 CHECK_GT(kMaxLength, i::ConsString::kMinLength); |
945 | 933 |
946 // Allocate two JavaScript arrays for holding short strings. | 934 // Allocate two JavaScript arrays for holding short strings. |
947 v8::Handle<v8::Array> ascii_external_strings = | 935 v8::Handle<v8::Array> ascii_external_strings = |
948 v8::Array::New(kMaxLength + 1); | 936 v8::Array::New(kMaxLength + 1); |
949 v8::Handle<v8::Array> non_ascii_external_strings = | 937 v8::Handle<v8::Array> non_ascii_external_strings = |
(...skipping 20 matching lines...) Expand all Loading... |
970 // Terminating '\0' is left out on purpose. It is not required for external | 958 // Terminating '\0' is left out on purpose. It is not required for external |
971 // string data. | 959 // string data. |
972 Resource* resource = new(zone) Resource(Vector<const uc16>(non_ascii, i)); | 960 Resource* resource = new(zone) Resource(Vector<const uc16>(non_ascii, i)); |
973 v8::Local<v8::String> non_ascii_external_string = | 961 v8::Local<v8::String> non_ascii_external_string = |
974 v8::String::NewExternal(resource); | 962 v8::String::NewExternal(resource); |
975 non_ascii_external_strings->Set(v8::Integer::New(i), | 963 non_ascii_external_strings->Set(v8::Integer::New(i), |
976 non_ascii_external_string); | 964 non_ascii_external_string); |
977 } | 965 } |
978 | 966 |
979 // Add the arrays with the short external strings in the global object. | 967 // Add the arrays with the short external strings in the global object. |
980 v8::Handle<v8::Object> global = env->Global(); | 968 v8::Handle<v8::Object> global = CcTest::env()->Global(); |
981 global->Set(v8_str("external_ascii"), ascii_external_strings); | 969 global->Set(v8_str("external_ascii"), ascii_external_strings); |
982 global->Set(v8_str("external_non_ascii"), non_ascii_external_strings); | 970 global->Set(v8_str("external_non_ascii"), non_ascii_external_strings); |
983 global->Set(v8_str("max_length"), v8::Integer::New(kMaxLength)); | 971 global->Set(v8_str("max_length"), v8::Integer::New(kMaxLength)); |
984 | 972 |
985 // Add short external ascii and non-ascii strings checking the result. | 973 // Add short external ascii and non-ascii strings checking the result. |
986 static const char* source = | 974 static const char* source = |
987 "function test() {" | 975 "function test() {" |
988 " var ascii_chars = 'aaaaaaaaaaaaaaaaaaaa';" | 976 " var ascii_chars = 'aaaaaaaaaaaaaaaaaaaa';" |
989 " var non_ascii_chars = '\\u1234\\u1234\\u1234\\u1234\\u1234\\u1234\\u1234\
\u1234\\u1234\\u1234\\u1234\\u1234\\u1234\\u1234\\u1234\\u1234\\u1234\\u1234\\u1
234\\u1234';" //NOLINT | 977 " var non_ascii_chars = '\\u1234\\u1234\\u1234\\u1234\\u1234\\u1234\\u1234\
\u1234\\u1234\\u1234\\u1234\\u1234\\u1234\\u1234\\u1234\\u1234\\u1234\\u1234\\u1
234\\u1234';" //NOLINT |
990 " if (ascii_chars.length != max_length) return 1;" | 978 " if (ascii_chars.length != max_length) return 1;" |
(...skipping 29 matching lines...) Expand all Loading... |
1020 } | 1008 } |
1021 | 1009 |
1022 | 1010 |
1023 TEST(CachedHashOverflow) { | 1011 TEST(CachedHashOverflow) { |
1024 // We incorrectly allowed strings to be tagged as array indices even if their | 1012 // We incorrectly allowed strings to be tagged as array indices even if their |
1025 // values didn't fit in the hash field. | 1013 // values didn't fit in the hash field. |
1026 // See http://code.google.com/p/v8/issues/detail?id=728 | 1014 // See http://code.google.com/p/v8/issues/detail?id=728 |
1027 Isolate* isolate = Isolate::Current(); | 1015 Isolate* isolate = Isolate::Current(); |
1028 ZoneScope zone(isolate->runtime_zone(), DELETE_ON_EXIT); | 1016 ZoneScope zone(isolate->runtime_zone(), DELETE_ON_EXIT); |
1029 | 1017 |
1030 InitializeVM(); | 1018 CcTest::InitializeVM(); |
1031 v8::HandleScope handle_scope(env->GetIsolate()); | 1019 v8::HandleScope handle_scope(CcTest::isolate()); |
1032 // Lines must be executed sequentially. Combining them into one script | 1020 // Lines must be executed sequentially. Combining them into one script |
1033 // makes the bug go away. | 1021 // makes the bug go away. |
1034 const char* lines[] = { | 1022 const char* lines[] = { |
1035 "var x = [];", | 1023 "var x = [];", |
1036 "x[4] = 42;", | 1024 "x[4] = 42;", |
1037 "var s = \"1073741828\";", | 1025 "var s = \"1073741828\";", |
1038 "x[s];", | 1026 "x[s];", |
1039 "x[s] = 37;", | 1027 "x[s] = 37;", |
1040 "x[4];", | 1028 "x[4];", |
1041 "x[s];", | 1029 "x[s];", |
(...skipping 21 matching lines...) Expand all Loading... |
1063 if (result->IsNumber()) { | 1051 if (result->IsNumber()) { |
1064 CHECK_EQ(Smi::cast(results[i]->ToSmi()->ToObjectChecked())->value(), | 1052 CHECK_EQ(Smi::cast(results[i]->ToSmi()->ToObjectChecked())->value(), |
1065 result->ToInt32()->Value()); | 1053 result->ToInt32()->Value()); |
1066 } | 1054 } |
1067 } | 1055 } |
1068 } | 1056 } |
1069 | 1057 |
1070 | 1058 |
1071 TEST(SliceFromCons) { | 1059 TEST(SliceFromCons) { |
1072 FLAG_string_slices = true; | 1060 FLAG_string_slices = true; |
1073 InitializeVM(); | 1061 CcTest::InitializeVM(); |
1074 v8::HandleScope scope(env->GetIsolate()); | 1062 v8::HandleScope scope(CcTest::isolate()); |
1075 Handle<String> string = | 1063 Handle<String> string = |
1076 FACTORY->NewStringFromAscii(CStrVector("parentparentparent")); | 1064 FACTORY->NewStringFromAscii(CStrVector("parentparentparent")); |
1077 Handle<String> parent = FACTORY->NewConsString(string, string); | 1065 Handle<String> parent = FACTORY->NewConsString(string, string); |
1078 CHECK(parent->IsConsString()); | 1066 CHECK(parent->IsConsString()); |
1079 CHECK(!parent->IsFlat()); | 1067 CHECK(!parent->IsFlat()); |
1080 Handle<String> slice = FACTORY->NewSubString(parent, 1, 25); | 1068 Handle<String> slice = FACTORY->NewSubString(parent, 1, 25); |
1081 // After slicing, the original string becomes a flat cons. | 1069 // After slicing, the original string becomes a flat cons. |
1082 CHECK(parent->IsFlat()); | 1070 CHECK(parent->IsFlat()); |
1083 CHECK(slice->IsSlicedString()); | 1071 CHECK(slice->IsSlicedString()); |
1084 CHECK_EQ(SlicedString::cast(*slice)->parent(), | 1072 CHECK_EQ(SlicedString::cast(*slice)->parent(), |
(...skipping 12 matching lines...) Expand all Loading... |
1097 virtual ~AsciiVectorResource() {} | 1085 virtual ~AsciiVectorResource() {} |
1098 virtual size_t length() const { return data_.length(); } | 1086 virtual size_t length() const { return data_.length(); } |
1099 virtual const char* data() const { return data_.start(); } | 1087 virtual const char* data() const { return data_.start(); } |
1100 private: | 1088 private: |
1101 i::Vector<const char> data_; | 1089 i::Vector<const char> data_; |
1102 }; | 1090 }; |
1103 | 1091 |
1104 | 1092 |
1105 TEST(SliceFromExternal) { | 1093 TEST(SliceFromExternal) { |
1106 FLAG_string_slices = true; | 1094 FLAG_string_slices = true; |
1107 InitializeVM(); | 1095 CcTest::InitializeVM(); |
1108 v8::HandleScope scope(env->GetIsolate()); | 1096 v8::HandleScope scope(CcTest::isolate()); |
1109 AsciiVectorResource resource( | 1097 AsciiVectorResource resource( |
1110 i::Vector<const char>("abcdefghijklmnopqrstuvwxyz", 26)); | 1098 i::Vector<const char>("abcdefghijklmnopqrstuvwxyz", 26)); |
1111 Handle<String> string = FACTORY->NewExternalStringFromAscii(&resource); | 1099 Handle<String> string = FACTORY->NewExternalStringFromAscii(&resource); |
1112 CHECK(string->IsExternalString()); | 1100 CHECK(string->IsExternalString()); |
1113 Handle<String> slice = FACTORY->NewSubString(string, 1, 25); | 1101 Handle<String> slice = FACTORY->NewSubString(string, 1, 25); |
1114 CHECK(slice->IsSlicedString()); | 1102 CHECK(slice->IsSlicedString()); |
1115 CHECK(string->IsExternalString()); | 1103 CHECK(string->IsExternalString()); |
1116 CHECK_EQ(SlicedString::cast(*slice)->parent(), *string); | 1104 CHECK_EQ(SlicedString::cast(*slice)->parent(), *string); |
1117 CHECK(SlicedString::cast(*slice)->parent()->IsExternalString()); | 1105 CHECK(SlicedString::cast(*slice)->parent()->IsExternalString()); |
1118 CHECK(slice->IsFlat()); | 1106 CHECK(slice->IsFlat()); |
1119 } | 1107 } |
1120 | 1108 |
1121 | 1109 |
1122 TEST(TrivialSlice) { | 1110 TEST(TrivialSlice) { |
1123 // This tests whether a slice that contains the entire parent string | 1111 // This tests whether a slice that contains the entire parent string |
1124 // actually creates a new string (it should not). | 1112 // actually creates a new string (it should not). |
1125 FLAG_string_slices = true; | 1113 FLAG_string_slices = true; |
1126 InitializeVM(); | 1114 CcTest::InitializeVM(); |
1127 v8::HandleScope scope(env->GetIsolate()); | 1115 v8::HandleScope scope(CcTest::isolate()); |
1128 v8::Local<v8::Value> result; | 1116 v8::Local<v8::Value> result; |
1129 Handle<String> string; | 1117 Handle<String> string; |
1130 const char* init = "var str = 'abcdefghijklmnopqrstuvwxyz';"; | 1118 const char* init = "var str = 'abcdefghijklmnopqrstuvwxyz';"; |
1131 const char* check = "str.slice(0,26)"; | 1119 const char* check = "str.slice(0,26)"; |
1132 const char* crosscheck = "str.slice(1,25)"; | 1120 const char* crosscheck = "str.slice(1,25)"; |
1133 | 1121 |
1134 CompileRun(init); | 1122 CompileRun(init); |
1135 | 1123 |
1136 result = CompileRun(check); | 1124 result = CompileRun(check); |
1137 CHECK(result->IsString()); | 1125 CHECK(result->IsString()); |
1138 string = v8::Utils::OpenHandle(v8::String::Cast(*result)); | 1126 string = v8::Utils::OpenHandle(v8::String::Cast(*result)); |
1139 CHECK(!string->IsSlicedString()); | 1127 CHECK(!string->IsSlicedString()); |
1140 | 1128 |
1141 string = FACTORY->NewSubString(string, 0, 26); | 1129 string = FACTORY->NewSubString(string, 0, 26); |
1142 CHECK(!string->IsSlicedString()); | 1130 CHECK(!string->IsSlicedString()); |
1143 result = CompileRun(crosscheck); | 1131 result = CompileRun(crosscheck); |
1144 CHECK(result->IsString()); | 1132 CHECK(result->IsString()); |
1145 string = v8::Utils::OpenHandle(v8::String::Cast(*result)); | 1133 string = v8::Utils::OpenHandle(v8::String::Cast(*result)); |
1146 CHECK(string->IsSlicedString()); | 1134 CHECK(string->IsSlicedString()); |
1147 CHECK_EQ("bcdefghijklmnopqrstuvwxy", *(string->ToCString())); | 1135 CHECK_EQ("bcdefghijklmnopqrstuvwxy", *(string->ToCString())); |
1148 } | 1136 } |
1149 | 1137 |
1150 | 1138 |
1151 TEST(SliceFromSlice) { | 1139 TEST(SliceFromSlice) { |
1152 // This tests whether a slice that contains the entire parent string | 1140 // This tests whether a slice that contains the entire parent string |
1153 // actually creates a new string (it should not). | 1141 // actually creates a new string (it should not). |
1154 FLAG_string_slices = true; | 1142 FLAG_string_slices = true; |
1155 InitializeVM(); | 1143 CcTest::InitializeVM(); |
1156 v8::HandleScope scope(env->GetIsolate()); | 1144 v8::HandleScope scope(CcTest::isolate()); |
1157 v8::Local<v8::Value> result; | 1145 v8::Local<v8::Value> result; |
1158 Handle<String> string; | 1146 Handle<String> string; |
1159 const char* init = "var str = 'abcdefghijklmnopqrstuvwxyz';"; | 1147 const char* init = "var str = 'abcdefghijklmnopqrstuvwxyz';"; |
1160 const char* slice = "var slice = str.slice(1,-1); slice"; | 1148 const char* slice = "var slice = str.slice(1,-1); slice"; |
1161 const char* slice_from_slice = "slice.slice(1,-1);"; | 1149 const char* slice_from_slice = "slice.slice(1,-1);"; |
1162 | 1150 |
1163 CompileRun(init); | 1151 CompileRun(init); |
1164 result = CompileRun(slice); | 1152 result = CompileRun(slice); |
1165 CHECK(result->IsString()); | 1153 CHECK(result->IsString()); |
1166 string = v8::Utils::OpenHandle(v8::String::Cast(*result)); | 1154 string = v8::Utils::OpenHandle(v8::String::Cast(*result)); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1213 static void CheckException(const char* source) { | 1201 static void CheckException(const char* source) { |
1214 // An empty handle is returned upon exception. | 1202 // An empty handle is returned upon exception. |
1215 CHECK(CompileRun(source).IsEmpty()); | 1203 CHECK(CompileRun(source).IsEmpty()); |
1216 } | 1204 } |
1217 | 1205 |
1218 | 1206 |
1219 TEST(RobustSubStringStub) { | 1207 TEST(RobustSubStringStub) { |
1220 // This tests whether the SubStringStub can handle unsafe arguments. | 1208 // This tests whether the SubStringStub can handle unsafe arguments. |
1221 // If not recognized, those unsafe arguments lead to out-of-bounds reads. | 1209 // If not recognized, those unsafe arguments lead to out-of-bounds reads. |
1222 FLAG_allow_natives_syntax = true; | 1210 FLAG_allow_natives_syntax = true; |
1223 InitializeVM(); | 1211 CcTest::InitializeVM(); |
1224 v8::HandleScope scope(env->GetIsolate()); | 1212 v8::HandleScope scope(CcTest::isolate()); |
1225 v8::Local<v8::Value> result; | 1213 v8::Local<v8::Value> result; |
1226 Handle<String> string; | 1214 Handle<String> string; |
1227 CompileRun("var short = 'abcdef';"); | 1215 CompileRun("var short = 'abcdef';"); |
1228 | 1216 |
1229 // Invalid indices. | 1217 // Invalid indices. |
1230 CheckException("%_SubString(short, 0, 10000);"); | 1218 CheckException("%_SubString(short, 0, 10000);"); |
1231 CheckException("%_SubString(short, -1234, 5);"); | 1219 CheckException("%_SubString(short, -1234, 5);"); |
1232 CheckException("%_SubString(short, 5, 2);"); | 1220 CheckException("%_SubString(short, 5, 2);"); |
1233 // Special HeapNumbers. | 1221 // Special HeapNumbers. |
1234 CheckException("%_SubString(short, 1, Infinity);"); | 1222 CheckException("%_SubString(short, 1, Infinity);"); |
(...skipping 22 matching lines...) Expand all Loading... |
1257 | 1245 |
1258 // Test that out-of-bounds substring of a slice fails when the indices | 1246 // Test that out-of-bounds substring of a slice fails when the indices |
1259 // would have been valid for the underlying string. | 1247 // would have been valid for the underlying string. |
1260 CompileRun("var slice = long.slice(1, 15);"); | 1248 CompileRun("var slice = long.slice(1, 15);"); |
1261 CheckException("%_SubString(slice, 0, 17);"); | 1249 CheckException("%_SubString(slice, 0, 17);"); |
1262 } | 1250 } |
1263 | 1251 |
1264 | 1252 |
1265 TEST(RegExpOverflow) { | 1253 TEST(RegExpOverflow) { |
1266 // Result string has the length 2^32, causing a 32-bit integer overflow. | 1254 // Result string has the length 2^32, causing a 32-bit integer overflow. |
1267 InitializeVM(); | 1255 CcTest::InitializeVM(); |
1268 v8::HandleScope scope(env->GetIsolate()); | 1256 v8::HandleScope scope(CcTest::isolate()); |
1269 LocalContext context; | 1257 LocalContext context; |
1270 v8::V8::IgnoreOutOfMemoryException(); | 1258 v8::V8::IgnoreOutOfMemoryException(); |
1271 v8::Local<v8::Value> result = CompileRun( | 1259 v8::Local<v8::Value> result = CompileRun( |
1272 "var a = 'a'; " | 1260 "var a = 'a'; " |
1273 "for (var i = 0; i < 16; i++) { " | 1261 "for (var i = 0; i < 16; i++) { " |
1274 " a += a; " | 1262 " a += a; " |
1275 "} " | 1263 "} " |
1276 "a.replace(/a/g, a); "); | 1264 "a.replace(/a/g, a); "); |
1277 CHECK(result.IsEmpty()); | 1265 CHECK(result.IsEmpty()); |
1278 CHECK(context->HasOutOfMemoryException()); | 1266 CHECK(context->HasOutOfMemoryException()); |
1279 } | 1267 } |
1280 | 1268 |
1281 | 1269 |
1282 TEST(StringReplaceAtomTwoByteResult) { | 1270 TEST(StringReplaceAtomTwoByteResult) { |
1283 InitializeVM(); | 1271 CcTest::InitializeVM(); |
1284 v8::HandleScope scope(env->GetIsolate()); | 1272 v8::HandleScope scope(CcTest::isolate()); |
1285 LocalContext context; | 1273 LocalContext context; |
1286 v8::Local<v8::Value> result = CompileRun( | 1274 v8::Local<v8::Value> result = CompileRun( |
1287 "var subject = 'ascii~only~string~'; " | 1275 "var subject = 'ascii~only~string~'; " |
1288 "var replace = '\x80'; " | 1276 "var replace = '\x80'; " |
1289 "subject.replace(/~/g, replace); "); | 1277 "subject.replace(/~/g, replace); "); |
1290 CHECK(result->IsString()); | 1278 CHECK(result->IsString()); |
1291 Handle<String> string = v8::Utils::OpenHandle(v8::String::Cast(*result)); | 1279 Handle<String> string = v8::Utils::OpenHandle(v8::String::Cast(*result)); |
1292 CHECK(string->IsSeqTwoByteString()); | 1280 CHECK(string->IsSeqTwoByteString()); |
1293 | 1281 |
1294 v8::Local<v8::String> expected = v8_str("ascii\x80only\x80string\x80"); | 1282 v8::Local<v8::String> expected = v8_str("ascii\x80only\x80string\x80"); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1349 CheckCanonicalEquivalence(c, test); | 1337 CheckCanonicalEquivalence(c, test); |
1350 continue; | 1338 continue; |
1351 } | 1339 } |
1352 if (upper != c && lower != c) { | 1340 if (upper != c && lower != c) { |
1353 CheckCanonicalEquivalence(c, test); | 1341 CheckCanonicalEquivalence(c, test); |
1354 continue; | 1342 continue; |
1355 } | 1343 } |
1356 CHECK_EQ(Min(upper, lower), test); | 1344 CHECK_EQ(Min(upper, lower), test); |
1357 } | 1345 } |
1358 } | 1346 } |
OLD | NEW |