OLD | NEW |
| (Empty) |
1 // Copyright 2014 the V8 project authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 // Flags: --expose-debug-as debug | |
6 // Test the mirror object for collection iterators. | |
7 | |
8 function testIteratorMirror(iter, offset, expected, opt_limit) { | |
9 while (offset-- > 0) iter.next(); | |
10 | |
11 var mirror = debug.MakeMirror(iter); | |
12 assertTrue(mirror.isIterator()); | |
13 | |
14 var preview = mirror.preview(opt_limit); | |
15 assertArrayEquals(expected, preview); | |
16 | |
17 // Check that iterator has not changed after taking preview. | |
18 var values = []; | |
19 for (var i of iter) { | |
20 if (opt_limit && values.length >= opt_limit) break; | |
21 values.push(i); | |
22 } | |
23 assertArrayEquals(expected, values); | |
24 } | |
25 | |
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 | |
42 var o1 = { foo: 1 }; | |
43 var o2 = { foo: 2 }; | |
44 | |
45 var map = new Map(); | |
46 map.set(41, 42); | |
47 map.set(o1, o2); | |
48 | |
49 testIteratorMirror(map.keys(), 0, [41, o1]); | |
50 testIteratorMirror(map.values(), 0, [42, o2]); | |
51 testIteratorMirror(map.entries(), 0, [[41, 42], [o1, o2]]); | |
52 | |
53 testIteratorMirror(map.keys(), 1, [o1]); | |
54 testIteratorMirror(map.values(), 1, [o2]); | |
55 testIteratorMirror(map.entries(), 1, [[o1, o2]]); | |
56 | |
57 testIteratorMirror(map.keys(), 2, []); | |
58 testIteratorMirror(map.values(), 2, []); | |
59 testIteratorMirror(map.entries(), 2, []); | |
60 | |
61 // Test with maximum limit. | |
62 testIteratorMirror(map.keys(), 0, [41], 1); | |
63 testIteratorMirror(map.values(), 0, [42], 1); | |
64 testIteratorMirror(map.entries(), 0, [[41, 42]], 1); | |
65 | |
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 | |
71 var set = new Set(); | |
72 set.add(41); | |
73 set.add(42); | |
74 set.add(o1); | |
75 set.add(o2); | |
76 | |
77 testIteratorMirror(set.keys(), 0, [41, 42, o1, o2]); | |
78 testIteratorMirror(set.values(), 0, [41, 42, o1, o2]); | |
79 testIteratorMirror(set.entries(), 0, [[41, 41], [42, 42], [o1, o1], [o2, o2]]); | |
80 | |
81 testIteratorMirror(set.keys(), 1, [42, o1, o2]); | |
82 testIteratorMirror(set.values(), 1, [42, o1, o2]); | |
83 testIteratorMirror(set.entries(), 1, [[42, 42], [o1, o1], [o2, o2]]); | |
84 | |
85 testIteratorMirror(set.keys(), 3, [o2]); | |
86 testIteratorMirror(set.values(), 3, [o2]); | |
87 testIteratorMirror(set.entries(), 3, [[o2, o2]]); | |
88 | |
89 testIteratorMirror(set.keys(), 5, []); | |
90 testIteratorMirror(set.values(), 5, []); | |
91 testIteratorMirror(set.entries(), 5, []); | |
92 | |
93 // Test with maximum limit. | |
94 testIteratorMirror(set.keys(), 1, [42, o1], 2); | |
95 testIteratorMirror(set.values(), 1, [42, o1], 2); | |
96 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); | |
OLD | NEW |