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_H_ 6 #define V8_OBJECTS_API_CALLBACKS_H_ 7 8 #include "src/objects/struct.h" 9 #include "torque-generated/bit-fields.h" 10 11 // Has to be the last include (doesn't have include guards): 12 #include "src/objects/object-macros.h" 13 14 namespace v8 { 15 namespace internal { 16 17 class StructBodyDescriptor; 18 19 #include "torque-generated/src/objects/api-callbacks-tq.inc" 20 21 // An accessor must have a getter, but can have no setter. 22 // 23 // When setting a property, V8 searches accessors in prototypes. 24 // If an accessor was found and it does not have a setter, 25 // the request is ignored. 26 // 27 // If the accessor in the prototype has the READ_ONLY property attribute, then 28 // a new value is added to the derived object when the property is set. 29 // This shadows the accessor in the prototype. 30 class AccessorInfo : public TorqueGeneratedAccessorInfo<AccessorInfo, Struct> { 31 public: 32 // This directly points at a foreign C function to be used from the runtime. 33 DECL_ACCESSORS(getter, Object) 34 inline bool has_getter(); 35 DECL_ACCESSORS(setter, Object) 36 inline bool has_setter(); 37 38 static Address redirect(Address address, AccessorComponent component); 39 Address redirected_getter() const; 40 41 DECL_BOOLEAN_ACCESSORS(all_can_read) 42 DECL_BOOLEAN_ACCESSORS(all_can_write) 43 DECL_BOOLEAN_ACCESSORS(is_special_data_property) 44 DECL_BOOLEAN_ACCESSORS(replace_on_access) 45 DECL_BOOLEAN_ACCESSORS(is_sloppy) 46 47 inline SideEffectType getter_side_effect_type() const; 48 inline void set_getter_side_effect_type(SideEffectType type); 49 50 inline SideEffectType setter_side_effect_type() const; 51 inline void set_setter_side_effect_type(SideEffectType type); 52 53 // The property attributes used when an API object template is instantiated 54 // for the first time. Changing of this value afterwards does not affect 55 // the actual attributes of a property. 56 inline PropertyAttributes initial_property_attributes() const; 57 inline void set_initial_property_attributes(PropertyAttributes attributes); 58 59 // Checks whether the given receiver is compatible with this accessor. 60 static bool IsCompatibleReceiverMap(Handle<AccessorInfo> info, 61 Handle<Map> map); 62 inline bool IsCompatibleReceiver(Object receiver); 63 64 // Append all descriptors to the array that are not already there. 65 // Return number added. 66 static int AppendUnique(Isolate* isolate, Handle<Object> descriptors, 67 Handle<FixedArray> array, int valid_descriptors); 68 69 DECL_PRINTER(AccessorInfo) 70 71 using BodyDescriptor = StructBodyDescriptor; 72 73 private: 74 inline bool HasExpectedReceiverType(); 75 76 // Bit positions in |flags|. 77 DEFINE_TORQUE_GENERATED_ACCESSOR_INFO_FLAGS() 78 79 TQ_OBJECT_CONSTRUCTORS(AccessorInfo) 80 }; 81 82 class AccessCheckInfo 83 : public TorqueGeneratedAccessCheckInfo<AccessCheckInfo, Struct> { 84 public: 85 static AccessCheckInfo Get(Isolate* isolate, Handle<JSObject> receiver); 86 87 using BodyDescriptor = StructBodyDescriptor; 88 89 TQ_OBJECT_CONSTRUCTORS(AccessCheckInfo) 90 }; 91 92 class InterceptorInfo 93 : public TorqueGeneratedInterceptorInfo<InterceptorInfo, Struct> { 94 public: 95 DECL_BOOLEAN_ACCESSORS(can_intercept_symbols) 96 DECL_BOOLEAN_ACCESSORS(all_can_read) 97 DECL_BOOLEAN_ACCESSORS(non_masking) 98 DECL_BOOLEAN_ACCESSORS(is_named) 99 DECL_BOOLEAN_ACCESSORS(has_no_side_effect) 100 101 DEFINE_TORQUE_GENERATED_INTERCEPTOR_INFO_FLAGS() 102 103 using BodyDescriptor = StructBodyDescriptor; 104 105 TQ_OBJECT_CONSTRUCTORS(InterceptorInfo) 106 }; 107 108 class CallHandlerInfo 109 : public TorqueGeneratedCallHandlerInfo<CallHandlerInfo, Struct> { 110 public: 111 inline bool IsSideEffectFreeCallHandlerInfo() const; 112 inline bool IsSideEffectCallHandlerInfo() const; 113 inline void SetNextCallHasNoSideEffect(); 114 // Returns whether or not the next call can be side effect free. 115 // Calling this will change the state back to having a side effect. 116 inline bool NextCallHasNoSideEffect(); 117 118 // Dispatched behavior. 119 DECL_PRINTER(CallHandlerInfo) 120 DECL_VERIFIER(CallHandlerInfo) 121 122 Address redirected_callback() const; 123 124 using BodyDescriptor = StructBodyDescriptor; 125 126 TQ_OBJECT_CONSTRUCTORS(CallHandlerInfo) 127 }; 128 129 } // namespace internal 130 } // namespace v8 131 132 #include "src/objects/object-macros-undef.h" 133 134 #endif // V8_OBJECTS_API_CALLBACKS_H_ 135