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 --expose-gc --harmony-collections | |
6 | |
7 function testMapMirror(mirror) { | |
8 // Create JSON representation. | |
9 var serializer = debug.MakeMirrorSerializer(); | |
Yang
2014/07/16 12:10:58
Same here. 2 space indentation please.
Alexandra Mikhaylova
2014/07/16 17:00:37
Done.
| |
10 var json = JSON.stringify(serializer.serializeValue(mirror)); | |
11 | |
12 // Check the mirror hierachy. | |
13 assertTrue(mirror instanceof debug.Mirror); | |
14 assertTrue(mirror instanceof debug.ValueMirror); | |
15 assertTrue(mirror instanceof debug.ObjectMirror); | |
16 assertTrue(mirror instanceof debug.MapMirror); | |
17 | |
18 assertTrue(mirror.isMap()); | |
19 | |
20 // Parse JSON representation and check. | |
21 var fromJSON = eval('(' + json + ')'); | |
22 assertEquals('map', fromJSON.type); | |
23 } | |
24 | |
25 var o1 = new Object(); | |
26 var o2 = new Object(); | |
27 var o3 = new Object(); | |
28 | |
29 // Test the mirror object for Maps | |
30 var map = new Map(); | |
31 map.set(o1, 11); | |
32 map.set(o2, 22); | |
33 map.delete(o1); | |
34 var mapMirror = debug.MakeMirror(map); | |
35 testMapMirror(mapMirror); | |
36 var entries = mapMirror.entries(); | |
37 assertEquals(2, entries.length); | |
38 assertSame(o2, entries[0]); | |
39 assertEquals(22, entries[1]); | |
40 map.set(o1, 33); | |
41 map.set(o3, o2); | |
42 map.delete(o2); | |
43 map.set(undefined, 44); | |
44 entries = mapMirror.entries(); | |
45 assertEquals(6, entries.length); | |
46 assertSame(o1, entries[0]); | |
47 assertEquals(33, entries[1]); | |
48 assertSame(o3, entries[2]); | |
49 assertSame(o2, entries[3]); | |
50 assertEquals(undefined, entries[4]); | |
51 assertEquals(44, entries[5]); | |
Yang
2014/07/16 12:10:58
Having MapMirror.entries() contain both keys and v
Alexandra Mikhaylova
2014/07/16 17:00:37
I've changed the return value of MapMirror.entries
| |
52 | |
53 // Test the mirror object for WeakMaps | |
54 var weakMap = new WeakMap(); | |
55 weakMap.set(o1, 11); | |
56 weakMap.set(new Object(), 22); | |
57 weakMap.set(o3, 33); | |
58 var weakMapMirror = debug.MakeMirror(weakMap); | |
59 testMapMirror(weakMapMirror); | |
60 | |
61 function testWeakMapMirrorBeforeGC(mirror) { | |
62 var entries = mirror.entries(); | |
63 assertEquals(6, entries.length); | |
64 assertEquals(11, entries[entries.indexOf(o1) + 1]); | |
65 assertEquals(33, entries[entries.indexOf(o3) + 1]); | |
66 assertTrue(entries.indexOf(22) >= 1); | |
67 } | |
68 | |
69 testWeakMapMirrorBeforeGC(weakMapMirror); | |
70 gc(); | |
71 | |
72 function testWeakMapMirrorAfterGC(mirror) { | |
73 var entries = mirror.entries(); | |
74 assertEquals(4, entries.length); | |
75 assertEquals(11, entries[entries.indexOf(o1) + 1]); | |
76 assertEquals(33, entries[entries.indexOf(o3) + 1]); | |
77 assertTrue(entries.indexOf(22) == -1); | |
78 } | |
79 | |
80 testWeakMapMirrorAfterGC(weakMapMirror); | |
OLD | NEW |