OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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 6162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6173 Handle<JSReceiver> props; | 6173 Handle<JSReceiver> props; |
6174 if (!Object::ToObject(isolate, properties).ToHandle(&props)) { | 6174 if (!Object::ToObject(isolate, properties).ToHandle(&props)) { |
6175 THROW_NEW_ERROR(isolate, | 6175 THROW_NEW_ERROR(isolate, |
6176 NewTypeError(MessageTemplate::kUndefinedOrNullToObject), | 6176 NewTypeError(MessageTemplate::kUndefinedOrNullToObject), |
6177 Object); | 6177 Object); |
6178 } | 6178 } |
6179 // 4. Let keys be props.[[OwnPropertyKeys]](). | 6179 // 4. Let keys be props.[[OwnPropertyKeys]](). |
6180 // 5. ReturnIfAbrupt(keys). | 6180 // 5. ReturnIfAbrupt(keys). |
6181 Handle<FixedArray> keys; | 6181 Handle<FixedArray> keys; |
6182 ASSIGN_RETURN_ON_EXCEPTION( | 6182 ASSIGN_RETURN_ON_EXCEPTION( |
6183 isolate, keys, JSReceiver::GetKeys(props, OWN_ONLY, ALL_PROPERTIES), | 6183 isolate, keys, KeyAccumulator::GetKeys(props, OWN_ONLY, ALL_PROPERTIES), |
6184 Object); | 6184 Object); |
6185 // 6. Let descriptors be an empty List. | 6185 // 6. Let descriptors be an empty List. |
6186 int capacity = keys->length(); | 6186 int capacity = keys->length(); |
6187 std::vector<PropertyDescriptor> descriptors(capacity); | 6187 std::vector<PropertyDescriptor> descriptors(capacity); |
6188 size_t descriptors_index = 0; | 6188 size_t descriptors_index = 0; |
6189 // 7. Repeat for each element nextKey of keys in List order, | 6189 // 7. Repeat for each element nextKey of keys in List order, |
6190 for (int i = 0; i < keys->length(); ++i) { | 6190 for (int i = 0; i < keys->length(); ++i) { |
6191 Handle<Object> next_key(keys->get(i), isolate); | 6191 Handle<Object> next_key(keys->get(i), isolate); |
6192 // 7a. Let propDesc be props.[[GetOwnProperty]](nextKey). | 6192 // 7a. Let propDesc be props.[[GetOwnProperty]](nextKey). |
6193 // 7b. ReturnIfAbrupt(propDesc). | 6193 // 7b. ReturnIfAbrupt(propDesc). |
(...skipping 1658 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7852 } | 7852 } |
7853 } | 7853 } |
7854 } | 7854 } |
7855 } else { | 7855 } else { |
7856 // Only deep copy fields from the object literal expression. | 7856 // Only deep copy fields from the object literal expression. |
7857 // In particular, don't try to copy the length attribute of | 7857 // In particular, don't try to copy the length attribute of |
7858 // an array. | 7858 // an array. |
7859 PropertyFilter filter = static_cast<PropertyFilter>( | 7859 PropertyFilter filter = static_cast<PropertyFilter>( |
7860 ONLY_WRITABLE | ONLY_ENUMERABLE | ONLY_CONFIGURABLE); | 7860 ONLY_WRITABLE | ONLY_ENUMERABLE | ONLY_CONFIGURABLE); |
7861 KeyAccumulator accumulator(isolate, OWN_ONLY, filter); | 7861 KeyAccumulator accumulator(isolate, OWN_ONLY, filter); |
7862 accumulator.NextPrototype(); | 7862 accumulator.CollectOwnPropertyNames(copy, copy); |
7863 accumulator.CollectOwnPropertyNames(copy); | |
7864 Handle<FixedArray> names = accumulator.GetKeys(); | 7863 Handle<FixedArray> names = accumulator.GetKeys(); |
7865 for (int i = 0; i < names->length(); i++) { | 7864 for (int i = 0; i < names->length(); i++) { |
7866 DCHECK(names->get(i)->IsName()); | 7865 DCHECK(names->get(i)->IsName()); |
7867 Handle<Name> name(Name::cast(names->get(i))); | 7866 Handle<Name> name(Name::cast(names->get(i))); |
7868 Handle<Object> value = | 7867 Handle<Object> value = |
7869 JSObject::GetProperty(copy, name).ToHandleChecked(); | 7868 JSObject::GetProperty(copy, name).ToHandleChecked(); |
7870 if (value->IsJSObject()) { | 7869 if (value->IsJSObject()) { |
7871 Handle<JSObject> result; | 7870 Handle<JSObject> result; |
7872 ASSIGN_RETURN_ON_EXCEPTION( | 7871 ASSIGN_RETURN_ON_EXCEPTION( |
7873 isolate, result, | 7872 isolate, result, |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8158 | 8157 |
8159 | 8158 |
8160 bool Map::OnlyHasSimpleProperties() { | 8159 bool Map::OnlyHasSimpleProperties() { |
8161 // Wrapped string elements aren't explicitly stored in the elements backing | 8160 // Wrapped string elements aren't explicitly stored in the elements backing |
8162 // store, but are loaded indirectly from the underlying string. | 8161 // store, but are loaded indirectly from the underlying string. |
8163 return !IsStringWrapperElementsKind(elements_kind()) && | 8162 return !IsStringWrapperElementsKind(elements_kind()) && |
8164 instance_type() > LAST_SPECIAL_RECEIVER_TYPE && | 8163 instance_type() > LAST_SPECIAL_RECEIVER_TYPE && |
8165 !has_hidden_prototype() && !is_dictionary_map(); | 8164 !has_hidden_prototype() && !is_dictionary_map(); |
8166 } | 8165 } |
8167 | 8166 |
8168 MaybeHandle<FixedArray> JSReceiver::GetKeys(Handle<JSReceiver> object, | |
8169 KeyCollectionType type, | |
8170 PropertyFilter filter, | |
8171 GetKeysConversion keys_conversion, | |
8172 bool filter_proxy_keys) { | |
8173 return KeyAccumulator::GetKeys(object, type, filter, keys_conversion, | |
8174 filter_proxy_keys); | |
8175 } | |
8176 | |
8177 MUST_USE_RESULT Maybe<bool> FastGetOwnValuesOrEntries( | 8167 MUST_USE_RESULT Maybe<bool> FastGetOwnValuesOrEntries( |
8178 Isolate* isolate, Handle<JSReceiver> receiver, bool get_entries, | 8168 Isolate* isolate, Handle<JSReceiver> receiver, bool get_entries, |
8179 Handle<FixedArray>* result) { | 8169 Handle<FixedArray>* result) { |
8180 Handle<Map> map(JSReceiver::cast(*receiver)->map(), isolate); | 8170 Handle<Map> map(JSReceiver::cast(*receiver)->map(), isolate); |
8181 | 8171 |
8182 if (!map->IsJSObjectMap()) return Just(false); | 8172 if (!map->IsJSObjectMap()) return Just(false); |
8183 if (!map->OnlyHasSimpleProperties()) return Just(false); | 8173 if (!map->OnlyHasSimpleProperties()) return Just(false); |
8184 | 8174 |
8185 Handle<JSObject> object(JSObject::cast(*receiver)); | 8175 Handle<JSObject> object(JSObject::cast(*receiver)); |
8186 | 8176 |
(...skipping 8947 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
17134 if (!AccessorInfo::cast(accessors)->all_can_read()) continue; | 17124 if (!AccessorInfo::cast(accessors)->all_can_read()) continue; |
17135 } | 17125 } |
17136 array->set(array_size++, Smi::FromInt(i)); | 17126 array->set(array_size++, Smi::FromInt(i)); |
17137 } | 17127 } |
17138 | 17128 |
17139 EnumIndexComparator<Derived> cmp(static_cast<Derived*>(raw_dict)); | 17129 EnumIndexComparator<Derived> cmp(static_cast<Derived*>(raw_dict)); |
17140 Smi** start = reinterpret_cast<Smi**>(array->GetFirstElementAddress()); | 17130 Smi** start = reinterpret_cast<Smi**>(array->GetFirstElementAddress()); |
17141 std::sort(start, start + array_size, cmp); | 17131 std::sort(start, start + array_size, cmp); |
17142 } | 17132 } |
17143 | 17133 |
| 17134 bool has_seen_symbol = false; |
17144 for (int i = 0; i < array_size; i++) { | 17135 for (int i = 0; i < array_size; i++) { |
17145 int index = Smi::cast(array->get(i))->value(); | 17136 int index = Smi::cast(array->get(i))->value(); |
17146 keys->AddKey(dictionary->KeyAt(index), DO_NOT_CONVERT); | 17137 Object* key = dictionary->KeyAt(index); |
| 17138 if (key->IsSymbol()) { |
| 17139 has_seen_symbol = true; |
| 17140 continue; |
| 17141 } |
| 17142 keys->AddKey(key, DO_NOT_CONVERT); |
| 17143 } |
| 17144 if (has_seen_symbol) { |
| 17145 for (int i = 0; i < array_size; i++) { |
| 17146 int index = Smi::cast(array->get(i))->value(); |
| 17147 Object* key = dictionary->KeyAt(index); |
| 17148 if (!key->IsSymbol()) continue; |
| 17149 keys->AddKey(key, DO_NOT_CONVERT); |
| 17150 } |
17147 } | 17151 } |
17148 } | 17152 } |
17149 | 17153 |
17150 | 17154 |
17151 // Backwards lookup (slow). | 17155 // Backwards lookup (slow). |
17152 template<typename Derived, typename Shape, typename Key> | 17156 template<typename Derived, typename Shape, typename Key> |
17153 Object* Dictionary<Derived, Shape, Key>::SlowReverseLookup(Object* value) { | 17157 Object* Dictionary<Derived, Shape, Key>::SlowReverseLookup(Object* value) { |
17154 int capacity = this->Capacity(); | 17158 int capacity = this->Capacity(); |
17155 for (int i = 0; i < capacity; i++) { | 17159 for (int i = 0; i < capacity; i++) { |
17156 Object* k = this->KeyAt(i); | 17160 Object* k = this->KeyAt(i); |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
17436 int new_entry = nof + table->NumberOfDeletedElements(); | 17440 int new_entry = nof + table->NumberOfDeletedElements(); |
17437 int new_index = table->EntryToIndex(new_entry); | 17441 int new_index = table->EntryToIndex(new_entry); |
17438 table->set(new_index, *key); | 17442 table->set(new_index, *key); |
17439 table->set(new_index + kChainOffset, Smi::FromInt(previous_entry)); | 17443 table->set(new_index + kChainOffset, Smi::FromInt(previous_entry)); |
17440 // and point the bucket to the new entry. | 17444 // and point the bucket to the new entry. |
17441 table->set(kHashTableStartIndex + bucket, Smi::FromInt(new_entry)); | 17445 table->set(kHashTableStartIndex + bucket, Smi::FromInt(new_entry)); |
17442 table->SetNumberOfElements(nof + 1); | 17446 table->SetNumberOfElements(nof + 1); |
17443 return table; | 17447 return table; |
17444 } | 17448 } |
17445 | 17449 |
| 17450 Handle<FixedArray> OrderedHashSet::ConvertToKeysArray( |
| 17451 Handle<OrderedHashSet> table, GetKeysConversion convert) { |
| 17452 Isolate* isolate = table->GetIsolate(); |
| 17453 int length = table->NumberOfElements(); |
| 17454 int nof_buckets = table->NumberOfBuckets(); |
| 17455 // Convert the dictionary to a linear list. |
| 17456 Handle<FixedArray> result = Handle<FixedArray>::cast(table); |
| 17457 // From this point on table is no longer a valid OrderedHashSet. |
| 17458 result->set_map_no_write_barrier(isolate->heap()->fixed_array_map()); |
| 17459 for (int i = 0; i < length; i++) { |
| 17460 int index = kHashTableStartIndex + nof_buckets + (i * kEntrySize); |
| 17461 Object* key = table->get(index); |
| 17462 if (convert == CONVERT_TO_STRING && key->IsNumber()) { |
| 17463 key = *isolate->factory()->NumberToString(handle(key, isolate)); |
| 17464 } |
| 17465 result->set(i, key); |
| 17466 } |
| 17467 result->Shrink(length); |
| 17468 return result; |
| 17469 } |
17446 | 17470 |
17447 template<class Derived, class Iterator, int entrysize> | 17471 template<class Derived, class Iterator, int entrysize> |
17448 Handle<Derived> OrderedHashTable<Derived, Iterator, entrysize>::Rehash( | 17472 Handle<Derived> OrderedHashTable<Derived, Iterator, entrysize>::Rehash( |
17449 Handle<Derived> table, int new_capacity) { | 17473 Handle<Derived> table, int new_capacity) { |
17450 Isolate* isolate = table->GetIsolate(); | 17474 Isolate* isolate = table->GetIsolate(); |
17451 Heap* heap = isolate->heap(); | 17475 Heap* heap = isolate->heap(); |
17452 DCHECK(!table->IsObsolete()); | 17476 DCHECK(!table->IsObsolete()); |
17453 | 17477 |
17454 Handle<Derived> new_table = Allocate( | 17478 Handle<Derived> new_table = Allocate( |
17455 isolate, new_capacity, heap->InNewSpace(*table) ? NOT_TENURED : TENURED); | 17479 isolate, new_capacity, heap->InNewSpace(*table) ? NOT_TENURED : TENURED); |
(...skipping 937 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
18393 if (cell->value() != *new_value) { | 18417 if (cell->value() != *new_value) { |
18394 cell->set_value(*new_value); | 18418 cell->set_value(*new_value); |
18395 Isolate* isolate = cell->GetIsolate(); | 18419 Isolate* isolate = cell->GetIsolate(); |
18396 cell->dependent_code()->DeoptimizeDependentCodeGroup( | 18420 cell->dependent_code()->DeoptimizeDependentCodeGroup( |
18397 isolate, DependentCode::kPropertyCellChangedGroup); | 18421 isolate, DependentCode::kPropertyCellChangedGroup); |
18398 } | 18422 } |
18399 } | 18423 } |
18400 | 18424 |
18401 } // namespace internal | 18425 } // namespace internal |
18402 } // namespace v8 | 18426 } // namespace v8 |
OLD | NEW |