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 836 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
847 class AllocationSite; | 847 class AllocationSite; |
848 class AllocationSiteCreationContext; | 848 class AllocationSiteCreationContext; |
849 class AllocationSiteUsageContext; | 849 class AllocationSiteUsageContext; |
850 class Cell; | 850 class Cell; |
851 class ConsString; | 851 class ConsString; |
852 class ElementsAccessor; | 852 class ElementsAccessor; |
853 class FixedArrayBase; | 853 class FixedArrayBase; |
854 class FunctionLiteral; | 854 class FunctionLiteral; |
855 class GlobalObject; | 855 class GlobalObject; |
856 class JSBuiltinsObject; | 856 class JSBuiltinsObject; |
| 857 class KeyAccumulator; |
857 class LayoutDescriptor; | 858 class LayoutDescriptor; |
858 class LiteralsArray; | 859 class LiteralsArray; |
859 class LookupIterator; | 860 class LookupIterator; |
860 class ObjectHashTable; | 861 class ObjectHashTable; |
861 class ObjectVisitor; | 862 class ObjectVisitor; |
862 class PropertyCell; | 863 class PropertyCell; |
863 class PropertyDescriptor; | 864 class PropertyDescriptor; |
864 class SafepointEntry; | 865 class SafepointEntry; |
865 class SharedFunctionInfo; | 866 class SharedFunctionInfo; |
866 class StringStream; | 867 class StringStream; |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1082 | 1083 |
1083 inline ElementsKind OptimalElementsKind(); | 1084 inline ElementsKind OptimalElementsKind(); |
1084 | 1085 |
1085 inline bool FitsRepresentation(Representation representation); | 1086 inline bool FitsRepresentation(Representation representation); |
1086 | 1087 |
1087 // Checks whether two valid primitive encodings of a property name resolve to | 1088 // Checks whether two valid primitive encodings of a property name resolve to |
1088 // the same logical property. E.g., the smi 1, the string "1" and the double | 1089 // the same logical property. E.g., the smi 1, the string "1" and the double |
1089 // 1 all refer to the same property, so this helper will return true. | 1090 // 1 all refer to the same property, so this helper will return true. |
1090 inline bool KeyEquals(Object* other); | 1091 inline bool KeyEquals(Object* other); |
1091 | 1092 |
| 1093 inline bool FilterKey(PropertyAttributes filter); |
| 1094 |
1092 Handle<HeapType> OptimalType(Isolate* isolate, Representation representation); | 1095 Handle<HeapType> OptimalType(Isolate* isolate, Representation representation); |
1093 | 1096 |
1094 inline static Handle<Object> NewStorageFor(Isolate* isolate, | 1097 inline static Handle<Object> NewStorageFor(Isolate* isolate, |
1095 Handle<Object> object, | 1098 Handle<Object> object, |
1096 Representation representation); | 1099 Representation representation); |
1097 | 1100 |
1098 inline static Handle<Object> WrapForRead(Isolate* isolate, | 1101 inline static Handle<Object> WrapForRead(Isolate* isolate, |
1099 Handle<Object> object, | 1102 Handle<Object> object, |
1100 Representation representation); | 1103 Representation representation); |
1101 | 1104 |
(...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1784 // Indicator for one component of an AccessorPair. | 1787 // Indicator for one component of an AccessorPair. |
1785 enum AccessorComponent { | 1788 enum AccessorComponent { |
1786 ACCESSOR_GETTER, | 1789 ACCESSOR_GETTER, |
1787 ACCESSOR_SETTER | 1790 ACCESSOR_SETTER |
1788 }; | 1791 }; |
1789 | 1792 |
1790 | 1793 |
1791 enum KeyFilter { SKIP_SYMBOLS, INCLUDE_SYMBOLS }; | 1794 enum KeyFilter { SKIP_SYMBOLS, INCLUDE_SYMBOLS }; |
1792 | 1795 |
1793 | 1796 |
| 1797 enum GetKeysConversion { KEEP_NUMBERS, CONVERT_TO_STRING }; |
| 1798 |
| 1799 |
1794 enum ShouldThrow { THROW_ON_ERROR, DONT_THROW }; | 1800 enum ShouldThrow { THROW_ON_ERROR, DONT_THROW }; |
1795 | 1801 |
1796 | 1802 |
1797 // JSReceiver includes types on which properties can be defined, i.e., | 1803 // JSReceiver includes types on which properties can be defined, i.e., |
1798 // JSObject and JSProxy. | 1804 // JSObject and JSProxy. |
1799 class JSReceiver: public HeapObject { | 1805 class JSReceiver: public HeapObject { |
1800 public: | 1806 public: |
1801 DECLARE_CAST(JSReceiver) | 1807 DECLARE_CAST(JSReceiver) |
1802 | 1808 |
1803 // ES6 section 7.1.1 ToPrimitive | 1809 // ES6 section 7.1.1 ToPrimitive |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1896 // hash code if needed and none exists. | 1902 // hash code if needed and none exists. |
1897 inline static Handle<Smi> GetOrCreateIdentityHash( | 1903 inline static Handle<Smi> GetOrCreateIdentityHash( |
1898 Handle<JSReceiver> object); | 1904 Handle<JSReceiver> object); |
1899 | 1905 |
1900 enum KeyCollectionType { OWN_ONLY, INCLUDE_PROTOS }; | 1906 enum KeyCollectionType { OWN_ONLY, INCLUDE_PROTOS }; |
1901 | 1907 |
1902 // Computes the enumerable keys for a JSObject. Used for implementing | 1908 // Computes the enumerable keys for a JSObject. Used for implementing |
1903 // "for (n in object) { }". | 1909 // "for (n in object) { }". |
1904 MUST_USE_RESULT static MaybeHandle<FixedArray> GetKeys( | 1910 MUST_USE_RESULT static MaybeHandle<FixedArray> GetKeys( |
1905 Handle<JSReceiver> object, KeyCollectionType type, | 1911 Handle<JSReceiver> object, KeyCollectionType type, |
1906 KeyFilter filter = SKIP_SYMBOLS); | 1912 KeyFilter filter = SKIP_SYMBOLS, |
| 1913 GetKeysConversion getConversion = KEEP_NUMBERS); |
1907 | 1914 |
1908 private: | 1915 private: |
1909 DISALLOW_IMPLICIT_CONSTRUCTORS(JSReceiver); | 1916 DISALLOW_IMPLICIT_CONSTRUCTORS(JSReceiver); |
1910 }; | 1917 }; |
1911 | 1918 |
1912 | 1919 |
1913 // The JSObject describes real heap allocated JavaScript objects with | 1920 // The JSObject describes real heap allocated JavaScript objects with |
1914 // properties. | 1921 // properties. |
1915 // Note that the map of JSObject changes during execution to enable inline | 1922 // Note that the map of JSObject changes during execution to enable inline |
1916 // caching. | 1923 // caching. |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2226 PropertyAttributes filter = NONE); | 2233 PropertyAttributes filter = NONE); |
2227 | 2234 |
2228 // Returns the number of properties on this object filtering out properties | 2235 // Returns the number of properties on this object filtering out properties |
2229 // with the specified attributes (ignoring interceptors). | 2236 // with the specified attributes (ignoring interceptors). |
2230 int NumberOfOwnElements(PropertyAttributes filter); | 2237 int NumberOfOwnElements(PropertyAttributes filter); |
2231 // Returns the number of enumerable elements (ignoring interceptors). | 2238 // Returns the number of enumerable elements (ignoring interceptors). |
2232 int NumberOfEnumElements(); | 2239 int NumberOfEnumElements(); |
2233 // Returns the number of elements on this object filtering out elements | 2240 // Returns the number of elements on this object filtering out elements |
2234 // with the specified attributes (ignoring interceptors). | 2241 // with the specified attributes (ignoring interceptors). |
2235 int GetOwnElementKeys(FixedArray* storage, PropertyAttributes filter); | 2242 int GetOwnElementKeys(FixedArray* storage, PropertyAttributes filter); |
| 2243 static void CollectOwnElementKeys(Handle<JSObject> object, |
| 2244 KeyAccumulator* keys, |
| 2245 PropertyAttributes filter); |
2236 // Count and fill in the enumerable elements into storage. | 2246 // Count and fill in the enumerable elements into storage. |
2237 // (storage->length() == NumberOfEnumElements()). | 2247 // (storage->length() == NumberOfEnumElements()). |
2238 // If storage is NULL, will count the elements without adding | 2248 // If storage is NULL, will count the elements without adding |
2239 // them to any storage. | 2249 // them to any storage. |
2240 // Returns the number of enumerable elements. | 2250 // Returns the number of enumerable elements. |
2241 int GetEnumElementKeys(FixedArray* storage); | 2251 int GetEnumElementKeys(FixedArray* storage); |
2242 | 2252 |
2243 static Handle<FixedArray> GetEnumPropertyKeys(Handle<JSObject> object, | 2253 static Handle<FixedArray> GetEnumPropertyKeys(Handle<JSObject> object, |
2244 bool cache_result); | 2254 bool cache_result); |
2245 | 2255 |
(...skipping 8459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10705 if (v) { | 10715 if (v) { |
10706 value |= (1 << bit_position); | 10716 value |= (1 << bit_position); |
10707 } else { | 10717 } else { |
10708 value &= ~(1 << bit_position); | 10718 value &= ~(1 << bit_position); |
10709 } | 10719 } |
10710 return value; | 10720 return value; |
10711 } | 10721 } |
10712 }; | 10722 }; |
10713 | 10723 |
10714 | 10724 |
| 10725 enum AddKeyConversion { DO_NOT_CONVERT, CONVERT_TO_ARRAY_INDEX, PROXY_MAGIC }; |
| 10726 |
| 10727 // This is a helper class for JSReceiver::GetKeys which collects and sorts keys. |
| 10728 // GetKeys needs to sort keys per prototype level, first showing the integer |
| 10729 // indices from elements then the strings from the properties. However, this |
| 10730 // does not apply to proxies which are in full control of how the keys are |
| 10731 // sorted. |
| 10732 // |
| 10733 // For performance reasons the KeyAccumulator internally separates integer |
| 10734 // keys in |elements_| into sorted lists per prototype level. String keys are |
| 10735 // collected in |properties_|, a single OrderedHashSet. To separate the keys per |
| 10736 // level later when assembling the final list, |levelLengths_| keeps track of |
| 10737 // the total number of keys (integers + strings) per level. |
| 10738 // |
| 10739 // Only unique keys are kept by the KeyAccumulator, strings are stored in a |
| 10740 // HashSet for inexpensive lookups. Integer keys are kept in sorted lists which |
| 10741 // are more compact and allow for reasonably fast includes check. |
10715 class KeyAccumulator final BASE_EMBEDDED { | 10742 class KeyAccumulator final BASE_EMBEDDED { |
10716 public: | 10743 public: |
10717 explicit KeyAccumulator(Isolate* isolate) : isolate_(isolate), length_(0) {} | 10744 explicit KeyAccumulator(Isolate* isolate, |
| 10745 KeyFilter filter = KeyFilter::SKIP_SYMBOLS) |
| 10746 : isolate_(isolate), filter_(filter), length_(0), levelLength_(0) {} |
| 10747 ~KeyAccumulator(); |
10718 | 10748 |
10719 void AddKey(Handle<Object> key, int check_limit); | 10749 bool AddKey(uint32_t key); |
10720 void AddKeys(Handle<FixedArray> array, KeyFilter filter); | 10750 bool AddKey(Object* key, AddKeyConversion convert = DO_NOT_CONVERT); |
10721 void AddKeys(Handle<JSObject> array, KeyFilter filter); | 10751 bool AddKey(Handle<Object> key, AddKeyConversion convert = DO_NOT_CONVERT); |
10722 void PrepareForComparisons(int count); | 10752 void AddKeys(Handle<FixedArray> array, |
10723 Handle<FixedArray> GetKeys(); | 10753 AddKeyConversion convert = DO_NOT_CONVERT); |
| 10754 void AddKeys(Handle<JSObject> array, |
| 10755 AddKeyConversion convert = DO_NOT_CONVERT); |
| 10756 void AddKeysFromProxy(Handle<JSObject> array); |
| 10757 // Jump to the next level, pushing the current |levelLength_| to |
| 10758 // |levelLengths_| and adding a new list to |elements_|. |
| 10759 void NextPrototype(); |
| 10760 // Sort the integer indices in the last list in |elements_| |
| 10761 void SortCurrentElementsList(); |
| 10762 Handle<FixedArray> GetKeys(GetKeysConversion convert = KEEP_NUMBERS); |
10724 | 10763 |
10725 int GetLength() { return length_; } | |
10726 | 10764 |
10727 private: | 10765 private: |
10728 void EnsureCapacity(int capacity); | 10766 Isolate* isolate_; |
10729 void Grow(); | 10767 KeyFilter filter_; |
| 10768 // |elements_| contains the sorted element keys (indices) per level. |
| 10769 List<List<uint32_t>*> elements_; |
| 10770 // |protoLengths_| contains the total number of keys (elements + properties) |
| 10771 // per level. Negative values mark counts for a level with keys from a proxy. |
| 10772 List<int> levelLengths_; |
| 10773 // |properties_| contains the property keys per level in insertion order. |
| 10774 Handle<OrderedHashSet> properties_; |
| 10775 // |length_| keeps track of the total number of all element and property keys. |
| 10776 int length_; |
| 10777 // |levelLength_| keeps track of the total number of keys |
| 10778 // (elements + properties) in the current level. |
| 10779 int levelLength_; |
10730 | 10780 |
10731 Isolate* isolate_; | |
10732 Handle<FixedArray> keys_; | |
10733 Handle<OrderedHashSet> set_; | |
10734 int length_; | |
10735 DISALLOW_COPY_AND_ASSIGN(KeyAccumulator); | 10781 DISALLOW_COPY_AND_ASSIGN(KeyAccumulator); |
10736 }; | 10782 }; |
10737 | 10783 |
10738 } // NOLINT, false-positive due to second-order macros. | 10784 } // NOLINT, false-positive due to second-order macros. |
10739 } // NOLINT, false-positive due to second-order macros. | 10785 } // NOLINT, false-positive due to second-order macros. |
10740 | 10786 |
10741 #endif // V8_OBJECTS_H_ | 10787 #endif // V8_OBJECTS_H_ |
OLD | NEW |