1 // Copyright 2017 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_DATA_HANDLER_H_
6 #define V8_OBJECTS_DATA_HANDLER_H_
7 
8 #include "src/objects.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 // DataHandler is a base class for load and store handlers that can't be
17 // encoded in one Smi. Kind of a handler can be deduced from instance type.
18 class DataHandler : public Struct {
19  public:
20   // [smi_handler]: A Smi which encodes a handler or Code object (we still
21   // use code handlers for accessing lexical environment variables, but soon
22   // only smi handlers will remain). See LoadHandler and StoreHandler for
23   // details about encoding.
24   DECL_ACCESSORS(smi_handler, Object)
25 
26   // [validity_cell]: A validity Cell that guards prototype chain modifications.
27   DECL_ACCESSORS(validity_cell, Object)
28 
29   // Returns number of optional data fields available in the object.
30   inline int data_field_count() const;
31 
32   // [data1-3]: These are optional general-purpose fields whose content and
33   // presence depends on the handler kind.
34   DECL_ACCESSORS(data1, Object)
35   DECL_ACCESSORS(data2, Object)
36   DECL_ACCESSORS(data3, Object)
37 
38 // Layout description.
39 #define DATA_HANDLER_FIELDS(V)         \
40   V(kSmiHandlerOffset, kPointerSize)   \
41   V(kValidityCellOffset, kPointerSize) \
42   V(kSizeWithData0, 0)                 \
43   V(kData1Offset, kPointerSize)        \
44   V(kSizeWithData1, 0)                 \
45   V(kData2Offset, kPointerSize)        \
46   V(kSizeWithData2, 0)                 \
47   V(kData3Offset, kPointerSize)        \
48   V(kSizeWithData3, 0)
49 
50   DEFINE_FIELD_OFFSET_CONSTANTS(HeapObject::kHeaderSize, DATA_HANDLER_FIELDS)
51 #undef DATA_HANDLER_FIELDS
52 
53   DECL_CAST(DataHandler)
54 
55   DECL_VERIFIER(DataHandler)
56 };
57 
58 }  // namespace internal
59 }  // namespace v8
60 
61 #include "src/objects/object-macros-undef.h"
62 
63 #endif  // V8_OBJECTS_DATA_HANDLER_H_
64