| 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 904 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 915 | 915 |
| 916 holder->set_buffer(*buffer); | 916 holder->set_buffer(*buffer); |
| 917 holder->set_byte_offset(*byte_offset_object); | 917 holder->set_byte_offset(*byte_offset_object); |
| 918 holder->set_byte_length(*byte_length_object); | 918 holder->set_byte_length(*byte_length_object); |
| 919 | 919 |
| 920 size_t byte_offset = NumberToSize(isolate, *byte_offset_object); | 920 size_t byte_offset = NumberToSize(isolate, *byte_offset_object); |
| 921 size_t byte_length = NumberToSize(isolate, *byte_length_object); | 921 size_t byte_length = NumberToSize(isolate, *byte_length_object); |
| 922 ASSERT(byte_length % element_size == 0); | 922 ASSERT(byte_length % element_size == 0); |
| 923 size_t length = byte_length / element_size; | 923 size_t length = byte_length / element_size; |
| 924 | 924 |
| 925 if (length > static_cast<unsigned>(Smi::kMaxValue)) { |
| 926 return isolate->Throw(*isolate->factory()-> |
| 927 NewRangeError("invalid_typed_array_length", |
| 928 HandleVector<Object>(NULL, 0))); |
| 929 } |
| 930 |
| 925 Handle<Object> length_obj = isolate->factory()->NewNumberFromSize(length); | 931 Handle<Object> length_obj = isolate->factory()->NewNumberFromSize(length); |
| 926 holder->set_length(*length_obj); | 932 holder->set_length(*length_obj); |
| 927 holder->set_weak_next(buffer->weak_first_view()); | 933 holder->set_weak_next(buffer->weak_first_view()); |
| 928 buffer->set_weak_first_view(*holder); | 934 buffer->set_weak_first_view(*holder); |
| 929 | 935 |
| 930 Handle<ExternalArray> elements = | 936 Handle<ExternalArray> elements = |
| 931 isolate->factory()->NewExternalArray( | 937 isolate->factory()->NewExternalArray( |
| 932 static_cast<int>(length), array_type, | 938 static_cast<int>(length), array_type, |
| 933 static_cast<uint8_t*>(buffer->backing_store()) + byte_offset); | 939 static_cast<uint8_t*>(buffer->backing_store()) + byte_offset); |
| 934 holder->set_elements(*elements); | 940 holder->set_elements(*elements); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 954 for (int i = 0; i < v8::ArrayBufferView::kInternalFieldCount; i++) { | 960 for (int i = 0; i < v8::ArrayBufferView::kInternalFieldCount; i++) { |
| 955 holder->SetInternalField(i, Smi::FromInt(0)); | 961 holder->SetInternalField(i, Smi::FromInt(0)); |
| 956 } | 962 } |
| 957 | 963 |
| 958 ExternalArrayType array_type = kExternalByteArray; // Bogus initialization. | 964 ExternalArrayType array_type = kExternalByteArray; // Bogus initialization. |
| 959 size_t element_size = 1; // Bogus initialization. | 965 size_t element_size = 1; // Bogus initialization. |
| 960 ArrayIdToTypeAndSize(arrayId, &array_type, &element_size); | 966 ArrayIdToTypeAndSize(arrayId, &array_type, &element_size); |
| 961 | 967 |
| 962 Handle<JSArrayBuffer> buffer = isolate->factory()->NewJSArrayBuffer(); | 968 Handle<JSArrayBuffer> buffer = isolate->factory()->NewJSArrayBuffer(); |
| 963 size_t length = NumberToSize(isolate, *length_obj); | 969 size_t length = NumberToSize(isolate, *length_obj); |
| 964 if (length > (kMaxInt / element_size)) { | 970 |
| 971 if ((length > static_cast<unsigned>(Smi::kMaxValue)) || |
| 972 (length > (kMaxInt / element_size))) { |
| 965 return isolate->Throw(*isolate->factory()-> | 973 return isolate->Throw(*isolate->factory()-> |
| 966 NewRangeError("invalid_array_buffer_length", | 974 NewRangeError("invalid_typed_array_length", |
| 967 HandleVector<Object>(NULL, 0))); | 975 HandleVector<Object>(NULL, 0))); |
| 968 } | 976 } |
| 969 size_t byte_length = length * element_size; | 977 size_t byte_length = length * element_size; |
| 970 | 978 |
| 971 // NOTE: not initializing backing store. | 979 // NOTE: not initializing backing store. |
| 972 // We assume that the caller of this function will initialize holder | 980 // We assume that the caller of this function will initialize holder |
| 973 // with the loop | 981 // with the loop |
| 974 // for(i = 0; i < length; i++) { holder[i] = source[i]; } | 982 // for(i = 0; i < length; i++) { holder[i] = source[i]; } |
| 975 // We assume that the caller of this function is always a typed array | 983 // We assume that the caller of this function is always a typed array |
| 976 // constructor. | 984 // constructor. |
| (...skipping 13805 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14782 : reinterpret_cast<Arguments*>(args[0]); | 14790 : reinterpret_cast<Arguments*>(args[0]); |
| 14783 CONVERT_ARG_HANDLE_CHECKED(JSFunction, constructor, parameters_start); | 14791 CONVERT_ARG_HANDLE_CHECKED(JSFunction, constructor, parameters_start); |
| 14784 | 14792 |
| 14785 return ArrayConstructorCommon(isolate, | 14793 return ArrayConstructorCommon(isolate, |
| 14786 constructor, | 14794 constructor, |
| 14787 Handle<Object>::null(), | 14795 Handle<Object>::null(), |
| 14788 caller_args); | 14796 caller_args); |
| 14789 } | 14797 } |
| 14790 | 14798 |
| 14791 | 14799 |
| 14800 RUNTIME_FUNCTION(MaybeObject*, Runtime_MaxSmi) { |
| 14801 return Smi::FromInt(Smi::kMaxValue); |
| 14802 } |
| 14803 |
| 14804 |
| 14792 // ---------------------------------------------------------------------------- | 14805 // ---------------------------------------------------------------------------- |
| 14793 // Implementation of Runtime | 14806 // Implementation of Runtime |
| 14794 | 14807 |
| 14795 #define F(name, number_of_args, result_size) \ | 14808 #define F(name, number_of_args, result_size) \ |
| 14796 { Runtime::k##name, Runtime::RUNTIME, #name, \ | 14809 { Runtime::k##name, Runtime::RUNTIME, #name, \ |
| 14797 FUNCTION_ADDR(Runtime_##name), number_of_args, result_size }, | 14810 FUNCTION_ADDR(Runtime_##name), number_of_args, result_size }, |
| 14798 | 14811 |
| 14799 | 14812 |
| 14800 #define I(name, number_of_args, result_size) \ | 14813 #define I(name, number_of_args, result_size) \ |
| 14801 { Runtime::kInline##name, Runtime::INLINE, \ | 14814 { Runtime::kInline##name, Runtime::INLINE, \ |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14866 // Handle last resort GC and make sure to allow future allocations | 14879 // Handle last resort GC and make sure to allow future allocations |
| 14867 // to grow the heap without causing GCs (if possible). | 14880 // to grow the heap without causing GCs (if possible). |
| 14868 isolate->counters()->gc_last_resort_from_js()->Increment(); | 14881 isolate->counters()->gc_last_resort_from_js()->Increment(); |
| 14869 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, | 14882 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, |
| 14870 "Runtime::PerformGC"); | 14883 "Runtime::PerformGC"); |
| 14871 } | 14884 } |
| 14872 } | 14885 } |
| 14873 | 14886 |
| 14874 | 14887 |
| 14875 } } // namespace v8::internal | 14888 } } // namespace v8::internal |
| OLD | NEW |