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