| 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 929 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 940 for (int i = 0; i < v8::ArrayBufferView::kInternalFieldCount; i++) { | 940 for (int i = 0; i < v8::ArrayBufferView::kInternalFieldCount; i++) { |
| 941 holder->SetInternalField(i, Smi::FromInt(0)); | 941 holder->SetInternalField(i, Smi::FromInt(0)); |
| 942 } | 942 } |
| 943 | 943 |
| 944 ExternalArrayType array_type = kExternalByteArray; // Bogus initialization. | 944 ExternalArrayType array_type = kExternalByteArray; // Bogus initialization. |
| 945 size_t element_size = 1; // Bogus initialization. | 945 size_t element_size = 1; // Bogus initialization. |
| 946 ArrayIdToTypeAndSize(arrayId, &array_type, &element_size); | 946 ArrayIdToTypeAndSize(arrayId, &array_type, &element_size); |
| 947 | 947 |
| 948 Handle<JSArrayBuffer> buffer = isolate->factory()->NewJSArrayBuffer(); | 948 Handle<JSArrayBuffer> buffer = isolate->factory()->NewJSArrayBuffer(); |
| 949 size_t length = NumberToSize(isolate, *length_obj); | 949 size_t length = NumberToSize(isolate, *length_obj); |
| 950 size_t byte_length = length * element_size; | 950 if (length > (kMaxInt / element_size)) { |
| 951 if (byte_length < length) { // Overflow | |
| 952 return isolate->Throw(*isolate->factory()-> | 951 return isolate->Throw(*isolate->factory()-> |
| 953 NewRangeError("invalid_array_buffer_length", | 952 NewRangeError("invalid_array_buffer_length", |
| 954 HandleVector<Object>(NULL, 0))); | 953 HandleVector<Object>(NULL, 0))); |
| 955 } | 954 } |
| 955 size_t byte_length = length * element_size; |
| 956 | 956 |
| 957 // We assume that the caller of this function will initialize holder | 957 // We assume that the caller of this function will initialize holder |
| 958 // with the loop | 958 // with the loop |
| 959 // for(i = 0; i < length; i++) { holder[i] = source[i]; } | 959 // for(i = 0; i < length; i++) { holder[i] = source[i]; } |
| 960 // If source is a typed array, this loop will always run to completion, | 960 // 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. | 961 // so we are sure that the backing store will be initialized. |
| 962 // Otherwise, we do not know (the indexing operation might throw). | 962 // Otherwise, we do not know (the indexing operation might throw). |
| 963 // Hence we require zero initialization unless our source is a typed array. | 963 // Hence we require zero initialization unless our source is a typed array. |
| 964 bool should_zero_initialize = !source->IsJSTypedArray(); | 964 bool should_zero_initialize = !source->IsJSTypedArray(); |
| 965 | 965 |
| (...skipping 13836 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14802 // Handle last resort GC and make sure to allow future allocations | 14802 // Handle last resort GC and make sure to allow future allocations |
| 14803 // to grow the heap without causing GCs (if possible). | 14803 // to grow the heap without causing GCs (if possible). |
| 14804 isolate->counters()->gc_last_resort_from_js()->Increment(); | 14804 isolate->counters()->gc_last_resort_from_js()->Increment(); |
| 14805 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, | 14805 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, |
| 14806 "Runtime::PerformGC"); | 14806 "Runtime::PerformGC"); |
| 14807 } | 14807 } |
| 14808 } | 14808 } |
| 14809 | 14809 |
| 14810 | 14810 |
| 14811 } } // namespace v8::internal | 14811 } } // namespace v8::internal |
| OLD | NEW |