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 "src/isolate.h" | 8 #include "src/isolate.h" |
9 #include "src/objects.h" | 9 #include "src/objects.h" |
10 | 10 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
45 Maybe<bool> AddKeysFromProxy(Handle<JSProxy> proxy, Handle<FixedArray> keys); | 45 Maybe<bool> AddKeysFromProxy(Handle<JSProxy> proxy, Handle<FixedArray> keys); |
46 void AddElementKeysFromInterceptor(Handle<JSObject> array); | 46 void AddElementKeysFromInterceptor(Handle<JSObject> array); |
47 // Jump to the next level, pushing the current |levelLength_| to | 47 // Jump to the next level, pushing the current |levelLength_| to |
48 // |levelLengths_| and adding a new list to |elements_|. | 48 // |levelLengths_| and adding a new list to |elements_|. |
49 void NextPrototype(); | 49 void NextPrototype(); |
50 // Sort the integer indices in the last list in |elements_| | 50 // Sort the integer indices in the last list in |elements_| |
51 void SortCurrentElementsList(); | 51 void SortCurrentElementsList(); |
52 Handle<FixedArray> GetKeys(GetKeysConversion convert = KEEP_NUMBERS); | 52 Handle<FixedArray> GetKeys(GetKeysConversion convert = KEEP_NUMBERS); |
53 int length() { return length_; } | 53 int length() { return length_; } |
54 Isolate* isolate() { return isolate_; } | 54 Isolate* isolate() { return isolate_; } |
55 void set_filter_proxy_keys(bool filter) { filter_proxy_keys_ = filter; } | |
55 | 56 |
56 private: | 57 private: |
57 bool AddIntegerKey(uint32_t key); | 58 bool AddIntegerKey(uint32_t key); |
58 bool AddStringKey(Handle<Object> key, AddKeyConversion convert); | 59 bool AddStringKey(Handle<Object> key, AddKeyConversion convert); |
59 bool AddSymbolKey(Handle<Object> array); | 60 bool AddSymbolKey(Handle<Object> array); |
60 void SortCurrentElementsListRemoveDuplicates(); | 61 void SortCurrentElementsListRemoveDuplicates(); |
61 | 62 |
62 Isolate* isolate_; | 63 Isolate* isolate_; |
63 KeyCollectionType type_; | 64 KeyCollectionType type_; |
64 PropertyFilter filter_; | 65 PropertyFilter filter_; |
66 bool filter_proxy_keys_ = true; | |
65 // |elements_| contains the sorted element keys (indices) per level. | 67 // |elements_| contains the sorted element keys (indices) per level. |
66 std::vector<std::vector<uint32_t>*> elements_; | 68 std::vector<std::vector<uint32_t>*> elements_; |
67 // |protoLengths_| contains the total number of keys (elements + properties) | 69 // |protoLengths_| contains the total number of keys (elements + properties) |
68 // per level. Negative values mark counts for a level with keys from a proxy. | 70 // per level. Negative values mark counts for a level with keys from a proxy. |
69 std::vector<int> level_lengths_; | 71 std::vector<int> level_lengths_; |
70 // |string_properties_| contains the unique String property keys for all | 72 // |string_properties_| contains the unique String property keys for all |
71 // levels in insertion order per level. | 73 // levels in insertion order per level. |
72 Handle<OrderedHashSet> string_properties_; | 74 Handle<OrderedHashSet> string_properties_; |
73 // |symbol_properties_| contains the unique Symbol property keys for all | 75 // |symbol_properties_| contains the unique Symbol property keys for all |
74 // levels in insertion order per level. | 76 // levels in insertion order per level. |
75 Handle<OrderedHashSet> symbol_properties_; | 77 Handle<OrderedHashSet> symbol_properties_; |
76 Handle<FixedArray> ownProxyKeys_; | 78 Handle<FixedArray> ownProxyKeys_; |
77 // |length_| keeps track of the total number of all element and property keys. | 79 // |length_| keeps track of the total number of all element and property keys. |
78 int length_ = 0; | 80 int length_ = 0; |
79 // |levelLength_| keeps track of the number of String keys in the current | 81 // |levelLength_| keeps track of the number of String keys in the current |
80 // level. | 82 // level. |
81 int level_string_length_ = 0; | 83 int level_string_length_ = 0; |
82 // |levelSymbolLength_| keeps track of the number of Symbol keys in the | 84 // |levelSymbolLength_| keeps track of the number of Symbol keys in the |
83 // current level. | 85 // current level. |
84 int level_symbol_length_ = 0; | 86 int level_symbol_length_ = 0; |
85 | 87 |
86 DISALLOW_COPY_AND_ASSIGN(KeyAccumulator); | 88 DISALLOW_COPY_AND_ASSIGN(KeyAccumulator); |
87 }; | 89 }; |
88 | 90 |
89 // The FastKeyAccumulator handles the cases where there are no elements on the | 91 // The FastKeyAccumulator handles the cases where there are no elements on the |
90 // prototype chain and forwords the complex/slow cases to the normal | 92 // prototype chain and forwords the complex/slow cases to the normal |
Jakob Kummerow
2016/03/18 14:12:00
drive-by nit: s/forwords/forwards/
| |
91 // KeyAccumulator. | 93 // KeyAccumulator. |
92 class FastKeyAccumulator { | 94 class FastKeyAccumulator { |
93 public: | 95 public: |
94 FastKeyAccumulator(Isolate* isolate, Handle<JSReceiver> receiver, | 96 FastKeyAccumulator(Isolate* isolate, Handle<JSReceiver> receiver, |
95 KeyCollectionType type, PropertyFilter filter) | 97 KeyCollectionType type, PropertyFilter filter) |
96 : isolate_(isolate), receiver_(receiver), type_(type), filter_(filter) { | 98 : isolate_(isolate), receiver_(receiver), type_(type), filter_(filter) { |
97 Prepare(); | 99 Prepare(); |
98 // TODO(cbruni): pass filter_ directly to the KeyAccumulator. | 100 // TODO(cbruni): pass filter_ directly to the KeyAccumulator. |
99 USE(filter_); | 101 USE(filter_); |
100 } | 102 } |
101 | 103 |
102 bool is_receiver_simple_enum() { return is_receiver_simple_enum_; } | 104 bool is_receiver_simple_enum() { return is_receiver_simple_enum_; } |
103 bool has_empty_prototype() { return has_empty_prototype_; } | 105 bool has_empty_prototype() { return has_empty_prototype_; } |
106 void set_filter_proxy_keys(bool filter) { filter_proxy_keys_ = filter; } | |
104 | 107 |
105 MaybeHandle<FixedArray> GetKeys(GetKeysConversion convert = KEEP_NUMBERS); | 108 MaybeHandle<FixedArray> GetKeys(GetKeysConversion convert = KEEP_NUMBERS); |
106 | 109 |
107 private: | 110 private: |
108 void Prepare(); | 111 void Prepare(); |
109 MaybeHandle<FixedArray> GetKeysFast(GetKeysConversion convert); | 112 MaybeHandle<FixedArray> GetKeysFast(GetKeysConversion convert); |
110 MaybeHandle<FixedArray> GetKeysSlow(GetKeysConversion convert); | 113 MaybeHandle<FixedArray> GetKeysSlow(GetKeysConversion convert); |
111 | 114 |
112 Isolate* isolate_; | 115 Isolate* isolate_; |
113 Handle<JSReceiver> receiver_; | 116 Handle<JSReceiver> receiver_; |
114 KeyCollectionType type_; | 117 KeyCollectionType type_; |
115 PropertyFilter filter_; | 118 PropertyFilter filter_; |
116 bool is_receiver_simple_enum_ = false; | 119 bool is_receiver_simple_enum_ = false; |
117 bool has_empty_prototype_ = false; | 120 bool has_empty_prototype_ = false; |
121 bool filter_proxy_keys_ = true; | |
118 | 122 |
119 DISALLOW_COPY_AND_ASSIGN(FastKeyAccumulator); | 123 DISALLOW_COPY_AND_ASSIGN(FastKeyAccumulator); |
120 }; | 124 }; |
121 | 125 |
122 } // namespace internal | 126 } // namespace internal |
123 } // namespace v8 | 127 } // namespace v8 |
124 | 128 |
125 #endif // V8_KEY_ACCUMULATOR_H_ | 129 #endif // V8_KEY_ACCUMULATOR_H_ |
OLD | NEW |