Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(145)

Side by Side Diff: src/factory.cc

Issue 1094333002: Reland "LayoutDescriptor should inherit from JSTypedArray" (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: updates Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/factory.h ('k') | src/layout-descriptor.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1807 matching lines...) Expand 10 before | Expand all | Expand 10 after
1818 #undef TYPED_ARRAY_CASE 1818 #undef TYPED_ARRAY_CASE
1819 } 1819 }
1820 1820
1821 1821
1822 size_t GetExternalArrayElementSize(ExternalArrayType type) { 1822 size_t GetExternalArrayElementSize(ExternalArrayType type) {
1823 switch (type) { 1823 switch (type) {
1824 #define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \ 1824 #define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \
1825 case kExternal##Type##Array: \ 1825 case kExternal##Type##Array: \
1826 return size; 1826 return size;
1827 TYPED_ARRAYS(TYPED_ARRAY_CASE) 1827 TYPED_ARRAYS(TYPED_ARRAY_CASE)
1828 default:
1829 UNREACHABLE();
1830 return 0;
1828 } 1831 }
1829 UNREACHABLE();
1830 return 0;
1831 #undef TYPED_ARRAY_CASE 1832 #undef TYPED_ARRAY_CASE
1832 } 1833 }
1833 1834
1835
1836 size_t GetFixedTypedArraysElementSize(ElementsKind kind) {
1837 switch (kind) {
1838 #define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \
1839 case TYPE##_ELEMENTS: \
1840 return size;
1841 TYPED_ARRAYS(TYPED_ARRAY_CASE)
1842 default:
1843 UNREACHABLE();
1844 return 0;
1845 }
1846 #undef TYPED_ARRAY_CASE
1847 }
1848
1849
1850 ExternalArrayType GetArrayTypeFromElementsKind(ElementsKind kind) {
1851 switch (kind) {
1852 #define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \
1853 case TYPE##_ELEMENTS: \
1854 return kExternal##Type##Array;
1855 TYPED_ARRAYS(TYPED_ARRAY_CASE)
1856 default:
1857 UNREACHABLE();
1858 return kExternalInt8Array;
1859 }
1860 #undef TYPED_ARRAY_CASE
1861 }
1862
1834 1863
1835 JSFunction* GetTypedArrayFun(ExternalArrayType type, Isolate* isolate) { 1864 JSFunction* GetTypedArrayFun(ExternalArrayType type, Isolate* isolate) {
1836 Context* native_context = isolate->context()->native_context(); 1865 Context* native_context = isolate->context()->native_context();
1837 switch (type) { 1866 switch (type) {
1838 #define TYPED_ARRAY_FUN(Type, type, TYPE, ctype, size) \ 1867 #define TYPED_ARRAY_FUN(Type, type, TYPE, ctype, size) \
1839 case kExternal##Type##Array: \ 1868 case kExternal##Type##Array: \
1840 return native_context->type##_array_fun(); 1869 return native_context->type##_array_fun();
1841 1870
1842 TYPED_ARRAYS(TYPED_ARRAY_FUN) 1871 TYPED_ARRAYS(TYPED_ARRAY_FUN)
1843 #undef TYPED_ARRAY_FUN 1872 #undef TYPED_ARRAY_FUN
1844 1873
1845 default: 1874 default:
1846 UNREACHABLE(); 1875 UNREACHABLE();
1847 return NULL; 1876 return NULL;
1848 } 1877 }
1849 } 1878 }
1850 1879
1851 1880
1881 JSFunction* GetTypedArrayFun(ElementsKind elements_kind, Isolate* isolate) {
1882 Context* native_context = isolate->context()->native_context();
1883 switch (elements_kind) {
1884 #define TYPED_ARRAY_FUN(Type, type, TYPE, ctype, size) \
1885 case TYPE##_ELEMENTS: \
1886 return native_context->type##_array_fun();
1887
1888 TYPED_ARRAYS(TYPED_ARRAY_FUN)
1889 #undef TYPED_ARRAY_FUN
1890
1891 default:
1892 UNREACHABLE();
1893 return NULL;
1894 }
1895 }
1896
1897
1852 void SetupArrayBufferView(i::Isolate* isolate, 1898 void SetupArrayBufferView(i::Isolate* isolate,
1853 i::Handle<i::JSArrayBufferView> obj, 1899 i::Handle<i::JSArrayBufferView> obj,
1854 i::Handle<i::JSArrayBuffer> buffer, 1900 i::Handle<i::JSArrayBuffer> buffer,
1855 size_t byte_offset, size_t byte_length) { 1901 size_t byte_offset, size_t byte_length) {
1856 DCHECK(byte_offset + byte_length <= 1902 DCHECK(byte_offset + byte_length <=
1857 static_cast<size_t>(buffer->byte_length()->Number())); 1903 static_cast<size_t>(buffer->byte_length()->Number()));
1858 1904
1859 obj->set_buffer(*buffer); 1905 obj->set_buffer(*buffer);
1860 1906
1861 Heap* heap = isolate->heap(); 1907 Heap* heap = isolate->heap();
(...skipping 21 matching lines...) Expand all
1883 Handle<JSTypedArray> Factory::NewJSTypedArray(ExternalArrayType type) { 1929 Handle<JSTypedArray> Factory::NewJSTypedArray(ExternalArrayType type) {
1884 Handle<JSFunction> typed_array_fun_handle(GetTypedArrayFun(type, isolate())); 1930 Handle<JSFunction> typed_array_fun_handle(GetTypedArrayFun(type, isolate()));
1885 1931
1886 CALL_HEAP_FUNCTION( 1932 CALL_HEAP_FUNCTION(
1887 isolate(), 1933 isolate(),
1888 isolate()->heap()->AllocateJSObject(*typed_array_fun_handle), 1934 isolate()->heap()->AllocateJSObject(*typed_array_fun_handle),
1889 JSTypedArray); 1935 JSTypedArray);
1890 } 1936 }
1891 1937
1892 1938
1939 Handle<JSTypedArray> Factory::NewJSTypedArray(ElementsKind elements_kind) {
1940 Handle<JSFunction> typed_array_fun_handle(
1941 GetTypedArrayFun(elements_kind, isolate()));
1942
1943 CALL_HEAP_FUNCTION(
1944 isolate(), isolate()->heap()->AllocateJSObject(*typed_array_fun_handle),
1945 JSTypedArray);
1946 }
1947
1948
1893 Handle<JSTypedArray> Factory::NewJSTypedArray(ExternalArrayType type, 1949 Handle<JSTypedArray> Factory::NewJSTypedArray(ExternalArrayType type,
1894 Handle<JSArrayBuffer> buffer, 1950 Handle<JSArrayBuffer> buffer,
1895 size_t byte_offset, 1951 size_t byte_offset,
1896 size_t length) { 1952 size_t length) {
1897 Handle<JSTypedArray> obj = NewJSTypedArray(type); 1953 Handle<JSTypedArray> obj = NewJSTypedArray(type);
1898 1954
1899 size_t element_size = GetExternalArrayElementSize(type); 1955 size_t element_size = GetExternalArrayElementSize(type);
1900 ElementsKind elements_kind = GetExternalArrayElementsKind(type); 1956 ElementsKind elements_kind = GetExternalArrayElementsKind(type);
1901 1957
1902 CHECK(byte_offset % element_size == 0); 1958 CHECK(byte_offset % element_size == 0);
1903 1959
1904 CHECK(length <= (std::numeric_limits<size_t>::max() / element_size)); 1960 CHECK(length <= (std::numeric_limits<size_t>::max() / element_size));
1905 CHECK(length <= static_cast<size_t>(Smi::kMaxValue)); 1961 CHECK(length <= static_cast<size_t>(Smi::kMaxValue));
1906 size_t byte_length = length * element_size; 1962 size_t byte_length = length * element_size;
1907 SetupArrayBufferView(isolate(), obj, buffer, byte_offset, byte_length); 1963 SetupArrayBufferView(isolate(), obj, buffer, byte_offset, byte_length);
1908 1964
1909 Handle<Object> length_object = NewNumberFromSize(length); 1965 Handle<Object> length_object = NewNumberFromSize(length);
1910 obj->set_length(*length_object); 1966 obj->set_length(*length_object);
1911 1967
1912 Handle<ExternalArray> elements = NewExternalArray( 1968 Handle<ExternalArray> elements = NewExternalArray(
1913 static_cast<int>(length), type, 1969 static_cast<int>(length), type,
1914 static_cast<uint8_t*>(buffer->backing_store()) + byte_offset); 1970 static_cast<uint8_t*>(buffer->backing_store()) + byte_offset);
1915 Handle<Map> map = JSObject::GetElementsTransitionMap(obj, elements_kind); 1971 Handle<Map> map = JSObject::GetElementsTransitionMap(obj, elements_kind);
1916 JSObject::SetMapAndElements(obj, map, elements); 1972 JSObject::SetMapAndElements(obj, map, elements);
1917 return obj; 1973 return obj;
1918 } 1974 }
1919 1975
1920 1976
1977 Handle<JSTypedArray> Factory::NewJSTypedArray(ElementsKind elements_kind,
1978 size_t number_of_elements) {
1979 Handle<JSTypedArray> obj = NewJSTypedArray(elements_kind);
1980
1981 size_t element_size = GetFixedTypedArraysElementSize(elements_kind);
1982 ExternalArrayType array_type = GetArrayTypeFromElementsKind(elements_kind);
1983
1984 CHECK(number_of_elements <=
1985 (std::numeric_limits<size_t>::max() / element_size));
1986 CHECK(number_of_elements <= static_cast<size_t>(Smi::kMaxValue));
1987 size_t byte_length = number_of_elements * element_size;
1988
1989 obj->set_byte_offset(Smi::FromInt(0));
1990 i::Handle<i::Object> byte_length_object =
1991 isolate()->factory()->NewNumberFromSize(byte_length);
1992 obj->set_byte_length(*byte_length_object);
1993 Handle<Object> length_object = NewNumberFromSize(number_of_elements);
1994 obj->set_length(*length_object);
1995
1996 obj->set_buffer(Smi::FromInt(0));
1997 obj->set_weak_next(isolate()->heap()->undefined_value());
1998 Handle<FixedTypedArrayBase> elements =
1999 isolate()->factory()->NewFixedTypedArray(
2000 static_cast<int>(number_of_elements), array_type);
2001 obj->set_elements(*elements);
2002 return obj;
2003 }
2004
2005
1921 Handle<JSDataView> Factory::NewJSDataView(Handle<JSArrayBuffer> buffer, 2006 Handle<JSDataView> Factory::NewJSDataView(Handle<JSArrayBuffer> buffer,
1922 size_t byte_offset, 2007 size_t byte_offset,
1923 size_t byte_length) { 2008 size_t byte_length) {
1924 Handle<JSDataView> obj = NewJSDataView(); 2009 Handle<JSDataView> obj = NewJSDataView();
1925 SetupArrayBufferView(isolate(), obj, buffer, byte_offset, byte_length); 2010 SetupArrayBufferView(isolate(), obj, buffer, byte_offset, byte_length);
1926 return obj; 2011 return obj;
1927 } 2012 }
1928 2013
1929 2014
1930 Handle<JSProxy> Factory::NewJSProxy(Handle<Object> handler, 2015 Handle<JSProxy> Factory::NewJSProxy(Handle<Object> handler,
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
2397 return Handle<Object>::null(); 2482 return Handle<Object>::null();
2398 } 2483 }
2399 2484
2400 2485
2401 Handle<Object> Factory::ToBoolean(bool value) { 2486 Handle<Object> Factory::ToBoolean(bool value) {
2402 return value ? true_value() : false_value(); 2487 return value ? true_value() : false_value();
2403 } 2488 }
2404 2489
2405 2490
2406 } } // namespace v8::internal 2491 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/factory.h ('k') | src/layout-descriptor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698