[dict] Add test for checking overflow of small ordered hash table

Bug: v8:6443, v8:7569
Change-Id: Ie1733198af76d07ac4601c5058af531701434fef
Reviewed-on: https://chromium-review.googlesource.com/c/1331549
Reviewed-by: Camillo Bruni <cbruni@chromium.org>
Commit-Queue: Sathya Gunasekaran <gsathya@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57442}
This commit is contained in:
Sathya Gunasekaran 2018-11-12 16:56:57 +00:00 committed by Commit Bot
parent a0409f0528
commit 6fbd157c59

View File

@ -1489,6 +1489,35 @@ TEST(SmallOrderedNameDictionaryInsertion) {
CHECK(dict->HasKey(isolate, key2));
}
TEST(SmallOrderedNameDictionaryInsertionMax) {
LocalContext context;
Isolate* isolate = GetIsolateFrom(&context);
Factory* factory = isolate->factory();
HandleScope scope(isolate);
Handle<SmallOrderedNameDictionary> dict =
factory->NewSmallOrderedNameDictionary();
Handle<String> value = isolate->factory()->InternalizeUtf8String("bar");
PropertyDetails details = PropertyDetails::Empty();
char buf[10];
for (int i = 0; i < SmallOrderedNameDictionary::kMaxCapacity; i++) {
CHECK_LT(0, snprintf(buf, sizeof(buf), "foo%d", i));
Handle<String> key = isolate->factory()->InternalizeUtf8String(buf);
dict = SmallOrderedNameDictionary::Add(isolate, dict, key, value, details)
.ToHandleChecked();
Verify(isolate, dict);
}
CHECK_EQ(SmallOrderedNameDictionary::kMaxCapacity /
SmallOrderedNameDictionary::kLoadFactor,
dict->NumberOfBuckets());
CHECK_EQ(SmallOrderedNameDictionary::kMaxCapacity, dict->NumberOfElements());
// This should overflow and fail.
CHECK(SmallOrderedNameDictionary::Add(isolate, dict, value, value, details)
.is_null());
}
TEST(SmallOrderedNameDictionaryFindEntry) {
LocalContext context;
Isolate* isolate = GetIsolateFrom(&context);