blob: 510e9852a987e0c175ac9121d6da77cbd6458b43 [file] [log] [blame]
rossberg@chromium.org994edf62012-02-06 10:12:55 +00001// Copyright 2012 the V8 project authors. All rights reserved.
danno@chromium.orgc612e022011-11-10 11:38:15 +00002// Redistribution and use in source and binary forms, with or without
3// modification, are permitted provided that the following conditions are
4// met:
5//
6// * Redistributions of source code must retain the above copyright
7// notice, this list of conditions and the following disclaimer.
8// * Redistributions in binary form must reproduce the above
9// copyright notice, this list of conditions and the following
10// disclaimer in the documentation and/or other materials provided
11// with the distribution.
12// * Neither the name of Google Inc. nor the names of its
13// contributors may be used to endorse or promote products derived
14// from this software without specific prior written permission.
15//
16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28#ifndef V8_PROPERTY_DETAILS_H_
29#define V8_PROPERTY_DETAILS_H_
30
31#include "../include/v8.h"
32#include "allocation.h"
33#include "utils.h"
34
35// Ecma-262 3rd 8.6.1
36enum PropertyAttributes {
37 NONE = v8::None,
38 READ_ONLY = v8::ReadOnly,
39 DONT_ENUM = v8::DontEnum,
40 DONT_DELETE = v8::DontDelete,
ulan@chromium.org8e8d8822012-11-23 14:36:46 +000041
42 SEALED = DONT_ENUM | DONT_DELETE,
43 FROZEN = SEALED | READ_ONLY,
44
danno@chromium.orgc612e022011-11-10 11:38:15 +000045 ABSENT = 16 // Used in runtime to indicate a property is absent.
46 // ABSENT can never be stored in or returned from a descriptor's attributes
47 // bitfield. It is only used as a return value meaning the attributes of
48 // a non-existent property.
49};
50
51
52namespace v8 {
53namespace internal {
54
55class Smi;
56
57// Type of properties.
58// Order of properties is significant.
59// Must fit in the BitField PropertyDetails::TypeField.
60// A copy of this is in mirror-debugger.js.
61enum PropertyType {
yangguo@chromium.org99aa4902012-07-06 16:21:55 +000062 // Only in slow mode.
63 NORMAL = 0,
64 // Only in fast mode.
65 FIELD = 1,
66 CONSTANT_FUNCTION = 2,
danno@chromium.orgc612e022011-11-10 11:38:15 +000067 CALLBACKS = 3,
yangguo@chromium.org99aa4902012-07-06 16:21:55 +000068 // Only in lookup results, not in descriptors.
69 HANDLER = 4,
70 INTERCEPTOR = 5,
71 TRANSITION = 6,
jkummerow@chromium.org7a6fc812012-06-27 11:12:38 +000072 // Only used as a marker in LookupResult.
yangguo@chromium.org99aa4902012-07-06 16:21:55 +000073 NONEXISTENT = 7
danno@chromium.orgc612e022011-11-10 11:38:15 +000074};
75
76
danno@chromium.orgc612e022011-11-10 11:38:15 +000077// PropertyDetails captures type and attributes for a property.
78// They are used both in property dictionaries and instance descriptors.
79class PropertyDetails BASE_EMBEDDED {
80 public:
81 PropertyDetails(PropertyAttributes attributes,
82 PropertyType type,
83 int index = 0) {
danno@chromium.orgc612e022011-11-10 11:38:15 +000084 value_ = TypeField::encode(type)
85 | AttributesField::encode(attributes)
yangguo@chromium.org46839fb2012-08-28 09:06:19 +000086 | DictionaryStorageField::encode(index);
danno@chromium.orgc612e022011-11-10 11:38:15 +000087
88 ASSERT(type == this->type());
89 ASSERT(attributes == this->attributes());
yangguo@chromium.org46839fb2012-08-28 09:06:19 +000090 ASSERT(index == this->dictionary_index());
danno@chromium.orgc612e022011-11-10 11:38:15 +000091 }
92
yangguo@chromium.org46839fb2012-08-28 09:06:19 +000093 int pointer() { return DescriptorPointer::decode(value_); }
94
95 PropertyDetails set_pointer(int i) { return PropertyDetails(value_, i); }
96
danno@chromium.orgc612e022011-11-10 11:38:15 +000097 // Conversion for storing details as Object*.
98 explicit inline PropertyDetails(Smi* smi);
99 inline Smi* AsSmi();
100
101 PropertyType type() { return TypeField::decode(value_); }
102
jkummerow@chromium.orgc1956672012-10-11 15:57:38 +0000103 PropertyAttributes attributes() const {
104 return AttributesField::decode(value_);
105 }
danno@chromium.orgc612e022011-11-10 11:38:15 +0000106
yangguo@chromium.org46839fb2012-08-28 09:06:19 +0000107 int dictionary_index() {
108 return DictionaryStorageField::decode(value_);
109 }
110
111 int descriptor_index() {
112 return DescriptorStorageField::decode(value_);
113 }
danno@chromium.orgc612e022011-11-10 11:38:15 +0000114
115 inline PropertyDetails AsDeleted();
116
117 static bool IsValidIndex(int index) {
yangguo@chromium.org46839fb2012-08-28 09:06:19 +0000118 return DictionaryStorageField::is_valid(index);
danno@chromium.orgc612e022011-11-10 11:38:15 +0000119 }
120
jkummerow@chromium.orgc1956672012-10-11 15:57:38 +0000121 bool IsReadOnly() const { return (attributes() & READ_ONLY) != 0; }
122 bool IsDontDelete() const { return (attributes() & DONT_DELETE) != 0; }
123 bool IsDontEnum() const { return (attributes() & DONT_ENUM) != 0; }
124 bool IsDeleted() const { return DeletedField::decode(value_) != 0;}
danno@chromium.orgc612e022011-11-10 11:38:15 +0000125
126 // Bit fields in value_ (type, shift, size). Must be public so the
127 // constants can be embedded in generated code.
yangguo@chromium.org46839fb2012-08-28 09:06:19 +0000128 class TypeField: public BitField<PropertyType, 0, 3> {};
129 class AttributesField: public BitField<PropertyAttributes, 3, 3> {};
130 class DeletedField: public BitField<uint32_t, 6, 1> {};
131 class DictionaryStorageField: public BitField<uint32_t, 7, 24> {};
132 class DescriptorStorageField: public BitField<uint32_t, 7, 11> {};
133 class DescriptorPointer: public BitField<uint32_t, 18, 11> {};
danno@chromium.orgc612e022011-11-10 11:38:15 +0000134
135 static const int kInitialIndex = 1;
136
137 private:
yangguo@chromium.org46839fb2012-08-28 09:06:19 +0000138 PropertyDetails(int value, int pointer) {
139 value_ = DescriptorPointer::update(value, pointer);
140 }
141
danno@chromium.orgc612e022011-11-10 11:38:15 +0000142 uint32_t value_;
143};
144
145} } // namespace v8::internal
146
147#endif // V8_PROPERTY_DETAILS_H_