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

Side by Side Diff: src/factory.cc

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