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

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

Issue 112863002: Merge bleeding_edge 18021:18297 (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: Created 7 years 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-representation.cc ('k') | test/cctest/test-weaktypedarrays.cc » ('j') | 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 925 matching lines...) Expand 10 before | Expand all | Expand 10 after
936 936
937 LocalContext context; 937 LocalContext context;
938 v8::HandleScope handle_scope(CcTest::isolate()); 938 v8::HandleScope handle_scope(CcTest::isolate());
939 939
940 // Make sure we cover all always-flat lengths and at least one above. 940 // Make sure we cover all always-flat lengths and at least one above.
941 static const int kMaxLength = 20; 941 static const int kMaxLength = 20;
942 CHECK_GT(kMaxLength, i::ConsString::kMinLength); 942 CHECK_GT(kMaxLength, i::ConsString::kMinLength);
943 943
944 // Allocate two JavaScript arrays for holding short strings. 944 // Allocate two JavaScript arrays for holding short strings.
945 v8::Handle<v8::Array> ascii_external_strings = 945 v8::Handle<v8::Array> ascii_external_strings =
946 v8::Array::New(kMaxLength + 1); 946 v8::Array::New(CcTest::isolate(), kMaxLength + 1);
947 v8::Handle<v8::Array> non_ascii_external_strings = 947 v8::Handle<v8::Array> non_ascii_external_strings =
948 v8::Array::New(kMaxLength + 1); 948 v8::Array::New(CcTest::isolate(), kMaxLength + 1);
949 949
950 // Generate short ascii and non-ascii external strings. 950 // Generate short ascii and non-ascii external strings.
951 for (int i = 0; i <= kMaxLength; i++) { 951 for (int i = 0; i <= kMaxLength; i++) {
952 char* ascii = zone.NewArray<char>(i + 1); 952 char* ascii = zone.NewArray<char>(i + 1);
953 for (int j = 0; j < i; j++) { 953 for (int j = 0; j < i; j++) {
954 ascii[j] = 'a'; 954 ascii[j] = 'a';
955 } 955 }
956 // Terminating '\0' is left out on purpose. It is not required for external 956 // Terminating '\0' is left out on purpose. It is not required for external
957 // string data. 957 // string data.
958 AsciiResource* ascii_resource = 958 AsciiResource* ascii_resource =
959 new(&zone) AsciiResource(Vector<const char>(ascii, i)); 959 new(&zone) AsciiResource(Vector<const char>(ascii, i));
960 v8::Local<v8::String> ascii_external_string = 960 v8::Local<v8::String> ascii_external_string =
961 v8::String::NewExternal(ascii_resource); 961 v8::String::NewExternal(CcTest::isolate(), ascii_resource);
962 962
963 ascii_external_strings->Set(v8::Integer::New(i), ascii_external_string); 963 ascii_external_strings->Set(v8::Integer::New(i), ascii_external_string);
964 uc16* non_ascii = zone.NewArray<uc16>(i + 1); 964 uc16* non_ascii = zone.NewArray<uc16>(i + 1);
965 for (int j = 0; j < i; j++) { 965 for (int j = 0; j < i; j++) {
966 non_ascii[j] = 0x1234; 966 non_ascii[j] = 0x1234;
967 } 967 }
968 // Terminating '\0' is left out on purpose. It is not required for external 968 // Terminating '\0' is left out on purpose. It is not required for external
969 // string data. 969 // string data.
970 Resource* resource = new(&zone) Resource(Vector<const uc16>(non_ascii, i)); 970 Resource* resource = new(&zone) Resource(Vector<const uc16>(non_ascii, i));
971 v8::Local<v8::String> non_ascii_external_string = 971 v8::Local<v8::String> non_ascii_external_string =
972 v8::String::NewExternal(resource); 972 v8::String::NewExternal(CcTest::isolate(), resource);
973 non_ascii_external_strings->Set(v8::Integer::New(i), 973 non_ascii_external_strings->Set(v8::Integer::New(i),
974 non_ascii_external_string); 974 non_ascii_external_string);
975 } 975 }
976 976
977 // Add the arrays with the short external strings in the global object. 977 // Add the arrays with the short external strings in the global object.
978 v8::Handle<v8::Object> global = context->Global(); 978 v8::Handle<v8::Object> global = context->Global();
979 global->Set(v8_str("external_ascii"), ascii_external_strings); 979 global->Set(v8_str("external_ascii"), ascii_external_strings);
980 global->Set(v8_str("external_non_ascii"), non_ascii_external_strings); 980 global->Set(v8_str("external_non_ascii"), non_ascii_external_strings);
981 global->Set(v8_str("max_length"), v8::Integer::New(kMaxLength)); 981 global->Set(v8_str("max_length"), v8::Integer::New(kMaxLength));
982 982
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
1168 CHECK(result->IsString()); 1168 CHECK(result->IsString());
1169 string = v8::Utils::OpenHandle(v8::String::Cast(*result)); 1169 string = v8::Utils::OpenHandle(v8::String::Cast(*result));
1170 CHECK(!string->IsSlicedString()); 1170 CHECK(!string->IsSlicedString());
1171 1171
1172 string = factory->NewSubString(string, 0, 26); 1172 string = factory->NewSubString(string, 0, 26);
1173 CHECK(!string->IsSlicedString()); 1173 CHECK(!string->IsSlicedString());
1174 result = CompileRun(crosscheck); 1174 result = CompileRun(crosscheck);
1175 CHECK(result->IsString()); 1175 CHECK(result->IsString());
1176 string = v8::Utils::OpenHandle(v8::String::Cast(*result)); 1176 string = v8::Utils::OpenHandle(v8::String::Cast(*result));
1177 CHECK(string->IsSlicedString()); 1177 CHECK(string->IsSlicedString());
1178 CHECK_EQ("bcdefghijklmnopqrstuvwxy", *(string->ToCString())); 1178 CHECK_EQ("bcdefghijklmnopqrstuvwxy", string->ToCString().get());
1179 } 1179 }
1180 1180
1181 1181
1182 TEST(SliceFromSlice) { 1182 TEST(SliceFromSlice) {
1183 // This tests whether a slice that contains the entire parent string 1183 // This tests whether a slice that contains the entire parent string
1184 // actually creates a new string (it should not). 1184 // actually creates a new string (it should not).
1185 FLAG_string_slices = true; 1185 FLAG_string_slices = true;
1186 CcTest::InitializeVM(); 1186 CcTest::InitializeVM();
1187 v8::HandleScope scope(CcTest::isolate()); 1187 v8::HandleScope scope(CcTest::isolate());
1188 v8::Local<v8::Value> result; 1188 v8::Local<v8::Value> result;
1189 Handle<String> string; 1189 Handle<String> string;
1190 const char* init = "var str = 'abcdefghijklmnopqrstuvwxyz';"; 1190 const char* init = "var str = 'abcdefghijklmnopqrstuvwxyz';";
1191 const char* slice = "var slice = str.slice(1,-1); slice"; 1191 const char* slice = "var slice = str.slice(1,-1); slice";
1192 const char* slice_from_slice = "slice.slice(1,-1);"; 1192 const char* slice_from_slice = "slice.slice(1,-1);";
1193 1193
1194 CompileRun(init); 1194 CompileRun(init);
1195 result = CompileRun(slice); 1195 result = CompileRun(slice);
1196 CHECK(result->IsString()); 1196 CHECK(result->IsString());
1197 string = v8::Utils::OpenHandle(v8::String::Cast(*result)); 1197 string = v8::Utils::OpenHandle(v8::String::Cast(*result));
1198 CHECK(string->IsSlicedString()); 1198 CHECK(string->IsSlicedString());
1199 CHECK(SlicedString::cast(*string)->parent()->IsSeqString()); 1199 CHECK(SlicedString::cast(*string)->parent()->IsSeqString());
1200 CHECK_EQ("bcdefghijklmnopqrstuvwxy", *(string->ToCString())); 1200 CHECK_EQ("bcdefghijklmnopqrstuvwxy", string->ToCString().get());
1201 1201
1202 result = CompileRun(slice_from_slice); 1202 result = CompileRun(slice_from_slice);
1203 CHECK(result->IsString()); 1203 CHECK(result->IsString());
1204 string = v8::Utils::OpenHandle(v8::String::Cast(*result)); 1204 string = v8::Utils::OpenHandle(v8::String::Cast(*result));
1205 CHECK(string->IsSlicedString()); 1205 CHECK(string->IsSlicedString());
1206 CHECK(SlicedString::cast(*string)->parent()->IsSeqString()); 1206 CHECK(SlicedString::cast(*string)->parent()->IsSeqString());
1207 CHECK_EQ("cdefghijklmnopqrstuvwx", *(string->ToCString())); 1207 CHECK_EQ("cdefghijklmnopqrstuvwx", string->ToCString().get());
1208 } 1208 }
1209 1209
1210 1210
1211 TEST(AsciiArrayJoin) { 1211 TEST(AsciiArrayJoin) {
1212 // Set heap limits. 1212 // Set heap limits.
1213 static const int K = 1024; 1213 static const int K = 1024;
1214 v8::ResourceConstraints constraints; 1214 v8::ResourceConstraints constraints;
1215 constraints.set_max_young_space_size(256 * K); 1215 constraints.set_max_young_space_size(256 * K);
1216 constraints.set_max_old_space_size(4 * K * K); 1216 constraints.set_max_old_space_size(4 * K * K);
1217 v8::SetResourceConstraints(CcTest::isolate(), &constraints); 1217 v8::SetResourceConstraints(CcTest::isolate(), &constraints);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1262 CheckException("%_SubString(short, -1234, 5);"); 1262 CheckException("%_SubString(short, -1234, 5);");
1263 CheckException("%_SubString(short, 5, 2);"); 1263 CheckException("%_SubString(short, 5, 2);");
1264 // Special HeapNumbers. 1264 // Special HeapNumbers.
1265 CheckException("%_SubString(short, 1, Infinity);"); 1265 CheckException("%_SubString(short, 1, Infinity);");
1266 CheckException("%_SubString(short, NaN, 5);"); 1266 CheckException("%_SubString(short, NaN, 5);");
1267 // String arguments. 1267 // String arguments.
1268 CheckException("%_SubString(short, '2', '5');"); 1268 CheckException("%_SubString(short, '2', '5');");
1269 // Ordinary HeapNumbers can be handled (in runtime). 1269 // Ordinary HeapNumbers can be handled (in runtime).
1270 result = CompileRun("%_SubString(short, Math.sqrt(4), 5.1);"); 1270 result = CompileRun("%_SubString(short, Math.sqrt(4), 5.1);");
1271 string = v8::Utils::OpenHandle(v8::String::Cast(*result)); 1271 string = v8::Utils::OpenHandle(v8::String::Cast(*result));
1272 CHECK_EQ("cde", *(string->ToCString())); 1272 CHECK_EQ("cde", string->ToCString().get());
1273 1273
1274 CompileRun("var long = 'abcdefghijklmnopqrstuvwxyz';"); 1274 CompileRun("var long = 'abcdefghijklmnopqrstuvwxyz';");
1275 // Invalid indices. 1275 // Invalid indices.
1276 CheckException("%_SubString(long, 0, 10000);"); 1276 CheckException("%_SubString(long, 0, 10000);");
1277 CheckException("%_SubString(long, -1234, 17);"); 1277 CheckException("%_SubString(long, -1234, 17);");
1278 CheckException("%_SubString(long, 17, 2);"); 1278 CheckException("%_SubString(long, 17, 2);");
1279 // Special HeapNumbers. 1279 // Special HeapNumbers.
1280 CheckException("%_SubString(long, 1, Infinity);"); 1280 CheckException("%_SubString(long, 1, Infinity);");
1281 CheckException("%_SubString(long, NaN, 17);"); 1281 CheckException("%_SubString(long, NaN, 17);");
1282 // String arguments. 1282 // String arguments.
1283 CheckException("%_SubString(long, '2', '17');"); 1283 CheckException("%_SubString(long, '2', '17');");
1284 // Ordinary HeapNumbers within bounds can be handled (in runtime). 1284 // Ordinary HeapNumbers within bounds can be handled (in runtime).
1285 result = CompileRun("%_SubString(long, Math.sqrt(4), 17.1);"); 1285 result = CompileRun("%_SubString(long, Math.sqrt(4), 17.1);");
1286 string = v8::Utils::OpenHandle(v8::String::Cast(*result)); 1286 string = v8::Utils::OpenHandle(v8::String::Cast(*result));
1287 CHECK_EQ("cdefghijklmnopq", *(string->ToCString())); 1287 CHECK_EQ("cdefghijklmnopq", string->ToCString().get());
1288 1288
1289 // Test that out-of-bounds substring of a slice fails when the indices 1289 // Test that out-of-bounds substring of a slice fails when the indices
1290 // would have been valid for the underlying string. 1290 // would have been valid for the underlying string.
1291 CompileRun("var slice = long.slice(1, 15);"); 1291 CompileRun("var slice = long.slice(1, 15);");
1292 CheckException("%_SubString(slice, 0, 17);"); 1292 CheckException("%_SubString(slice, 0, 17);");
1293 } 1293 }
1294 1294
1295 1295
1296 TEST(RegExpOverflow) { 1296 TEST(RegExpOverflow) {
1297 // Result string has the length 2^32, causing a 32-bit integer overflow. 1297 // Result string has the length 2^32, causing a 32-bit integer overflow.
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1380 CheckCanonicalEquivalence(c, test); 1380 CheckCanonicalEquivalence(c, test);
1381 continue; 1381 continue;
1382 } 1382 }
1383 if (upper != c && lower != c) { 1383 if (upper != c && lower != c) {
1384 CheckCanonicalEquivalence(c, test); 1384 CheckCanonicalEquivalence(c, test);
1385 continue; 1385 continue;
1386 } 1386 }
1387 CHECK_EQ(Min(upper, lower), test); 1387 CHECK_EQ(Min(upper, lower), test);
1388 } 1388 }
1389 } 1389 }
OLDNEW
« no previous file with comments | « test/cctest/test-representation.cc ('k') | test/cctest/test-weaktypedarrays.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698