Index: test/cctest/test-strings.cc |
diff --git a/test/cctest/test-strings.cc b/test/cctest/test-strings.cc |
index 8e63cb0d4716593da925135014244e8c96f43ada..9168d86c4f38e74e5ad3d17073dcb7ffcb871582 100644 |
--- a/test/cctest/test-strings.cc |
+++ b/test/cctest/test-strings.cc |
@@ -1275,23 +1275,6 @@ TEST(RobustSubStringStub) { |
} |
-TEST(RegExpOverflow) { |
- // Result string has the length 2^32, causing a 32-bit integer overflow. |
- CcTest::InitializeVM(); |
- v8::HandleScope scope(CcTest::isolate()); |
- LocalContext context; |
- v8::V8::IgnoreOutOfMemoryException(); |
- v8::Local<v8::Value> result = CompileRun( |
- "var a = 'a'; " |
- "for (var i = 0; i < 16; i++) { " |
- " a += a; " |
- "} " |
- "a.replace(/a/g, a); "); |
- CHECK(result.IsEmpty()); |
- CHECK(context->HasOutOfMemoryException()); |
-} |
- |
- |
TEST(StringReplaceAtomTwoByteResult) { |
CcTest::InitializeVM(); |
v8::HandleScope scope(CcTest::isolate()); |
@@ -1369,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 |