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

Unified Diff: test/cctest/test-ordered-hash-table.cc

Issue 236143002: ES6: Add support for Map.prototype.forEach and Set.prototype.forEach (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Add test that calls gc() Created 6 years, 8 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/x64/full-codegen-x64.cc ('k') | test/mjsunit/harmony/collections.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-ordered-hash-table.cc
diff --git a/test/cctest/test-ordered-hash-table.cc b/test/cctest/test-ordered-hash-table.cc
index f6ebc16f1ef3467c4ea08751277aecb403153482..f495804ee6a276cd5604eee0068eca157dc64832 100644
--- a/test/cctest/test-ordered-hash-table.cc
+++ b/test/cctest/test-ordered-hash-table.cc
@@ -36,7 +36,20 @@ namespace {
using namespace v8::internal;
+
+void CheckIterResultObject(Factory* factory,
+ Handle<JSObject> result,
+ Handle<Object> value,
+ bool done) {
+ CHECK(GetProperty(result, "value").ToHandleChecked()->SameValue(*value));
+ CHECK(GetProperty(result, "done").ToHandleChecked()->IsBoolean());
+ CHECK_EQ(GetProperty(result, "done").ToHandleChecked()->BooleanValue(), done);
+}
+
+
TEST(Set) {
+ i::FLAG_harmony_collections = true;
+
LocalContext context;
Isolate* isolate = CcTest::i_isolate();
Factory* factory = isolate->factory();
@@ -46,6 +59,11 @@ TEST(Set) {
CHECK_EQ(0, ordered_set->NumberOfElements());
CHECK_EQ(0, ordered_set->NumberOfDeletedElements());
+ Handle<JSSetIterator> value_iterator =
+ JSSetIterator::Create(ordered_set, JSSetIterator::kKindValues);
+ Handle<JSSetIterator> value_iterator_2 =
+ JSSetIterator::Create(ordered_set, JSSetIterator::kKindValues);
+
Handle<Map> map = factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize);
Handle<JSObject> obj = factory->NewJSObjectFromMap(map);
CHECK(!ordered_set->Contains(*obj));
@@ -68,6 +86,18 @@ TEST(Set) {
CHECK(ordered_set->Contains(*obj2));
CHECK(ordered_set->Contains(*obj3));
+ // Test iteration
+ CheckIterResultObject(
+ factory, JSSetIterator::Next(value_iterator), obj1, false);
+ CheckIterResultObject(
+ factory, JSSetIterator::Next(value_iterator), obj2, false);
+ CheckIterResultObject(
+ factory, JSSetIterator::Next(value_iterator), obj3, false);
+ CheckIterResultObject(factory,
+ JSSetIterator::Next(value_iterator),
+ factory->undefined_value(),
+ true);
+
// Test growth
ordered_set = OrderedHashSet::Add(ordered_set, obj);
Handle<JSObject> obj4 = factory->NewJSObjectFromMap(map);
@@ -81,6 +111,22 @@ TEST(Set) {
CHECK_EQ(0, ordered_set->NumberOfDeletedElements());
CHECK_EQ(4, ordered_set->NumberOfBuckets());
+ // Test iteration after growth
+ CheckIterResultObject(
+ factory, JSSetIterator::Next(value_iterator_2), obj1, false);
+ CheckIterResultObject(
+ factory, JSSetIterator::Next(value_iterator_2), obj2, false);
+ CheckIterResultObject(
+ factory, JSSetIterator::Next(value_iterator_2), obj3, false);
+ CheckIterResultObject(
+ factory, JSSetIterator::Next(value_iterator_2), obj, false);
+ CheckIterResultObject(
+ factory, JSSetIterator::Next(value_iterator_2), obj4, false);
+ CheckIterResultObject(factory,
+ JSSetIterator::Next(value_iterator_2),
+ factory->undefined_value(),
+ true);
+
// Test shrinking
ordered_set = OrderedHashSet::Remove(ordered_set, obj);
ordered_set = OrderedHashSet::Remove(ordered_set, obj1);
@@ -92,6 +138,8 @@ TEST(Set) {
TEST(Map) {
+ i::FLAG_harmony_collections = true;
+
LocalContext context;
Isolate* isolate = CcTest::i_isolate();
Factory* factory = isolate->factory();
@@ -101,6 +149,11 @@ TEST(Map) {
CHECK_EQ(0, ordered_map->NumberOfElements());
CHECK_EQ(0, ordered_map->NumberOfDeletedElements());
+ Handle<JSMapIterator> value_iterator =
+ JSMapIterator::Create(ordered_map, JSMapIterator::kKindValues);
+ Handle<JSMapIterator> key_iterator =
+ JSMapIterator::Create(ordered_map, JSMapIterator::kKindKeys);
+
Handle<Map> map = factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize);
Handle<JSObject> obj = factory->NewJSObjectFromMap(map);
Handle<JSObject> val = factory->NewJSObjectFromMap(map);
@@ -128,6 +181,18 @@ TEST(Map) {
CHECK(ordered_map->Lookup(*obj2)->SameValue(*val2));
CHECK(ordered_map->Lookup(*obj3)->SameValue(*val3));
+ // Test iteration
+ CheckIterResultObject(
+ factory, JSMapIterator::Next(value_iterator), val1, false);
+ CheckIterResultObject(
+ factory, JSMapIterator::Next(value_iterator), val2, false);
+ CheckIterResultObject(
+ factory, JSMapIterator::Next(value_iterator), val3, false);
+ CheckIterResultObject(factory,
+ JSMapIterator::Next(value_iterator),
+ factory->undefined_value(),
+ true);
+
// Test growth
ordered_map = OrderedHashMap::Put(ordered_map, obj, val);
Handle<JSObject> obj4 = factory->NewJSObjectFromMap(map);
@@ -141,6 +206,22 @@ TEST(Map) {
CHECK_EQ(5, ordered_map->NumberOfElements());
CHECK_EQ(4, ordered_map->NumberOfBuckets());
+ // Test iteration after growth
+ CheckIterResultObject(
+ factory, JSMapIterator::Next(key_iterator), obj1, false);
+ CheckIterResultObject(
+ factory, JSMapIterator::Next(key_iterator), obj2, false);
+ CheckIterResultObject(
+ factory, JSMapIterator::Next(key_iterator), obj3, false);
+ CheckIterResultObject(
+ factory, JSMapIterator::Next(key_iterator), obj, false);
+ CheckIterResultObject(
+ factory, JSMapIterator::Next(key_iterator), obj4, false);
+ CheckIterResultObject(factory,
+ JSMapIterator::Next(key_iterator),
+ factory->undefined_value(),
+ true);
+
// Test shrinking
ordered_map = OrderedHashMap::Put(
ordered_map, obj, factory->the_hole_value());
« no previous file with comments | « src/x64/full-codegen-x64.cc ('k') | test/mjsunit/harmony/collections.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698