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 899 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
910 | 910 |
911 holder->set_buffer(*buffer); | 911 holder->set_buffer(*buffer); |
912 holder->set_byte_offset(*byte_offset_object); | 912 holder->set_byte_offset(*byte_offset_object); |
913 holder->set_byte_length(*byte_length_object); | 913 holder->set_byte_length(*byte_length_object); |
914 | 914 |
915 size_t byte_offset = NumberToSize(isolate, *byte_offset_object); | 915 size_t byte_offset = NumberToSize(isolate, *byte_offset_object); |
916 size_t byte_length = NumberToSize(isolate, *byte_length_object); | 916 size_t byte_length = NumberToSize(isolate, *byte_length_object); |
917 ASSERT(byte_length % element_size == 0); | 917 ASSERT(byte_length % element_size == 0); |
918 size_t length = byte_length / element_size; | 918 size_t length = byte_length / element_size; |
919 | 919 |
920 if (length > static_cast<unsigned>(Smi::kMaxValue)) { | |
921 return isolate->Throw(*isolate->factory()-> | |
922 NewRangeError("invalid_array_buffer_length", | |
923 HandleVector<Object>(NULL, 0))); | |
924 } | |
925 | |
926 Handle<Object> length_obj = isolate->factory()->NewNumberFromSize(length); | 920 Handle<Object> length_obj = isolate->factory()->NewNumberFromSize(length); |
927 holder->set_length(*length_obj); | 921 holder->set_length(*length_obj); |
928 holder->set_weak_next(buffer->weak_first_view()); | 922 holder->set_weak_next(buffer->weak_first_view()); |
929 buffer->set_weak_first_view(*holder); | 923 buffer->set_weak_first_view(*holder); |
930 | 924 |
931 Handle<ExternalArray> elements = | 925 Handle<ExternalArray> elements = |
932 isolate->factory()->NewExternalArray( | 926 isolate->factory()->NewExternalArray( |
933 static_cast<int>(length), array_type, | 927 static_cast<int>(length), array_type, |
934 static_cast<uint8_t*>(buffer->backing_store()) + byte_offset); | 928 static_cast<uint8_t*>(buffer->backing_store()) + byte_offset); |
935 holder->set_elements(*elements); | 929 holder->set_elements(*elements); |
(...skipping 19 matching lines...) Expand all Loading... |
955 for (int i = 0; i < v8::ArrayBufferView::kInternalFieldCount; i++) { | 949 for (int i = 0; i < v8::ArrayBufferView::kInternalFieldCount; i++) { |
956 holder->SetInternalField(i, Smi::FromInt(0)); | 950 holder->SetInternalField(i, Smi::FromInt(0)); |
957 } | 951 } |
958 | 952 |
959 ExternalArrayType array_type = kExternalByteArray; // Bogus initialization. | 953 ExternalArrayType array_type = kExternalByteArray; // Bogus initialization. |
960 size_t element_size = 1; // Bogus initialization. | 954 size_t element_size = 1; // Bogus initialization. |
961 ArrayIdToTypeAndSize(arrayId, &array_type, &element_size); | 955 ArrayIdToTypeAndSize(arrayId, &array_type, &element_size); |
962 | 956 |
963 Handle<JSArrayBuffer> buffer = isolate->factory()->NewJSArrayBuffer(); | 957 Handle<JSArrayBuffer> buffer = isolate->factory()->NewJSArrayBuffer(); |
964 size_t length = NumberToSize(isolate, *length_obj); | 958 size_t length = NumberToSize(isolate, *length_obj); |
965 | 959 if (length > (kMaxInt / element_size)) { |
966 if ((length > static_cast<unsigned>(Smi::kMaxValue)) || | |
967 (length > (kMaxInt / element_size))) { | |
968 return isolate->Throw(*isolate->factory()-> | 960 return isolate->Throw(*isolate->factory()-> |
969 NewRangeError("invalid_array_buffer_length", | 961 NewRangeError("invalid_array_buffer_length", |
970 HandleVector<Object>(NULL, 0))); | 962 HandleVector<Object>(NULL, 0))); |
971 } | 963 } |
972 size_t byte_length = length * element_size; | 964 size_t byte_length = length * element_size; |
973 | 965 |
974 // NOTE: not initializing backing store. | 966 // NOTE: not initializing backing store. |
975 // We assume that the caller of this function will initialize holder | 967 // We assume that the caller of this function will initialize holder |
976 // with the loop | 968 // with the loop |
977 // for(i = 0; i < length; i++) { holder[i] = source[i]; } | 969 // for(i = 0; i < length; i++) { holder[i] = source[i]; } |
(...skipping 13832 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14810 ASSERT(arg_count == caller_args->length()); | 14802 ASSERT(arg_count == caller_args->length()); |
14811 } | 14803 } |
14812 #endif | 14804 #endif |
14813 return ArrayConstructorCommon(isolate, | 14805 return ArrayConstructorCommon(isolate, |
14814 constructor, | 14806 constructor, |
14815 Handle<AllocationSite>::null(), | 14807 Handle<AllocationSite>::null(), |
14816 caller_args); | 14808 caller_args); |
14817 } | 14809 } |
14818 | 14810 |
14819 | 14811 |
14820 RUNTIME_FUNCTION(MaybeObject*, Runtime_MaxSmi) { | |
14821 return Smi::FromInt(Smi::kMaxValue); | |
14822 } | |
14823 | |
14824 | |
14825 // ---------------------------------------------------------------------------- | 14812 // ---------------------------------------------------------------------------- |
14826 // Implementation of Runtime | 14813 // Implementation of Runtime |
14827 | 14814 |
14828 #define F(name, number_of_args, result_size) \ | 14815 #define F(name, number_of_args, result_size) \ |
14829 { Runtime::k##name, Runtime::RUNTIME, #name, \ | 14816 { Runtime::k##name, Runtime::RUNTIME, #name, \ |
14830 FUNCTION_ADDR(Runtime_##name), number_of_args, result_size }, | 14817 FUNCTION_ADDR(Runtime_##name), number_of_args, result_size }, |
14831 | 14818 |
14832 | 14819 |
14833 #define I(name, number_of_args, result_size) \ | 14820 #define I(name, number_of_args, result_size) \ |
14834 { Runtime::kInline##name, Runtime::INLINE, \ | 14821 { Runtime::kInline##name, Runtime::INLINE, \ |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14899 // Handle last resort GC and make sure to allow future allocations | 14886 // Handle last resort GC and make sure to allow future allocations |
14900 // to grow the heap without causing GCs (if possible). | 14887 // to grow the heap without causing GCs (if possible). |
14901 isolate->counters()->gc_last_resort_from_js()->Increment(); | 14888 isolate->counters()->gc_last_resort_from_js()->Increment(); |
14902 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, | 14889 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, |
14903 "Runtime::PerformGC"); | 14890 "Runtime::PerformGC"); |
14904 } | 14891 } |
14905 } | 14892 } |
14906 | 14893 |
14907 | 14894 |
14908 } } // namespace v8::internal | 14895 } } // namespace v8::internal |
OLD | NEW |