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 637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
648 proxy->Fix(); | 648 proxy->Fix(); |
649 return isolate->heap()->undefined_value(); | 649 return isolate->heap()->undefined_value(); |
650 } | 650 } |
651 | 651 |
652 | 652 |
653 static void ArrayBufferWeakCallback(v8::Isolate* external_isolate, | 653 static void ArrayBufferWeakCallback(v8::Isolate* external_isolate, |
654 Persistent<Value>* object, | 654 Persistent<Value>* object, |
655 void* data) { | 655 void* data) { |
656 Isolate* isolate = reinterpret_cast<Isolate*>(external_isolate); | 656 Isolate* isolate = reinterpret_cast<Isolate*>(external_isolate); |
657 HandleScope scope(isolate); | 657 HandleScope scope(isolate); |
658 Handle<Object> internal_object = Utils::OpenHandle(**object); | 658 Handle<Object> internal_object = Utils::OpenPersistent(object); |
659 Handle<JSArrayBuffer> array_buffer(JSArrayBuffer::cast(*internal_object)); | 659 Handle<JSArrayBuffer> array_buffer(JSArrayBuffer::cast(*internal_object)); |
660 | 660 |
661 if (!array_buffer->is_external()) { | 661 if (!array_buffer->is_external()) { |
662 size_t allocated_length = NumberToSize( | 662 size_t allocated_length = NumberToSize( |
663 isolate, array_buffer->byte_length()); | 663 isolate, array_buffer->byte_length()); |
664 isolate->heap()->AdjustAmountOfExternalAllocatedMemory( | 664 isolate->heap()->AdjustAmountOfExternalAllocatedMemory( |
665 -static_cast<intptr_t>(allocated_length)); | 665 -static_cast<intptr_t>(allocated_length)); |
666 CHECK(V8::ArrayBufferAllocator() != NULL); | 666 CHECK(V8::ArrayBufferAllocator() != NULL); |
667 V8::ArrayBufferAllocator()->Free(data); | 667 V8::ArrayBufferAllocator()->Free(data); |
668 } | 668 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
704 if (allocated_length != 0) { | 704 if (allocated_length != 0) { |
705 data = V8::ArrayBufferAllocator()->Allocate(allocated_length); | 705 data = V8::ArrayBufferAllocator()->Allocate(allocated_length); |
706 if (data == NULL) return false; | 706 if (data == NULL) return false; |
707 memset(data, 0, allocated_length); | 707 memset(data, 0, allocated_length); |
708 } else { | 708 } else { |
709 data = NULL; | 709 data = NULL; |
710 } | 710 } |
711 | 711 |
712 SetupArrayBuffer(isolate, array_buffer, false, data, allocated_length); | 712 SetupArrayBuffer(isolate, array_buffer, false, data, allocated_length); |
713 | 713 |
714 v8::Isolate* external_isolate = reinterpret_cast<v8::Isolate*>(isolate); | 714 Handle<Object> persistent = isolate->global_handles()->Create(*array_buffer); |
715 v8::Persistent<v8::Value> weak_handle( | 715 GlobalHandles::MakeWeak(persistent.location(), data, ArrayBufferWeakCallback); |
716 external_isolate, v8::Utils::ToLocal(Handle<Object>::cast(array_buffer))); | 716 GlobalHandles::MarkIndependent(persistent.location()); |
717 weak_handle.MakeWeak(external_isolate, data, ArrayBufferWeakCallback); | 717 |
718 weak_handle.MarkIndependent(external_isolate); | |
719 isolate->heap()->AdjustAmountOfExternalAllocatedMemory(allocated_length); | 718 isolate->heap()->AdjustAmountOfExternalAllocatedMemory(allocated_length); |
720 | 719 |
721 return true; | 720 return true; |
722 } | 721 } |
723 | 722 |
724 | 723 |
725 RUNTIME_FUNCTION(MaybeObject*, Runtime_ArrayBufferInitialize) { | 724 RUNTIME_FUNCTION(MaybeObject*, Runtime_ArrayBufferInitialize) { |
726 HandleScope scope(isolate); | 725 HandleScope scope(isolate); |
727 ASSERT(args.length() == 2); | 726 ASSERT(args.length() == 2); |
728 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, holder, 0); | 727 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, holder, 0); |
(...skipping 12906 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13635 // Handle last resort GC and make sure to allow future allocations | 13634 // Handle last resort GC and make sure to allow future allocations |
13636 // to grow the heap without causing GCs (if possible). | 13635 // to grow the heap without causing GCs (if possible). |
13637 isolate->counters()->gc_last_resort_from_js()->Increment(); | 13636 isolate->counters()->gc_last_resort_from_js()->Increment(); |
13638 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, | 13637 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, |
13639 "Runtime::PerformGC"); | 13638 "Runtime::PerformGC"); |
13640 } | 13639 } |
13641 } | 13640 } |
13642 | 13641 |
13643 | 13642 |
13644 } } // namespace v8::internal | 13643 } } // namespace v8::internal |
OLD | NEW |