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/factory.h" | 5 #include "src/factory.h" |
6 | 6 |
7 #include "src/allocation-site-scopes.h" | 7 #include "src/allocation-site-scopes.h" |
8 #include "src/base/bits.h" | 8 #include "src/base/bits.h" |
9 #include "src/bootstrapper.h" | 9 #include "src/bootstrapper.h" |
10 #include "src/conversions.h" | 10 #include "src/conversions.h" |
(...skipping 865 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
876 Handle<BytecodeArray> Factory::NewBytecodeArray(int length, | 876 Handle<BytecodeArray> Factory::NewBytecodeArray(int length, |
877 const byte* raw_bytecodes, | 877 const byte* raw_bytecodes, |
878 int frame_size) { | 878 int frame_size) { |
879 DCHECK(0 <= length); | 879 DCHECK(0 <= length); |
880 CALL_HEAP_FUNCTION(isolate(), isolate()->heap()->AllocateBytecodeArray( | 880 CALL_HEAP_FUNCTION(isolate(), isolate()->heap()->AllocateBytecodeArray( |
881 length, raw_bytecodes, frame_size), | 881 length, raw_bytecodes, frame_size), |
882 BytecodeArray); | 882 BytecodeArray); |
883 } | 883 } |
884 | 884 |
885 | 885 |
886 Handle<ExternalArray> Factory::NewExternalArray(int length, | 886 Handle<FixedTypedArrayBase> Factory::NewFixedTypedArrayWithExternalPointer( |
887 ExternalArrayType array_type, | 887 int length, ExternalArrayType array_type, void* external_pointer, |
888 void* external_pointer, | 888 PretenureFlag pretenure) { |
889 PretenureFlag pretenure) { | |
890 DCHECK(0 <= length && length <= Smi::kMaxValue); | 889 DCHECK(0 <= length && length <= Smi::kMaxValue); |
891 CALL_HEAP_FUNCTION( | 890 CALL_HEAP_FUNCTION( |
892 isolate(), | 891 isolate(), isolate()->heap()->AllocateFixedTypedArrayWithExternalPointer( |
893 isolate()->heap()->AllocateExternalArray(length, | 892 length, array_type, external_pointer, pretenure), |
894 array_type, | 893 FixedTypedArrayBase); |
895 external_pointer, | |
896 pretenure), | |
897 ExternalArray); | |
898 } | 894 } |
899 | 895 |
900 | 896 |
901 Handle<FixedTypedArrayBase> Factory::NewFixedTypedArray( | 897 Handle<FixedTypedArrayBase> Factory::NewFixedTypedArray( |
902 int length, ExternalArrayType array_type, bool initialize, | 898 int length, ExternalArrayType array_type, bool initialize, |
903 PretenureFlag pretenure) { | 899 PretenureFlag pretenure) { |
904 DCHECK(0 <= length && length <= Smi::kMaxValue); | 900 DCHECK(0 <= length && length <= Smi::kMaxValue); |
905 CALL_HEAP_FUNCTION(isolate(), isolate()->heap()->AllocateFixedTypedArray( | 901 CALL_HEAP_FUNCTION(isolate(), isolate()->heap()->AllocateFixedTypedArray( |
906 length, array_type, initialize, pretenure), | 902 length, array_type, initialize, pretenure), |
907 FixedTypedArrayBase); | 903 FixedTypedArrayBase); |
(...skipping 850 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1758 JSSetIterator); | 1754 JSSetIterator); |
1759 } | 1755 } |
1760 | 1756 |
1761 | 1757 |
1762 namespace { | 1758 namespace { |
1763 | 1759 |
1764 ElementsKind GetExternalArrayElementsKind(ExternalArrayType type) { | 1760 ElementsKind GetExternalArrayElementsKind(ExternalArrayType type) { |
1765 switch (type) { | 1761 switch (type) { |
1766 #define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \ | 1762 #define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \ |
1767 case kExternal##Type##Array: \ | 1763 case kExternal##Type##Array: \ |
1768 return EXTERNAL_##TYPE##_ELEMENTS; | 1764 return TYPE##_ELEMENTS; |
1769 TYPED_ARRAYS(TYPED_ARRAY_CASE) | 1765 TYPED_ARRAYS(TYPED_ARRAY_CASE) |
1770 } | 1766 } |
1771 UNREACHABLE(); | 1767 UNREACHABLE(); |
1772 return FIRST_EXTERNAL_ARRAY_ELEMENTS_KIND; | 1768 return FIRST_FIXED_TYPED_ARRAY_ELEMENTS_KIND; |
1773 #undef TYPED_ARRAY_CASE | 1769 #undef TYPED_ARRAY_CASE |
1774 } | 1770 } |
1775 | 1771 |
1776 | 1772 |
1777 size_t GetExternalArrayElementSize(ExternalArrayType type) { | 1773 size_t GetExternalArrayElementSize(ExternalArrayType type) { |
1778 switch (type) { | 1774 switch (type) { |
1779 #define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \ | 1775 #define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \ |
1780 case kExternal##Type##Array: \ | 1776 case kExternal##Type##Array: \ |
1781 return size; | 1777 return size; |
1782 TYPED_ARRAYS(TYPED_ARRAY_CASE) | 1778 TYPED_ARRAYS(TYPED_ARRAY_CASE) |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1904 CHECK(byte_offset % element_size == 0); | 1900 CHECK(byte_offset % element_size == 0); |
1905 | 1901 |
1906 CHECK(length <= (std::numeric_limits<size_t>::max() / element_size)); | 1902 CHECK(length <= (std::numeric_limits<size_t>::max() / element_size)); |
1907 CHECK(length <= static_cast<size_t>(Smi::kMaxValue)); | 1903 CHECK(length <= static_cast<size_t>(Smi::kMaxValue)); |
1908 size_t byte_length = length * element_size; | 1904 size_t byte_length = length * element_size; |
1909 SetupArrayBufferView(isolate(), obj, buffer, byte_offset, byte_length); | 1905 SetupArrayBufferView(isolate(), obj, buffer, byte_offset, byte_length); |
1910 | 1906 |
1911 Handle<Object> length_object = NewNumberFromSize(length); | 1907 Handle<Object> length_object = NewNumberFromSize(length); |
1912 obj->set_length(*length_object); | 1908 obj->set_length(*length_object); |
1913 | 1909 |
1914 Handle<ExternalArray> elements = NewExternalArray( | 1910 Handle<FixedTypedArrayBase> elements = NewFixedTypedArrayWithExternalPointer( |
1915 static_cast<int>(length), type, | 1911 static_cast<int>(length), type, |
1916 static_cast<uint8_t*>(buffer->backing_store()) + byte_offset); | 1912 static_cast<uint8_t*>(buffer->backing_store()) + byte_offset); |
1917 Handle<Map> map = JSObject::GetElementsTransitionMap(obj, elements_kind); | 1913 Handle<Map> map = JSObject::GetElementsTransitionMap(obj, elements_kind); |
1918 JSObject::SetMapAndElements(obj, map, elements); | 1914 JSObject::SetMapAndElements(obj, map, elements); |
1919 return obj; | 1915 return obj; |
1920 } | 1916 } |
1921 | 1917 |
1922 | 1918 |
1923 Handle<JSTypedArray> Factory::NewJSTypedArray(ElementsKind elements_kind, | 1919 Handle<JSTypedArray> Factory::NewJSTypedArray(ElementsKind elements_kind, |
1924 size_t number_of_elements) { | 1920 size_t number_of_elements) { |
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2429 } | 2425 } |
2430 | 2426 |
2431 | 2427 |
2432 Handle<Object> Factory::ToBoolean(bool value) { | 2428 Handle<Object> Factory::ToBoolean(bool value) { |
2433 return value ? true_value() : false_value(); | 2429 return value ? true_value() : false_value(); |
2434 } | 2430 } |
2435 | 2431 |
2436 | 2432 |
2437 } // namespace internal | 2433 } // namespace internal |
2438 } // namespace v8 | 2434 } // namespace v8 |
OLD | NEW |