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 1713 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1724 case kExternal##Type##Array: \ | 1724 case kExternal##Type##Array: \ |
1725 return EXTERNAL_##TYPE##_ELEMENTS; | 1725 return EXTERNAL_##TYPE##_ELEMENTS; |
1726 TYPED_ARRAYS(TYPED_ARRAY_CASE) | 1726 TYPED_ARRAYS(TYPED_ARRAY_CASE) |
1727 } | 1727 } |
1728 UNREACHABLE(); | 1728 UNREACHABLE(); |
1729 return FIRST_EXTERNAL_ARRAY_ELEMENTS_KIND; | 1729 return FIRST_EXTERNAL_ARRAY_ELEMENTS_KIND; |
1730 #undef TYPED_ARRAY_CASE | 1730 #undef TYPED_ARRAY_CASE |
1731 } | 1731 } |
1732 | 1732 |
1733 | 1733 |
1734 size_t GetExternalArrayElementSize(ExternalArrayType type) { | |
1735 switch (type) { | |
1736 #define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \ | |
1737 case kExternal##Type##Array: \ | |
1738 return size; | |
1739 TYPED_ARRAYS(TYPED_ARRAY_CASE) | |
1740 } | |
1741 UNREACHABLE(); | |
1742 return 0; | |
1743 #undef TYPED_ARRAY_CASE | |
1744 } | |
1745 | |
1746 | |
1734 JSFunction* GetTypedArrayFun(ExternalArrayType type, Isolate* isolate) { | 1747 JSFunction* GetTypedArrayFun(ExternalArrayType type, Isolate* isolate) { |
1735 Context* native_context = isolate->context()->native_context(); | 1748 Context* native_context = isolate->context()->native_context(); |
1736 switch (type) { | 1749 switch (type) { |
1737 #define TYPED_ARRAY_FUN(Type, type, TYPE, ctype, size) \ | 1750 #define TYPED_ARRAY_FUN(Type, type, TYPE, ctype, size) \ |
1738 case kExternal##Type##Array: \ | 1751 case kExternal##Type##Array: \ |
1739 return native_context->type##_array_fun(); | 1752 return native_context->type##_array_fun(); |
1740 | 1753 |
1741 TYPED_ARRAYS(TYPED_ARRAY_FUN) | 1754 TYPED_ARRAYS(TYPED_ARRAY_FUN) |
1742 #undef TYPED_ARRAY_FUN | 1755 #undef TYPED_ARRAY_FUN |
1743 | 1756 |
(...skipping 18 matching lines...) Expand all Loading... | |
1762 | 1775 |
1763 Handle<JSTypedArray> Factory::NewJSTypedArray(ExternalArrayType type, | 1776 Handle<JSTypedArray> Factory::NewJSTypedArray(ExternalArrayType type, |
1764 Handle<JSArrayBuffer> buffer, | 1777 Handle<JSArrayBuffer> buffer, |
1765 size_t length) { | 1778 size_t length) { |
1766 DCHECK(length <= static_cast<size_t>(kMaxInt)); | 1779 DCHECK(length <= static_cast<size_t>(kMaxInt)); |
1767 Handle<JSTypedArray> array = NewJSTypedArray(type); | 1780 Handle<JSTypedArray> array = NewJSTypedArray(type); |
1768 array->set_buffer(*buffer); | 1781 array->set_buffer(*buffer); |
1769 array->set_weak_next(buffer->weak_first_view()); | 1782 array->set_weak_next(buffer->weak_first_view()); |
1770 buffer->set_weak_first_view(*array); | 1783 buffer->set_weak_first_view(*array); |
1771 array->set_byte_offset(Smi::FromInt(0)); | 1784 array->set_byte_offset(Smi::FromInt(0)); |
1772 array->set_byte_length(buffer->byte_length()); | 1785 Handle<Object> byte_length_handle = |
Dmitry Lomov (no reviews)
2014/10/10 08:43:02
DBC: why we have this Factory::NewJSTypedArray?
W
| |
1786 NewNumberFromSize(length * GetExternalArrayElementSize(type)); | |
1787 array->set_byte_length(*byte_length_handle); | |
1773 Handle<Object> length_handle = NewNumberFromSize(length); | 1788 Handle<Object> length_handle = NewNumberFromSize(length); |
1774 array->set_length(*length_handle); | 1789 array->set_length(*length_handle); |
1775 Handle<ExternalArray> elements = | 1790 Handle<ExternalArray> elements = |
1776 NewExternalArray(static_cast<int>(length), type, buffer->backing_store()); | 1791 NewExternalArray(static_cast<int>(length), type, buffer->backing_store()); |
1777 JSObject::SetMapAndElements(array, | 1792 JSObject::SetMapAndElements(array, |
1778 JSObject::GetElementsTransitionMap( | 1793 JSObject::GetElementsTransitionMap( |
1779 array, GetExternalArrayElementsKind(type)), | 1794 array, GetExternalArrayElementsKind(type)), |
1780 elements); | 1795 elements); |
1781 return array; | 1796 return array; |
1782 } | 1797 } |
(...skipping 653 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2436 return Handle<Object>::null(); | 2451 return Handle<Object>::null(); |
2437 } | 2452 } |
2438 | 2453 |
2439 | 2454 |
2440 Handle<Object> Factory::ToBoolean(bool value) { | 2455 Handle<Object> Factory::ToBoolean(bool value) { |
2441 return value ? true_value() : false_value(); | 2456 return value ? true_value() : false_value(); |
2442 } | 2457 } |
2443 | 2458 |
2444 | 2459 |
2445 } } // namespace v8::internal | 2460 } } // namespace v8::internal |
OLD | NEW |