property.h 3.04 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
#include "src/isolate.h"
12

13 14
namespace v8 {
namespace internal {
15 16 17 18 19 20 21 22

// 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:
23 24 25
  Handle<Name> GetKey() const { return key_; }
  Handle<Object> GetValue() const { return value_; }
  PropertyDetails GetDetails() const { return details_; }
26

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

29
 private:
30 31
  Handle<Name> key_;
  Handle<Object> value_;
32 33 34 35 36
  PropertyDetails details_;

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

37
  void Init(Handle<Name> key, Handle<Object> value, PropertyDetails details) {
38
    DCHECK(key->IsUniqueName());
39 40 41 42 43
    key_ = key;
    value_ = value;
    details_ = details;
  }

44
  Descriptor(Handle<Name> key, Handle<Object> value, PropertyDetails details)
45 46 47 48 49 50 51
      : key_(key), value_(value), details_(details) {
    DCHECK(key->IsUniqueName());
  }

  Descriptor(Handle<Name> key, Handle<Object> value,
             PropertyAttributes attributes, PropertyType type,
             Representation representation, int field_index = 0)
52 53
      : key_(key),
        value_(value),
54 55 56
        details_(attributes, type, representation, field_index) {
    DCHECK(key->IsUniqueName());
  }
57 58

  friend class DescriptorArray;
59
  friend class Map;
60 61 62
};


63
std::ostream& operator<<(std::ostream& os, const Descriptor& d);
64 65


66
class DataDescriptor final : public Descriptor {
67
 public:
68
  DataDescriptor(Handle<Name> key, int field_index,
69
                 PropertyAttributes attributes, Representation representation);
70 71 72
  // 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,
73
                 PropertyAttributes attributes, Representation representation)
74 75 76 77
      : Descriptor(key, wrapped_field_type, attributes, DATA, representation,
                   field_index) {
    DCHECK(wrapped_field_type->IsSmi() || wrapped_field_type->IsWeakCell());
  }
78 79 80
};


81
class DataConstantDescriptor final : public Descriptor {
82
 public:
83 84 85
  DataConstantDescriptor(Handle<Name> key, Handle<Object> value,
                         PropertyAttributes attributes)
      : Descriptor(key, value, attributes, DATA_CONSTANT,
86
                   value->OptimalRepresentation()) {}
87 88 89
};


90
class AccessorConstantDescriptor final : public Descriptor {
91
 public:
92 93 94
  AccessorConstantDescriptor(Handle<Name> key, Handle<Object> foreign,
                             PropertyAttributes attributes)
      : Descriptor(key, foreign, attributes, ACCESSOR_CONSTANT,
95
                   Representation::Tagged()) {}
96 97 98
};


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

#endif  // V8_PROPERTY_H_