Reviewers: vsevik, Yang,

Description:
Expose internal properties of map/set iterators via mirrors.

[email protected], vsevik
LOG=Y

Please review this at https://codereview.chromium.org/710273002/

Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files (+78, -0 lines):
  M src/mirror-debugger.js
  M src/runtime/runtime.h
  M src/runtime/runtime-collections.cc
  M test/mjsunit/es6/mirror-iterators.js


Index: src/mirror-debugger.js
diff --git a/src/mirror-debugger.js b/src/mirror-debugger.js
index da031d3383b55321827fee2d8bbb8e14477e7049..58948f3a941924899c7b4f2b92c6a81261ee888b 100644
--- a/src/mirror-debugger.js
+++ b/src/mirror-debugger.js
@@ -919,6 +919,22 @@ ObjectMirror.GetInternalProperties = function(value) {
       result.push(new InternalPropertyMirror("[[BoundArgs]]", boundArgs));
     }
     return result;
+  } else if (IS_MAP_ITERATOR(value) || IS_SET_ITERATOR(value)) {
+    var details = IS_MAP_ITERATOR(value) ? %MapIteratorDetails(value)
+                                         : %SetIteratorDetails(value);
+    var kind;
+    switch (details[2]) {
+      case 1: kind = "keys"; break;
+      case 2: kind = "values"; break;
+      case 3: kind = "entries"; break;
+    }
+    var result = [];
+ result.push(new InternalPropertyMirror("[[IteratorHasMore]]", details[0])); + result.push(new InternalPropertyMirror("[[IteratorIndex]]", details[1]));
+    if (kind) {
+      result.push(new InternalPropertyMirror("[[IteratorKind]]", kind));
+    }
+    return result;
   } else if (ObjectIsPromise(value)) {
     var result = [];
     result.push(new InternalPropertyMirror("[[PromiseStatus]]",
Index: src/runtime/runtime-collections.cc
diff --git a/src/runtime/runtime-collections.cc b/src/runtime/runtime-collections.cc index 45ac41c6209d702b28f7788c33fd89d19266944f..a9aa692947e24c425b6de610fa7bf646452f188a 100644
--- a/src/runtime/runtime-collections.cc
+++ b/src/runtime/runtime-collections.cc
@@ -115,6 +115,22 @@ RUNTIME_FUNCTION(Runtime_SetIteratorNext) {
 }


+// The array returned contains the following information:
+// 0: HasMore flag
+// 1: Iteration index
+// 2: Iteration kind
+RUNTIME_FUNCTION(Runtime_SetIteratorDetails) {
+  HandleScope scope(isolate);
+  DCHECK(args.length() == 1);
+  CONVERT_ARG_HANDLE_CHECKED(JSSetIterator, holder, 0);
+  Handle<FixedArray> details = isolate->factory()->NewFixedArray(4);
+  details->set(0, isolate->heap()->ToBoolean(holder->HasMore()));
+  details->set(1, holder->index());
+  details->set(2, holder->kind());
+  return *isolate->factory()->NewJSArrayWithElements(details);
+}
+
+
 RUNTIME_FUNCTION(Runtime_MapInitialize) {
   HandleScope scope(isolate);
   DCHECK(args.length() == 1);
@@ -225,6 +241,22 @@ RUNTIME_FUNCTION(Runtime_MapIteratorClone) {
 }


+// The array returned contains the following information:
+// 0: HasMore flag
+// 1: Iteration index
+// 2: Iteration kind
+RUNTIME_FUNCTION(Runtime_MapIteratorDetails) {
+  HandleScope scope(isolate);
+  DCHECK(args.length() == 1);
+  CONVERT_ARG_HANDLE_CHECKED(JSMapIterator, holder, 0);
+  Handle<FixedArray> details = isolate->factory()->NewFixedArray(4);
+  details->set(0, isolate->heap()->ToBoolean(holder->HasMore()));
+  details->set(1, holder->index());
+  details->set(2, holder->kind());
+  return *isolate->factory()->NewJSArrayWithElements(details);
+}
+
+
 RUNTIME_FUNCTION(Runtime_GetWeakMapEntries) {
   HandleScope scope(isolate);
   DCHECK(args.length() == 1);
Index: src/runtime/runtime.h
diff --git a/src/runtime/runtime.h b/src/runtime/runtime.h
index 5d6ccac709f235e85cc87230283e63cb7174505b..9442360477a6385f9940baf0addc6c42718cdb5b 100644
--- a/src/runtime/runtime.h
+++ b/src/runtime/runtime.h
@@ -312,6 +312,7 @@ namespace internal {
   F(SetIteratorInitialize, 3, 1)                       \
   F(SetIteratorClone, 1, 1)                            \
   F(SetIteratorNext, 2, 1)                             \
+  F(SetIteratorDetails, 1, 1)                          \
                                                        \
   /* Harmony maps */                                   \
   F(MapInitialize, 1, 1)                               \
@@ -325,6 +326,7 @@ namespace internal {
   F(MapIteratorInitialize, 3, 1)                       \
   F(MapIteratorClone, 1, 1)                            \
   F(MapIteratorNext, 2, 1)                             \
+  F(MapIteratorDetails, 1, 1)                          \
                                                        \
   /* Harmony weak maps and sets */                     \
   F(WeakCollectionInitialize, 1, 1)                    \
Index: test/mjsunit/es6/mirror-iterators.js
diff --git a/test/mjsunit/es6/mirror-iterators.js b/test/mjsunit/es6/mirror-iterators.js index 02fe7ffde009cd3ac97251bfb99f1ec385abd1c4..c4d6c64271938cf4aa9ad714d6d0ab87d8c7fcb3 100644
--- a/test/mjsunit/es6/mirror-iterators.js
+++ b/test/mjsunit/es6/mirror-iterators.js
@@ -20,6 +20,22 @@ function testIteratorMirror(iter, offset, expected) {
   assertArrayEquals(expected, values);
 }

+function testIteratorInternalProperties(iter, offset, kind, index, has_more) {
+  while (offset-- > 0) iter.next();
+
+  var mirror = debug.MakeMirror(iter);
+  assertTrue(mirror.isIterator());
+
+  var properties = mirror.internalProperties();
+  assertEquals(3, properties.length);
+  assertEquals("[[IteratorHasMore]]", properties[0].name());
+  assertEquals(has_more, properties[0].value().value());
+  assertEquals("[[IteratorIndex]]", properties[1].name());
+  assertEquals(index, properties[1].value().value());
+  assertEquals("[[IteratorKind]]", properties[2].name());
+  assertEquals(kind, properties[2].value().value());
+}
+
 var o1 = { foo: 1 };
 var o2 = { foo: 2 };

@@ -39,6 +55,11 @@ testIteratorMirror(map.keys(), 2, []);
 testIteratorMirror(map.values(), 2, []);
 testIteratorMirror(map.entries(), 2, []);

+testIteratorInternalProperties(map.keys(), 0, "keys", 0, true);
+testIteratorInternalProperties(map.values(), 1, "values", 1, true);
+testIteratorInternalProperties(map.entries(), 2, "entries", 2, false);
+testIteratorInternalProperties(map.keys(), 3, "keys", 2, false);
+
 var set = new Set();
 set.add(41);
 set.add(42);
@@ -60,3 +81,10 @@ testIteratorMirror(set.entries(), 3, [[o2, o2]]);
 testIteratorMirror(set.keys(), 5, []);
 testIteratorMirror(set.values(), 5, []);
 testIteratorMirror(set.entries(), 5, []);
+
+testIteratorInternalProperties(set.keys(), 0, "values", 0, true);
+testIteratorInternalProperties(set.values(), 1, "values", 1, true);
+testIteratorInternalProperties(set.entries(), 2, "entries", 2, true);
+testIteratorInternalProperties(set.keys(), 3, "values", 3, true);
+testIteratorInternalProperties(set.values(), 4, "values", 4, false);
+testIteratorInternalProperties(set.entries(), 5, "entries", 4, false);


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to