4984224af2
R=yangguo@chromium.org LOG=N Review URL: https://codereview.chromium.org/712083002 Cr-Commit-Position: refs/heads/master@{#25257} git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@25257 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
76 lines
2.3 KiB
JavaScript
76 lines
2.3 KiB
JavaScript
// 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.
|
|
|
|
function testIteratorMirror(iter, offset, expected, opt_limit) {
|
|
while (offset-- > 0) iter.next();
|
|
|
|
var mirror = debug.MakeMirror(iter);
|
|
assertTrue(mirror.isIterator());
|
|
|
|
var preview = mirror.preview(opt_limit);
|
|
assertArrayEquals(expected, preview);
|
|
|
|
// Check that iterator has not changed after taking preview.
|
|
var values = [];
|
|
for (var i of iter) {
|
|
if (opt_limit && values.length >= opt_limit) break;
|
|
values.push(i);
|
|
}
|
|
assertArrayEquals(expected, values);
|
|
}
|
|
|
|
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, []);
|
|
|
|
// Test with maximum limit.
|
|
testIteratorMirror(map.keys(), 0, [41], 1);
|
|
testIteratorMirror(map.values(), 0, [42], 1);
|
|
testIteratorMirror(map.entries(), 0, [[41, 42]], 1);
|
|
|
|
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, []);
|
|
|
|
// 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);
|