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() == 3); |
17 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, target, 0); | 17 CONVERT_ARG_HANDLE_CHECKED(JSProxy, instance, 0); |
18 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, handler, 1); | 18 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, target, 1); |
19 CONVERT_ARG_HANDLE_CHECKED(Object, prototype, 2); | 19 CONVERT_ARG_HANDLE_CHECKED(Object, handler, 2); |
20 if (!prototype->IsJSReceiver()) prototype = isolate->factory()->null_value(); | 20 if (!target->IsSpecObject()) { |
21 return *isolate->factory()->NewJSProxy(target, handler, prototype); | 21 THROW_NEW_ERROR_RETURN_FAILURE( |
| 22 isolate, NewTypeError(MessageTemplate::kProxyTargetNonObject)); |
| 23 } |
| 24 if (target->IsJSProxy() && !JSProxy::cast(*target)->has_handler()) { |
| 25 // TODO(cbruni): Use better error message. |
| 26 THROW_NEW_ERROR_RETURN_FAILURE( |
| 27 isolate, NewTypeError(MessageTemplate::kProxyTargetNonObject)); |
| 28 } |
| 29 if (!handler->IsSpecObject()) { |
| 30 THROW_NEW_ERROR_RETURN_FAILURE( |
| 31 isolate, NewTypeError(MessageTemplate::kProxyHandlerNonObject)); |
| 32 } |
| 33 if (handler->IsJSProxy() && !JSProxy::cast(*handler)->has_handler()) { |
| 34 // TODO(cbruni): Use better error message. |
| 35 THROW_NEW_ERROR_RETURN_FAILURE( |
| 36 isolate, NewTypeError(MessageTemplate::kProxyHandlerNonObject)); |
| 37 } |
| 38 instance->set_target(*target); |
| 39 instance->set_handler(*handler); |
| 40 instance->set_hash(isolate->heap()->undefined_value(), SKIP_WRITE_BARRIER); |
| 41 return *instance; |
22 } | 42 } |
23 | 43 |
24 | 44 |
25 RUNTIME_FUNCTION(Runtime_CreateJSFunctionProxy) { | 45 RUNTIME_FUNCTION(Runtime_CreateJSFunctionProxy) { |
26 HandleScope scope(isolate); | 46 HandleScope scope(isolate); |
27 DCHECK(args.length() == 5); | 47 DCHECK(args.length() == 5); |
28 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, target, 0); | 48 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, target, 0); |
29 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, handler, 1); | 49 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, handler, 1); |
30 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, call_trap, 2); | 50 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, call_trap, 2); |
31 RUNTIME_ASSERT(call_trap->IsJSFunction() || call_trap->IsJSFunctionProxy()); | 51 RUNTIME_ASSERT(call_trap->IsJSFunction() || call_trap->IsJSFunctionProxy()); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 | 91 |
72 RUNTIME_FUNCTION(Runtime_GetConstructTrap) { | 92 RUNTIME_FUNCTION(Runtime_GetConstructTrap) { |
73 SealHandleScope shs(isolate); | 93 SealHandleScope shs(isolate); |
74 DCHECK(args.length() == 1); | 94 DCHECK(args.length() == 1); |
75 CONVERT_ARG_CHECKED(JSFunctionProxy, proxy, 0); | 95 CONVERT_ARG_CHECKED(JSFunctionProxy, proxy, 0); |
76 return proxy->construct_trap(); | 96 return proxy->construct_trap(); |
77 } | 97 } |
78 | 98 |
79 } // namespace internal | 99 } // namespace internal |
80 } // namespace v8 | 100 } // namespace v8 |
OLD | NEW |