V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
api-callbacks-inl.h
1 // Copyright 2018 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 #ifndef V8_OBJECTS_API_CALLBACKS_INL_H_
6 #define V8_OBJECTS_API_CALLBACKS_INL_H_
7 
8 #include "src/objects/api-callbacks.h"
9 
10 #include "src/heap/heap-inl.h"
11 #include "src/heap/heap-write-barrier.h"
12 #include "src/objects/name.h"
13 #include "src/objects/templates.h"
14 
15 // Has to be the last include (doesn't have include guards):
16 #include "src/objects/object-macros.h"
17 
18 namespace v8 {
19 namespace internal {
20 
21 CAST_ACCESSOR(AccessorInfo)
22 CAST_ACCESSOR(AccessCheckInfo)
23 CAST_ACCESSOR(InterceptorInfo)
24 CAST_ACCESSOR(CallHandlerInfo)
25 
26 ACCESSORS2(AccessorInfo, name, Name, kNameOffset)
27 SMI_ACCESSORS(AccessorInfo, flags, kFlagsOffset)
28 ACCESSORS(AccessorInfo, expected_receiver_type, Object,
29  kExpectedReceiverTypeOffset)
30 
31 ACCESSORS_CHECKED2(AccessorInfo, getter, Object, kGetterOffset, true,
32  Foreign::IsNormalized(value))
33 ACCESSORS_CHECKED2(AccessorInfo, setter, Object, kSetterOffset, true,
34  Foreign::IsNormalized(value));
35 ACCESSORS(AccessorInfo, js_getter, Object, kJsGetterOffset)
36 ACCESSORS(AccessorInfo, data, Object, kDataOffset)
37 
38 bool AccessorInfo::has_getter() {
39  bool result = getter() != Smi::kZero;
40  DCHECK_EQ(result,
41  getter() != Smi::kZero &&
42  Foreign::cast(getter())->foreign_address() != kNullAddress);
43  return result;
44 }
45 
46 bool AccessorInfo::has_setter() {
47  bool result = setter() != Smi::kZero;
48  DCHECK_EQ(result,
49  setter() != Smi::kZero &&
50  Foreign::cast(setter())->foreign_address() != kNullAddress);
51  return result;
52 }
53 
54 BIT_FIELD_ACCESSORS(AccessorInfo, flags, all_can_read,
55  AccessorInfo::AllCanReadBit)
56 BIT_FIELD_ACCESSORS(AccessorInfo, flags, all_can_write,
57  AccessorInfo::AllCanWriteBit)
58 BIT_FIELD_ACCESSORS(AccessorInfo, flags, is_special_data_property,
59  AccessorInfo::IsSpecialDataPropertyBit)
60 BIT_FIELD_ACCESSORS(AccessorInfo, flags, replace_on_access,
61  AccessorInfo::ReplaceOnAccessBit)
62 BIT_FIELD_ACCESSORS(AccessorInfo, flags, is_sloppy, AccessorInfo::IsSloppyBit)
63 BIT_FIELD_ACCESSORS(AccessorInfo, flags, getter_side_effect_type,
64  AccessorInfo::GetterSideEffectTypeBits)
65 
66 SideEffectType AccessorInfo::setter_side_effect_type() const {
67  return SetterSideEffectTypeBits::decode(flags());
68 }
69 
70 void AccessorInfo::set_setter_side_effect_type(SideEffectType value) {
71  // We do not support describing setters as having no side effect, since
72  // calling set accessors must go through a store bytecode. Store bytecodes
73  // support checking receivers for temporary objects, but still expect
74  // the receiver to be written to.
75  CHECK_NE(value, SideEffectType::kHasNoSideEffect);
76  set_flags(SetterSideEffectTypeBits::update(flags(), value));
77 }
78 
79 BIT_FIELD_ACCESSORS(AccessorInfo, flags, initial_property_attributes,
80  AccessorInfo::InitialAttributesBits)
81 
82 bool AccessorInfo::IsCompatibleReceiver(Object* receiver) {
83  if (!HasExpectedReceiverType()) return true;
84  if (!receiver->IsJSObject()) return false;
85  return FunctionTemplateInfo::cast(expected_receiver_type())
86  ->IsTemplateFor(JSObject::cast(receiver)->map());
87 }
88 
89 bool AccessorInfo::HasExpectedReceiverType() {
90  return expected_receiver_type()->IsFunctionTemplateInfo();
91 }
92 
93 ACCESSORS(AccessCheckInfo, callback, Object, kCallbackOffset)
94 ACCESSORS(AccessCheckInfo, named_interceptor, Object, kNamedInterceptorOffset)
95 ACCESSORS(AccessCheckInfo, indexed_interceptor, Object,
96  kIndexedInterceptorOffset)
97 ACCESSORS(AccessCheckInfo, data, Object, kDataOffset)
98 
99 ACCESSORS(InterceptorInfo, getter, Object, kGetterOffset)
100 ACCESSORS(InterceptorInfo, setter, Object, kSetterOffset)
101 ACCESSORS(InterceptorInfo, query, Object, kQueryOffset)
102 ACCESSORS(InterceptorInfo, descriptor, Object, kDescriptorOffset)
103 ACCESSORS(InterceptorInfo, deleter, Object, kDeleterOffset)
104 ACCESSORS(InterceptorInfo, enumerator, Object, kEnumeratorOffset)
105 ACCESSORS(InterceptorInfo, definer, Object, kDefinerOffset)
106 ACCESSORS(InterceptorInfo, data, Object, kDataOffset)
107 SMI_ACCESSORS(InterceptorInfo, flags, kFlagsOffset)
108 BOOL_ACCESSORS(InterceptorInfo, flags, can_intercept_symbols,
109  kCanInterceptSymbolsBit)
110 BOOL_ACCESSORS(InterceptorInfo, flags, all_can_read, kAllCanReadBit)
111 BOOL_ACCESSORS(InterceptorInfo, flags, non_masking, kNonMasking)
112 BOOL_ACCESSORS(InterceptorInfo, flags, is_named, kNamed)
113 BOOL_ACCESSORS(InterceptorInfo, flags, has_no_side_effect, kHasNoSideEffect)
114 
115 ACCESSORS(CallHandlerInfo, callback, Object, kCallbackOffset)
116 ACCESSORS(CallHandlerInfo, js_callback, Object, kJsCallbackOffset)
117 ACCESSORS(CallHandlerInfo, data, Object, kDataOffset)
118 
119 bool CallHandlerInfo::IsSideEffectFreeCallHandlerInfo() const {
120  ReadOnlyRoots roots = GetReadOnlyRoots();
121  DCHECK(map() == roots.side_effect_call_handler_info_map() ||
122  map() == roots.side_effect_free_call_handler_info_map() ||
123  map() == roots.next_call_side_effect_free_call_handler_info_map());
124  return map() == roots.side_effect_free_call_handler_info_map();
125 }
126 
127 bool CallHandlerInfo::IsSideEffectCallHandlerInfo() const {
128  ReadOnlyRoots roots = GetReadOnlyRoots();
129  DCHECK(map() == roots.side_effect_call_handler_info_map() ||
130  map() == roots.side_effect_free_call_handler_info_map() ||
131  map() == roots.next_call_side_effect_free_call_handler_info_map());
132  return map() == roots.side_effect_call_handler_info_map();
133 }
134 
135 void CallHandlerInfo::SetNextCallHasNoSideEffect() {
136  set_map(
137  GetReadOnlyRoots().next_call_side_effect_free_call_handler_info_map());
138 }
139 
140 bool CallHandlerInfo::NextCallHasNoSideEffect() {
141  ReadOnlyRoots roots = GetReadOnlyRoots();
142  if (map() == roots.next_call_side_effect_free_call_handler_info_map()) {
143  set_map(roots.side_effect_call_handler_info_map());
144  return true;
145  }
146  return false;
147 }
148 
149 } // namespace internal
150 } // namespace v8
151 
152 #include "src/objects/object-macros-undef.h"
153 
154 #endif // V8_OBJECTS_API_CALLBACKS_INL_H_
Definition: libplatform.h:13
SideEffectType
Definition: v8.h:3204