Index: test/cctest/test-api.cc |
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc |
index 4b911f95c8e8e60388f768230c2a51fd56dd66d2..463e3902b2e211e52bc52089fecfa5ddaf0491ef 100644 |
--- a/test/cctest/test-api.cc |
+++ b/test/cctest/test-api.cc |
@@ -7418,6 +7418,57 @@ THREADED_TEST(Utf16Symbol) { |
} |
+THREADED_TEST(Utf16MissingTrailing) { |
+ LocalContext context; |
+ v8::HandleScope scope(context->GetIsolate()); |
+ |
+ // Make sure it will go past the buffer, so it will call `WriteUtf16Slow` |
+ int size = 1024 * 64; |
+ uint8_t* buffer = new uint8_t[size]; |
+ for (int i = 0; i < size; i += 4) { |
+ buffer[i] = 0xf0; |
+ buffer[i + 1] = 0x9d; |
+ buffer[i + 2] = 0x80; |
+ buffer[i + 3] = 0x9e; |
+ } |
+ |
+ // Now invoke the decoder without last 3 bytes |
+ v8::Local<v8::String> str = |
+ v8::String::NewFromUtf8( |
+ context->GetIsolate(), reinterpret_cast<char*>(buffer), |
+ v8::NewStringType::kNormal, size - 3).ToLocalChecked(); |
+ USE(str); |
+ delete[] buffer; |
+} |
+ |
+ |
+THREADED_TEST(Utf16Trailing3Byte) { |
+ LocalContext context; |
+ v8::HandleScope scope(context->GetIsolate()); |
+ |
+ // Make sure it will go past the buffer, so it will call `WriteUtf16Slow` |
+ int size = 1024 * 63; |
+ uint8_t* buffer = new uint8_t[size]; |
+ for (int i = 0; i < size; i += 3) { |
+ buffer[i] = 0xe2; |
+ buffer[i + 1] = 0x80; |
+ buffer[i + 2] = 0xa6; |
+ } |
+ |
+ // Now invoke the decoder without last 3 bytes |
+ v8::Local<v8::String> str = |
+ v8::String::NewFromUtf8( |
+ context->GetIsolate(), reinterpret_cast<char*>(buffer), |
+ v8::NewStringType::kNormal, size).ToLocalChecked(); |
+ |
+ v8::String::Value value(str); |
+ CHECK_EQ(value.length(), size / 3); |
+ CHECK_EQ((*value)[value.length() - 1], 0x2026); |
+ |
+ delete[] buffer; |
+} |
+ |
+ |
THREADED_TEST(ToArrayIndex) { |
LocalContext context; |
v8::Isolate* isolate = context->GetIsolate(); |