OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 26 matching lines...) Expand all Loading... |
37 | 37 |
38 // Abstraction for elements in instance-descriptor arrays. | 38 // Abstraction for elements in instance-descriptor arrays. |
39 // | 39 // |
40 // Each descriptor has a key, property attributes, property type, | 40 // Each descriptor has a key, property attributes, property type, |
41 // property index (in the actual instance-descriptor array) and | 41 // property index (in the actual instance-descriptor array) and |
42 // optionally a piece of data. | 42 // optionally a piece of data. |
43 // | 43 // |
44 | 44 |
45 class Descriptor BASE_EMBEDDED { | 45 class Descriptor BASE_EMBEDDED { |
46 public: | 46 public: |
47 static int IndexFromValue(Object* value) { | |
48 return Smi::cast(value)->value(); | |
49 } | |
50 | |
51 MUST_USE_RESULT MaybeObject* KeyToUniqueName() { | 47 MUST_USE_RESULT MaybeObject* KeyToUniqueName() { |
52 if (!key_->IsUniqueName()) { | 48 if (!key_->IsUniqueName()) { |
53 MaybeObject* maybe_result = HEAP->InternalizeString(String::cast(key_)); | 49 MaybeObject* maybe_result = HEAP->InternalizeString(String::cast(key_)); |
54 if (!maybe_result->To(&key_)) return maybe_result; | 50 if (!maybe_result->To(&key_)) return maybe_result; |
55 } | 51 } |
56 return key_; | 52 return key_; |
57 } | 53 } |
58 | 54 |
59 Name* GetKey() { return key_; } | 55 Name* GetKey() { return key_; } |
60 Object* GetValue() { return value_; } | 56 Object* GetValue() { return value_; } |
(...skipping 21 matching lines...) Expand all Loading... |
82 | 78 |
83 Descriptor(Name* key, Object* value, PropertyDetails details) | 79 Descriptor(Name* key, Object* value, PropertyDetails details) |
84 : key_(key), | 80 : key_(key), |
85 value_(value), | 81 value_(value), |
86 details_(details) { } | 82 details_(details) { } |
87 | 83 |
88 Descriptor(Name* key, | 84 Descriptor(Name* key, |
89 Object* value, | 85 Object* value, |
90 PropertyAttributes attributes, | 86 PropertyAttributes attributes, |
91 PropertyType type, | 87 PropertyType type, |
92 Representation representation) | 88 Representation representation, |
| 89 int field_index = 0) |
93 : key_(key), | 90 : key_(key), |
94 value_(value), | 91 value_(value), |
95 details_(attributes, type, representation) { } | 92 details_(attributes, type, representation, field_index) { } |
96 | 93 |
97 friend class DescriptorArray; | 94 friend class DescriptorArray; |
98 }; | 95 }; |
99 | 96 |
100 | 97 |
101 class FieldDescriptor: public Descriptor { | 98 class FieldDescriptor: public Descriptor { |
102 public: | 99 public: |
103 FieldDescriptor(Name* key, | 100 FieldDescriptor(Name* key, |
104 int field_index, | 101 int field_index, |
105 PropertyAttributes attributes, | 102 PropertyAttributes attributes, |
106 Representation representation) | 103 Representation representation) |
107 : Descriptor(key, Smi::FromInt(field_index), attributes, | 104 : Descriptor(key, Smi::FromInt(0), attributes, |
108 FIELD, representation) {} | 105 FIELD, representation, field_index) {} |
109 }; | 106 }; |
110 | 107 |
111 | 108 |
112 class ConstantFunctionDescriptor: public Descriptor { | 109 class ConstantFunctionDescriptor: public Descriptor { |
113 public: | 110 public: |
114 ConstantFunctionDescriptor(Name* key, | 111 ConstantFunctionDescriptor(Name* key, |
115 JSFunction* function, | 112 JSFunction* function, |
116 PropertyAttributes attributes) | 113 PropertyAttributes attributes) |
117 : Descriptor(key, function, attributes, CONSTANT_FUNCTION, | 114 : Descriptor(key, function, attributes, CONSTANT_FUNCTION, |
118 Representation::Tagged()) {} | 115 Representation::Tagged()) {} |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 return details_.type() == NORMAL; | 301 return details_.type() == NORMAL; |
305 } | 302 } |
306 | 303 |
307 bool IsConstantFunction() { | 304 bool IsConstantFunction() { |
308 ASSERT(!(details_.type() == CONSTANT_FUNCTION && !IsFound())); | 305 ASSERT(!(details_.type() == CONSTANT_FUNCTION && !IsFound())); |
309 return details_.type() == CONSTANT_FUNCTION; | 306 return details_.type() == CONSTANT_FUNCTION; |
310 } | 307 } |
311 | 308 |
312 bool IsDontDelete() { return details_.IsDontDelete(); } | 309 bool IsDontDelete() { return details_.IsDontDelete(); } |
313 bool IsDontEnum() { return details_.IsDontEnum(); } | 310 bool IsDontEnum() { return details_.IsDontEnum(); } |
314 bool IsDeleted() { return details_.IsDeleted(); } | |
315 bool IsFound() { return lookup_type_ != NOT_FOUND; } | 311 bool IsFound() { return lookup_type_ != NOT_FOUND; } |
316 bool IsTransition() { return lookup_type_ == TRANSITION_TYPE; } | 312 bool IsTransition() { return lookup_type_ == TRANSITION_TYPE; } |
317 bool IsHandler() { return lookup_type_ == HANDLER_TYPE; } | 313 bool IsHandler() { return lookup_type_ == HANDLER_TYPE; } |
318 bool IsInterceptor() { return lookup_type_ == INTERCEPTOR_TYPE; } | 314 bool IsInterceptor() { return lookup_type_ == INTERCEPTOR_TYPE; } |
319 | 315 |
320 // Is the result is a property excluding transitions and the null descriptor? | 316 // Is the result is a property excluding transitions and the null descriptor? |
321 bool IsProperty() { | 317 bool IsProperty() { |
322 return IsFound() && !IsTransition(); | 318 return IsFound() && !IsTransition(); |
323 } | 319 } |
324 | 320 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 } | 406 } |
411 | 407 |
412 int GetDescriptorIndex() { | 408 int GetDescriptorIndex() { |
413 ASSERT(lookup_type_ == DESCRIPTOR_TYPE); | 409 ASSERT(lookup_type_ == DESCRIPTOR_TYPE); |
414 return number_; | 410 return number_; |
415 } | 411 } |
416 | 412 |
417 PropertyIndex GetFieldIndex() { | 413 PropertyIndex GetFieldIndex() { |
418 ASSERT(lookup_type_ == DESCRIPTOR_TYPE); | 414 ASSERT(lookup_type_ == DESCRIPTOR_TYPE); |
419 ASSERT(IsField()); | 415 ASSERT(IsField()); |
420 return PropertyIndex::NewFieldIndex( | 416 return PropertyIndex::NewFieldIndex(GetFieldIndexFromMap(holder()->map())); |
421 Descriptor::IndexFromValue(GetValue())); | |
422 } | 417 } |
423 | 418 |
424 int GetLocalFieldIndexFromMap(Map* map) { | 419 int GetLocalFieldIndexFromMap(Map* map) { |
425 ASSERT(IsField()); | 420 ASSERT(IsField()); |
426 return Descriptor::IndexFromValue(GetValueFromMap(map)) - | 421 return GetFieldIndexFromMap(map) - map->inobject_properties(); |
427 map->inobject_properties(); | |
428 } | 422 } |
429 | 423 |
430 int GetDictionaryEntry() { | 424 int GetDictionaryEntry() { |
431 ASSERT(lookup_type_ == DICTIONARY_TYPE); | 425 ASSERT(lookup_type_ == DICTIONARY_TYPE); |
432 return number_; | 426 return number_; |
433 } | 427 } |
434 | 428 |
435 JSFunction* GetConstantFunction() { | 429 JSFunction* GetConstantFunction() { |
436 ASSERT(type() == CONSTANT_FUNCTION); | 430 ASSERT(type() == CONSTANT_FUNCTION); |
437 return JSFunction::cast(GetValue()); | 431 return JSFunction::cast(GetValue()); |
(...skipping 21 matching lines...) Expand all Loading... |
459 ASSERT(lookup_type_ == DICTIONARY_TYPE); | 453 ASSERT(lookup_type_ == DICTIONARY_TYPE); |
460 return holder()->GetNormalizedProperty(this); | 454 return holder()->GetNormalizedProperty(this); |
461 } | 455 } |
462 | 456 |
463 Object* GetValueFromMap(Map* map) const { | 457 Object* GetValueFromMap(Map* map) const { |
464 ASSERT(lookup_type_ == DESCRIPTOR_TYPE); | 458 ASSERT(lookup_type_ == DESCRIPTOR_TYPE); |
465 ASSERT(number_ < map->NumberOfOwnDescriptors()); | 459 ASSERT(number_ < map->NumberOfOwnDescriptors()); |
466 return map->instance_descriptors()->GetValue(number_); | 460 return map->instance_descriptors()->GetValue(number_); |
467 } | 461 } |
468 | 462 |
| 463 int GetFieldIndexFromMap(Map* map) const { |
| 464 ASSERT(lookup_type_ == DESCRIPTOR_TYPE); |
| 465 ASSERT(number_ < map->NumberOfOwnDescriptors()); |
| 466 return map->instance_descriptors()->GetFieldIndex(number_); |
| 467 } |
| 468 |
469 void Iterate(ObjectVisitor* visitor); | 469 void Iterate(ObjectVisitor* visitor); |
470 | 470 |
471 private: | 471 private: |
472 Isolate* isolate_; | 472 Isolate* isolate_; |
473 LookupResult* next_; | 473 LookupResult* next_; |
474 | 474 |
475 // Where did we find the result; | 475 // Where did we find the result; |
476 enum { | 476 enum { |
477 NOT_FOUND, | 477 NOT_FOUND, |
478 DESCRIPTOR_TYPE, | 478 DESCRIPTOR_TYPE, |
479 TRANSITION_TYPE, | 479 TRANSITION_TYPE, |
480 DICTIONARY_TYPE, | 480 DICTIONARY_TYPE, |
481 HANDLER_TYPE, | 481 HANDLER_TYPE, |
482 INTERCEPTOR_TYPE | 482 INTERCEPTOR_TYPE |
483 } lookup_type_; | 483 } lookup_type_; |
484 | 484 |
485 JSReceiver* holder_; | 485 JSReceiver* holder_; |
486 int number_; | 486 int number_; |
487 bool cacheable_; | 487 bool cacheable_; |
488 PropertyDetails details_; | 488 PropertyDetails details_; |
489 }; | 489 }; |
490 | 490 |
491 | 491 |
492 } } // namespace v8::internal | 492 } } // namespace v8::internal |
493 | 493 |
494 #endif // V8_PROPERTY_H_ | 494 #endif // V8_PROPERTY_H_ |
OLD | NEW |