Index: test/cctest/test-api.cc |
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc |
index 95a64a91cfcc15ad5ee6391857fda20119ff60e8..f1593fe4efa5dbf1cab2cd68dbd963c13d5779de 100644 |
--- a/test/cctest/test-api.cc |
+++ b/test/cctest/test-api.cc |
@@ -21914,3 +21914,36 @@ TEST(StreamingScriptWithSourceMappingURLInTheMiddle) { |
RunStreamingTest(chunks, v8::ScriptCompiler::StreamedSource::UTF8, true, NULL, |
"bar2.js"); |
} |
+ |
+ |
+TEST(NewStringRangeError) { |
+ v8::Isolate* isolate = CcTest::isolate(); |
+ v8::HandleScope handle_scope(isolate); |
+ LocalContext env; |
+ const int length = i::String::kMaxLength + 1; |
+ const int buffer_size = length * sizeof(uint16_t); |
+ void* buffer = malloc(buffer_size); |
+ memset(buffer, 'A', buffer_size); |
+ { |
+ v8::TryCatch try_catch; |
+ char* data = reinterpret_cast<char*>(buffer); |
+ CHECK(v8::String::NewFromUtf8(isolate, data, v8::String::kNormalString, |
+ length).IsEmpty()); |
+ CHECK(try_catch.HasCaught()); |
+ } |
+ { |
+ v8::TryCatch try_catch; |
+ uint8_t* data = reinterpret_cast<uint8_t*>(buffer); |
+ CHECK(v8::String::NewFromOneByte(isolate, data, v8::String::kNormalString, |
+ length).IsEmpty()); |
+ CHECK(try_catch.HasCaught()); |
+ } |
+ { |
+ v8::TryCatch try_catch; |
+ uint16_t* data = reinterpret_cast<uint16_t*>(buffer); |
+ CHECK(v8::String::NewFromTwoByte(isolate, data, v8::String::kNormalString, |
+ length).IsEmpty()); |
+ CHECK(try_catch.HasCaught()); |
+ } |
+ free(buffer); |
+} |