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/bootstrapper.h" | 5 #include "src/bootstrapper.h" |
6 | 6 |
7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
8 #include "src/api-natives.h" | 8 #include "src/api-natives.h" |
9 #include "src/base/utils/random-number-generator.h" | 9 #include "src/base/utils/random-number-generator.h" |
10 #include "src/code-stubs.h" | 10 #include "src/code-stubs.h" |
(...skipping 1585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1596 #undef INSTALL_NATIVE_FUNCTIONS_FOR | 1596 #undef INSTALL_NATIVE_FUNCTIONS_FOR |
1597 } | 1597 } |
1598 | 1598 |
1599 | 1599 |
1600 template <typename Data> | 1600 template <typename Data> |
1601 Data* SetBuiltinTypedArray(Isolate* isolate, Handle<JSBuiltinsObject> builtins, | 1601 Data* SetBuiltinTypedArray(Isolate* isolate, Handle<JSBuiltinsObject> builtins, |
1602 ExternalArrayType type, Data* data, | 1602 ExternalArrayType type, Data* data, |
1603 size_t num_elements, const char* name) { | 1603 size_t num_elements, const char* name) { |
1604 size_t byte_length = num_elements * sizeof(*data); | 1604 size_t byte_length = num_elements * sizeof(*data); |
1605 Handle<JSArrayBuffer> buffer = isolate->factory()->NewJSArrayBuffer(); | 1605 Handle<JSArrayBuffer> buffer = isolate->factory()->NewJSArrayBuffer(); |
1606 bool should_be_freed = false; | 1606 bool is_external = data != nullptr; |
1607 if (data == NULL) { | 1607 if (!is_external) { |
1608 data = reinterpret_cast<Data*>(malloc(byte_length)); | 1608 data = reinterpret_cast<Data*>( |
1609 should_be_freed = true; | 1609 V8::ArrayBufferAllocator()->Allocate(byte_length)); |
1610 } | 1610 } |
1611 Runtime::SetupArrayBuffer(isolate, buffer, true, data, byte_length); | 1611 Runtime::SetupArrayBuffer(isolate, buffer, is_external, data, byte_length); |
1612 buffer->set_should_be_freed(should_be_freed); | |
1613 | 1612 |
1614 Handle<JSTypedArray> typed_array = | 1613 Handle<JSTypedArray> typed_array = |
1615 isolate->factory()->NewJSTypedArray(type, buffer, 0, num_elements); | 1614 isolate->factory()->NewJSTypedArray(type, buffer, 0, num_elements); |
1616 Handle<String> name_string = isolate->factory()->InternalizeUtf8String(name); | 1615 Handle<String> name_string = isolate->factory()->InternalizeUtf8String(name); |
1617 // Reset property cell type before (re)initializing. | 1616 // Reset property cell type before (re)initializing. |
1618 JSBuiltinsObject::InvalidatePropertyCell(builtins, name_string); | 1617 JSBuiltinsObject::InvalidatePropertyCell(builtins, name_string); |
1619 JSObject::SetOwnPropertyIgnoreAttributes(builtins, name_string, typed_array, | 1618 JSObject::SetOwnPropertyIgnoreAttributes(builtins, name_string, typed_array, |
1620 DONT_DELETE).Assert(); | 1619 DONT_DELETE).Assert(); |
1621 return data; | 1620 return data; |
1622 } | 1621 } |
(...skipping 1337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2960 return from + sizeof(NestingCounterType); | 2959 return from + sizeof(NestingCounterType); |
2961 } | 2960 } |
2962 | 2961 |
2963 | 2962 |
2964 // Called when the top-level V8 mutex is destroyed. | 2963 // Called when the top-level V8 mutex is destroyed. |
2965 void Bootstrapper::FreeThreadResources() { | 2964 void Bootstrapper::FreeThreadResources() { |
2966 DCHECK(!IsActive()); | 2965 DCHECK(!IsActive()); |
2967 } | 2966 } |
2968 | 2967 |
2969 } } // namespace v8::internal | 2968 } } // namespace v8::internal |
OLD | NEW |