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

Unified Diff: test/cctest/test-dictionary.cc

Issue 2081733002: [keys] support shadowing keys in the KeyAccumulator (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: rebasing 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/objects-inl.h ('k') | test/mjsunit/for-in.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-dictionary.cc
diff --git a/test/cctest/test-dictionary.cc b/test/cctest/test-dictionary.cc
index 28adc7b4d34d60378213fa0e7124e40620561f0d..0756de6c1d783dc724c3e5c186a946886bbc7901 100644
--- a/test/cctest/test-dictionary.cc
+++ b/test/cctest/test-dictionary.cc
@@ -113,6 +113,74 @@ TEST(HashMap) {
TestHashMap(ObjectHashTable::New(isolate, 23));
}
+template <typename HashSet>
+static void TestHashSet(Handle<HashSet> table) {
+ Isolate* isolate = CcTest::i_isolate();
+ Factory* factory = isolate->factory();
+
+ Handle<JSObject> a = factory->NewJSArray(7);
+ Handle<JSObject> b = factory->NewJSArray(11);
+ table = HashSet::Add(table, a);
+ CHECK_EQ(table->NumberOfElements(), 1);
+ CHECK(table->Has(isolate, a));
+ CHECK(!table->Has(isolate, b));
+
+ // Keys still have to be valid after objects were moved.
+ CcTest::heap()->CollectGarbage(NEW_SPACE);
+ CHECK_EQ(table->NumberOfElements(), 1);
+ CHECK(table->Has(isolate, a));
+ CHECK(!table->Has(isolate, b));
+
+ // Keys that are overwritten should not change number of elements.
+ table = HashSet::Add(table, a);
+ CHECK_EQ(table->NumberOfElements(), 1);
+ CHECK(table->Has(isolate, a));
+ CHECK(!table->Has(isolate, b));
+
+ // Keys that have been removed are mapped to the hole.
+ // TODO(cbruni): not implemented yet.
+ // bool was_present = false;
+ // table = HashSet::Remove(table, a, &was_present);
+ // CHECK(was_present);
+ // CHECK_EQ(table->NumberOfElements(), 0);
+ // CHECK(!table->Has(a));
+ // CHECK(!table->Has(b));
+
+ // Keys should map back to their respective values and also should get
+ // an identity hash code generated.
+ for (int i = 0; i < 100; i++) {
+ Handle<JSReceiver> key = factory->NewJSArray(7);
+ table = HashSet::Add(table, key);
+ CHECK_EQ(table->NumberOfElements(), i + 2);
+ CHECK(table->Has(isolate, key));
+ CHECK(JSReceiver::GetIdentityHash(isolate, key)->IsSmi());
+ }
+
+ // Keys never added to the map which already have an identity hash
+ // code should not be found.
+ for (int i = 0; i < 100; i++) {
+ Handle<JSReceiver> key = factory->NewJSArray(7);
+ CHECK(JSReceiver::GetOrCreateIdentityHash(isolate, key)->IsSmi());
+ CHECK(!table->Has(isolate, key));
+ CHECK(JSReceiver::GetIdentityHash(isolate, key)->IsSmi());
+ }
+
+ // Keys that don't have an identity hash should not be found and also
+ // should not get an identity hash code generated.
+ for (int i = 0; i < 100; i++) {
+ Handle<JSReceiver> key = factory->NewJSArray(7);
+ CHECK(!table->Has(isolate, key));
+ Object* identity_hash = JSReceiver::GetIdentityHash(isolate, key);
+ CHECK_EQ(CcTest::heap()->undefined_value(), identity_hash);
+ }
+}
+
+TEST(HashSet) {
+ LocalContext context;
+ v8::HandleScope scope(context->GetIsolate());
+ Isolate* isolate = CcTest::i_isolate();
+ TestHashSet(ObjectHashSet::New(isolate, 23));
+}
class ObjectHashTableTest: public ObjectHashTable {
public:
« no previous file with comments | « src/objects-inl.h ('k') | test/mjsunit/for-in.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698