| 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 #include "src/elements.h" | 5 #include "src/elements.h" |
| 6 | 6 |
| 7 #include "src/arguments.h" | 7 #include "src/arguments.h" |
| 8 #include "src/conversions.h" | 8 #include "src/conversions.h" |
| 9 #include "src/factory.h" | 9 #include "src/factory.h" |
| 10 #include "src/isolate-inl.h" | 10 #include "src/isolate-inl.h" |
| (...skipping 868 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 879 PropertyFilter filter) { | 879 PropertyFilter filter) { |
| 880 return Subclass::CollectValuesOrEntriesImpl( | 880 return Subclass::CollectValuesOrEntriesImpl( |
| 881 isolate, object, values_or_entries, get_entries, nof_items, filter); | 881 isolate, object, values_or_entries, get_entries, nof_items, filter); |
| 882 } | 882 } |
| 883 | 883 |
| 884 static Maybe<bool> CollectValuesOrEntriesImpl( | 884 static Maybe<bool> CollectValuesOrEntriesImpl( |
| 885 Isolate* isolate, Handle<JSObject> object, | 885 Isolate* isolate, Handle<JSObject> object, |
| 886 Handle<FixedArray> values_or_entries, bool get_entries, int* nof_items, | 886 Handle<FixedArray> values_or_entries, bool get_entries, int* nof_items, |
| 887 PropertyFilter filter) { | 887 PropertyFilter filter) { |
| 888 int count = 0; | 888 int count = 0; |
| 889 KeyAccumulator accumulator(isolate, OWN_ONLY, ALL_PROPERTIES); | 889 KeyAccumulator accumulator(isolate, KeyCollectionMode::kOwnOnly, |
| 890 ALL_PROPERTIES); |
| 890 Subclass::CollectElementIndicesImpl( | 891 Subclass::CollectElementIndicesImpl( |
| 891 object, handle(object->elements(), isolate), &accumulator); | 892 object, handle(object->elements(), isolate), &accumulator); |
| 892 Handle<FixedArray> keys = accumulator.GetKeys(); | 893 Handle<FixedArray> keys = accumulator.GetKeys(); |
| 893 | 894 |
| 894 for (int i = 0; i < keys->length(); ++i) { | 895 for (int i = 0; i < keys->length(); ++i) { |
| 895 Handle<Object> key(keys->get(i), isolate); | 896 Handle<Object> key(keys->get(i), isolate); |
| 896 Handle<Object> value; | 897 Handle<Object> value; |
| 897 uint32_t index; | 898 uint32_t index; |
| 898 if (!key->ToUint32(&index)) continue; | 899 if (!key->ToUint32(&index)) continue; |
| 899 | 900 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 943 } | 944 } |
| 944 | 945 |
| 945 static Handle<FixedArray> DirectCollectElementIndicesImpl( | 946 static Handle<FixedArray> DirectCollectElementIndicesImpl( |
| 946 Isolate* isolate, Handle<JSObject> object, | 947 Isolate* isolate, Handle<JSObject> object, |
| 947 Handle<FixedArrayBase> backing_store, GetKeysConversion convert, | 948 Handle<FixedArrayBase> backing_store, GetKeysConversion convert, |
| 948 PropertyFilter filter, Handle<FixedArray> list, uint32_t* nof_indices, | 949 PropertyFilter filter, Handle<FixedArray> list, uint32_t* nof_indices, |
| 949 uint32_t insertion_index = 0) { | 950 uint32_t insertion_index = 0) { |
| 950 uint32_t length = Subclass::GetMaxIndex(*object, *backing_store); | 951 uint32_t length = Subclass::GetMaxIndex(*object, *backing_store); |
| 951 for (uint32_t i = 0; i < length; i++) { | 952 for (uint32_t i = 0; i < length; i++) { |
| 952 if (Subclass::HasElementImpl(object, i, backing_store, filter)) { | 953 if (Subclass::HasElementImpl(object, i, backing_store, filter)) { |
| 953 if (convert == CONVERT_TO_STRING) { | 954 if (convert == GetKeysConversion::kConvertToString) { |
| 954 Handle<String> index_string = isolate->factory()->Uint32ToString(i); | 955 Handle<String> index_string = isolate->factory()->Uint32ToString(i); |
| 955 list->set(insertion_index, *index_string); | 956 list->set(insertion_index, *index_string); |
| 956 } else { | 957 } else { |
| 957 list->set(insertion_index, Smi::FromInt(i), SKIP_WRITE_BARRIER); | 958 list->set(insertion_index, Smi::FromInt(i), SKIP_WRITE_BARRIER); |
| 958 } | 959 } |
| 959 insertion_index++; | 960 insertion_index++; |
| 960 } | 961 } |
| 961 } | 962 } |
| 962 *nof_indices = insertion_index; | 963 *nof_indices = insertion_index; |
| 963 return list; | 964 return list; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 989 combined_keys = Subclass::DirectCollectElementIndicesImpl( | 990 combined_keys = Subclass::DirectCollectElementIndicesImpl( |
| 990 isolate, object, backing_store, convert, filter, combined_keys, | 991 isolate, object, backing_store, convert, filter, combined_keys, |
| 991 &nof_indices); | 992 &nof_indices); |
| 992 | 993 |
| 993 // Sort the indices list if necessary. | 994 // Sort the indices list if necessary. |
| 994 if (IsDictionaryElementsKind(kind()) || IsSloppyArgumentsElements(kind())) { | 995 if (IsDictionaryElementsKind(kind()) || IsSloppyArgumentsElements(kind())) { |
| 995 SortIndices(combined_keys, nof_indices, SKIP_WRITE_BARRIER); | 996 SortIndices(combined_keys, nof_indices, SKIP_WRITE_BARRIER); |
| 996 uint32_t array_length = 0; | 997 uint32_t array_length = 0; |
| 997 // Indices from dictionary elements should only be converted after | 998 // Indices from dictionary elements should only be converted after |
| 998 // sorting. | 999 // sorting. |
| 999 if (convert == CONVERT_TO_STRING) { | 1000 if (convert == GetKeysConversion::kConvertToString) { |
| 1000 for (uint32_t i = 0; i < nof_indices; i++) { | 1001 for (uint32_t i = 0; i < nof_indices; i++) { |
| 1001 Handle<Object> index_string = isolate->factory()->Uint32ToString( | 1002 Handle<Object> index_string = isolate->factory()->Uint32ToString( |
| 1002 combined_keys->get(i)->Number()); | 1003 combined_keys->get(i)->Number()); |
| 1003 combined_keys->set(i, *index_string); | 1004 combined_keys->set(i, *index_string); |
| 1004 } | 1005 } |
| 1005 } else if (!(object->IsJSArray() && | 1006 } else if (!(object->IsJSArray() && |
| 1006 JSArray::cast(*object)->length()->ToArrayLength( | 1007 JSArray::cast(*object)->length()->ToArrayLength( |
| 1007 &array_length) && | 1008 &array_length) && |
| 1008 array_length <= Smi::kMaxValue)) { | 1009 array_length <= Smi::kMaxValue)) { |
| 1009 // Since we use std::sort above, the GC will no longer know where the | 1010 // Since we use std::sort above, the GC will no longer know where the |
| (...skipping 1392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2402 } | 2403 } |
| 2403 | 2404 |
| 2404 static void CollectElementIndicesImpl(Handle<JSObject> object, | 2405 static void CollectElementIndicesImpl(Handle<JSObject> object, |
| 2405 Handle<FixedArrayBase> backing_store, | 2406 Handle<FixedArrayBase> backing_store, |
| 2406 KeyAccumulator* keys) { | 2407 KeyAccumulator* keys) { |
| 2407 Isolate* isolate = keys->isolate(); | 2408 Isolate* isolate = keys->isolate(); |
| 2408 uint32_t nof_indices = 0; | 2409 uint32_t nof_indices = 0; |
| 2409 Handle<FixedArray> indices = isolate->factory()->NewFixedArray( | 2410 Handle<FixedArray> indices = isolate->factory()->NewFixedArray( |
| 2410 GetCapacityImpl(*object, *backing_store)); | 2411 GetCapacityImpl(*object, *backing_store)); |
| 2411 DirectCollectElementIndicesImpl(isolate, object, backing_store, | 2412 DirectCollectElementIndicesImpl(isolate, object, backing_store, |
| 2412 KEEP_NUMBERS, ENUMERABLE_STRINGS, indices, | 2413 GetKeysConversion::kKeepNumbers, |
| 2413 &nof_indices); | 2414 ENUMERABLE_STRINGS, indices, &nof_indices); |
| 2414 SortIndices(indices, nof_indices); | 2415 SortIndices(indices, nof_indices); |
| 2415 for (uint32_t i = 0; i < nof_indices; i++) { | 2416 for (uint32_t i = 0; i < nof_indices; i++) { |
| 2416 keys->AddKey(indices->get(i)); | 2417 keys->AddKey(indices->get(i)); |
| 2417 } | 2418 } |
| 2418 } | 2419 } |
| 2419 | 2420 |
| 2420 static Handle<FixedArray> DirectCollectElementIndicesImpl( | 2421 static Handle<FixedArray> DirectCollectElementIndicesImpl( |
| 2421 Isolate* isolate, Handle<JSObject> object, | 2422 Isolate* isolate, Handle<JSObject> object, |
| 2422 Handle<FixedArrayBase> backing_store, GetKeysConversion convert, | 2423 Handle<FixedArrayBase> backing_store, GetKeysConversion convert, |
| 2423 PropertyFilter filter, Handle<FixedArray> list, uint32_t* nof_indices, | 2424 PropertyFilter filter, Handle<FixedArray> list, uint32_t* nof_indices, |
| 2424 uint32_t insertion_index = 0) { | 2425 uint32_t insertion_index = 0) { |
| 2425 FixedArray* parameter_map = FixedArray::cast(*backing_store); | 2426 FixedArray* parameter_map = FixedArray::cast(*backing_store); |
| 2426 uint32_t length = parameter_map->length() - 2; | 2427 uint32_t length = parameter_map->length() - 2; |
| 2427 | 2428 |
| 2428 for (uint32_t i = 0; i < length; ++i) { | 2429 for (uint32_t i = 0; i < length; ++i) { |
| 2429 if (parameter_map->get(i + 2)->IsTheHole()) continue; | 2430 if (parameter_map->get(i + 2)->IsTheHole()) continue; |
| 2430 if (convert == CONVERT_TO_STRING) { | 2431 if (convert == GetKeysConversion::kConvertToString) { |
| 2431 Handle<String> index_string = isolate->factory()->Uint32ToString(i); | 2432 Handle<String> index_string = isolate->factory()->Uint32ToString(i); |
| 2432 list->set(insertion_index, *index_string); | 2433 list->set(insertion_index, *index_string); |
| 2433 } else { | 2434 } else { |
| 2434 list->set(insertion_index, Smi::FromInt(i), SKIP_WRITE_BARRIER); | 2435 list->set(insertion_index, Smi::FromInt(i), SKIP_WRITE_BARRIER); |
| 2435 } | 2436 } |
| 2436 insertion_index++; | 2437 insertion_index++; |
| 2437 } | 2438 } |
| 2438 | 2439 |
| 2439 Handle<FixedArrayBase> store(FixedArrayBase::cast(parameter_map->get(1))); | 2440 Handle<FixedArrayBase> store(FixedArrayBase::cast(parameter_map->get(1))); |
| 2440 return ArgumentsAccessor::DirectCollectElementIndicesImpl( | 2441 return ArgumentsAccessor::DirectCollectElementIndicesImpl( |
| (...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3041 insertion_index += len; | 3042 insertion_index += len; |
| 3042 } | 3043 } |
| 3043 | 3044 |
| 3044 DCHECK_EQ(insertion_index, result_len); | 3045 DCHECK_EQ(insertion_index, result_len); |
| 3045 return result_array; | 3046 return result_array; |
| 3046 } | 3047 } |
| 3047 | 3048 |
| 3048 ElementsAccessor** ElementsAccessor::elements_accessors_ = NULL; | 3049 ElementsAccessor** ElementsAccessor::elements_accessors_ = NULL; |
| 3049 } // namespace internal | 3050 } // namespace internal |
| 3050 } // namespace v8 | 3051 } // namespace v8 |
| OLD | NEW |