| 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 13 matching lines...) Expand all Loading... |
| 24 // collected in |string_properties_|, a single OrderedHashSet (similar for | 24 // collected in |string_properties_|, a single OrderedHashSet (similar for |
| 25 // Symbols in |symbol_properties_|. To separate the keys per level later when | 25 // Symbols in |symbol_properties_|. To separate the keys per level later when |
| 26 // assembling the final list, |levelLengths_| keeps track of the number of | 26 // assembling the final list, |levelLengths_| keeps track of the number of |
| 27 // String and Symbol keys per level. | 27 // String and Symbol keys per level. |
| 28 // | 28 // |
| 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, KeyCollectionMode mode, |
| 35 PropertyFilter filter) | 35 PropertyFilter filter) |
| 36 : isolate_(isolate), type_(type), filter_(filter) {} | 36 : isolate_(isolate), mode_(mode), filter_(filter) {} |
| 37 ~KeyAccumulator(); | 37 ~KeyAccumulator(); |
| 38 | 38 |
| 39 static MaybeHandle<FixedArray> GetKeys( | 39 static MaybeHandle<FixedArray> GetKeys( |
| 40 Handle<JSReceiver> object, KeyCollectionType type, PropertyFilter filter, | 40 Handle<JSReceiver> object, KeyCollectionMode mode, PropertyFilter filter, |
| 41 GetKeysConversion keys_conversion = KEEP_NUMBERS, | 41 GetKeysConversion keys_conversion = GetKeysConversion::kKeepNumbers, |
| 42 bool filter_proxy_keys = true, bool is_for_in = false); | 42 bool filter_proxy_keys = true, bool is_for_in = false); |
| 43 Handle<FixedArray> GetKeys(GetKeysConversion convert = KEEP_NUMBERS); | 43 Handle<FixedArray> GetKeys( |
| 44 GetKeysConversion convert = GetKeysConversion::kKeepNumbers); |
| 44 Maybe<bool> CollectKeys(Handle<JSReceiver> receiver, | 45 Maybe<bool> CollectKeys(Handle<JSReceiver> receiver, |
| 45 Handle<JSReceiver> object); | 46 Handle<JSReceiver> object); |
| 46 Maybe<bool> CollectOwnElementIndices(Handle<JSReceiver> receiver, | 47 Maybe<bool> CollectOwnElementIndices(Handle<JSReceiver> receiver, |
| 47 Handle<JSObject> object); | 48 Handle<JSObject> object); |
| 48 Maybe<bool> CollectOwnPropertyNames(Handle<JSReceiver> receiver, | 49 Maybe<bool> CollectOwnPropertyNames(Handle<JSReceiver> receiver, |
| 49 Handle<JSObject> object); | 50 Handle<JSObject> object); |
| 50 | 51 |
| 51 static Handle<FixedArray> GetEnumPropertyKeys(Isolate* isolate, | 52 static Handle<FixedArray> GetEnumPropertyKeys(Isolate* isolate, |
| 52 Handle<JSObject> object); | 53 Handle<JSObject> object); |
| 53 | 54 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 74 | 75 |
| 75 Maybe<bool> AddKeysFromJSProxy(Handle<JSProxy> proxy, | 76 Maybe<bool> AddKeysFromJSProxy(Handle<JSProxy> proxy, |
| 76 Handle<FixedArray> keys); | 77 Handle<FixedArray> keys); |
| 77 | 78 |
| 78 Handle<OrderedHashSet> keys() { return Handle<OrderedHashSet>::cast(keys_); } | 79 Handle<OrderedHashSet> keys() { return Handle<OrderedHashSet>::cast(keys_); } |
| 79 | 80 |
| 80 Isolate* isolate_; | 81 Isolate* isolate_; |
| 81 // keys_ is either an Handle<OrderedHashSet> or in the case of own JSProxy | 82 // keys_ is either an Handle<OrderedHashSet> or in the case of own JSProxy |
| 82 // keys a Handle<FixedArray>. | 83 // keys a Handle<FixedArray>. |
| 83 Handle<FixedArray> keys_; | 84 Handle<FixedArray> keys_; |
| 84 KeyCollectionType type_; | 85 KeyCollectionMode mode_; |
| 85 PropertyFilter filter_; | 86 PropertyFilter filter_; |
| 86 bool filter_proxy_keys_ = true; | 87 bool filter_proxy_keys_ = true; |
| 87 bool is_for_in_ = false; | 88 bool is_for_in_ = false; |
| 88 bool skip_indices_ = false; | 89 bool skip_indices_ = false; |
| 89 | 90 |
| 90 DISALLOW_COPY_AND_ASSIGN(KeyAccumulator); | 91 DISALLOW_COPY_AND_ASSIGN(KeyAccumulator); |
| 91 }; | 92 }; |
| 92 | 93 |
| 93 // The FastKeyAccumulator handles the cases where there are no elements on the | 94 // The FastKeyAccumulator handles the cases where there are no elements on the |
| 94 // prototype chain and forwords the complex/slow cases to the normal | 95 // prototype chain and forwords the complex/slow cases to the normal |
| 95 // KeyAccumulator. | 96 // KeyAccumulator. |
| 96 class FastKeyAccumulator { | 97 class FastKeyAccumulator { |
| 97 public: | 98 public: |
| 98 FastKeyAccumulator(Isolate* isolate, Handle<JSReceiver> receiver, | 99 FastKeyAccumulator(Isolate* isolate, Handle<JSReceiver> receiver, |
| 99 KeyCollectionType type, PropertyFilter filter) | 100 KeyCollectionMode mode, PropertyFilter filter) |
| 100 : isolate_(isolate), receiver_(receiver), type_(type), filter_(filter) { | 101 : isolate_(isolate), receiver_(receiver), mode_(mode), filter_(filter) { |
| 101 Prepare(); | 102 Prepare(); |
| 102 } | 103 } |
| 103 | 104 |
| 104 bool is_receiver_simple_enum() { return is_receiver_simple_enum_; } | 105 bool is_receiver_simple_enum() { return is_receiver_simple_enum_; } |
| 105 bool has_empty_prototype() { return has_empty_prototype_; } | 106 bool has_empty_prototype() { return has_empty_prototype_; } |
| 106 void set_filter_proxy_keys(bool filter) { filter_proxy_keys_ = filter; } | 107 void set_filter_proxy_keys(bool filter) { filter_proxy_keys_ = filter; } |
| 107 void set_is_for_in(bool value) { is_for_in_ = value; } | 108 void set_is_for_in(bool value) { is_for_in_ = value; } |
| 108 | 109 |
| 109 MaybeHandle<FixedArray> GetKeys(GetKeysConversion convert = KEEP_NUMBERS); | 110 MaybeHandle<FixedArray> GetKeys( |
| 111 GetKeysConversion convert = GetKeysConversion::kKeepNumbers); |
| 110 | 112 |
| 111 private: | 113 private: |
| 112 void Prepare(); | 114 void Prepare(); |
| 113 MaybeHandle<FixedArray> GetKeysFast(GetKeysConversion convert); | 115 MaybeHandle<FixedArray> GetKeysFast(GetKeysConversion convert); |
| 114 MaybeHandle<FixedArray> GetKeysSlow(GetKeysConversion convert); | 116 MaybeHandle<FixedArray> GetKeysSlow(GetKeysConversion convert); |
| 115 | 117 |
| 116 Isolate* isolate_; | 118 Isolate* isolate_; |
| 117 Handle<JSReceiver> receiver_; | 119 Handle<JSReceiver> receiver_; |
| 118 KeyCollectionType type_; | 120 KeyCollectionMode mode_; |
| 119 PropertyFilter filter_; | 121 PropertyFilter filter_; |
| 120 bool filter_proxy_keys_ = true; | 122 bool filter_proxy_keys_ = true; |
| 121 bool is_for_in_ = false; | 123 bool is_for_in_ = false; |
| 122 bool is_receiver_simple_enum_ = false; | 124 bool is_receiver_simple_enum_ = false; |
| 123 bool has_empty_prototype_ = false; | 125 bool has_empty_prototype_ = false; |
| 124 | 126 |
| 125 DISALLOW_COPY_AND_ASSIGN(FastKeyAccumulator); | 127 DISALLOW_COPY_AND_ASSIGN(FastKeyAccumulator); |
| 126 }; | 128 }; |
| 127 | 129 |
| 128 } // namespace internal | 130 } // namespace internal |
| 129 } // namespace v8 | 131 } // namespace v8 |
| 130 | 132 |
| 131 #endif // V8_KEYS_H_ | 133 #endif // V8_KEYS_H_ |
| OLD | NEW |