rossberg@chromium.org | 994edf6 | 2012-02-06 10:12:55 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2 | // 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_H_ |
| 29 | #define V8_PROPERTY_H_ |
| 30 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 31 | #include "allocation.h" |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 32 | #include "transitions.h" |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 33 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 34 | namespace v8 { |
| 35 | namespace internal { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 36 | |
| 37 | |
| 38 | // Abstraction for elements in instance-descriptor arrays. |
| 39 | // |
| 40 | // Each descriptor has a key, property attributes, property type, |
| 41 | // property index (in the actual instance-descriptor array) and |
| 42 | // optionally a piece of data. |
| 43 | // |
| 44 | |
| 45 | class Descriptor BASE_EMBEDDED { |
| 46 | public: |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 47 | MUST_USE_RESULT MaybeObject* KeyToUniqueName() { |
| 48 | if (!key_->IsUniqueName()) { |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 49 | MaybeObject* maybe_result = |
| 50 | key_->GetIsolate()->heap()->InternalizeString(String::cast(key_)); |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 51 | if (!maybe_result->To(&key_)) return maybe_result; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 52 | } |
| 53 | return key_; |
| 54 | } |
| 55 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 56 | Name* GetKey() { return key_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 57 | Object* GetValue() { return value_; } |
| 58 | PropertyDetails GetDetails() { return details_; } |
| 59 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 60 | #ifdef OBJECT_PRINT |
| 61 | void Print(FILE* out); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 62 | #endif |
| 63 | |
verwaest@chromium.org | 06ab2ec | 2012-10-09 17:00:13 +0000 | [diff] [blame] | 64 | void SetSortedKeyIndex(int index) { details_ = details_.set_pointer(index); } |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 65 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 66 | private: |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 67 | Name* key_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 68 | Object* value_; |
| 69 | PropertyDetails details_; |
| 70 | |
| 71 | protected: |
| 72 | Descriptor() : details_(Smi::FromInt(0)) {} |
| 73 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 74 | void Init(Name* key, Object* value, PropertyDetails details) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 75 | key_ = key; |
| 76 | value_ = value; |
| 77 | details_ = details; |
| 78 | } |
| 79 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 80 | Descriptor(Name* key, Object* value, PropertyDetails details) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 81 | : key_(key), |
| 82 | value_(value), |
| 83 | details_(details) { } |
| 84 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 85 | Descriptor(Name* key, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 86 | Object* value, |
| 87 | PropertyAttributes attributes, |
| 88 | PropertyType type, |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 89 | Representation representation, |
| 90 | int field_index = 0) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 91 | : key_(key), |
| 92 | value_(value), |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 93 | details_(attributes, type, representation, field_index) { } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 94 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 95 | friend class DescriptorArray; |
| 96 | }; |
| 97 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 98 | |
| 99 | class FieldDescriptor: public Descriptor { |
| 100 | public: |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 101 | FieldDescriptor(Name* key, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 102 | int field_index, |
| 103 | PropertyAttributes attributes, |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 104 | Representation representation) |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 105 | : Descriptor(key, Smi::FromInt(0), attributes, |
| 106 | FIELD, representation, field_index) {} |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 107 | }; |
| 108 | |
| 109 | |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 110 | class ConstantDescriptor: public Descriptor { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 111 | public: |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 112 | ConstantDescriptor(Name* key, |
| 113 | Object* value, |
| 114 | PropertyAttributes attributes) |
| 115 | : Descriptor(key, value, attributes, CONSTANT, |
| 116 | value->OptimalRepresentation()) {} |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 117 | }; |
| 118 | |
| 119 | |
| 120 | class CallbacksDescriptor: public Descriptor { |
| 121 | public: |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 122 | CallbacksDescriptor(Name* key, |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 123 | Object* foreign, |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 124 | PropertyAttributes attributes) |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 125 | : Descriptor(key, foreign, attributes, CALLBACKS, |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 126 | Representation::Tagged()) {} |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 127 | }; |
| 128 | |
| 129 | |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 130 | // Holds a property index value distinguishing if it is a field index or an |
| 131 | // index inside the object header. |
| 132 | class PropertyIndex { |
| 133 | public: |
| 134 | static PropertyIndex NewFieldIndex(int index) { |
| 135 | return PropertyIndex(index, false); |
| 136 | } |
| 137 | static PropertyIndex NewHeaderIndex(int index) { |
| 138 | return PropertyIndex(index, true); |
| 139 | } |
| 140 | |
| 141 | bool is_field_index() { return (index_ & kHeaderIndexBit) == 0; } |
| 142 | bool is_header_index() { return (index_ & kHeaderIndexBit) != 0; } |
| 143 | |
| 144 | int field_index() { |
| 145 | ASSERT(is_field_index()); |
| 146 | return value(); |
| 147 | } |
| 148 | int header_index() { |
| 149 | ASSERT(is_header_index()); |
| 150 | return value(); |
| 151 | } |
| 152 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 153 | bool is_inobject(Handle<JSObject> holder) { |
| 154 | if (is_header_index()) return true; |
| 155 | return field_index() < holder->map()->inobject_properties(); |
| 156 | } |
| 157 | |
| 158 | int translate(Handle<JSObject> holder) { |
| 159 | if (is_header_index()) return header_index(); |
| 160 | int index = field_index() - holder->map()->inobject_properties(); |
| 161 | if (index >= 0) return index; |
| 162 | return index + holder->map()->instance_size() / kPointerSize; |
| 163 | } |
| 164 | |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 165 | private: |
| 166 | static const int kHeaderIndexBit = 1 << 31; |
| 167 | static const int kIndexMask = ~kHeaderIndexBit; |
| 168 | |
| 169 | int value() { return index_ & kIndexMask; } |
| 170 | |
| 171 | PropertyIndex(int index, bool is_header_based) |
| 172 | : index_(index | (is_header_based ? kHeaderIndexBit : 0)) { |
| 173 | ASSERT(index <= kIndexMask); |
| 174 | } |
| 175 | |
| 176 | int index_; |
| 177 | }; |
| 178 | |
| 179 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 180 | class LookupResult BASE_EMBEDDED { |
| 181 | public: |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 182 | explicit LookupResult(Isolate* isolate) |
| 183 | : isolate_(isolate), |
| 184 | next_(isolate->top_lookup_result()), |
| 185 | lookup_type_(NOT_FOUND), |
| 186 | holder_(NULL), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 187 | cacheable_(true), |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 188 | details_(NONE, NONEXISTENT, Representation::None()) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 189 | isolate->SetTopLookupResult(this); |
| 190 | } |
| 191 | |
| 192 | ~LookupResult() { |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 193 | ASSERT(isolate()->top_lookup_result() == this); |
| 194 | isolate()->SetTopLookupResult(next_); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 195 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 196 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 197 | Isolate* isolate() const { return isolate_; } |
| 198 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 199 | void DescriptorResult(JSObject* holder, PropertyDetails details, int number) { |
| 200 | lookup_type_ = DESCRIPTOR_TYPE; |
| 201 | holder_ = holder; |
| 202 | details_ = details; |
| 203 | number_ = number; |
| 204 | } |
| 205 | |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 206 | bool CanHoldValue(Handle<Object> value) { |
danno@chromium.org | 1fd77d5 | 2013-06-07 16:01:45 +0000 | [diff] [blame] | 207 | if (IsNormal()) return true; |
| 208 | ASSERT(!IsTransition()); |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 209 | return value->FitsRepresentation(details_.representation()); |
| 210 | } |
| 211 | |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 212 | void TransitionResult(JSObject* holder, int number) { |
| 213 | lookup_type_ = TRANSITION_TYPE; |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 214 | details_ = PropertyDetails(NONE, TRANSITION, Representation::None()); |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 215 | holder_ = holder; |
| 216 | number_ = number; |
| 217 | } |
| 218 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 219 | void DictionaryResult(JSObject* holder, int entry) { |
| 220 | lookup_type_ = DICTIONARY_TYPE; |
| 221 | holder_ = holder; |
| 222 | details_ = holder->property_dictionary()->DetailsAt(entry); |
| 223 | number_ = entry; |
| 224 | } |
| 225 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 226 | void HandlerResult(JSProxy* proxy) { |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 227 | lookup_type_ = HANDLER_TYPE; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 228 | holder_ = proxy; |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 229 | details_ = PropertyDetails(NONE, HANDLER, Representation::Tagged()); |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 230 | cacheable_ = false; |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 231 | } |
| 232 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 233 | void InterceptorResult(JSObject* holder) { |
| 234 | lookup_type_ = INTERCEPTOR_TYPE; |
| 235 | holder_ = holder; |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 236 | details_ = PropertyDetails(NONE, INTERCEPTOR, Representation::Tagged()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | void NotFound() { |
| 240 | lookup_type_ = NOT_FOUND; |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 241 | details_ = PropertyDetails(NONE, NONEXISTENT, Representation::None()); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 242 | holder_ = NULL; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 243 | } |
| 244 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 245 | JSObject* holder() { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 246 | ASSERT(IsFound()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 247 | return JSObject::cast(holder_); |
| 248 | } |
| 249 | |
| 250 | JSProxy* proxy() { |
| 251 | ASSERT(IsFound()); |
| 252 | return JSProxy::cast(holder_); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | PropertyType type() { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 256 | ASSERT(IsFound()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 257 | return details_.type(); |
| 258 | } |
| 259 | |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 260 | Representation representation() { |
| 261 | ASSERT(IsFound()); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 262 | ASSERT(!IsTransition()); |
| 263 | ASSERT(details_.type() != NONEXISTENT); |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 264 | return details_.representation(); |
| 265 | } |
| 266 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 267 | PropertyAttributes GetAttributes() { |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 268 | ASSERT(!IsTransition()); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 269 | ASSERT(IsFound()); |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 270 | ASSERT(details_.type() != NONEXISTENT); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 271 | return details_.attributes(); |
| 272 | } |
| 273 | |
| 274 | PropertyDetails GetPropertyDetails() { |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 275 | ASSERT(!IsTransition()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 276 | return details_; |
| 277 | } |
| 278 | |
yangguo@chromium.org | de0db00 | 2012-06-22 13:44:28 +0000 | [diff] [blame] | 279 | bool IsFastPropertyType() { |
| 280 | ASSERT(IsFound()); |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 281 | return IsTransition() || type() != NORMAL; |
| 282 | } |
| 283 | |
| 284 | // Property callbacks does not include transitions to callbacks. |
| 285 | bool IsPropertyCallbacks() { |
| 286 | ASSERT(!(details_.type() == CALLBACKS && !IsFound())); |
| 287 | return details_.type() == CALLBACKS; |
| 288 | } |
| 289 | |
yangguo@chromium.org | de0db00 | 2012-06-22 13:44:28 +0000 | [diff] [blame] | 290 | bool IsReadOnly() { |
| 291 | ASSERT(IsFound()); |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 292 | ASSERT(!IsTransition()); |
| 293 | ASSERT(details_.type() != NONEXISTENT); |
yangguo@chromium.org | de0db00 | 2012-06-22 13:44:28 +0000 | [diff] [blame] | 294 | return details_.IsReadOnly(); |
| 295 | } |
| 296 | |
yangguo@chromium.org | de0db00 | 2012-06-22 13:44:28 +0000 | [diff] [blame] | 297 | bool IsField() { |
| 298 | ASSERT(!(details_.type() == FIELD && !IsFound())); |
| 299 | return details_.type() == FIELD; |
| 300 | } |
| 301 | |
| 302 | bool IsNormal() { |
| 303 | ASSERT(!(details_.type() == NORMAL && !IsFound())); |
| 304 | return details_.type() == NORMAL; |
| 305 | } |
| 306 | |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 307 | bool IsConstant() { |
| 308 | ASSERT(!(details_.type() == CONSTANT && !IsFound())); |
| 309 | return details_.type() == CONSTANT; |
| 310 | } |
| 311 | |
yangguo@chromium.org | de0db00 | 2012-06-22 13:44:28 +0000 | [diff] [blame] | 312 | bool IsConstantFunction() { |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 313 | return IsConstant() && GetValue()->IsJSFunction(); |
yangguo@chromium.org | de0db00 | 2012-06-22 13:44:28 +0000 | [diff] [blame] | 314 | } |
| 315 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 316 | bool IsDontDelete() { return details_.IsDontDelete(); } |
| 317 | bool IsDontEnum() { return details_.IsDontEnum(); } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 318 | bool IsFound() { return lookup_type_ != NOT_FOUND; } |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 319 | bool IsTransition() { return lookup_type_ == TRANSITION_TYPE; } |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 320 | bool IsHandler() { return lookup_type_ == HANDLER_TYPE; } |
yangguo@chromium.org | de0db00 | 2012-06-22 13:44:28 +0000 | [diff] [blame] | 321 | bool IsInterceptor() { return lookup_type_ == INTERCEPTOR_TYPE; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 322 | |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 323 | // Is the result is a property excluding transitions and the null descriptor? |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 324 | bool IsProperty() { |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 325 | return IsFound() && !IsTransition(); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 326 | } |
| 327 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 328 | bool IsDataProperty() { |
| 329 | switch (type()) { |
| 330 | case FIELD: |
| 331 | case NORMAL: |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 332 | case CONSTANT: |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 333 | return true; |
| 334 | case CALLBACKS: { |
| 335 | Object* callback = GetCallbackObject(); |
| 336 | return callback->IsAccessorInfo() || callback->IsForeign(); |
| 337 | } |
| 338 | case HANDLER: |
| 339 | case INTERCEPTOR: |
| 340 | case TRANSITION: |
| 341 | case NONEXISTENT: |
| 342 | return false; |
| 343 | } |
| 344 | UNREACHABLE(); |
| 345 | return false; |
| 346 | } |
| 347 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 348 | bool IsCacheable() { return cacheable_; } |
| 349 | void DisallowCaching() { cacheable_ = false; } |
| 350 | |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 351 | Object* GetLazyValue() { |
| 352 | switch (type()) { |
| 353 | case FIELD: |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 354 | return holder()->RawFastPropertyAt(GetFieldIndex().field_index()); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 355 | case NORMAL: { |
| 356 | Object* value; |
| 357 | value = holder()->property_dictionary()->ValueAt(GetDictionaryEntry()); |
| 358 | if (holder()->IsGlobalObject()) { |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 359 | value = PropertyCell::cast(value)->value(); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 360 | } |
| 361 | return value; |
| 362 | } |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 363 | case CONSTANT: |
| 364 | return GetConstant(); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 365 | case CALLBACKS: |
| 366 | case HANDLER: |
| 367 | case INTERCEPTOR: |
| 368 | case TRANSITION: |
| 369 | case NONEXISTENT: |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 370 | return isolate()->heap()->the_hole_value(); |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 371 | } |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 372 | UNREACHABLE(); |
| 373 | return NULL; |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 374 | } |
| 375 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 376 | Map* GetTransitionTarget(Map* map) { |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 377 | ASSERT(IsTransition()); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 378 | TransitionArray* transitions = map->transitions(); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 379 | return transitions->GetTarget(number_); |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 380 | } |
| 381 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 382 | Map* GetTransitionTarget() { |
| 383 | return GetTransitionTarget(holder()->map()); |
| 384 | } |
| 385 | |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 386 | PropertyDetails GetTransitionDetails(Map* map) { |
| 387 | ASSERT(IsTransition()); |
| 388 | TransitionArray* transitions = map->transitions(); |
| 389 | return transitions->GetTargetDetails(number_); |
| 390 | } |
| 391 | |
| 392 | PropertyDetails GetTransitionDetails() { |
| 393 | return GetTransitionDetails(holder()->map()); |
| 394 | } |
| 395 | |
| 396 | bool IsTransitionToField(Map* map) { |
| 397 | return IsTransition() && GetTransitionDetails(map).type() == FIELD; |
| 398 | } |
| 399 | |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 400 | bool IsTransitionToConstant(Map* map) { |
| 401 | return IsTransition() && GetTransitionDetails(map).type() == CONSTANT; |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 402 | } |
| 403 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 404 | Map* GetTransitionMap() { |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 405 | ASSERT(IsTransition()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 406 | return Map::cast(GetValue()); |
| 407 | } |
| 408 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 409 | Map* GetTransitionMapFromMap(Map* map) { |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 410 | ASSERT(IsTransition()); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 411 | return map->transitions()->GetTarget(number_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 412 | } |
| 413 | |
jkummerow@chromium.org | 28583c9 | 2012-07-16 11:31:55 +0000 | [diff] [blame] | 414 | int GetTransitionIndex() { |
| 415 | ASSERT(IsTransition()); |
| 416 | return number_; |
| 417 | } |
| 418 | |
verwaest@chromium.org | 178fb15 | 2012-07-18 11:21:48 +0000 | [diff] [blame] | 419 | int GetDescriptorIndex() { |
| 420 | ASSERT(lookup_type_ == DESCRIPTOR_TYPE); |
| 421 | return number_; |
| 422 | } |
| 423 | |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 424 | PropertyIndex GetFieldIndex() { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 425 | ASSERT(lookup_type_ == DESCRIPTOR_TYPE); |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 426 | return PropertyIndex::NewFieldIndex(GetFieldIndexFromMap(holder()->map())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 427 | } |
| 428 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 429 | int GetLocalFieldIndexFromMap(Map* map) { |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 430 | return GetFieldIndexFromMap(map) - map->inobject_properties(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 431 | } |
| 432 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 433 | int GetDictionaryEntry() { |
| 434 | ASSERT(lookup_type_ == DICTIONARY_TYPE); |
| 435 | return number_; |
| 436 | } |
| 437 | |
| 438 | JSFunction* GetConstantFunction() { |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 439 | ASSERT(type() == CONSTANT); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 440 | return JSFunction::cast(GetValue()); |
| 441 | } |
| 442 | |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 443 | Object* GetConstantFromMap(Map* map) { |
| 444 | ASSERT(type() == CONSTANT); |
| 445 | return GetValueFromMap(map); |
| 446 | } |
| 447 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 448 | JSFunction* GetConstantFunctionFromMap(Map* map) { |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 449 | return JSFunction::cast(GetConstantFromMap(map)); |
| 450 | } |
| 451 | |
| 452 | Object* GetConstant() { |
| 453 | ASSERT(type() == CONSTANT); |
| 454 | return GetValue(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 455 | } |
| 456 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 457 | Object* GetCallbackObject() { |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 458 | ASSERT(type() == CALLBACKS && !IsTransition()); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 459 | return GetValue(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 460 | } |
| 461 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 462 | #ifdef OBJECT_PRINT |
| 463 | void Print(FILE* out); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 464 | #endif |
| 465 | |
| 466 | Object* GetValue() { |
| 467 | if (lookup_type_ == DESCRIPTOR_TYPE) { |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 468 | return GetValueFromMap(holder()->map()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 469 | } |
| 470 | // In the dictionary case, the data is held in the value field. |
| 471 | ASSERT(lookup_type_ == DICTIONARY_TYPE); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 472 | return holder()->GetNormalizedProperty(this); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 473 | } |
| 474 | |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 475 | Object* GetValueFromMap(Map* map) const { |
| 476 | ASSERT(lookup_type_ == DESCRIPTOR_TYPE); |
verwaest@chromium.org | 06ab2ec | 2012-10-09 17:00:13 +0000 | [diff] [blame] | 477 | ASSERT(number_ < map->NumberOfOwnDescriptors()); |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 478 | return map->instance_descriptors()->GetValue(number_); |
| 479 | } |
| 480 | |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 481 | int GetFieldIndexFromMap(Map* map) const { |
| 482 | ASSERT(lookup_type_ == DESCRIPTOR_TYPE); |
| 483 | ASSERT(number_ < map->NumberOfOwnDescriptors()); |
| 484 | return map->instance_descriptors()->GetFieldIndex(number_); |
| 485 | } |
| 486 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 487 | void Iterate(ObjectVisitor* visitor); |
| 488 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 489 | private: |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 490 | Isolate* isolate_; |
| 491 | LookupResult* next_; |
| 492 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 493 | // Where did we find the result; |
| 494 | enum { |
| 495 | NOT_FOUND, |
| 496 | DESCRIPTOR_TYPE, |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 497 | TRANSITION_TYPE, |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 498 | DICTIONARY_TYPE, |
| 499 | HANDLER_TYPE, |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 500 | INTERCEPTOR_TYPE |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 501 | } lookup_type_; |
| 502 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 503 | JSReceiver* holder_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 504 | int number_; |
| 505 | bool cacheable_; |
| 506 | PropertyDetails details_; |
| 507 | }; |
| 508 | |
| 509 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 510 | } } // namespace v8::internal |
| 511 | |
| 512 | #endif // V8_PROPERTY_H_ |