| 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 1257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1268 string = v8::Utils::OpenHandle(v8::String::Cast(*result)); | 1268 string = v8::Utils::OpenHandle(v8::String::Cast(*result)); |
| 1269 CHECK_EQ("cdefghijklmnopq", string->ToCString().get()); | 1269 CHECK_EQ("cdefghijklmnopq", string->ToCString().get()); |
| 1270 | 1270 |
| 1271 // Test that out-of-bounds substring of a slice fails when the indices | 1271 // Test that out-of-bounds substring of a slice fails when the indices |
| 1272 // would have been valid for the underlying string. | 1272 // would have been valid for the underlying string. |
| 1273 CompileRun("var slice = long.slice(1, 15);"); | 1273 CompileRun("var slice = long.slice(1, 15);"); |
| 1274 CheckException("%_SubString(slice, 0, 17);"); | 1274 CheckException("%_SubString(slice, 0, 17);"); |
| 1275 } | 1275 } |
| 1276 | 1276 |
| 1277 | 1277 |
| 1278 TEST(RegExpOverflow) { | |
| 1279 // Result string has the length 2^32, causing a 32-bit integer overflow. | |
| 1280 CcTest::InitializeVM(); | |
| 1281 v8::HandleScope scope(CcTest::isolate()); | |
| 1282 LocalContext context; | |
| 1283 v8::V8::IgnoreOutOfMemoryException(); | |
| 1284 v8::Local<v8::Value> result = CompileRun( | |
| 1285 "var a = 'a'; " | |
| 1286 "for (var i = 0; i < 16; i++) { " | |
| 1287 " a += a; " | |
| 1288 "} " | |
| 1289 "a.replace(/a/g, a); "); | |
| 1290 CHECK(result.IsEmpty()); | |
| 1291 CHECK(context->HasOutOfMemoryException()); | |
| 1292 } | |
| 1293 | |
| 1294 | |
| 1295 TEST(StringReplaceAtomTwoByteResult) { | 1278 TEST(StringReplaceAtomTwoByteResult) { |
| 1296 CcTest::InitializeVM(); | 1279 CcTest::InitializeVM(); |
| 1297 v8::HandleScope scope(CcTest::isolate()); | 1280 v8::HandleScope scope(CcTest::isolate()); |
| 1298 LocalContext context; | 1281 LocalContext context; |
| 1299 v8::Local<v8::Value> result = CompileRun( | 1282 v8::Local<v8::Value> result = CompileRun( |
| 1300 "var subject = 'ascii~only~string~'; " | 1283 "var subject = 'ascii~only~string~'; " |
| 1301 "var replace = '\x80'; " | 1284 "var replace = '\x80'; " |
| 1302 "subject.replace(/~/g, replace); "); | 1285 "subject.replace(/~/g, replace); "); |
| 1303 CHECK(result->IsString()); | 1286 CHECK(result->IsString()); |
| 1304 Handle<String> string = v8::Utils::OpenHandle(v8::String::Cast(*result)); | 1287 Handle<String> string = v8::Utils::OpenHandle(v8::String::Cast(*result)); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1362 CheckCanonicalEquivalence(c, test); | 1345 CheckCanonicalEquivalence(c, test); |
| 1363 continue; | 1346 continue; |
| 1364 } | 1347 } |
| 1365 if (upper != c && lower != c) { | 1348 if (upper != c && lower != c) { |
| 1366 CheckCanonicalEquivalence(c, test); | 1349 CheckCanonicalEquivalence(c, test); |
| 1367 continue; | 1350 continue; |
| 1368 } | 1351 } |
| 1369 CHECK_EQ(Min(upper, lower), test); | 1352 CHECK_EQ(Min(upper, lower), test); |
| 1370 } | 1353 } |
| 1371 } | 1354 } |
| 1355 |
| 1356 |
| 1357 class DummyResource: public v8::String::ExternalStringResource { |
| 1358 public: |
| 1359 virtual const uint16_t* data() const { return NULL; } |
| 1360 virtual size_t length() const { return 1 << 30; } |
| 1361 }; |
| 1362 |
| 1363 |
| 1364 class DummyOneByteResource: public v8::String::ExternalOneByteStringResource { |
| 1365 public: |
| 1366 virtual const char* data() const { return NULL; } |
| 1367 virtual size_t length() const { return 1 << 30; } |
| 1368 }; |
| 1369 |
| 1370 |
| 1371 TEST(InvalidExternalString) { |
| 1372 CcTest::InitializeVM(); |
| 1373 LocalContext context; |
| 1374 Isolate* isolate = CcTest::i_isolate(); |
| 1375 { HandleScope scope(isolate); |
| 1376 DummyOneByteResource r; |
| 1377 CHECK(isolate->factory()->NewExternalStringFromAscii(&r).is_null()); |
| 1378 CHECK(isolate->has_pending_exception()); |
| 1379 isolate->clear_pending_exception(); |
| 1380 } |
| 1381 |
| 1382 { HandleScope scope(isolate); |
| 1383 DummyResource r; |
| 1384 CHECK(isolate->factory()->NewExternalStringFromTwoByte(&r).is_null()); |
| 1385 CHECK(isolate->has_pending_exception()); |
| 1386 isolate->clear_pending_exception(); |
| 1387 } |
| 1388 } |
| 1389 |
| 1390 |
| 1391 #define INVALID_STRING_TEST(FUN, TYPE) \ |
| 1392 TEST(StringOOM##FUN) { \ |
| 1393 CcTest::InitializeVM(); \ |
| 1394 LocalContext context; \ |
| 1395 Isolate* isolate = CcTest::i_isolate(); \ |
| 1396 STATIC_ASSERT(String::kMaxLength < kMaxInt); \ |
| 1397 static const int invalid = String::kMaxLength + 1; \ |
| 1398 HandleScope scope(isolate); \ |
| 1399 Vector<TYPE> dummy = Vector<TYPE>::New(invalid); \ |
| 1400 CHECK(isolate->factory()->FUN(Vector<const TYPE>::cast(dummy)).is_null()); \ |
| 1401 memset(dummy.start(), 0x20, dummy.length() * sizeof(TYPE)); \ |
| 1402 CHECK(isolate->has_pending_exception()); \ |
| 1403 isolate->clear_pending_exception(); \ |
| 1404 dummy.Dispose(); \ |
| 1405 } |
| 1406 |
| 1407 INVALID_STRING_TEST(NewStringFromAscii, char) |
| 1408 INVALID_STRING_TEST(NewStringFromUtf8, char) |
| 1409 INVALID_STRING_TEST(NewStringFromOneByte, uint8_t) |
| 1410 INVALID_STRING_TEST(NewStringFromTwoByte, uint16_t) |
| 1411 INVALID_STRING_TEST(InternalizeOneByteString, uint8_t) |
| 1412 INVALID_STRING_TEST(InternalizeUtf8String, char) |
| 1413 INVALID_STRING_TEST(InternalizeTwoByteString, uint16_t) |
| 1414 |
| 1415 #undef INVALID_STRING_TEST |
| OLD | NEW |