Index: test/cctest/test-api.cc |
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc |
index 5a9df90e21fc8350c5e1d0dbc7bf5f8e8de9d1f4..26483e019c6a49071c465f217fec001dab26e2ee 100644 |
--- a/test/cctest/test-api.cc |
+++ b/test/cctest/test-api.cc |
@@ -5570,6 +5570,7 @@ THREADED_TEST(StringWrite) { |
v8::Handle<String> str = v8_str("abcde"); |
// abc<Icelandic eth><Unicode snowman>. |
v8::Handle<String> str2 = v8_str("abc\303\260\342\230\203"); |
+ v8::Handle<String> str3 = v8::String::New("abc\0def", 7); |
const int kStride = 4; // Must match stride in for loops in JS below. |
CompileRun( |
"var left = '';" |
@@ -5780,6 +5781,28 @@ THREADED_TEST(StringWrite) { |
CHECK_NE(0, strcmp(utf8buf, "abc\303\260\342\230\203")); |
utf8buf[8] = '\0'; |
CHECK_EQ(0, strcmp(utf8buf, "abc\303\260\342\230\203")); |
+ |
+ memset(utf8buf, 0x1, sizeof(utf8buf)); |
+ utf8buf[5] = 'X'; |
+ len = str->WriteUtf8(utf8buf, sizeof(utf8buf), &charlen, |
+ String::NO_NULL_TERMINATION); |
+ CHECK_EQ(5, len); |
+ CHECK_EQ('X', utf8buf[5]); // Test that the sixth character is untouched. |
+ CHECK_EQ(5, charlen); |
+ utf8buf[5] = '\0'; |
+ CHECK_EQ(0, strcmp(utf8buf, "abcde")); |
+ |
+ memset(buf, 0x1, sizeof(buf)); |
+ len = str3->WriteAscii(buf); |
+ CHECK_EQ(7, len); |
+ CHECK_EQ(0, strcmp("abc def", buf)); |
+ |
+ memset(buf, 0x1, sizeof(buf)); |
+ len = str3->WriteAscii(buf, 0, -1, String::PRESERVE_ASCII_NULL); |
+ CHECK_EQ(7, len); |
+ CHECK_EQ(0, strcmp("abc", buf)); |
+ CHECK_EQ(0, buf[3]); |
+ CHECK_EQ(0, strcmp("def", buf + 4)); |
} |