| 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" |
| 11 #include "src/runtime/runtime.h" | 11 #include "src/runtime/runtime.h" |
| 12 | 12 |
| 13 namespace v8 { | 13 namespace v8 { |
| 14 namespace internal { | 14 namespace internal { |
| 15 | 15 |
| 16 | |
| 17 RUNTIME_FUNCTION(Runtime_ArrayBufferInitialize) { | |
| 18 HandleScope scope(isolate); | |
| 19 DCHECK(args.length() == 3); | |
| 20 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, holder, 0); | |
| 21 CONVERT_NUMBER_ARG_HANDLE_CHECKED(byteLength, 1); | |
| 22 CONVERT_BOOLEAN_ARG_CHECKED(is_shared, 2); | |
| 23 if (!holder->byte_length()->IsUndefined()) { | |
| 24 // ArrayBuffer is already initialized; probably a fuzz test. | |
| 25 return *holder; | |
| 26 } | |
| 27 size_t allocated_length = 0; | |
| 28 if (!TryNumberToSize(isolate, *byteLength, &allocated_length)) { | |
| 29 THROW_NEW_ERROR_RETURN_FAILURE( | |
| 30 isolate, NewRangeError(MessageTemplate::kInvalidArrayBufferLength)); | |
| 31 } | |
| 32 if (!JSArrayBuffer::SetupAllocatingData( | |
| 33 holder, isolate, allocated_length, true, | |
| 34 is_shared ? SharedFlag::kShared : SharedFlag::kNotShared)) { | |
| 35 THROW_NEW_ERROR_RETURN_FAILURE( | |
| 36 isolate, NewRangeError(MessageTemplate::kArrayBufferAllocationFailed)); | |
| 37 } | |
| 38 return *holder; | |
| 39 } | |
| 40 | |
| 41 | |
| 42 RUNTIME_FUNCTION(Runtime_ArrayBufferGetByteLength) { | 16 RUNTIME_FUNCTION(Runtime_ArrayBufferGetByteLength) { |
| 43 SealHandleScope shs(isolate); | 17 SealHandleScope shs(isolate); |
| 44 DCHECK(args.length() == 1); | 18 DCHECK(args.length() == 1); |
| 45 CONVERT_ARG_CHECKED(JSArrayBuffer, holder, 0); | 19 CONVERT_ARG_CHECKED(JSArrayBuffer, holder, 0); |
| 46 return holder->byte_length(); | 20 return holder->byte_length(); |
| 47 } | 21 } |
| 48 | 22 |
| 49 | 23 |
| 50 RUNTIME_FUNCTION(Runtime_ArrayBufferSliceImpl) { | 24 RUNTIME_FUNCTION(Runtime_ArrayBufferSliceImpl) { |
| 51 HandleScope scope(isolate); | 25 HandleScope scope(isolate); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 63 size_t source_byte_length = NumberToSize(isolate, source->byte_length()); | 37 size_t source_byte_length = NumberToSize(isolate, source->byte_length()); |
| 64 RUNTIME_ASSERT(start <= source_byte_length); | 38 RUNTIME_ASSERT(start <= source_byte_length); |
| 65 RUNTIME_ASSERT(source_byte_length - start >= target_length); | 39 RUNTIME_ASSERT(source_byte_length - start >= target_length); |
| 66 uint8_t* source_data = reinterpret_cast<uint8_t*>(source->backing_store()); | 40 uint8_t* source_data = reinterpret_cast<uint8_t*>(source->backing_store()); |
| 67 uint8_t* target_data = reinterpret_cast<uint8_t*>(target->backing_store()); | 41 uint8_t* target_data = reinterpret_cast<uint8_t*>(target->backing_store()); |
| 68 CopyBytes(target_data, source_data + start, target_length); | 42 CopyBytes(target_data, source_data + start, target_length); |
| 69 return isolate->heap()->undefined_value(); | 43 return isolate->heap()->undefined_value(); |
| 70 } | 44 } |
| 71 | 45 |
| 72 | 46 |
| 73 RUNTIME_FUNCTION(Runtime_ArrayBufferIsView) { | |
| 74 HandleScope scope(isolate); | |
| 75 DCHECK(args.length() == 1); | |
| 76 CONVERT_ARG_CHECKED(Object, object, 0); | |
| 77 return isolate->heap()->ToBoolean(object->IsJSArrayBufferView()); | |
| 78 } | |
| 79 | |
| 80 | |
| 81 RUNTIME_FUNCTION(Runtime_ArrayBufferNeuter) { | 47 RUNTIME_FUNCTION(Runtime_ArrayBufferNeuter) { |
| 82 HandleScope scope(isolate); | 48 HandleScope scope(isolate); |
| 83 DCHECK(args.length() == 1); | 49 DCHECK(args.length() == 1); |
| 84 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, array_buffer, 0); | 50 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, array_buffer, 0); |
| 85 if (array_buffer->backing_store() == NULL) { | 51 if (array_buffer->backing_store() == NULL) { |
| 86 CHECK(Smi::FromInt(0) == array_buffer->byte_length()); | 52 CHECK(Smi::FromInt(0) == array_buffer->byte_length()); |
| 87 return isolate->heap()->undefined_value(); | 53 return isolate->heap()->undefined_value(); |
| 88 } | 54 } |
| 89 // Shared array buffers should never be neutered. | 55 // Shared array buffers should never be neutered. |
| 90 RUNTIME_ASSERT(!array_buffer->is_shared()); | 56 RUNTIME_ASSERT(!array_buffer->is_shared()); |
| (...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 694 DATA_VIEW_SETTER(Uint16, uint16_t) | 660 DATA_VIEW_SETTER(Uint16, uint16_t) |
| 695 DATA_VIEW_SETTER(Int16, int16_t) | 661 DATA_VIEW_SETTER(Int16, int16_t) |
| 696 DATA_VIEW_SETTER(Uint32, uint32_t) | 662 DATA_VIEW_SETTER(Uint32, uint32_t) |
| 697 DATA_VIEW_SETTER(Int32, int32_t) | 663 DATA_VIEW_SETTER(Int32, int32_t) |
| 698 DATA_VIEW_SETTER(Float32, float) | 664 DATA_VIEW_SETTER(Float32, float) |
| 699 DATA_VIEW_SETTER(Float64, double) | 665 DATA_VIEW_SETTER(Float64, double) |
| 700 | 666 |
| 701 #undef DATA_VIEW_SETTER | 667 #undef DATA_VIEW_SETTER |
| 702 } // namespace internal | 668 } // namespace internal |
| 703 } // namespace v8 | 669 } // namespace v8 |
| OLD | NEW |