| 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/v8.h" | 5 #include "src/v8.h" |
| 6 | 6 |
| 7 #include "src/arguments.h" | 7 #include "src/arguments.h" |
| 8 #include "src/runtime/runtime.h" | 8 #include "src/runtime/runtime.h" |
| 9 #include "src/runtime/runtime-utils.h" | 9 #include "src/runtime/runtime-utils.h" |
| 10 | 10 |
| 11 | 11 |
| 12 namespace v8 { | 12 namespace v8 { |
| 13 namespace internal { | 13 namespace internal { |
| 14 | 14 |
| 15 void Runtime::FreeArrayBuffer(Isolate* isolate, | 15 void Runtime::FreeArrayBuffer(Isolate* isolate, |
| 16 JSArrayBuffer* phantom_array_buffer) { | 16 JSArrayBuffer* phantom_array_buffer) { |
| 17 if (phantom_array_buffer->is_external()) return; | 17 if (phantom_array_buffer->is_external()) return; |
| 18 | 18 |
| 19 size_t allocated_length = | 19 size_t allocated_length = |
| 20 NumberToSize(isolate, phantom_array_buffer->byte_length()); | 20 NumberToSize(isolate, phantom_array_buffer->byte_length()); |
| 21 | 21 |
| 22 reinterpret_cast<v8::Isolate*>(isolate) | 22 reinterpret_cast<v8::Isolate*>(isolate) |
| 23 ->AdjustAmountOfExternalAllocatedMemory( | 23 ->AdjustAmountOfExternalAllocatedMemory( |
| 24 -static_cast<int64_t>(allocated_length)); | 24 -static_cast<int64_t>(allocated_length)); |
| 25 CHECK(V8::ArrayBufferAllocator() != NULL); | 25 CHECK(isolate->array_buffer_allocator() != NULL); |
| 26 V8::ArrayBufferAllocator()->Free(phantom_array_buffer->backing_store(), | 26 isolate->array_buffer_allocator()->Free(phantom_array_buffer->backing_store(), |
| 27 allocated_length); | 27 allocated_length); |
| 28 } | 28 } |
| 29 | 29 |
| 30 | 30 |
| 31 void Runtime::SetupArrayBuffer(Isolate* isolate, | 31 void Runtime::SetupArrayBuffer(Isolate* isolate, |
| 32 Handle<JSArrayBuffer> array_buffer, | 32 Handle<JSArrayBuffer> array_buffer, |
| 33 bool is_external, void* data, | 33 bool is_external, void* data, |
| 34 size_t allocated_length) { | 34 size_t allocated_length) { |
| 35 DCHECK(array_buffer->GetInternalFieldCount() == | 35 DCHECK(array_buffer->GetInternalFieldCount() == |
| 36 v8::ArrayBuffer::kInternalFieldCount); | 36 v8::ArrayBuffer::kInternalFieldCount); |
| 37 for (int i = 0; i < v8::ArrayBuffer::kInternalFieldCount; i++) { | 37 for (int i = 0; i < v8::ArrayBuffer::kInternalFieldCount; i++) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 60 isolate->heap()->set_last_array_buffer_in_list(*array_buffer); | 60 isolate->heap()->set_last_array_buffer_in_list(*array_buffer); |
| 61 } | 61 } |
| 62 } | 62 } |
| 63 | 63 |
| 64 | 64 |
| 65 bool Runtime::SetupArrayBufferAllocatingData(Isolate* isolate, | 65 bool Runtime::SetupArrayBufferAllocatingData(Isolate* isolate, |
| 66 Handle<JSArrayBuffer> array_buffer, | 66 Handle<JSArrayBuffer> array_buffer, |
| 67 size_t allocated_length, | 67 size_t allocated_length, |
| 68 bool initialize) { | 68 bool initialize) { |
| 69 void* data; | 69 void* data; |
| 70 CHECK(V8::ArrayBufferAllocator() != NULL); | 70 CHECK(isolate->array_buffer_allocator() != NULL); |
| 71 // Prevent creating array buffers when serializing. | 71 // Prevent creating array buffers when serializing. |
| 72 DCHECK(!isolate->serializer_enabled()); | 72 DCHECK(!isolate->serializer_enabled()); |
| 73 if (allocated_length != 0) { | 73 if (allocated_length != 0) { |
| 74 if (initialize) { | 74 if (initialize) { |
| 75 data = V8::ArrayBufferAllocator()->Allocate(allocated_length); | 75 data = isolate->array_buffer_allocator()->Allocate(allocated_length); |
| 76 } else { | 76 } else { |
| 77 data = | 77 data = isolate->array_buffer_allocator()->AllocateUninitialized( |
| 78 V8::ArrayBufferAllocator()->AllocateUninitialized(allocated_length); | 78 allocated_length); |
| 79 } | 79 } |
| 80 if (data == NULL) return false; | 80 if (data == NULL) return false; |
| 81 } else { | 81 } else { |
| 82 data = NULL; | 82 data = NULL; |
| 83 } | 83 } |
| 84 | 84 |
| 85 SetupArrayBuffer(isolate, array_buffer, false, data, allocated_length); | 85 SetupArrayBuffer(isolate, array_buffer, false, data, allocated_length); |
| 86 | 86 |
| 87 reinterpret_cast<v8::Isolate*>(isolate) | 87 reinterpret_cast<v8::Isolate*>(isolate) |
| 88 ->AdjustAmountOfExternalAllocatedMemory(allocated_length); | 88 ->AdjustAmountOfExternalAllocatedMemory(allocated_length); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, array_buffer, 0); | 166 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, array_buffer, 0); |
| 167 if (array_buffer->backing_store() == NULL) { | 167 if (array_buffer->backing_store() == NULL) { |
| 168 CHECK(Smi::FromInt(0) == array_buffer->byte_length()); | 168 CHECK(Smi::FromInt(0) == array_buffer->byte_length()); |
| 169 return isolate->heap()->undefined_value(); | 169 return isolate->heap()->undefined_value(); |
| 170 } | 170 } |
| 171 DCHECK(!array_buffer->is_external()); | 171 DCHECK(!array_buffer->is_external()); |
| 172 void* backing_store = array_buffer->backing_store(); | 172 void* backing_store = array_buffer->backing_store(); |
| 173 size_t byte_length = NumberToSize(isolate, array_buffer->byte_length()); | 173 size_t byte_length = NumberToSize(isolate, array_buffer->byte_length()); |
| 174 array_buffer->set_is_external(true); | 174 array_buffer->set_is_external(true); |
| 175 Runtime::NeuterArrayBuffer(array_buffer); | 175 Runtime::NeuterArrayBuffer(array_buffer); |
| 176 V8::ArrayBufferAllocator()->Free(backing_store, byte_length); | 176 isolate->array_buffer_allocator()->Free(backing_store, byte_length); |
| 177 return isolate->heap()->undefined_value(); | 177 return isolate->heap()->undefined_value(); |
| 178 } | 178 } |
| 179 | 179 |
| 180 | 180 |
| 181 void Runtime::ArrayIdToTypeAndSize(int arrayId, ExternalArrayType* array_type, | 181 void Runtime::ArrayIdToTypeAndSize(int arrayId, ExternalArrayType* array_type, |
| 182 ElementsKind* external_elements_kind, | 182 ElementsKind* external_elements_kind, |
| 183 ElementsKind* fixed_elements_kind, | 183 ElementsKind* fixed_elements_kind, |
| 184 size_t* element_size) { | 184 size_t* element_size) { |
| 185 switch (arrayId) { | 185 switch (arrayId) { |
| 186 #define ARRAY_ID_CASE(Type, type, TYPE, ctype, size) \ | 186 #define ARRAY_ID_CASE(Type, type, TYPE, ctype, size) \ |
| (...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 745 DATA_VIEW_SETTER(Uint16, uint16_t) | 745 DATA_VIEW_SETTER(Uint16, uint16_t) |
| 746 DATA_VIEW_SETTER(Int16, int16_t) | 746 DATA_VIEW_SETTER(Int16, int16_t) |
| 747 DATA_VIEW_SETTER(Uint32, uint32_t) | 747 DATA_VIEW_SETTER(Uint32, uint32_t) |
| 748 DATA_VIEW_SETTER(Int32, int32_t) | 748 DATA_VIEW_SETTER(Int32, int32_t) |
| 749 DATA_VIEW_SETTER(Float32, float) | 749 DATA_VIEW_SETTER(Float32, float) |
| 750 DATA_VIEW_SETTER(Float64, double) | 750 DATA_VIEW_SETTER(Float64, double) |
| 751 | 751 |
| 752 #undef DATA_VIEW_SETTER | 752 #undef DATA_VIEW_SETTER |
| 753 } | 753 } |
| 754 } // namespace v8::internal | 754 } // namespace v8::internal |
| OLD | NEW |