Index: src/bootstrapper.cc |
diff --git a/src/bootstrapper.cc b/src/bootstrapper.cc |
index 8c17ae2b913ded0100b149ea60f5a7e186c68b6a..3db75a4dc048af5118017137ca510dbfdfdbe3ca 100644 |
--- a/src/bootstrapper.cc |
+++ b/src/bootstrapper.cc |
@@ -1726,6 +1726,24 @@ |
Handle<Object> value = |
Object::GetProperty(object, inner_string).ToHandleChecked(); |
return Handle<JSObject>::cast(value); |
+} |
+ |
+ |
+template <typename Data> |
+Handle<JSTypedArray> CreateTypedArray(Isolate* isolate, ExternalArrayType type, |
+ size_t num_elements, Data** data) { |
+ size_t byte_length = num_elements * sizeof(**data); |
+ Handle<JSArrayBuffer> buffer = |
+ isolate->factory()->NewJSArrayBuffer(SharedFlag::kNotShared, TENURED); |
+ bool is_external = (*data != nullptr); |
+ if (!is_external) { |
+ *data = reinterpret_cast<Data*>( |
+ isolate->array_buffer_allocator()->Allocate(byte_length)); |
+ } |
+ JSArrayBuffer::Setup(buffer, isolate, is_external, *data, byte_length, |
+ SharedFlag::kNotShared); |
+ return isolate->factory()->NewJSTypedArray(type, buffer, 0, num_elements, |
+ TENURED); |
} |