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

Side by Side Diff: src/factory.cc

Issue 1080403004: Revert of Reland "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 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;
1831 } 1828 }
1829 UNREACHABLE();
1830 return 0;
1832 #undef TYPED_ARRAY_CASE 1831 #undef TYPED_ARRAY_CASE
1833 } 1832 }
1834 1833
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
1863 1834
1864 JSFunction* GetTypedArrayFun(ExternalArrayType type, Isolate* isolate) { 1835 JSFunction* GetTypedArrayFun(ExternalArrayType type, Isolate* isolate) {
1865 Context* native_context = isolate->context()->native_context(); 1836 Context* native_context = isolate->context()->native_context();
1866 switch (type) { 1837 switch (type) {
1867 #define TYPED_ARRAY_FUN(Type, type, TYPE, ctype, size) \ 1838 #define TYPED_ARRAY_FUN(Type, type, TYPE, ctype, size) \
1868 case kExternal##Type##Array: \ 1839 case kExternal##Type##Array: \
1869 return native_context->type##_array_fun(); 1840 return native_context->type##_array_fun();
1870 1841
1871 TYPED_ARRAYS(TYPED_ARRAY_FUN) 1842 TYPED_ARRAYS(TYPED_ARRAY_FUN)
1872 #undef TYPED_ARRAY_FUN 1843 #undef TYPED_ARRAY_FUN
1873
1874 default:
1875 UNREACHABLE();
1876 return NULL;
1877 }
1878 }
1879
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 1844
1891 default: 1845 default:
1892 UNREACHABLE(); 1846 UNREACHABLE();
1893 return NULL; 1847 return NULL;
1894 } 1848 }
1895 } 1849 }
1896 1850
1897 1851
1898 void SetupArrayBufferView(i::Isolate* isolate, 1852 void SetupArrayBufferView(i::Isolate* isolate,
1899 i::Handle<i::JSArrayBufferView> obj, 1853 i::Handle<i::JSArrayBufferView> obj,
(...skipping 29 matching lines...) Expand all
1929 Handle<JSTypedArray> Factory::NewJSTypedArray(ExternalArrayType type) { 1883 Handle<JSTypedArray> Factory::NewJSTypedArray(ExternalArrayType type) {
1930 Handle<JSFunction> typed_array_fun_handle(GetTypedArrayFun(type, isolate())); 1884 Handle<JSFunction> typed_array_fun_handle(GetTypedArrayFun(type, isolate()));
1931 1885
1932 CALL_HEAP_FUNCTION( 1886 CALL_HEAP_FUNCTION(
1933 isolate(), 1887 isolate(),
1934 isolate()->heap()->AllocateJSObject(*typed_array_fun_handle), 1888 isolate()->heap()->AllocateJSObject(*typed_array_fun_handle),
1935 JSTypedArray); 1889 JSTypedArray);
1936 } 1890 }
1937 1891
1938 1892
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
1949 Handle<JSTypedArray> Factory::NewJSTypedArray(ExternalArrayType type, 1893 Handle<JSTypedArray> Factory::NewJSTypedArray(ExternalArrayType type,
1950 Handle<JSArrayBuffer> buffer, 1894 Handle<JSArrayBuffer> buffer,
1951 size_t byte_offset, 1895 size_t byte_offset,
1952 size_t length) { 1896 size_t length) {
1953 Handle<JSTypedArray> obj = NewJSTypedArray(type); 1897 Handle<JSTypedArray> obj = NewJSTypedArray(type);
1954 1898
1955 size_t element_size = GetExternalArrayElementSize(type); 1899 size_t element_size = GetExternalArrayElementSize(type);
1956 ElementsKind elements_kind = GetExternalArrayElementsKind(type); 1900 ElementsKind elements_kind = GetExternalArrayElementsKind(type);
1957 1901
1958 CHECK(byte_offset % element_size == 0); 1902 CHECK(byte_offset % element_size == 0);
1959 1903
1960 CHECK(length <= (std::numeric_limits<size_t>::max() / element_size)); 1904 CHECK(length <= (std::numeric_limits<size_t>::max() / element_size));
1961 CHECK(length <= static_cast<size_t>(Smi::kMaxValue)); 1905 CHECK(length <= static_cast<size_t>(Smi::kMaxValue));
1962 size_t byte_length = length * element_size; 1906 size_t byte_length = length * element_size;
1963 SetupArrayBufferView(isolate(), obj, buffer, byte_offset, byte_length); 1907 SetupArrayBufferView(isolate(), obj, buffer, byte_offset, byte_length);
1964 1908
1965 Handle<Object> length_object = NewNumberFromSize(length); 1909 Handle<Object> length_object = NewNumberFromSize(length);
1966 obj->set_length(*length_object); 1910 obj->set_length(*length_object);
1967 1911
1968 Handle<ExternalArray> elements = NewExternalArray( 1912 Handle<ExternalArray> elements = NewExternalArray(
1969 static_cast<int>(length), type, 1913 static_cast<int>(length), type,
1970 static_cast<uint8_t*>(buffer->backing_store()) + byte_offset); 1914 static_cast<uint8_t*>(buffer->backing_store()) + byte_offset);
1971 Handle<Map> map = JSObject::GetElementsTransitionMap(obj, elements_kind); 1915 Handle<Map> map = JSObject::GetElementsTransitionMap(obj, elements_kind);
1972 JSObject::SetMapAndElements(obj, map, elements); 1916 JSObject::SetMapAndElements(obj, map, elements);
1973 return obj; 1917 return obj;
1974 } 1918 }
1975 1919
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 1920
2006 Handle<JSDataView> Factory::NewJSDataView(Handle<JSArrayBuffer> buffer, 1921 Handle<JSDataView> Factory::NewJSDataView(Handle<JSArrayBuffer> buffer,
2007 size_t byte_offset, 1922 size_t byte_offset,
2008 size_t byte_length) { 1923 size_t byte_length) {
2009 Handle<JSDataView> obj = NewJSDataView(); 1924 Handle<JSDataView> obj = NewJSDataView();
2010 SetupArrayBufferView(isolate(), obj, buffer, byte_offset, byte_length); 1925 SetupArrayBufferView(isolate(), obj, buffer, byte_offset, byte_length);
2011 return obj; 1926 return obj;
2012 } 1927 }
2013 1928
2014 1929
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after
2482 return Handle<Object>::null(); 2397 return Handle<Object>::null();
2483 } 2398 }
2484 2399
2485 2400
2486 Handle<Object> Factory::ToBoolean(bool value) { 2401 Handle<Object> Factory::ToBoolean(bool value) {
2487 return value ? true_value() : false_value(); 2402 return value ? true_value() : false_value();
2488 } 2403 }
2489 2404
2490 2405
2491 } } // namespace v8::internal 2406 } } // 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