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 1083 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3329 } | 3339 } |
3330 | 3340 |
3331 // Returns true if property at given entry is deleted. | 3341 // Returns true if property at given entry is deleted. |
3332 bool IsDeleted(int entry) { | 3342 bool IsDeleted(int entry) { |
3333 return Shape::IsDeleted(static_cast<Derived*>(this), entry); | 3343 return Shape::IsDeleted(static_cast<Derived*>(this), entry); |
3334 } | 3344 } |
3335 | 3345 |
3336 // Delete a property from the dictionary. | 3346 // Delete a property from the dictionary. |
3337 static Handle<Object> DeleteProperty(Handle<Derived> dictionary, int entry); | 3347 static Handle<Object> DeleteProperty(Handle<Derived> dictionary, int entry); |
3338 | 3348 |
3349 | |
Igor Sheludko
2015/10/19 13:11:19
Spurious change.
| |
3339 // Attempt to shrink the dictionary after deletion of key. | 3350 // Attempt to shrink the dictionary after deletion of key. |
3340 MUST_USE_RESULT static inline Handle<Derived> Shrink( | 3351 MUST_USE_RESULT static inline Handle<Derived> Shrink( |
3341 Handle<Derived> dictionary, | 3352 Handle<Derived> dictionary, |
3342 Key key) { | 3353 Key key) { |
3343 return DerivedHashTable::Shrink(dictionary, key); | 3354 return DerivedHashTable::Shrink(dictionary, key); |
3344 } | 3355 } |
3345 | 3356 |
3346 // Sorting support | 3357 // Sorting support |
3347 // TODO(dcarney): templatize or move to SeededNumberDictionary | 3358 // TODO(dcarney): templatize or move to SeededNumberDictionary |
3348 void CopyValuesTo(FixedArray* elements); | 3359 void CopyValuesTo(FixedArray* elements); |
(...skipping 7356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
10705 if (v) { | 10716 if (v) { |
10706 value |= (1 << bit_position); | 10717 value |= (1 << bit_position); |
10707 } else { | 10718 } else { |
10708 value &= ~(1 << bit_position); | 10719 value &= ~(1 << bit_position); |
10709 } | 10720 } |
10710 return value; | 10721 return value; |
10711 } | 10722 } |
10712 }; | 10723 }; |
10713 | 10724 |
10714 | 10725 |
10726 enum AddKeyConversion { DO_NOT_CONVERT, CONVERT_TO_ARRAY_INDEX, PROXY_MAGIC }; | |
10727 | |
10728 // This is a helper class for JSReceiver::GetKeys which collects and sorts keys. | |
10729 // GetKeys needs to sort keys per prototype level, first showing the integer | |
10730 // indices from elements then the strings from the properties. However, this | |
10731 // does | |
Igor Sheludko
2015/10/19 13:11:19
Extra line break.
| |
10732 // not apply to proxies which are in full control of how the keys are sorted. | |
10733 // | |
10734 // For performance reasones the KeyAccumulator internally separates integer | |
Igor Sheludko
2015/10/19 13:11:19
s/reasones/reasons/
| |
10735 // keys in |elements_| into sorted lists per prototype level. String keys are | |
10736 // collected in |properties_|, a single OrderedHashSet. To separate the keys per | |
10737 // level later when assembling the final list, |levelLengths_| keeps track of | |
10738 // the total number of keys (integers + strings) per level. | |
10739 // | |
10740 // Only unique keys are kepy by the KeyAccumulator, strings are stored in a | |
Igor Sheludko
2015/10/19 13:11:19
s/kepy/kept/
| |
10741 // HashSet for inexpensive lookups. Integer keys are kept in sorted lists which | |
10742 // are more compact and allow for reasonably fast includes check. | |
10715 class KeyAccumulator final BASE_EMBEDDED { | 10743 class KeyAccumulator final BASE_EMBEDDED { |
10716 public: | 10744 public: |
10717 explicit KeyAccumulator(Isolate* isolate) : isolate_(isolate), length_(0) {} | 10745 explicit KeyAccumulator(Isolate* isolate, |
10746 KeyFilter filter = KeyFilter::SKIP_SYMBOLS) | |
10747 : isolate_(isolate), filter_(filter), length_(0), levelLength_(0) {} | |
10748 ~KeyAccumulator(); | |
10718 | 10749 |
10719 void AddKey(Handle<Object> key, int check_limit); | 10750 bool AddKey(uint32_t key); |
10720 void AddKeys(Handle<FixedArray> array, KeyFilter filter); | 10751 bool AddKey(Object* key, AddKeyConversion convert = DO_NOT_CONVERT); |
10721 void AddKeys(Handle<JSObject> array, KeyFilter filter); | 10752 bool AddKey(Handle<Object> key, AddKeyConversion convert = DO_NOT_CONVERT); |
10722 void PrepareForComparisons(int count); | 10753 void AddKeys(Handle<FixedArray> array, |
10723 Handle<FixedArray> GetKeys(); | 10754 AddKeyConversion convert = DO_NOT_CONVERT); |
10755 void AddKeys(Handle<JSObject> array, | |
10756 AddKeyConversion convert = DO_NOT_CONVERT); | |
10757 void AddKeysFromProxy(Handle<JSObject> array); | |
10758 // Jump to the next level, pushing the current |levelLength_| to | |
10759 // |levelLengths_| and adding a new list to |elements_|. | |
10760 void NextPrototype(); | |
10761 // Sort the integer indices in the last list in |elements_| | |
10762 void SortCurrentElementsList(); | |
10763 Handle<FixedArray> GetKeys(GetKeysConversion convert = KEEP_NUMBERS); | |
10724 | 10764 |
10725 int GetLength() { return length_; } | |
10726 | 10765 |
10727 private: | 10766 private: |
10728 void EnsureCapacity(int capacity); | 10767 Isolate* isolate_; |
10729 void Grow(); | 10768 KeyFilter filter_; |
10769 // |elements_| contains the sorted element keys (indices) per level. | |
10770 List<List<uint32_t>*> elements_; | |
10771 // |protoLengths_| contains the total number of keys (elements + properties) | |
10772 // per level. Negative values mark counts for a level with keys from a proxy. | |
10773 List<int> levelLengths_; | |
10774 // |properties_| contains the property keys per level in insertion order. | |
10775 Handle<OrderedHashSet> properties_; | |
10776 // |length_| keeps track of the total number of all element and property keys. | |
10777 int length_; | |
10778 // |levelLength_| keeps track of the total number of keys | |
10779 // (elements + properties) in the current level. | |
10780 int levelLength_; | |
10730 | 10781 |
10731 Isolate* isolate_; | |
10732 Handle<FixedArray> keys_; | |
10733 Handle<OrderedHashSet> set_; | |
10734 int length_; | |
10735 DISALLOW_COPY_AND_ASSIGN(KeyAccumulator); | 10782 DISALLOW_COPY_AND_ASSIGN(KeyAccumulator); |
10736 }; | 10783 }; |
10737 | 10784 |
10738 } // NOLINT, false-positive due to second-order macros. | 10785 } // NOLINT, false-positive due to second-order macros. |
10739 } // NOLINT, false-positive due to second-order macros. | 10786 } // NOLINT, false-positive due to second-order macros. |
10740 | 10787 |
10741 #endif // V8_OBJECTS_H_ | 10788 #endif // V8_OBJECTS_H_ |
OLD | NEW |