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