Index: src/factory.cc |
diff --git a/src/factory.cc b/src/factory.cc |
index 106f3d75d3d27775ba2d13f6e27989f4521a3903..f038fec6ddf2daa7c6df66a39b15c9aa3764c4f3 100644 |
--- a/src/factory.cc |
+++ b/src/factory.cc |
@@ -1826,9 +1826,38 @@ size_t GetExternalArrayElementSize(ExternalArrayType type) { |
case kExternal##Type##Array: \ |
return size; |
TYPED_ARRAYS(TYPED_ARRAY_CASE) |
+ default: |
+ UNREACHABLE(); |
+ return 0; |
+ } |
+#undef TYPED_ARRAY_CASE |
+} |
+ |
+ |
+size_t GetFixedTypedArraysElementSize(ElementsKind kind) { |
+ switch (kind) { |
+#define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \ |
+ case TYPE##_ELEMENTS: \ |
+ return size; |
+ TYPED_ARRAYS(TYPED_ARRAY_CASE) |
+ default: |
+ UNREACHABLE(); |
+ return 0; |
+ } |
+#undef TYPED_ARRAY_CASE |
+} |
+ |
+ |
+ExternalArrayType GetArrayTypeFromElementsKind(ElementsKind kind) { |
+ switch (kind) { |
+#define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \ |
+ case TYPE##_ELEMENTS: \ |
+ return kExternal##Type##Array; |
+ TYPED_ARRAYS(TYPED_ARRAY_CASE) |
+ default: |
+ UNREACHABLE(); |
+ return kExternalInt8Array; |
} |
- UNREACHABLE(); |
- return 0; |
#undef TYPED_ARRAY_CASE |
} |
@@ -1850,6 +1879,23 @@ JSFunction* GetTypedArrayFun(ExternalArrayType type, Isolate* isolate) { |
} |
+JSFunction* GetTypedArrayFun(ElementsKind elements_kind, Isolate* isolate) { |
+ Context* native_context = isolate->context()->native_context(); |
+ switch (elements_kind) { |
+#define TYPED_ARRAY_FUN(Type, type, TYPE, ctype, size) \ |
+ case TYPE##_ELEMENTS: \ |
+ return native_context->type##_array_fun(); |
+ |
+ TYPED_ARRAYS(TYPED_ARRAY_FUN) |
+#undef TYPED_ARRAY_FUN |
+ |
+ default: |
+ UNREACHABLE(); |
+ return NULL; |
+ } |
+} |
+ |
+ |
void SetupArrayBufferView(i::Isolate* isolate, |
i::Handle<i::JSArrayBufferView> obj, |
i::Handle<i::JSArrayBuffer> buffer, |
@@ -1891,6 +1937,16 @@ Handle<JSTypedArray> Factory::NewJSTypedArray(ExternalArrayType type) { |
} |
+Handle<JSTypedArray> Factory::NewJSTypedArray(ElementsKind elements_kind) { |
+ Handle<JSFunction> typed_array_fun_handle( |
+ GetTypedArrayFun(elements_kind, isolate())); |
+ |
+ CALL_HEAP_FUNCTION( |
+ isolate(), isolate()->heap()->AllocateJSObject(*typed_array_fun_handle), |
+ JSTypedArray); |
+} |
+ |
+ |
Handle<JSTypedArray> Factory::NewJSTypedArray(ExternalArrayType type, |
Handle<JSArrayBuffer> buffer, |
size_t byte_offset, |
@@ -1919,6 +1975,35 @@ Handle<JSTypedArray> Factory::NewJSTypedArray(ExternalArrayType type, |
} |
+Handle<JSTypedArray> Factory::NewJSTypedArray(ElementsKind elements_kind, |
+ size_t number_of_elements) { |
+ Handle<JSTypedArray> obj = NewJSTypedArray(elements_kind); |
+ |
+ size_t element_size = GetFixedTypedArraysElementSize(elements_kind); |
+ ExternalArrayType array_type = GetArrayTypeFromElementsKind(elements_kind); |
+ |
+ CHECK(number_of_elements <= |
+ (std::numeric_limits<size_t>::max() / element_size)); |
+ CHECK(number_of_elements <= static_cast<size_t>(Smi::kMaxValue)); |
+ size_t byte_length = number_of_elements * element_size; |
+ |
+ obj->set_byte_offset(Smi::FromInt(0)); |
+ i::Handle<i::Object> byte_length_object = |
+ isolate()->factory()->NewNumberFromSize(byte_length); |
+ obj->set_byte_length(*byte_length_object); |
+ Handle<Object> length_object = NewNumberFromSize(number_of_elements); |
+ obj->set_length(*length_object); |
+ |
+ obj->set_buffer(Smi::FromInt(0)); |
+ obj->set_weak_next(isolate()->heap()->undefined_value()); |
+ Handle<FixedTypedArrayBase> elements = |
+ isolate()->factory()->NewFixedTypedArray( |
+ static_cast<int>(number_of_elements), array_type); |
+ obj->set_elements(*elements); |
+ return obj; |
+} |
+ |
+ |
Handle<JSDataView> Factory::NewJSDataView(Handle<JSArrayBuffer> buffer, |
size_t byte_offset, |
size_t byte_length) { |