Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(23)

Side by Side Diff: src/key-accumulator.h

Issue 1668853002: [proxies] allow duplicate keys for [[OwnPropertyKeys]] trap. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: addressing nits Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/json-stringifier.h ('k') | src/key-accumulator.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 13 matching lines...) Expand all
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, PropertyFilter filter) 34 KeyAccumulator(Isolate* isolate, KeyCollectionType type,
35 : isolate_(isolate), filter_(filter) {} 35 PropertyFilter filter)
36 : isolate_(isolate), type_(type), filter_(filter) {}
36 ~KeyAccumulator(); 37 ~KeyAccumulator();
37 38
38 bool AddKey(uint32_t key); 39 bool AddKey(uint32_t key);
39 bool AddKey(Object* key, AddKeyConversion convert); 40 bool AddKey(Object* key, AddKeyConversion convert);
40 bool AddKey(Handle<Object> key, AddKeyConversion convert); 41 bool AddKey(Handle<Object> key, AddKeyConversion convert);
41 void AddKeys(Handle<FixedArray> array, AddKeyConversion convert); 42 void AddKeys(Handle<FixedArray> array, AddKeyConversion convert);
42 void AddKeys(Handle<JSObject> array, AddKeyConversion convert); 43 void AddKeys(Handle<JSObject> array, AddKeyConversion convert);
43 void AddKeysFromProxy(Handle<JSObject> array); 44 void AddKeysFromProxy(Handle<JSObject> array);
44 Maybe<bool> AddKeysFromProxy(Handle<JSProxy> proxy, Handle<FixedArray> keys); 45 Maybe<bool> AddKeysFromProxy(Handle<JSProxy> proxy, Handle<FixedArray> keys);
45 void AddElementKeysFromInterceptor(Handle<JSObject> array); 46 void AddElementKeysFromInterceptor(Handle<JSObject> array);
46 // Jump to the next level, pushing the current |levelLength_| to 47 // Jump to the next level, pushing the current |levelLength_| to
47 // |levelLengths_| and adding a new list to |elements_|. 48 // |levelLengths_| and adding a new list to |elements_|.
48 void NextPrototype(); 49 void NextPrototype();
49 // Sort the integer indices in the last list in |elements_| 50 // Sort the integer indices in the last list in |elements_|
50 void SortCurrentElementsList(); 51 void SortCurrentElementsList();
51 Handle<FixedArray> GetKeys(GetKeysConversion convert = KEEP_NUMBERS); 52 Handle<FixedArray> GetKeys(GetKeysConversion convert = KEEP_NUMBERS);
52 int length() { return length_; } 53 int length() { return length_; }
53 Isolate* isolate() { return isolate_; } 54 Isolate* isolate() { return isolate_; }
54 55
55 private: 56 private:
56 bool AddIntegerKey(uint32_t key); 57 bool AddIntegerKey(uint32_t key);
57 bool AddStringKey(Handle<Object> key, AddKeyConversion convert); 58 bool AddStringKey(Handle<Object> key, AddKeyConversion convert);
58 bool AddSymbolKey(Handle<Object> array); 59 bool AddSymbolKey(Handle<Object> array);
59 void SortCurrentElementsListRemoveDuplicates(); 60 void SortCurrentElementsListRemoveDuplicates();
60 61
61 Isolate* isolate_; 62 Isolate* isolate_;
63 KeyCollectionType type_;
62 PropertyFilter filter_; 64 PropertyFilter filter_;
63 // |elements_| contains the sorted element keys (indices) per level. 65 // |elements_| contains the sorted element keys (indices) per level.
64 std::vector<std::vector<uint32_t>*> elements_; 66 std::vector<std::vector<uint32_t>*> elements_;
65 // |protoLengths_| contains the total number of keys (elements + properties) 67 // |protoLengths_| contains the total number of keys (elements + properties)
66 // per level. Negative values mark counts for a level with keys from a proxy. 68 // per level. Negative values mark counts for a level with keys from a proxy.
67 std::vector<int> level_lengths_; 69 std::vector<int> level_lengths_;
68 // |string_properties_| contains the unique String property keys for all 70 // |string_properties_| contains the unique String property keys for all
69 // levels in insertion order per level. 71 // levels in insertion order per level.
70 Handle<OrderedHashSet> string_properties_; 72 Handle<OrderedHashSet> string_properties_;
71 // |symbol_properties_| contains the unique Symbol property keys for all 73 // |symbol_properties_| contains the unique Symbol property keys for all
72 // levels in insertion order per level. 74 // levels in insertion order per level.
73 Handle<OrderedHashSet> symbol_properties_; 75 Handle<OrderedHashSet> symbol_properties_;
76 Handle<FixedArray> ownProxyKeys_;
74 // |length_| keeps track of the total number of all element and property keys. 77 // |length_| keeps track of the total number of all element and property keys.
75 int length_ = 0; 78 int length_ = 0;
76 // |levelLength_| keeps track of the number of String keys in the current 79 // |levelLength_| keeps track of the number of String keys in the current
77 // level. 80 // level.
78 int level_string_length_ = 0; 81 int level_string_length_ = 0;
79 // |levelSymbolLength_| keeps track of the number of Symbol keys in the 82 // |levelSymbolLength_| keeps track of the number of Symbol keys in the
80 // current level. 83 // current level.
81 int level_symbol_length_ = 0; 84 int level_symbol_length_ = 0;
82 85
83 DISALLOW_COPY_AND_ASSIGN(KeyAccumulator); 86 DISALLOW_COPY_AND_ASSIGN(KeyAccumulator);
84 }; 87 };
85 88
86 89
87 } // namespace internal 90 } // namespace internal
88 } // namespace v8 91 } // namespace v8
89 92
90 93
91 #endif // V8_KEY_ACCUMULATOR_H_ 94 #endif // V8_KEY_ACCUMULATOR_H_
OLDNEW
« no previous file with comments | « src/json-stringifier.h ('k') | src/key-accumulator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698