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 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
631 | 631 |
632 RUNTIME_FUNCTION(MaybeObject*, Runtime_Fix) { | 632 RUNTIME_FUNCTION(MaybeObject*, Runtime_Fix) { |
633 NoHandleAllocation ha(isolate); | 633 NoHandleAllocation ha(isolate); |
634 ASSERT(args.length() == 1); | 634 ASSERT(args.length() == 1); |
635 CONVERT_ARG_CHECKED(JSProxy, proxy, 0); | 635 CONVERT_ARG_CHECKED(JSProxy, proxy, 0); |
636 proxy->Fix(); | 636 proxy->Fix(); |
637 return isolate->heap()->undefined_value(); | 637 return isolate->heap()->undefined_value(); |
638 } | 638 } |
639 | 639 |
640 | 640 |
641 static size_t ArrayBufferAllocatedLength(Isolate* isolate, | 641 static size_t NumberToSize(Isolate* isolate, |
rossberg
2013/04/15 13:11:03
This should probably move to v8conversions.
Dmitry Lomov (no reviews)
2013/04/15 15:40:58
Done.
| |
642 JSArrayBuffer* buffer) { | 642 Object* number) { |
643 NoHandleAllocation hc(isolate); | 643 NoHandleAllocation hc(isolate); |
644 Object* byte_length = buffer->byte_length(); | 644 if (number->IsSmi()) { |
645 if (byte_length->IsSmi()) { | 645 return Smi::cast(number)->value(); |
646 return Smi::cast(byte_length)->value(); | |
647 } else { | 646 } else { |
648 double value = HeapNumber::cast(byte_length)->value(); | 647 ASSERT(number->IsHeapNumber()); |
648 double value = HeapNumber::cast(number)->value(); | |
649 return static_cast<size_t>(value); | 649 return static_cast<size_t>(value); |
650 } | 650 } |
651 } | 651 } |
652 | 652 |
653 | 653 |
654 static void ArrayBufferWeakCallback(v8::Isolate* external_isolate, | 654 static void ArrayBufferWeakCallback(v8::Isolate* external_isolate, |
655 Persistent<Value> object, | 655 Persistent<Value> object, |
656 void* data) { | 656 void* data) { |
657 Isolate* isolate = reinterpret_cast<Isolate*>(external_isolate); | 657 Isolate* isolate = reinterpret_cast<Isolate*>(external_isolate); |
658 HandleScope scope(isolate); | 658 HandleScope scope(isolate); |
659 Handle<Object> internal_object = Utils::OpenHandle(*object); | 659 Handle<Object> internal_object = Utils::OpenHandle(*object); |
660 | 660 |
661 size_t allocated_length = ArrayBufferAllocatedLength( | 661 size_t allocated_length = NumberToSize( |
662 isolate, JSArrayBuffer::cast(*internal_object)); | 662 isolate, JSArrayBuffer::cast(*internal_object)->byte_length()); |
663 isolate->heap()->AdjustAmountOfExternalAllocatedMemory( | 663 isolate->heap()->AdjustAmountOfExternalAllocatedMemory( |
664 -static_cast<intptr_t>(allocated_length)); | 664 -static_cast<intptr_t>(allocated_length)); |
665 if (data != NULL) | 665 if (data != NULL) |
666 free(data); | 666 free(data); |
667 object.Dispose(external_isolate); | 667 object.Dispose(external_isolate); |
668 } | 668 } |
669 | 669 |
670 | 670 |
671 RUNTIME_FUNCTION(MaybeObject*, Runtime_ArrayBufferInitialize) { | 671 RUNTIME_FUNCTION(MaybeObject*, Runtime_ArrayBufferInitialize) { |
672 HandleScope scope(isolate); | 672 HandleScope scope(isolate); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
737 } | 737 } |
738 | 738 |
739 | 739 |
740 RUNTIME_FUNCTION(MaybeObject*, Runtime_ArrayBufferSliceImpl) { | 740 RUNTIME_FUNCTION(MaybeObject*, Runtime_ArrayBufferSliceImpl) { |
741 HandleScope scope(isolate); | 741 HandleScope scope(isolate); |
742 ASSERT(args.length() == 3); | 742 ASSERT(args.length() == 3); |
743 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, source, 0); | 743 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, source, 0); |
744 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, target, 1); | 744 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, target, 1); |
745 CONVERT_DOUBLE_ARG_CHECKED(first, 2); | 745 CONVERT_DOUBLE_ARG_CHECKED(first, 2); |
746 size_t start = static_cast<size_t>(first); | 746 size_t start = static_cast<size_t>(first); |
747 size_t target_length = ArrayBufferAllocatedLength(isolate, *target); | 747 size_t target_length = NumberToSize(isolate, target->byte_length()); |
748 | 748 |
749 if (target_length == 0) | 749 if (target_length == 0) |
750 return isolate->heap()->undefined_value(); | 750 return isolate->heap()->undefined_value(); |
751 | 751 |
752 ASSERT(ArrayBufferAllocatedLength(isolate, *source) - target_length >= start); | 752 ASSERT(NumberToSize(isolate, source->byte_length()) - target_length >= start); |
753 uint8_t* source_data = reinterpret_cast<uint8_t*>(source->backing_store()); | 753 uint8_t* source_data = reinterpret_cast<uint8_t*>(source->backing_store()); |
754 uint8_t* target_data = reinterpret_cast<uint8_t*>(target->backing_store()); | 754 uint8_t* target_data = reinterpret_cast<uint8_t*>(target->backing_store()); |
755 CopyBytes(target_data, source_data + start, target_length); | 755 CopyBytes(target_data, source_data + start, target_length); |
756 return isolate->heap()->undefined_value(); | 756 return isolate->heap()->undefined_value(); |
757 } | 757 } |
758 | 758 |
759 | 759 |
760 RUNTIME_FUNCTION(MaybeObject*, Runtime_TypedArrayInitialize) { | |
761 HandleScope scope(isolate); | |
762 ASSERT(args.length() == 6); | |
763 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, holder, 0); | |
764 CONVERT_SMI_ARG_CHECKED(arrayId, 1); | |
765 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, buffer, 2); | |
766 CONVERT_ARG_HANDLE_CHECKED(Object, byte_offset_object, 3); | |
767 CONVERT_ARG_HANDLE_CHECKED(Object, length_object, 4); | |
768 CONVERT_ARG_HANDLE_CHECKED(Object, byte_length_object, 5); | |
769 | |
770 ExternalArrayType arrayType; | |
771 ElementsKind elementsKind; | |
772 size_t elementSize; | |
773 // arrayIds below should be synchromized with typedarray.js natives. | |
774 switch (arrayId) { | |
775 case 1: | |
rossberg
2013/04/15 13:11:03
Can we define an enum for that?
Dmitry Lomov (no reviews)
2013/04/15 15:40:58
Done.
| |
776 elementsKind = EXTERNAL_UNSIGNED_BYTE_ELEMENTS; | |
777 arrayType = kExternalUnsignedByteArray; | |
778 elementSize = 1; | |
779 break; | |
780 case 2: | |
781 elementsKind = EXTERNAL_BYTE_ELEMENTS; | |
782 arrayType = kExternalByteArray; | |
783 elementSize = 1; | |
784 break; | |
785 case 3: | |
786 elementsKind = EXTERNAL_UNSIGNED_SHORT_ELEMENTS; | |
787 arrayType = kExternalUnsignedShortArray; | |
788 elementSize = 2; | |
789 break; | |
790 case 4: | |
791 elementsKind = EXTERNAL_SHORT_ELEMENTS; | |
792 arrayType = kExternalShortArray; | |
793 elementSize = 2; | |
794 break; | |
795 case 5: | |
796 elementsKind = EXTERNAL_UNSIGNED_INT_ELEMENTS; | |
797 arrayType = kExternalUnsignedIntArray; | |
798 elementSize = 4; | |
799 break; | |
800 case 6: | |
801 elementsKind = EXTERNAL_INT_ELEMENTS; | |
802 arrayType = kExternalIntArray; | |
803 elementSize = 4; | |
804 break; | |
805 case 7: | |
806 elementsKind = EXTERNAL_FLOAT_ELEMENTS; | |
807 arrayType = kExternalFloatArray; | |
808 elementSize = 4; | |
809 break; | |
810 case 8: | |
811 elementsKind = EXTERNAL_DOUBLE_ELEMENTS; | |
812 arrayType = kExternalDoubleArray; | |
813 elementSize = 8; | |
814 break; | |
815 default: | |
816 ASSERT(false); | |
rossberg
2013/04/15 13:11:03
You can use UNREACHABLE() here. Also, the NULL ret
Dmitry Lomov (no reviews)
2013/04/15 15:40:58
Done.
| |
817 return NULL; | |
818 } | |
819 holder->set_buffer(*buffer); | |
820 holder->set_byte_offset(*byte_offset_object); | |
821 holder->set_byte_length(*byte_length_object); | |
822 holder->set_length(*length_object); | |
823 | |
824 size_t byte_offset = NumberToSize(isolate, *byte_offset_object); | |
825 size_t byte_length = NumberToSize(isolate, *byte_length_object); | |
826 size_t length = NumberToSize(isolate, *length_object); | |
827 ASSERT(length * elementSize == byte_length); | |
rossberg
2013/04/15 13:11:03
Given this invariant, why not drop the byte_length
Dmitry Lomov (no reviews)
2013/04/15 15:40:58
Done. The invariant helped me find some bugs in pr
| |
828 Handle<ExternalArray> elements = | |
829 isolate->factory()->NewExternalArray( | |
830 length, arrayType, | |
831 static_cast<uint8_t*>(buffer->backing_store()) + byte_offset); | |
832 Handle<Map> map = | |
833 isolate->factory()->GetElementsTransitionMap( | |
834 holder, elementsKind); | |
rossberg
2013/04/15 13:11:03
Nit: should fit on the previous line
Dmitry Lomov (no reviews)
2013/04/15 15:40:58
Done.
| |
835 holder->set_map(*map); | |
836 holder->set_elements(*elements); | |
837 return isolate->heap()->undefined_value(); | |
838 } | |
839 | |
rossberg
2013/04/15 13:11:03
Style: add extra newline
Dmitry Lomov (no reviews)
2013/04/15 15:40:58
Done.
| |
840 #define TYPED_ARRAY_GETTER(getter, accessor) \ | |
841 RUNTIME_FUNCTION(MaybeObject*, Runtime_TypedArrayGet##getter) { \ | |
842 HandleScope scope(isolate); \ | |
843 ASSERT(args.length() == 1); \ | |
844 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, holder, 0); \ | |
845 return holder->accessor(); \ | |
846 } | |
847 | |
848 TYPED_ARRAY_GETTER(Buffer, buffer) | |
849 TYPED_ARRAY_GETTER(ByteLength, byte_length) | |
850 TYPED_ARRAY_GETTER(ByteOffset, byte_offset) | |
851 TYPED_ARRAY_GETTER(Length, length) | |
852 | |
853 #undef TYPED_ARRAY_GETTER | |
854 | |
rossberg
2013/04/15 13:11:03
Style: add another newline
Dmitry Lomov (no reviews)
2013/04/15 15:40:58
Done.
| |
760 RUNTIME_FUNCTION(MaybeObject*, Runtime_SetInitialize) { | 855 RUNTIME_FUNCTION(MaybeObject*, Runtime_SetInitialize) { |
761 HandleScope scope(isolate); | 856 HandleScope scope(isolate); |
762 ASSERT(args.length() == 1); | 857 ASSERT(args.length() == 1); |
763 CONVERT_ARG_HANDLE_CHECKED(JSSet, holder, 0); | 858 CONVERT_ARG_HANDLE_CHECKED(JSSet, holder, 0); |
764 Handle<ObjectHashSet> table = isolate->factory()->NewObjectHashSet(0); | 859 Handle<ObjectHashSet> table = isolate->factory()->NewObjectHashSet(0); |
765 holder->set_table(*table); | 860 holder->set_table(*table); |
766 return *holder; | 861 return *holder; |
767 } | 862 } |
768 | 863 |
769 | 864 |
(...skipping 12314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
13084 // Handle last resort GC and make sure to allow future allocations | 13179 // Handle last resort GC and make sure to allow future allocations |
13085 // to grow the heap without causing GCs (if possible). | 13180 // to grow the heap without causing GCs (if possible). |
13086 isolate->counters()->gc_last_resort_from_js()->Increment(); | 13181 isolate->counters()->gc_last_resort_from_js()->Increment(); |
13087 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, | 13182 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, |
13088 "Runtime::PerformGC"); | 13183 "Runtime::PerformGC"); |
13089 } | 13184 } |
13090 } | 13185 } |
13091 | 13186 |
13092 | 13187 |
13093 } } // namespace v8::internal | 13188 } } // namespace v8::internal |
OLD | NEW |