4 https://bugzilla.mozilla.org/show_bug.cgi?id=688277
8 <title>Tests for nondeterministicGetWeakMapKeys
</title>
9 <script src=
"/tests/SimpleTest/SimpleTest.js"></script>
10 <link rel=
"stylesheet" type=
"text/css" href=
"/tests/SimpleTest/test.css"/>
11 <script type=
"application/javascript">
12 /** Test for Bug
688277 **/
14 /* Fail gracefully if junk is passed in. */
15 is(SpecialPowers.nondeterministicGetWeakMapKeys(
11), undefined,
16 "nondeterministicGetWeakMapKeys should return undefined for non-objects");
17 is(SpecialPowers.nondeterministicGetWeakMapKeys({}), undefined,
18 "nondeterministicGetWeakMapKeys should return undefined for non-weakmap objects");
19 is(SpecialPowers.nondeterministicGetWeakMapKeys(null), undefined,
20 "nondeterministicGetWeakMapKeys should return undefined for null");
22 /* return an empty array for an empty WeakMap */
23 let mempty = new WeakMap();
24 is(SpecialPowers.nondeterministicGetWeakMapKeys(mempty).length,
0,
25 "nondeterministicGetWeakMapKeys should return empty array for empty weakmap");
27 /* Test freeing/nonfreeing. */
28 let m = new WeakMap();
29 let liveKeys = new Array();
31 let add_elements = function () {
40 m.set(k, k); /* simple cycle */
45 SpecialPowers.exactGC(function () {
46 let keys = SpecialPowers.nondeterministicGetWeakMapKeys(m);
47 is(liveKeys.length,
1,
"Wrong number of live keys.");
48 is(keys.length,
1,
"Should have one weak map key.");
49 is(m.get(keys[
0]),
"live1",
"live1 should be live");
53 SimpleTest.waitForExplicitFinish();