| 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 | |
| 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 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 | |
| 43 var o1 = new Object(); | |
| 44 var o2 = new Object(); | |
| 45 var o3 = new Object(); | |
| 46 | |
| 47 // Test the mirror object for Maps | |
| 48 var map = new Map(); | |
| 49 map.set(o1, 11); | |
| 50 map.set(o2, 22); | |
| 51 map.delete(o1); | |
| 52 var mapMirror = debug.MakeMirror(map); | |
| 53 testMapMirror(mapMirror); | |
| 54 | |
| 55 var entries = mapMirror.entries(); | |
| 56 assertEquals(1, entries.length); | |
| 57 assertSame(o2, entries[0].key); | |
| 58 assertEquals(22, entries[0].value); | |
| 59 map.set(o1, 33); | |
| 60 map.set(o3, o2); | |
| 61 map.delete(o2); | |
| 62 map.set(undefined, 44); | |
| 63 | |
| 64 entries = mapMirror.entries(); | |
| 65 assertEquals(3, entries.length); | |
| 66 assertSame(o1, entries[0].key); | |
| 67 assertEquals(33, entries[0].value); | |
| 68 assertSame(o3, entries[1].key); | |
| 69 assertSame(o2, entries[1].value); | |
| 70 assertEquals(undefined, entries[2].key); | |
| 71 assertEquals(44, entries[2].value); | |
| 72 | |
| 73 assertEquals(3, mapMirror.entries(0).length); | |
| 74 assertEquals(1, mapMirror.entries(1).length); | |
| 75 assertEquals(2, mapMirror.entries(2).length); | |
| 76 | |
| 77 // Test the mirror object for Sets | |
| 78 var set = new Set(); | |
| 79 set.add(o1); | |
| 80 set.add(o2); | |
| 81 set.delete(o1); | |
| 82 set.add(undefined); | |
| 83 var setMirror = debug.MakeMirror(set); | |
| 84 testSetMirror(setMirror); | |
| 85 var values = setMirror.values(); | |
| 86 assertEquals(2, values.length); | |
| 87 assertEquals(1, setMirror.values(1).length); | |
| 88 assertSame(o2, values[0]); | |
| 89 assertEquals(undefined, values[1]); | |
| 90 | |
| 91 function initWeakMap(weakMap) { | |
| 92 weakMap.set(o1, 11); | |
| 93 weakMap.set(new Object(), 22); | |
| 94 weakMap.set(o3, 33); | |
| 95 weakMap.set(new Object(), 44); | |
| 96 var weakMapMirror = debug.MakeMirror(weakMap); | |
| 97 testMapMirror(weakMapMirror); | |
| 98 weakMap.set(new Object(), 55); | |
| 99 assertTrue(weakMapMirror.entries().length <= 5); | |
| 100 return weakMapMirror; | |
| 101 } | |
| 102 | |
| 103 // Test the mirror object for WeakMaps | |
| 104 var weakMap = new WeakMap(); | |
| 105 var weakMapMirror = initWeakMap(weakMap); | |
| 106 gc(); | |
| 107 | |
| 108 function testWeakMapEntries(weakMapMirror) { | |
| 109 var entries = weakMapMirror.entries(); | |
| 110 assertEquals(2, entries.length); | |
| 111 assertEquals(2, weakMapMirror.entries(0).length); | |
| 112 assertEquals(1, weakMapMirror.entries(1).length); | |
| 113 var found = 0; | |
| 114 for (var i = 0; i < entries.length; i++) { | |
| 115 if (Object.is(entries[i].key, o1)) { | |
| 116 assertEquals(11, entries[i].value); | |
| 117 found++; | |
| 118 } | |
| 119 if (Object.is(entries[i].key, o3)) { | |
| 120 assertEquals(33, entries[i].value); | |
| 121 found++; | |
| 122 } | |
| 123 } | |
| 124 assertEquals(2, found); | |
| 125 } | |
| 126 | |
| 127 testWeakMapEntries(weakMapMirror); | |
| 128 | |
| 129 function initWeakSet(weakSet) { | |
| 130 weakSet.add(o1); | |
| 131 weakSet.add(new Object()); | |
| 132 weakSet.add(o2); | |
| 133 weakSet.add(new Object()); | |
| 134 weakSet.add(new Object()); | |
| 135 weakSet.add(o3); | |
| 136 weakSet.delete(o2); | |
| 137 var weakSetMirror = debug.MakeMirror(weakSet); | |
| 138 testSetMirror(weakSetMirror); | |
| 139 assertTrue(weakSetMirror.values().length <= 5); | |
| 140 return weakSetMirror; | |
| 141 } | |
| 142 | |
| 143 // Test the mirror object for WeakSets | |
| 144 var weakSet = new WeakSet(); | |
| 145 var weakSetMirror = initWeakSet(weakSet); | |
| 146 gc(); | |
| 147 | |
| 148 function testWeakSetValues(weakSetMirror) { | |
| 149 var values = weakSetMirror.values(); | |
| 150 assertEquals(2, values.length); | |
| 151 assertEquals(2, weakSetMirror.values(0).length); | |
| 152 assertEquals(1, weakSetMirror.values(1).length); | |
| 153 var found = 0; | |
| 154 for (var i = 0; i < values.length; i++) { | |
| 155 if (Object.is(values[i], o1)) { | |
| 156 found++; | |
| 157 } | |
| 158 if (Object.is(values[i], o3)) { | |
| 159 found++; | |
| 160 } | |
| 161 } | |
| 162 assertEquals(2, found); | |
| 163 } | |
| 164 | |
| 165 testWeakSetValues(weakSetMirror); | |
| OLD | NEW |