2014-11-04 10:02:25 +00:00
|
|
|
// Copyright 2014 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
// Flags: --expose-debug-as debug
|
|
|
|
// Test the mirror object for collection iterators.
|
|
|
|
|
2014-11-11 09:46:40 +00:00
|
|
|
function testIteratorMirror(iter, offset, expected, opt_limit) {
|
2014-11-04 10:02:25 +00:00
|
|
|
while (offset-- > 0) iter.next();
|
|
|
|
|
|
|
|
var mirror = debug.MakeMirror(iter);
|
|
|
|
assertTrue(mirror.isIterator());
|
|
|
|
|
2014-11-11 09:46:40 +00:00
|
|
|
var preview = mirror.preview(opt_limit);
|
2014-11-04 10:02:25 +00:00
|
|
|
assertArrayEquals(expected, preview);
|
|
|
|
|
|
|
|
// Check that iterator has not changed after taking preview.
|
|
|
|
var values = [];
|
2014-11-11 09:46:40 +00:00
|
|
|
for (var i of iter) {
|
|
|
|
if (opt_limit && values.length >= opt_limit) break;
|
|
|
|
values.push(i);
|
|
|
|
}
|
2014-11-04 10:02:25 +00:00
|
|
|
assertArrayEquals(expected, values);
|
|
|
|
}
|
|
|
|
|
2014-11-17 12:48:11 +00:00
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
2014-11-04 10:02:25 +00:00
|
|
|
var o1 = { foo: 1 };
|
|
|
|
var o2 = { foo: 2 };
|
|
|
|
|
|
|
|
var map = new Map();
|
|
|
|
map.set(41, 42);
|
|
|
|
map.set(o1, o2);
|
|
|
|
|
|
|
|
testIteratorMirror(map.keys(), 0, [41, o1]);
|
|
|
|
testIteratorMirror(map.values(), 0, [42, o2]);
|
|
|
|
testIteratorMirror(map.entries(), 0, [[41, 42], [o1, o2]]);
|
|
|
|
|
|
|
|
testIteratorMirror(map.keys(), 1, [o1]);
|
|
|
|
testIteratorMirror(map.values(), 1, [o2]);
|
|
|
|
testIteratorMirror(map.entries(), 1, [[o1, o2]]);
|
|
|
|
|
|
|
|
testIteratorMirror(map.keys(), 2, []);
|
|
|
|
testIteratorMirror(map.values(), 2, []);
|
|
|
|
testIteratorMirror(map.entries(), 2, []);
|
|
|
|
|
2014-11-11 09:46:40 +00:00
|
|
|
// Test with maximum limit.
|
|
|
|
testIteratorMirror(map.keys(), 0, [41], 1);
|
|
|
|
testIteratorMirror(map.values(), 0, [42], 1);
|
|
|
|
testIteratorMirror(map.entries(), 0, [[41, 42]], 1);
|
|
|
|
|
2014-11-17 12:48:11 +00:00
|
|
|
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);
|
|
|
|
|
2014-11-04 10:02:25 +00:00
|
|
|
var set = new Set();
|
|
|
|
set.add(41);
|
|
|
|
set.add(42);
|
|
|
|
set.add(o1);
|
|
|
|
set.add(o2);
|
|
|
|
|
|
|
|
testIteratorMirror(set.keys(), 0, [41, 42, o1, o2]);
|
|
|
|
testIteratorMirror(set.values(), 0, [41, 42, o1, o2]);
|
|
|
|
testIteratorMirror(set.entries(), 0, [[41, 41], [42, 42], [o1, o1], [o2, o2]]);
|
|
|
|
|
|
|
|
testIteratorMirror(set.keys(), 1, [42, o1, o2]);
|
|
|
|
testIteratorMirror(set.values(), 1, [42, o1, o2]);
|
|
|
|
testIteratorMirror(set.entries(), 1, [[42, 42], [o1, o1], [o2, o2]]);
|
|
|
|
|
|
|
|
testIteratorMirror(set.keys(), 3, [o2]);
|
|
|
|
testIteratorMirror(set.values(), 3, [o2]);
|
|
|
|
testIteratorMirror(set.entries(), 3, [[o2, o2]]);
|
|
|
|
|
|
|
|
testIteratorMirror(set.keys(), 5, []);
|
|
|
|
testIteratorMirror(set.values(), 5, []);
|
|
|
|
testIteratorMirror(set.entries(), 5, []);
|
2014-11-11 09:46:40 +00:00
|
|
|
|
|
|
|
// Test with maximum limit.
|
|
|
|
testIteratorMirror(set.keys(), 1, [42, o1], 2);
|
|
|
|
testIteratorMirror(set.values(), 1, [42, o1], 2);
|
|
|
|
testIteratorMirror(set.entries(), 1, [[42, 42], [o1, o1]], 2);
|
2014-11-17 12:48:11 +00:00
|
|
|
|
|
|
|
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);
|