V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
runtime-proxy.cc
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
3 // found in the LICENSE file.
4 
5 #include "src/runtime/runtime-utils.h"
6 
7 #include "src/arguments-inl.h"
8 #include "src/counters.h"
9 #include "src/elements.h"
10 #include "src/heap/factory.h"
11 #include "src/isolate-inl.h"
12 #include "src/objects-inl.h"
13 
14 namespace v8 {
15 namespace internal {
16 
17 
18 RUNTIME_FUNCTION(Runtime_IsJSProxy) {
19  SealHandleScope shs(isolate);
20  DCHECK_EQ(1, args.length());
21  CONVERT_ARG_CHECKED(Object, obj, 0);
22  return isolate->heap()->ToBoolean(obj->IsJSProxy());
23 }
24 
25 
26 RUNTIME_FUNCTION(Runtime_JSProxyGetHandler) {
27  SealHandleScope shs(isolate);
28  DCHECK_EQ(1, args.length());
29  CONVERT_ARG_CHECKED(JSProxy, proxy, 0);
30  return proxy->handler();
31 }
32 
33 
34 RUNTIME_FUNCTION(Runtime_JSProxyGetTarget) {
35  SealHandleScope shs(isolate);
36  DCHECK_EQ(1, args.length());
37  CONVERT_ARG_CHECKED(JSProxy, proxy, 0);
38  return proxy->target();
39 }
40 
41 
42 RUNTIME_FUNCTION(Runtime_GetPropertyWithReceiver) {
43  HandleScope scope(isolate);
44 
45  DCHECK_EQ(4, args.length());
46  CONVERT_ARG_HANDLE_CHECKED(JSReceiver, holder, 0);
47  CONVERT_ARG_HANDLE_CHECKED(Object, key, 1);
48  CONVERT_ARG_HANDLE_CHECKED(Object, receiver, 2);
49  CONVERT_ARG_HANDLE_CHECKED(Smi, on_non_existent, 3);
50 
51  bool success = false;
52  LookupIterator it = LookupIterator::PropertyOrElement(isolate, receiver, key,
53  &success, holder);
54  if (!success) {
55  DCHECK(isolate->has_pending_exception());
56  return ReadOnlyRoots(isolate).exception();
57  }
58 
59  RETURN_RESULT_OR_FAILURE(
60  isolate, Object::GetProperty(
61  &it, static_cast<OnNonExistent>(on_non_existent->value())));
62 }
63 
64 RUNTIME_FUNCTION(Runtime_SetPropertyWithReceiver) {
65  HandleScope scope(isolate);
66 
67  DCHECK_EQ(5, args.length());
68  CONVERT_ARG_HANDLE_CHECKED(JSReceiver, holder, 0);
69  CONVERT_ARG_HANDLE_CHECKED(Object, key, 1);
70  CONVERT_ARG_HANDLE_CHECKED(Object, value, 2);
71  CONVERT_ARG_HANDLE_CHECKED(Object, receiver, 3);
72  CONVERT_LANGUAGE_MODE_ARG_CHECKED(language_mode, 4);
73 
74  bool success = false;
75  LookupIterator it = LookupIterator::PropertyOrElement(isolate, receiver, key,
76  &success, holder);
77  if (!success) {
78  DCHECK(isolate->has_pending_exception());
79  return ReadOnlyRoots(isolate).exception();
80  }
81  Maybe<bool> result = Object::SetSuperProperty(&it, value, language_mode,
82  StoreOrigin::kMaybeKeyed);
83  MAYBE_RETURN(result, ReadOnlyRoots(isolate).exception());
84  return *isolate->factory()->ToBoolean(result.FromJust());
85 }
86 
87 RUNTIME_FUNCTION(Runtime_CheckProxyGetSetTrapResult) {
88  HandleScope scope(isolate);
89 
90  DCHECK_EQ(4, args.length());
91  CONVERT_ARG_HANDLE_CHECKED(Name, name, 0);
92  CONVERT_ARG_HANDLE_CHECKED(JSReceiver, target, 1);
93  CONVERT_ARG_HANDLE_CHECKED(Object, trap_result, 2);
94  CONVERT_NUMBER_CHECKED(int64_t, access_kind, Int64, args[3]);
95 
96  RETURN_RESULT_OR_FAILURE(isolate, JSProxy::CheckGetSetTrapResult(
97  isolate, name, target, trap_result,
98  JSProxy::AccessKind(access_kind)));
99 }
100 
101 RUNTIME_FUNCTION(Runtime_CheckProxyHasTrap) {
102  HandleScope scope(isolate);
103 
104  DCHECK_EQ(2, args.length());
105  CONVERT_ARG_HANDLE_CHECKED(Name, name, 0);
106  CONVERT_ARG_HANDLE_CHECKED(JSReceiver, target, 1);
107 
108  Maybe<bool> result = JSProxy::CheckHasTrap(isolate, name, target);
109  if (!result.IsJust()) return ReadOnlyRoots(isolate).exception();
110  return isolate->heap()->ToBoolean(result.FromJust());
111 }
112 
113 } // namespace internal
114 } // namespace v8
Definition: libplatform.h:13