|
1 <?xml version="1.0"?> |
|
2 <?xml-stylesheet type="text/css" href="chrome://global/skin"?> |
|
3 <?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?> |
|
4 <!-- |
|
5 https://bugzilla.mozilla.org/show_bug.cgi?id=688277 |
|
6 --> |
|
7 <window title="Mozilla Bug " |
|
8 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> |
|
9 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> |
|
10 |
|
11 <!-- test results are displayed in the html:body --> |
|
12 <body xmlns="http://www.w3.org/1999/xhtml"> |
|
13 <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=" |
|
14 target="_blank">Mozilla Bug 688277</a> |
|
15 </body> |
|
16 |
|
17 <!-- test code goes here --> |
|
18 <script type="application/javascript"> |
|
19 <![CDATA[ |
|
20 /** Test for Bug 688277 **/ |
|
21 |
|
22 let Cu = Components.utils; |
|
23 |
|
24 /* Fail gracefully if junk is passed in. */ |
|
25 is(Cu.nondeterministicGetWeakMapKeys(11), undefined, |
|
26 "nondeterministicGetWeakMapKeys should return undefined for non-objects"); |
|
27 is(Cu.nondeterministicGetWeakMapKeys({}), undefined, |
|
28 "nondeterministicGetWeakMapKeys should return undefined for non-weakmap objects"); |
|
29 is(Cu.nondeterministicGetWeakMapKeys(null), undefined, |
|
30 "nondeterministicGetWeakMapKeys should return undefined for null"); |
|
31 |
|
32 /* return an empty array for an empty WeakMap */ |
|
33 let mempty = WeakMap(); |
|
34 is(Cu.nondeterministicGetWeakMapKeys(mempty).length, 0, |
|
35 "nondeterministicGetWeakMapKeys should return empty array for empty weakmap"); |
|
36 |
|
37 /* Test freeing/nonfreeing. */ |
|
38 let m = WeakMap(); |
|
39 let liveKeys = new Array(); |
|
40 |
|
41 let add_elements = function () { |
|
42 let k1 = {}; |
|
43 m.set(k1, "live1"); |
|
44 liveKeys.push(k1); |
|
45 |
|
46 let k2 = {}; |
|
47 m.set(k2, "dead1"); |
|
48 |
|
49 let k = {}; |
|
50 m.set(k, k); /* simple cycle */ |
|
51 }; |
|
52 |
|
53 add_elements(); |
|
54 |
|
55 Cu.schedulePreciseGC(function () { |
|
56 let keys = Cu.nondeterministicGetWeakMapKeys(m); |
|
57 is(liveKeys.length, 1, "Wrong number of live keys."); |
|
58 is(keys.length, 1, "Should have one weak map key."); |
|
59 is(m.get(keys[0]), "live1", "live1 should be live"); |
|
60 SimpleTest.finish(); |
|
61 }); |
|
62 |
|
63 SimpleTest.waitForExplicitFinish(); |
|
64 |
|
65 ]]> |
|
66 </script> |
|
67 </window> |