Chromium Code Reviews| 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_KEY_ACCUMULATOR_H_ | 5 #ifndef V8_KEY_ACCUMULATOR_H_ |
| 6 #define V8_KEY_ACCUMULATOR_H_ | 6 #define V8_KEY_ACCUMULATOR_H_ |
| 7 | 7 |
| 8 #include <algorithm> | |
|
Jakob Kummerow
2016/01/19 15:32:53
nit: I guess this can be moved to the .cc file?
| |
| 9 #include <set> | |
| 10 | |
| 8 #include "src/isolate.h" | 11 #include "src/isolate.h" |
| 9 #include "src/objects.h" | 12 #include "src/objects.h" |
| 10 | 13 |
| 11 namespace v8 { | 14 namespace v8 { |
| 12 namespace internal { | 15 namespace internal { |
| 13 | 16 |
| 14 enum AddKeyConversion { DO_NOT_CONVERT, CONVERT_TO_ARRAY_INDEX, PROXY_MAGIC }; | 17 enum AddKeyConversion { DO_NOT_CONVERT, CONVERT_TO_ARRAY_INDEX, PROXY_MAGIC }; |
| 15 | 18 |
| 16 // This is a helper class for JSReceiver::GetKeys which collects and sorts keys. | 19 // This is a helper class for JSReceiver::GetKeys which collects and sorts keys. |
| 17 // GetKeys needs to sort keys per prototype level, first showing the integer | 20 // GetKeys needs to sort keys per prototype level, first showing the integer |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 38 bool AddKey(uint32_t key); | 41 bool AddKey(uint32_t key); |
| 39 bool AddKey(Object* key, AddKeyConversion convert = DO_NOT_CONVERT); | 42 bool AddKey(Object* key, AddKeyConversion convert = DO_NOT_CONVERT); |
| 40 bool AddKey(Handle<Object> key, AddKeyConversion convert = DO_NOT_CONVERT); | 43 bool AddKey(Handle<Object> key, AddKeyConversion convert = DO_NOT_CONVERT); |
| 41 void AddKeys(Handle<FixedArray> array, | 44 void AddKeys(Handle<FixedArray> array, |
| 42 AddKeyConversion convert = DO_NOT_CONVERT); | 45 AddKeyConversion convert = DO_NOT_CONVERT); |
| 43 void AddKeys(Handle<JSObject> array, | 46 void AddKeys(Handle<JSObject> array, |
| 44 AddKeyConversion convert = DO_NOT_CONVERT); | 47 AddKeyConversion convert = DO_NOT_CONVERT); |
| 45 void AddKeysFromProxy(Handle<JSObject> array); | 48 void AddKeysFromProxy(Handle<JSObject> array); |
| 46 Maybe<bool> AddKeysFromProxy(Handle<JSProxy> proxy, Handle<FixedArray> keys); | 49 Maybe<bool> AddKeysFromProxy(Handle<JSProxy> proxy, Handle<FixedArray> keys); |
| 47 void AddElementKeysFromInterceptor(Handle<JSObject> array); | 50 void AddElementKeysFromInterceptor(Handle<JSObject> array); |
| 51 void HideKey(uint32_t key); | |
| 52 void HideKey(Object* key); | |
| 53 void HideKey(Handle<Object> key); | |
| 48 // Jump to the next level, pushing the current |levelLength_| to | 54 // Jump to the next level, pushing the current |levelLength_| to |
| 49 // |levelLengths_| and adding a new list to |elements_|. | 55 // |levelLengths_| and adding a new list to |elements_|. |
| 50 void NextPrototype(); | 56 void NextPrototype(); |
| 51 // Sort the integer indices in the last list in |elements_| | 57 // Sort the integer indices in the last list in |elements_| |
| 52 void SortCurrentElementsList(); | 58 void SortCurrentElementsList(); |
| 53 Handle<FixedArray> GetKeys(GetKeysConversion convert = KEEP_NUMBERS); | 59 Handle<FixedArray> GetKeys(GetKeysConversion convert = KEEP_NUMBERS); |
| 54 int length() { return length_; } | 60 int length() { return length_; } |
| 55 Isolate* isolate() { return isolate_; } | 61 Isolate* isolate() { return isolate_; } |
| 56 | 62 |
| 57 private: | 63 private: |
| 58 bool AddIntegerKey(uint32_t key); | 64 bool AddIntegerKey(uint32_t key); |
| 59 bool AddStringKey(Handle<Object> key, AddKeyConversion convert); | 65 bool AddStringKey(Handle<Object> key, AddKeyConversion convert); |
| 60 bool AddSymbolKey(Handle<Object> array); | 66 bool AddSymbolKey(Handle<Object> array); |
| 61 void SortCurrentElementsListRemoveDuplicates(); | 67 void SortCurrentElementsListRemoveDuplicates(); |
| 68 bool IsKeyHidden(Handle<Object> key); | |
| 69 bool IsKeyHidden(uint32_t key); | |
| 62 | 70 |
| 63 Isolate* isolate_; | 71 Isolate* isolate_; |
| 64 PropertyFilter filter_; | 72 PropertyFilter filter_; |
| 65 // |elements_| contains the sorted element keys (indices) per level. | 73 // |elements_| contains the sorted element keys (indices) per level. |
| 66 std::vector<std::vector<uint32_t>*> elements_; | 74 std::vector<std::vector<uint32_t>*> elements_; |
| 67 // |protoLengths_| contains the total number of keys (elements + properties) | 75 // |protoLengths_| contains the total number of keys (elements + properties) |
| 68 // per level. Negative values mark counts for a level with keys from a proxy. | 76 // per level. Negative values mark counts for a level with keys from a proxy. |
| 69 std::vector<int> level_lengths_; | 77 std::vector<int> level_lengths_; |
| 70 // |string_properties_| contains the unique String property keys for all | 78 // |string_properties_| contains the unique String property keys for all |
| 71 // levels in insertion order per level. | 79 // levels in insertion order per level. |
| 72 Handle<OrderedHashSet> string_properties_; | 80 Handle<OrderedHashSet> string_properties_; |
| 73 // |symbol_properties_| contains the unique Symbol property keys for all | 81 // |symbol_properties_| contains the unique Symbol property keys for all |
| 74 // levels in insertion order per level. | 82 // levels in insertion order per level. |
| 75 Handle<OrderedHashSet> symbol_properties_; | 83 Handle<OrderedHashSet> symbol_properties_; |
| 84 // |hidden_keys_| keeps track of the non-enumerable property keys to prevent | |
| 85 // them from being added to the accumulator if they reappear higher up in the | |
| 86 // prototype-chain. | |
| 87 Handle<OrderedHashSet> hidden_keys_; | |
| 88 std::set<uint32_t> hidden_element_keys_; | |
| 76 // |length_| keeps track of the total number of all element and property keys. | 89 // |length_| keeps track of the total number of all element and property keys. |
| 77 int length_ = 0; | 90 int length_ = 0; |
| 78 // |levelLength_| keeps track of the number of String keys in the current | 91 // |levelLength_| keeps track of the number of String keys in the current |
| 79 // level. | 92 // level. |
| 80 int level_string_length_ = 0; | 93 int level_string_length_ = 0; |
| 81 // |levelSymbolLength_| keeps track of the number of Symbol keys in the | 94 // |levelSymbolLength_| keeps track of the number of Symbol keys in the |
| 82 // current level. | 95 // current level. |
| 83 int level_symbol_length_ = 0; | 96 int level_symbol_length_ = 0; |
| 84 | 97 |
| 85 DISALLOW_COPY_AND_ASSIGN(KeyAccumulator); | 98 DISALLOW_COPY_AND_ASSIGN(KeyAccumulator); |
| 86 }; | 99 }; |
| 87 | 100 |
| 88 | 101 |
| 89 } // namespace internal | 102 } // namespace internal |
| 90 } // namespace v8 | 103 } // namespace v8 |
| 91 | 104 |
| 92 | 105 |
| 93 #endif // V8_KEY_ACCUMULATOR_H_ | 106 #endif // V8_KEY_ACCUMULATOR_H_ |
| OLD | NEW |