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(); | |
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(1, entries.length); | |
38 assertSame(o2, entries[0].key); | |
39 assertEquals(22, entries[0].value); | |
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(3, entries.length); | |
46 assertSame(o1, entries[0].key); | |
47 assertEquals(33, entries[0].value); | |
48 assertSame(o3, entries[1].key); | |
49 assertSame(o2, entries[1].value); | |
50 assertEquals(undefined, entries[2].key); | |
51 assertEquals(44, entries[2].value); | |
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) { | |
aandrey
2014/07/17 09:42:28
could you extract a method out of these two?
Alexandra Mikhaylova
2014/07/17 10:21:18
Done.
| |
62 var entries = mirror.entries(); | |
63 assertEquals(3, entries.length); | |
64 var found = 0; | |
65 for (var i = 0; i < entries.length; i++) { | |
66 if (Object.is(entries[i].key, o1)) { | |
67 assertEquals(11, entries[i].value); | |
68 found++; | |
69 continue; | |
70 } | |
71 if (Object.is(entries[i].key, o3)) { | |
72 assertEquals(33, entries[i].value); | |
73 found++; | |
74 continue; | |
75 } | |
76 if (entries[i].value == 22) | |
77 found++; | |
78 } | |
79 assertEquals(3, found); | |
80 } | |
81 | |
82 testWeakMapMirrorBeforeGC(weakMapMirror); | |
83 gc(); | |
84 | |
85 function testWeakMapMirrorAfterGC(mirror) { | |
86 var entries = mirror.entries(); | |
87 assertEquals(2, entries.length); | |
88 var found = 0; | |
89 for (var i = 0; i < entries.length; i++) { | |
90 if (Object.is(entries[i].key, o1)) { | |
91 assertEquals(11, entries[i].value); | |
92 found++; | |
93 } | |
94 if (Object.is(entries[i].key, o3)) { | |
95 assertEquals(33, entries[i].value); | |
96 found++; | |
97 } | |
98 } | |
99 assertEquals(2, found); | |
100 } | |
101 | |
102 testWeakMapMirrorAfterGC(weakMapMirror); | |
OLD | NEW |