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

Side by Side Diff: src/factory.cc

Issue 1069883002: WIP SharedArrayBuffer implementation (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: merge master Created 5 years, 7 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/flag-definitions.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 1743 matching lines...) Expand 10 before | Expand all | Expand 10 after
1754 JSFunction::EnsureHasInitialMap(function); 1754 JSFunction::EnsureHasInitialMap(function);
1755 Handle<Map> map(function->initial_map()); 1755 Handle<Map> map(function->initial_map());
1756 DCHECK(map->instance_type() == JS_GENERATOR_OBJECT_TYPE); 1756 DCHECK(map->instance_type() == JS_GENERATOR_OBJECT_TYPE);
1757 CALL_HEAP_FUNCTION( 1757 CALL_HEAP_FUNCTION(
1758 isolate(), 1758 isolate(),
1759 isolate()->heap()->AllocateJSObjectFromMap(*map), 1759 isolate()->heap()->AllocateJSObjectFromMap(*map),
1760 JSGeneratorObject); 1760 JSGeneratorObject);
1761 } 1761 }
1762 1762
1763 1763
1764 Handle<JSArrayBuffer> Factory::NewJSArrayBuffer() { 1764 Handle<JSArrayBuffer> Factory::NewJSArrayBuffer(SharedFlag is_shared) {
1765 Handle<JSFunction> array_buffer_fun( 1765 Handle<JSFunction> array_buffer_fun(
1766 isolate()->native_context()->array_buffer_fun()); 1766 is_shared ? isolate()->native_context()->shared_array_buffer_fun()
1767 : isolate()->native_context()->array_buffer_fun());
1767 CALL_HEAP_FUNCTION( 1768 CALL_HEAP_FUNCTION(
1768 isolate(), 1769 isolate(),
1769 isolate()->heap()->AllocateJSObject(*array_buffer_fun), 1770 isolate()->heap()->AllocateJSObject(*array_buffer_fun),
1770 JSArrayBuffer); 1771 JSArrayBuffer);
1771 } 1772 }
1772 1773
1773 1774
1774 Handle<JSDataView> Factory::NewJSDataView() { 1775 Handle<JSDataView> Factory::NewJSDataView() {
1775 Handle<JSFunction> data_view_fun( 1776 Handle<JSFunction> data_view_fun(
1776 isolate()->native_context()->data_view_fun()); 1777 isolate()->native_context()->data_view_fun());
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
1881 TYPED_ARRAYS(TYPED_ARRAY_FUN) 1882 TYPED_ARRAYS(TYPED_ARRAY_FUN)
1882 #undef TYPED_ARRAY_FUN 1883 #undef TYPED_ARRAY_FUN
1883 1884
1884 default: 1885 default:
1885 UNREACHABLE(); 1886 UNREACHABLE();
1886 return NULL; 1887 return NULL;
1887 } 1888 }
1888 } 1889 }
1889 1890
1890 1891
1892 JSFunction* GetSharedTypedArrayFun(ExternalArrayType type, Isolate* isolate) {
1893 Context* native_context = isolate->context()->native_context();
1894 switch (type) {
1895 #define SHARED_TYPED_ARRAY_FUN(Type, type, TYPE, ctype, size) \
1896 case kExternal##Type##Array: \
1897 return native_context->shared_##type##_array_fun();
1898
1899 TYPED_ARRAYS(SHARED_TYPED_ARRAY_FUN)
1900 #undef SHARED_TYPED_ARRAY_FUN
1901
1902 default:
1903 UNREACHABLE();
1904 return NULL;
1905 }
1906 }
1907
1908
1891 void SetupArrayBufferView(i::Isolate* isolate, 1909 void SetupArrayBufferView(i::Isolate* isolate,
1892 i::Handle<i::JSArrayBufferView> obj, 1910 i::Handle<i::JSArrayBufferView> obj,
1893 i::Handle<i::JSArrayBuffer> buffer, 1911 i::Handle<i::JSArrayBuffer> buffer,
1894 size_t byte_offset, size_t byte_length) { 1912 size_t byte_offset, size_t byte_length) {
1895 DCHECK(byte_offset + byte_length <= 1913 DCHECK(byte_offset + byte_length <=
1896 static_cast<size_t>(buffer->byte_length()->Number())); 1914 static_cast<size_t>(buffer->byte_length()->Number()));
1897 1915
1898 obj->set_buffer(*buffer); 1916 obj->set_buffer(*buffer);
1899 1917
1900 i::Handle<i::Object> byte_offset_object = 1918 i::Handle<i::Object> byte_offset_object =
1901 isolate->factory()->NewNumberFromSize(byte_offset); 1919 isolate->factory()->NewNumberFromSize(byte_offset);
1902 obj->set_byte_offset(*byte_offset_object); 1920 obj->set_byte_offset(*byte_offset_object);
1903 1921
1904 i::Handle<i::Object> byte_length_object = 1922 i::Handle<i::Object> byte_length_object =
1905 isolate->factory()->NewNumberFromSize(byte_length); 1923 isolate->factory()->NewNumberFromSize(byte_length);
1906 obj->set_byte_length(*byte_length_object); 1924 obj->set_byte_length(*byte_length_object);
1907 } 1925 }
1908 1926
1909 1927
1910 } // namespace 1928 } // namespace
1911 1929
1912 1930
1913 Handle<JSTypedArray> Factory::NewJSTypedArray(ExternalArrayType type) { 1931 Handle<JSTypedArray> Factory::NewJSTypedArray(ExternalArrayType type,
1914 Handle<JSFunction> typed_array_fun_handle(GetTypedArrayFun(type, isolate())); 1932 SharedFlag is_shared) {
1933 Handle<JSFunction> typed_array_fun_handle(
1934 is_shared ? GetSharedTypedArrayFun(type, isolate())
1935 : GetTypedArrayFun(type, isolate()));
1915 1936
1916 CALL_HEAP_FUNCTION( 1937 CALL_HEAP_FUNCTION(
1917 isolate(), 1938 isolate(),
1918 isolate()->heap()->AllocateJSObject(*typed_array_fun_handle), 1939 isolate()->heap()->AllocateJSObject(*typed_array_fun_handle),
1919 JSTypedArray); 1940 JSTypedArray);
1920 } 1941 }
1921 1942
1922 1943
1923 Handle<JSTypedArray> Factory::NewJSTypedArray(ElementsKind elements_kind) { 1944 Handle<JSTypedArray> Factory::NewJSTypedArray(ElementsKind elements_kind) {
1924 Handle<JSFunction> typed_array_fun_handle( 1945 Handle<JSFunction> typed_array_fun_handle(
1925 GetTypedArrayFun(elements_kind, isolate())); 1946 GetTypedArrayFun(elements_kind, isolate()));
1926 1947
1927 CALL_HEAP_FUNCTION( 1948 CALL_HEAP_FUNCTION(
1928 isolate(), isolate()->heap()->AllocateJSObject(*typed_array_fun_handle), 1949 isolate(), isolate()->heap()->AllocateJSObject(*typed_array_fun_handle),
1929 JSTypedArray); 1950 JSTypedArray);
1930 } 1951 }
1931 1952
1932 1953
1933 Handle<JSTypedArray> Factory::NewJSTypedArray(ExternalArrayType type, 1954 Handle<JSTypedArray> Factory::NewJSTypedArray(ExternalArrayType type,
1934 Handle<JSArrayBuffer> buffer, 1955 Handle<JSArrayBuffer> buffer,
1935 size_t byte_offset, 1956 size_t byte_offset, size_t length,
1936 size_t length) { 1957 SharedFlag is_shared) {
1937 Handle<JSTypedArray> obj = NewJSTypedArray(type); 1958 Handle<JSTypedArray> obj = NewJSTypedArray(type, is_shared);
1938 1959
1939 size_t element_size = GetExternalArrayElementSize(type); 1960 size_t element_size = GetExternalArrayElementSize(type);
1940 ElementsKind elements_kind = GetExternalArrayElementsKind(type); 1961 ElementsKind elements_kind = GetExternalArrayElementsKind(type);
1941 1962
1942 CHECK(byte_offset % element_size == 0); 1963 CHECK(byte_offset % element_size == 0);
1943 1964
1944 CHECK(length <= (std::numeric_limits<size_t>::max() / element_size)); 1965 CHECK(length <= (std::numeric_limits<size_t>::max() / element_size));
1945 CHECK(length <= static_cast<size_t>(Smi::kMaxValue)); 1966 CHECK(length <= static_cast<size_t>(Smi::kMaxValue));
1946 size_t byte_length = length * element_size; 1967 size_t byte_length = length * element_size;
1947 SetupArrayBufferView(isolate(), obj, buffer, byte_offset, byte_length); 1968 SetupArrayBufferView(isolate(), obj, buffer, byte_offset, byte_length);
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after
2469 return Handle<Object>::null(); 2490 return Handle<Object>::null();
2470 } 2491 }
2471 2492
2472 2493
2473 Handle<Object> Factory::ToBoolean(bool value) { 2494 Handle<Object> Factory::ToBoolean(bool value) {
2474 return value ? true_value() : false_value(); 2495 return value ? true_value() : false_value();
2475 } 2496 }
2476 2497
2477 2498
2478 } } // namespace v8::internal 2499 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/factory.h ('k') | src/flag-definitions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698