Bug 1915045 Ensure decode tasks are scheduled on BufferingState::Enter() r=media...
[gecko.git] / js / xpconnect / tests / mochitest / test_getweakmapkeys.html
blob7942d9b945908600d8147fbc0e6469d8b59b6576
1 <!DOCTYPE HTML>
2 <html>
3 <!--
4 https://bugzilla.mozilla.org/show_bug.cgi?id=688277
5 -->
6 <head>
7 <meta charset="utf-8">
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 () {
32 let k1 = {};
33 m.set(k1, "live1");
34 liveKeys.push(k1);
36 let k2 = {};
37 m.set(k2, "dead1");
39 let k = {};
40 m.set(k, k); /* simple cycle */
43 add_elements();
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");
50 SimpleTest.finish();
51 });
53 SimpleTest.waitForExplicitFinish();
54 </script>
55 </head>
56 <body>
57 <p id="display"></p>
58 </body>
59 </html>