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 688 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
699 { | 699 { |
700 MaybeObject* maybe_byte_length = | 700 MaybeObject* maybe_byte_length = |
701 isolate->heap()->NumberFromDouble( | 701 isolate->heap()->NumberFromDouble( |
702 static_cast<double>(allocated_length)); | 702 static_cast<double>(allocated_length)); |
703 if (!maybe_byte_length->ToObject(&byte_length)) return maybe_byte_length; | 703 if (!maybe_byte_length->ToObject(&byte_length)) return maybe_byte_length; |
704 } | 704 } |
705 CHECK(byte_length->IsSmi() || byte_length->IsHeapNumber()); | 705 CHECK(byte_length->IsSmi() || byte_length->IsHeapNumber()); |
706 holder->set_byte_length(byte_length); | 706 holder->set_byte_length(byte_length); |
707 | 707 |
708 v8::Isolate* external_isolate = reinterpret_cast<v8::Isolate*>(isolate); | 708 v8::Isolate* external_isolate = reinterpret_cast<v8::Isolate*>(isolate); |
709 v8::Handle<Object> external_holder(*holder); | 709 v8::Persistent<v8::Value> weak_handle = v8::Persistent<v8::Value>::New( |
710 Persistent<Object> weak_handle = Persistent<Object>::New( | 710 external_isolate, v8::Utils::ToLocal(Handle<Object>::cast(holder))); |
711 external_isolate, external_holder); | |
712 weak_handle.MakeWeak(external_isolate, data, ArrayBufferWeakCallback); | 711 weak_handle.MakeWeak(external_isolate, data, ArrayBufferWeakCallback); |
713 weak_handle.MarkIndependent(external_isolate); | 712 weak_handle.MarkIndependent(external_isolate); |
714 isolate->heap()->AdjustAmountOfExternalAllocatedMemory(allocated_length); | 713 isolate->heap()->AdjustAmountOfExternalAllocatedMemory(allocated_length); |
715 | 714 |
716 return *holder; | 715 return *holder; |
717 } | 716 } |
718 | 717 |
719 | 718 |
720 RUNTIME_FUNCTION(MaybeObject*, Runtime_ArrayBufferGetByteLength) { | 719 RUNTIME_FUNCTION(MaybeObject*, Runtime_ArrayBufferGetByteLength) { |
721 NoHandleAllocation ha(isolate); | 720 NoHandleAllocation ha(isolate); |
722 ASSERT(args.length() == 1); | 721 ASSERT(args.length() == 1); |
723 CONVERT_ARG_CHECKED(JSArrayBuffer, holder, 0); | 722 CONVERT_ARG_CHECKED(JSArrayBuffer, holder, 0); |
724 return holder->byte_length(); | 723 return holder->byte_length(); |
725 } | 724 } |
726 | 725 |
727 | 726 |
728 RUNTIME_FUNCTION(MaybeObject*, Runtime_ArrayBufferSliceImpl) { | 727 RUNTIME_FUNCTION(MaybeObject*, Runtime_ArrayBufferSliceImpl) { |
729 HandleScope scope(isolate); | 728 HandleScope scope(isolate); |
730 ASSERT(args.length() == 3); | 729 ASSERT(args.length() == 3); |
731 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, source, 0); | 730 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, source, 0); |
732 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, target, 1); | 731 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, target, 1); |
733 CONVERT_DOUBLE_ARG_CHECKED(first, 2); | 732 CONVERT_DOUBLE_ARG_CHECKED(first, 2); |
734 size_t start = static_cast<size_t>(first); | 733 size_t start = static_cast<size_t>(first); |
735 size_t target_length = NumberToSize(isolate, target->byte_length()); | 734 size_t target_length = NumberToSize(isolate, target->byte_length()); |
736 | 735 |
737 if (target_length == 0) | 736 if (target_length == 0) return isolate->heap()->undefined_value(); |
738 return isolate->heap()->undefined_value(); | |
739 | 737 |
740 ASSERT(NumberToSize(isolate, source->byte_length()) - target_length >= start); | 738 ASSERT(NumberToSize(isolate, source->byte_length()) - target_length >= start); |
741 uint8_t* source_data = reinterpret_cast<uint8_t*>(source->backing_store()); | 739 uint8_t* source_data = reinterpret_cast<uint8_t*>(source->backing_store()); |
742 uint8_t* target_data = reinterpret_cast<uint8_t*>(target->backing_store()); | 740 uint8_t* target_data = reinterpret_cast<uint8_t*>(target->backing_store()); |
743 CopyBytes(target_data, source_data + start, target_length); | 741 CopyBytes(target_data, source_data + start, target_length); |
744 return isolate->heap()->undefined_value(); | 742 return isolate->heap()->undefined_value(); |
745 } | 743 } |
746 | 744 |
747 | 745 |
748 enum TypedArrayId { | 746 enum TypedArrayId { |
(...skipping 12474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13223 // Handle last resort GC and make sure to allow future allocations | 13221 // Handle last resort GC and make sure to allow future allocations |
13224 // to grow the heap without causing GCs (if possible). | 13222 // to grow the heap without causing GCs (if possible). |
13225 isolate->counters()->gc_last_resort_from_js()->Increment(); | 13223 isolate->counters()->gc_last_resort_from_js()->Increment(); |
13226 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, | 13224 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, |
13227 "Runtime::PerformGC"); | 13225 "Runtime::PerformGC"); |
13228 } | 13226 } |
13229 } | 13227 } |
13230 | 13228 |
13231 | 13229 |
13232 } } // namespace v8::internal | 13230 } } // namespace v8::internal |
OLD | NEW |