blob: add9e4d11bfca0ef25f3606b6e343d11e8ba05a6 [file] [log] [blame]
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001// Copyright 2014 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
Steve Blocka7e24c12009-10-30 11:49:00 +00004
5#ifndef V8_PROPERTY_H_
6#define V8_PROPERTY_H_
7
Emily Bernierd0a1eb72015-03-24 16:35:39 -04008#include <iosfwd>
9
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010#include "src/factory.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +000011#include "src/isolate.h"
Ben Murdoch257744e2011-11-30 15:57:28 +000012
Steve Blocka7e24c12009-10-30 11:49:00 +000013namespace v8 {
14namespace internal {
15
Steve Blocka7e24c12009-10-30 11:49:00 +000016// Abstraction for elements in instance-descriptor arrays.
17//
18// Each descriptor has a key, property attributes, property type,
19// property index (in the actual instance-descriptor array) and
20// optionally a piece of data.
Steve Blocka7e24c12009-10-30 11:49:00 +000021class Descriptor BASE_EMBEDDED {
22 public:
Ben Murdochb8a8cc12014-11-26 15:28:44 +000023 Handle<Name> GetKey() const { return key_; }
24 Handle<Object> GetValue() const { return value_; }
25 PropertyDetails GetDetails() const { return details_; }
Steve Blocka7e24c12009-10-30 11:49:00 +000026
Ben Murdochb8a8cc12014-11-26 15:28:44 +000027 void SetSortedKeyIndex(int index) { details_ = details_.set_pointer(index); }
Ben Murdoch3ef787d2012-04-12 10:51:47 +010028
Steve Blocka7e24c12009-10-30 11:49:00 +000029 private:
Ben Murdochb8a8cc12014-11-26 15:28:44 +000030 Handle<Name> key_;
31 Handle<Object> value_;
Steve Blocka7e24c12009-10-30 11:49:00 +000032 PropertyDetails details_;
33
34 protected:
35 Descriptor() : details_(Smi::FromInt(0)) {}
36
Ben Murdochb8a8cc12014-11-26 15:28:44 +000037 void Init(Handle<Name> key, Handle<Object> value, PropertyDetails details) {
Ben Murdoch097c5b22016-05-18 11:27:45 +010038 DCHECK(key->IsUniqueName());
Steve Blocka7e24c12009-10-30 11:49:00 +000039 key_ = key;
40 value_ = value;
41 details_ = details;
42 }
43
Ben Murdochb8a8cc12014-11-26 15:28:44 +000044 Descriptor(Handle<Name> key, Handle<Object> value, PropertyDetails details)
Ben Murdoch097c5b22016-05-18 11:27:45 +010045 : key_(key), value_(value), details_(details) {
46 DCHECK(key->IsUniqueName());
47 }
Steve Blocka7e24c12009-10-30 11:49:00 +000048
Ben Murdoch097c5b22016-05-18 11:27:45 +010049 Descriptor(Handle<Name> key, Handle<Object> value,
50 PropertyAttributes attributes, PropertyType type,
51 Representation representation, int field_index = 0)
Steve Blocka7e24c12009-10-30 11:49:00 +000052 : key_(key),
53 value_(value),
Ben Murdoch097c5b22016-05-18 11:27:45 +010054 details_(attributes, type, representation, field_index) {
55 DCHECK(key->IsUniqueName());
56 }
Steve Blocka7e24c12009-10-30 11:49:00 +000057
58 friend class DescriptorArray;
Ben Murdochb8a8cc12014-11-26 15:28:44 +000059 friend class Map;
Steve Blocka7e24c12009-10-30 11:49:00 +000060};
61
62
Emily Bernierd0a1eb72015-03-24 16:35:39 -040063std::ostream& operator<<(std::ostream& os, const Descriptor& d);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000064
65
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000066class DataDescriptor final : public Descriptor {
Steve Blocka7e24c12009-10-30 11:49:00 +000067 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000068 DataDescriptor(Handle<Name> key, int field_index,
Ben Murdoch097c5b22016-05-18 11:27:45 +010069 PropertyAttributes attributes, Representation representation);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000070 // The field type is either a simple type or a map wrapped in a weak cell.
71 DataDescriptor(Handle<Name> key, int field_index,
72 Handle<Object> wrapped_field_type,
73 PropertyAttributes attributes, Representation representation)
74 : Descriptor(key, wrapped_field_type, attributes, DATA, representation,
75 field_index) {
76 DCHECK(wrapped_field_type->IsSmi() || wrapped_field_type->IsWeakCell());
77 }
Steve Blocka7e24c12009-10-30 11:49:00 +000078};
79
80
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000081class DataConstantDescriptor final : public Descriptor {
Steve Blocka7e24c12009-10-30 11:49:00 +000082 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000083 DataConstantDescriptor(Handle<Name> key, Handle<Object> value,
84 PropertyAttributes attributes)
85 : Descriptor(key, value, attributes, DATA_CONSTANT,
Ben Murdochb8a8cc12014-11-26 15:28:44 +000086 value->OptimalRepresentation()) {}
Steve Blocka7e24c12009-10-30 11:49:00 +000087};
88
89
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000090class AccessorConstantDescriptor final : public Descriptor {
Steve Blocka7e24c12009-10-30 11:49:00 +000091 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000092 AccessorConstantDescriptor(Handle<Name> key, Handle<Object> foreign,
93 PropertyAttributes attributes)
94 : Descriptor(key, foreign, attributes, ACCESSOR_CONSTANT,
Ben Murdochb8a8cc12014-11-26 15:28:44 +000095 Representation::Tagged()) {}
Steve Blocka7e24c12009-10-30 11:49:00 +000096};
97
98
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000099} // namespace internal
100} // namespace v8
Steve Blocka7e24c12009-10-30 11:49:00 +0000101
102#endif // V8_PROPERTY_H_