| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 5425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5436 } | 5436 } |
| 5437 } | 5437 } |
| 5438 | 5438 |
| 5439 | 5439 |
| 5440 THREADED_TEST(StringWrite) { | 5440 THREADED_TEST(StringWrite) { |
| 5441 LocalContext context; | 5441 LocalContext context; |
| 5442 v8::HandleScope scope; | 5442 v8::HandleScope scope; |
| 5443 v8::Handle<String> str = v8_str("abcde"); | 5443 v8::Handle<String> str = v8_str("abcde"); |
| 5444 // abc<Icelandic eth><Unicode snowman>. | 5444 // abc<Icelandic eth><Unicode snowman>. |
| 5445 v8::Handle<String> str2 = v8_str("abc\303\260\342\230\203"); | 5445 v8::Handle<String> str2 = v8_str("abc\303\260\342\230\203"); |
| 5446 v8::Handle<String> str3 = v8::String::New("abc\0def", 7); |
| 5446 const int kStride = 4; // Must match stride in for loops in JS below. | 5447 const int kStride = 4; // Must match stride in for loops in JS below. |
| 5447 CompileRun( | 5448 CompileRun( |
| 5448 "var left = '';" | 5449 "var left = '';" |
| 5449 "for (var i = 0; i < 0xd800; i += 4) {" | 5450 "for (var i = 0; i < 0xd800; i += 4) {" |
| 5450 " left = left + String.fromCharCode(i);" | 5451 " left = left + String.fromCharCode(i);" |
| 5451 "}"); | 5452 "}"); |
| 5452 CompileRun( | 5453 CompileRun( |
| 5453 "var right = '';" | 5454 "var right = '';" |
| 5454 "for (var i = 0; i < 0xd800; i += 4) {" | 5455 "for (var i = 0; i < 0xd800; i += 4) {" |
| 5455 " right = String.fromCharCode(i) + right;" | 5456 " right = String.fromCharCode(i) + right;" |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5646 utf8buf[8] = 'X'; | 5647 utf8buf[8] = 'X'; |
| 5647 len = str2->WriteUtf8(utf8buf, sizeof(utf8buf), &charlen, | 5648 len = str2->WriteUtf8(utf8buf, sizeof(utf8buf), &charlen, |
| 5648 String::NO_NULL_TERMINATION); | 5649 String::NO_NULL_TERMINATION); |
| 5649 CHECK_EQ(8, len); | 5650 CHECK_EQ(8, len); |
| 5650 CHECK_EQ('X', utf8buf[8]); | 5651 CHECK_EQ('X', utf8buf[8]); |
| 5651 CHECK_EQ(5, charlen); | 5652 CHECK_EQ(5, charlen); |
| 5652 CHECK_EQ(0, strncmp(utf8buf, "abc\303\260\342\230\203", 8)); | 5653 CHECK_EQ(0, strncmp(utf8buf, "abc\303\260\342\230\203", 8)); |
| 5653 CHECK_NE(0, strcmp(utf8buf, "abc\303\260\342\230\203")); | 5654 CHECK_NE(0, strcmp(utf8buf, "abc\303\260\342\230\203")); |
| 5654 utf8buf[8] = '\0'; | 5655 utf8buf[8] = '\0'; |
| 5655 CHECK_EQ(0, strcmp(utf8buf, "abc\303\260\342\230\203")); | 5656 CHECK_EQ(0, strcmp(utf8buf, "abc\303\260\342\230\203")); |
| 5657 |
| 5658 memset(utf8buf, 0x1, sizeof(utf8buf)); |
| 5659 utf8buf[6] = 'X'; |
| 5660 len = str->WriteUtf8(utf8buf, sizeof(utf8buf), &charlen, |
| 5661 String::NO_NULL_TERMINATION); |
| 5662 CHECK_EQ(5, len); |
| 5663 CHECK_EQ('X', utf8buf[6]); |
| 5664 CHECK_EQ(5, charlen); |
| 5665 CHECK_EQ(0, strncmp(utf8buf, "abcde", 5)); |
| 5666 CHECK_NE(0, strcmp(utf8buf, "abcde")); |
| 5667 utf8buf[5] = '\0'; |
| 5668 CHECK_EQ(0, strcmp(utf8buf, "abcde")); |
| 5669 |
| 5670 memset(buf, 0x1, sizeof(buf)); |
| 5671 len = str3->WriteAscii(buf); |
| 5672 CHECK_EQ(7, len); |
| 5673 CHECK_EQ(0, strcmp("abc def", buf)); |
| 5656 } | 5674 } |
| 5657 | 5675 |
| 5658 | 5676 |
| 5659 THREADED_TEST(ToArrayIndex) { | 5677 THREADED_TEST(ToArrayIndex) { |
| 5660 v8::HandleScope scope; | 5678 v8::HandleScope scope; |
| 5661 LocalContext context; | 5679 LocalContext context; |
| 5662 | 5680 |
| 5663 v8::Handle<String> str = v8_str("42"); | 5681 v8::Handle<String> str = v8_str("42"); |
| 5664 v8::Handle<v8::Uint32> index = str->ToArrayIndex(); | 5682 v8::Handle<v8::Uint32> index = str->ToArrayIndex(); |
| 5665 CHECK(!index.IsEmpty()); | 5683 CHECK(!index.IsEmpty()); |
| (...skipping 9821 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15487 CHECK(i->Equals(CompileRun("'abcbd'.replace(/b/g,func)[3]"))); | 15505 CHECK(i->Equals(CompileRun("'abcbd'.replace(/b/g,func)[3]"))); |
| 15488 | 15506 |
| 15489 // TODO(1547): Make the following also return "i". | 15507 // TODO(1547): Make the following also return "i". |
| 15490 // Calling with environment record as base. | 15508 // Calling with environment record as base. |
| 15491 TestReceiver(o, context->Global(), "func()"); | 15509 TestReceiver(o, context->Global(), "func()"); |
| 15492 // Calling with no base. | 15510 // Calling with no base. |
| 15493 TestReceiver(o, context->Global(), "(1,func)()"); | 15511 TestReceiver(o, context->Global(), "(1,func)()"); |
| 15494 | 15512 |
| 15495 foreign_context.Dispose(); | 15513 foreign_context.Dispose(); |
| 15496 } | 15514 } |
| OLD | NEW |