| 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 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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) { | 624 TEST(MakingExternalUnalignedAsciiString) { |
| 625 LocalContext env; | 625 LocalContext env; |
| 626 v8::HandleScope scope(env->GetIsolate()); | 626 v8::HandleScope scope(env->GetIsolate()); |
| 627 | 627 |
| 628 CompileRun("function cons(a, b) { return a + b; }" |
| 629 "function slice(a) { return a.substring(1); }"); |
| 628 // Create a cons string that will land in old pointer space. | 630 // Create a cons string that will land in old pointer space. |
| 629 Local<String> string = Local<String>::Cast(CompileRun( | 631 Local<String> cons = Local<String>::Cast(CompileRun( |
| 630 "function cons(a, b) { return a + b; }" | |
| 631 "cons('abcdefghijklm', 'nopqrstuvwxyz');")); | 632 "cons('abcdefghijklm', 'nopqrstuvwxyz');")); |
| 633 // Create a sliced string that will land in old pointer space. |
| 634 Local<String> slice = Local<String>::Cast(CompileRun( |
| 635 "slice('abcdefghijklmnopqrstuvwxyz');")); |
| 632 | 636 |
| 633 // Trigger GCs so that the newly allocated string moves to old gen. | 637 // Trigger GCs so that the newly allocated string moves to old gen. |
| 634 SimulateFullSpace(HEAP->old_pointer_space()); | 638 SimulateFullSpace(HEAP->old_pointer_space()); |
| 635 HEAP->CollectGarbage(i::NEW_SPACE); // in survivor space now | 639 HEAP->CollectGarbage(i::NEW_SPACE); // in survivor space now |
| 636 HEAP->CollectGarbage(i::NEW_SPACE); // in old gen now | 640 HEAP->CollectGarbage(i::NEW_SPACE); // in old gen now |
| 637 | 641 |
| 638 // Turn into external string with unaligned resource data. | 642 // Turn into external string with unaligned resource data. |
| 639 int dispose_count = 0; | 643 int dispose_count = 0; |
| 640 const char* c_source = "_abcdefghijklmnopqrstuvwxyz"; | 644 const char* c_cons = "_abcdefghijklmnopqrstuvwxyz"; |
| 641 bool success = string->MakeExternal( | 645 bool success = cons->MakeExternal( |
| 642 new TestAsciiResource(i::StrDup(c_source) + 1, &dispose_count)); | 646 new TestAsciiResource(i::StrDup(c_cons) + 1, &dispose_count)); |
| 647 CHECK(success); |
| 648 const char* c_slice = "_bcdefghijklmnopqrstuvwxyz"; |
| 649 success = slice->MakeExternal( |
| 650 new TestAsciiResource(i::StrDup(c_slice) + 1, &dispose_count)); |
| 643 CHECK(success); | 651 CHECK(success); |
| 644 | 652 |
| 645 // Trigger GCs and force evacuation. | 653 // Trigger GCs and force evacuation. |
| 646 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); | 654 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); |
| 647 HEAP->CollectAllGarbage(i::Heap::kReduceMemoryFootprintMask); | 655 HEAP->CollectAllGarbage(i::Heap::kReduceMemoryFootprintMask); |
| 648 } | 656 } |
| 649 | 657 |
| 650 | 658 |
| 651 THREADED_TEST(UsingExternalString) { | 659 THREADED_TEST(UsingExternalString) { |
| 652 i::Factory* factory = i::Isolate::Current()->factory(); | 660 i::Factory* factory = i::Isolate::Current()->factory(); |
| (...skipping 19271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 19924 CheckCorrectThrow("%HasProperty(other, 'x')"); | 19932 CheckCorrectThrow("%HasProperty(other, 'x')"); |
| 19925 CheckCorrectThrow("%HasElement(other, 1)"); | 19933 CheckCorrectThrow("%HasElement(other, 1)"); |
| 19926 CheckCorrectThrow("%IsPropertyEnumerable(other, 'x')"); | 19934 CheckCorrectThrow("%IsPropertyEnumerable(other, 'x')"); |
| 19927 CheckCorrectThrow("%GetPropertyNames(other)"); | 19935 CheckCorrectThrow("%GetPropertyNames(other)"); |
| 19928 CheckCorrectThrow("%GetLocalPropertyNames(other, true)"); | 19936 CheckCorrectThrow("%GetLocalPropertyNames(other, true)"); |
| 19929 CheckCorrectThrow("%DefineOrRedefineAccessorProperty(" | 19937 CheckCorrectThrow("%DefineOrRedefineAccessorProperty(" |
| 19930 "other, 'x', null, null, 1)"); | 19938 "other, 'x', null, null, 1)"); |
| 19931 } | 19939 } |
| 19932 | 19940 |
| 19933 #endif // WIN32 | 19941 #endif // WIN32 |
| OLD | NEW |