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'; // Test that the sixth character is left untouched. | |
Toon Verwaest
2012/07/23 13:07:21
This comment probably belongs on line 5790.
| |
5787 len = str->WriteUtf8(utf8buf, sizeof(utf8buf), &charlen, | |
5788 String::NO_NULL_TERMINATION); | |
5789 CHECK_EQ(5, len); | |
5790 CHECK_EQ('X', utf8buf[5]); | |
5791 CHECK_EQ(5, charlen); | |
5792 CHECK_EQ(0, strncmp(utf8buf, "abcde", 5)); | |
5793 utf8buf[5] = '\0'; | |
5794 CHECK_EQ(0, strcmp(utf8buf, "abcde")); | |
Toon Verwaest
2012/07/23 13:07:21
Testing with strcmp and strncmp seems superfluous.
| |
5795 | |
5796 memset(buf, 0x1, sizeof(buf)); | |
5797 len = str3->WriteAscii(buf); | |
5798 CHECK_EQ(7, len); | |
5799 CHECK_EQ(0, strcmp("abc def", buf)); | |
5800 | |
5801 memset(buf, 0x1, sizeof(buf)); | |
5802 len = str3->WriteAscii(buf, 0, -1, String::PRESERVE_ASCII_NULL); | |
5803 CHECK_EQ(7, len); | |
5804 CHECK_EQ(0, strcmp("abc", buf)); | |
5805 CHECK_EQ(0, buf[3]); | |
5806 CHECK_EQ(0, strcmp("def", buf + 4)); | |
5783 } | 5807 } |
5784 | 5808 |
5785 | 5809 |
5786 static void Utf16Helper( | 5810 static void Utf16Helper( |
5787 LocalContext& context, | 5811 LocalContext& context, |
5788 const char* name, | 5812 const char* name, |
5789 const char* lengths_name, | 5813 const char* lengths_name, |
5790 int len) { | 5814 int len) { |
5791 Local<v8::Array> a = | 5815 Local<v8::Array> a = |
5792 Local<v8::Array>::Cast(context->Global()->Get(v8_str(name))); | 5816 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; | 17018 v8::HandleScope scope; |
16995 LocalContext context; | 17019 LocalContext context; |
16996 | 17020 |
16997 // Compile a try-finally clause where the finally block causes a GC | 17021 // Compile a try-finally clause where the finally block causes a GC |
16998 // while there still is a message pending for external reporting. | 17022 // while there still is a message pending for external reporting. |
16999 TryCatch try_catch; | 17023 TryCatch try_catch; |
17000 try_catch.SetVerbose(true); | 17024 try_catch.SetVerbose(true); |
17001 CompileRun("try { throw new Error(); } finally { gc(); }"); | 17025 CompileRun("try { throw new Error(); } finally { gc(); }"); |
17002 CHECK(try_catch.HasCaught()); | 17026 CHECK(try_catch.HasCaught()); |
17003 } | 17027 } |
OLD | NEW |