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

Unified Diff: test/cctest/test-strings.cc

Issue 207613005: No longer OOM on invalid string length. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: rebase + addressed nits 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-strings.cc
diff --git a/test/cctest/test-strings.cc b/test/cctest/test-strings.cc
index 0f37c3e5172d659bc249675ea5d8d829be3226ba..9168d86c4f38e74e5ad3d17073dcb7ffcb871582 100644
--- a/test/cctest/test-strings.cc
+++ b/test/cctest/test-strings.cc
@@ -1352,3 +1352,64 @@ TEST(Latin1IgnoreCase) {
CHECK_EQ(Min(upper, lower), test);
}
}
+
+
+class DummyResource: public v8::String::ExternalStringResource {
+ public:
+ virtual const uint16_t* data() const { return NULL; }
+ virtual size_t length() const { return 1 << 30; }
+};
+
+
+class DummyOneByteResource: public v8::String::ExternalOneByteStringResource {
+ public:
+ virtual const char* data() const { return NULL; }
+ virtual size_t length() const { return 1 << 30; }
+};
+
+
+TEST(InvalidExternalString) {
+ CcTest::InitializeVM();
+ LocalContext context;
+ Isolate* isolate = CcTest::i_isolate();
+ { HandleScope scope(isolate);
+ DummyOneByteResource r;
+ CHECK(isolate->factory()->NewExternalStringFromAscii(&r).is_null());
+ CHECK(isolate->has_pending_exception());
+ isolate->clear_pending_exception();
+ }
+
+ { HandleScope scope(isolate);
+ DummyResource r;
+ CHECK(isolate->factory()->NewExternalStringFromTwoByte(&r).is_null());
+ CHECK(isolate->has_pending_exception());
+ isolate->clear_pending_exception();
+ }
+}
+
+
+#define INVALID_STRING_TEST(FUN, TYPE) \
+ TEST(StringOOM##FUN) { \
+ CcTest::InitializeVM(); \
+ LocalContext context; \
+ Isolate* isolate = CcTest::i_isolate(); \
+ STATIC_ASSERT(String::kMaxLength < kMaxInt); \
+ static const int invalid = String::kMaxLength + 1; \
+ HandleScope scope(isolate); \
+ Vector<TYPE> dummy = Vector<TYPE>::New(invalid); \
+ CHECK(isolate->factory()->FUN(Vector<const TYPE>::cast(dummy)).is_null()); \
+ memset(dummy.start(), 0x20, dummy.length() * sizeof(TYPE)); \
+ CHECK(isolate->has_pending_exception()); \
+ isolate->clear_pending_exception(); \
+ dummy.Dispose(); \
+ }
+
+INVALID_STRING_TEST(NewStringFromAscii, char)
+INVALID_STRING_TEST(NewStringFromUtf8, char)
+INVALID_STRING_TEST(NewStringFromOneByte, uint8_t)
+INVALID_STRING_TEST(NewStringFromTwoByte, uint16_t)
+INVALID_STRING_TEST(InternalizeOneByteString, uint8_t)
+INVALID_STRING_TEST(InternalizeUtf8String, char)
+INVALID_STRING_TEST(InternalizeTwoByteString, uint16_t)
+
+#undef INVALID_STRING_TEST
« 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