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

Side by Side Diff: src/factory.cc

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