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/conversions.h" | 9 #include "src/conversions.h" |
10 #include "src/isolate-inl.h" | 10 #include "src/isolate-inl.h" |
(...skipping 1692 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1703 JSFunction::EnsureHasInitialMap(function); | 1703 JSFunction::EnsureHasInitialMap(function); |
1704 Handle<Map> map(function->initial_map()); | 1704 Handle<Map> map(function->initial_map()); |
1705 DCHECK(map->instance_type() == JS_GENERATOR_OBJECT_TYPE); | 1705 DCHECK(map->instance_type() == JS_GENERATOR_OBJECT_TYPE); |
1706 CALL_HEAP_FUNCTION( | 1706 CALL_HEAP_FUNCTION( |
1707 isolate(), | 1707 isolate(), |
1708 isolate()->heap()->AllocateJSObjectFromMap(*map), | 1708 isolate()->heap()->AllocateJSObjectFromMap(*map), |
1709 JSGeneratorObject); | 1709 JSGeneratorObject); |
1710 } | 1710 } |
1711 | 1711 |
1712 | 1712 |
1713 Handle<JSArrayBuffer> Factory::NewJSArrayBuffer() { | 1713 Handle<JSArrayBuffer> Factory::NewJSArrayBuffer(bool is_shared) { |
1714 Handle<JSFunction> array_buffer_fun( | 1714 Handle<JSFunction> array_buffer_fun( |
1715 isolate()->native_context()->array_buffer_fun()); | 1715 is_shared ? isolate()->native_context()->shared_array_buffer_fun() |
| 1716 : isolate()->native_context()->array_buffer_fun()); |
1716 CALL_HEAP_FUNCTION( | 1717 CALL_HEAP_FUNCTION( |
1717 isolate(), | 1718 isolate(), |
1718 isolate()->heap()->AllocateJSObject(*array_buffer_fun), | 1719 isolate()->heap()->AllocateJSObject(*array_buffer_fun), |
1719 JSArrayBuffer); | 1720 JSArrayBuffer); |
1720 } | 1721 } |
1721 | 1722 |
1722 | 1723 |
1723 Handle<JSDataView> Factory::NewJSDataView() { | 1724 Handle<JSDataView> Factory::NewJSDataView() { |
1724 Handle<JSFunction> data_view_fun( | 1725 Handle<JSFunction> data_view_fun( |
1725 isolate()->native_context()->data_view_fun()); | 1726 isolate()->native_context()->data_view_fun()); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1784 TYPED_ARRAYS(TYPED_ARRAY_FUN) | 1785 TYPED_ARRAYS(TYPED_ARRAY_FUN) |
1785 #undef TYPED_ARRAY_FUN | 1786 #undef TYPED_ARRAY_FUN |
1786 | 1787 |
1787 default: | 1788 default: |
1788 UNREACHABLE(); | 1789 UNREACHABLE(); |
1789 return NULL; | 1790 return NULL; |
1790 } | 1791 } |
1791 } | 1792 } |
1792 | 1793 |
1793 | 1794 |
| 1795 JSFunction* GetSharedTypedArrayFun(ExternalArrayType type, Isolate* isolate) { |
| 1796 Context* native_context = isolate->context()->native_context(); |
| 1797 switch (type) { |
| 1798 #define SHARED_TYPED_ARRAY_FUN(Type, type, TYPE, ctype, size) \ |
| 1799 case kExternal##Type##Array: \ |
| 1800 return native_context->shared_##type##_array_fun(); |
| 1801 |
| 1802 TYPED_ARRAYS(SHARED_TYPED_ARRAY_FUN) |
| 1803 #undef SHARED_TYPED_ARRAY_FUN |
| 1804 |
| 1805 default: |
| 1806 UNREACHABLE(); |
| 1807 return NULL; |
| 1808 } |
| 1809 } |
| 1810 |
| 1811 |
1794 void SetupArrayBufferView(i::Isolate* isolate, | 1812 void SetupArrayBufferView(i::Isolate* isolate, |
1795 i::Handle<i::JSArrayBufferView> obj, | 1813 i::Handle<i::JSArrayBufferView> obj, |
1796 i::Handle<i::JSArrayBuffer> buffer, | 1814 i::Handle<i::JSArrayBuffer> buffer, |
1797 size_t byte_offset, size_t byte_length) { | 1815 size_t byte_offset, size_t byte_length) { |
1798 DCHECK(byte_offset + byte_length <= | 1816 DCHECK(byte_offset + byte_length <= |
1799 static_cast<size_t>(buffer->byte_length()->Number())); | 1817 static_cast<size_t>(buffer->byte_length()->Number())); |
1800 | 1818 |
1801 obj->set_buffer(*buffer); | 1819 obj->set_buffer(*buffer); |
1802 | 1820 |
1803 Heap* heap = isolate->heap(); | 1821 Heap* heap = isolate->heap(); |
(...skipping 11 matching lines...) Expand all Loading... |
1815 | 1833 |
1816 i::Handle<i::Object> byte_length_object = | 1834 i::Handle<i::Object> byte_length_object = |
1817 isolate->factory()->NewNumberFromSize(byte_length); | 1835 isolate->factory()->NewNumberFromSize(byte_length); |
1818 obj->set_byte_length(*byte_length_object); | 1836 obj->set_byte_length(*byte_length_object); |
1819 } | 1837 } |
1820 | 1838 |
1821 | 1839 |
1822 } // namespace | 1840 } // namespace |
1823 | 1841 |
1824 | 1842 |
1825 Handle<JSTypedArray> Factory::NewJSTypedArray(ExternalArrayType type) { | 1843 Handle<JSTypedArray> Factory::NewJSTypedArray(ExternalArrayType type, |
1826 Handle<JSFunction> typed_array_fun_handle(GetTypedArrayFun(type, isolate())); | 1844 bool is_shared) { |
| 1845 Handle<JSFunction> typed_array_fun_handle( |
| 1846 is_shared ? GetSharedTypedArrayFun(type, isolate()) |
| 1847 : GetTypedArrayFun(type, isolate())); |
1827 | 1848 |
1828 CALL_HEAP_FUNCTION( | 1849 CALL_HEAP_FUNCTION( |
1829 isolate(), | 1850 isolate(), |
1830 isolate()->heap()->AllocateJSObject(*typed_array_fun_handle), | 1851 isolate()->heap()->AllocateJSObject(*typed_array_fun_handle), |
1831 JSTypedArray); | 1852 JSTypedArray); |
1832 } | 1853 } |
1833 | 1854 |
1834 | 1855 |
1835 Handle<JSTypedArray> Factory::NewJSTypedArray(ExternalArrayType type, | 1856 Handle<JSTypedArray> Factory::NewJSTypedArray(ExternalArrayType type, |
1836 Handle<JSArrayBuffer> buffer, | 1857 Handle<JSArrayBuffer> buffer, |
1837 size_t byte_offset, | 1858 size_t byte_offset, size_t length, |
1838 size_t length) { | 1859 bool is_shared) { |
1839 Handle<JSTypedArray> obj = NewJSTypedArray(type); | 1860 Handle<JSTypedArray> obj = NewJSTypedArray(type, is_shared); |
1840 | 1861 |
1841 size_t element_size = GetExternalArrayElementSize(type); | 1862 size_t element_size = GetExternalArrayElementSize(type); |
1842 ElementsKind elements_kind = GetExternalArrayElementsKind(type); | 1863 ElementsKind elements_kind = GetExternalArrayElementsKind(type); |
1843 | 1864 |
1844 CHECK(byte_offset % element_size == 0); | 1865 CHECK(byte_offset % element_size == 0); |
1845 | 1866 |
1846 CHECK(length <= (std::numeric_limits<size_t>::max() / element_size)); | 1867 CHECK(length <= (std::numeric_limits<size_t>::max() / element_size)); |
1847 CHECK(length <= static_cast<size_t>(Smi::kMaxValue)); | 1868 CHECK(length <= static_cast<size_t>(Smi::kMaxValue)); |
1848 size_t byte_length = length * element_size; | 1869 size_t byte_length = length * element_size; |
1849 SetupArrayBufferView(isolate(), obj, buffer, byte_offset, byte_length); | 1870 SetupArrayBufferView(isolate(), obj, buffer, byte_offset, byte_length); |
1850 | 1871 |
1851 Handle<Object> length_object = NewNumberFromSize(length); | 1872 Handle<Object> length_object = NewNumberFromSize(length); |
1852 obj->set_length(*length_object); | 1873 obj->set_length(*length_object); |
| 1874 obj->set_is_shared(is_shared); |
1853 | 1875 |
1854 Handle<ExternalArray> elements = NewExternalArray( | 1876 Handle<ExternalArray> elements = NewExternalArray( |
1855 static_cast<int>(length), type, | 1877 static_cast<int>(length), type, |
1856 static_cast<uint8_t*>(buffer->backing_store()) + byte_offset); | 1878 static_cast<uint8_t*>(buffer->backing_store()) + byte_offset); |
1857 Handle<Map> map = JSObject::GetElementsTransitionMap(obj, elements_kind); | 1879 Handle<Map> map = JSObject::GetElementsTransitionMap(obj, elements_kind); |
1858 JSObject::SetMapAndElements(obj, map, elements); | 1880 JSObject::SetMapAndElements(obj, map, elements); |
1859 return obj; | 1881 return obj; |
1860 } | 1882 } |
1861 | 1883 |
1862 | 1884 |
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2337 return Handle<Object>::null(); | 2359 return Handle<Object>::null(); |
2338 } | 2360 } |
2339 | 2361 |
2340 | 2362 |
2341 Handle<Object> Factory::ToBoolean(bool value) { | 2363 Handle<Object> Factory::ToBoolean(bool value) { |
2342 return value ? true_value() : false_value(); | 2364 return value ? true_value() : false_value(); |
2343 } | 2365 } |
2344 | 2366 |
2345 | 2367 |
2346 } } // namespace v8::internal | 2368 } } // namespace v8::internal |
OLD | NEW |