michael@0: var key = {}; michael@0: var wm = WeakMap(); michael@0: michael@0: assertEq(wm.has(key), false); michael@0: // Clearing an already empty WeakMap michael@0: wm.clear(); michael@0: assertEq(wm.has(key), false); michael@0: michael@0: // Clearing a WeakMap with a live key michael@0: wm.set(key, 42); michael@0: assertEq(wm.has(key), true); michael@0: wm.clear(); michael@0: assertEq(wm.has(key), false); michael@0: michael@0: // Clearing a WeakMap with keys turned to garbage michael@0: wm.set(key, {}); michael@0: for (var i = 0; i < 10; i++) michael@0: wm.set({}, {}); michael@0: assertEq(wm.has(key), true); michael@0: wm.clear(); michael@0: assertEq(wm.has(key), false); michael@0: michael@0: // Clearing a WeakMap with keys turned to garbage and after doing a GC michael@0: wm.set(key, {}); michael@0: for (var i = 0; i < 10; i++) michael@0: wm.set({}, {}); michael@0: assertEq(wm.has(key), true); michael@0: gc(); michael@0: assertEq(wm.has(key), true); michael@0: wm.clear(); michael@0: assertEq(wm.has(key), false); michael@0: michael@0: // More testing when the key is no longer live michael@0: wm.set(key, {}); michael@0: key = null; michael@0: wm.clear(); michael@0: gc(); michael@0: var key2 = {}; michael@0: wm.set(key2, {}); michael@0: key2 = null; michael@0: gc(); michael@0: wm.clear();