property.h 3.35 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
#include "src/field-index.h"
#include "src/field-index-inl.h"
13
#include "src/isolate.h"
14
#include "src/types.h"
15

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

// 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.
class Descriptor BASE_EMBEDDED {
 public:
26
  void KeyToUniqueName() {
27
    if (!key_->IsUniqueName()) {
28 29
      key_ = key_->GetIsolate()->factory()->InternalizeString(
          Handle<String>::cast(key_));
30 31 32
    }
  }

33 34 35
  Handle<Name> GetKey() const { return key_; }
  Handle<Object> GetValue() const { return value_; }
  PropertyDetails GetDetails() const { return details_; }
36

37
  void SetSortedKeyIndex(int index) { details_ = details_.set_pointer(index); }
38

39
 private:
40 41
  Handle<Name> key_;
  Handle<Object> value_;
42 43 44 45 46
  PropertyDetails details_;

 protected:
  Descriptor() : details_(Smi::FromInt(0)) {}

47
  void Init(Handle<Name> key, Handle<Object> value, PropertyDetails details) {
48 49 50 51 52
    key_ = key;
    value_ = value;
    details_ = details;
  }

53
  Descriptor(Handle<Name> key, Handle<Object> value, PropertyDetails details)
54 55 56 57
      : key_(key),
        value_(value),
        details_(details) { }

58 59
  Descriptor(Handle<Name> key,
             Handle<Object> value,
60 61
             PropertyAttributes attributes,
             PropertyType type,
62 63
             Representation representation,
             int field_index = 0)
64 65
      : key_(key),
        value_(value),
66
        details_(attributes, type, representation, field_index) { }
67 68

  friend class DescriptorArray;
69
  friend class Map;
70 71 72
};


73
std::ostream& operator<<(std::ostream& os, const Descriptor& d);
74 75


76
class DataDescriptor final : public Descriptor {
77
 public:
78 79 80 81
  DataDescriptor(Handle<Name> key, int field_index,
                 PropertyAttributes attributes, Representation representation)
      : Descriptor(key, HeapType::Any(key->GetIsolate()), attributes, DATA,
                   representation, field_index) {}
82 83 84
  // The field type is either a simple type or a map wrapped in a weak cell.
  DataDescriptor(Handle<Name> key, int field_index,
                 Handle<Object> wrapped_field_type,
85
                 PropertyAttributes attributes, Representation representation)
86 87 88 89
      : Descriptor(key, wrapped_field_type, attributes, DATA, representation,
                   field_index) {
    DCHECK(wrapped_field_type->IsSmi() || wrapped_field_type->IsWeakCell());
  }
90 91 92
};


93
class DataConstantDescriptor final : public Descriptor {
94
 public:
95 96 97
  DataConstantDescriptor(Handle<Name> key, Handle<Object> value,
                         PropertyAttributes attributes)
      : Descriptor(key, value, attributes, DATA_CONSTANT,
98
                   value->OptimalRepresentation()) {}
99 100 101
};


102
class AccessorConstantDescriptor final : public Descriptor {
103
 public:
104 105 106
  AccessorConstantDescriptor(Handle<Name> key, Handle<Object> foreign,
                             PropertyAttributes attributes)
      : Descriptor(key, foreign, attributes, ACCESSOR_CONSTANT,
107
                   Representation::Tagged()) {}
108 109 110 111 112 113
};


} }  // namespace v8::internal

#endif  // V8_PROPERTY_H_