| 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_KEYS_H_ | 5 #ifndef V8_KEYS_H_ |
| 6 #define V8_KEYS_H_ | 6 #define V8_KEYS_H_ |
| 7 | 7 |
| 8 #include "src/isolate.h" | 8 #include "src/isolate.h" |
| 9 #include "src/objects.h" | 9 #include "src/objects.h" |
| 10 | 10 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 // Only unique keys are kept by the KeyAccumulator, strings are stored in a | 29 // Only unique keys are kept by the KeyAccumulator, strings are stored in a |
| 30 // HashSet for inexpensive lookups. Integer keys are kept in sorted lists which | 30 // HashSet for inexpensive lookups. Integer keys are kept in sorted lists which |
| 31 // are more compact and allow for reasonably fast includes check. | 31 // are more compact and allow for reasonably fast includes check. |
| 32 class KeyAccumulator final BASE_EMBEDDED { | 32 class KeyAccumulator final BASE_EMBEDDED { |
| 33 public: | 33 public: |
| 34 KeyAccumulator(Isolate* isolate, KeyCollectionType type, | 34 KeyAccumulator(Isolate* isolate, KeyCollectionType type, |
| 35 PropertyFilter filter) | 35 PropertyFilter filter) |
| 36 : isolate_(isolate), type_(type), filter_(filter) {} | 36 : isolate_(isolate), type_(type), filter_(filter) {} |
| 37 ~KeyAccumulator(); | 37 ~KeyAccumulator(); |
| 38 | 38 |
| 39 Handle<FixedArray> GetKeys(GetKeysConversion convert = KEEP_NUMBERS); |
| 40 Maybe<bool> CollectKeys(Handle<JSReceiver> receiver, |
| 41 Handle<JSReceiver> object); |
| 42 void CollectOwnElementIndices(Handle<JSObject> object); |
| 43 void CollectOwnPropertyNames(Handle<JSObject> object); |
| 44 |
| 45 static Handle<FixedArray> GetEnumPropertyKeys(Isolate* isolate, |
| 46 Handle<JSObject> object); |
| 47 |
| 39 bool AddKey(uint32_t key); | 48 bool AddKey(uint32_t key); |
| 40 bool AddKey(Object* key, AddKeyConversion convert); | 49 bool AddKey(Object* key, AddKeyConversion convert); |
| 41 bool AddKey(Handle<Object> key, AddKeyConversion convert); | 50 bool AddKey(Handle<Object> key, AddKeyConversion convert); |
| 42 void AddKeys(Handle<FixedArray> array, AddKeyConversion convert); | 51 void AddKeys(Handle<FixedArray> array, AddKeyConversion convert); |
| 43 void AddKeys(Handle<JSObject> array, AddKeyConversion convert); | 52 void AddKeys(Handle<JSObject> array, AddKeyConversion convert); |
| 44 void AddKeysFromProxy(Handle<JSObject> array); | 53 void AddKeysFromProxy(Handle<JSObject> array); |
| 45 Maybe<bool> AddKeysFromProxy(Handle<JSProxy> proxy, Handle<FixedArray> keys); | 54 Maybe<bool> AddKeysFromProxy(Handle<JSProxy> proxy, Handle<FixedArray> keys); |
| 46 void AddElementKeysFromInterceptor(Handle<JSObject> array); | 55 void AddElementKeysFromInterceptor(Handle<JSObject> array); |
| 56 |
| 47 // Jump to the next level, pushing the current |levelLength_| to | 57 // Jump to the next level, pushing the current |levelLength_| to |
| 48 // |levelLengths_| and adding a new list to |elements_|. | 58 // |levelLengths_| and adding a new list to |elements_|. |
| 49 void NextPrototype(); | 59 void NextPrototype(); |
| 50 // Sort the integer indices in the last list in |elements_| | 60 // Sort the integer indices in the last list in |elements_| |
| 51 void SortCurrentElementsList(); | 61 void SortCurrentElementsList(); |
| 52 Handle<FixedArray> GetKeys(GetKeysConversion convert = KEEP_NUMBERS); | |
| 53 int length() { return length_; } | 62 int length() { return length_; } |
| 54 Isolate* isolate() { return isolate_; } | 63 Isolate* isolate() { return isolate_; } |
| 64 PropertyFilter filter() { return filter_; } |
| 55 void set_filter_proxy_keys(bool filter) { filter_proxy_keys_ = filter; } | 65 void set_filter_proxy_keys(bool filter) { filter_proxy_keys_ = filter; } |
| 56 PropertyFilter filter() { return filter_; } | |
| 57 | |
| 58 Maybe<bool> GetKeys_Internal(Handle<JSReceiver> receiver, | |
| 59 Handle<JSReceiver> object, | |
| 60 KeyCollectionType type); | |
| 61 static Handle<FixedArray> GetEnumPropertyKeys(Isolate* isolate, | |
| 62 Handle<JSObject> object); | |
| 63 | |
| 64 void CollectOwnElementKeys(Handle<JSObject> object); | |
| 65 void CollectOwnPropertyNames(Handle<JSObject> object); | |
| 66 | 66 |
| 67 private: | 67 private: |
| 68 Maybe<bool> CollectOwnJSProxyKeys(Handle<JSReceiver> receiver, |
| 69 Handle<JSProxy> proxy); |
| 70 Maybe<bool> CollectOwnKeys(Handle<JSReceiver> receiver, |
| 71 Handle<JSObject> object); |
| 68 bool AddIntegerKey(uint32_t key); | 72 bool AddIntegerKey(uint32_t key); |
| 69 bool AddStringKey(Handle<Object> key, AddKeyConversion convert); | 73 bool AddStringKey(Handle<Object> key, AddKeyConversion convert); |
| 70 bool AddSymbolKey(Handle<Object> array); | 74 bool AddSymbolKey(Handle<Object> array); |
| 71 void SortCurrentElementsListRemoveDuplicates(); | 75 void SortCurrentElementsListRemoveDuplicates(); |
| 72 | 76 |
| 73 Maybe<bool> JSProxyOwnPropertyKeys(Handle<JSReceiver> receiver, | |
| 74 Handle<JSProxy> proxy); | |
| 75 Maybe<bool> GetKeysFromJSObject(Handle<JSReceiver> receiver, | |
| 76 Handle<JSObject> object, | |
| 77 KeyCollectionType type); | |
| 78 | |
| 79 Isolate* isolate_; | 77 Isolate* isolate_; |
| 80 KeyCollectionType type_; | 78 KeyCollectionType type_; |
| 81 PropertyFilter filter_; | 79 PropertyFilter filter_; |
| 82 bool filter_proxy_keys_ = true; | 80 bool filter_proxy_keys_ = true; |
| 83 // |elements_| contains the sorted element keys (indices) per level. | 81 // |elements_| contains the sorted element keys (indices) per level. |
| 84 std::vector<std::vector<uint32_t>*> elements_; | 82 std::vector<std::vector<uint32_t>*> elements_; |
| 85 // |protoLengths_| contains the total number of keys (elements + properties) | 83 // |protoLengths_| contains the total number of keys (elements + properties) |
| 86 // per level. Negative values mark counts for a level with keys from a proxy. | 84 // per level. Negative values mark counts for a level with keys from a proxy. |
| 87 std::vector<int> level_lengths_; | 85 std::vector<int> level_lengths_; |
| 88 // |string_properties_| contains the unique String property keys for all | 86 // |string_properties_| contains the unique String property keys for all |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 bool has_empty_prototype_ = false; | 134 bool has_empty_prototype_ = false; |
| 137 bool filter_proxy_keys_ = true; | 135 bool filter_proxy_keys_ = true; |
| 138 | 136 |
| 139 DISALLOW_COPY_AND_ASSIGN(FastKeyAccumulator); | 137 DISALLOW_COPY_AND_ASSIGN(FastKeyAccumulator); |
| 140 }; | 138 }; |
| 141 | 139 |
| 142 } // namespace internal | 140 } // namespace internal |
| 143 } // namespace v8 | 141 } // namespace v8 |
| 144 | 142 |
| 145 #endif // V8_KEYS_H_ | 143 #endif // V8_KEYS_H_ |
| OLD | NEW |