diff options
author | Timothy J Fontaine <tjfontaine@gmail.com> | 2013-10-22 15:14:25 -0700 |
---|---|---|
committer | Timothy J Fontaine <tjfontaine@gmail.com> | 2013-10-23 09:17:31 -0700 |
commit | a53c763c16eeabb0901a05dbcf38a72fa96d2f26 (patch) | |
tree | 309bf250e1521cedf0e945d7a7629db511e64498 /deps/v8/test/cctest/test-dictionary.cc | |
parent | 54910044b33a6405c72ad085915a55c575c027fc (diff) | |
download | node-new-a53c763c16eeabb0901a05dbcf38a72fa96d2f26.tar.gz |
v8: upgrade 3.21.18.3
Diffstat (limited to 'deps/v8/test/cctest/test-dictionary.cc')
-rw-r--r-- | deps/v8/test/cctest/test-dictionary.cc | 57 |
1 files changed, 54 insertions, 3 deletions
diff --git a/deps/v8/test/cctest/test-dictionary.cc b/deps/v8/test/cctest/test-dictionary.cc index 2bdf235524..b9e8b1ec06 100644 --- a/deps/v8/test/cctest/test-dictionary.cc +++ b/deps/v8/test/cctest/test-dictionary.cc @@ -72,7 +72,7 @@ TEST(ObjectHashTable) { // 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<JSObject> key = factory->NewJSArray(7); + Handle<JSReceiver> key = factory->NewJSArray(7); Handle<JSObject> value = factory->NewJSArray(11); table = PutIntoObjectHashTable(table, key, value); CHECK_EQ(table->NumberOfElements(), i + 1); @@ -84,7 +84,7 @@ TEST(ObjectHashTable) { // 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<JSObject> key = factory->NewJSArray(7); + Handle<JSReceiver> key = factory->NewJSArray(7); CHECK(key->GetIdentityHash(ALLOW_CREATION)->ToObjectChecked()->IsSmi()); CHECK_EQ(table->FindEntry(*key), ObjectHashTable::kNotFound); CHECK_EQ(table->Lookup(*key), HEAP->the_hole_value()); @@ -94,13 +94,64 @@ TEST(ObjectHashTable) { // 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<JSObject> key = factory->NewJSArray(7); + Handle<JSReceiver> key = factory->NewJSArray(7); CHECK_EQ(table->Lookup(*key), HEAP->the_hole_value()); CHECK_EQ(key->GetIdentityHash(OMIT_CREATION), HEAP->undefined_value()); } } +class ObjectHashTableTest: public ObjectHashTable { + public: + void insert(int entry, int key, int value) { + set(EntryToIndex(entry), Smi::FromInt(key)); + set(EntryToIndex(entry) + 1, Smi::FromInt(value)); + } + + int lookup(int key) { + return Smi::cast(Lookup(Smi::FromInt(key)))->value(); + } + + int capacity() { + return Capacity(); + } +}; + + +TEST(HashTableRehash) { + LocalContext context; + Isolate* isolate = Isolate::Current(); + Factory* factory = isolate->factory(); + v8::HandleScope scope(context->GetIsolate()); + // Test almost filled table. + { + Handle<ObjectHashTable> table = factory->NewObjectHashTable(100); + ObjectHashTableTest* t = reinterpret_cast<ObjectHashTableTest*>(*table); + int capacity = t->capacity(); + for (int i = 0; i < capacity - 1; i++) { + t->insert(i, i * i, i); + } + t->Rehash(Smi::FromInt(0)); + for (int i = 0; i < capacity - 1; i++) { + CHECK_EQ(i, t->lookup(i * i)); + } + } + // Test half-filled table. + { + Handle<ObjectHashTable> table = factory->NewObjectHashTable(100); + ObjectHashTableTest* t = reinterpret_cast<ObjectHashTableTest*>(*table); + int capacity = t->capacity(); + for (int i = 0; i < capacity / 2; i++) { + t->insert(i, i * i, i); + } + t->Rehash(Smi::FromInt(0)); + for (int i = 0; i < capacity / 2; i++) { + CHECK_EQ(i, t->lookup(i * i)); + } + } +} + + #ifdef DEBUG TEST(ObjectHashSetCausesGC) { i::FLAG_stress_compaction = false; |