| 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 891 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 902 | 902 |
| 903 holder->set_buffer(*buffer); | 903 holder->set_buffer(*buffer); |
| 904 holder->set_byte_offset(*byte_offset_object); | 904 holder->set_byte_offset(*byte_offset_object); |
| 905 holder->set_byte_length(*byte_length_object); | 905 holder->set_byte_length(*byte_length_object); |
| 906 | 906 |
| 907 size_t byte_offset = NumberToSize(isolate, *byte_offset_object); | 907 size_t byte_offset = NumberToSize(isolate, *byte_offset_object); |
| 908 size_t byte_length = NumberToSize(isolate, *byte_length_object); | 908 size_t byte_length = NumberToSize(isolate, *byte_length_object); |
| 909 ASSERT(byte_length % element_size == 0); | 909 ASSERT(byte_length % element_size == 0); |
| 910 size_t length = byte_length / element_size; | 910 size_t length = byte_length / element_size; |
| 911 | 911 |
| 912 if (length > static_cast<unsigned>(Smi::kMaxValue)) { |
| 913 return isolate->Throw(*isolate->factory()-> |
| 914 NewRangeError("invalid_typed_array_length", |
| 915 HandleVector<Object>(NULL, 0))); |
| 916 } |
| 917 |
| 912 Handle<Object> length_obj = isolate->factory()->NewNumberFromSize(length); | 918 Handle<Object> length_obj = isolate->factory()->NewNumberFromSize(length); |
| 913 holder->set_length(*length_obj); | 919 holder->set_length(*length_obj); |
| 914 holder->set_weak_next(buffer->weak_first_view()); | 920 holder->set_weak_next(buffer->weak_first_view()); |
| 915 buffer->set_weak_first_view(*holder); | 921 buffer->set_weak_first_view(*holder); |
| 916 | 922 |
| 917 Handle<ExternalArray> elements = | 923 Handle<ExternalArray> elements = |
| 918 isolate->factory()->NewExternalArray( | 924 isolate->factory()->NewExternalArray( |
| 919 static_cast<int>(length), array_type, | 925 static_cast<int>(length), array_type, |
| 920 static_cast<uint8_t*>(buffer->backing_store()) + byte_offset); | 926 static_cast<uint8_t*>(buffer->backing_store()) + byte_offset); |
| 921 holder->set_elements(*elements); | 927 holder->set_elements(*elements); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 941 for (int i = 0; i < v8::ArrayBufferView::kInternalFieldCount; i++) { | 947 for (int i = 0; i < v8::ArrayBufferView::kInternalFieldCount; i++) { |
| 942 holder->SetInternalField(i, Smi::FromInt(0)); | 948 holder->SetInternalField(i, Smi::FromInt(0)); |
| 943 } | 949 } |
| 944 | 950 |
| 945 ExternalArrayType array_type = kExternalByteArray; // Bogus initialization. | 951 ExternalArrayType array_type = kExternalByteArray; // Bogus initialization. |
| 946 size_t element_size = 1; // Bogus initialization. | 952 size_t element_size = 1; // Bogus initialization. |
| 947 ArrayIdToTypeAndSize(arrayId, &array_type, &element_size); | 953 ArrayIdToTypeAndSize(arrayId, &array_type, &element_size); |
| 948 | 954 |
| 949 Handle<JSArrayBuffer> buffer = isolate->factory()->NewJSArrayBuffer(); | 955 Handle<JSArrayBuffer> buffer = isolate->factory()->NewJSArrayBuffer(); |
| 950 size_t length = NumberToSize(isolate, *length_obj); | 956 size_t length = NumberToSize(isolate, *length_obj); |
| 951 if (length > (kMaxInt / element_size)) { | 957 |
| 958 if ((length > static_cast<unsigned>(Smi::kMaxValue)) || |
| 959 (length > (kMaxInt / element_size))) { |
| 952 return isolate->Throw(*isolate->factory()-> | 960 return isolate->Throw(*isolate->factory()-> |
| 953 NewRangeError("invalid_array_buffer_length", | 961 NewRangeError("invalid_typed_array_length", |
| 954 HandleVector<Object>(NULL, 0))); | 962 HandleVector<Object>(NULL, 0))); |
| 955 } | 963 } |
| 956 size_t byte_length = length * element_size; | 964 size_t byte_length = length * element_size; |
| 957 | 965 |
| 958 // We assume that the caller of this function will initialize holder | 966 // We assume that the caller of this function will initialize holder |
| 959 // with the loop | 967 // with the loop |
| 960 // for(i = 0; i < length; i++) { holder[i] = source[i]; } | 968 // for(i = 0; i < length; i++) { holder[i] = source[i]; } |
| 961 // If source is a typed array, this loop will always run to completion, | 969 // If source is a typed array, this loop will always run to completion, |
| 962 // so we are sure that the backing store will be initialized. | 970 // so we are sure that the backing store will be initialized. |
| 963 // Otherwise, we do not know (the indexing operation might throw). | 971 // Otherwise, we do not know (the indexing operation might throw). |
| (...skipping 13441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14405 : reinterpret_cast<Arguments*>(args[0]); | 14413 : reinterpret_cast<Arguments*>(args[0]); |
| 14406 CONVERT_ARG_HANDLE_CHECKED(JSFunction, constructor, parameters_start); | 14414 CONVERT_ARG_HANDLE_CHECKED(JSFunction, constructor, parameters_start); |
| 14407 | 14415 |
| 14408 return ArrayConstructorCommon(isolate, | 14416 return ArrayConstructorCommon(isolate, |
| 14409 constructor, | 14417 constructor, |
| 14410 Handle<Object>::null(), | 14418 Handle<Object>::null(), |
| 14411 caller_args); | 14419 caller_args); |
| 14412 } | 14420 } |
| 14413 | 14421 |
| 14414 | 14422 |
| 14423 RUNTIME_FUNCTION(MaybeObject*, Runtime_MaxSmi) { |
| 14424 return Smi::FromInt(Smi::kMaxValue); |
| 14425 } |
| 14426 |
| 14427 |
| 14415 // ---------------------------------------------------------------------------- | 14428 // ---------------------------------------------------------------------------- |
| 14416 // Implementation of Runtime | 14429 // Implementation of Runtime |
| 14417 | 14430 |
| 14418 #define F(name, number_of_args, result_size) \ | 14431 #define F(name, number_of_args, result_size) \ |
| 14419 { Runtime::k##name, Runtime::RUNTIME, #name, \ | 14432 { Runtime::k##name, Runtime::RUNTIME, #name, \ |
| 14420 FUNCTION_ADDR(Runtime_##name), number_of_args, result_size }, | 14433 FUNCTION_ADDR(Runtime_##name), number_of_args, result_size }, |
| 14421 | 14434 |
| 14422 | 14435 |
| 14423 #define I(name, number_of_args, result_size) \ | 14436 #define I(name, number_of_args, result_size) \ |
| 14424 { Runtime::kInline##name, Runtime::INLINE, \ | 14437 { Runtime::kInline##name, Runtime::INLINE, \ |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14491 // Handle last resort GC and make sure to allow future allocations | 14504 // Handle last resort GC and make sure to allow future allocations |
| 14492 // to grow the heap without causing GCs (if possible). | 14505 // to grow the heap without causing GCs (if possible). |
| 14493 isolate->counters()->gc_last_resort_from_js()->Increment(); | 14506 isolate->counters()->gc_last_resort_from_js()->Increment(); |
| 14494 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, | 14507 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, |
| 14495 "Runtime::PerformGC"); | 14508 "Runtime::PerformGC"); |
| 14496 } | 14509 } |
| 14497 } | 14510 } |
| 14498 | 14511 |
| 14499 | 14512 |
| 14500 } } // namespace v8::internal | 14513 } } // namespace v8::internal |
| OLD | NEW |