Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(170)

Side by Side Diff: test/mjsunit/es6/mirror-collections.js

Issue 712083002: Add optional max elements limit for Map/Set mirror iterator preview. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/runtime/runtime-collections.cc ('k') | test/mjsunit/es6/mirror-iterators.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Flags: --expose-debug-as debug --expose-gc 5 // Flags: --expose-debug-as debug --expose-gc
6 6
7 function testMapMirror(mirror) { 7 function testMapMirror(mirror) {
8 // Create JSON representation. 8 // Create JSON representation.
9 var serializer = debug.MakeMirrorSerializer(); 9 var serializer = debug.MakeMirrorSerializer();
10 var json = JSON.stringify(serializer.serializeValue(mirror)); 10 var json = JSON.stringify(serializer.serializeValue(mirror));
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 var o2 = new Object(); 44 var o2 = new Object();
45 var o3 = new Object(); 45 var o3 = new Object();
46 46
47 // Test the mirror object for Maps 47 // Test the mirror object for Maps
48 var map = new Map(); 48 var map = new Map();
49 map.set(o1, 11); 49 map.set(o1, 11);
50 map.set(o2, 22); 50 map.set(o2, 22);
51 map.delete(o1); 51 map.delete(o1);
52 var mapMirror = debug.MakeMirror(map); 52 var mapMirror = debug.MakeMirror(map);
53 testMapMirror(mapMirror); 53 testMapMirror(mapMirror);
54
54 var entries = mapMirror.entries(); 55 var entries = mapMirror.entries();
55 assertEquals(1, entries.length); 56 assertEquals(1, entries.length);
56 assertSame(o2, entries[0].key); 57 assertSame(o2, entries[0].key);
57 assertEquals(22, entries[0].value); 58 assertEquals(22, entries[0].value);
58 map.set(o1, 33); 59 map.set(o1, 33);
59 map.set(o3, o2); 60 map.set(o3, o2);
60 map.delete(o2); 61 map.delete(o2);
61 map.set(undefined, 44); 62 map.set(undefined, 44);
63
62 entries = mapMirror.entries(); 64 entries = mapMirror.entries();
63 assertEquals(3, entries.length); 65 assertEquals(3, entries.length);
64 assertSame(o1, entries[0].key); 66 assertSame(o1, entries[0].key);
65 assertEquals(33, entries[0].value); 67 assertEquals(33, entries[0].value);
66 assertSame(o3, entries[1].key); 68 assertSame(o3, entries[1].key);
67 assertSame(o2, entries[1].value); 69 assertSame(o2, entries[1].value);
68 assertEquals(undefined, entries[2].key); 70 assertEquals(undefined, entries[2].key);
69 assertEquals(44, entries[2].value); 71 assertEquals(44, entries[2].value);
70 72
73 assertEquals(3, mapMirror.entries(0).length);
74 assertEquals(1, mapMirror.entries(1).length);
75 assertEquals(2, mapMirror.entries(2).length);
76
71 // Test the mirror object for Sets 77 // Test the mirror object for Sets
72 var set = new Set(); 78 var set = new Set();
73 set.add(o1); 79 set.add(o1);
74 set.add(o2); 80 set.add(o2);
75 set.delete(o1); 81 set.delete(o1);
76 set.add(undefined); 82 set.add(undefined);
77 var setMirror = debug.MakeMirror(set); 83 var setMirror = debug.MakeMirror(set);
78 testSetMirror(setMirror); 84 testSetMirror(setMirror);
79 var values = setMirror.values(); 85 var values = setMirror.values();
80 assertEquals(2, values.length); 86 assertEquals(2, values.length);
87 assertEquals(1, setMirror.values(1).length);
81 assertSame(o2, values[0]); 88 assertSame(o2, values[0]);
82 assertEquals(undefined, values[1]); 89 assertEquals(undefined, values[1]);
83 90
84 // Test the mirror object for WeakMaps 91 // Test the mirror object for WeakMaps
85 var weakMap = new WeakMap(); 92 var weakMap = new WeakMap();
86 weakMap.set(o1, 11); 93 weakMap.set(o1, 11);
87 weakMap.set(new Object(), 22); 94 weakMap.set(new Object(), 22);
88 weakMap.set(o3, 33); 95 weakMap.set(o3, 33);
89 weakMap.set(new Object(), 44); 96 weakMap.set(new Object(), 44);
90 var weakMapMirror = debug.MakeMirror(weakMap); 97 var weakMapMirror = debug.MakeMirror(weakMap);
91 testMapMirror(weakMapMirror); 98 testMapMirror(weakMapMirror);
92 weakMap.set(new Object(), 55); 99 weakMap.set(new Object(), 55);
93 assertTrue(weakMapMirror.entries().length <= 5); 100 assertTrue(weakMapMirror.entries().length <= 5);
94 gc(); 101 gc();
95 102
96 function testWeakMapEntries(weakMapMirror) { 103 function testWeakMapEntries(weakMapMirror) {
97 var entries = weakMapMirror.entries(); 104 var entries = weakMapMirror.entries();
98 assertEquals(2, entries.length); 105 assertEquals(2, entries.length);
106 assertEquals(2, weakMapMirror.entries(0).length);
107 assertEquals(1, weakMapMirror.entries(1).length);
99 var found = 0; 108 var found = 0;
100 for (var i = 0; i < entries.length; i++) { 109 for (var i = 0; i < entries.length; i++) {
101 if (Object.is(entries[i].key, o1)) { 110 if (Object.is(entries[i].key, o1)) {
102 assertEquals(11, entries[i].value); 111 assertEquals(11, entries[i].value);
103 found++; 112 found++;
104 } 113 }
105 if (Object.is(entries[i].key, o3)) { 114 if (Object.is(entries[i].key, o3)) {
106 assertEquals(33, entries[i].value); 115 assertEquals(33, entries[i].value);
107 found++; 116 found++;
108 } 117 }
(...skipping 13 matching lines...) Expand all
122 weakSet.add(o3); 131 weakSet.add(o3);
123 weakSet.delete(o2); 132 weakSet.delete(o2);
124 var weakSetMirror = debug.MakeMirror(weakSet); 133 var weakSetMirror = debug.MakeMirror(weakSet);
125 testSetMirror(weakSetMirror); 134 testSetMirror(weakSetMirror);
126 assertTrue(weakSetMirror.values().length <= 5); 135 assertTrue(weakSetMirror.values().length <= 5);
127 gc(); 136 gc();
128 137
129 function testWeakSetValues(weakSetMirror) { 138 function testWeakSetValues(weakSetMirror) {
130 var values = weakSetMirror.values(); 139 var values = weakSetMirror.values();
131 assertEquals(2, values.length); 140 assertEquals(2, values.length);
141 assertEquals(2, weakSetMirror.values(0).length);
142 assertEquals(1, weakSetMirror.values(1).length);
132 var found = 0; 143 var found = 0;
133 for (var i = 0; i < values.length; i++) { 144 for (var i = 0; i < values.length; i++) {
134 if (Object.is(values[i], o1)) { 145 if (Object.is(values[i], o1)) {
135 found++; 146 found++;
136 } 147 }
137 if (Object.is(values[i], o3)) { 148 if (Object.is(values[i], o3)) {
138 found++; 149 found++;
139 } 150 }
140 } 151 }
141 assertEquals(2, found); 152 assertEquals(2, found);
142 } 153 }
143 154
144 testWeakSetValues(weakSetMirror); 155 testWeakSetValues(weakSetMirror);
OLDNEW
« no previous file with comments | « src/runtime/runtime-collections.cc ('k') | test/mjsunit/es6/mirror-iterators.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698