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 1355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1366 CheckCanonicalEquivalence(c, test); | 1366 CheckCanonicalEquivalence(c, test); |
1367 continue; | 1367 continue; |
1368 } | 1368 } |
1369 CHECK_EQ(Min(upper, lower), test); | 1369 CHECK_EQ(Min(upper, lower), test); |
1370 } | 1370 } |
1371 } | 1371 } |
1372 | 1372 |
1373 | 1373 |
1374 class DummyResource: public v8::String::ExternalStringResource { | 1374 class DummyResource: public v8::String::ExternalStringResource { |
1375 public: | 1375 public: |
1376 virtual const uint16_t* data() const { return NULL; } | 1376 virtual const uint16_t* data() const { return string_; } |
1377 virtual size_t length() const { return 1 << 30; } | 1377 virtual size_t length() const { return 1 << 30; } |
1378 | |
1379 private: | |
1380 uint16_t string_[10]; | |
yurys
2014/09/26 09:30:34
Length 1 should be enough
| |
1378 }; | 1381 }; |
1379 | 1382 |
1380 | 1383 |
1381 class DummyOneByteResource: public v8::String::ExternalOneByteStringResource { | 1384 class DummyOneByteResource: public v8::String::ExternalOneByteStringResource { |
1382 public: | 1385 public: |
1383 virtual const char* data() const { return NULL; } | 1386 virtual const char* data() const { return string_; } |
1384 virtual size_t length() const { return 1 << 30; } | 1387 virtual size_t length() const { return 1 << 30; } |
1388 | |
1389 private: | |
1390 char string_[10]; | |
yurys
2014/09/26 09:30:34
ditto
| |
1385 }; | 1391 }; |
1386 | 1392 |
1387 | 1393 |
1388 TEST(InvalidExternalString) { | 1394 TEST(InvalidExternalString) { |
1389 CcTest::InitializeVM(); | 1395 CcTest::InitializeVM(); |
1390 LocalContext context; | 1396 LocalContext context; |
1391 Isolate* isolate = CcTest::i_isolate(); | 1397 Isolate* isolate = CcTest::i_isolate(); |
1392 { HandleScope scope(isolate); | 1398 { HandleScope scope(isolate); |
1393 DummyOneByteResource r; | 1399 DummyOneByteResource r; |
1394 CHECK(isolate->factory()->NewExternalStringFromOneByte(&r).is_null()); | 1400 CHECK(isolate->factory()->NewExternalStringFromOneByte(&r).is_null()); |
1395 CHECK(isolate->has_pending_exception()); | 1401 CHECK(isolate->has_pending_exception()); |
1396 isolate->clear_pending_exception(); | 1402 isolate->clear_pending_exception(); |
1397 } | 1403 } |
1398 | 1404 |
1399 { HandleScope scope(isolate); | 1405 { HandleScope scope(isolate); |
1400 DummyResource r; | 1406 DummyResource r; |
1401 CHECK(isolate->factory()->NewExternalStringFromTwoByte(&r).is_null()); | 1407 CHECK(isolate->factory()->NewExternalStringFromTwoByte(&r).is_null()); |
1402 CHECK(isolate->has_pending_exception()); | 1408 CHECK(isolate->has_pending_exception()); |
1403 isolate->clear_pending_exception(); | 1409 isolate->clear_pending_exception(); |
1404 } | 1410 } |
1411 | |
1412 { | |
1413 HandleScope scope(isolate); | |
1414 DummyOneByteResource r; | |
1415 v8::Local<v8::String> str = v8::String::NewExternal(CcTest::isolate(), &r); | |
1416 CHECK(str.IsEmpty()); | |
1417 CHECK(isolate->has_pending_exception()); | |
1418 isolate->clear_pending_exception(); | |
1419 } | |
1420 | |
1421 { | |
1422 HandleScope scope(isolate); | |
1423 DummyResource r; | |
1424 v8::Local<v8::String> str = v8::String::NewExternal(CcTest::isolate(), &r); | |
1425 CHECK(str.IsEmpty()); | |
1426 CHECK(isolate->has_pending_exception()); | |
1427 isolate->clear_pending_exception(); | |
1428 } | |
1405 } | 1429 } |
1406 | 1430 |
1407 | 1431 |
1408 #define INVALID_STRING_TEST(FUN, TYPE) \ | 1432 #define INVALID_STRING_TEST(FUN, TYPE) \ |
1409 TEST(StringOOM##FUN) { \ | 1433 TEST(StringOOM##FUN) { \ |
1410 CcTest::InitializeVM(); \ | 1434 CcTest::InitializeVM(); \ |
1411 LocalContext context; \ | 1435 LocalContext context; \ |
1412 Isolate* isolate = CcTest::i_isolate(); \ | 1436 Isolate* isolate = CcTest::i_isolate(); \ |
1413 STATIC_ASSERT(String::kMaxLength < kMaxInt); \ | 1437 STATIC_ASSERT(String::kMaxLength < kMaxInt); \ |
1414 static const int invalid = String::kMaxLength + 1; \ | 1438 static const int invalid = String::kMaxLength + 1; \ |
1415 HandleScope scope(isolate); \ | 1439 HandleScope scope(isolate); \ |
1416 Vector<TYPE> dummy = Vector<TYPE>::New(invalid); \ | 1440 Vector<TYPE> dummy = Vector<TYPE>::New(invalid); \ |
1417 CHECK(isolate->factory()->FUN(Vector<const TYPE>::cast(dummy)).is_null()); \ | 1441 CHECK(isolate->factory()->FUN(Vector<const TYPE>::cast(dummy)).is_null()); \ |
1418 memset(dummy.start(), 0x20, dummy.length() * sizeof(TYPE)); \ | 1442 memset(dummy.start(), 0x20, dummy.length() * sizeof(TYPE)); \ |
1419 CHECK(isolate->has_pending_exception()); \ | 1443 CHECK(isolate->has_pending_exception()); \ |
1420 isolate->clear_pending_exception(); \ | 1444 isolate->clear_pending_exception(); \ |
1421 dummy.Dispose(); \ | 1445 dummy.Dispose(); \ |
1422 } | 1446 } |
1423 | 1447 |
1424 INVALID_STRING_TEST(NewStringFromAscii, char) | 1448 INVALID_STRING_TEST(NewStringFromAscii, char) |
1425 INVALID_STRING_TEST(NewStringFromUtf8, char) | 1449 INVALID_STRING_TEST(NewStringFromUtf8, char) |
1426 INVALID_STRING_TEST(NewStringFromOneByte, uint8_t) | 1450 INVALID_STRING_TEST(NewStringFromOneByte, uint8_t) |
1427 | 1451 |
1428 #undef INVALID_STRING_TEST | 1452 #undef INVALID_STRING_TEST |
OLD | NEW |