blob: baf7cdb49db8527afc1beef65d612ee5c85ea9c7 [file] [log] [blame]
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001// 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
3// found in the LICENSE file.
4
5#include "src/v8.h"
6
7#include "src/arguments.h"
8#include "src/runtime/runtime-utils.h"
9
10namespace v8 {
11namespace internal {
12
13RUNTIME_FUNCTION(Runtime_CreateJSProxy) {
14 HandleScope scope(isolate);
15 DCHECK(args.length() == 2);
16 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, handler, 0);
17 CONVERT_ARG_HANDLE_CHECKED(Object, prototype, 1);
18 if (!prototype->IsJSReceiver()) prototype = isolate->factory()->null_value();
19 return *isolate->factory()->NewJSProxy(handler, prototype);
20}
21
22
23RUNTIME_FUNCTION(Runtime_CreateJSFunctionProxy) {
24 HandleScope scope(isolate);
25 DCHECK(args.length() == 4);
26 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, handler, 0);
27 CONVERT_ARG_HANDLE_CHECKED(Object, call_trap, 1);
28 RUNTIME_ASSERT(call_trap->IsJSFunction() || call_trap->IsJSFunctionProxy());
29 CONVERT_ARG_HANDLE_CHECKED(JSFunction, construct_trap, 2);
30 CONVERT_ARG_HANDLE_CHECKED(Object, prototype, 3);
31 if (!prototype->IsJSReceiver()) prototype = isolate->factory()->null_value();
32 return *isolate->factory()->NewJSFunctionProxy(handler, call_trap,
33 construct_trap, prototype);
34}
35
36
37RUNTIME_FUNCTION(RuntimeReference_IsJSProxy) {
38 SealHandleScope shs(isolate);
39 DCHECK(args.length() == 1);
40 CONVERT_ARG_CHECKED(Object, obj, 0);
41 return isolate->heap()->ToBoolean(obj->IsJSProxy());
42}
43
44
45RUNTIME_FUNCTION(Runtime_IsJSFunctionProxy) {
46 SealHandleScope shs(isolate);
47 DCHECK(args.length() == 1);
48 CONVERT_ARG_HANDLE_CHECKED(Object, obj, 0);
49 return isolate->heap()->ToBoolean(obj->IsJSFunctionProxy());
50}
51
52
53RUNTIME_FUNCTION(Runtime_GetHandler) {
54 SealHandleScope shs(isolate);
55 DCHECK(args.length() == 1);
56 CONVERT_ARG_CHECKED(JSProxy, proxy, 0);
57 return proxy->handler();
58}
59
60
61RUNTIME_FUNCTION(Runtime_GetCallTrap) {
62 SealHandleScope shs(isolate);
63 DCHECK(args.length() == 1);
64 CONVERT_ARG_CHECKED(JSFunctionProxy, proxy, 0);
65 return proxy->call_trap();
66}
67
68
69RUNTIME_FUNCTION(Runtime_GetConstructTrap) {
70 SealHandleScope shs(isolate);
71 DCHECK(args.length() == 1);
72 CONVERT_ARG_CHECKED(JSFunctionProxy, proxy, 0);
73 return proxy->construct_trap();
74}
75
76
77RUNTIME_FUNCTION(Runtime_Fix) {
78 HandleScope scope(isolate);
79 DCHECK(args.length() == 1);
80 CONVERT_ARG_HANDLE_CHECKED(JSProxy, proxy, 0);
81 JSProxy::Fix(proxy);
82 return isolate->heap()->undefined_value();
83}
84}
85} // namespace v8::internal