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

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

Issue 210683003: Reland "No longer OOM on invalid string length." (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 9 months 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/cctest.status ('k') | test/mjsunit/string-oom-replace-global-regexp-with-string.js » ('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 1334 matching lines...) Expand 10 before | Expand all | Expand 10 after
1345 CheckCanonicalEquivalence(c, test); 1345 CheckCanonicalEquivalence(c, test);
1346 continue; 1346 continue;
1347 } 1347 }
1348 if (upper != c && lower != c) { 1348 if (upper != c && lower != c) {
1349 CheckCanonicalEquivalence(c, test); 1349 CheckCanonicalEquivalence(c, test);
1350 continue; 1350 continue;
1351 } 1351 }
1352 CHECK_EQ(Min(upper, lower), test); 1352 CHECK_EQ(Min(upper, lower), test);
1353 } 1353 }
1354 } 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
OLDNEW
« no previous file with comments | « test/cctest/cctest.status ('k') | test/mjsunit/string-oom-replace-global-regexp-with-string.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698