xref: /third_party/node/deps/v8/src/objects/struct.h (revision 1cb0ef41)
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_STRUCT_H_
6#define V8_OBJECTS_STRUCT_H_
7
8#include "src/objects/heap-object.h"
9#include "src/objects/objects.h"
10
11// Has to be the last include (doesn't have include guards):
12#include "src/objects/object-macros.h"
13
14namespace v8 {
15namespace internal {
16
17class StructBodyDescriptor;
18
19#include "torque-generated/src/objects/struct-tq.inc"
20
21// An abstract superclass, a marker class really, for simple structure classes.
22// It doesn't carry any functionality but allows struct classes to be
23// identified in the type system.
24class Struct : public TorqueGeneratedStruct<Struct, HeapObject> {
25 public:
26  void BriefPrintDetails(std::ostream& os);
27  STATIC_ASSERT(kHeaderSize == HeapObject::kHeaderSize);
28
29  TQ_OBJECT_CONSTRUCTORS(Struct)
30};
31
32class Tuple2 : public TorqueGeneratedTuple2<Tuple2, Struct> {
33 public:
34  void BriefPrintDetails(std::ostream& os);
35
36  using BodyDescriptor = StructBodyDescriptor;
37
38  TQ_OBJECT_CONSTRUCTORS(Tuple2)
39};
40
41// Support for JavaScript accessors: A pair of a getter and a setter. Each
42// accessor can either be
43//   * a JavaScript function or proxy: a real accessor
44//   * a FunctionTemplateInfo: a real (lazy) accessor
45//   * undefined: considered an accessor by the spec, too, strangely enough
46//   * null: an accessor which has not been set
47class AccessorPair : public TorqueGeneratedAccessorPair<AccessorPair, Struct> {
48 public:
49  NEVER_READ_ONLY_SPACE
50  static Handle<AccessorPair> Copy(Isolate* isolate, Handle<AccessorPair> pair);
51
52  inline Object get(AccessorComponent component);
53  inline void set(AccessorComponent component, Object value);
54  inline void set(AccessorComponent component, Object value,
55                  ReleaseStoreTag tag);
56
57  using TorqueGeneratedAccessorPair::getter;
58  using TorqueGeneratedAccessorPair::set_getter;
59  DECL_RELEASE_ACQUIRE_ACCESSORS(getter, Object)
60
61  using TorqueGeneratedAccessorPair::set_setter;
62  using TorqueGeneratedAccessorPair::setter;
63  DECL_RELEASE_ACQUIRE_ACCESSORS(setter, Object)
64
65  // Note: Returns undefined if the component is not set.
66  static Handle<Object> GetComponent(Isolate* isolate,
67                                     Handle<NativeContext> native_context,
68                                     Handle<AccessorPair> accessor_pair,
69                                     AccessorComponent component);
70
71  // Set both components, skipping arguments which are a JavaScript null.
72  inline void SetComponents(Object getter, Object setter);
73
74  inline bool Equals(Object getter_value, Object setter_value);
75
76  using BodyDescriptor = StructBodyDescriptor;
77
78  TQ_OBJECT_CONSTRUCTORS(AccessorPair)
79};
80
81class ClassPositions
82    : public TorqueGeneratedClassPositions<ClassPositions, Struct> {
83 public:
84  // Dispatched behavior.
85  void BriefPrintDetails(std::ostream& os);
86
87  using BodyDescriptor = StructBodyDescriptor;
88
89  TQ_OBJECT_CONSTRUCTORS(ClassPositions)
90};
91
92}  // namespace internal
93}  // namespace v8
94
95#include "src/objects/object-macros-undef.h"
96
97#endif  // V8_OBJECTS_STRUCT_H_
98