Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1 | // 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 Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4 | |
| 5 | #ifndef V8_PROPERTY_H_ |
| 6 | #define V8_PROPERTY_H_ |
| 7 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 8 | #include <iosfwd> |
| 9 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10 | #include "src/factory.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 11 | #include "src/isolate.h" |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 12 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 13 | namespace v8 { |
| 14 | namespace internal { |
| 15 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 16 | // 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 Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 21 | class Descriptor BASE_EMBEDDED { |
| 22 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 23 | Handle<Name> GetKey() const { return key_; } |
| 24 | Handle<Object> GetValue() const { return value_; } |
| 25 | PropertyDetails GetDetails() const { return details_; } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 26 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 27 | void SetSortedKeyIndex(int index) { details_ = details_.set_pointer(index); } |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 28 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 29 | private: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 30 | Handle<Name> key_; |
| 31 | Handle<Object> value_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 32 | PropertyDetails details_; |
| 33 | |
| 34 | protected: |
| 35 | Descriptor() : details_(Smi::FromInt(0)) {} |
| 36 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 37 | void Init(Handle<Name> key, Handle<Object> value, PropertyDetails details) { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 38 | DCHECK(key->IsUniqueName()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 39 | key_ = key; |
| 40 | value_ = value; |
| 41 | details_ = details; |
| 42 | } |
| 43 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 44 | Descriptor(Handle<Name> key, Handle<Object> value, PropertyDetails details) |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 45 | : key_(key), value_(value), details_(details) { |
| 46 | DCHECK(key->IsUniqueName()); |
| 47 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 48 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 49 | Descriptor(Handle<Name> key, Handle<Object> value, |
| 50 | PropertyAttributes attributes, PropertyType type, |
| 51 | Representation representation, int field_index = 0) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 52 | : key_(key), |
| 53 | value_(value), |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 54 | details_(attributes, type, representation, field_index) { |
| 55 | DCHECK(key->IsUniqueName()); |
| 56 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 57 | |
| 58 | friend class DescriptorArray; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 59 | friend class Map; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 60 | }; |
| 61 | |
| 62 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 63 | std::ostream& operator<<(std::ostream& os, const Descriptor& d); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 64 | |
| 65 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 66 | class DataDescriptor final : public Descriptor { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 67 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 68 | DataDescriptor(Handle<Name> key, int field_index, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 69 | PropertyAttributes attributes, Representation representation); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 70 | // 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 Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 78 | }; |
| 79 | |
| 80 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 81 | class DataConstantDescriptor final : public Descriptor { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 82 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 83 | DataConstantDescriptor(Handle<Name> key, Handle<Object> value, |
| 84 | PropertyAttributes attributes) |
| 85 | : Descriptor(key, value, attributes, DATA_CONSTANT, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 86 | value->OptimalRepresentation()) {} |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 87 | }; |
| 88 | |
| 89 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 90 | class AccessorConstantDescriptor final : public Descriptor { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 91 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 92 | AccessorConstantDescriptor(Handle<Name> key, Handle<Object> foreign, |
| 93 | PropertyAttributes attributes) |
| 94 | : Descriptor(key, foreign, attributes, ACCESSOR_CONSTANT, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 95 | Representation::Tagged()) {} |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 96 | }; |
| 97 | |
| 98 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 99 | } // namespace internal |
| 100 | } // namespace v8 |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 101 | |
| 102 | #endif // V8_PROPERTY_H_ |