js/src/jit-test/tests/collections/WeakMap-clear.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 var key = {};
michael@0 2 var wm = WeakMap();
michael@0 3
michael@0 4 assertEq(wm.has(key), false);
michael@0 5 // Clearing an already empty WeakMap
michael@0 6 wm.clear();
michael@0 7 assertEq(wm.has(key), false);
michael@0 8
michael@0 9 // Clearing a WeakMap with a live key
michael@0 10 wm.set(key, 42);
michael@0 11 assertEq(wm.has(key), true);
michael@0 12 wm.clear();
michael@0 13 assertEq(wm.has(key), false);
michael@0 14
michael@0 15 // Clearing a WeakMap with keys turned to garbage
michael@0 16 wm.set(key, {});
michael@0 17 for (var i = 0; i < 10; i++)
michael@0 18 wm.set({}, {});
michael@0 19 assertEq(wm.has(key), true);
michael@0 20 wm.clear();
michael@0 21 assertEq(wm.has(key), false);
michael@0 22
michael@0 23 // Clearing a WeakMap with keys turned to garbage and after doing a GC
michael@0 24 wm.set(key, {});
michael@0 25 for (var i = 0; i < 10; i++)
michael@0 26 wm.set({}, {});
michael@0 27 assertEq(wm.has(key), true);
michael@0 28 gc();
michael@0 29 assertEq(wm.has(key), true);
michael@0 30 wm.clear();
michael@0 31 assertEq(wm.has(key), false);
michael@0 32
michael@0 33 // More testing when the key is no longer live
michael@0 34 wm.set(key, {});
michael@0 35 key = null;
michael@0 36 wm.clear();
michael@0 37 gc();
michael@0 38 var key2 = {};
michael@0 39 wm.set(key2, {});
michael@0 40 key2 = null;
michael@0 41 gc();
michael@0 42 wm.clear();

mercurial