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 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
614 char* buf = i::NewArray<char>(buf_size); | 614 char* buf = i::NewArray<char>(buf_size); |
615 memset(buf, 'a', buf_size); | 615 memset(buf, 'a', buf_size); |
616 buf[buf_size - 1] = '\0'; | 616 buf[buf_size - 1] = '\0'; |
617 Local<String> large_string = String::New(buf); | 617 Local<String> large_string = String::New(buf); |
618 i::DeleteArray(buf); | 618 i::DeleteArray(buf); |
619 // Large strings should be immediately accepted. | 619 // Large strings should be immediately accepted. |
620 CHECK(large_string->CanMakeExternal()); | 620 CHECK(large_string->CanMakeExternal()); |
621 } | 621 } |
622 | 622 |
623 | 623 |
| 624 TEST(MakingExternalUnalignedAsciiString) { |
| 625 LocalContext env; |
| 626 v8::HandleScope scope(env->GetIsolate()); |
| 627 |
| 628 // Create a cons string that will land in old pointer space. |
| 629 Local<String> string = Local<String>::Cast(CompileRun( |
| 630 "function cons(a, b) { return a + b; }" |
| 631 "cons('abcdefghijklm', 'nopqrstuvwxyz');")); |
| 632 |
| 633 // Trigger GCs so that the newly allocated string moves to old gen. |
| 634 SimulateFullSpace(HEAP->old_pointer_space()); |
| 635 HEAP->CollectGarbage(i::NEW_SPACE); // in survivor space now |
| 636 HEAP->CollectGarbage(i::NEW_SPACE); // in old gen now |
| 637 |
| 638 // Turn into external string with unaligned resource data. |
| 639 int dispose_count = 0; |
| 640 const char* c_source = "_abcdefghijklmnopqrstuvwxyz"; |
| 641 bool success = string->MakeExternal( |
| 642 new TestAsciiResource(i::StrDup(c_source) + 1, &dispose_count)); |
| 643 CHECK(success); |
| 644 |
| 645 // Trigger GCs and force evacuation. |
| 646 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); |
| 647 HEAP->CollectAllGarbage(i::Heap::kReduceMemoryFootprintMask); |
| 648 } |
| 649 |
| 650 |
624 THREADED_TEST(UsingExternalString) { | 651 THREADED_TEST(UsingExternalString) { |
625 i::Factory* factory = i::Isolate::Current()->factory(); | 652 i::Factory* factory = i::Isolate::Current()->factory(); |
626 { | 653 { |
627 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 654 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
628 uint16_t* two_byte_string = AsciiToTwoByteString("test string"); | 655 uint16_t* two_byte_string = AsciiToTwoByteString("test string"); |
629 Local<String> string = | 656 Local<String> string = |
630 String::NewExternal(new TestResource(two_byte_string)); | 657 String::NewExternal(new TestResource(two_byte_string)); |
631 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string); | 658 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string); |
632 // Trigger GCs so that the newly allocated string moves to old gen. | 659 // Trigger GCs so that the newly allocated string moves to old gen. |
633 HEAP->CollectGarbage(i::NEW_SPACE); // in survivor space now | 660 HEAP->CollectGarbage(i::NEW_SPACE); // in survivor space now |
(...skipping 19263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
19897 CheckCorrectThrow("%HasProperty(other, 'x')"); | 19924 CheckCorrectThrow("%HasProperty(other, 'x')"); |
19898 CheckCorrectThrow("%HasElement(other, 1)"); | 19925 CheckCorrectThrow("%HasElement(other, 1)"); |
19899 CheckCorrectThrow("%IsPropertyEnumerable(other, 'x')"); | 19926 CheckCorrectThrow("%IsPropertyEnumerable(other, 'x')"); |
19900 CheckCorrectThrow("%GetPropertyNames(other)"); | 19927 CheckCorrectThrow("%GetPropertyNames(other)"); |
19901 CheckCorrectThrow("%GetLocalPropertyNames(other, true)"); | 19928 CheckCorrectThrow("%GetLocalPropertyNames(other, true)"); |
19902 CheckCorrectThrow("%DefineOrRedefineAccessorProperty(" | 19929 CheckCorrectThrow("%DefineOrRedefineAccessorProperty(" |
19903 "other, 'x', null, null, 1)"); | 19930 "other, 'x', null, null, 1)"); |
19904 } | 19931 } |
19905 | 19932 |
19906 #endif // WIN32 | 19933 #endif // WIN32 |
OLD | NEW |