Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: test/cctest/test-api.cc

Issue 14638003: deprecate WriteAscii and MayContainNonAscii (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/debug.cc ('k') | test/cctest/test-debug.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 "Fun2(new Cons1(), new Cons2()) == '[object Cons1],[object Cons2]'"); 282 "Fun2(new Cons1(), new Cons2()) == '[object Cons1],[object Cons2]'");
283 CHECK(value8->IsTrue()); 283 CHECK(value8->IsTrue());
284 } 284 }
285 285
286 286
287 THREADED_TEST(HulIgennem) { 287 THREADED_TEST(HulIgennem) {
288 LocalContext env; 288 LocalContext env;
289 v8::HandleScope scope(env->GetIsolate()); 289 v8::HandleScope scope(env->GetIsolate());
290 v8::Handle<v8::Primitive> undef = v8::Undefined(); 290 v8::Handle<v8::Primitive> undef = v8::Undefined();
291 Local<String> undef_str = undef->ToString(); 291 Local<String> undef_str = undef->ToString();
292 char* value = i::NewArray<char>(undef_str->Length() + 1); 292 char* value = i::NewArray<char>(undef_str->Utf8Length() + 1);
293 undef_str->WriteAscii(value); 293 undef_str->WriteUtf8(value);
294 CHECK_EQ(0, strcmp(value, "undefined")); 294 CHECK_EQ(0, strcmp(value, "undefined"));
295 i::DeleteArray(value); 295 i::DeleteArray(value);
296 } 296 }
297 297
298 298
299 THREADED_TEST(Access) { 299 THREADED_TEST(Access) {
300 LocalContext env; 300 LocalContext env;
301 v8::HandleScope scope(env->GetIsolate()); 301 v8::HandleScope scope(env->GetIsolate());
302 Local<v8::Object> obj = v8::Object::New(); 302 Local<v8::Object> obj = v8::Object::New();
303 Local<Value> foo_before = obj->Get(v8_str("foo")); 303 Local<Value> foo_before = obj->Get(v8_str("foo"));
(...skipping 6231 matching lines...) Expand 10 before | Expand all | Expand 10 after
6535 len = right_tree->WriteUtf8(utf8buf, utf8_expected, &charlen); 6535 len = right_tree->WriteUtf8(utf8buf, utf8_expected, &charlen);
6536 CHECK_EQ(utf8_expected, len); 6536 CHECK_EQ(utf8_expected, len);
6537 CHECK_EQ(0xd800 / kStride, charlen); 6537 CHECK_EQ(0xd800 / kStride, charlen);
6538 CHECK_EQ(0xed, static_cast<unsigned char>(utf8buf[0])); 6538 CHECK_EQ(0xed, static_cast<unsigned char>(utf8buf[0]));
6539 CHECK_EQ(0x9f, static_cast<unsigned char>(utf8buf[1])); 6539 CHECK_EQ(0x9f, static_cast<unsigned char>(utf8buf[1]));
6540 CHECK_EQ(0xc0 - kStride, static_cast<unsigned char>(utf8buf[2])); 6540 CHECK_EQ(0xc0 - kStride, static_cast<unsigned char>(utf8buf[2]));
6541 CHECK_EQ(1, utf8buf[utf8_expected]); 6541 CHECK_EQ(1, utf8buf[utf8_expected]);
6542 6542
6543 memset(buf, 0x1, sizeof(buf)); 6543 memset(buf, 0x1, sizeof(buf));
6544 memset(wbuf, 0x1, sizeof(wbuf)); 6544 memset(wbuf, 0x1, sizeof(wbuf));
6545 len = str->WriteAscii(buf); 6545 len = str->WriteOneByte(reinterpret_cast<uint8_t*>(buf));
6546 CHECK_EQ(5, len); 6546 CHECK_EQ(5, len);
6547 len = str->Write(wbuf); 6547 len = str->Write(wbuf);
6548 CHECK_EQ(5, len); 6548 CHECK_EQ(5, len);
6549 CHECK_EQ(0, strcmp("abcde", buf)); 6549 CHECK_EQ(0, strcmp("abcde", buf));
6550 uint16_t answer1[] = {'a', 'b', 'c', 'd', 'e', '\0'}; 6550 uint16_t answer1[] = {'a', 'b', 'c', 'd', 'e', '\0'};
6551 CHECK_EQ(0, StrCmp16(answer1, wbuf)); 6551 CHECK_EQ(0, StrCmp16(answer1, wbuf));
6552 6552
6553 memset(buf, 0x1, sizeof(buf)); 6553 memset(buf, 0x1, sizeof(buf));
6554 memset(wbuf, 0x1, sizeof(wbuf)); 6554 memset(wbuf, 0x1, sizeof(wbuf));
6555 len = str->WriteAscii(buf, 0, 4); 6555 len = str->WriteOneByte(reinterpret_cast<uint8_t*>(buf), 0, 4);
6556 CHECK_EQ(4, len); 6556 CHECK_EQ(4, len);
6557 len = str->Write(wbuf, 0, 4); 6557 len = str->Write(wbuf, 0, 4);
6558 CHECK_EQ(4, len); 6558 CHECK_EQ(4, len);
6559 CHECK_EQ(0, strncmp("abcd\1", buf, 5)); 6559 CHECK_EQ(0, strncmp("abcd\1", buf, 5));
6560 uint16_t answer2[] = {'a', 'b', 'c', 'd', 0x101}; 6560 uint16_t answer2[] = {'a', 'b', 'c', 'd', 0x101};
6561 CHECK_EQ(0, StrNCmp16(answer2, wbuf, 5)); 6561 CHECK_EQ(0, StrNCmp16(answer2, wbuf, 5));
6562 6562
6563 memset(buf, 0x1, sizeof(buf)); 6563 memset(buf, 0x1, sizeof(buf));
6564 memset(wbuf, 0x1, sizeof(wbuf)); 6564 memset(wbuf, 0x1, sizeof(wbuf));
6565 len = str->WriteAscii(buf, 0, 5); 6565 len = str->WriteOneByte(reinterpret_cast<uint8_t*>(buf), 0, 5);
6566 CHECK_EQ(5, len); 6566 CHECK_EQ(5, len);
6567 len = str->Write(wbuf, 0, 5); 6567 len = str->Write(wbuf, 0, 5);
6568 CHECK_EQ(5, len); 6568 CHECK_EQ(5, len);
6569 CHECK_EQ(0, strncmp("abcde\1", buf, 6)); 6569 CHECK_EQ(0, strncmp("abcde\1", buf, 6));
6570 uint16_t answer3[] = {'a', 'b', 'c', 'd', 'e', 0x101}; 6570 uint16_t answer3[] = {'a', 'b', 'c', 'd', 'e', 0x101};
6571 CHECK_EQ(0, StrNCmp16(answer3, wbuf, 6)); 6571 CHECK_EQ(0, StrNCmp16(answer3, wbuf, 6));
6572 6572
6573 memset(buf, 0x1, sizeof(buf)); 6573 memset(buf, 0x1, sizeof(buf));
6574 memset(wbuf, 0x1, sizeof(wbuf)); 6574 memset(wbuf, 0x1, sizeof(wbuf));
6575 len = str->WriteAscii(buf, 0, 6); 6575 len = str->WriteOneByte(reinterpret_cast<uint8_t*>(buf), 0, 6);
6576 CHECK_EQ(5, len); 6576 CHECK_EQ(5, len);
6577 len = str->Write(wbuf, 0, 6); 6577 len = str->Write(wbuf, 0, 6);
6578 CHECK_EQ(5, len); 6578 CHECK_EQ(5, len);
6579 CHECK_EQ(0, strcmp("abcde", buf)); 6579 CHECK_EQ(0, strcmp("abcde", buf));
6580 uint16_t answer4[] = {'a', 'b', 'c', 'd', 'e', '\0'}; 6580 uint16_t answer4[] = {'a', 'b', 'c', 'd', 'e', '\0'};
6581 CHECK_EQ(0, StrCmp16(answer4, wbuf)); 6581 CHECK_EQ(0, StrCmp16(answer4, wbuf));
6582 6582
6583 memset(buf, 0x1, sizeof(buf)); 6583 memset(buf, 0x1, sizeof(buf));
6584 memset(wbuf, 0x1, sizeof(wbuf)); 6584 memset(wbuf, 0x1, sizeof(wbuf));
6585 len = str->WriteAscii(buf, 4, -1); 6585 len = str->WriteOneByte(reinterpret_cast<uint8_t*>(buf), 4, -1);
6586 CHECK_EQ(1, len); 6586 CHECK_EQ(1, len);
6587 len = str->Write(wbuf, 4, -1); 6587 len = str->Write(wbuf, 4, -1);
6588 CHECK_EQ(1, len); 6588 CHECK_EQ(1, len);
6589 CHECK_EQ(0, strcmp("e", buf)); 6589 CHECK_EQ(0, strcmp("e", buf));
6590 uint16_t answer5[] = {'e', '\0'}; 6590 uint16_t answer5[] = {'e', '\0'};
6591 CHECK_EQ(0, StrCmp16(answer5, wbuf)); 6591 CHECK_EQ(0, StrCmp16(answer5, wbuf));
6592 6592
6593 memset(buf, 0x1, sizeof(buf)); 6593 memset(buf, 0x1, sizeof(buf));
6594 memset(wbuf, 0x1, sizeof(wbuf)); 6594 memset(wbuf, 0x1, sizeof(wbuf));
6595 len = str->WriteAscii(buf, 4, 6); 6595 len = str->WriteOneByte(reinterpret_cast<uint8_t*>(buf), 4, 6);
6596 CHECK_EQ(1, len); 6596 CHECK_EQ(1, len);
6597 len = str->Write(wbuf, 4, 6); 6597 len = str->Write(wbuf, 4, 6);
6598 CHECK_EQ(1, len); 6598 CHECK_EQ(1, len);
6599 CHECK_EQ(0, strcmp("e", buf)); 6599 CHECK_EQ(0, strcmp("e", buf));
6600 CHECK_EQ(0, StrCmp16(answer5, wbuf)); 6600 CHECK_EQ(0, StrCmp16(answer5, wbuf));
6601 6601
6602 memset(buf, 0x1, sizeof(buf)); 6602 memset(buf, 0x1, sizeof(buf));
6603 memset(wbuf, 0x1, sizeof(wbuf)); 6603 memset(wbuf, 0x1, sizeof(wbuf));
6604 len = str->WriteAscii(buf, 4, 1); 6604 len = str->WriteOneByte(reinterpret_cast<uint8_t*>(buf), 4, 1);
6605 CHECK_EQ(1, len); 6605 CHECK_EQ(1, len);
6606 len = str->Write(wbuf, 4, 1); 6606 len = str->Write(wbuf, 4, 1);
6607 CHECK_EQ(1, len); 6607 CHECK_EQ(1, len);
6608 CHECK_EQ(0, strncmp("e\1", buf, 2)); 6608 CHECK_EQ(0, strncmp("e\1", buf, 2));
6609 uint16_t answer6[] = {'e', 0x101}; 6609 uint16_t answer6[] = {'e', 0x101};
6610 CHECK_EQ(0, StrNCmp16(answer6, wbuf, 2)); 6610 CHECK_EQ(0, StrNCmp16(answer6, wbuf, 2));
6611 6611
6612 memset(buf, 0x1, sizeof(buf)); 6612 memset(buf, 0x1, sizeof(buf));
6613 memset(wbuf, 0x1, sizeof(wbuf)); 6613 memset(wbuf, 0x1, sizeof(wbuf));
6614 len = str->WriteAscii(buf, 3, 1); 6614 len = str->WriteOneByte(reinterpret_cast<uint8_t*>(buf), 3, 1);
6615 CHECK_EQ(1, len); 6615 CHECK_EQ(1, len);
6616 len = str->Write(wbuf, 3, 1); 6616 len = str->Write(wbuf, 3, 1);
6617 CHECK_EQ(1, len); 6617 CHECK_EQ(1, len);
6618 CHECK_EQ(0, strncmp("d\1", buf, 2)); 6618 CHECK_EQ(0, strncmp("d\1", buf, 2));
6619 uint16_t answer7[] = {'d', 0x101}; 6619 uint16_t answer7[] = {'d', 0x101};
6620 CHECK_EQ(0, StrNCmp16(answer7, wbuf, 2)); 6620 CHECK_EQ(0, StrNCmp16(answer7, wbuf, 2));
6621 6621
6622 memset(wbuf, 0x1, sizeof(wbuf)); 6622 memset(wbuf, 0x1, sizeof(wbuf));
6623 wbuf[5] = 'X'; 6623 wbuf[5] = 'X';
6624 len = str->Write(wbuf, 0, 6, String::NO_NULL_TERMINATION); 6624 len = str->Write(wbuf, 0, 6, String::NO_NULL_TERMINATION);
6625 CHECK_EQ(5, len); 6625 CHECK_EQ(5, len);
6626 CHECK_EQ('X', wbuf[5]); 6626 CHECK_EQ('X', wbuf[5]);
6627 uint16_t answer8a[] = {'a', 'b', 'c', 'd', 'e'}; 6627 uint16_t answer8a[] = {'a', 'b', 'c', 'd', 'e'};
6628 uint16_t answer8b[] = {'a', 'b', 'c', 'd', 'e', '\0'}; 6628 uint16_t answer8b[] = {'a', 'b', 'c', 'd', 'e', '\0'};
6629 CHECK_EQ(0, StrNCmp16(answer8a, wbuf, 5)); 6629 CHECK_EQ(0, StrNCmp16(answer8a, wbuf, 5));
6630 CHECK_NE(0, StrCmp16(answer8b, wbuf)); 6630 CHECK_NE(0, StrCmp16(answer8b, wbuf));
6631 wbuf[5] = '\0'; 6631 wbuf[5] = '\0';
6632 CHECK_EQ(0, StrCmp16(answer8b, wbuf)); 6632 CHECK_EQ(0, StrCmp16(answer8b, wbuf));
6633 6633
6634 memset(buf, 0x1, sizeof(buf)); 6634 memset(buf, 0x1, sizeof(buf));
6635 buf[5] = 'X'; 6635 buf[5] = 'X';
6636 len = str->WriteAscii(buf, 0, 6, String::NO_NULL_TERMINATION); 6636 len = str->WriteOneByte(reinterpret_cast<uint8_t*>(buf),
6637 0,
6638 6,
6639 String::NO_NULL_TERMINATION);
6637 CHECK_EQ(5, len); 6640 CHECK_EQ(5, len);
6638 CHECK_EQ('X', buf[5]); 6641 CHECK_EQ('X', buf[5]);
6639 CHECK_EQ(0, strncmp("abcde", buf, 5)); 6642 CHECK_EQ(0, strncmp("abcde", buf, 5));
6640 CHECK_NE(0, strcmp("abcde", buf)); 6643 CHECK_NE(0, strcmp("abcde", buf));
6641 buf[5] = '\0'; 6644 buf[5] = '\0';
6642 CHECK_EQ(0, strcmp("abcde", buf)); 6645 CHECK_EQ(0, strcmp("abcde", buf));
6643 6646
6644 memset(utf8buf, 0x1, sizeof(utf8buf)); 6647 memset(utf8buf, 0x1, sizeof(utf8buf));
6645 utf8buf[8] = 'X'; 6648 utf8buf[8] = 'X';
6646 len = str2->WriteUtf8(utf8buf, sizeof(utf8buf), &charlen, 6649 len = str2->WriteUtf8(utf8buf, sizeof(utf8buf), &charlen,
(...skipping 10 matching lines...) Expand all
6657 utf8buf[5] = 'X'; 6660 utf8buf[5] = 'X';
6658 len = str->WriteUtf8(utf8buf, sizeof(utf8buf), &charlen, 6661 len = str->WriteUtf8(utf8buf, sizeof(utf8buf), &charlen,
6659 String::NO_NULL_TERMINATION); 6662 String::NO_NULL_TERMINATION);
6660 CHECK_EQ(5, len); 6663 CHECK_EQ(5, len);
6661 CHECK_EQ('X', utf8buf[5]); // Test that the sixth character is untouched. 6664 CHECK_EQ('X', utf8buf[5]); // Test that the sixth character is untouched.
6662 CHECK_EQ(5, charlen); 6665 CHECK_EQ(5, charlen);
6663 utf8buf[5] = '\0'; 6666 utf8buf[5] = '\0';
6664 CHECK_EQ(0, strcmp(utf8buf, "abcde")); 6667 CHECK_EQ(0, strcmp(utf8buf, "abcde"));
6665 6668
6666 memset(buf, 0x1, sizeof(buf)); 6669 memset(buf, 0x1, sizeof(buf));
6667 len = str3->WriteAscii(buf); 6670 len = str3->WriteOneByte(reinterpret_cast<uint8_t*>(buf));
6668 CHECK_EQ(7, len);
6669 CHECK_EQ(0, strcmp("abc def", buf));
6670
6671 memset(buf, 0x1, sizeof(buf));
6672 len = str3->WriteAscii(buf, 0, -1, String::PRESERVE_ASCII_NULL);
6673 CHECK_EQ(7, len); 6671 CHECK_EQ(7, len);
6674 CHECK_EQ(0, strcmp("abc", buf)); 6672 CHECK_EQ(0, strcmp("abc", buf));
6675 CHECK_EQ(0, buf[3]); 6673 CHECK_EQ(0, buf[3]);
6676 CHECK_EQ(0, strcmp("def", buf + 4)); 6674 CHECK_EQ(0, strcmp("def", buf + 4));
6677 6675
6678 CHECK_EQ(0, str->WriteAscii(NULL, 0, 0, String::NO_NULL_TERMINATION)); 6676 CHECK_EQ(0, str->WriteOneByte(NULL, 0, 0, String::NO_NULL_TERMINATION));
6679 CHECK_EQ(0, str->WriteUtf8(NULL, 0, 0, String::NO_NULL_TERMINATION)); 6677 CHECK_EQ(0, str->WriteUtf8(NULL, 0, 0, String::NO_NULL_TERMINATION));
6680 CHECK_EQ(0, str->Write(NULL, 0, 0, String::NO_NULL_TERMINATION)); 6678 CHECK_EQ(0, str->Write(NULL, 0, 0, String::NO_NULL_TERMINATION));
6681 } 6679 }
6682 6680
6683 6681
6684 static void Utf16Helper( 6682 static void Utf16Helper(
6685 LocalContext& context, 6683 LocalContext& context,
6686 const char* name, 6684 const char* name,
6687 const char* lengths_name, 6685 const char* lengths_name,
6688 int len) { 6686 int len) {
(...skipping 1542 matching lines...) Expand 10 before | Expand all | Expand 10 after
8231 static bool NamedAccessFlatten(Local<v8::Object> global, 8229 static bool NamedAccessFlatten(Local<v8::Object> global,
8232 Local<Value> name, 8230 Local<Value> name,
8233 v8::AccessType type, 8231 v8::AccessType type,
8234 Local<Value> data) { 8232 Local<Value> data) {
8235 char buf[100]; 8233 char buf[100];
8236 int len; 8234 int len;
8237 8235
8238 CHECK(name->IsString()); 8236 CHECK(name->IsString());
8239 8237
8240 memset(buf, 0x1, sizeof(buf)); 8238 memset(buf, 0x1, sizeof(buf));
8241 len = name.As<String>()->WriteAscii(buf); 8239 len = name.As<String>()->WriteOneByte(reinterpret_cast<uint8_t*>(buf));
8242 CHECK_EQ(4, len); 8240 CHECK_EQ(4, len);
8243 8241
8244 uint16_t buf2[100]; 8242 uint16_t buf2[100];
8245 8243
8246 memset(buf, 0x1, sizeof(buf)); 8244 memset(buf, 0x1, sizeof(buf));
8247 len = name.As<String>()->Write(buf2); 8245 len = name.As<String>()->Write(buf2);
8248 CHECK_EQ(4, len); 8246 CHECK_EQ(4, len);
8249 8247
8250 return true; 8248 return true;
8251 } 8249 }
(...skipping 10605 matching lines...) Expand 10 before | Expand all | Expand 10 after
18857 i::Semaphore* sem_; 18855 i::Semaphore* sem_;
18858 volatile int sem_value_; 18856 volatile int sem_value_;
18859 }; 18857 };
18860 18858
18861 18859
18862 THREADED_TEST(SemaphoreInterruption) { 18860 THREADED_TEST(SemaphoreInterruption) {
18863 ThreadInterruptTest().RunTest(); 18861 ThreadInterruptTest().RunTest();
18864 } 18862 }
18865 18863
18866 #endif // WIN32 18864 #endif // WIN32
OLDNEW
« no previous file with comments | « src/debug.cc ('k') | test/cctest/test-debug.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698