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/objects.h" | 5 #include "src/objects.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 #include <iomanip> | 8 #include <iomanip> |
9 #include <sstream> | 9 #include <sstream> |
10 | 10 |
(...skipping 15079 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15090 } else if (IsJSGlobalObject()) { | 15090 } else if (IsJSGlobalObject()) { |
15091 return global_dictionary()->CopyKeysTo(storage, index, filter, | 15091 return global_dictionary()->CopyKeysTo(storage, index, filter, |
15092 GlobalDictionary::UNSORTED); | 15092 GlobalDictionary::UNSORTED); |
15093 } else { | 15093 } else { |
15094 return property_dictionary()->CopyKeysTo(storage, index, filter, | 15094 return property_dictionary()->CopyKeysTo(storage, index, filter, |
15095 NameDictionary::UNSORTED); | 15095 NameDictionary::UNSORTED); |
15096 } | 15096 } |
15097 } | 15097 } |
15098 | 15098 |
15099 | 15099 |
15100 int JSObject::CollectOwnPropertyNames(KeyAccumulator* keys, | 15100 void JSObject::CollectOwnPropertyNames(KeyAccumulator* keys, |
15101 PropertyAttributes filter) { | 15101 PropertyAttributes filter) { |
15102 if (HasFastProperties()) { | 15102 if (HasFastProperties()) { |
15103 int nof_keys = keys->length(); | |
15104 int real_size = map()->NumberOfOwnDescriptors(); | 15103 int real_size = map()->NumberOfOwnDescriptors(); |
15105 Handle<DescriptorArray> descs(map()->instance_descriptors()); | 15104 Handle<DescriptorArray> descs(map()->instance_descriptors()); |
15106 for (int i = 0; i < real_size; i++) { | 15105 for (int i = 0; i < real_size; i++) { |
15107 if ((descs->GetDetails(i).attributes() & filter) != 0) continue; | 15106 if ((descs->GetDetails(i).attributes() & filter) != 0) continue; |
15108 Name* key = descs->GetKey(i); | 15107 Name* key = descs->GetKey(i); |
15109 if (key->FilterKey(filter)) continue; | 15108 if (key->FilterKey(filter)) continue; |
15110 keys->AddKey(key); | 15109 keys->AddKey(key); |
15111 } | 15110 } |
15112 return nof_keys - keys->length(); | |
15113 } else if (IsJSGlobalObject()) { | 15111 } else if (IsJSGlobalObject()) { |
15114 return global_dictionary()->CollectKeysTo(keys, filter); | 15112 global_dictionary()->CollectKeysTo(keys, filter); |
15115 } else { | 15113 } else { |
15116 return property_dictionary()->CollectKeysTo(keys, filter); | 15114 property_dictionary()->CollectKeysTo(keys, filter); |
15117 } | 15115 } |
15118 } | 15116 } |
15119 | 15117 |
15120 | 15118 |
15121 int JSObject::NumberOfOwnElements(PropertyAttributes filter) { | 15119 int JSObject::NumberOfOwnElements(PropertyAttributes filter) { |
15122 // Fast case for objects with no elements. | 15120 // Fast case for objects with no elements. |
15123 if (!IsJSValue() && HasFastElements()) { | 15121 if (!IsJSValue() && HasFastElements()) { |
15124 uint32_t length = | 15122 uint32_t length = |
15125 IsJSArray() | 15123 IsJSArray() |
15126 ? static_cast<uint32_t>( | 15124 ? static_cast<uint32_t>( |
(...skipping 1770 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16897 } | 16895 } |
16898 if (sort_mode == Dictionary::SORTED) { | 16896 if (sort_mode == Dictionary::SORTED) { |
16899 storage->SortPairs(storage, index); | 16897 storage->SortPairs(storage, index); |
16900 } | 16898 } |
16901 DCHECK(storage->length() >= index); | 16899 DCHECK(storage->length() >= index); |
16902 return index - start_index; | 16900 return index - start_index; |
16903 } | 16901 } |
16904 | 16902 |
16905 | 16903 |
16906 template <typename Derived, typename Shape, typename Key> | 16904 template <typename Derived, typename Shape, typename Key> |
16907 int Dictionary<Derived, Shape, Key>::CollectKeysTo(KeyAccumulator* keys, | 16905 void Dictionary<Derived, Shape, Key>::CollectKeysTo(KeyAccumulator* keys, |
16908 PropertyAttributes filter) { | 16906 PropertyAttributes filter) { |
16909 int capacity = this->Capacity(); | 16907 int capacity = this->Capacity(); |
16910 int keyLength = keys->length(); | 16908 Handle<FixedArray> array = |
| 16909 keys->isolate()->factory()->NewFixedArray(this->NumberOfElements()); |
| 16910 int array_size = 0; |
| 16911 |
16911 for (int i = 0; i < capacity; i++) { | 16912 for (int i = 0; i < capacity; i++) { |
16912 Object* k = this->KeyAt(i); | 16913 Object* k = this->KeyAt(i); |
16913 if (!this->IsKey(k) || k->FilterKey(filter)) continue; | 16914 if (!this->IsKey(k) || k->FilterKey(filter)) continue; |
16914 if (this->IsDeleted(i)) continue; | 16915 if (this->IsDeleted(i)) continue; |
16915 PropertyDetails details = this->DetailsAt(i); | 16916 PropertyDetails details = this->DetailsAt(i); |
16916 PropertyAttributes attr = details.attributes(); | 16917 PropertyAttributes attr = details.attributes(); |
16917 if ((attr & filter) != 0) continue; | 16918 if ((attr & filter) != 0) continue; |
16918 keys->AddKey(k); | 16919 array->set(array_size++, Smi::FromInt(i)); |
16919 } | 16920 } |
16920 return keyLength - keys->length(); | 16921 |
| 16922 EnumIndexComparator<Derived> cmp(static_cast<Derived*>(this)); |
| 16923 Smi** start = reinterpret_cast<Smi**>(array->GetFirstElementAddress()); |
| 16924 std::sort(start, start + array_size, cmp); |
| 16925 for (int i = 0; i < array_size; i++) { |
| 16926 int index = Smi::cast(array->get(i))->value(); |
| 16927 keys->AddKey(this->KeyAt(index)); |
| 16928 } |
16921 } | 16929 } |
16922 | 16930 |
16923 | 16931 |
16924 // Backwards lookup (slow). | 16932 // Backwards lookup (slow). |
16925 template<typename Derived, typename Shape, typename Key> | 16933 template<typename Derived, typename Shape, typename Key> |
16926 Object* Dictionary<Derived, Shape, Key>::SlowReverseLookup(Object* value) { | 16934 Object* Dictionary<Derived, Shape, Key>::SlowReverseLookup(Object* value) { |
16927 int capacity = this->Capacity(); | 16935 int capacity = this->Capacity(); |
16928 for (int i = 0; i < capacity; i++) { | 16936 for (int i = 0; i < capacity; i++) { |
16929 Object* k = this->KeyAt(i); | 16937 Object* k = this->KeyAt(i); |
16930 if (this->IsKey(k)) { | 16938 if (this->IsKey(k)) { |
(...skipping 1192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
18123 if (cell->value() != *new_value) { | 18131 if (cell->value() != *new_value) { |
18124 cell->set_value(*new_value); | 18132 cell->set_value(*new_value); |
18125 Isolate* isolate = cell->GetIsolate(); | 18133 Isolate* isolate = cell->GetIsolate(); |
18126 cell->dependent_code()->DeoptimizeDependentCodeGroup( | 18134 cell->dependent_code()->DeoptimizeDependentCodeGroup( |
18127 isolate, DependentCode::kPropertyCellChangedGroup); | 18135 isolate, DependentCode::kPropertyCellChangedGroup); |
18128 } | 18136 } |
18129 } | 18137 } |
18130 | 18138 |
18131 } // namespace internal | 18139 } // namespace internal |
18132 } // namespace v8 | 18140 } // namespace v8 |
OLD | NEW |