literal-objects.h 5.33 KB
Newer Older
1 2 3 4 5 6 7
// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef V8_OBJECTS_LITERAL_OBJECTS_H_
#define V8_OBJECTS_LITERAL_OBJECTS_H_

8
#include "src/base/bit-field.h"
9
#include "src/objects/fixed-array.h"
10
#include "src/objects/struct.h"
11 12 13 14 15 16 17

// Has to be the last include (doesn't have include guards):
#include "src/objects/object-macros.h"

namespace v8 {
namespace internal {

18
class ClassLiteral;
19
class StructBodyDescriptor;
20

21 22
#include "torque-generated/src/objects/literal-objects-tq.inc"

23
// ObjectBoilerplateDescription is a list of properties consisting of name value
24 25 26 27
// pairs. In addition to the properties, it provides the projected number
// of properties in the backing store. This number includes properties with
// computed names that are not
// in the list.
28
// TODO(ishell): Don't derive from FixedArray as it already has its own map.
29
class ObjectBoilerplateDescription : public FixedArray {
30
 public:
31
  inline Object name(int index) const;
32
  inline Object name(PtrComprCageBase cage_base, int index) const;
33

34
  inline Object value(int index) const;
35
  inline Object value(PtrComprCageBase cage_base, int index) const;
36 37

  inline void set_key_value(int index, Object key, Object value);
38

39
  // The number of boilerplate properties.
40
  inline int size() const;
41 42

  // Number of boilerplate properties and properties with computed names.
43 44
  inline int backing_store_size() const;
  inline void set_backing_store_size(int backing_store_size);
45

46 47 48 49 50 51
  // Used to encode ObjectLiteral::Flags for nested object literals
  // Stored as the first element of the fixed array
  DECL_INT_ACCESSORS(flags)
  static const int kLiteralTypeOffset = 0;
  static const int kDescriptionStartIndex = 1;

52
  DECL_CAST(ObjectBoilerplateDescription)
53 54
  DECL_VERIFIER(ObjectBoilerplateDescription)
  DECL_PRINTER(ObjectBoilerplateDescription)
55 56

 private:
57
  inline bool has_number_of_properties() const;
58

59
  OBJECT_CONSTRUCTORS(ObjectBoilerplateDescription, FixedArray);
60 61
};

62 63 64
class ArrayBoilerplateDescription
    : public TorqueGeneratedArrayBoilerplateDescription<
          ArrayBoilerplateDescription, Struct> {
65
 public:
66 67
  inline ElementsKind elements_kind() const;
  inline void set_elements_kind(ElementsKind kind);
68

69
  inline bool is_empty() const;
70

71 72 73
  // Dispatched behavior.
  DECL_PRINTER(ArrayBoilerplateDescription)
  void BriefPrintDetails(std::ostream& os);
74

75 76
  using BodyDescriptor = StructBodyDescriptor;

77
 private:
78
  TQ_OBJECT_CONSTRUCTORS(ArrayBoilerplateDescription)
79
};
80

81 82 83 84 85 86 87
class RegExpBoilerplateDescription
    : public TorqueGeneratedRegExpBoilerplateDescription<
          RegExpBoilerplateDescription, Struct> {
 public:
  // Dispatched behavior.
  void BriefPrintDetails(std::ostream& os);

88 89
  using BodyDescriptor = StructBodyDescriptor;

90 91 92 93
 private:
  TQ_OBJECT_CONSTRUCTORS(RegExpBoilerplateDescription)
};

94
class ClassBoilerplate : public FixedArray {
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
 public:
  enum ValueKind { kData, kGetter, kSetter };

  struct ComputedEntryFlags {
#define COMPUTED_ENTRY_BIT_FIELDS(V, _) \
  V(ValueKindBits, ValueKind, 2, _)     \
  V(KeyIndexBits, unsigned, 29, _)
    DEFINE_BIT_FIELDS(COMPUTED_ENTRY_BIT_FIELDS)
#undef COMPUTED_ENTRY_BIT_FIELDS
  };

  enum DefineClassArgumentsIndices {
    kConstructorArgumentIndex = 1,
    kPrototypeArgumentIndex = 2,
    // The index of a first dynamic argument passed to Runtime::kDefineClass
    // function. The dynamic arguments are consist of method closures and
    // computed property names.
    kFirstDynamicArgumentIndex = 3,
  };

  static const int kMinimumClassPropertiesCount = 6;
  static const int kMinimumPrototypePropertiesCount = 1;

118
  DECL_CAST(ClassBoilerplate)
119 120 121 122 123

  DECL_BOOLEAN_ACCESSORS(install_class_name_accessor)
  DECL_INT_ACCESSORS(arguments_count)
  DECL_ACCESSORS(static_properties_template, Object)
  DECL_ACCESSORS(static_elements_template, Object)
124
  DECL_ACCESSORS(static_computed_properties, FixedArray)
125 126
  DECL_ACCESSORS(instance_properties_template, Object)
  DECL_ACCESSORS(instance_elements_template, Object)
127
  DECL_ACCESSORS(instance_computed_properties, FixedArray)
128

129 130
  template <typename IsolateT, typename Dictionary>
  static void AddToPropertiesTemplate(IsolateT* isolate,
131
                                      Handle<Dictionary> dictionary,
132
                                      Handle<Name> name, int key_index,
133
                                      ValueKind value_kind, Smi value);
134

135 136
  template <typename IsolateT>
  static void AddToElementsTemplate(IsolateT* isolate,
137 138
                                    Handle<NumberDictionary> dictionary,
                                    uint32_t key, int key_index,
139
                                    ValueKind value_kind, Smi value);
140

141 142
  template <typename IsolateT>
  static Handle<ClassBoilerplate> BuildClassBoilerplate(IsolateT* isolate,
143 144 145
                                                        ClassLiteral* expr);

  enum {
146
    kArgumentsCountIndex,
147 148 149 150 151 152
    kClassPropertiesTemplateIndex,
    kClassElementsTemplateIndex,
    kClassComputedPropertiesIndex,
    kPrototypePropertiesTemplateIndex,
    kPrototypeElementsTemplateIndex,
    kPrototypeComputedPropertiesIndex,
153
    kBoilerplateLength  // last element
154 155 156 157
  };

 private:
  DECL_INT_ACCESSORS(flags)
158

159
  OBJECT_CONSTRUCTORS(ClassBoilerplate, FixedArray);
160 161
};

162 163 164 165 166 167
}  // namespace internal
}  // namespace v8

#include "src/objects/object-macros-undef.h"

#endif  // V8_OBJECTS_LITERAL_OBJECTS_H_