| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_PROPERTY_H_ | 5 #ifndef V8_PROPERTY_H_ |
| 6 #define V8_PROPERTY_H_ | 6 #define V8_PROPERTY_H_ |
| 7 | 7 |
| 8 #include "src/factory.h" | 8 #include "src/factory.h" |
| 9 #include "src/field-index.h" | 9 #include "src/field-index.h" |
| 10 #include "src/field-index-inl.h" | 10 #include "src/field-index-inl.h" |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 | 112 |
| 113 | 113 |
| 114 class LookupResult V8_FINAL BASE_EMBEDDED { | 114 class LookupResult V8_FINAL BASE_EMBEDDED { |
| 115 public: | 115 public: |
| 116 explicit LookupResult(Isolate* isolate) | 116 explicit LookupResult(Isolate* isolate) |
| 117 : isolate_(isolate), | 117 : isolate_(isolate), |
| 118 next_(isolate->top_lookup_result()), | 118 next_(isolate->top_lookup_result()), |
| 119 lookup_type_(NOT_FOUND), | 119 lookup_type_(NOT_FOUND), |
| 120 holder_(NULL), | 120 holder_(NULL), |
| 121 transition_(NULL), | 121 transition_(NULL), |
| 122 cacheable_(true), | |
| 123 details_(NONE, NORMAL, Representation::None()) { | 122 details_(NONE, NORMAL, Representation::None()) { |
| 124 isolate->set_top_lookup_result(this); | 123 isolate->set_top_lookup_result(this); |
| 125 } | 124 } |
| 126 | 125 |
| 127 ~LookupResult() { | 126 ~LookupResult() { |
| 128 DCHECK(isolate()->top_lookup_result() == this); | 127 DCHECK(isolate()->top_lookup_result() == this); |
| 129 isolate()->set_top_lookup_result(next_); | 128 isolate()->set_top_lookup_result(next_); |
| 130 } | 129 } |
| 131 | 130 |
| 132 Isolate* isolate() const { return isolate_; } | 131 Isolate* isolate() const { return isolate_; } |
| 133 | 132 |
| 134 void DescriptorResult(JSObject* holder, PropertyDetails details, int number) { | 133 void DescriptorResult(JSObject* holder, PropertyDetails details, int number) { |
| 135 lookup_type_ = DESCRIPTOR_TYPE; | 134 lookup_type_ = DESCRIPTOR_TYPE; |
| 136 holder_ = holder; | 135 holder_ = holder; |
| 137 transition_ = NULL; | 136 transition_ = NULL; |
| 138 details_ = details; | 137 details_ = details; |
| 139 number_ = number; | 138 number_ = number; |
| 140 } | 139 } |
| 141 | 140 |
| 142 bool CanHoldValue(Handle<Object> value) const { | |
| 143 switch (type()) { | |
| 144 case NORMAL: | |
| 145 return true; | |
| 146 case FIELD: | |
| 147 return value->FitsRepresentation(representation()) && | |
| 148 GetFieldType()->NowContains(value); | |
| 149 case CONSTANT: { | |
| 150 Map* map = | |
| 151 lookup_type_ == DESCRIPTOR_TYPE ? holder_->map() : transition_; | |
| 152 Object* constant = GetConstantFromMap(map); | |
| 153 DCHECK(constant != *value || | |
| 154 value->FitsRepresentation(representation())); | |
| 155 return constant == *value; | |
| 156 } | |
| 157 case CALLBACKS: | |
| 158 case HANDLER: | |
| 159 case INTERCEPTOR: | |
| 160 return true; | |
| 161 } | |
| 162 UNREACHABLE(); | |
| 163 return true; | |
| 164 } | |
| 165 | |
| 166 void TransitionResult(JSObject* holder, Map* target) { | 141 void TransitionResult(JSObject* holder, Map* target) { |
| 167 lookup_type_ = TRANSITION_TYPE; | 142 lookup_type_ = TRANSITION_TYPE; |
| 168 number_ = target->LastAdded(); | 143 number_ = target->LastAdded(); |
| 169 details_ = target->instance_descriptors()->GetDetails(number_); | 144 details_ = target->instance_descriptors()->GetDetails(number_); |
| 170 holder_ = holder; | 145 holder_ = holder; |
| 171 transition_ = target; | 146 transition_ = target; |
| 172 } | 147 } |
| 173 | 148 |
| 174 void DictionaryResult(JSObject* holder, int entry) { | |
| 175 lookup_type_ = DICTIONARY_TYPE; | |
| 176 holder_ = holder; | |
| 177 transition_ = NULL; | |
| 178 details_ = holder->property_dictionary()->DetailsAt(entry); | |
| 179 number_ = entry; | |
| 180 } | |
| 181 | |
| 182 void HandlerResult(JSProxy* proxy) { | |
| 183 lookup_type_ = HANDLER_TYPE; | |
| 184 holder_ = proxy; | |
| 185 transition_ = NULL; | |
| 186 details_ = PropertyDetails(NONE, HANDLER, Representation::Tagged()); | |
| 187 cacheable_ = false; | |
| 188 } | |
| 189 | |
| 190 void InterceptorResult(JSObject* holder) { | |
| 191 lookup_type_ = INTERCEPTOR_TYPE; | |
| 192 holder_ = holder; | |
| 193 transition_ = NULL; | |
| 194 details_ = PropertyDetails(NONE, INTERCEPTOR, Representation::Tagged()); | |
| 195 } | |
| 196 | |
| 197 void NotFound() { | 149 void NotFound() { |
| 198 lookup_type_ = NOT_FOUND; | 150 lookup_type_ = NOT_FOUND; |
| 199 details_ = PropertyDetails(NONE, NORMAL, Representation::None()); | 151 details_ = PropertyDetails(NONE, NORMAL, Representation::None()); |
| 200 holder_ = NULL; | 152 holder_ = NULL; |
| 201 transition_ = NULL; | 153 transition_ = NULL; |
| 202 } | 154 } |
| 203 | 155 |
| 204 JSObject* holder() const { | |
| 205 DCHECK(IsFound()); | |
| 206 return JSObject::cast(holder_); | |
| 207 } | |
| 208 | |
| 209 JSProxy* proxy() const { | |
| 210 DCHECK(IsHandler()); | |
| 211 return JSProxy::cast(holder_); | |
| 212 } | |
| 213 | |
| 214 PropertyType type() const { | |
| 215 DCHECK(IsFound()); | |
| 216 return details_.type(); | |
| 217 } | |
| 218 | |
| 219 Representation representation() const { | 156 Representation representation() const { |
| 220 DCHECK(IsFound()); | 157 DCHECK(IsFound()); |
| 221 return details_.representation(); | 158 return details_.representation(); |
| 222 } | 159 } |
| 223 | 160 |
| 224 PropertyAttributes GetAttributes() const { | |
| 225 DCHECK(IsFound()); | |
| 226 return details_.attributes(); | |
| 227 } | |
| 228 | |
| 229 PropertyDetails GetPropertyDetails() const { | |
| 230 return details_; | |
| 231 } | |
| 232 | |
| 233 bool IsFastPropertyType() const { | |
| 234 DCHECK(IsFound()); | |
| 235 return IsTransition() || type() != NORMAL; | |
| 236 } | |
| 237 | |
| 238 // Property callbacks does not include transitions to callbacks. | 161 // Property callbacks does not include transitions to callbacks. |
| 239 bool IsPropertyCallbacks() const { | 162 bool IsPropertyCallbacks() const { |
| 240 DCHECK(!(details_.type() == CALLBACKS && !IsFound())); | 163 DCHECK(!(details_.type() == CALLBACKS && !IsFound())); |
| 241 return !IsTransition() && details_.type() == CALLBACKS; | 164 return !IsTransition() && details_.type() == CALLBACKS; |
| 242 } | 165 } |
| 243 | 166 |
| 244 bool IsReadOnly() const { | 167 bool IsReadOnly() const { |
| 245 DCHECK(IsFound()); | 168 DCHECK(IsFound()); |
| 246 return details_.IsReadOnly(); | 169 return details_.IsReadOnly(); |
| 247 } | 170 } |
| 248 | 171 |
| 249 bool IsField() const { | 172 bool IsField() const { |
| 250 DCHECK(!(details_.type() == FIELD && !IsFound())); | 173 DCHECK(!(details_.type() == FIELD && !IsFound())); |
| 251 return IsDescriptorOrDictionary() && type() == FIELD; | 174 return lookup_type_ == DESCRIPTOR_TYPE && details_.type() == FIELD; |
| 252 } | |
| 253 | |
| 254 bool IsNormal() const { | |
| 255 return IsFound() && IsDescriptorOrDictionary() && type() == NORMAL; | |
| 256 } | 175 } |
| 257 | 176 |
| 258 bool IsConstant() const { | 177 bool IsConstant() const { |
| 259 DCHECK(!(details_.type() == CONSTANT && !IsFound())); | 178 DCHECK(!(details_.type() == CONSTANT && !IsFound())); |
| 260 return IsDescriptorOrDictionary() && type() == CONSTANT; | 179 return lookup_type_ == DESCRIPTOR_TYPE && details_.type() == CONSTANT; |
| 261 } | 180 } |
| 262 | 181 |
| 263 bool IsConfigurable() const { return details_.IsConfigurable(); } | 182 bool IsConfigurable() const { return details_.IsConfigurable(); } |
| 264 bool IsDontEnum() const { return details_.IsDontEnum(); } | |
| 265 bool IsFound() const { return lookup_type_ != NOT_FOUND; } | 183 bool IsFound() const { return lookup_type_ != NOT_FOUND; } |
| 266 bool IsDescriptorOrDictionary() const { | |
| 267 return lookup_type_ == DESCRIPTOR_TYPE || lookup_type_ == DICTIONARY_TYPE; | |
| 268 } | |
| 269 bool IsTransition() const { return lookup_type_ == TRANSITION_TYPE; } | 184 bool IsTransition() const { return lookup_type_ == TRANSITION_TYPE; } |
| 270 bool IsHandler() const { return lookup_type_ == HANDLER_TYPE; } | |
| 271 bool IsInterceptor() const { return lookup_type_ == INTERCEPTOR_TYPE; } | |
| 272 | 185 |
| 273 // Is the result is a property excluding transitions and the null descriptor? | 186 // Is the result is a property excluding transitions and the null descriptor? |
| 274 bool IsProperty() const { | 187 bool IsProperty() const { |
| 275 return IsFound() && !IsTransition(); | 188 return IsFound() && !IsTransition(); |
| 276 } | 189 } |
| 277 | 190 |
| 278 bool IsCacheable() const { return cacheable_; } | |
| 279 void DisallowCaching() { cacheable_ = false; } | |
| 280 | |
| 281 Map* GetTransitionTarget() const { | 191 Map* GetTransitionTarget() const { |
| 282 DCHECK(IsTransition()); | 192 DCHECK(IsTransition()); |
| 283 return transition_; | 193 return transition_; |
| 284 } | 194 } |
| 285 | 195 |
| 286 bool IsTransitionToField() const { | 196 bool IsTransitionToField() const { |
| 287 return IsTransition() && details_.type() == FIELD; | 197 return IsTransition() && details_.type() == FIELD; |
| 288 } | 198 } |
| 289 | 199 |
| 290 bool IsTransitionToConstant() const { | |
| 291 return IsTransition() && details_.type() == CONSTANT; | |
| 292 } | |
| 293 | |
| 294 int GetDescriptorIndex() const { | |
| 295 DCHECK(lookup_type_ == DESCRIPTOR_TYPE); | |
| 296 return number_; | |
| 297 } | |
| 298 | |
| 299 FieldIndex GetFieldIndex() const { | |
| 300 DCHECK(lookup_type_ == DESCRIPTOR_TYPE || | |
| 301 lookup_type_ == TRANSITION_TYPE); | |
| 302 return FieldIndex::ForLookupResult(this); | |
| 303 } | |
| 304 | |
| 305 int GetLocalFieldIndexFromMap(Map* map) const { | 200 int GetLocalFieldIndexFromMap(Map* map) const { |
| 306 return GetFieldIndexFromMap(map) - map->inobject_properties(); | 201 return GetFieldIndexFromMap(map) - map->inobject_properties(); |
| 307 } | 202 } |
| 308 | 203 |
| 309 int GetDictionaryEntry() const { | |
| 310 DCHECK(lookup_type_ == DICTIONARY_TYPE); | |
| 311 return number_; | |
| 312 } | |
| 313 | |
| 314 Object* GetConstantFromMap(Map* map) const { | 204 Object* GetConstantFromMap(Map* map) const { |
| 315 DCHECK(type() == CONSTANT); | 205 DCHECK(details_.type() == CONSTANT); |
| 316 return GetValueFromMap(map); | 206 return GetValueFromMap(map); |
| 317 } | 207 } |
| 318 | 208 |
| 319 Object* GetValueFromMap(Map* map) const { | 209 Object* GetValueFromMap(Map* map) const { |
| 320 DCHECK(lookup_type_ == DESCRIPTOR_TYPE || | 210 DCHECK(lookup_type_ == DESCRIPTOR_TYPE || |
| 321 lookup_type_ == TRANSITION_TYPE); | 211 lookup_type_ == TRANSITION_TYPE); |
| 322 DCHECK(number_ < map->NumberOfOwnDescriptors()); | 212 DCHECK(number_ < map->NumberOfOwnDescriptors()); |
| 323 return map->instance_descriptors()->GetValue(number_); | 213 return map->instance_descriptors()->GetValue(number_); |
| 324 } | 214 } |
| 325 | 215 |
| 326 int GetFieldIndexFromMap(Map* map) const { | 216 int GetFieldIndexFromMap(Map* map) const { |
| 327 DCHECK(lookup_type_ == DESCRIPTOR_TYPE || | 217 DCHECK(lookup_type_ == DESCRIPTOR_TYPE || |
| 328 lookup_type_ == TRANSITION_TYPE); | 218 lookup_type_ == TRANSITION_TYPE); |
| 329 DCHECK(number_ < map->NumberOfOwnDescriptors()); | 219 DCHECK(number_ < map->NumberOfOwnDescriptors()); |
| 330 return map->instance_descriptors()->GetFieldIndex(number_); | 220 return map->instance_descriptors()->GetFieldIndex(number_); |
| 331 } | 221 } |
| 332 | 222 |
| 333 HeapType* GetFieldType() const { | |
| 334 DCHECK(type() == FIELD); | |
| 335 if (lookup_type_ == DESCRIPTOR_TYPE) { | |
| 336 return GetFieldTypeFromMap(holder()->map()); | |
| 337 } | |
| 338 DCHECK(lookup_type_ == TRANSITION_TYPE); | |
| 339 return GetFieldTypeFromMap(transition_); | |
| 340 } | |
| 341 | |
| 342 HeapType* GetFieldTypeFromMap(Map* map) const { | 223 HeapType* GetFieldTypeFromMap(Map* map) const { |
| 343 DCHECK(lookup_type_ == DESCRIPTOR_TYPE || | 224 DCHECK_NE(NOT_FOUND, lookup_type_); |
| 344 lookup_type_ == TRANSITION_TYPE); | |
| 345 DCHECK(number_ < map->NumberOfOwnDescriptors()); | 225 DCHECK(number_ < map->NumberOfOwnDescriptors()); |
| 346 return map->instance_descriptors()->GetFieldType(number_); | 226 return map->instance_descriptors()->GetFieldType(number_); |
| 347 } | 227 } |
| 348 | 228 |
| 349 Map* GetFieldOwner() const { | |
| 350 return GetFieldOwnerFromMap(holder()->map()); | |
| 351 } | |
| 352 | |
| 353 Map* GetFieldOwnerFromMap(Map* map) const { | 229 Map* GetFieldOwnerFromMap(Map* map) const { |
| 354 DCHECK(lookup_type_ == DESCRIPTOR_TYPE || | 230 DCHECK(lookup_type_ == DESCRIPTOR_TYPE || |
| 355 lookup_type_ == TRANSITION_TYPE); | 231 lookup_type_ == TRANSITION_TYPE); |
| 356 DCHECK(number_ < map->NumberOfOwnDescriptors()); | 232 DCHECK(number_ < map->NumberOfOwnDescriptors()); |
| 357 return map->FindFieldOwner(number_); | 233 return map->FindFieldOwner(number_); |
| 358 } | 234 } |
| 359 | 235 |
| 360 bool ReceiverIsHolder(Handle<Object> receiver) { | |
| 361 if (*receiver == holder()) return true; | |
| 362 if (lookup_type_ == TRANSITION_TYPE) return true; | |
| 363 return false; | |
| 364 } | |
| 365 | |
| 366 void Iterate(ObjectVisitor* visitor); | 236 void Iterate(ObjectVisitor* visitor); |
| 367 | 237 |
| 368 private: | 238 private: |
| 369 Isolate* isolate_; | 239 Isolate* isolate_; |
| 370 LookupResult* next_; | 240 LookupResult* next_; |
| 371 | 241 |
| 372 // Where did we find the result; | 242 // Where did we find the result; |
| 373 enum { | 243 enum { NOT_FOUND, DESCRIPTOR_TYPE, TRANSITION_TYPE } lookup_type_; |
| 374 NOT_FOUND, | |
| 375 DESCRIPTOR_TYPE, | |
| 376 TRANSITION_TYPE, | |
| 377 DICTIONARY_TYPE, | |
| 378 HANDLER_TYPE, | |
| 379 INTERCEPTOR_TYPE | |
| 380 } lookup_type_; | |
| 381 | 244 |
| 382 JSReceiver* holder_; | 245 JSReceiver* holder_; |
| 383 Map* transition_; | 246 Map* transition_; |
| 384 int number_; | 247 int number_; |
| 385 bool cacheable_; | |
| 386 PropertyDetails details_; | 248 PropertyDetails details_; |
| 387 }; | 249 }; |
| 388 | 250 |
| 389 | 251 |
| 390 OStream& operator<<(OStream& os, const LookupResult& r); | 252 OStream& operator<<(OStream& os, const LookupResult& r); |
| 391 } } // namespace v8::internal | 253 } } // namespace v8::internal |
| 392 | 254 |
| 393 #endif // V8_PROPERTY_H_ | 255 #endif // V8_PROPERTY_H_ |
| OLD | NEW |