OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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_OBJECTS_H_ | 5 #ifndef V8_OBJECTS_H_ |
6 #define V8_OBJECTS_H_ | 6 #define V8_OBJECTS_H_ |
7 | 7 |
8 #include <iosfwd> | 8 #include <iosfwd> |
9 | 9 |
10 #include "src/allocation.h" | 10 #include "src/allocation.h" |
(...skipping 3509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3520 DECLARE_CAST(StringTable) | 3520 DECLARE_CAST(StringTable) |
3521 | 3521 |
3522 private: | 3522 private: |
3523 template <bool seq_one_byte> | 3523 template <bool seq_one_byte> |
3524 friend class JsonParser; | 3524 friend class JsonParser; |
3525 | 3525 |
3526 DISALLOW_IMPLICIT_CONSTRUCTORS(StringTable); | 3526 DISALLOW_IMPLICIT_CONSTRUCTORS(StringTable); |
3527 }; | 3527 }; |
3528 | 3528 |
3529 | 3529 |
| 3530 enum class DictionaryEntryType { kObjects, kCells }; |
| 3531 |
| 3532 |
3530 template <typename Derived, typename Shape, typename Key> | 3533 template <typename Derived, typename Shape, typename Key> |
3531 class Dictionary: public HashTable<Derived, Shape, Key> { | 3534 class Dictionary: public HashTable<Derived, Shape, Key> { |
3532 protected: | 3535 protected: |
3533 typedef HashTable<Derived, Shape, Key> DerivedHashTable; | 3536 typedef HashTable<Derived, Shape, Key> DerivedHashTable; |
3534 | 3537 |
3535 public: | 3538 public: |
3536 // Returns the value at entry. | 3539 // Returns the value at entry. |
3537 Object* ValueAt(int entry) { | 3540 Object* ValueAt(int entry) { |
3538 return this->get(DerivedHashTable::EntryToIndex(entry) + 1); | 3541 return this->get(DerivedHashTable::EntryToIndex(entry) + 1); |
3539 } | 3542 } |
3540 | 3543 |
3541 // Set the value for entry. | 3544 // Set the value for entry. |
3542 void ValueAtPut(int entry, Object* value) { | 3545 void ValueAtPut(int entry, Object* value) { |
3543 this->set(DerivedHashTable::EntryToIndex(entry) + 1, value); | 3546 this->set(DerivedHashTable::EntryToIndex(entry) + 1, value); |
3544 } | 3547 } |
3545 | 3548 |
3546 // Returns the property details for the property at entry. | 3549 // Returns the property details for the property at entry. |
3547 PropertyDetails DetailsAt(int entry) { | 3550 PropertyDetails DetailsAt(int entry) { |
3548 DCHECK(entry >= 0); // Not found is -1, which is not caught by get(). | 3551 DCHECK(entry >= 0); // Not found is -1, which is not caught by get(). |
3549 return PropertyDetails( | 3552 return PropertyDetails( |
3550 Smi::cast(this->get(DerivedHashTable::EntryToIndex(entry) + 2))); | 3553 Smi::cast(this->get(DerivedHashTable::EntryToIndex(entry) + 2))); |
3551 } | 3554 } |
3552 | 3555 |
3553 // Set the details for entry. | 3556 // Set the details for entry. |
3554 void DetailsAtPut(int entry, PropertyDetails value) { | 3557 void DetailsAtPut(int entry, PropertyDetails value) { |
3555 this->set(DerivedHashTable::EntryToIndex(entry) + 2, value.AsSmi()); | 3558 this->set(DerivedHashTable::EntryToIndex(entry) + 2, value.AsSmi()); |
3556 } | 3559 } |
3557 | 3560 |
3558 // Sorting support | |
3559 void CopyValuesTo(FixedArray* elements); | |
3560 | |
3561 // Delete a property from the dictionary. | 3561 // Delete a property from the dictionary. |
3562 static Handle<Object> DeleteProperty(Handle<Derived> dictionary, int entry); | 3562 static Handle<Object> DeleteProperty(Handle<Derived> dictionary, int entry); |
3563 | 3563 |
3564 // Attempt to shrink the dictionary after deletion of key. | 3564 // Attempt to shrink the dictionary after deletion of key. |
3565 MUST_USE_RESULT static inline Handle<Derived> Shrink( | 3565 MUST_USE_RESULT static inline Handle<Derived> Shrink( |
3566 Handle<Derived> dictionary, | 3566 Handle<Derived> dictionary, |
3567 Key key) { | 3567 Key key) { |
3568 return DerivedHashTable::Shrink(dictionary, key); | 3568 return DerivedHashTable::Shrink(dictionary, key); |
3569 } | 3569 } |
3570 | 3570 |
| 3571 // Sorting support |
| 3572 // TODO(dcarney): templatize or move to SeededNumberDictionary |
| 3573 void CopyValuesTo(FixedArray* elements); |
| 3574 |
3571 // Returns the number of elements in the dictionary filtering out properties | 3575 // Returns the number of elements in the dictionary filtering out properties |
3572 // with the specified attributes. | 3576 // with the specified attributes. |
| 3577 template <DictionaryEntryType type> |
3573 int NumberOfElementsFilterAttributes(PropertyAttributes filter); | 3578 int NumberOfElementsFilterAttributes(PropertyAttributes filter); |
| 3579 int NumberOfElementsFilterAttributes(Object* holder, |
| 3580 PropertyAttributes filter) { |
| 3581 if (holder->IsGlobalObject()) { |
| 3582 return NumberOfElementsFilterAttributes<DictionaryEntryType::kCells>( |
| 3583 filter); |
| 3584 } else { |
| 3585 return NumberOfElementsFilterAttributes<DictionaryEntryType::kObjects>( |
| 3586 filter); |
| 3587 } |
| 3588 } |
3574 | 3589 |
3575 // Returns the number of enumerable elements in the dictionary. | 3590 // Returns the number of enumerable elements in the dictionary. |
3576 int NumberOfEnumElements(); | 3591 template <DictionaryEntryType type> |
| 3592 int NumberOfEnumElements() { |
| 3593 return NumberOfElementsFilterAttributes<type>( |
| 3594 static_cast<PropertyAttributes>(DONT_ENUM | SYMBOLIC)); |
| 3595 } |
| 3596 int NumberOfEnumElements(Object* holder) { |
| 3597 if (holder->IsGlobalObject()) { |
| 3598 return NumberOfEnumElements<DictionaryEntryType::kCells>(); |
| 3599 } else { |
| 3600 return NumberOfEnumElements<DictionaryEntryType::kObjects>(); |
| 3601 } |
| 3602 } |
3577 | 3603 |
3578 // Returns true if the dictionary contains any elements that are non-writable, | 3604 // Returns true if the dictionary contains any elements that are non-writable, |
3579 // non-configurable, non-enumerable, or have getters/setters. | 3605 // non-configurable, non-enumerable, or have getters/setters. |
| 3606 template <DictionaryEntryType type> |
3580 bool HasComplexElements(); | 3607 bool HasComplexElements(); |
| 3608 bool HasComplexElements(Object* holder) { |
| 3609 if (holder->IsGlobalObject()) { |
| 3610 return HasComplexElements<DictionaryEntryType::kCells>(); |
| 3611 } else { |
| 3612 return HasComplexElements<DictionaryEntryType::kObjects>(); |
| 3613 } |
| 3614 } |
3581 | 3615 |
3582 enum SortMode { UNSORTED, SORTED }; | 3616 enum SortMode { UNSORTED, SORTED }; |
| 3617 |
3583 // Copies keys to preallocated fixed array. | 3618 // Copies keys to preallocated fixed array. |
3584 void CopyKeysTo(FixedArray* storage, | 3619 template <DictionaryEntryType type> |
3585 PropertyAttributes filter, | 3620 void CopyKeysTo(FixedArray* storage, PropertyAttributes filter, |
3586 SortMode sort_mode); | 3621 SortMode sort_mode); |
| 3622 void CopyKeysTo(Object* holder, FixedArray* storage, |
| 3623 PropertyAttributes filter, SortMode sort_mode) { |
| 3624 if (holder->IsGlobalObject()) { |
| 3625 return CopyKeysTo<DictionaryEntryType::kCells>(storage, filter, |
| 3626 sort_mode); |
| 3627 } else { |
| 3628 return CopyKeysTo<DictionaryEntryType::kObjects>(storage, filter, |
| 3629 sort_mode); |
| 3630 } |
| 3631 } |
| 3632 |
3587 // Fill in details for properties into storage. | 3633 // Fill in details for properties into storage. |
3588 void CopyKeysTo(FixedArray* storage, | 3634 template <DictionaryEntryType type> |
3589 int index, | 3635 void CopyKeysTo(FixedArray* storage, int index, PropertyAttributes filter, |
3590 PropertyAttributes filter, | |
3591 SortMode sort_mode); | 3636 SortMode sort_mode); |
| 3637 void CopyKeysTo(Object* holder, FixedArray* storage, int index, |
| 3638 PropertyAttributes filter, SortMode sort_mode) { |
| 3639 if (holder->IsGlobalObject()) { |
| 3640 return CopyKeysTo<DictionaryEntryType::kCells>(storage, index, filter, |
| 3641 sort_mode); |
| 3642 } else { |
| 3643 return CopyKeysTo<DictionaryEntryType::kObjects>(storage, index, filter, |
| 3644 sort_mode); |
| 3645 } |
| 3646 } |
3592 | 3647 |
3593 // Accessors for next enumeration index. | 3648 // Accessors for next enumeration index. |
3594 void SetNextEnumerationIndex(int index) { | 3649 void SetNextEnumerationIndex(int index) { |
3595 DCHECK(index != 0); | 3650 DCHECK(index != 0); |
3596 this->set(kNextEnumerationIndexIndex, Smi::FromInt(index)); | 3651 this->set(kNextEnumerationIndexIndex, Smi::FromInt(index)); |
3597 } | 3652 } |
3598 | 3653 |
3599 int NextEnumerationIndex() { | 3654 int NextEnumerationIndex() { |
3600 return Smi::cast(this->get(kNextEnumerationIndexIndex))->value(); | 3655 return Smi::cast(this->get(kNextEnumerationIndexIndex))->value(); |
3601 } | 3656 } |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3674 class NameDictionary: public Dictionary<NameDictionary, | 3729 class NameDictionary: public Dictionary<NameDictionary, |
3675 NameDictionaryShape, | 3730 NameDictionaryShape, |
3676 Handle<Name> > { | 3731 Handle<Name> > { |
3677 typedef Dictionary< | 3732 typedef Dictionary< |
3678 NameDictionary, NameDictionaryShape, Handle<Name> > DerivedDictionary; | 3733 NameDictionary, NameDictionaryShape, Handle<Name> > DerivedDictionary; |
3679 | 3734 |
3680 public: | 3735 public: |
3681 DECLARE_CAST(NameDictionary) | 3736 DECLARE_CAST(NameDictionary) |
3682 | 3737 |
3683 // Copies enumerable keys to preallocated fixed array. | 3738 // Copies enumerable keys to preallocated fixed array. |
| 3739 template <DictionaryEntryType type> |
3684 void CopyEnumKeysTo(FixedArray* storage); | 3740 void CopyEnumKeysTo(FixedArray* storage); |
| 3741 void CopyEnumKeysTo(Object* holder, FixedArray* storage) { |
| 3742 if (holder->IsGlobalObject()) { |
| 3743 return CopyEnumKeysTo<DictionaryEntryType::kCells>(storage); |
| 3744 } else { |
| 3745 return CopyEnumKeysTo<DictionaryEntryType::kObjects>(storage); |
| 3746 } |
| 3747 } |
| 3748 |
3685 inline static Handle<FixedArray> DoGenerateNewEnumerationIndices( | 3749 inline static Handle<FixedArray> DoGenerateNewEnumerationIndices( |
3686 Handle<NameDictionary> dictionary); | 3750 Handle<NameDictionary> dictionary); |
3687 | 3751 |
3688 // Find entry for key, otherwise return kNotFound. Optimized version of | 3752 // Find entry for key, otherwise return kNotFound. Optimized version of |
3689 // HashTable::FindEntry. | 3753 // HashTable::FindEntry. |
3690 int FindEntry(Handle<Name> key); | 3754 int FindEntry(Handle<Name> key); |
3691 }; | 3755 }; |
3692 | 3756 |
3693 | 3757 |
3694 class NumberDictionaryShape : public BaseShape<uint32_t> { | 3758 class NumberDictionaryShape : public BaseShape<uint32_t> { |
(...skipping 7236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10931 } else { | 10995 } else { |
10932 value &= ~(1 << bit_position); | 10996 value &= ~(1 << bit_position); |
10933 } | 10997 } |
10934 return value; | 10998 return value; |
10935 } | 10999 } |
10936 }; | 11000 }; |
10937 | 11001 |
10938 } } // namespace v8::internal | 11002 } } // namespace v8::internal |
10939 | 11003 |
10940 #endif // V8_OBJECTS_H_ | 11004 #endif // V8_OBJECTS_H_ |
OLD | NEW |