Index: test/mjsunit/harmony/mirror-collections.js |
diff --git a/test/mjsunit/harmony/mirror-collections.js b/test/mjsunit/harmony/mirror-collections.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..1879fa8970eb4d65c6a82bdc1bf43bff63b67c4d |
--- /dev/null |
+++ b/test/mjsunit/harmony/mirror-collections.js |
@@ -0,0 +1,80 @@ |
+// Copyright 2014 the V8 project authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+// Flags: --expose-debug-as debug --expose-gc --harmony-collections |
+ |
+function testMapMirror(mirror) { |
+ // Create JSON representation. |
+ 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.
|
+ var json = JSON.stringify(serializer.serializeValue(mirror)); |
+ |
+ // Check the mirror hierachy. |
+ assertTrue(mirror instanceof debug.Mirror); |
+ assertTrue(mirror instanceof debug.ValueMirror); |
+ assertTrue(mirror instanceof debug.ObjectMirror); |
+ assertTrue(mirror instanceof debug.MapMirror); |
+ |
+ assertTrue(mirror.isMap()); |
+ |
+ // Parse JSON representation and check. |
+ var fromJSON = eval('(' + json + ')'); |
+ assertEquals('map', fromJSON.type); |
+} |
+ |
+var o1 = new Object(); |
+var o2 = new Object(); |
+var o3 = new Object(); |
+ |
+// Test the mirror object for Maps |
+var map = new Map(); |
+map.set(o1, 11); |
+map.set(o2, 22); |
+map.delete(o1); |
+var mapMirror = debug.MakeMirror(map); |
+testMapMirror(mapMirror); |
+var entries = mapMirror.entries(); |
+assertEquals(2, entries.length); |
+assertSame(o2, entries[0]); |
+assertEquals(22, entries[1]); |
+map.set(o1, 33); |
+map.set(o3, o2); |
+map.delete(o2); |
+map.set(undefined, 44); |
+entries = mapMirror.entries(); |
+assertEquals(6, entries.length); |
+assertSame(o1, entries[0]); |
+assertEquals(33, entries[1]); |
+assertSame(o3, entries[2]); |
+assertSame(o2, entries[3]); |
+assertEquals(undefined, entries[4]); |
+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
|
+ |
+// Test the mirror object for WeakMaps |
+var weakMap = new WeakMap(); |
+weakMap.set(o1, 11); |
+weakMap.set(new Object(), 22); |
+weakMap.set(o3, 33); |
+var weakMapMirror = debug.MakeMirror(weakMap); |
+testMapMirror(weakMapMirror); |
+ |
+function testWeakMapMirrorBeforeGC(mirror) { |
+ var entries = mirror.entries(); |
+ assertEquals(6, entries.length); |
+ assertEquals(11, entries[entries.indexOf(o1) + 1]); |
+ assertEquals(33, entries[entries.indexOf(o3) + 1]); |
+ assertTrue(entries.indexOf(22) >= 1); |
+} |
+ |
+testWeakMapMirrorBeforeGC(weakMapMirror); |
+gc(); |
+ |
+function testWeakMapMirrorAfterGC(mirror) { |
+ var entries = mirror.entries(); |
+ assertEquals(4, entries.length); |
+ assertEquals(11, entries[entries.indexOf(o1) + 1]); |
+ assertEquals(33, entries[entries.indexOf(o3) + 1]); |
+ assertTrue(entries.indexOf(22) == -1); |
+} |
+ |
+testWeakMapMirrorAfterGC(weakMapMirror); |