LCOV - code coverage report
Current view: top level - src/objects - api-callbacks.h (source / functions) Hit Total Coverage
Test: app.info Lines: 3 3 100.0 %
Date: 2019-02-19 Functions: 3 3 100.0 %

          Line data    Source code
       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             : 
      10             : // Has to be the last include (doesn't have include guards):
      11             : #include "src/objects/object-macros.h"
      12             : 
      13             : namespace v8 {
      14             : namespace internal {
      15             : 
      16             : // An accessor must have a getter, but can have no setter.
      17             : //
      18             : // When setting a property, V8 searches accessors in prototypes.
      19             : // If an accessor was found and it does not have a setter,
      20             : // the request is ignored.
      21             : //
      22             : // If the accessor in the prototype has the READ_ONLY property attribute, then
      23             : // a new value is added to the derived object when the property is set.
      24             : // This shadows the accessor in the prototype.
      25             : class AccessorInfo : public Struct {
      26             :  public:
      27             :   DECL_ACCESSORS(name, Name)
      28             :   DECL_INT_ACCESSORS(flags)
      29             :   DECL_ACCESSORS(expected_receiver_type, Object)
      30             :   // This directly points at a foreign C function to be used from the runtime.
      31             :   DECL_ACCESSORS(getter, Object)
      32             :   inline bool has_getter();
      33             :   DECL_ACCESSORS(setter, Object)
      34             :   inline bool has_setter();
      35             :   // This either points at the same as above, or a trampoline in case we are
      36             :   // running with the simulator. Use these entries from generated code.
      37             :   DECL_ACCESSORS(js_getter, Object)
      38             :   DECL_ACCESSORS(data, Object)
      39             : 
      40             :   static Address redirect(Address address, AccessorComponent component);
      41             :   Address redirected_getter() const;
      42             : 
      43             :   // Dispatched behavior.
      44             :   DECL_PRINTER(AccessorInfo)
      45             : 
      46             :   DECL_BOOLEAN_ACCESSORS(all_can_read)
      47             :   DECL_BOOLEAN_ACCESSORS(all_can_write)
      48             :   DECL_BOOLEAN_ACCESSORS(is_special_data_property)
      49             :   DECL_BOOLEAN_ACCESSORS(replace_on_access)
      50             :   DECL_BOOLEAN_ACCESSORS(is_sloppy)
      51             : 
      52             :   inline SideEffectType getter_side_effect_type() const;
      53             :   inline void set_getter_side_effect_type(SideEffectType type);
      54             : 
      55             :   inline SideEffectType setter_side_effect_type() const;
      56             :   inline void set_setter_side_effect_type(SideEffectType type);
      57             : 
      58             :   // The property attributes used when an API object template is instantiated
      59             :   // for the first time. Changing of this value afterwards does not affect
      60             :   // the actual attributes of a property.
      61             :   inline PropertyAttributes initial_property_attributes() const;
      62             :   inline void set_initial_property_attributes(PropertyAttributes attributes);
      63             : 
      64             :   // Checks whether the given receiver is compatible with this accessor.
      65             :   static bool IsCompatibleReceiverMap(Handle<AccessorInfo> info,
      66             :                                       Handle<Map> map);
      67             :   inline bool IsCompatibleReceiver(Object receiver);
      68             : 
      69             :   DECL_CAST(AccessorInfo)
      70             : 
      71             :   // Dispatched behavior.
      72             :   DECL_VERIFIER(AccessorInfo)
      73             : 
      74             :   // Append all descriptors to the array that are not already there.
      75             :   // Return number added.
      76             :   static int AppendUnique(Isolate* isolate, Handle<Object> descriptors,
      77             :                           Handle<FixedArray> array, int valid_descriptors);
      78             : 
      79             : // Layout description.
      80             : #define ACCESSOR_INFO_FIELDS(V)               \
      81             :   V(kNameOffset, kTaggedSize)                 \
      82             :   V(kFlagsOffset, kTaggedSize)                \
      83             :   V(kExpectedReceiverTypeOffset, kTaggedSize) \
      84             :   V(kSetterOffset, kTaggedSize)               \
      85             :   V(kGetterOffset, kTaggedSize)               \
      86             :   V(kJsGetterOffset, kTaggedSize)             \
      87             :   V(kDataOffset, kTaggedSize)                 \
      88             :   V(kSize, 0)
      89             : 
      90             :   DEFINE_FIELD_OFFSET_CONSTANTS(HeapObject::kHeaderSize, ACCESSOR_INFO_FIELDS)
      91             : #undef ACCESSOR_INFO_FIELDS
      92             : 
      93             :  private:
      94             :   inline bool HasExpectedReceiverType();
      95             : 
      96             : // Bit positions in |flags|.
      97             : #define ACCESSOR_INFO_FLAGS_BIT_FIELDS(V, _)                           \
      98             :   V(AllCanReadBit, bool, 1, _)                                         \
      99             :   V(AllCanWriteBit, bool, 1, _)                                        \
     100             :   V(IsSpecialDataPropertyBit, bool, 1, _)                              \
     101             :   V(IsSloppyBit, bool, 1, _)                                           \
     102             :   V(ReplaceOnAccessBit, bool, 1, _)                                    \
     103             :   V(GetterSideEffectTypeBits, SideEffectType, 2, _)                    \
     104             :   /* We could save a bit from setter side-effect type, if necessary */ \
     105             :   V(SetterSideEffectTypeBits, SideEffectType, 2, _)                    \
     106             :   V(InitialAttributesBits, PropertyAttributes, 3, _)
     107             : 
     108             :   DEFINE_BIT_FIELDS(ACCESSOR_INFO_FLAGS_BIT_FIELDS)
     109             : #undef ACCESSOR_INFO_FLAGS_BIT_FIELDS
     110             : 
     111      493234 :   OBJECT_CONSTRUCTORS(AccessorInfo, Struct);
     112             : };
     113             : 
     114             : class AccessCheckInfo : public Struct {
     115             :  public:
     116             :   DECL_ACCESSORS(callback, Object)
     117             :   DECL_ACCESSORS(named_interceptor, Object)
     118             :   DECL_ACCESSORS(indexed_interceptor, Object)
     119             :   DECL_ACCESSORS(data, Object)
     120             : 
     121             :   DECL_CAST(AccessCheckInfo)
     122             : 
     123             :   // Dispatched behavior.
     124             :   DECL_PRINTER(AccessCheckInfo)
     125             :   DECL_VERIFIER(AccessCheckInfo)
     126             : 
     127             :   static AccessCheckInfo Get(Isolate* isolate, Handle<JSObject> receiver);
     128             : 
     129             : // Layout description.
     130             : #define ACCESS_CHECK_INFO_FIELDS(V)         \
     131             :   V(kCallbackOffset, kTaggedSize)           \
     132             :   V(kNamedInterceptorOffset, kTaggedSize)   \
     133             :   V(kIndexedInterceptorOffset, kTaggedSize) \
     134             :   V(kDataOffset, kTaggedSize)               \
     135             :   V(kSize, 0)
     136             : 
     137             :   DEFINE_FIELD_OFFSET_CONSTANTS(HeapObject::kHeaderSize,
     138             :                                 ACCESS_CHECK_INFO_FIELDS)
     139             : #undef ACCESS_CHECK_INFO_FIELDS
     140             : 
     141             :   OBJECT_CONSTRUCTORS(AccessCheckInfo, Struct);
     142             : };
     143             : 
     144             : class InterceptorInfo : public Struct {
     145             :  public:
     146             :   DECL_ACCESSORS(getter, Object)
     147             :   DECL_ACCESSORS(setter, Object)
     148             :   DECL_ACCESSORS(query, Object)
     149             :   DECL_ACCESSORS(descriptor, Object)
     150             :   DECL_ACCESSORS(deleter, Object)
     151             :   DECL_ACCESSORS(enumerator, Object)
     152             :   DECL_ACCESSORS(definer, Object)
     153             :   DECL_ACCESSORS(data, Object)
     154             :   DECL_BOOLEAN_ACCESSORS(can_intercept_symbols)
     155             :   DECL_BOOLEAN_ACCESSORS(all_can_read)
     156             :   DECL_BOOLEAN_ACCESSORS(non_masking)
     157             :   DECL_BOOLEAN_ACCESSORS(is_named)
     158             :   DECL_BOOLEAN_ACCESSORS(has_no_side_effect)
     159             : 
     160             :   inline int flags() const;
     161             :   inline void set_flags(int flags);
     162             : 
     163             :   DECL_CAST(InterceptorInfo)
     164             : 
     165             :   // Dispatched behavior.
     166             :   DECL_PRINTER(InterceptorInfo)
     167             :   DECL_VERIFIER(InterceptorInfo)
     168             : 
     169             : // Layout description.
     170             : #define INTERCEPTOR_INFO_FIELDS(V)  \
     171             :   V(kGetterOffset, kTaggedSize)     \
     172             :   V(kSetterOffset, kTaggedSize)     \
     173             :   V(kQueryOffset, kTaggedSize)      \
     174             :   V(kDescriptorOffset, kTaggedSize) \
     175             :   V(kDeleterOffset, kTaggedSize)    \
     176             :   V(kEnumeratorOffset, kTaggedSize) \
     177             :   V(kDefinerOffset, kTaggedSize)    \
     178             :   V(kDataOffset, kTaggedSize)       \
     179             :   V(kFlagsOffset, kTaggedSize)      \
     180             :   V(kSize, 0)
     181             : 
     182             :   DEFINE_FIELD_OFFSET_CONSTANTS(HeapObject::kHeaderSize,
     183             :                                 INTERCEPTOR_INFO_FIELDS)
     184             : #undef INTERCEPTOR_INFO_FIELDS
     185             : 
     186             :   static const int kCanInterceptSymbolsBit = 0;
     187             :   static const int kAllCanReadBit = 1;
     188             :   static const int kNonMasking = 2;
     189             :   static const int kNamed = 3;
     190             :   static const int kHasNoSideEffect = 4;
     191             : 
     192      679067 :   OBJECT_CONSTRUCTORS(InterceptorInfo, Struct);
     193             : };
     194             : 
     195             : class CallHandlerInfo : public Tuple3 {
     196             :  public:
     197             :   DECL_ACCESSORS(callback, Object)
     198             :   DECL_ACCESSORS(js_callback, Object)
     199             :   DECL_ACCESSORS(data, Object)
     200             : 
     201             :   DECL_CAST(CallHandlerInfo)
     202             : 
     203             :   inline bool IsSideEffectFreeCallHandlerInfo() const;
     204             :   inline bool IsSideEffectCallHandlerInfo() const;
     205             :   inline void SetNextCallHasNoSideEffect();
     206             :   // Returns whether or not the next call can be side effect free.
     207             :   // Calling this will change the state back to having a side effect.
     208             :   inline bool NextCallHasNoSideEffect();
     209             : 
     210             :   // Dispatched behavior.
     211             :   DECL_PRINTER(CallHandlerInfo)
     212             :   DECL_VERIFIER(CallHandlerInfo)
     213             : 
     214             :   Address redirected_callback() const;
     215             : 
     216             :   static const int kCallbackOffset = kValue1Offset;
     217             :   static const int kJsCallbackOffset = kValue2Offset;
     218             :   static const int kDataOffset = kValue3Offset;
     219             : 
     220        4005 :   OBJECT_CONSTRUCTORS(CallHandlerInfo, Tuple3);
     221             : };
     222             : 
     223             : }  // namespace internal
     224             : }  // namespace v8
     225             : 
     226             : #include "src/objects/object-macros-undef.h"
     227             : 
     228             : #endif  // V8_OBJECTS_API_CALLBACKS_H_

Generated by: LCOV version 1.10