Skip to content

Commit 685bc04

Browse files
author
Andrey Adaikin
committed
Expose internal properties of map/set iterators via mirrors.
R=yangguo@chromium.org, vsevik LOG=Y Committed: https://code.google.com/p/v8/source/detail?r=d5f5d38f73f43eba9658d91ffbe511af8c340d78 Review URL: https://codereview.chromium.org/710273002 Cr-Commit-Position: refs/heads/master@{#25380}
1 parent 032191e commit 685bc04

4 files changed

Lines changed: 78 additions & 0 deletions

File tree

src/mirror-debugger.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -919,6 +919,22 @@ ObjectMirror.GetInternalProperties = function(value) {
919919
result.push(new InternalPropertyMirror("[[BoundArgs]]", boundArgs));
920920
}
921921
return result;
922+
} else if (IS_MAP_ITERATOR(value) || IS_SET_ITERATOR(value)) {
923+
var details = IS_MAP_ITERATOR(value) ? %MapIteratorDetails(value)
924+
: %SetIteratorDetails(value);
925+
var kind;
926+
switch (details[2]) {
927+
case 1: kind = "keys"; break;
928+
case 2: kind = "values"; break;
929+
case 3: kind = "entries"; break;
930+
}
931+
var result = [];
932+
result.push(new InternalPropertyMirror("[[IteratorHasMore]]", details[0]));
933+
result.push(new InternalPropertyMirror("[[IteratorIndex]]", details[1]));
934+
if (kind) {
935+
result.push(new InternalPropertyMirror("[[IteratorKind]]", kind));
936+
}
937+
return result;
922938
} else if (ObjectIsPromise(value)) {
923939
var result = [];
924940
result.push(new InternalPropertyMirror("[[PromiseStatus]]",

src/runtime/runtime-collections.cc

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,22 @@ RUNTIME_FUNCTION(Runtime_SetIteratorNext) {
115115
}
116116

117117

118+
// The array returned contains the following information:
119+
// 0: HasMore flag
120+
// 1: Iteration index
121+
// 2: Iteration kind
122+
RUNTIME_FUNCTION(Runtime_SetIteratorDetails) {
123+
HandleScope scope(isolate);
124+
DCHECK(args.length() == 1);
125+
CONVERT_ARG_HANDLE_CHECKED(JSSetIterator, holder, 0);
126+
Handle<FixedArray> details = isolate->factory()->NewFixedArray(4);
127+
details->set(0, isolate->heap()->ToBoolean(holder->HasMore()));
128+
details->set(1, holder->index());
129+
details->set(2, holder->kind());
130+
return *isolate->factory()->NewJSArrayWithElements(details);
131+
}
132+
133+
118134
RUNTIME_FUNCTION(Runtime_MapInitialize) {
119135
HandleScope scope(isolate);
120136
DCHECK(args.length() == 1);
@@ -225,6 +241,22 @@ RUNTIME_FUNCTION(Runtime_MapIteratorClone) {
225241
}
226242

227243

244+
// The array returned contains the following information:
245+
// 0: HasMore flag
246+
// 1: Iteration index
247+
// 2: Iteration kind
248+
RUNTIME_FUNCTION(Runtime_MapIteratorDetails) {
249+
HandleScope scope(isolate);
250+
DCHECK(args.length() == 1);
251+
CONVERT_ARG_HANDLE_CHECKED(JSMapIterator, holder, 0);
252+
Handle<FixedArray> details = isolate->factory()->NewFixedArray(4);
253+
details->set(0, isolate->heap()->ToBoolean(holder->HasMore()));
254+
details->set(1, holder->index());
255+
details->set(2, holder->kind());
256+
return *isolate->factory()->NewJSArrayWithElements(details);
257+
}
258+
259+
228260
RUNTIME_FUNCTION(Runtime_GetWeakMapEntries) {
229261
HandleScope scope(isolate);
230262
DCHECK(args.length() == 2);

src/runtime/runtime.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ namespace internal {
313313
F(SetIteratorInitialize, 3, 1) \
314314
F(SetIteratorClone, 1, 1) \
315315
F(SetIteratorNext, 2, 1) \
316+
F(SetIteratorDetails, 1, 1) \
316317
\
317318
/* Harmony maps */ \
318319
F(MapInitialize, 1, 1) \
@@ -326,6 +327,7 @@ namespace internal {
326327
F(MapIteratorInitialize, 3, 1) \
327328
F(MapIteratorClone, 1, 1) \
328329
F(MapIteratorNext, 2, 1) \
330+
F(MapIteratorDetails, 1, 1) \
329331
\
330332
/* Harmony weak maps and sets */ \
331333
F(WeakCollectionInitialize, 1, 1) \

test/mjsunit/es6/mirror-iterators.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,22 @@ function testIteratorMirror(iter, offset, expected, opt_limit) {
2323
assertArrayEquals(expected, values);
2424
}
2525

26+
function testIteratorInternalProperties(iter, offset, kind, index, has_more) {
27+
while (offset-- > 0) iter.next();
28+
29+
var mirror = debug.MakeMirror(iter);
30+
assertTrue(mirror.isIterator());
31+
32+
var properties = mirror.internalProperties();
33+
assertEquals(3, properties.length);
34+
assertEquals("[[IteratorHasMore]]", properties[0].name());
35+
assertEquals(has_more, properties[0].value().value());
36+
assertEquals("[[IteratorIndex]]", properties[1].name());
37+
assertEquals(index, properties[1].value().value());
38+
assertEquals("[[IteratorKind]]", properties[2].name());
39+
assertEquals(kind, properties[2].value().value());
40+
}
41+
2642
var o1 = { foo: 1 };
2743
var o2 = { foo: 2 };
2844

@@ -47,6 +63,11 @@ testIteratorMirror(map.keys(), 0, [41], 1);
4763
testIteratorMirror(map.values(), 0, [42], 1);
4864
testIteratorMirror(map.entries(), 0, [[41, 42]], 1);
4965

66+
testIteratorInternalProperties(map.keys(), 0, "keys", 0, true);
67+
testIteratorInternalProperties(map.values(), 1, "values", 1, true);
68+
testIteratorInternalProperties(map.entries(), 2, "entries", 2, false);
69+
testIteratorInternalProperties(map.keys(), 3, "keys", 2, false);
70+
5071
var set = new Set();
5172
set.add(41);
5273
set.add(42);
@@ -73,3 +94,10 @@ testIteratorMirror(set.entries(), 5, []);
7394
testIteratorMirror(set.keys(), 1, [42, o1], 2);
7495
testIteratorMirror(set.values(), 1, [42, o1], 2);
7596
testIteratorMirror(set.entries(), 1, [[42, 42], [o1, o1]], 2);
97+
98+
testIteratorInternalProperties(set.keys(), 0, "values", 0, true);
99+
testIteratorInternalProperties(set.values(), 1, "values", 1, true);
100+
testIteratorInternalProperties(set.entries(), 2, "entries", 2, true);
101+
testIteratorInternalProperties(set.keys(), 3, "values", 3, true);
102+
testIteratorInternalProperties(set.values(), 4, "values", 4, false);
103+
testIteratorInternalProperties(set.entries(), 5, "entries", 4, false);

0 commit comments

Comments
 (0)