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, | 1719 namespace { |
1720 Isolate* isolate) { | 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) { | |
1721 Context* native_context = isolate->context()->native_context(); | 1735 Context* native_context = isolate->context()->native_context(); |
1722 switch (type) { | 1736 switch (type) { |
1723 #define TYPED_ARRAY_FUN(Type, type, TYPE, ctype, size) \ | 1737 #define TYPED_ARRAY_FUN(Type, type, TYPE, ctype, size) \ |
1724 case kExternal##Type##Array: \ | 1738 case kExternal##Type##Array: \ |
1725 return native_context->type##_array_fun(); | 1739 return native_context->type##_array_fun(); |
1726 | 1740 |
1727 TYPED_ARRAYS(TYPED_ARRAY_FUN) | 1741 TYPED_ARRAYS(TYPED_ARRAY_FUN) |
1728 #undef TYPED_ARRAY_FUN | 1742 #undef TYPED_ARRAY_FUN |
1729 | 1743 |
1730 default: | 1744 default: |
1731 UNREACHABLE(); | 1745 UNREACHABLE(); |
1732 return NULL; | 1746 return NULL; |
1733 } | 1747 } |
1734 } | 1748 } |
1735 | 1749 |
1750 } // namespace | |
1751 | |
1736 | 1752 |
1737 Handle<JSTypedArray> Factory::NewJSTypedArray(ExternalArrayType type) { | 1753 Handle<JSTypedArray> Factory::NewJSTypedArray(ExternalArrayType type) { |
1738 Handle<JSFunction> typed_array_fun_handle(GetTypedArrayFun(type, isolate())); | 1754 Handle<JSFunction> typed_array_fun_handle(GetTypedArrayFun(type, isolate())); |
1739 | 1755 |
1740 CALL_HEAP_FUNCTION( | 1756 CALL_HEAP_FUNCTION( |
1741 isolate(), | 1757 isolate(), |
1742 isolate()->heap()->AllocateJSObject(*typed_array_fun_handle), | 1758 isolate()->heap()->AllocateJSObject(*typed_array_fun_handle), |
1743 JSTypedArray); | 1759 JSTypedArray); |
1744 } | 1760 } |
1745 | 1761 |
1746 | 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 array->set_length(*NewNumberFromSize(length)); | |
Michael Starzinger
2014/10/02 08:33:06
This is not handle-safe I think, GCMole will shout
| |
1774 Handle<ExternalArray> elements = | |
1775 NewExternalArray(static_cast<int>(length), type, buffer->backing_store()); | |
1776 JSObject::SetMapAndElements(array, | |
1777 JSObject::GetElementsTransitionMap( | |
1778 array, GetExternalArrayElementsKind(type)), | |
1779 elements); | |
1780 return array; | |
1781 } | |
1782 | |
1783 | |
1747 Handle<JSProxy> Factory::NewJSProxy(Handle<Object> handler, | 1784 Handle<JSProxy> Factory::NewJSProxy(Handle<Object> handler, |
1748 Handle<Object> prototype) { | 1785 Handle<Object> prototype) { |
1749 // Allocate map. | 1786 // Allocate map. |
1750 // TODO(rossberg): Once we optimize proxies, think about a scheme to share | 1787 // TODO(rossberg): Once we optimize proxies, think about a scheme to share |
1751 // maps. Will probably depend on the identity of the handler object, too. | 1788 // maps. Will probably depend on the identity of the handler object, too. |
1752 Handle<Map> map = NewMap(JS_PROXY_TYPE, JSProxy::kSize); | 1789 Handle<Map> map = NewMap(JS_PROXY_TYPE, JSProxy::kSize); |
1753 map->set_prototype(*prototype); | 1790 map->set_prototype(*prototype); |
1754 | 1791 |
1755 // Allocate the proxy object. | 1792 // Allocate the proxy object. |
1756 Handle<JSProxy> result = New<JSProxy>(map, NEW_SPACE); | 1793 Handle<JSProxy> result = New<JSProxy>(map, NEW_SPACE); |
(...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2398 return Handle<Object>::null(); | 2435 return Handle<Object>::null(); |
2399 } | 2436 } |
2400 | 2437 |
2401 | 2438 |
2402 Handle<Object> Factory::ToBoolean(bool value) { | 2439 Handle<Object> Factory::ToBoolean(bool value) { |
2403 return value ? true_value() : false_value(); | 2440 return value ? true_value() : false_value(); |
2404 } | 2441 } |
2405 | 2442 |
2406 | 2443 |
2407 } } // namespace v8::internal | 2444 } } // namespace v8::internal |
OLD | NEW |