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