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

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

Issue 19678023: ES6: Implement WeakSet (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Reitveld is acting up Created 7 years, 5 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
Index: test/cctest/test-weaksets.cc
diff --git a/test/cctest/test-weakmaps.cc b/test/cctest/test-weaksets.cc
similarity index 76%
copy from test/cctest/test-weakmaps.cc
copy to test/cctest/test-weaksets.cc
index 9044f17e4e39f7b56aeef11462457220090c52f7..707f903284889a30f70d5c65e46e43861ca2d3e4 100644
--- a/test/cctest/test-weakmaps.cc
+++ b/test/cctest/test-weaksets.cc
@@ -39,28 +39,28 @@ static Isolate* GetIsolateFrom(LocalContext* context) {
}
-static Handle<JSWeakMap> AllocateJSWeakMap(Isolate* isolate) {
+static Handle<JSWeakSet> AllocateJSWeakSet(Isolate* isolate) {
Factory* factory = isolate->factory();
Heap* heap = isolate->heap();
- Handle<Map> map = factory->NewMap(JS_WEAK_MAP_TYPE, JSWeakMap::kSize);
- Handle<JSObject> weakmap_obj = factory->NewJSObjectFromMap(map);
- Handle<JSWeakMap> weakmap(JSWeakMap::cast(*weakmap_obj));
+ Handle<Map> map = factory->NewMap(JS_WEAK_SET_TYPE, JSWeakSet::kSize);
+ Handle<JSObject> weakset_obj = factory->NewJSObjectFromMap(map);
+ Handle<JSWeakSet> weakset(JSWeakSet::cast(*weakset_obj));
// Do not use handles for the hash table, it would make entries strong.
Object* table_obj = ObjectHashTable::Allocate(heap, 1)->ToObjectChecked();
ObjectHashTable* table = ObjectHashTable::cast(table_obj);
- weakmap->set_table(table);
- weakmap->set_next(Smi::FromInt(0));
- return weakmap;
+ weakset->set_table(table);
+ weakset->set_next(Smi::FromInt(0));
+ return weakset;
}
-static void PutIntoWeakMap(Handle<JSWeakMap> weakmap,
+static void PutIntoWeakSet(Handle<JSWeakSet> weakset,
Handle<JSObject> key,
Handle<Object> value) {
Handle<ObjectHashTable> table = PutIntoObjectHashTable(
- Handle<ObjectHashTable>(ObjectHashTable::cast(weakmap->table())),
+ Handle<ObjectHashTable>(ObjectHashTable::cast(weakset->table())),
Handle<JSObject>(JSObject::cast(*key)),
value);
- weakmap->set_table(*table);
+ weakset->set_table(*table);
}
static int NumberOfWeakCalls = 0;
@@ -73,14 +73,14 @@ static void WeakPointerCallback(v8::Isolate* isolate,
}
-TEST(Weakness) {
+TEST(WeakSet_Weakness) {
FLAG_incremental_marking = false;
LocalContext context;
Isolate* isolate = GetIsolateFrom(&context);
Factory* factory = isolate->factory();
Heap* heap = isolate->heap();
HandleScope scope(isolate);
- Handle<JSWeakMap> weakmap = AllocateJSWeakMap(isolate);
+ Handle<JSWeakSet> weakset = AllocateJSWeakSet(isolate);
GlobalHandles* global_handles = isolate->global_handles();
// Keep global reference to the key.
@@ -93,21 +93,21 @@ TEST(Weakness) {
}
CHECK(!global_handles->IsWeak(key.location()));
- // Put entry into weak map.
+ // Put entry into weak set.
{
HandleScope scope(isolate);
- PutIntoWeakMap(weakmap,
+ PutIntoWeakSet(weakset,
Handle<JSObject>(JSObject::cast(*key)),
Handle<Smi>(Smi::FromInt(23), isolate));
}
- CHECK_EQ(1, ObjectHashTable::cast(weakmap->table())->NumberOfElements());
+ CHECK_EQ(1, ObjectHashTable::cast(weakset->table())->NumberOfElements());
// Force a full GC.
heap->CollectAllGarbage(false);
CHECK_EQ(0, NumberOfWeakCalls);
- CHECK_EQ(1, ObjectHashTable::cast(weakmap->table())->NumberOfElements());
+ CHECK_EQ(1, ObjectHashTable::cast(weakset->table())->NumberOfElements());
CHECK_EQ(
- 0, ObjectHashTable::cast(weakmap->table())->NumberOfDeletedElements());
+ 0, ObjectHashTable::cast(weakset->table())->NumberOfDeletedElements());
// Make the global reference to the key weak.
{
@@ -120,61 +120,61 @@ TEST(Weakness) {
// Force a full GC.
// Perform two consecutive GCs because the first one will only clear
- // weak references whereas the second one will also clear weak maps.
+ // weak references whereas the second one will also clear weak sets.
heap->CollectAllGarbage(false);
CHECK_EQ(1, NumberOfWeakCalls);
- CHECK_EQ(1, ObjectHashTable::cast(weakmap->table())->NumberOfElements());
+ CHECK_EQ(1, ObjectHashTable::cast(weakset->table())->NumberOfElements());
CHECK_EQ(
- 0, ObjectHashTable::cast(weakmap->table())->NumberOfDeletedElements());
+ 0, ObjectHashTable::cast(weakset->table())->NumberOfDeletedElements());
heap->CollectAllGarbage(false);
CHECK_EQ(1, NumberOfWeakCalls);
- CHECK_EQ(0, ObjectHashTable::cast(weakmap->table())->NumberOfElements());
+ CHECK_EQ(0, ObjectHashTable::cast(weakset->table())->NumberOfElements());
CHECK_EQ(
- 1, ObjectHashTable::cast(weakmap->table())->NumberOfDeletedElements());
+ 1, ObjectHashTable::cast(weakset->table())->NumberOfDeletedElements());
}
-TEST(Shrinking) {
+TEST(WeakSet_Shrinking) {
LocalContext context;
Isolate* isolate = GetIsolateFrom(&context);
Factory* factory = isolate->factory();
Heap* heap = isolate->heap();
HandleScope scope(isolate);
- Handle<JSWeakMap> weakmap = AllocateJSWeakMap(isolate);
+ Handle<JSWeakSet> weakset = AllocateJSWeakSet(isolate);
// Check initial capacity.
- CHECK_EQ(32, ObjectHashTable::cast(weakmap->table())->Capacity());
+ CHECK_EQ(32, ObjectHashTable::cast(weakset->table())->Capacity());
- // Fill up weak map to trigger capacity change.
+ // Fill up weak set to trigger capacity change.
{
HandleScope scope(isolate);
Handle<Map> map = factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize);
for (int i = 0; i < 32; i++) {
Handle<JSObject> object = factory->NewJSObjectFromMap(map);
- PutIntoWeakMap(weakmap, object, Handle<Smi>(Smi::FromInt(i), isolate));
+ PutIntoWeakSet(weakset, object, Handle<Smi>(Smi::FromInt(i), isolate));
}
}
// Check increased capacity.
- CHECK_EQ(128, ObjectHashTable::cast(weakmap->table())->Capacity());
+ CHECK_EQ(128, ObjectHashTable::cast(weakset->table())->Capacity());
// Force a full GC.
- CHECK_EQ(32, ObjectHashTable::cast(weakmap->table())->NumberOfElements());
+ CHECK_EQ(32, ObjectHashTable::cast(weakset->table())->NumberOfElements());
CHECK_EQ(
- 0, ObjectHashTable::cast(weakmap->table())->NumberOfDeletedElements());
+ 0, ObjectHashTable::cast(weakset->table())->NumberOfDeletedElements());
heap->CollectAllGarbage(false);
- CHECK_EQ(0, ObjectHashTable::cast(weakmap->table())->NumberOfElements());
+ CHECK_EQ(0, ObjectHashTable::cast(weakset->table())->NumberOfElements());
CHECK_EQ(
- 32, ObjectHashTable::cast(weakmap->table())->NumberOfDeletedElements());
+ 32, ObjectHashTable::cast(weakset->table())->NumberOfDeletedElements());
// Check shrunk capacity.
- CHECK_EQ(32, ObjectHashTable::cast(weakmap->table())->Capacity());
+ CHECK_EQ(32, ObjectHashTable::cast(weakset->table())->Capacity());
}
-// Test that weak map values on an evacuation candidate which are not reachable
+// Test that weak set values on an evacuation candidate which are not reachable
// by other paths are correctly recorded in the slots buffer.
-TEST(Regress2060a) {
+TEST(WeakSet_Regress2060a) {
FLAG_always_compact = true;
LocalContext context;
Isolate* isolate = GetIsolateFrom(&context);
@@ -184,20 +184,20 @@ TEST(Regress2060a) {
Handle<JSFunction> function =
factory->NewFunction(factory->function_string(), factory->null_value());
Handle<JSObject> key = factory->NewJSObject(function);
- Handle<JSWeakMap> weakmap = AllocateJSWeakMap(isolate);
+ Handle<JSWeakSet> weakset = AllocateJSWeakSet(isolate);
// Start second old-space page so that values land on evacuation candidate.
Page* first_page = heap->old_pointer_space()->anchor()->next_page();
factory->NewFixedArray(900 * KB / kPointerSize, TENURED);
- // Fill up weak map with values on an evacuation candidate.
+ // Fill up weak set with values on an evacuation candidate.
{
HandleScope scope(isolate);
for (int i = 0; i < 32; i++) {
Handle<JSObject> object = factory->NewJSObject(function, TENURED);
CHECK(!heap->InNewSpace(object->address()));
CHECK(!first_page->Contains(object->address()));
- PutIntoWeakMap(weakmap, key, object);
+ PutIntoWeakSet(weakset, key, object);
}
}
@@ -207,9 +207,9 @@ TEST(Regress2060a) {
}
-// Test that weak map keys on an evacuation candidate which are reachable by
+// Test that weak set keys on an evacuation candidate which are reachable by
// other strong paths are correctly recorded in the slots buffer.
-TEST(Regress2060b) {
+TEST(WeakSet_Regress2060b) {
FLAG_always_compact = true;
#ifdef VERIFY_HEAP
FLAG_verify_heap = true;
@@ -227,16 +227,16 @@ TEST(Regress2060b) {
Page* first_page = heap->old_pointer_space()->anchor()->next_page();
factory->NewFixedArray(900 * KB / kPointerSize, TENURED);
- // Fill up weak map with keys on an evacuation candidate.
+ // Fill up weak set with keys on an evacuation candidate.
Handle<JSObject> keys[32];
for (int i = 0; i < 32; i++) {
keys[i] = factory->NewJSObject(function, TENURED);
CHECK(!heap->InNewSpace(keys[i]->address()));
CHECK(!first_page->Contains(keys[i]->address()));
}
- Handle<JSWeakMap> weakmap = AllocateJSWeakMap(isolate);
+ Handle<JSWeakSet> weakset = AllocateJSWeakSet(isolate);
for (int i = 0; i < 32; i++) {
- PutIntoWeakMap(weakmap,
+ PutIntoWeakSet(weakset,
keys[i],
Handle<Smi>(Smi::FromInt(i), isolate));
}

Powered by Google App Engine
This is Rietveld 408576698