OLD | NEW |
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/conversions.h" | 9 #include "src/conversions.h" |
10 #include "src/isolate-inl.h" | 10 #include "src/isolate-inl.h" |
(...skipping 1698 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1709 Handle<JSDataView> Factory::NewJSDataView() { | 1709 Handle<JSDataView> Factory::NewJSDataView() { |
1710 Handle<JSFunction> data_view_fun( | 1710 Handle<JSFunction> data_view_fun( |
1711 isolate()->native_context()->data_view_fun()); | 1711 isolate()->native_context()->data_view_fun()); |
1712 CALL_HEAP_FUNCTION( | 1712 CALL_HEAP_FUNCTION( |
1713 isolate(), | 1713 isolate(), |
1714 isolate()->heap()->AllocateJSObject(*data_view_fun), | 1714 isolate()->heap()->AllocateJSObject(*data_view_fun), |
1715 JSDataView); | 1715 JSDataView); |
1716 } | 1716 } |
1717 | 1717 |
1718 | 1718 |
1719 static JSFunction* GetTypedArrayFun(ExternalArrayType type, Isolate* isolate) { | 1719 namespace { |
| 1720 |
| 1721 ElementsKind GetExternalArrayElementsKind(ExternalArrayType type) { |
| 1722 switch (type) { |
| 1723 #define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \ |
| 1724 case kExternal##Type##Array: \ |
| 1725 return EXTERNAL_##TYPE##_ELEMENTS; |
| 1726 TYPED_ARRAYS(TYPED_ARRAY_CASE) |
| 1727 } |
| 1728 UNREACHABLE(); |
| 1729 return FIRST_EXTERNAL_ARRAY_ELEMENTS_KIND; |
| 1730 #undef TYPED_ARRAY_CASE |
| 1731 } |
| 1732 |
| 1733 |
| 1734 JSFunction* GetTypedArrayFun(ExternalArrayType type, Isolate* isolate) { |
1720 Context* native_context = isolate->context()->native_context(); | 1735 Context* native_context = isolate->context()->native_context(); |
1721 switch (type) { | 1736 switch (type) { |
1722 #define TYPED_ARRAY_FUN(Type, type, TYPE, ctype, size) \ | 1737 #define TYPED_ARRAY_FUN(Type, type, TYPE, ctype, size) \ |
1723 case kExternal##Type##Array: \ | 1738 case kExternal##Type##Array: \ |
1724 return native_context->type##_array_fun(); | 1739 return native_context->type##_array_fun(); |
1725 | 1740 |
1726 TYPED_ARRAYS(TYPED_ARRAY_FUN) | 1741 TYPED_ARRAYS(TYPED_ARRAY_FUN) |
1727 #undef TYPED_ARRAY_FUN | 1742 #undef TYPED_ARRAY_FUN |
1728 | 1743 |
1729 default: | 1744 default: |
1730 UNREACHABLE(); | 1745 UNREACHABLE(); |
1731 return NULL; | 1746 return NULL; |
1732 } | 1747 } |
1733 } | 1748 } |
1734 | 1749 |
| 1750 } // namespace |
| 1751 |
1735 | 1752 |
1736 Handle<JSTypedArray> Factory::NewJSTypedArray(ExternalArrayType type) { | 1753 Handle<JSTypedArray> Factory::NewJSTypedArray(ExternalArrayType type) { |
1737 Handle<JSFunction> typed_array_fun_handle(GetTypedArrayFun(type, isolate())); | 1754 Handle<JSFunction> typed_array_fun_handle(GetTypedArrayFun(type, isolate())); |
1738 | 1755 |
1739 CALL_HEAP_FUNCTION( | 1756 CALL_HEAP_FUNCTION( |
1740 isolate(), | 1757 isolate(), |
1741 isolate()->heap()->AllocateJSObject(*typed_array_fun_handle), | 1758 isolate()->heap()->AllocateJSObject(*typed_array_fun_handle), |
1742 JSTypedArray); | 1759 JSTypedArray); |
1743 } | 1760 } |
1744 | 1761 |
1745 | 1762 |
| 1763 Handle<JSTypedArray> Factory::NewJSTypedArray(ExternalArrayType type, |
| 1764 Handle<JSArrayBuffer> buffer, |
| 1765 size_t length) { |
| 1766 DCHECK(length <= static_cast<size_t>(kMaxInt)); |
| 1767 Handle<JSTypedArray> array = NewJSTypedArray(type); |
| 1768 array->set_buffer(*buffer); |
| 1769 array->set_weak_next(buffer->weak_first_view()); |
| 1770 buffer->set_weak_first_view(*array); |
| 1771 array->set_byte_offset(Smi::FromInt(0)); |
| 1772 array->set_byte_length(buffer->byte_length()); |
| 1773 Handle<Object> length_handle = NewNumberFromSize(length); |
| 1774 array->set_length(*length_handle); |
| 1775 Handle<ExternalArray> elements = |
| 1776 NewExternalArray(static_cast<int>(length), type, buffer->backing_store()); |
| 1777 JSObject::SetMapAndElements(array, |
| 1778 JSObject::GetElementsTransitionMap( |
| 1779 array, GetExternalArrayElementsKind(type)), |
| 1780 elements); |
| 1781 return array; |
| 1782 } |
| 1783 |
| 1784 |
1746 Handle<JSProxy> Factory::NewJSProxy(Handle<Object> handler, | 1785 Handle<JSProxy> Factory::NewJSProxy(Handle<Object> handler, |
1747 Handle<Object> prototype) { | 1786 Handle<Object> prototype) { |
1748 // Allocate map. | 1787 // Allocate map. |
1749 // TODO(rossberg): Once we optimize proxies, think about a scheme to share | 1788 // TODO(rossberg): Once we optimize proxies, think about a scheme to share |
1750 // maps. Will probably depend on the identity of the handler object, too. | 1789 // maps. Will probably depend on the identity of the handler object, too. |
1751 Handle<Map> map = NewMap(JS_PROXY_TYPE, JSProxy::kSize); | 1790 Handle<Map> map = NewMap(JS_PROXY_TYPE, JSProxy::kSize); |
1752 map->set_prototype(*prototype); | 1791 map->set_prototype(*prototype); |
1753 | 1792 |
1754 // Allocate the proxy object. | 1793 // Allocate the proxy object. |
1755 Handle<JSProxy> result = New<JSProxy>(map, NEW_SPACE); | 1794 Handle<JSProxy> result = New<JSProxy>(map, NEW_SPACE); |
(...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2397 return Handle<Object>::null(); | 2436 return Handle<Object>::null(); |
2398 } | 2437 } |
2399 | 2438 |
2400 | 2439 |
2401 Handle<Object> Factory::ToBoolean(bool value) { | 2440 Handle<Object> Factory::ToBoolean(bool value) { |
2402 return value ? true_value() : false_value(); | 2441 return value ? true_value() : false_value(); |
2403 } | 2442 } |
2404 | 2443 |
2405 | 2444 |
2406 } } // namespace v8::internal | 2445 } } // namespace v8::internal |
OLD | NEW |