Commit 6b82acd4 authored by Sathya Gunasekaran's avatar Sathya Gunasekaran

[dict] Add ValueAt, PutValueAt, DetailsAt and PutDetailsAt

... to OrderedNameDict

Bug: v8:6443, v8:7569
Change-Id: Ic952c88e3256935391707032320913069020b045
Reviewed-on: https://chromium-review.googlesource.com/c/1329682Reviewed-by: 's avatarToon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57432}
parent d332ac22
......@@ -34,10 +34,42 @@ RootIndex SmallOrderedHashSet::GetMapRootIndex() {
}
inline Object* OrderedHashMap::ValueAt(int entry) {
DCHECK_LT(entry, this->UsedCapacity());
DCHECK_NE(entry, kNotFound);
DCHECK_LT(entry, UsedCapacity());
return get(EntryToIndex(entry) + kValueOffset);
}
inline Object* OrderedNameDictionary::ValueAt(int entry) {
DCHECK_NE(entry, kNotFound);
DCHECK_LT(entry, UsedCapacity());
return get(EntryToIndex(entry) + kValueOffset);
}
// Set the value for entry.
inline void OrderedNameDictionary::ValueAtPut(int entry, Object* value) {
DCHECK_NE(entry, kNotFound);
DCHECK_LT(entry, UsedCapacity());
this->set(EntryToIndex(entry) + kValueOffset, value);
}
// Returns the property details for the property at entry.
inline PropertyDetails OrderedNameDictionary::DetailsAt(int entry) {
DCHECK_NE(entry, kNotFound);
DCHECK_LT(entry, this->UsedCapacity());
// TODO(gsathya): Optimize the cast away.
return PropertyDetails(
Smi::cast(get(EntryToIndex(entry) + kPropertyDetailsOffset)));
}
// Set the details for entry.
inline void OrderedNameDictionary::DetailsAtPut(int entry,
PropertyDetails value) {
DCHECK_NE(entry, kNotFound);
DCHECK_LT(entry, this->UsedCapacity());
// TODO(gsathya): Optimize the cast away.
this->set(EntryToIndex(entry) + kPropertyDetailsOffset, value.AsSmi());
}
inline bool OrderedHashSet::Is(Handle<HeapObject> table) {
return table->IsOrderedHashSet();
}
......
......@@ -601,6 +601,18 @@ class OrderedNameDictionary
Handle<Object> value,
PropertyDetails details);
// Returns the value for entry.
inline Object* ValueAt(int entry);
// Set the value for entry.
inline void ValueAtPut(int entry, Object* value);
// Returns the property details for the property at entry.
inline PropertyDetails DetailsAt(int entry);
// Set the details for entry.
inline void DetailsAtPut(int entry, PropertyDetails value);
static HeapObject* GetEmpty(ReadOnlyRoots ro_roots);
static inline RootIndex GetMapRootIndex();
......
......@@ -1342,6 +1342,132 @@ TEST(OrderedNameDictionaryFindEntry) {
CHECK_NE(entry, OrderedNameDictionary::kNotFound);
}
TEST(OrderedNameDictionaryValueAtAndValueAtPut) {
LocalContext context;
Isolate* isolate = GetIsolateFrom(&context);
Factory* factory = isolate->factory();
HandleScope scope(isolate);
Handle<OrderedNameDictionary> dict = factory->NewOrderedNameDictionary();
Verify(isolate, dict);
CHECK_EQ(2, dict->NumberOfBuckets());
CHECK_EQ(0, dict->NumberOfElements());
Handle<String> key1 = isolate->factory()->InternalizeUtf8String("foo");
Handle<String> value = isolate->factory()->InternalizeUtf8String("foo");
CHECK(!OrderedNameDictionary::HasKey(isolate, *dict, *key1));
PropertyDetails details = PropertyDetails::Empty();
dict = OrderedNameDictionary::Add(isolate, dict, key1, value, details);
Verify(isolate, dict);
CHECK_EQ(2, dict->NumberOfBuckets());
CHECK_EQ(1, dict->NumberOfElements());
CHECK(OrderedNameDictionary::HasKey(isolate, *dict, *key1));
int entry = dict->FindEntry(isolate, *key1);
CHECK_NE(entry, OrderedNameDictionary::kNotFound);
Handle<Object> found = handle(dict->ValueAt(entry), isolate);
CHECK(found->SameValue(*value));
// Change the value
Handle<String> other_value = isolate->factory()->InternalizeUtf8String("foo");
dict->ValueAtPut(entry, *other_value);
entry = dict->FindEntry(isolate, *key1);
CHECK_NE(entry, OrderedNameDictionary::kNotFound);
found = handle(dict->ValueAt(entry), isolate);
CHECK(found->SameValue(*other_value));
Handle<Symbol> key2 = factory->NewSymbol();
CHECK(!OrderedNameDictionary::HasKey(isolate, *dict, *key2));
dict = OrderedNameDictionary::Add(isolate, dict, key2, value, details);
Verify(isolate, dict);
CHECK_EQ(2, dict->NumberOfBuckets());
CHECK_EQ(2, dict->NumberOfElements());
CHECK(OrderedNameDictionary::HasKey(isolate, *dict, *key1));
CHECK(OrderedNameDictionary::HasKey(isolate, *dict, *key2));
entry = dict->FindEntry(isolate, *key1);
CHECK_NE(entry, OrderedNameDictionary::kNotFound);
found = handle(dict->ValueAt(entry), isolate);
CHECK(found->SameValue(*other_value));
entry = dict->FindEntry(isolate, *key2);
CHECK_NE(entry, OrderedNameDictionary::kNotFound);
found = handle(dict->ValueAt(entry), isolate);
CHECK(found->SameValue(*value));
// Change the value
dict->ValueAtPut(entry, *other_value);
entry = dict->FindEntry(isolate, *key1);
CHECK_NE(entry, OrderedNameDictionary::kNotFound);
found = handle(dict->ValueAt(entry), isolate);
CHECK(found->SameValue(*other_value));
}
TEST(OrderedNameDictionaryDetailsAtAndDetailsAtPut) {
LocalContext context;
Isolate* isolate = GetIsolateFrom(&context);
Factory* factory = isolate->factory();
HandleScope scope(isolate);
Handle<OrderedNameDictionary> dict = factory->NewOrderedNameDictionary();
Verify(isolate, dict);
CHECK_EQ(2, dict->NumberOfBuckets());
CHECK_EQ(0, dict->NumberOfElements());
Handle<String> key1 = isolate->factory()->InternalizeUtf8String("foo");
Handle<String> value = isolate->factory()->InternalizeUtf8String("foo");
CHECK(!OrderedNameDictionary::HasKey(isolate, *dict, *key1));
PropertyDetails details = PropertyDetails::Empty();
dict = OrderedNameDictionary::Add(isolate, dict, key1, value, details);
Verify(isolate, dict);
CHECK_EQ(2, dict->NumberOfBuckets());
CHECK_EQ(1, dict->NumberOfElements());
CHECK(OrderedNameDictionary::HasKey(isolate, *dict, *key1));
int entry = dict->FindEntry(isolate, *key1);
CHECK_NE(entry, OrderedNameDictionary::kNotFound);
PropertyDetails found = dict->DetailsAt(entry);
CHECK_EQ(PropertyDetails::Empty().AsSmi(), found.AsSmi());
PropertyDetails other =
PropertyDetails(kAccessor, READ_ONLY, PropertyCellType::kNoCell);
dict->DetailsAtPut(entry, other);
found = dict->DetailsAt(entry);
CHECK_NE(PropertyDetails::Empty().AsSmi(), found.AsSmi());
CHECK_EQ(other.AsSmi(), found.AsSmi());
Handle<Symbol> key2 = factory->NewSymbol();
CHECK(!OrderedNameDictionary::HasKey(isolate, *dict, *key2));
dict = OrderedNameDictionary::Add(isolate, dict, key2, value, details);
Verify(isolate, dict);
CHECK_EQ(2, dict->NumberOfBuckets());
CHECK_EQ(2, dict->NumberOfElements());
CHECK(OrderedNameDictionary::HasKey(isolate, *dict, *key1));
CHECK(OrderedNameDictionary::HasKey(isolate, *dict, *key2));
entry = dict->FindEntry(isolate, *key1);
CHECK_NE(entry, OrderedNameDictionary::kNotFound);
found = dict->DetailsAt(entry);
CHECK_EQ(other.AsSmi(), found.AsSmi());
entry = dict->FindEntry(isolate, *key2);
CHECK_EQ(other.AsSmi(), found.AsSmi());
dict->DetailsAtPut(entry, other);
found = dict->DetailsAt(entry);
CHECK_NE(PropertyDetails::Empty().AsSmi(), found.AsSmi());
CHECK_EQ(other.AsSmi(), found.AsSmi());
}
} // namespace test_orderedhashtable
} // namespace internal
} // namespace v8
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment