| OLD | NEW |
| 1 // Copyright 2007-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2009 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 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 for (int i = 0; i < 100; i++) { | 491 for (int i = 0; i < 100; i++) { |
| 492 String::Value value(small_string); | 492 String::Value value(small_string); |
| 493 } | 493 } |
| 494 // Frequently used strings should be accepted. | 494 // Frequently used strings should be accepted. |
| 495 CHECK(small_string->CanMakeExternal()); | 495 CHECK(small_string->CanMakeExternal()); |
| 496 | 496 |
| 497 const int buf_size = 10 * 1024; | 497 const int buf_size = 10 * 1024; |
| 498 char* buf = i::NewArray<char>(buf_size); | 498 char* buf = i::NewArray<char>(buf_size); |
| 499 memset(buf, 'a', buf_size); | 499 memset(buf, 'a', buf_size); |
| 500 buf[buf_size - 1] = '\0'; | 500 buf[buf_size - 1] = '\0'; |
| 501 | 501 |
| 502 two_byte_string = AsciiToTwoByteString(buf); | 502 two_byte_string = AsciiToTwoByteString(buf); |
| 503 Local<String> large_string = String::New(two_byte_string); | 503 Local<String> large_string = String::New(two_byte_string); |
| 504 i::DeleteArray(buf); | 504 i::DeleteArray(buf); |
| 505 i::DeleteArray(two_byte_string); | 505 i::DeleteArray(two_byte_string); |
| 506 // Large strings should be immediately accepted. | 506 // Large strings should be immediately accepted. |
| 507 CHECK(large_string->CanMakeExternal()); | 507 CHECK(large_string->CanMakeExternal()); |
| 508 } | 508 } |
| 509 | 509 |
| 510 | 510 |
| 511 TEST(MakingExternalAsciiStringConditions) { | 511 TEST(MakingExternalAsciiStringConditions) { |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 690 v8::HandleScope scope; | 690 v8::HandleScope scope; |
| 691 LocalContext env; | 691 LocalContext env; |
| 692 const char* one_byte_string_1 = "function a_times_t"; | 692 const char* one_byte_string_1 = "function a_times_t"; |
| 693 const char* two_byte_string_1 = "wo_plus_b(a, b) {return "; | 693 const char* two_byte_string_1 = "wo_plus_b(a, b) {return "; |
| 694 const char* one_byte_extern_1 = "a * 2 + b;} a_times_two_plus_b(4, 8) + "; | 694 const char* one_byte_extern_1 = "a * 2 + b;} a_times_two_plus_b(4, 8) + "; |
| 695 const char* two_byte_extern_1 = "a_times_two_plus_b(4, 8) + "; | 695 const char* two_byte_extern_1 = "a_times_two_plus_b(4, 8) + "; |
| 696 const char* one_byte_string_2 = "a_times_two_plus_b(4, 8) + "; | 696 const char* one_byte_string_2 = "a_times_two_plus_b(4, 8) + "; |
| 697 const char* two_byte_string_2 = "a_times_two_plus_b(4, 8) + "; | 697 const char* two_byte_string_2 = "a_times_two_plus_b(4, 8) + "; |
| 698 const char* two_byte_extern_2 = "a_times_two_plus_b(1, 2);"; | 698 const char* two_byte_extern_2 = "a_times_two_plus_b(1, 2);"; |
| 699 Local<String> left = v8_str(one_byte_string_1); | 699 Local<String> left = v8_str(one_byte_string_1); |
| 700 | 700 |
| 701 uint16_t* two_byte_source = AsciiToTwoByteString(two_byte_string_1); | 701 uint16_t* two_byte_source = AsciiToTwoByteString(two_byte_string_1); |
| 702 Local<String> right = String::New(two_byte_source); | 702 Local<String> right = String::New(two_byte_source); |
| 703 i::DeleteArray(two_byte_source); | 703 i::DeleteArray(two_byte_source); |
| 704 | 704 |
| 705 Local<String> source = String::Concat(left, right); | 705 Local<String> source = String::Concat(left, right); |
| 706 right = String::NewExternal( | 706 right = String::NewExternal( |
| 707 new TestAsciiResource(i::StrDup(one_byte_extern_1))); | 707 new TestAsciiResource(i::StrDup(one_byte_extern_1))); |
| 708 source = String::Concat(source, right); | 708 source = String::Concat(source, right); |
| 709 right = String::NewExternal( | 709 right = String::NewExternal( |
| 710 new TestResource(AsciiToTwoByteString(two_byte_extern_1))); | 710 new TestResource(AsciiToTwoByteString(two_byte_extern_1))); |
| 711 source = String::Concat(source, right); | 711 source = String::Concat(source, right); |
| 712 right = v8_str(one_byte_string_2); | 712 right = v8_str(one_byte_string_2); |
| 713 source = String::Concat(source, right); | 713 source = String::Concat(source, right); |
| 714 | 714 |
| (...skipping 10462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11177 | 11177 |
| 11178 ExpectString("str2.substring(2, 10);", "elspenda"); | 11178 ExpectString("str2.substring(2, 10);", "elspenda"); |
| 11179 | 11179 |
| 11180 ExpectString("str2.substring(2, 20);", "elspendabelabelspe"); | 11180 ExpectString("str2.substring(2, 20);", "elspendabelabelspe"); |
| 11181 | 11181 |
| 11182 ExpectString("str2.charAt(2);", "e"); | 11182 ExpectString("str2.charAt(2);", "e"); |
| 11183 | 11183 |
| 11184 reresult = CompileRun("str2.charCodeAt(2);"); | 11184 reresult = CompileRun("str2.charCodeAt(2);"); |
| 11185 CHECK_EQ(static_cast<int32_t>('e'), reresult->Int32Value()); | 11185 CHECK_EQ(static_cast<int32_t>('e'), reresult->Int32Value()); |
| 11186 } | 11186 } |
| OLD | NEW |