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

Side by Side Diff: src/keys.h

Issue 2176113009: [keys] Trigger [[getOwnPropertyDescriptor]] trap for Object.keys (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: eval scoping is hard Created 4 years, 4 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 | « no previous file | src/keys.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_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 21 matching lines...) Expand all
32 class KeyAccumulator final BASE_EMBEDDED { 32 class KeyAccumulator final BASE_EMBEDDED {
33 public: 33 public:
34 KeyAccumulator(Isolate* isolate, KeyCollectionMode mode, 34 KeyAccumulator(Isolate* isolate, KeyCollectionMode mode,
35 PropertyFilter filter) 35 PropertyFilter filter)
36 : isolate_(isolate), mode_(mode), 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, KeyCollectionMode mode, PropertyFilter filter, 40 Handle<JSReceiver> object, KeyCollectionMode mode, PropertyFilter filter,
41 GetKeysConversion keys_conversion = GetKeysConversion::kKeepNumbers, 41 GetKeysConversion keys_conversion = GetKeysConversion::kKeepNumbers,
42 bool filter_proxy_keys = true, bool is_for_in = false); 42 bool is_for_in = false);
43 43
44 Handle<FixedArray> GetKeys( 44 Handle<FixedArray> GetKeys(
45 GetKeysConversion convert = GetKeysConversion::kKeepNumbers); 45 GetKeysConversion convert = GetKeysConversion::kKeepNumbers);
46 Maybe<bool> CollectKeys(Handle<JSReceiver> receiver, 46 Maybe<bool> CollectKeys(Handle<JSReceiver> receiver,
47 Handle<JSReceiver> object); 47 Handle<JSReceiver> object);
48 Maybe<bool> CollectOwnElementIndices(Handle<JSReceiver> receiver, 48 Maybe<bool> CollectOwnElementIndices(Handle<JSReceiver> receiver,
49 Handle<JSObject> object); 49 Handle<JSObject> object);
50 Maybe<bool> CollectOwnPropertyNames(Handle<JSReceiver> receiver, 50 Maybe<bool> CollectOwnPropertyNames(Handle<JSReceiver> receiver,
51 Handle<JSObject> object); 51 Handle<JSObject> object);
52 Maybe<bool> CollectAccessCheckInterceptorKeys( 52 Maybe<bool> CollectAccessCheckInterceptorKeys(
53 Handle<AccessCheckInfo> access_check_info, Handle<JSReceiver> receiver, 53 Handle<AccessCheckInfo> access_check_info, Handle<JSReceiver> receiver,
54 Handle<JSObject> object); 54 Handle<JSObject> object);
55 55
56 static Handle<FixedArray> GetOwnEnumPropertyKeys(Isolate* isolate, 56 static Handle<FixedArray> GetOwnEnumPropertyKeys(Isolate* isolate,
57 Handle<JSObject> object); 57 Handle<JSObject> object);
58 58
59 void AddKey(Object* key, AddKeyConversion convert = DO_NOT_CONVERT); 59 void AddKey(Object* key, AddKeyConversion convert = DO_NOT_CONVERT);
60 void AddKey(Handle<Object> key, AddKeyConversion convert = DO_NOT_CONVERT); 60 void AddKey(Handle<Object> key, AddKeyConversion convert = DO_NOT_CONVERT);
61 void AddKeys(Handle<FixedArray> array, AddKeyConversion convert); 61 void AddKeys(Handle<FixedArray> array, AddKeyConversion convert);
62 void AddKeys(Handle<JSObject> array_like, AddKeyConversion convert); 62 void AddKeys(Handle<JSObject> array_like, AddKeyConversion convert);
63 63
64 // Jump to the next level, pushing the current |levelLength_| to 64 // Jump to the next level, pushing the current |levelLength_| to
65 // |levelLengths_| and adding a new list to |elements_|. 65 // |levelLengths_| and adding a new list to |elements_|.
66 Isolate* isolate() { return isolate_; } 66 Isolate* isolate() { return isolate_; }
67 // Filter keys based on their property descriptors. 67 // Filter keys based on their property descriptors.
68 PropertyFilter filter() { return filter_; } 68 PropertyFilter filter() { return filter_; }
69 // The collection mode defines whether we collect the keys from the prototype 69 // The collection mode defines whether we collect the keys from the prototype
70 // chain or only look at the receiver. 70 // chain or only look at the receiver.
71 KeyCollectionMode mode() { return mode_; } 71 KeyCollectionMode mode() { return mode_; }
72 void set_filter_proxy_keys(bool filter) { filter_proxy_keys_ = filter; }
73 // In case of for-in loops we have to treat JSProxy keys differently and 72 // In case of for-in loops we have to treat JSProxy keys differently and
74 // deduplicate them. Additionally we convert JSProxy keys back to array 73 // deduplicate them. Additionally we convert JSProxy keys back to array
75 // indices. 74 // indices.
76 void set_is_for_in(bool value) { is_for_in_ = value; } 75 void set_is_for_in(bool value) { is_for_in_ = value; }
77 void set_skip_indices(bool value) { skip_indices_ = value; } 76 void set_skip_indices(bool value) { skip_indices_ = value; }
78 // The last_non_empty_prototype is used to limit the prototypes for which 77 // The last_non_empty_prototype is used to limit the prototypes for which
79 // we have to keep track of non-enumerable keys that can shadow keys 78 // we have to keep track of non-enumerable keys that can shadow keys
80 // repeated on the prototype chain. 79 // repeated on the prototype chain.
81 void set_last_non_empty_prototype(Handle<JSReceiver> object) { 80 void set_last_non_empty_prototype(Handle<JSReceiver> object) {
82 last_non_empty_prototype_ = object; 81 last_non_empty_prototype_ = object;
(...skipping 18 matching lines...) Expand all
101 100
102 Isolate* isolate_; 101 Isolate* isolate_;
103 // keys_ is either an Handle<OrderedHashSet> or in the case of own JSProxy 102 // keys_ is either an Handle<OrderedHashSet> or in the case of own JSProxy
104 // keys a Handle<FixedArray>. The OrderedHashSet is in-place converted to the 103 // keys a Handle<FixedArray>. The OrderedHashSet is in-place converted to the
105 // result list, a FixedArray containing all collected keys. 104 // result list, a FixedArray containing all collected keys.
106 Handle<FixedArray> keys_; 105 Handle<FixedArray> keys_;
107 Handle<JSReceiver> last_non_empty_prototype_; 106 Handle<JSReceiver> last_non_empty_prototype_;
108 Handle<ObjectHashSet> shadowing_keys_; 107 Handle<ObjectHashSet> shadowing_keys_;
109 KeyCollectionMode mode_; 108 KeyCollectionMode mode_;
110 PropertyFilter filter_; 109 PropertyFilter filter_;
111 bool filter_proxy_keys_ = true;
112 bool is_for_in_ = false; 110 bool is_for_in_ = false;
113 bool skip_indices_ = false; 111 bool skip_indices_ = false;
114 // For all the keys on the first receiver adding a shadowing key we can skip 112 // For all the keys on the first receiver adding a shadowing key we can skip
115 // the shadow check. 113 // the shadow check.
116 bool skip_shadow_check_ = true; 114 bool skip_shadow_check_ = true;
117 115
118 DISALLOW_COPY_AND_ASSIGN(KeyAccumulator); 116 DISALLOW_COPY_AND_ASSIGN(KeyAccumulator);
119 }; 117 };
120 118
121 // The FastKeyAccumulator handles the cases where there are no elements on the 119 // The FastKeyAccumulator handles the cases where there are no elements on the
122 // prototype chain and forwords the complex/slow cases to the normal 120 // prototype chain and forwords the complex/slow cases to the normal
123 // KeyAccumulator. This significantly speeds up the cases where the OWN_ONLY 121 // KeyAccumulator. This significantly speeds up the cases where the OWN_ONLY
124 // case where we do not have to walk the prototype chain. 122 // case where we do not have to walk the prototype chain.
125 class FastKeyAccumulator { 123 class FastKeyAccumulator {
126 public: 124 public:
127 FastKeyAccumulator(Isolate* isolate, Handle<JSReceiver> receiver, 125 FastKeyAccumulator(Isolate* isolate, Handle<JSReceiver> receiver,
128 KeyCollectionMode mode, PropertyFilter filter) 126 KeyCollectionMode mode, PropertyFilter filter)
129 : isolate_(isolate), receiver_(receiver), mode_(mode), filter_(filter) { 127 : isolate_(isolate), receiver_(receiver), mode_(mode), filter_(filter) {
130 Prepare(); 128 Prepare();
131 } 129 }
132 130
133 bool is_receiver_simple_enum() { return is_receiver_simple_enum_; } 131 bool is_receiver_simple_enum() { return is_receiver_simple_enum_; }
134 bool has_empty_prototype() { return has_empty_prototype_; } 132 bool has_empty_prototype() { return has_empty_prototype_; }
135 void set_filter_proxy_keys(bool filter) { filter_proxy_keys_ = filter; }
136 void set_is_for_in(bool value) { is_for_in_ = value; } 133 void set_is_for_in(bool value) { is_for_in_ = value; }
137 134
138 MaybeHandle<FixedArray> GetKeys( 135 MaybeHandle<FixedArray> GetKeys(
139 GetKeysConversion convert = GetKeysConversion::kKeepNumbers); 136 GetKeysConversion convert = GetKeysConversion::kKeepNumbers);
140 137
141 private: 138 private:
142 void Prepare(); 139 void Prepare();
143 MaybeHandle<FixedArray> GetKeysFast(GetKeysConversion convert); 140 MaybeHandle<FixedArray> GetKeysFast(GetKeysConversion convert);
144 MaybeHandle<FixedArray> GetKeysSlow(GetKeysConversion convert); 141 MaybeHandle<FixedArray> GetKeysSlow(GetKeysConversion convert);
145 142
146 Isolate* isolate_; 143 Isolate* isolate_;
147 Handle<JSReceiver> receiver_; 144 Handle<JSReceiver> receiver_;
148 Handle<JSReceiver> last_non_empty_prototype_; 145 Handle<JSReceiver> last_non_empty_prototype_;
149 KeyCollectionMode mode_; 146 KeyCollectionMode mode_;
150 PropertyFilter filter_; 147 PropertyFilter filter_;
151 bool filter_proxy_keys_ = true;
152 bool is_for_in_ = false; 148 bool is_for_in_ = false;
153 bool is_receiver_simple_enum_ = false; 149 bool is_receiver_simple_enum_ = false;
154 bool has_empty_prototype_ = false; 150 bool has_empty_prototype_ = false;
155 151
156 DISALLOW_COPY_AND_ASSIGN(FastKeyAccumulator); 152 DISALLOW_COPY_AND_ASSIGN(FastKeyAccumulator);
157 }; 153 };
158 154
159 } // namespace internal 155 } // namespace internal
160 } // namespace v8 156 } // namespace v8
161 157
162 #endif // V8_KEYS_H_ 158 #endif // V8_KEYS_H_
OLDNEW
« no previous file with comments | « no previous file | src/keys.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698