Chromium Code Reviews| 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 761 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 772 if (target_length == 0) return isolate->heap()->undefined_value(); | 772 if (target_length == 0) return isolate->heap()->undefined_value(); |
| 773 | 773 |
| 774 ASSERT(NumberToSize(isolate, source->byte_length()) - target_length >= start); | 774 ASSERT(NumberToSize(isolate, source->byte_length()) - target_length >= start); |
| 775 uint8_t* source_data = reinterpret_cast<uint8_t*>(source->backing_store()); | 775 uint8_t* source_data = reinterpret_cast<uint8_t*>(source->backing_store()); |
| 776 uint8_t* target_data = reinterpret_cast<uint8_t*>(target->backing_store()); | 776 uint8_t* target_data = reinterpret_cast<uint8_t*>(target->backing_store()); |
| 777 CopyBytes(target_data, source_data + start, target_length); | 777 CopyBytes(target_data, source_data + start, target_length); |
| 778 return isolate->heap()->undefined_value(); | 778 return isolate->heap()->undefined_value(); |
| 779 } | 779 } |
| 780 | 780 |
| 781 | 781 |
| 782 RUNTIME_FUNCTION(MaybeObject*, Runtime_DataViewInitialize) { | |
| 783 HandleScope scope(isolate); | |
| 784 ASSERT(args.length() == 4); | |
| 785 CONVERT_ARG_HANDLE_CHECKED(JSDataView, holder, 0); | |
| 786 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, buffer, 1); | |
| 787 CONVERT_ARG_HANDLE_CHECKED(Object, byte_offset_object, 2); | |
| 788 CONVERT_ARG_HANDLE_CHECKED(Object, byte_length_object, 3); | |
| 789 | |
| 790 holder->set_buffer(*buffer); | |
| 791 holder->set_byte_offset(*byte_offset_object); | |
| 792 holder->set_byte_length(*byte_length_object); | |
| 793 | |
| 794 Handle<Map> map = | |
| 795 isolate->factory()->GetElementsTransitionMap( | |
| 796 holder, EXTERNAL_UNSIGNED_BYTE_ELEMENTS); | |
| 797 holder->set_map(*map); | |
| 798 return isolate->heap()->undefined_value(); | |
| 799 } | |
| 800 | |
| 801 | |
| 802 #define DATA_VIEW_GETTER(getter, accessor) \ | |
|
bnoordhuis
2013/05/23 22:59:04
These could be merged / DRY'd with the code in src
Sven Panne
2013/05/24 06:58:25
Whatever you do, we shouldn't land this with pages
| |
| 803 RUNTIME_FUNCTION(MaybeObject*, Runtime_DataViewGet##getter) { \ | |
| 804 HandleScope scope(isolate); \ | |
| 805 ASSERT(args.length() == 1); \ | |
| 806 CONVERT_ARG_HANDLE_CHECKED(JSDataView, holder, 0); \ | |
| 807 return (*holder)->accessor(); \ | |
| 808 } | |
| 809 | |
| 810 #define DATA_VIEW_GETTER_SWIZZLE(FunctionName, TypeName, ReturnValue) \ | |
| 811 RUNTIME_FUNCTION(MaybeObject*, Runtime_DataView ## FunctionName) { \ | |
| 812 HandleScope scope(isolate); \ | |
| 813 ASSERT(args.length() == 3); \ | |
| 814 CONVERT_ARG_HANDLE_CHECKED(JSDataView, holder, 0); \ | |
| 815 CONVERT_SMI_ARG_CHECKED(byte_offset, 1); \ | |
| 816 CONVERT_BOOLEAN_ARG_CHECKED(little_endian, 2); \ | |
| 817 ASSERT(byte_offset >= 0); \ | |
| 818 Handle<JSArrayBuffer> buffer(JSArrayBuffer::cast(holder->buffer())); \ | |
| 819 ASSERT(byte_offset + sizeof(TypeName) <= buffer->byte_length()->Number());\ | |
| 820 const char* data = static_cast<const char*>(buffer->backing_store()) + \ | |
| 821 static_cast<size_t>(holder->byte_offset()->Number()) + \ | |
| 822 byte_offset; \ | |
| 823 TypeName value; \ | |
| 824 OS::MemCopy(&value, data, sizeof(value)); \ | |
| 825 /* Swizzle only when native endianness differs from requested one. */ \ | |
| 826 if (little_endian ^ IsLittleEndian()) Swizzle(&value); \ | |
| 827 return ReturnValue; \ | |
| 828 } | |
| 829 | |
| 830 #define DATA_VIEW_SETTER_SWIZZLE(FunctionName, TypeName) \ | |
| 831 RUNTIME_FUNCTION(MaybeObject*, Runtime_DataView ## FunctionName) { \ | |
| 832 HandleScope scope(isolate); \ | |
| 833 ASSERT(args.length() == 4); \ | |
| 834 CONVERT_ARG_HANDLE_CHECKED(JSDataView, holder, 0); \ | |
| 835 CONVERT_SMI_ARG_CHECKED(byte_offset, 1); \ | |
| 836 TypeName value; \ | |
| 837 if (args[2]->IsSmi()) { \ | |
| 838 value = args.smi_at(2); \ | |
| 839 } else { \ | |
| 840 RUNTIME_ASSERT(args[2]->IsNumber()); \ | |
| 841 value = args.number_at(2); \ | |
| 842 } \ | |
| 843 CONVERT_BOOLEAN_ARG_CHECKED(little_endian, 3); \ | |
| 844 ASSERT(byte_offset >= 0); \ | |
| 845 Handle<JSArrayBuffer> buffer(JSArrayBuffer::cast(holder->buffer())); \ | |
| 846 ASSERT(byte_offset + sizeof(TypeName) <= buffer->byte_length()->Number());\ | |
| 847 char* data = static_cast<char*>(buffer->backing_store()) + \ | |
| 848 static_cast<size_t>(holder->byte_offset()->Number()) + \ | |
| 849 byte_offset; \ | |
| 850 /* Swizzle only when native endianness differs from requested one. */ \ | |
| 851 if (little_endian ^ IsLittleEndian()) Swizzle(&value); \ | |
| 852 OS::MemCopy(data, &value, sizeof(value)); \ | |
| 853 return isolate->heap()->undefined_value(); \ | |
| 854 } | |
| 855 | |
| 856 DATA_VIEW_GETTER(Buffer, buffer) | |
| 857 DATA_VIEW_GETTER(ByteLength, byte_length) | |
| 858 DATA_VIEW_GETTER(ByteOffset, byte_offset) | |
| 859 | |
| 860 DATA_VIEW_GETTER_SWIZZLE(GetInt8, int8_t, Smi::FromInt(value)) | |
| 861 DATA_VIEW_GETTER_SWIZZLE(GetUint8, uint8_t, Smi::FromInt(value)) | |
| 862 DATA_VIEW_GETTER_SWIZZLE(GetInt16, int16_t, Smi::FromInt(value)) | |
| 863 DATA_VIEW_GETTER_SWIZZLE(GetUint16, uint16_t, Smi::FromInt(value)) | |
| 864 DATA_VIEW_GETTER_SWIZZLE(GetInt32, | |
| 865 int32_t, | |
| 866 isolate->heap()->NumberFromInt32(value)) | |
| 867 DATA_VIEW_GETTER_SWIZZLE(GetUint32, | |
| 868 uint32_t, | |
| 869 isolate->heap()->NumberFromUint32(value)) | |
| 870 DATA_VIEW_GETTER_SWIZZLE(GetFloat32, | |
| 871 float, | |
| 872 isolate->heap()->NumberFromDouble(value)) | |
| 873 DATA_VIEW_GETTER_SWIZZLE(GetFloat64, | |
| 874 double, | |
| 875 isolate->heap()->NumberFromDouble(value)) | |
| 876 | |
| 877 DATA_VIEW_SETTER_SWIZZLE(SetInt8, int8_t) | |
| 878 DATA_VIEW_SETTER_SWIZZLE(SetUint8, uint8_t) | |
| 879 DATA_VIEW_SETTER_SWIZZLE(SetInt16, int16_t) | |
| 880 DATA_VIEW_SETTER_SWIZZLE(SetUint16, uint16_t) | |
| 881 DATA_VIEW_SETTER_SWIZZLE(SetInt32, int32_t) | |
| 882 DATA_VIEW_SETTER_SWIZZLE(SetUint32, uint32_t) | |
| 883 DATA_VIEW_SETTER_SWIZZLE(SetFloat32, float) | |
| 884 DATA_VIEW_SETTER_SWIZZLE(SetFloat64, double) | |
| 885 | |
| 886 #undef DATA_VIEW_SETTER_SWIZZLE | |
| 887 #undef DATA_VIEW_GETTER_SWIZZLE | |
| 888 #undef DATA_VIEW_GETTER | |
| 889 | |
| 782 enum TypedArrayId { | 890 enum TypedArrayId { |
| 783 // arrayIds below should be synchromized with typedarray.js natives. | 891 // arrayIds below should be synchromized with typedarray.js natives. |
| 784 ARRAY_ID_UINT8 = 1, | 892 ARRAY_ID_UINT8 = 1, |
| 785 ARRAY_ID_INT8 = 2, | 893 ARRAY_ID_INT8 = 2, |
| 786 ARRAY_ID_UINT16 = 3, | 894 ARRAY_ID_UINT16 = 3, |
| 787 ARRAY_ID_INT16 = 4, | 895 ARRAY_ID_INT16 = 4, |
| 788 ARRAY_ID_UINT32 = 5, | 896 ARRAY_ID_UINT32 = 5, |
| 789 ARRAY_ID_INT32 = 6, | 897 ARRAY_ID_INT32 = 6, |
| 790 ARRAY_ID_FLOAT32 = 7, | 898 ARRAY_ID_FLOAT32 = 7, |
| 791 ARRAY_ID_FLOAT64 = 8, | 899 ARRAY_ID_FLOAT64 = 8, |
| (...skipping 12722 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 13514 // Handle last resort GC and make sure to allow future allocations | 13622 // Handle last resort GC and make sure to allow future allocations |
| 13515 // to grow the heap without causing GCs (if possible). | 13623 // to grow the heap without causing GCs (if possible). |
| 13516 isolate->counters()->gc_last_resort_from_js()->Increment(); | 13624 isolate->counters()->gc_last_resort_from_js()->Increment(); |
| 13517 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, | 13625 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, |
| 13518 "Runtime::PerformGC"); | 13626 "Runtime::PerformGC"); |
| 13519 } | 13627 } |
| 13520 } | 13628 } |
| 13521 | 13629 |
| 13522 | 13630 |
| 13523 } } // namespace v8::internal | 13631 } } // namespace v8::internal |
| OLD | NEW |