OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 5552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5563 return len; | 5563 return len; |
5564 } | 5564 } |
5565 | 5565 |
5566 | 5566 |
5567 THREADED_TEST(StringWrite) { | 5567 THREADED_TEST(StringWrite) { |
5568 LocalContext context; | 5568 LocalContext context; |
5569 v8::HandleScope scope; | 5569 v8::HandleScope scope; |
5570 v8::Handle<String> str = v8_str("abcde"); | 5570 v8::Handle<String> str = v8_str("abcde"); |
5571 // abc<Icelandic eth><Unicode snowman>. | 5571 // abc<Icelandic eth><Unicode snowman>. |
5572 v8::Handle<String> str2 = v8_str("abc\303\260\342\230\203"); | 5572 v8::Handle<String> str2 = v8_str("abc\303\260\342\230\203"); |
| 5573 v8::Handle<String> str3 = v8::String::New("abc\0def", 7); |
5573 const int kStride = 4; // Must match stride in for loops in JS below. | 5574 const int kStride = 4; // Must match stride in for loops in JS below. |
5574 CompileRun( | 5575 CompileRun( |
5575 "var left = '';" | 5576 "var left = '';" |
5576 "for (var i = 0; i < 0xd800; i += 4) {" | 5577 "for (var i = 0; i < 0xd800; i += 4) {" |
5577 " left = left + String.fromCharCode(i);" | 5578 " left = left + String.fromCharCode(i);" |
5578 "}"); | 5579 "}"); |
5579 CompileRun( | 5580 CompileRun( |
5580 "var right = '';" | 5581 "var right = '';" |
5581 "for (var i = 0; i < 0xd800; i += 4) {" | 5582 "for (var i = 0; i < 0xd800; i += 4) {" |
5582 " right = String.fromCharCode(i) + right;" | 5583 " right = String.fromCharCode(i) + right;" |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5773 utf8buf[8] = 'X'; | 5774 utf8buf[8] = 'X'; |
5774 len = str2->WriteUtf8(utf8buf, sizeof(utf8buf), &charlen, | 5775 len = str2->WriteUtf8(utf8buf, sizeof(utf8buf), &charlen, |
5775 String::NO_NULL_TERMINATION); | 5776 String::NO_NULL_TERMINATION); |
5776 CHECK_EQ(8, len); | 5777 CHECK_EQ(8, len); |
5777 CHECK_EQ('X', utf8buf[8]); | 5778 CHECK_EQ('X', utf8buf[8]); |
5778 CHECK_EQ(5, charlen); | 5779 CHECK_EQ(5, charlen); |
5779 CHECK_EQ(0, strncmp(utf8buf, "abc\303\260\342\230\203", 8)); | 5780 CHECK_EQ(0, strncmp(utf8buf, "abc\303\260\342\230\203", 8)); |
5780 CHECK_NE(0, strcmp(utf8buf, "abc\303\260\342\230\203")); | 5781 CHECK_NE(0, strcmp(utf8buf, "abc\303\260\342\230\203")); |
5781 utf8buf[8] = '\0'; | 5782 utf8buf[8] = '\0'; |
5782 CHECK_EQ(0, strcmp(utf8buf, "abc\303\260\342\230\203")); | 5783 CHECK_EQ(0, strcmp(utf8buf, "abc\303\260\342\230\203")); |
| 5784 |
| 5785 memset(utf8buf, 0x1, sizeof(utf8buf)); |
| 5786 utf8buf[5] = 'X'; |
| 5787 len = str->WriteUtf8(utf8buf, sizeof(utf8buf), &charlen, |
| 5788 String::NO_NULL_TERMINATION); |
| 5789 CHECK_EQ(5, len); |
| 5790 CHECK_EQ('X', utf8buf[5]); // Test that the sixth character is untouched. |
| 5791 CHECK_EQ(5, charlen); |
| 5792 utf8buf[5] = '\0'; |
| 5793 CHECK_EQ(0, strcmp(utf8buf, "abcde")); |
| 5794 |
| 5795 memset(buf, 0x1, sizeof(buf)); |
| 5796 len = str3->WriteAscii(buf); |
| 5797 CHECK_EQ(7, len); |
| 5798 CHECK_EQ(0, strcmp("abc def", buf)); |
| 5799 |
| 5800 memset(buf, 0x1, sizeof(buf)); |
| 5801 len = str3->WriteAscii(buf, 0, -1, String::PRESERVE_ASCII_NULL); |
| 5802 CHECK_EQ(7, len); |
| 5803 CHECK_EQ(0, strcmp("abc", buf)); |
| 5804 CHECK_EQ(0, buf[3]); |
| 5805 CHECK_EQ(0, strcmp("def", buf + 4)); |
5783 } | 5806 } |
5784 | 5807 |
5785 | 5808 |
5786 static void Utf16Helper( | 5809 static void Utf16Helper( |
5787 LocalContext& context, | 5810 LocalContext& context, |
5788 const char* name, | 5811 const char* name, |
5789 const char* lengths_name, | 5812 const char* lengths_name, |
5790 int len) { | 5813 int len) { |
5791 Local<v8::Array> a = | 5814 Local<v8::Array> a = |
5792 Local<v8::Array>::Cast(context->Global()->Get(v8_str(name))); | 5815 Local<v8::Array>::Cast(context->Global()->Get(v8_str(name))); |
(...skipping 11201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16994 v8::HandleScope scope; | 17017 v8::HandleScope scope; |
16995 LocalContext context; | 17018 LocalContext context; |
16996 | 17019 |
16997 // Compile a try-finally clause where the finally block causes a GC | 17020 // Compile a try-finally clause where the finally block causes a GC |
16998 // while there still is a message pending for external reporting. | 17021 // while there still is a message pending for external reporting. |
16999 TryCatch try_catch; | 17022 TryCatch try_catch; |
17000 try_catch.SetVerbose(true); | 17023 try_catch.SetVerbose(true); |
17001 CompileRun("try { throw new Error(); } finally { gc(); }"); | 17024 CompileRun("try { throw new Error(); } finally { gc(); }"); |
17002 CHECK(try_catch.HasCaught()); | 17025 CHECK(try_catch.HasCaught()); |
17003 } | 17026 } |
OLD | NEW |