property.h 3.24 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
#include "src/factory.h"
11

12 13
namespace v8 {
namespace internal {
14 15 16 17 18 19

// 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.
20
class Descriptor final BASE_EMBEDDED {
21
 public:
22 23
  Descriptor() : details_(Smi::kZero) {}

24 25 26
  Handle<Name> GetKey() const { return key_; }
  Handle<Object> GetValue() const { return value_; }
  PropertyDetails GetDetails() const { return details_; }
27

28
  void SetSortedKeyIndex(int index) { details_ = details_.set_pointer(index); }
29

30 31 32 33 34 35
  static Descriptor DataField(Handle<Name> key, int field_index,
                              PropertyAttributes attributes,
                              Representation representation);

  static Descriptor DataField(Handle<Name> key, int field_index,
                              PropertyAttributes attributes,
36 37 38
                              PropertyConstness constness,
                              Representation representation,
                              Handle<Object> wrapped_field_type);
39 40 41

  static Descriptor DataConstant(Handle<Name> key, Handle<Object> value,
                                 PropertyAttributes attributes) {
42 43
    return Descriptor(key, value, kData, attributes, kDescriptor, kConst,
                      value->OptimalRepresentation(), 0);
44 45
  }

46 47 48 49
  static Descriptor DataConstant(Handle<Name> key, int field_index,
                                 Handle<Object> value,
                                 PropertyAttributes attributes);

50 51
  static Descriptor AccessorConstant(Handle<Name> key, Handle<Object> foreign,
                                     PropertyAttributes attributes) {
52 53
    return Descriptor(key, foreign, kAccessor, attributes, kDescriptor, kConst,
                      Representation::Tagged(), 0);
54 55
  }

56
 private:
57 58
  Handle<Name> key_;
  Handle<Object> value_;
59 60 61
  PropertyDetails details_;

 protected:
62
  void Init(Handle<Name> key, Handle<Object> value, PropertyDetails details) {
63
    DCHECK(key->IsUniqueName());
64
    DCHECK_IMPLIES(key->IsPrivate(), !details.IsEnumerable());
65 66 67 68 69
    key_ = key;
    value_ = value;
    details_ = details;
  }

70
  Descriptor(Handle<Name> key, Handle<Object> value, PropertyDetails details)
71 72
      : key_(key), value_(value), details_(details) {
    DCHECK(key->IsUniqueName());
73
    DCHECK_IMPLIES(key->IsPrivate(), !details_.IsEnumerable());
74 75
  }

76 77
  Descriptor(Handle<Name> key, Handle<Object> value, PropertyKind kind,
             PropertyAttributes attributes, PropertyLocation location,
78 79
             PropertyConstness constness, Representation representation,
             int field_index)
80 81
      : key_(key),
        value_(value),
82 83
        details_(kind, attributes, location, constness, representation,
                 field_index) {
84
    DCHECK(key->IsUniqueName());
85
    DCHECK_IMPLIES(key->IsPrivate(), !details_.IsEnumerable());
86
  }
87 88

  friend class DescriptorArray;
89
  friend class Map;
90
  friend class MapUpdater;
91 92
};

93 94
}  // namespace internal
}  // namespace v8
95 96

#endif  // V8_PROPERTY_H_