OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 #include "src/key-accumulator.h" | 5 #include "src/key-accumulator.h" |
6 | 6 |
7 #include "src/elements.h" | 7 #include "src/elements.h" |
8 #include "src/factory.h" | 8 #include "src/factory.h" |
9 #include "src/isolate-inl.h" | 9 #include "src/isolate-inl.h" |
10 #include "src/objects-inl.h" | 10 #include "src/objects-inl.h" |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 | 92 |
93 } // namespace | 93 } // namespace |
94 | 94 |
95 bool KeyAccumulator::AddKey(Object* key, AddKeyConversion convert) { | 95 bool KeyAccumulator::AddKey(Object* key, AddKeyConversion convert) { |
96 return AddKey(handle(key, isolate_), convert); | 96 return AddKey(handle(key, isolate_), convert); |
97 } | 97 } |
98 | 98 |
99 | 99 |
100 bool KeyAccumulator::AddKey(Handle<Object> key, AddKeyConversion convert) { | 100 bool KeyAccumulator::AddKey(Handle<Object> key, AddKeyConversion convert) { |
101 if (key->IsSymbol()) { | 101 if (key->IsSymbol()) { |
102 if (filter_ == SKIP_SYMBOLS) return false; | 102 if (filter_ & SKIP_SYMBOLS) return false; |
| 103 if (Handle<Symbol>::cast(key)->is_private()) return false; |
103 return AddSymbolKey(key); | 104 return AddSymbolKey(key); |
104 } | 105 } |
105 // Make sure we do not add keys to a proxy-level (see AddKeysFromProxy). | 106 // Make sure we do not add keys to a proxy-level (see AddKeysFromProxy). |
106 DCHECK_LE(0, level_string_length_); | 107 DCHECK_LE(0, level_string_length_); |
107 // In some cases (e.g. proxies) we might get in String-converted ints which | 108 // In some cases (e.g. proxies) we might get in String-converted ints which |
108 // should be added to the elements list instead of the properties. For | 109 // should be added to the elements list instead of the properties. For |
109 // proxies we have to convert as well but also respect the original order. | 110 // proxies we have to convert as well but also respect the original order. |
110 // Therefore we add a converted key to both sides | 111 // Therefore we add a converted key to both sides |
111 if (convert == CONVERT_TO_ARRAY_INDEX || convert == PROXY_MAGIC) { | 112 if (convert == CONVERT_TO_ARRAY_INDEX || convert == PROXY_MAGIC) { |
112 uint32_t index = 0; | 113 uint32_t index = 0; |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 AddKeys(array_like, PROXY_MAGIC); | 215 AddKeys(array_like, PROXY_MAGIC); |
215 // Invert the current length to indicate a present proxy, so we can ignore | 216 // Invert the current length to indicate a present proxy, so we can ignore |
216 // element keys for this level. Otherwise we would not fully respect the order | 217 // element keys for this level. Otherwise we would not fully respect the order |
217 // given by the proxy. | 218 // given by the proxy. |
218 level_string_length_ = -level_string_length_; | 219 level_string_length_ = -level_string_length_; |
219 } | 220 } |
220 | 221 |
221 | 222 |
222 MaybeHandle<FixedArray> FilterProxyKeys(Isolate* isolate, Handle<JSProxy> owner, | 223 MaybeHandle<FixedArray> FilterProxyKeys(Isolate* isolate, Handle<JSProxy> owner, |
223 Handle<FixedArray> keys, | 224 Handle<FixedArray> keys, |
224 KeyFilter filter, | 225 PropertyFilter filter) { |
225 Enumerability enum_policy) { | 226 if (filter == ALL_PROPERTIES) { |
226 if (filter == INCLUDE_SYMBOLS && enum_policy == IGNORE_ENUMERABILITY) { | |
227 // Nothing to do. | 227 // Nothing to do. |
228 return keys; | 228 return keys; |
229 } | 229 } |
230 int store_position = 0; | 230 int store_position = 0; |
231 for (int i = 0; i < keys->length(); ++i) { | 231 for (int i = 0; i < keys->length(); ++i) { |
232 Handle<Name> key(Name::cast(keys->get(i)), isolate); | 232 Handle<Name> key(Name::cast(keys->get(i)), isolate); |
233 if (filter == SKIP_SYMBOLS && key->IsSymbol()) continue; // Skip this key. | 233 if (key->IsSymbol()) { |
234 if (enum_policy == RESPECT_ENUMERABILITY) { | 234 if ((filter & SKIP_SYMBOLS) || Handle<Symbol>::cast(key)->is_private()) { |
| 235 continue; // Skip this key. |
| 236 } |
| 237 } |
| 238 if (filter & ONLY_ENUMERABLE) { |
235 PropertyDescriptor desc; | 239 PropertyDescriptor desc; |
236 bool found = | 240 bool found = |
237 JSProxy::GetOwnPropertyDescriptor(isolate, owner, key, &desc); | 241 JSProxy::GetOwnPropertyDescriptor(isolate, owner, key, &desc); |
238 if (isolate->has_pending_exception()) return MaybeHandle<FixedArray>(); | 242 if (isolate->has_pending_exception()) return MaybeHandle<FixedArray>(); |
239 if (!found || !desc.enumerable()) continue; // Skip this key. | 243 if (!found || !desc.enumerable()) continue; // Skip this key. |
240 } | 244 } |
241 // Keep this key. | 245 // Keep this key. |
242 if (store_position != i) { | 246 if (store_position != i) { |
243 keys->set(store_position, *key); | 247 keys->set(store_position, *key); |
244 } | 248 } |
245 store_position++; | 249 store_position++; |
246 } | 250 } |
247 if (store_position == 0) return isolate->factory()->empty_fixed_array(); | 251 if (store_position == 0) return isolate->factory()->empty_fixed_array(); |
248 keys->Shrink(store_position); | 252 keys->Shrink(store_position); |
249 return keys; | 253 return keys; |
250 } | 254 } |
251 | 255 |
252 | 256 |
253 // Returns "false" in case of exception, "true" on success. | 257 // Returns "false" in case of exception, "true" on success. |
254 bool KeyAccumulator::AddKeysFromProxy(Handle<JSProxy> proxy, | 258 bool KeyAccumulator::AddKeysFromProxy(Handle<JSProxy> proxy, |
255 Handle<FixedArray> keys, KeyFilter filter, | 259 Handle<FixedArray> keys) { |
256 Enumerability enum_policy) { | |
257 ASSIGN_RETURN_ON_EXCEPTION_VALUE( | 260 ASSIGN_RETURN_ON_EXCEPTION_VALUE( |
258 isolate_, keys, | 261 isolate_, keys, FilterProxyKeys(isolate_, proxy, keys, filter_), false); |
259 FilterProxyKeys(isolate_, proxy, keys, filter, enum_policy), false); | |
260 // Proxies define a complete list of keys with no distinction of | 262 // Proxies define a complete list of keys with no distinction of |
261 // elements and properties, which breaks the normal assumption for the | 263 // elements and properties, which breaks the normal assumption for the |
262 // KeyAccumulator. | 264 // KeyAccumulator. |
263 AddKeys(keys, PROXY_MAGIC); | 265 AddKeys(keys, PROXY_MAGIC); |
264 // Invert the current length to indicate a present proxy, so we can ignore | 266 // Invert the current length to indicate a present proxy, so we can ignore |
265 // element keys for this level. Otherwise we would not fully respect the order | 267 // element keys for this level. Otherwise we would not fully respect the order |
266 // given by the proxy. | 268 // given by the proxy. |
267 level_string_length_ = -level_string_length_; | 269 level_string_length_ = -level_string_length_; |
268 return true; | 270 return true; |
269 } | 271 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 level_lengths_.push_back(level_symbol_length_); | 308 level_lengths_.push_back(level_symbol_length_); |
307 } | 309 } |
308 elements_.push_back(new std::vector<uint32_t>()); | 310 elements_.push_back(new std::vector<uint32_t>()); |
309 level_string_length_ = 0; | 311 level_string_length_ = 0; |
310 level_symbol_length_ = 0; | 312 level_symbol_length_ = 0; |
311 } | 313 } |
312 | 314 |
313 | 315 |
314 } // namespace internal | 316 } // namespace internal |
315 } // namespace v8 | 317 } // namespace v8 |
OLD | NEW |