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

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

Issue 402423003: Expose the content of Sets and WeakSets through SetMirror. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Address comments Created 6 years, 5 months 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.cc ('k') | test/mjsunit/runtime-gen/getweaksetvalues.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 --harmony-collections 5 // Flags: --expose-debug-as debug --expose-gc --harmony-collections
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));
11 11
12 // Check the mirror hierachy. 12 // Check the mirror hierachy.
13 assertTrue(mirror instanceof debug.Mirror); 13 assertTrue(mirror instanceof debug.Mirror);
14 assertTrue(mirror instanceof debug.ValueMirror); 14 assertTrue(mirror instanceof debug.ValueMirror);
15 assertTrue(mirror instanceof debug.ObjectMirror); 15 assertTrue(mirror instanceof debug.ObjectMirror);
16 assertTrue(mirror instanceof debug.MapMirror); 16 assertTrue(mirror instanceof debug.MapMirror);
17 17
18 assertTrue(mirror.isMap()); 18 assertTrue(mirror.isMap());
19 19
20 // Parse JSON representation and check. 20 // Parse JSON representation and check.
21 var fromJSON = eval('(' + json + ')'); 21 var fromJSON = eval('(' + json + ')');
22 assertEquals('map', fromJSON.type); 22 assertEquals('map', fromJSON.type);
23 } 23 }
24 24
25 function testSetMirror(mirror) {
26 // Create JSON representation.
27 var serializer = debug.MakeMirrorSerializer();
28 var json = JSON.stringify(serializer.serializeValue(mirror));
29
30 // Check the mirror hierachy.
31 assertTrue(mirror instanceof debug.Mirror);
32 assertTrue(mirror instanceof debug.ValueMirror);
33 assertTrue(mirror instanceof debug.ObjectMirror);
34 assertTrue(mirror instanceof debug.SetMirror);
35
36 assertTrue(mirror.isSet());
37
38 // Parse JSON representation and check.
39 var fromJSON = eval('(' + json + ')');
40 assertEquals('set', fromJSON.type);
41 }
42
25 var o1 = new Object(); 43 var o1 = new Object();
26 var o2 = new Object(); 44 var o2 = new Object();
27 var o3 = new Object(); 45 var o3 = new Object();
28 46
29 // Test the mirror object for Maps 47 // Test the mirror object for Maps
30 var map = new Map(); 48 var map = new Map();
31 map.set(o1, 11); 49 map.set(o1, 11);
32 map.set(o2, 22); 50 map.set(o2, 22);
33 map.delete(o1); 51 map.delete(o1);
34 var mapMirror = debug.MakeMirror(map); 52 var mapMirror = debug.MakeMirror(map);
35 testMapMirror(mapMirror); 53 testMapMirror(mapMirror);
36 var entries = mapMirror.entries(); 54 var entries = mapMirror.entries();
37 assertEquals(1, entries.length); 55 assertEquals(1, entries.length);
38 assertSame(o2, entries[0].key); 56 assertSame(o2, entries[0].key);
39 assertEquals(22, entries[0].value); 57 assertEquals(22, entries[0].value);
40 map.set(o1, 33); 58 map.set(o1, 33);
41 map.set(o3, o2); 59 map.set(o3, o2);
42 map.delete(o2); 60 map.delete(o2);
43 map.set(undefined, 44); 61 map.set(undefined, 44);
44 entries = mapMirror.entries(); 62 entries = mapMirror.entries();
45 assertEquals(3, entries.length); 63 assertEquals(3, entries.length);
46 assertSame(o1, entries[0].key); 64 assertSame(o1, entries[0].key);
47 assertEquals(33, entries[0].value); 65 assertEquals(33, entries[0].value);
48 assertSame(o3, entries[1].key); 66 assertSame(o3, entries[1].key);
49 assertSame(o2, entries[1].value); 67 assertSame(o2, entries[1].value);
50 assertEquals(undefined, entries[2].key); 68 assertEquals(undefined, entries[2].key);
51 assertEquals(44, entries[2].value); 69 assertEquals(44, entries[2].value);
52 70
71 // Test the mirror object for Sets
72 var set = new Set();
73 set.add(o1);
74 set.add(o2);
75 set.delete(o1);
76 set.add(undefined);
77 var setMirror = debug.MakeMirror(set);
78 testSetMirror(setMirror);
79 var values = setMirror.values();
80 assertEquals(2, values.length);
81 assertSame(o2, values[0]);
82 assertEquals(undefined, values[1]);
83
53 // Test the mirror object for WeakMaps 84 // Test the mirror object for WeakMaps
54 var weakMap = new WeakMap(); 85 var weakMap = new WeakMap();
55 weakMap.set(o1, 11); 86 weakMap.set(o1, 11);
56 weakMap.set(new Object(), 22); 87 weakMap.set(new Object(), 22);
57 weakMap.set(o3, 33); 88 weakMap.set(o3, 33);
58 weakMap.set(new Object(), 44); 89 weakMap.set(new Object(), 44);
59 var weakMapMirror = debug.MakeMirror(weakMap); 90 var weakMapMirror = debug.MakeMirror(weakMap);
60 testMapMirror(weakMapMirror); 91 testMapMirror(weakMapMirror);
61 weakMap.set(new Object(), 55); 92 weakMap.set(new Object(), 55);
62 assertTrue(weakMapMirror.entries().length <= 5); 93 assertTrue(weakMapMirror.entries().length <= 5);
(...skipping 10 matching lines...) Expand all
73 } 104 }
74 if (Object.is(entries[i].key, o3)) { 105 if (Object.is(entries[i].key, o3)) {
75 assertEquals(33, entries[i].value); 106 assertEquals(33, entries[i].value);
76 found++; 107 found++;
77 } 108 }
78 } 109 }
79 assertEquals(2, found); 110 assertEquals(2, found);
80 } 111 }
81 112
82 testWeakMapEntries(weakMapMirror); 113 testWeakMapEntries(weakMapMirror);
114
115 // Test the mirror object for WeakSets
116 var weakSet = new WeakSet();
117 weakSet.add(o1);
118 weakSet.add(new Object());
119 weakSet.add(o2);
120 weakSet.add(new Object());
121 weakSet.add(new Object());
122 weakSet.add(o3);
123 weakSet.delete(o2);
124 var weakSetMirror = debug.MakeMirror(weakSet);
125 testSetMirror(weakSetMirror);
126 assertTrue(weakSetMirror.values().length <= 5);
127 gc();
128
129 function testWeakSetValues(weakSetMirror) {
130 var values = weakSetMirror.values();
131 assertEquals(2, values.length);
132 var found = 0;
133 for (var i = 0; i < values.length; i++) {
134 if (Object.is(values[i], o1)) {
135 found++;
136 }
137 if (Object.is(values[i], o3)) {
138 found++;
139 }
140 }
141 assertEquals(2, found);
142 }
143
144 testWeakSetValues(weakSetMirror);
OLDNEW
« no previous file with comments | « src/runtime.cc ('k') | test/mjsunit/runtime-gen/getweaksetvalues.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698