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 2249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2260 inline void SetInternalField(int index, Object* value); | 2260 inline void SetInternalField(int index, Object* value); |
2261 inline void SetInternalField(int index, Smi* value); | 2261 inline void SetInternalField(int index, Smi* value); |
2262 | 2262 |
2263 // Returns the number of properties on this object filtering out properties | 2263 // Returns the number of properties on this object filtering out properties |
2264 // with the specified attributes (ignoring interceptors). | 2264 // with the specified attributes (ignoring interceptors). |
2265 int NumberOfOwnProperties(PropertyAttributes filter = NONE); | 2265 int NumberOfOwnProperties(PropertyAttributes filter = NONE); |
2266 // Fill in details for properties into storage starting at the specified | 2266 // Fill in details for properties into storage starting at the specified |
2267 // index. Returns the number of properties added. | 2267 // index. Returns the number of properties added. |
2268 int GetOwnPropertyNames(FixedArray* storage, int index, | 2268 int GetOwnPropertyNames(FixedArray* storage, int index, |
2269 PropertyAttributes filter = NONE); | 2269 PropertyAttributes filter = NONE); |
2270 int CollectOwnPropertyNames(KeyAccumulator* keys, | |
2271 PropertyAttributes filter = NONE); | |
2270 | 2272 |
2271 // Returns the number of properties on this object filtering out properties | 2273 // Returns the number of properties on this object filtering out properties |
2272 // with the specified attributes (ignoring interceptors). | 2274 // with the specified attributes (ignoring interceptors). |
2273 int NumberOfOwnElements(PropertyAttributes filter); | 2275 int NumberOfOwnElements(PropertyAttributes filter); |
2274 // Returns the number of enumerable elements (ignoring interceptors). | 2276 // Returns the number of enumerable elements (ignoring interceptors). |
2275 int NumberOfEnumElements(); | 2277 int NumberOfEnumElements(); |
2276 // Returns the number of elements on this object filtering out elements | 2278 // Returns the number of elements on this object filtering out elements |
2277 // with the specified attributes (ignoring interceptors). | 2279 // with the specified attributes (ignoring interceptors). |
2278 int GetOwnElementKeys(FixedArray* storage, PropertyAttributes filter); | 2280 int GetOwnElementKeys(FixedArray* storage, PropertyAttributes filter); |
2279 static void CollectOwnElementKeys(Handle<JSObject> object, | 2281 static void CollectOwnElementKeys(Handle<JSObject> object, |
(...skipping 1129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3409 // Returns true if the dictionary contains any elements that are non-writable, | 3411 // Returns true if the dictionary contains any elements that are non-writable, |
3410 // non-configurable, non-enumerable, or have getters/setters. | 3412 // non-configurable, non-enumerable, or have getters/setters. |
3411 bool HasComplexElements(); | 3413 bool HasComplexElements(); |
3412 | 3414 |
3413 enum SortMode { UNSORTED, SORTED }; | 3415 enum SortMode { UNSORTED, SORTED }; |
3414 | 3416 |
3415 // Fill in details for properties into storage. | 3417 // Fill in details for properties into storage. |
3416 // Returns the number of properties added. | 3418 // Returns the number of properties added. |
3417 int CopyKeysTo(FixedArray* storage, int index, PropertyAttributes filter, | 3419 int CopyKeysTo(FixedArray* storage, int index, PropertyAttributes filter, |
3418 SortMode sort_mode); | 3420 SortMode sort_mode); |
3421 // Collect the unsorted keys into the given KeyAccumulator. | |
3422 int CollectKeysTo(KeyAccumulator* keys, PropertyAttributes filter); | |
3419 | 3423 |
3420 // Copies enumerable keys to preallocated fixed array. | 3424 // Copies enumerable keys to preallocated fixed array. |
3421 void CopyEnumKeysTo(FixedArray* storage); | 3425 void CopyEnumKeysTo(FixedArray* storage); |
3422 | 3426 |
3423 // Accessors for next enumeration index. | 3427 // Accessors for next enumeration index. |
3424 void SetNextEnumerationIndex(int index) { | 3428 void SetNextEnumerationIndex(int index) { |
3425 DCHECK(index != 0); | 3429 DCHECK(index != 0); |
3426 this->set(kNextEnumerationIndexIndex, Smi::FromInt(index)); | 3430 this->set(kNextEnumerationIndexIndex, Smi::FromInt(index)); |
3427 } | 3431 } |
3428 | 3432 |
(...skipping 7317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
10746 enum AddKeyConversion { DO_NOT_CONVERT, CONVERT_TO_ARRAY_INDEX, PROXY_MAGIC }; | 10750 enum AddKeyConversion { DO_NOT_CONVERT, CONVERT_TO_ARRAY_INDEX, PROXY_MAGIC }; |
10747 | 10751 |
10748 // This is a helper class for JSReceiver::GetKeys which collects and sorts keys. | 10752 // This is a helper class for JSReceiver::GetKeys which collects and sorts keys. |
10749 // GetKeys needs to sort keys per prototype level, first showing the integer | 10753 // GetKeys needs to sort keys per prototype level, first showing the integer |
10750 // indices from elements then the strings from the properties. However, this | 10754 // indices from elements then the strings from the properties. However, this |
10751 // does not apply to proxies which are in full control of how the keys are | 10755 // does not apply to proxies which are in full control of how the keys are |
10752 // sorted. | 10756 // sorted. |
10753 // | 10757 // |
10754 // For performance reasons the KeyAccumulator internally separates integer | 10758 // For performance reasons the KeyAccumulator internally separates integer |
10755 // keys in |elements_| into sorted lists per prototype level. String keys are | 10759 // keys in |elements_| into sorted lists per prototype level. String keys are |
10756 // collected in |properties_|, a single OrderedHashSet. To separate the keys per | 10760 // collected in |properties_|, a single OrderedHashSet. To separate the keys per |
Jakob Kummerow
2015/11/03 15:33:37
nit: outdated comment
| |
10757 // level later when assembling the final list, |levelLengths_| keeps track of | 10761 // level later when assembling the final list, |levelLengths_| keeps track of |
10758 // the total number of keys (integers + strings) per level. | 10762 // the total number of keys (integers + strings) per level. |
10759 // | 10763 // |
10760 // Only unique keys are kept by the KeyAccumulator, strings are stored in a | 10764 // Only unique keys are kept by the KeyAccumulator, strings are stored in a |
10761 // HashSet for inexpensive lookups. Integer keys are kept in sorted lists which | 10765 // HashSet for inexpensive lookups. Integer keys are kept in sorted lists which |
10762 // are more compact and allow for reasonably fast includes check. | 10766 // are more compact and allow for reasonably fast includes check. |
10763 class KeyAccumulator final BASE_EMBEDDED { | 10767 class KeyAccumulator final BASE_EMBEDDED { |
10764 public: | 10768 public: |
10765 explicit KeyAccumulator(Isolate* isolate, | 10769 explicit KeyAccumulator(Isolate* isolate, |
10766 KeyFilter filter = KeyFilter::SKIP_SYMBOLS) | 10770 KeyFilter filter = KeyFilter::SKIP_SYMBOLS) |
10767 : isolate_(isolate), filter_(filter) {} | 10771 : isolate_(isolate), filter_(filter) {} |
10768 ~KeyAccumulator(); | 10772 ~KeyAccumulator(); |
10769 | 10773 |
10770 bool AddKey(uint32_t key); | 10774 bool AddKey(uint32_t key); |
Jakob Kummerow
2015/11/03 15:39:59
nit: most of these methods can probably be private
| |
10771 bool AddKey(Object* key, AddKeyConversion convert = DO_NOT_CONVERT); | 10775 bool AddKey(Object* key, AddKeyConversion convert = DO_NOT_CONVERT); |
10772 bool AddKey(Handle<Object> key, AddKeyConversion convert = DO_NOT_CONVERT); | 10776 bool AddKey(Handle<Object> key, AddKeyConversion convert = DO_NOT_CONVERT); |
10777 bool AddStringKey(Handle<Object> key, AddKeyConversion convert); | |
10778 bool AddSymbolKey(Handle<Object> array); | |
10773 void AddKeys(Handle<FixedArray> array, | 10779 void AddKeys(Handle<FixedArray> array, |
10774 AddKeyConversion convert = DO_NOT_CONVERT); | 10780 AddKeyConversion convert = DO_NOT_CONVERT); |
10775 void AddKeys(Handle<JSObject> array, | 10781 void AddKeys(Handle<JSObject> array, |
10776 AddKeyConversion convert = DO_NOT_CONVERT); | 10782 AddKeyConversion convert = DO_NOT_CONVERT); |
10777 void AddKeysFromProxy(Handle<JSObject> array); | 10783 void AddKeysFromProxy(Handle<JSObject> array); |
10778 void AddElementKeysFromInterceptor(Handle<JSObject> array); | 10784 void AddElementKeysFromInterceptor(Handle<JSObject> array); |
10779 // Jump to the next level, pushing the current |levelLength_| to | 10785 // Jump to the next level, pushing the current |levelLength_| to |
Jakob Kummerow
2015/11/03 15:33:37
nit: s/levelLength_/level_lengths_/.
I count six
| |
10780 // |levelLengths_| and adding a new list to |elements_|. | 10786 // |levelLengths_| and adding a new list to |elements_|. |
10781 void NextPrototype(); | 10787 void NextPrototype(); |
10782 // Sort the integer indices in the last list in |elements_| | 10788 // Sort the integer indices in the last list in |elements_| |
10783 void SortCurrentElementsList(); | 10789 void SortCurrentElementsList(); |
10784 void SortCurrentElementsListRemoveDuplicates(); | 10790 void SortCurrentElementsListRemoveDuplicates(); |
10785 Handle<FixedArray> GetKeys(GetKeysConversion convert = KEEP_NUMBERS); | 10791 Handle<FixedArray> GetKeys(GetKeysConversion convert = KEEP_NUMBERS); |
10792 int GetLength(); | |
10786 | 10793 |
Jakob Kummerow
2015/11/03 15:33:37
nit: one empty line is enough
| |
10787 | 10794 |
10788 private: | 10795 private: |
10789 Isolate* isolate_; | 10796 Isolate* isolate_; |
10790 KeyFilter filter_; | 10797 KeyFilter filter_; |
10791 // |elements_| contains the sorted element keys (indices) per level. | 10798 // |elements_| contains the sorted element keys (indices) per level. |
10792 std::vector<std::vector<uint32_t>*> elements_; | 10799 std::vector<std::vector<uint32_t>*> elements_; |
10793 // |protoLengths_| contains the total number of keys (elements + properties) | 10800 // |protoLengths_| contains the total number of keys (elements + properties) |
10794 // per level. Negative values mark counts for a level with keys from a proxy. | 10801 // per level. Negative values mark counts for a level with keys from a proxy. |
10795 std::vector<int> levelLengths_; | 10802 std::vector<int> level_lengths_; |
10796 // |properties_| contains the property keys per level in insertion order. | 10803 // |properties_| contains the property keys per level in insertion order. |
10797 Handle<OrderedHashSet> properties_; | 10804 Handle<OrderedHashSet> string_properties_; |
10805 // |properties_| contains the symbol property keys per level in | |
10806 // insertion order. | |
10807 Handle<OrderedHashSet> symbol_properties_; | |
10798 // |length_| keeps track of the total number of all element and property keys. | 10808 // |length_| keeps track of the total number of all element and property keys. |
10799 int length_ = 0; | 10809 int length_ = 0; |
10800 // |levelLength_| keeps track of the total number of keys | 10810 // |levelLength_| keeps track of the total number of keys |
10801 // (elements + properties) in the current level. | 10811 // (elements + properties) in the current level. |
10802 int levelLength_ = 0; | 10812 int level_string_length_ = 0; |
10813 // |levelSymbolLength_| keeps track of the total number of symbol keys | |
10814 // (elements + properties) in the current level. | |
10815 int level_symbol_length_ = 0; | |
10803 | 10816 |
10804 DISALLOW_COPY_AND_ASSIGN(KeyAccumulator); | 10817 DISALLOW_COPY_AND_ASSIGN(KeyAccumulator); |
10805 }; | 10818 }; |
10806 | 10819 |
10807 } // NOLINT, false-positive due to second-order macros. | 10820 } // NOLINT, false-positive due to second-order macros. |
10808 } // NOLINT, false-positive due to second-order macros. | 10821 } // NOLINT, false-positive due to second-order macros. |
10809 | 10822 |
10810 #endif // V8_OBJECTS_H_ | 10823 #endif // V8_OBJECTS_H_ |
OLD | NEW |