| 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 890 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 901 | 901 |
| 902 holder->set_buffer(*buffer); | 902 holder->set_buffer(*buffer); |
| 903 holder->set_byte_offset(*byte_offset_object); | 903 holder->set_byte_offset(*byte_offset_object); |
| 904 holder->set_byte_length(*byte_length_object); | 904 holder->set_byte_length(*byte_length_object); |
| 905 | 905 |
| 906 size_t byte_offset = NumberToSize(isolate, *byte_offset_object); | 906 size_t byte_offset = NumberToSize(isolate, *byte_offset_object); |
| 907 size_t byte_length = NumberToSize(isolate, *byte_length_object); | 907 size_t byte_length = NumberToSize(isolate, *byte_length_object); |
| 908 ASSERT(byte_length % element_size == 0); | 908 ASSERT(byte_length % element_size == 0); |
| 909 size_t length = byte_length / element_size; | 909 size_t length = byte_length / element_size; |
| 910 | 910 |
| 911 if (length > static_cast<unsigned>(Smi::kMaxValue)) { |
| 912 return isolate->Throw(*isolate->factory()-> |
| 913 NewRangeError("invalid_typed_array_length", |
| 914 HandleVector<Object>(NULL, 0))); |
| 915 } |
| 916 |
| 911 Handle<Object> length_obj = isolate->factory()->NewNumberFromSize(length); | 917 Handle<Object> length_obj = isolate->factory()->NewNumberFromSize(length); |
| 912 holder->set_length(*length_obj); | 918 holder->set_length(*length_obj); |
| 913 holder->set_weak_next(buffer->weak_first_view()); | 919 holder->set_weak_next(buffer->weak_first_view()); |
| 914 buffer->set_weak_first_view(*holder); | 920 buffer->set_weak_first_view(*holder); |
| 915 | 921 |
| 916 Handle<ExternalArray> elements = | 922 Handle<ExternalArray> elements = |
| 917 isolate->factory()->NewExternalArray( | 923 isolate->factory()->NewExternalArray( |
| 918 static_cast<int>(length), array_type, | 924 static_cast<int>(length), array_type, |
| 919 static_cast<uint8_t*>(buffer->backing_store()) + byte_offset); | 925 static_cast<uint8_t*>(buffer->backing_store()) + byte_offset); |
| 920 holder->set_elements(*elements); | 926 holder->set_elements(*elements); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 940 for (int i = 0; i < v8::ArrayBufferView::kInternalFieldCount; i++) { | 946 for (int i = 0; i < v8::ArrayBufferView::kInternalFieldCount; i++) { |
| 941 holder->SetInternalField(i, Smi::FromInt(0)); | 947 holder->SetInternalField(i, Smi::FromInt(0)); |
| 942 } | 948 } |
| 943 | 949 |
| 944 ExternalArrayType array_type = kExternalByteArray; // Bogus initialization. | 950 ExternalArrayType array_type = kExternalByteArray; // Bogus initialization. |
| 945 size_t element_size = 1; // Bogus initialization. | 951 size_t element_size = 1; // Bogus initialization. |
| 946 ArrayIdToTypeAndSize(arrayId, &array_type, &element_size); | 952 ArrayIdToTypeAndSize(arrayId, &array_type, &element_size); |
| 947 | 953 |
| 948 Handle<JSArrayBuffer> buffer = isolate->factory()->NewJSArrayBuffer(); | 954 Handle<JSArrayBuffer> buffer = isolate->factory()->NewJSArrayBuffer(); |
| 949 size_t length = NumberToSize(isolate, *length_obj); | 955 size_t length = NumberToSize(isolate, *length_obj); |
| 950 if (length > (kMaxInt / element_size)) { | 956 |
| 957 if ((length > static_cast<unsigned>(Smi::kMaxValue)) || |
| 958 (length > (kMaxInt / element_size))) { |
| 951 return isolate->Throw(*isolate->factory()-> | 959 return isolate->Throw(*isolate->factory()-> |
| 952 NewRangeError("invalid_array_buffer_length", | 960 NewRangeError("invalid_typed_array_length", |
| 953 HandleVector<Object>(NULL, 0))); | 961 HandleVector<Object>(NULL, 0))); |
| 954 } | 962 } |
| 955 size_t byte_length = length * element_size; | 963 size_t byte_length = length * element_size; |
| 956 | 964 |
| 957 // We assume that the caller of this function will initialize holder | 965 // We assume that the caller of this function will initialize holder |
| 958 // with the loop | 966 // with the loop |
| 959 // for(i = 0; i < length; i++) { holder[i] = source[i]; } | 967 // for(i = 0; i < length; i++) { holder[i] = source[i]; } |
| 960 // If source is a typed array, this loop will always run to completion, | 968 // If source is a typed array, this loop will always run to completion, |
| 961 // so we are sure that the backing store will be initialized. | 969 // so we are sure that the backing store will be initialized. |
| 962 // Otherwise, we do not know (the indexing operation might throw). | 970 // Otherwise, we do not know (the indexing operation might throw). |
| (...skipping 13754 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14717 : reinterpret_cast<Arguments*>(args[0]); | 14725 : reinterpret_cast<Arguments*>(args[0]); |
| 14718 CONVERT_ARG_HANDLE_CHECKED(JSFunction, constructor, parameters_start); | 14726 CONVERT_ARG_HANDLE_CHECKED(JSFunction, constructor, parameters_start); |
| 14719 | 14727 |
| 14720 return ArrayConstructorCommon(isolate, | 14728 return ArrayConstructorCommon(isolate, |
| 14721 constructor, | 14729 constructor, |
| 14722 Handle<Object>::null(), | 14730 Handle<Object>::null(), |
| 14723 caller_args); | 14731 caller_args); |
| 14724 } | 14732 } |
| 14725 | 14733 |
| 14726 | 14734 |
| 14735 RUNTIME_FUNCTION(MaybeObject*, Runtime_MaxSmi) { |
| 14736 return Smi::FromInt(Smi::kMaxValue); |
| 14737 } |
| 14738 |
| 14739 |
| 14727 // ---------------------------------------------------------------------------- | 14740 // ---------------------------------------------------------------------------- |
| 14728 // Implementation of Runtime | 14741 // Implementation of Runtime |
| 14729 | 14742 |
| 14730 #define F(name, number_of_args, result_size) \ | 14743 #define F(name, number_of_args, result_size) \ |
| 14731 { Runtime::k##name, Runtime::RUNTIME, #name, \ | 14744 { Runtime::k##name, Runtime::RUNTIME, #name, \ |
| 14732 FUNCTION_ADDR(Runtime_##name), number_of_args, result_size }, | 14745 FUNCTION_ADDR(Runtime_##name), number_of_args, result_size }, |
| 14733 | 14746 |
| 14734 | 14747 |
| 14735 #define I(name, number_of_args, result_size) \ | 14748 #define I(name, number_of_args, result_size) \ |
| 14736 { Runtime::kInline##name, Runtime::INLINE, \ | 14749 { Runtime::kInline##name, Runtime::INLINE, \ |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14802 // Handle last resort GC and make sure to allow future allocations | 14815 // Handle last resort GC and make sure to allow future allocations |
| 14803 // to grow the heap without causing GCs (if possible). | 14816 // to grow the heap without causing GCs (if possible). |
| 14804 isolate->counters()->gc_last_resort_from_js()->Increment(); | 14817 isolate->counters()->gc_last_resort_from_js()->Increment(); |
| 14805 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, | 14818 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, |
| 14806 "Runtime::PerformGC"); | 14819 "Runtime::PerformGC"); |
| 14807 } | 14820 } |
| 14808 } | 14821 } |
| 14809 | 14822 |
| 14810 | 14823 |
| 14811 } } // namespace v8::internal | 14824 } } // namespace v8::internal |
| OLD | NEW |