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

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: update MakeTypeError calls 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
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 1750 matching lines...) Expand 10 before | Expand all | Expand 10 after
1761 JSFunction::EnsureHasInitialMap(function); 1761 JSFunction::EnsureHasInitialMap(function);
1762 Handle<Map> map(function->initial_map()); 1762 Handle<Map> map(function->initial_map());
1763 DCHECK(map->instance_type() == JS_GENERATOR_OBJECT_TYPE); 1763 DCHECK(map->instance_type() == JS_GENERATOR_OBJECT_TYPE);
1764 CALL_HEAP_FUNCTION( 1764 CALL_HEAP_FUNCTION(
1765 isolate(), 1765 isolate(),
1766 isolate()->heap()->AllocateJSObjectFromMap(*map), 1766 isolate()->heap()->AllocateJSObjectFromMap(*map),
1767 JSGeneratorObject); 1767 JSGeneratorObject);
1768 } 1768 }
1769 1769
1770 1770
1771 Handle<JSArrayBuffer> Factory::NewJSArrayBuffer() { 1771 Handle<JSArrayBuffer> Factory::NewJSArrayBuffer(SharedFlag is_shared) {
1772 Handle<JSFunction> array_buffer_fun( 1772 Handle<JSFunction> array_buffer_fun(
1773 isolate()->native_context()->array_buffer_fun()); 1773 is_shared ? isolate()->native_context()->shared_array_buffer_fun()
1774 : isolate()->native_context()->array_buffer_fun());
1774 CALL_HEAP_FUNCTION( 1775 CALL_HEAP_FUNCTION(
1775 isolate(), 1776 isolate(),
1776 isolate()->heap()->AllocateJSObject(*array_buffer_fun), 1777 isolate()->heap()->AllocateJSObject(*array_buffer_fun),
1777 JSArrayBuffer); 1778 JSArrayBuffer);
1778 } 1779 }
1779 1780
1780 1781
1781 Handle<JSDataView> Factory::NewJSDataView() { 1782 Handle<JSDataView> Factory::NewJSDataView() {
1782 Handle<JSFunction> data_view_fun( 1783 Handle<JSFunction> data_view_fun(
1783 isolate()->native_context()->data_view_fun()); 1784 isolate()->native_context()->data_view_fun());
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
1888 TYPED_ARRAYS(TYPED_ARRAY_FUN) 1889 TYPED_ARRAYS(TYPED_ARRAY_FUN)
1889 #undef TYPED_ARRAY_FUN 1890 #undef TYPED_ARRAY_FUN
1890 1891
1891 default: 1892 default:
1892 UNREACHABLE(); 1893 UNREACHABLE();
1893 return NULL; 1894 return NULL;
1894 } 1895 }
1895 } 1896 }
1896 1897
1897 1898
1899 JSFunction* GetSharedTypedArrayFun(ExternalArrayType type, Isolate* isolate) {
1900 Context* native_context = isolate->context()->native_context();
1901 switch (type) {
1902 #define SHARED_TYPED_ARRAY_FUN(Type, type, TYPE, ctype, size) \
1903 case kExternal##Type##Array: \
1904 return native_context->shared_##type##_array_fun();
1905
1906 TYPED_ARRAYS(SHARED_TYPED_ARRAY_FUN)
1907 #undef SHARED_TYPED_ARRAY_FUN
1908
1909 default:
1910 UNREACHABLE();
1911 return NULL;
1912 }
1913 }
1914
1915
1898 void SetupArrayBufferView(i::Isolate* isolate, 1916 void SetupArrayBufferView(i::Isolate* isolate,
1899 i::Handle<i::JSArrayBufferView> obj, 1917 i::Handle<i::JSArrayBufferView> obj,
1900 i::Handle<i::JSArrayBuffer> buffer, 1918 i::Handle<i::JSArrayBuffer> buffer,
1901 size_t byte_offset, size_t byte_length) { 1919 size_t byte_offset, size_t byte_length) {
1902 DCHECK(byte_offset + byte_length <= 1920 DCHECK(byte_offset + byte_length <=
1903 static_cast<size_t>(buffer->byte_length()->Number())); 1921 static_cast<size_t>(buffer->byte_length()->Number()));
1904 1922
1905 obj->set_buffer(*buffer); 1923 obj->set_buffer(*buffer);
1906 1924
1907 i::Handle<i::Object> byte_offset_object = 1925 i::Handle<i::Object> byte_offset_object =
1908 isolate->factory()->NewNumberFromSize(byte_offset); 1926 isolate->factory()->NewNumberFromSize(byte_offset);
1909 obj->set_byte_offset(*byte_offset_object); 1927 obj->set_byte_offset(*byte_offset_object);
1910 1928
1911 i::Handle<i::Object> byte_length_object = 1929 i::Handle<i::Object> byte_length_object =
1912 isolate->factory()->NewNumberFromSize(byte_length); 1930 isolate->factory()->NewNumberFromSize(byte_length);
1913 obj->set_byte_length(*byte_length_object); 1931 obj->set_byte_length(*byte_length_object);
1914 } 1932 }
1915 1933
1916 1934
1917 } // namespace 1935 } // namespace
1918 1936
1919 1937
1920 Handle<JSTypedArray> Factory::NewJSTypedArray(ExternalArrayType type) { 1938 Handle<JSTypedArray> Factory::NewJSTypedArray(ExternalArrayType type,
1921 Handle<JSFunction> typed_array_fun_handle(GetTypedArrayFun(type, isolate())); 1939 SharedFlag is_shared) {
1940 Handle<JSFunction> typed_array_fun_handle(
1941 is_shared ? GetSharedTypedArrayFun(type, isolate())
1942 : GetTypedArrayFun(type, isolate()));
1922 1943
1923 CALL_HEAP_FUNCTION( 1944 CALL_HEAP_FUNCTION(
1924 isolate(), 1945 isolate(),
1925 isolate()->heap()->AllocateJSObject(*typed_array_fun_handle), 1946 isolate()->heap()->AllocateJSObject(*typed_array_fun_handle),
1926 JSTypedArray); 1947 JSTypedArray);
1927 } 1948 }
1928 1949
1929 1950
1930 Handle<JSTypedArray> Factory::NewJSTypedArray(ElementsKind elements_kind) { 1951 Handle<JSTypedArray> Factory::NewJSTypedArray(ElementsKind elements_kind) {
1931 Handle<JSFunction> typed_array_fun_handle( 1952 Handle<JSFunction> typed_array_fun_handle(
1932 GetTypedArrayFun(elements_kind, isolate())); 1953 GetTypedArrayFun(elements_kind, isolate()));
1933 1954
1934 CALL_HEAP_FUNCTION( 1955 CALL_HEAP_FUNCTION(
1935 isolate(), isolate()->heap()->AllocateJSObject(*typed_array_fun_handle), 1956 isolate(), isolate()->heap()->AllocateJSObject(*typed_array_fun_handle),
1936 JSTypedArray); 1957 JSTypedArray);
1937 } 1958 }
1938 1959
1939 1960
1940 Handle<JSTypedArray> Factory::NewJSTypedArray(ExternalArrayType type, 1961 Handle<JSTypedArray> Factory::NewJSTypedArray(ExternalArrayType type,
1941 Handle<JSArrayBuffer> buffer, 1962 Handle<JSArrayBuffer> buffer,
1942 size_t byte_offset, 1963 size_t byte_offset, size_t length,
1943 size_t length) { 1964 SharedFlag is_shared) {
1944 Handle<JSTypedArray> obj = NewJSTypedArray(type); 1965 Handle<JSTypedArray> obj = NewJSTypedArray(type, is_shared);
1945 1966
1946 size_t element_size = GetExternalArrayElementSize(type); 1967 size_t element_size = GetExternalArrayElementSize(type);
1947 ElementsKind elements_kind = GetExternalArrayElementsKind(type); 1968 ElementsKind elements_kind = GetExternalArrayElementsKind(type);
1948 1969
1949 CHECK(byte_offset % element_size == 0); 1970 CHECK(byte_offset % element_size == 0);
1950 1971
1951 CHECK(length <= (std::numeric_limits<size_t>::max() / element_size)); 1972 CHECK(length <= (std::numeric_limits<size_t>::max() / element_size));
1952 CHECK(length <= static_cast<size_t>(Smi::kMaxValue)); 1973 CHECK(length <= static_cast<size_t>(Smi::kMaxValue));
1953 size_t byte_length = length * element_size; 1974 size_t byte_length = length * element_size;
1954 SetupArrayBufferView(isolate(), obj, buffer, byte_offset, byte_length); 1975 SetupArrayBufferView(isolate(), obj, buffer, byte_offset, byte_length);
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after
2472 return Handle<Object>::null(); 2493 return Handle<Object>::null();
2473 } 2494 }
2474 2495
2475 2496
2476 Handle<Object> Factory::ToBoolean(bool value) { 2497 Handle<Object> Factory::ToBoolean(bool value) {
2477 return value ? true_value() : false_value(); 2498 return value ? true_value() : false_value();
2478 } 2499 }
2479 2500
2480 2501
2481 } } // namespace v8::internal 2502 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698