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/runtime/runtime-utils.h" | 5 #include "src/runtime/runtime-utils.h" |
6 | 6 |
7 #include "src/arguments.h" | 7 #include "src/arguments.h" |
8 #include "src/factory.h" | 8 #include "src/factory.h" |
9 #include "src/objects-inl.h" | 9 #include "src/objects-inl.h" |
10 | 10 |
11 namespace v8 { | 11 namespace v8 { |
12 namespace internal { | 12 namespace internal { |
13 | 13 |
14 RUNTIME_FUNCTION(Runtime_CreateJSProxy) { | 14 RUNTIME_FUNCTION(Runtime_CreateJSProxy) { |
15 HandleScope scope(isolate); | 15 HandleScope scope(isolate); |
16 DCHECK(args.length() == 3); | 16 DCHECK(args.length() == 2); |
17 CONVERT_ARG_HANDLE_CHECKED(JSProxy, instance, 0); | 17 CONVERT_ARG_HANDLE_CHECKED(Object, target, 0); |
18 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, target, 1); | 18 CONVERT_ARG_HANDLE_CHECKED(Object, handler, 1); |
19 CONVERT_ARG_HANDLE_CHECKED(Object, handler, 2); | |
20 if (!target->IsSpecObject()) { | 19 if (!target->IsSpecObject()) { |
21 THROW_NEW_ERROR_RETURN_FAILURE( | 20 THROW_NEW_ERROR_RETURN_FAILURE( |
22 isolate, NewTypeError(MessageTemplate::kProxyTargetNonObject)); | 21 isolate, NewTypeError(MessageTemplate::kProxyTargetNonObject)); |
23 } | 22 } |
24 if (target->IsJSProxy() && !JSProxy::cast(*target)->has_handler()) { | 23 if (target->IsJSProxy() && !JSProxy::cast(*target)->has_handler()) { |
25 // TODO(cbruni): Use better error message. | 24 // TODO(cbruni): Use better error message. |
26 THROW_NEW_ERROR_RETURN_FAILURE( | 25 THROW_NEW_ERROR_RETURN_FAILURE( |
27 isolate, NewTypeError(MessageTemplate::kProxyTargetNonObject)); | 26 isolate, NewTypeError(MessageTemplate::kProxyTargetNonObject)); |
28 } | 27 } |
29 if (!handler->IsSpecObject()) { | 28 if (!handler->IsSpecObject()) { |
30 THROW_NEW_ERROR_RETURN_FAILURE( | 29 THROW_NEW_ERROR_RETURN_FAILURE( |
31 isolate, NewTypeError(MessageTemplate::kProxyHandlerNonObject)); | 30 isolate, NewTypeError(MessageTemplate::kProxyHandlerNonObject)); |
32 } | 31 } |
33 if (handler->IsJSProxy() && !JSProxy::cast(*handler)->has_handler()) { | 32 if (handler->IsJSProxy() && !JSProxy::cast(*handler)->has_handler()) { |
34 // TODO(cbruni): Use better error message. | 33 // TODO(cbruni): Use better error message. |
35 THROW_NEW_ERROR_RETURN_FAILURE( | 34 THROW_NEW_ERROR_RETURN_FAILURE( |
36 isolate, NewTypeError(MessageTemplate::kProxyHandlerNonObject)); | 35 isolate, NewTypeError(MessageTemplate::kProxyHandlerNonObject)); |
37 } | 36 } |
38 instance->set_target(*target); | 37 return *isolate->factory()->NewJSProxy(Handle<JSReceiver>::cast(target), |
39 instance->set_handler(*handler); | 38 Handle<JSReceiver>::cast(handler)); |
40 instance->set_hash(isolate->heap()->undefined_value(), SKIP_WRITE_BARRIER); | |
41 return *instance; | |
42 } | 39 } |
43 | 40 |
44 | 41 |
45 RUNTIME_FUNCTION(Runtime_CreateJSFunctionProxy) { | 42 RUNTIME_FUNCTION(Runtime_CreateJSFunctionProxy) { |
46 HandleScope scope(isolate); | 43 HandleScope scope(isolate); |
47 DCHECK(args.length() == 5); | 44 DCHECK(args.length() == 5); |
48 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, target, 0); | 45 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, target, 0); |
49 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, handler, 1); | 46 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, handler, 1); |
50 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, call_trap, 2); | 47 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, call_trap, 2); |
51 RUNTIME_ASSERT(call_trap->IsJSFunction() || call_trap->IsJSFunctionProxy()); | 48 RUNTIME_ASSERT(call_trap->IsJSFunction() || call_trap->IsJSFunctionProxy()); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 | 88 |
92 RUNTIME_FUNCTION(Runtime_GetConstructTrap) { | 89 RUNTIME_FUNCTION(Runtime_GetConstructTrap) { |
93 SealHandleScope shs(isolate); | 90 SealHandleScope shs(isolate); |
94 DCHECK(args.length() == 1); | 91 DCHECK(args.length() == 1); |
95 CONVERT_ARG_CHECKED(JSFunctionProxy, proxy, 0); | 92 CONVERT_ARG_CHECKED(JSFunctionProxy, proxy, 0); |
96 return proxy->construct_trap(); | 93 return proxy->construct_trap(); |
97 } | 94 } |
98 | 95 |
99 } // namespace internal | 96 } // namespace internal |
100 } // namespace v8 | 97 } // namespace v8 |
OLD | NEW |