| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/runtime/runtime-utils.h" | 5 #include "src/runtime/runtime-utils.h" |
| 6 | 6 |
| 7 #include "src/arguments.h" | 7 #include "src/arguments.h" |
| 8 #include "src/factory.h" | 8 #include "src/factory.h" |
| 9 #include "src/messages.h" | 9 #include "src/messages.h" |
| 10 #include "src/objects-inl.h" | 10 #include "src/objects-inl.h" |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 RUNTIME_ASSERT(byte_length % element_size == 0); | 157 RUNTIME_ASSERT(byte_length % element_size == 0); |
| 158 size_t length = byte_length / element_size; | 158 size_t length = byte_length / element_size; |
| 159 | 159 |
| 160 if (length > static_cast<unsigned>(Smi::kMaxValue)) { | 160 if (length > static_cast<unsigned>(Smi::kMaxValue)) { |
| 161 THROW_NEW_ERROR_RETURN_FAILURE( | 161 THROW_NEW_ERROR_RETURN_FAILURE( |
| 162 isolate, NewRangeError(MessageTemplate::kInvalidTypedArrayLength)); | 162 isolate, NewRangeError(MessageTemplate::kInvalidTypedArrayLength)); |
| 163 } | 163 } |
| 164 | 164 |
| 165 // All checks are done, now we can modify objects. | 165 // All checks are done, now we can modify objects. |
| 166 | 166 |
| 167 DCHECK(holder->GetInternalFieldCount() == | 167 DCHECK_EQ(v8::ArrayBufferView::kInternalFieldCount, |
| 168 v8::ArrayBufferView::kInternalFieldCount); | 168 holder->GetInternalFieldCount()); |
| 169 for (int i = 0; i < v8::ArrayBufferView::kInternalFieldCount; i++) { | 169 for (int i = 0; i < v8::ArrayBufferView::kInternalFieldCount; i++) { |
| 170 holder->SetInternalField(i, Smi::FromInt(0)); | 170 holder->SetInternalField(i, Smi::FromInt(0)); |
| 171 } | 171 } |
| 172 Handle<Object> length_obj = isolate->factory()->NewNumberFromSize(length); | 172 Handle<Object> length_obj = isolate->factory()->NewNumberFromSize(length); |
| 173 holder->set_length(*length_obj); | 173 holder->set_length(*length_obj); |
| 174 holder->set_byte_offset(*byte_offset_object); | 174 holder->set_byte_offset(*byte_offset_object); |
| 175 holder->set_byte_length(*byte_length_object); | 175 holder->set_byte_length(*byte_length_object); |
| 176 | 176 |
| 177 if (!maybe_buffer->IsNull()) { | 177 if (!maybe_buffer->IsNull()) { |
| 178 Handle<JSArrayBuffer> buffer = Handle<JSArrayBuffer>::cast(maybe_buffer); | 178 Handle<JSArrayBuffer> buffer = Handle<JSArrayBuffer>::cast(maybe_buffer); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 RUNTIME_ASSERT(TryNumberToSize(isolate, *length_obj, &length)); | 231 RUNTIME_ASSERT(TryNumberToSize(isolate, *length_obj, &length)); |
| 232 } | 232 } |
| 233 | 233 |
| 234 if ((length > static_cast<unsigned>(Smi::kMaxValue)) || | 234 if ((length > static_cast<unsigned>(Smi::kMaxValue)) || |
| 235 (length > (kMaxInt / element_size))) { | 235 (length > (kMaxInt / element_size))) { |
| 236 THROW_NEW_ERROR_RETURN_FAILURE( | 236 THROW_NEW_ERROR_RETURN_FAILURE( |
| 237 isolate, NewRangeError(MessageTemplate::kInvalidTypedArrayLength)); | 237 isolate, NewRangeError(MessageTemplate::kInvalidTypedArrayLength)); |
| 238 } | 238 } |
| 239 size_t byte_length = length * element_size; | 239 size_t byte_length = length * element_size; |
| 240 | 240 |
| 241 DCHECK(holder->GetInternalFieldCount() == | 241 DCHECK_EQ(v8::ArrayBufferView::kInternalFieldCount, |
| 242 v8::ArrayBufferView::kInternalFieldCount); | 242 holder->GetInternalFieldCount()); |
| 243 for (int i = 0; i < v8::ArrayBufferView::kInternalFieldCount; i++) { | 243 for (int i = 0; i < v8::ArrayBufferView::kInternalFieldCount; i++) { |
| 244 holder->SetInternalField(i, Smi::FromInt(0)); | 244 holder->SetInternalField(i, Smi::FromInt(0)); |
| 245 } | 245 } |
| 246 | 246 |
| 247 // NOTE: not initializing backing store. | 247 // NOTE: not initializing backing store. |
| 248 // We assume that the caller of this function will initialize holder | 248 // We assume that the caller of this function will initialize holder |
| 249 // with the loop | 249 // with the loop |
| 250 // for(i = 0; i < length; i++) { holder[i] = source[i]; } | 250 // for(i = 0; i < length; i++) { holder[i] = source[i]; } |
| 251 // We assume that the caller of this function is always a typed array | 251 // We assume that the caller of this function is always a typed array |
| 252 // constructor. | 252 // constructor. |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 | 434 |
| 435 | 435 |
| 436 RUNTIME_FUNCTION(Runtime_DataViewInitialize) { | 436 RUNTIME_FUNCTION(Runtime_DataViewInitialize) { |
| 437 HandleScope scope(isolate); | 437 HandleScope scope(isolate); |
| 438 DCHECK(args.length() == 4); | 438 DCHECK(args.length() == 4); |
| 439 CONVERT_ARG_HANDLE_CHECKED(JSDataView, holder, 0); | 439 CONVERT_ARG_HANDLE_CHECKED(JSDataView, holder, 0); |
| 440 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, buffer, 1); | 440 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, buffer, 1); |
| 441 CONVERT_NUMBER_ARG_HANDLE_CHECKED(byte_offset, 2); | 441 CONVERT_NUMBER_ARG_HANDLE_CHECKED(byte_offset, 2); |
| 442 CONVERT_NUMBER_ARG_HANDLE_CHECKED(byte_length, 3); | 442 CONVERT_NUMBER_ARG_HANDLE_CHECKED(byte_length, 3); |
| 443 | 443 |
| 444 DCHECK(holder->GetInternalFieldCount() == | 444 DCHECK_EQ(v8::ArrayBufferView::kInternalFieldCount, |
| 445 v8::ArrayBufferView::kInternalFieldCount); | 445 holder->GetInternalFieldCount()); |
| 446 for (int i = 0; i < v8::ArrayBufferView::kInternalFieldCount; i++) { | 446 for (int i = 0; i < v8::ArrayBufferView::kInternalFieldCount; i++) { |
| 447 holder->SetInternalField(i, Smi::FromInt(0)); | 447 holder->SetInternalField(i, Smi::FromInt(0)); |
| 448 } | 448 } |
| 449 size_t buffer_length = 0; | 449 size_t buffer_length = 0; |
| 450 size_t offset = 0; | 450 size_t offset = 0; |
| 451 size_t length = 0; | 451 size_t length = 0; |
| 452 RUNTIME_ASSERT( | 452 RUNTIME_ASSERT( |
| 453 TryNumberToSize(isolate, buffer->byte_length(), &buffer_length)); | 453 TryNumberToSize(isolate, buffer->byte_length(), &buffer_length)); |
| 454 RUNTIME_ASSERT(TryNumberToSize(isolate, *byte_offset, &offset)); | 454 RUNTIME_ASSERT(TryNumberToSize(isolate, *byte_offset, &offset)); |
| 455 RUNTIME_ASSERT(TryNumberToSize(isolate, *byte_length, &length)); | 455 RUNTIME_ASSERT(TryNumberToSize(isolate, *byte_length, &length)); |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 681 DATA_VIEW_SETTER(Uint16, uint16_t) | 681 DATA_VIEW_SETTER(Uint16, uint16_t) |
| 682 DATA_VIEW_SETTER(Int16, int16_t) | 682 DATA_VIEW_SETTER(Int16, int16_t) |
| 683 DATA_VIEW_SETTER(Uint32, uint32_t) | 683 DATA_VIEW_SETTER(Uint32, uint32_t) |
| 684 DATA_VIEW_SETTER(Int32, int32_t) | 684 DATA_VIEW_SETTER(Int32, int32_t) |
| 685 DATA_VIEW_SETTER(Float32, float) | 685 DATA_VIEW_SETTER(Float32, float) |
| 686 DATA_VIEW_SETTER(Float64, double) | 686 DATA_VIEW_SETTER(Float64, double) |
| 687 | 687 |
| 688 #undef DATA_VIEW_SETTER | 688 #undef DATA_VIEW_SETTER |
| 689 } // namespace internal | 689 } // namespace internal |
| 690 } // namespace v8 | 690 } // namespace v8 |
| OLD | NEW |