| 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/messages.h" | 8 #include "src/messages.h" |
| 9 #include "src/runtime/runtime.h" | 9 #include "src/runtime/runtime.h" |
| 10 #include "src/runtime/runtime-utils.h" | 10 #include "src/runtime/runtime-utils.h" |
| 11 | 11 |
| 12 | 12 |
| 13 namespace v8 { | 13 namespace v8 { |
| 14 namespace internal { | 14 namespace internal { |
| 15 | 15 |
| 16 void Runtime::SetupArrayBuffer(Isolate* isolate, | 16 void Runtime::SetupArrayBuffer(Isolate* isolate, |
| 17 Handle<JSArrayBuffer> array_buffer, | 17 Handle<JSArrayBuffer> array_buffer, |
| 18 bool is_external, void* data, | 18 bool is_external, void* data, |
| 19 size_t allocated_length) { | 19 size_t allocated_length) { |
| 20 DCHECK(array_buffer->GetInternalFieldCount() == | 20 DCHECK(array_buffer->GetInternalFieldCount() == |
| 21 v8::ArrayBuffer::kInternalFieldCount); | 21 v8::ArrayBuffer::kInternalFieldCount); |
| 22 for (int i = 0; i < v8::ArrayBuffer::kInternalFieldCount; i++) { | 22 for (int i = 0; i < v8::ArrayBuffer::kInternalFieldCount; i++) { |
| 23 array_buffer->SetInternalField(i, Smi::FromInt(0)); | 23 array_buffer->SetInternalField(i, Smi::FromInt(0)); |
| 24 } | 24 } |
| 25 array_buffer->set_backing_store(data); | 25 array_buffer->set_backing_store(data); |
| 26 array_buffer->set_bit_field(0); | 26 array_buffer->set_bit_field(0); |
| 27 array_buffer->set_is_external(is_external); | 27 array_buffer->set_is_external(is_external); |
| 28 array_buffer->set_is_neuterable(true); | 28 array_buffer->set_is_neuterable(true); |
| 29 | 29 |
| 30 if (data && !is_external) { |
| 31 isolate->heap()->RegisterNewArrayBuffer( |
| 32 isolate->heap()->InNewSpace(*array_buffer), data, allocated_length); |
| 33 } |
| 34 |
| 30 Handle<Object> byte_length = | 35 Handle<Object> byte_length = |
| 31 isolate->factory()->NewNumberFromSize(allocated_length); | 36 isolate->factory()->NewNumberFromSize(allocated_length); |
| 32 CHECK(byte_length->IsSmi() || byte_length->IsHeapNumber()); | 37 CHECK(byte_length->IsSmi() || byte_length->IsHeapNumber()); |
| 33 array_buffer->set_byte_length(*byte_length); | 38 array_buffer->set_byte_length(*byte_length); |
| 34 | |
| 35 if (data && !is_external) { | |
| 36 isolate->heap()->RegisterNewArrayBuffer( | |
| 37 isolate->heap()->InNewSpace(*array_buffer), data, allocated_length); | |
| 38 } | |
| 39 } | 39 } |
| 40 | 40 |
| 41 | 41 |
| 42 bool Runtime::SetupArrayBufferAllocatingData(Isolate* isolate, | 42 bool Runtime::SetupArrayBufferAllocatingData(Isolate* isolate, |
| 43 Handle<JSArrayBuffer> array_buffer, | 43 Handle<JSArrayBuffer> array_buffer, |
| 44 size_t allocated_length, | 44 size_t allocated_length, |
| 45 bool initialize) { | 45 bool initialize) { |
| 46 void* data; | 46 void* data; |
| 47 CHECK(isolate->array_buffer_allocator() != NULL); | 47 CHECK(isolate->array_buffer_allocator() != NULL); |
| 48 // Prevent creating array buffers when serializing. | 48 // Prevent creating array buffers when serializing. |
| (...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 715 DATA_VIEW_SETTER(Uint16, uint16_t) | 715 DATA_VIEW_SETTER(Uint16, uint16_t) |
| 716 DATA_VIEW_SETTER(Int16, int16_t) | 716 DATA_VIEW_SETTER(Int16, int16_t) |
| 717 DATA_VIEW_SETTER(Uint32, uint32_t) | 717 DATA_VIEW_SETTER(Uint32, uint32_t) |
| 718 DATA_VIEW_SETTER(Int32, int32_t) | 718 DATA_VIEW_SETTER(Int32, int32_t) |
| 719 DATA_VIEW_SETTER(Float32, float) | 719 DATA_VIEW_SETTER(Float32, float) |
| 720 DATA_VIEW_SETTER(Float64, double) | 720 DATA_VIEW_SETTER(Float64, double) |
| 721 | 721 |
| 722 #undef DATA_VIEW_SETTER | 722 #undef DATA_VIEW_SETTER |
| 723 } | 723 } |
| 724 } // namespace v8::internal | 724 } // namespace v8::internal |
| OLD | NEW |