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 1020 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1031 CHECK(v8::Utils::OpenHandle(*underlying)->IsSeqOneByteString()); | 1031 CHECK(v8::Utils::OpenHandle(*underlying)->IsSeqOneByteString()); |
1032 | 1032 |
1033 int length = underlying->Length(); | 1033 int length = underlying->Length(); |
1034 uc16* two_byte = NewArray<uc16>(length + 1); | 1034 uc16* two_byte = NewArray<uc16>(length + 1); |
1035 underlying->Write(two_byte); | 1035 underlying->Write(two_byte); |
1036 Resource* resource = new Resource(two_byte, length); | 1036 Resource* resource = new Resource(two_byte, length); |
1037 CHECK(underlying->MakeExternal(resource)); | 1037 CHECK(underlying->MakeExternal(resource)); |
1038 CHECK(v8::Utils::OpenHandle(*slice)->IsSlicedString()); | 1038 CHECK(v8::Utils::OpenHandle(*slice)->IsSlicedString()); |
1039 CHECK(v8::Utils::OpenHandle(*underlying)->IsExternalTwoByteString()); | 1039 CHECK(v8::Utils::OpenHandle(*underlying)->IsExternalTwoByteString()); |
1040 | 1040 |
1041 CHECK_EQ("\"bcdefghijklmnopqrstuvwxyz\"", | 1041 CHECK_EQ(0, |
1042 *v8::String::Utf8Value(CompileRun("JSON.stringify(slice)"))); | 1042 strcmp("\"bcdefghijklmnopqrstuvwxyz\"", |
| 1043 *v8::String::Utf8Value(CompileRun("JSON.stringify(slice)")))); |
1043 } | 1044 } |
1044 | 1045 |
1045 | 1046 |
1046 TEST(CachedHashOverflow) { | 1047 TEST(CachedHashOverflow) { |
1047 CcTest::InitializeVM(); | 1048 CcTest::InitializeVM(); |
1048 // We incorrectly allowed strings to be tagged as array indices even if their | 1049 // We incorrectly allowed strings to be tagged as array indices even if their |
1049 // values didn't fit in the hash field. | 1050 // values didn't fit in the hash field. |
1050 // See http://code.google.com/p/v8/issues/detail?id=728 | 1051 // See http://code.google.com/p/v8/issues/detail?id=728 |
1051 Isolate* isolate = CcTest::i_isolate(); | 1052 Isolate* isolate = CcTest::i_isolate(); |
1052 | 1053 |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1164 CHECK(result->IsString()); | 1165 CHECK(result->IsString()); |
1165 string = v8::Utils::OpenHandle(v8::String::Cast(*result)); | 1166 string = v8::Utils::OpenHandle(v8::String::Cast(*result)); |
1166 CHECK(!string->IsSlicedString()); | 1167 CHECK(!string->IsSlicedString()); |
1167 | 1168 |
1168 string = factory->NewSubString(string, 0, 26); | 1169 string = factory->NewSubString(string, 0, 26); |
1169 CHECK(!string->IsSlicedString()); | 1170 CHECK(!string->IsSlicedString()); |
1170 result = CompileRun(crosscheck); | 1171 result = CompileRun(crosscheck); |
1171 CHECK(result->IsString()); | 1172 CHECK(result->IsString()); |
1172 string = v8::Utils::OpenHandle(v8::String::Cast(*result)); | 1173 string = v8::Utils::OpenHandle(v8::String::Cast(*result)); |
1173 CHECK(string->IsSlicedString()); | 1174 CHECK(string->IsSlicedString()); |
1174 CHECK_EQ("bcdefghijklmnopqrstuvwxy", string->ToCString().get()); | 1175 CHECK_EQ(0, strcmp("bcdefghijklmnopqrstuvwxy", string->ToCString().get())); |
1175 } | 1176 } |
1176 | 1177 |
1177 | 1178 |
1178 TEST(SliceFromSlice) { | 1179 TEST(SliceFromSlice) { |
1179 // This tests whether a slice that contains the entire parent string | 1180 // This tests whether a slice that contains the entire parent string |
1180 // actually creates a new string (it should not). | 1181 // actually creates a new string (it should not). |
1181 FLAG_string_slices = true; | 1182 FLAG_string_slices = true; |
1182 CcTest::InitializeVM(); | 1183 CcTest::InitializeVM(); |
1183 v8::HandleScope scope(CcTest::isolate()); | 1184 v8::HandleScope scope(CcTest::isolate()); |
1184 v8::Local<v8::Value> result; | 1185 v8::Local<v8::Value> result; |
1185 Handle<String> string; | 1186 Handle<String> string; |
1186 const char* init = "var str = 'abcdefghijklmnopqrstuvwxyz';"; | 1187 const char* init = "var str = 'abcdefghijklmnopqrstuvwxyz';"; |
1187 const char* slice = "var slice = ''; slice = str.slice(1,-1); slice"; | 1188 const char* slice = "var slice = ''; slice = str.slice(1,-1); slice"; |
1188 const char* slice_from_slice = "slice.slice(1,-1);"; | 1189 const char* slice_from_slice = "slice.slice(1,-1);"; |
1189 | 1190 |
1190 CompileRun(init); | 1191 CompileRun(init); |
1191 result = CompileRun(slice); | 1192 result = CompileRun(slice); |
1192 CHECK(result->IsString()); | 1193 CHECK(result->IsString()); |
1193 string = v8::Utils::OpenHandle(v8::String::Cast(*result)); | 1194 string = v8::Utils::OpenHandle(v8::String::Cast(*result)); |
1194 CHECK(string->IsSlicedString()); | 1195 CHECK(string->IsSlicedString()); |
1195 CHECK(SlicedString::cast(*string)->parent()->IsSeqString()); | 1196 CHECK(SlicedString::cast(*string)->parent()->IsSeqString()); |
1196 CHECK_EQ("bcdefghijklmnopqrstuvwxy", string->ToCString().get()); | 1197 CHECK_EQ(0, strcmp("bcdefghijklmnopqrstuvwxy", string->ToCString().get())); |
1197 | 1198 |
1198 result = CompileRun(slice_from_slice); | 1199 result = CompileRun(slice_from_slice); |
1199 CHECK(result->IsString()); | 1200 CHECK(result->IsString()); |
1200 string = v8::Utils::OpenHandle(v8::String::Cast(*result)); | 1201 string = v8::Utils::OpenHandle(v8::String::Cast(*result)); |
1201 CHECK(string->IsSlicedString()); | 1202 CHECK(string->IsSlicedString()); |
1202 CHECK(SlicedString::cast(*string)->parent()->IsSeqString()); | 1203 CHECK(SlicedString::cast(*string)->parent()->IsSeqString()); |
1203 CHECK_EQ("cdefghijklmnopqrstuvwx", string->ToCString().get()); | 1204 CHECK_EQ(0, strcmp("cdefghijklmnopqrstuvwx", string->ToCString().get())); |
1204 } | 1205 } |
1205 | 1206 |
1206 | 1207 |
1207 UNINITIALIZED_TEST(OneByteArrayJoin) { | 1208 UNINITIALIZED_TEST(OneByteArrayJoin) { |
1208 v8::Isolate::CreateParams create_params; | 1209 v8::Isolate::CreateParams create_params; |
1209 // Set heap limits. | 1210 // Set heap limits. |
1210 create_params.constraints.set_max_semi_space_size(1); | 1211 create_params.constraints.set_max_semi_space_size(1); |
1211 create_params.constraints.set_max_old_space_size(4); | 1212 create_params.constraints.set_max_old_space_size(4); |
1212 v8::Isolate* isolate = v8::Isolate::New(create_params); | 1213 v8::Isolate* isolate = v8::Isolate::New(create_params); |
1213 isolate->Enter(); | 1214 isolate->Enter(); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1256 CheckException("%_SubString(short, -1234, 5);"); | 1257 CheckException("%_SubString(short, -1234, 5);"); |
1257 CheckException("%_SubString(short, 5, 2);"); | 1258 CheckException("%_SubString(short, 5, 2);"); |
1258 // Special HeapNumbers. | 1259 // Special HeapNumbers. |
1259 CheckException("%_SubString(short, 1, Infinity);"); | 1260 CheckException("%_SubString(short, 1, Infinity);"); |
1260 CheckException("%_SubString(short, NaN, 5);"); | 1261 CheckException("%_SubString(short, NaN, 5);"); |
1261 // String arguments. | 1262 // String arguments. |
1262 CheckException("%_SubString(short, '2', '5');"); | 1263 CheckException("%_SubString(short, '2', '5');"); |
1263 // Ordinary HeapNumbers can be handled (in runtime). | 1264 // Ordinary HeapNumbers can be handled (in runtime). |
1264 result = CompileRun("%_SubString(short, Math.sqrt(4), 5.1);"); | 1265 result = CompileRun("%_SubString(short, Math.sqrt(4), 5.1);"); |
1265 string = v8::Utils::OpenHandle(v8::String::Cast(*result)); | 1266 string = v8::Utils::OpenHandle(v8::String::Cast(*result)); |
1266 CHECK_EQ("cde", string->ToCString().get()); | 1267 CHECK_EQ(0, strcmp("cde", string->ToCString().get())); |
1267 | 1268 |
1268 CompileRun("var long = 'abcdefghijklmnopqrstuvwxyz';"); | 1269 CompileRun("var long = 'abcdefghijklmnopqrstuvwxyz';"); |
1269 // Invalid indices. | 1270 // Invalid indices. |
1270 CheckException("%_SubString(long, 0, 10000);"); | 1271 CheckException("%_SubString(long, 0, 10000);"); |
1271 CheckException("%_SubString(long, -1234, 17);"); | 1272 CheckException("%_SubString(long, -1234, 17);"); |
1272 CheckException("%_SubString(long, 17, 2);"); | 1273 CheckException("%_SubString(long, 17, 2);"); |
1273 // Special HeapNumbers. | 1274 // Special HeapNumbers. |
1274 CheckException("%_SubString(long, 1, Infinity);"); | 1275 CheckException("%_SubString(long, 1, Infinity);"); |
1275 CheckException("%_SubString(long, NaN, 17);"); | 1276 CheckException("%_SubString(long, NaN, 17);"); |
1276 // String arguments. | 1277 // String arguments. |
1277 CheckException("%_SubString(long, '2', '17');"); | 1278 CheckException("%_SubString(long, '2', '17');"); |
1278 // Ordinary HeapNumbers within bounds can be handled (in runtime). | 1279 // Ordinary HeapNumbers within bounds can be handled (in runtime). |
1279 result = CompileRun("%_SubString(long, Math.sqrt(4), 17.1);"); | 1280 result = CompileRun("%_SubString(long, Math.sqrt(4), 17.1);"); |
1280 string = v8::Utils::OpenHandle(v8::String::Cast(*result)); | 1281 string = v8::Utils::OpenHandle(v8::String::Cast(*result)); |
1281 CHECK_EQ("cdefghijklmnopq", string->ToCString().get()); | 1282 CHECK_EQ(0, strcmp("cdefghijklmnopq", string->ToCString().get())); |
1282 | 1283 |
1283 // Test that out-of-bounds substring of a slice fails when the indices | 1284 // Test that out-of-bounds substring of a slice fails when the indices |
1284 // would have been valid for the underlying string. | 1285 // would have been valid for the underlying string. |
1285 CompileRun("var slice = long.slice(1, 15);"); | 1286 CompileRun("var slice = long.slice(1, 15);"); |
1286 CheckException("%_SubString(slice, 0, 17);"); | 1287 CheckException("%_SubString(slice, 0, 17);"); |
1287 } | 1288 } |
1288 | 1289 |
1289 | 1290 |
1290 namespace { | 1291 namespace { |
1291 | 1292 |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1451 CHECK(isolate->has_pending_exception()); \ | 1452 CHECK(isolate->has_pending_exception()); \ |
1452 isolate->clear_pending_exception(); \ | 1453 isolate->clear_pending_exception(); \ |
1453 dummy.Dispose(); \ | 1454 dummy.Dispose(); \ |
1454 } | 1455 } |
1455 | 1456 |
1456 INVALID_STRING_TEST(NewStringFromAscii, char) | 1457 INVALID_STRING_TEST(NewStringFromAscii, char) |
1457 INVALID_STRING_TEST(NewStringFromUtf8, char) | 1458 INVALID_STRING_TEST(NewStringFromUtf8, char) |
1458 INVALID_STRING_TEST(NewStringFromOneByte, uint8_t) | 1459 INVALID_STRING_TEST(NewStringFromOneByte, uint8_t) |
1459 | 1460 |
1460 #undef INVALID_STRING_TEST | 1461 #undef INVALID_STRING_TEST |
OLD | NEW |