| 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 7307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10736 if (v) { | 10740 if (v) { |
| 10737 value |= (1 << bit_position); | 10741 value |= (1 << bit_position); |
| 10738 } else { | 10742 } else { |
| 10739 value &= ~(1 << bit_position); | 10743 value &= ~(1 << bit_position); |
| 10740 } | 10744 } |
| 10741 return value; | 10745 return value; |
| 10742 } | 10746 } |
| 10743 }; | 10747 }; |
| 10744 | 10748 |
| 10745 | 10749 |
| 10746 enum AddKeyConversion { DO_NOT_CONVERT, CONVERT_TO_ARRAY_INDEX, PROXY_MAGIC }; | |
| 10747 | |
| 10748 // 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 | |
| 10750 // 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 | |
| 10752 // sorted. | |
| 10753 // | |
| 10754 // For performance reasons the KeyAccumulator internally separates integer | |
| 10755 // keys in |elements_| into sorted lists per prototype level. String keys are | |
| 10756 // collected in |properties_|, a single OrderedHashSet. To separate the keys per | |
| 10757 // level later when assembling the final list, |levelLengths_| keeps track of | |
| 10758 // the total number of keys (integers + strings) per level. | |
| 10759 // | |
| 10760 // 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 | |
| 10762 // are more compact and allow for reasonably fast includes check. | |
| 10763 class KeyAccumulator final BASE_EMBEDDED { | |
| 10764 public: | |
| 10765 explicit KeyAccumulator(Isolate* isolate, | |
| 10766 KeyFilter filter = KeyFilter::SKIP_SYMBOLS) | |
| 10767 : isolate_(isolate), filter_(filter) {} | |
| 10768 ~KeyAccumulator(); | |
| 10769 | |
| 10770 bool AddKey(uint32_t key); | |
| 10771 bool AddKey(Object* key, AddKeyConversion convert = DO_NOT_CONVERT); | |
| 10772 bool AddKey(Handle<Object> key, AddKeyConversion convert = DO_NOT_CONVERT); | |
| 10773 void AddKeys(Handle<FixedArray> array, | |
| 10774 AddKeyConversion convert = DO_NOT_CONVERT); | |
| 10775 void AddKeys(Handle<JSObject> array, | |
| 10776 AddKeyConversion convert = DO_NOT_CONVERT); | |
| 10777 void AddKeysFromProxy(Handle<JSObject> array); | |
| 10778 void AddElementKeysFromInterceptor(Handle<JSObject> array); | |
| 10779 // Jump to the next level, pushing the current |levelLength_| to | |
| 10780 // |levelLengths_| and adding a new list to |elements_|. | |
| 10781 void NextPrototype(); | |
| 10782 // Sort the integer indices in the last list in |elements_| | |
| 10783 void SortCurrentElementsList(); | |
| 10784 void SortCurrentElementsListRemoveDuplicates(); | |
| 10785 Handle<FixedArray> GetKeys(GetKeysConversion convert = KEEP_NUMBERS); | |
| 10786 | |
| 10787 | |
| 10788 private: | |
| 10789 Isolate* isolate_; | |
| 10790 KeyFilter filter_; | |
| 10791 // |elements_| contains the sorted element keys (indices) per level. | |
| 10792 std::vector<std::vector<uint32_t>*> elements_; | |
| 10793 // |protoLengths_| contains the total number of keys (elements + properties) | |
| 10794 // per level. Negative values mark counts for a level with keys from a proxy. | |
| 10795 std::vector<int> levelLengths_; | |
| 10796 // |properties_| contains the property keys per level in insertion order. | |
| 10797 Handle<OrderedHashSet> properties_; | |
| 10798 // |length_| keeps track of the total number of all element and property keys. | |
| 10799 int length_ = 0; | |
| 10800 // |levelLength_| keeps track of the total number of keys | |
| 10801 // (elements + properties) in the current level. | |
| 10802 int levelLength_ = 0; | |
| 10803 | |
| 10804 DISALLOW_COPY_AND_ASSIGN(KeyAccumulator); | |
| 10805 }; | |
| 10806 | |
| 10807 } // NOLINT, false-positive due to second-order macros. | 10750 } // NOLINT, false-positive due to second-order macros. |
| 10808 } // NOLINT, false-positive due to second-order macros. | 10751 } // NOLINT, false-positive due to second-order macros. |
| 10809 | 10752 |
| 10810 #endif // V8_OBJECTS_H_ | 10753 #endif // V8_OBJECTS_H_ |
| OLD | NEW |