property.h 3.5 KB
Newer Older
1 2 3
// Copyright 2014 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.
4 5 6 7

#ifndef V8_PROPERTY_H_
#define V8_PROPERTY_H_

8 9
#include <iosfwd>

10 11 12 13 14
#include "src/globals.h"
#include "src/handles.h"
#include "src/objects.h"
#include "src/objects/name.h"
#include "src/property-details.h"
15

16 17
namespace v8 {
namespace internal {
18 19 20 21 22 23

// Abstraction for elements in instance-descriptor arrays.
//
// Each descriptor has a key, property attributes, property type,
// property index (in the actual instance-descriptor array) and
// optionally a piece of data.
24
class Descriptor final BASE_EMBEDDED {
25
 public:
26 27
  Descriptor() : details_(Smi::kZero) {}

28
  Handle<Name> GetKey() const { return key_; }
29
  MaybeObjectHandle GetValue() const { return value_; }
30
  PropertyDetails GetDetails() const { return details_; }
31

32
  void SetSortedKeyIndex(int index) { details_ = details_.set_pointer(index); }
33

34 35 36 37 38 39
  static Descriptor DataField(Handle<Name> key, int field_index,
                              PropertyAttributes attributes,
                              Representation representation);

  static Descriptor DataField(Handle<Name> key, int field_index,
                              PropertyAttributes attributes,
40 41
                              PropertyConstness constness,
                              Representation representation,
42
                              MaybeObjectHandle wrapped_field_type);
43 44 45

  static Descriptor DataConstant(Handle<Name> key, Handle<Object> value,
                                 PropertyAttributes attributes) {
46 47 48
    return Descriptor(key, MaybeObjectHandle(value), kData, attributes,
                      kDescriptor, PropertyConstness::kConst,
                      value->OptimalRepresentation(), 0);
49 50
  }

51 52 53 54
  static Descriptor DataConstant(Handle<Name> key, int field_index,
                                 Handle<Object> value,
                                 PropertyAttributes attributes);

55 56
  static Descriptor AccessorConstant(Handle<Name> key, Handle<Object> foreign,
                                     PropertyAttributes attributes) {
57 58 59
    return Descriptor(key, MaybeObjectHandle(foreign), kAccessor, attributes,
                      kDescriptor, PropertyConstness::kConst,
                      Representation::Tagged(), 0);
60 61
  }

62
 private:
63
  Handle<Name> key_;
64
  MaybeObjectHandle value_;
65 66 67
  PropertyDetails details_;

 protected:
68 69
  void Init(Handle<Name> key, MaybeObjectHandle value,
            PropertyDetails details) {
70
    DCHECK(key->IsUniqueName());
71
    DCHECK_IMPLIES(key->IsPrivate(), !details.IsEnumerable());
72 73 74 75 76
    key_ = key;
    value_ = value;
    details_ = details;
  }

77
  Descriptor(Handle<Name> key, MaybeObjectHandle value, PropertyDetails details)
78 79
      : key_(key), value_(value), details_(details) {
    DCHECK(key->IsUniqueName());
80
    DCHECK_IMPLIES(key->IsPrivate(), !details_.IsEnumerable());
81 82
  }

83
  Descriptor(Handle<Name> key, MaybeObjectHandle value, PropertyKind kind,
84
             PropertyAttributes attributes, PropertyLocation location,
85 86
             PropertyConstness constness, Representation representation,
             int field_index)
87 88
      : key_(key),
        value_(value),
89 90
        details_(kind, attributes, location, constness, representation,
                 field_index) {
91
    DCHECK(key->IsUniqueName());
92
    DCHECK_IMPLIES(key->IsPrivate(), !details_.IsEnumerable());
93
  }
94 95

  friend class DescriptorArray;
96
  friend class Map;
97
  friend class MapUpdater;
98 99
};

100 101
}  // namespace internal
}  // namespace v8
102 103

#endif  // V8_PROPERTY_H_