Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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/builtins.h" | 5 #include "src/builtins.h" |
| 6 | 6 |
| 7 #include "src/api.h" | 7 #include "src/api.h" |
| 8 #include "src/api-natives.h" | 8 #include "src/api-natives.h" |
| 9 #include "src/arguments.h" | 9 #include "src/arguments.h" |
| 10 #include "src/base/once.h" | 10 #include "src/base/once.h" |
| (...skipping 1726 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1737 HandleScope scope(isolate); | 1737 HandleScope scope(isolate); |
| 1738 // The ConstructStub is executed in the context of the caller, so we need | 1738 // The ConstructStub is executed in the context of the caller, so we need |
| 1739 // to enter the callee context first before raising an exception. | 1739 // to enter the callee context first before raising an exception. |
| 1740 isolate->set_context(args.target()->context()); | 1740 isolate->set_context(args.target()->context()); |
| 1741 THROW_NEW_ERROR_RETURN_FAILURE( | 1741 THROW_NEW_ERROR_RETURN_FAILURE( |
| 1742 isolate, NewTypeError(MessageTemplate::kNotConstructor, | 1742 isolate, NewTypeError(MessageTemplate::kNotConstructor, |
| 1743 isolate->factory()->Symbol_string())); | 1743 isolate->factory()->Symbol_string())); |
| 1744 } | 1744 } |
| 1745 | 1745 |
| 1746 | 1746 |
| 1747 // ES6 section 24.1.2.1 ArrayBuffer( length ) for the [[Call]] case. | |
| 1748 BUILTIN(ArrayBufferConstructor) { | |
| 1749 HandleScope scope(isolate); | |
| 1750 Handle<JSFunction> target = args.target(); | |
| 1751 DCHECK(*target == target->native_context()->array_buffer_fun() || | |
| 1752 *target == target->native_context()->shared_array_buffer_fun()); | |
| 1753 THROW_NEW_ERROR_RETURN_FAILURE( | |
| 1754 isolate, NewTypeError(MessageTemplate::kConstructorNotFunction, | |
| 1755 handle(target->shared()->name(), isolate))); | |
| 1756 } | |
| 1757 | |
| 1758 | |
| 1759 // ES6 section 24.1.2.1 ArrayBuffer( length ) for the [[Construct]] case. | |
| 1760 BUILTIN(ArrayBufferConstructor_ConstructStub) { | |
| 1761 HandleScope scope(isolate); | |
| 1762 DCHECK_EQ(2, args.length()); | |
| 1763 Handle<JSFunction> target = args.target(); | |
| 1764 Handle<JSReceiver> new_target = Handle<JSReceiver>::cast(args.new_target()); | |
| 1765 Handle<Object> length = args.at<Object>(1); | |
| 1766 DCHECK(*target == target->native_context()->array_buffer_fun() || | |
| 1767 *target == target->native_context()->shared_array_buffer_fun()); | |
| 1768 // The ConstructStub is executed in the context of the caller, so we need | |
| 1769 // to enter the callee context first before raising an exception. | |
| 1770 isolate->set_context(args.target()->context()); | |
| 1771 Handle<Object> number_length; | |
| 1772 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, number_length, | |
|
Camillo Bruni
2015/12/03 14:58:28
shouldn't the byteLength conversion happen after c
Benedikt Meurer
2015/12/03 15:24:56
No, for builtins the creation happens later.
| |
| 1773 Object::ToNumber(length)); | |
| 1774 size_t byte_length; | |
| 1775 if (!TryNumberToSize(isolate, *number_length, &byte_length)) { | |
| 1776 THROW_NEW_ERROR_RETURN_FAILURE( | |
| 1777 isolate, NewRangeError(MessageTemplate::kInvalidArrayBufferLength)); | |
| 1778 } | |
| 1779 Handle<Map> initial_map; | |
| 1780 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | |
| 1781 isolate, initial_map, | |
| 1782 JSFunction::GetDerivedMap(isolate, target, new_target)); | |
| 1783 Handle<JSArrayBuffer> result = Handle<JSArrayBuffer>::cast( | |
| 1784 isolate->factory()->NewJSObjectFromMap(initial_map)); | |
| 1785 SharedFlag shared_flag = | |
| 1786 (*target == target->native_context()->array_buffer_fun()) | |
| 1787 ? SharedFlag::kNotShared | |
| 1788 : SharedFlag::kShared; | |
| 1789 if (!JSArrayBuffer::SetupAllocatingData(result, isolate, byte_length, true, | |
| 1790 shared_flag)) { | |
| 1791 THROW_NEW_ERROR_RETURN_FAILURE( | |
| 1792 isolate, NewRangeError(MessageTemplate::kArrayBufferAllocationFailed)); | |
| 1793 } | |
| 1794 return *result; | |
| 1795 } | |
| 1796 | |
| 1797 | |
| 1798 // ES6 section 24.1.3.1 ArrayBuffer.isView ( arg ) | |
| 1799 BUILTIN(ArrayBufferIsView) { | |
| 1800 SealHandleScope shs(isolate); | |
| 1801 DCHECK_EQ(2, args.length()); | |
| 1802 Object* arg = args[1]; | |
| 1803 return isolate->heap()->ToBoolean(arg->IsJSArrayBufferView()); | |
| 1804 } | |
| 1805 | |
| 1806 | |
| 1747 namespace { | 1807 namespace { |
| 1748 | 1808 |
| 1749 // ES6 section 9.5.15 ProxyCreate (target, handler) | 1809 // ES6 section 9.5.15 ProxyCreate (target, handler) |
| 1750 MaybeHandle<JSProxy> ProxyCreate(Isolate* isolate, Handle<Object> target, | 1810 MaybeHandle<JSProxy> ProxyCreate(Isolate* isolate, Handle<Object> target, |
| 1751 Handle<Object> handler) { | 1811 Handle<Object> handler) { |
| 1752 if (!target->IsJSReceiver()) { | 1812 if (!target->IsJSReceiver()) { |
| 1753 THROW_NEW_ERROR( | 1813 THROW_NEW_ERROR( |
| 1754 isolate, NewTypeError(MessageTemplate::kProxyTargetNonObject), JSProxy); | 1814 isolate, NewTypeError(MessageTemplate::kProxyTargetNonObject), JSProxy); |
| 1755 } | 1815 } |
| 1756 if (target->IsJSProxy() && JSProxy::cast(*target)->IsRevoked()) { | 1816 if (target->IsJSProxy() && JSProxy::cast(*target)->IsRevoked()) { |
| (...skipping 674 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2431 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) | 2491 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) |
| 2432 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) | 2492 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) |
| 2433 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) | 2493 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) |
| 2434 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) | 2494 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) |
| 2435 #undef DEFINE_BUILTIN_ACCESSOR_C | 2495 #undef DEFINE_BUILTIN_ACCESSOR_C |
| 2436 #undef DEFINE_BUILTIN_ACCESSOR_A | 2496 #undef DEFINE_BUILTIN_ACCESSOR_A |
| 2437 | 2497 |
| 2438 | 2498 |
| 2439 } // namespace internal | 2499 } // namespace internal |
| 2440 } // namespace v8 | 2500 } // namespace v8 |
| OLD | NEW |