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