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

Side by Side Diff: src/objects.cc

Issue 1995263002: [keys] Simplify KeyAccumulator (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fix handle dereferencing Created 4 years, 6 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 | « src/objects.h ('k') | src/objects-inl.h » ('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 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 6161 matching lines...) Expand 10 before | Expand all | Expand 10 after
6172 Handle<JSReceiver> props; 6172 Handle<JSReceiver> props;
6173 if (!Object::ToObject(isolate, properties).ToHandle(&props)) { 6173 if (!Object::ToObject(isolate, properties).ToHandle(&props)) {
6174 THROW_NEW_ERROR(isolate, 6174 THROW_NEW_ERROR(isolate,
6175 NewTypeError(MessageTemplate::kUndefinedOrNullToObject), 6175 NewTypeError(MessageTemplate::kUndefinedOrNullToObject),
6176 Object); 6176 Object);
6177 } 6177 }
6178 // 4. Let keys be props.[[OwnPropertyKeys]](). 6178 // 4. Let keys be props.[[OwnPropertyKeys]]().
6179 // 5. ReturnIfAbrupt(keys). 6179 // 5. ReturnIfAbrupt(keys).
6180 Handle<FixedArray> keys; 6180 Handle<FixedArray> keys;
6181 ASSIGN_RETURN_ON_EXCEPTION( 6181 ASSIGN_RETURN_ON_EXCEPTION(
6182 isolate, keys, JSReceiver::GetKeys(props, OWN_ONLY, ALL_PROPERTIES), 6182 isolate, keys, KeyAccumulator::GetKeys(props, OWN_ONLY, ALL_PROPERTIES),
6183 Object); 6183 Object);
6184 // 6. Let descriptors be an empty List. 6184 // 6. Let descriptors be an empty List.
6185 int capacity = keys->length(); 6185 int capacity = keys->length();
6186 std::vector<PropertyDescriptor> descriptors(capacity); 6186 std::vector<PropertyDescriptor> descriptors(capacity);
6187 size_t descriptors_index = 0; 6187 size_t descriptors_index = 0;
6188 // 7. Repeat for each element nextKey of keys in List order, 6188 // 7. Repeat for each element nextKey of keys in List order,
6189 for (int i = 0; i < keys->length(); ++i) { 6189 for (int i = 0; i < keys->length(); ++i) {
6190 Handle<Object> next_key(keys->get(i), isolate); 6190 Handle<Object> next_key(keys->get(i), isolate);
6191 // 7a. Let propDesc be props.[[GetOwnProperty]](nextKey). 6191 // 7a. Let propDesc be props.[[GetOwnProperty]](nextKey).
6192 // 7b. ReturnIfAbrupt(propDesc). 6192 // 7b. ReturnIfAbrupt(propDesc).
(...skipping 1658 matching lines...) Expand 10 before | Expand all | Expand 10 after
7851 } 7851 }
7852 } 7852 }
7853 } 7853 }
7854 } else { 7854 } else {
7855 // Only deep copy fields from the object literal expression. 7855 // Only deep copy fields from the object literal expression.
7856 // In particular, don't try to copy the length attribute of 7856 // In particular, don't try to copy the length attribute of
7857 // an array. 7857 // an array.
7858 PropertyFilter filter = static_cast<PropertyFilter>( 7858 PropertyFilter filter = static_cast<PropertyFilter>(
7859 ONLY_WRITABLE | ONLY_ENUMERABLE | ONLY_CONFIGURABLE); 7859 ONLY_WRITABLE | ONLY_ENUMERABLE | ONLY_CONFIGURABLE);
7860 KeyAccumulator accumulator(isolate, OWN_ONLY, filter); 7860 KeyAccumulator accumulator(isolate, OWN_ONLY, filter);
7861 accumulator.NextPrototype(); 7861 accumulator.CollectOwnPropertyNames(copy, copy);
7862 accumulator.CollectOwnPropertyNames(copy);
7863 Handle<FixedArray> names = accumulator.GetKeys(); 7862 Handle<FixedArray> names = accumulator.GetKeys();
7864 for (int i = 0; i < names->length(); i++) { 7863 for (int i = 0; i < names->length(); i++) {
7865 DCHECK(names->get(i)->IsName()); 7864 DCHECK(names->get(i)->IsName());
7866 Handle<Name> name(Name::cast(names->get(i))); 7865 Handle<Name> name(Name::cast(names->get(i)));
7867 Handle<Object> value = 7866 Handle<Object> value =
7868 JSObject::GetProperty(copy, name).ToHandleChecked(); 7867 JSObject::GetProperty(copy, name).ToHandleChecked();
7869 if (value->IsJSObject()) { 7868 if (value->IsJSObject()) {
7870 Handle<JSObject> result; 7869 Handle<JSObject> result;
7871 ASSIGN_RETURN_ON_EXCEPTION( 7870 ASSIGN_RETURN_ON_EXCEPTION(
7872 isolate, result, 7871 isolate, result,
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
8157 8156
8158 8157
8159 bool Map::OnlyHasSimpleProperties() { 8158 bool Map::OnlyHasSimpleProperties() {
8160 // Wrapped string elements aren't explicitly stored in the elements backing 8159 // Wrapped string elements aren't explicitly stored in the elements backing
8161 // store, but are loaded indirectly from the underlying string. 8160 // store, but are loaded indirectly from the underlying string.
8162 return !IsStringWrapperElementsKind(elements_kind()) && 8161 return !IsStringWrapperElementsKind(elements_kind()) &&
8163 instance_type() > LAST_SPECIAL_RECEIVER_TYPE && 8162 instance_type() > LAST_SPECIAL_RECEIVER_TYPE &&
8164 !has_hidden_prototype() && !is_dictionary_map(); 8163 !has_hidden_prototype() && !is_dictionary_map();
8165 } 8164 }
8166 8165
8167 MaybeHandle<FixedArray> JSReceiver::GetKeys(Handle<JSReceiver> object,
8168 KeyCollectionType type,
8169 PropertyFilter filter,
8170 GetKeysConversion keys_conversion,
8171 bool filter_proxy_keys) {
8172 return KeyAccumulator::GetKeys(object, type, filter, keys_conversion,
8173 filter_proxy_keys);
8174 }
8175
8176 MUST_USE_RESULT Maybe<bool> FastGetOwnValuesOrEntries( 8166 MUST_USE_RESULT Maybe<bool> FastGetOwnValuesOrEntries(
8177 Isolate* isolate, Handle<JSReceiver> receiver, bool get_entries, 8167 Isolate* isolate, Handle<JSReceiver> receiver, bool get_entries,
8178 Handle<FixedArray>* result) { 8168 Handle<FixedArray>* result) {
8179 Handle<Map> map(JSReceiver::cast(*receiver)->map(), isolate); 8169 Handle<Map> map(JSReceiver::cast(*receiver)->map(), isolate);
8180 8170
8181 if (!map->IsJSObjectMap()) return Just(false); 8171 if (!map->IsJSObjectMap()) return Just(false);
8182 if (!map->OnlyHasSimpleProperties()) return Just(false); 8172 if (!map->OnlyHasSimpleProperties()) return Just(false);
8183 8173
8184 Handle<JSObject> object(JSObject::cast(*receiver)); 8174 Handle<JSObject> object(JSObject::cast(*receiver));
8185 8175
(...skipping 8996 matching lines...) Expand 10 before | Expand all | Expand 10 after
17182 if (!AccessorInfo::cast(accessors)->all_can_read()) continue; 17172 if (!AccessorInfo::cast(accessors)->all_can_read()) continue;
17183 } 17173 }
17184 array->set(array_size++, Smi::FromInt(i)); 17174 array->set(array_size++, Smi::FromInt(i));
17185 } 17175 }
17186 17176
17187 EnumIndexComparator<Derived> cmp(static_cast<Derived*>(raw_dict)); 17177 EnumIndexComparator<Derived> cmp(static_cast<Derived*>(raw_dict));
17188 Smi** start = reinterpret_cast<Smi**>(array->GetFirstElementAddress()); 17178 Smi** start = reinterpret_cast<Smi**>(array->GetFirstElementAddress());
17189 std::sort(start, start + array_size, cmp); 17179 std::sort(start, start + array_size, cmp);
17190 } 17180 }
17191 17181
17182 bool has_seen_symbol = false;
17192 for (int i = 0; i < array_size; i++) { 17183 for (int i = 0; i < array_size; i++) {
17193 int index = Smi::cast(array->get(i))->value(); 17184 int index = Smi::cast(array->get(i))->value();
17194 keys->AddKey(dictionary->KeyAt(index), DO_NOT_CONVERT); 17185 Object* key = dictionary->KeyAt(index);
17186 if (key->IsSymbol()) {
17187 has_seen_symbol = true;
17188 continue;
17189 }
17190 keys->AddKey(key, DO_NOT_CONVERT);
17191 }
17192 if (has_seen_symbol) {
17193 for (int i = 0; i < array_size; i++) {
17194 int index = Smi::cast(array->get(i))->value();
17195 Object* key = dictionary->KeyAt(index);
17196 if (!key->IsSymbol()) continue;
17197 keys->AddKey(key, DO_NOT_CONVERT);
17198 }
17195 } 17199 }
17196 } 17200 }
17197 17201
17198 17202
17199 // Backwards lookup (slow). 17203 // Backwards lookup (slow).
17200 template<typename Derived, typename Shape, typename Key> 17204 template<typename Derived, typename Shape, typename Key>
17201 Object* Dictionary<Derived, Shape, Key>::SlowReverseLookup(Object* value) { 17205 Object* Dictionary<Derived, Shape, Key>::SlowReverseLookup(Object* value) {
17202 int capacity = this->Capacity(); 17206 int capacity = this->Capacity();
17203 for (int i = 0; i < capacity; i++) { 17207 for (int i = 0; i < capacity; i++) {
17204 Object* k = this->KeyAt(i); 17208 Object* k = this->KeyAt(i);
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
17484 int new_entry = nof + table->NumberOfDeletedElements(); 17488 int new_entry = nof + table->NumberOfDeletedElements();
17485 int new_index = table->EntryToIndex(new_entry); 17489 int new_index = table->EntryToIndex(new_entry);
17486 table->set(new_index, *key); 17490 table->set(new_index, *key);
17487 table->set(new_index + kChainOffset, Smi::FromInt(previous_entry)); 17491 table->set(new_index + kChainOffset, Smi::FromInt(previous_entry));
17488 // and point the bucket to the new entry. 17492 // and point the bucket to the new entry.
17489 table->set(kHashTableStartIndex + bucket, Smi::FromInt(new_entry)); 17493 table->set(kHashTableStartIndex + bucket, Smi::FromInt(new_entry));
17490 table->SetNumberOfElements(nof + 1); 17494 table->SetNumberOfElements(nof + 1);
17491 return table; 17495 return table;
17492 } 17496 }
17493 17497
17498 Handle<FixedArray> OrderedHashSet::ConvertToKeysArray(
17499 Handle<OrderedHashSet> table, GetKeysConversion convert) {
17500 Isolate* isolate = table->GetIsolate();
17501 int length = table->NumberOfElements();
17502 int nof_buckets = table->NumberOfBuckets();
17503 // Convert the dictionary to a linear list.
17504 Handle<FixedArray> result = Handle<FixedArray>::cast(table);
17505 // From this point on table is no longer a valid OrderedHashSet.
17506 result->set_map(isolate->heap()->fixed_array_map());
17507 for (int i = 0; i < length; i++) {
17508 int index = kHashTableStartIndex + nof_buckets + (i * kEntrySize);
17509 Object* key = table->get(index);
17510 if (convert == CONVERT_TO_STRING && key->IsNumber()) {
17511 key = *isolate->factory()->NumberToString(handle(key, isolate));
17512 }
17513 result->set(i, key);
17514 }
17515 result->Shrink(length);
17516 return result;
17517 }
17494 17518
17495 template<class Derived, class Iterator, int entrysize> 17519 template<class Derived, class Iterator, int entrysize>
17496 Handle<Derived> OrderedHashTable<Derived, Iterator, entrysize>::Rehash( 17520 Handle<Derived> OrderedHashTable<Derived, Iterator, entrysize>::Rehash(
17497 Handle<Derived> table, int new_capacity) { 17521 Handle<Derived> table, int new_capacity) {
17498 Isolate* isolate = table->GetIsolate(); 17522 Isolate* isolate = table->GetIsolate();
17499 Heap* heap = isolate->heap(); 17523 Heap* heap = isolate->heap();
17500 DCHECK(!table->IsObsolete()); 17524 DCHECK(!table->IsObsolete());
17501 17525
17502 Handle<Derived> new_table = Allocate( 17526 Handle<Derived> new_table = Allocate(
17503 isolate, new_capacity, heap->InNewSpace(*table) ? NOT_TENURED : TENURED); 17527 isolate, new_capacity, heap->InNewSpace(*table) ? NOT_TENURED : TENURED);
(...skipping 937 matching lines...) Expand 10 before | Expand all | Expand 10 after
18441 if (cell->value() != *new_value) { 18465 if (cell->value() != *new_value) {
18442 cell->set_value(*new_value); 18466 cell->set_value(*new_value);
18443 Isolate* isolate = cell->GetIsolate(); 18467 Isolate* isolate = cell->GetIsolate();
18444 cell->dependent_code()->DeoptimizeDependentCodeGroup( 18468 cell->dependent_code()->DeoptimizeDependentCodeGroup(
18445 isolate, DependentCode::kPropertyCellChangedGroup); 18469 isolate, DependentCode::kPropertyCellChangedGroup);
18446 } 18470 }
18447 } 18471 }
18448 18472
18449 } // namespace internal 18473 } // namespace internal
18450 } // namespace v8 18474 } // namespace v8
OLDNEW
« no previous file with comments | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698