|
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=777385 |
|
6 --> |
|
7 <window title="Mozilla Bug 777385" |
|
8 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> |
|
9 <div></div> |
|
10 <div id="mydivname"></div> |
|
11 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> |
|
12 |
|
13 <!-- test results are displayed in the html:body --> |
|
14 <body xmlns="http://www.w3.org/1999/xhtml"> |
|
15 <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=" |
|
16 target="_blank">Mozilla Bug 777385</a> |
|
17 </body> |
|
18 |
|
19 <!-- test code goes here --> |
|
20 <script type="application/javascript"> |
|
21 <![CDATA[ |
|
22 /** Test for Bug 777385 **/ |
|
23 |
|
24 let Cu = Components.utils; |
|
25 |
|
26 let live_map = new WeakMap; |
|
27 |
|
28 let get_div_style = function () { |
|
29 return document.getElementById("mydivname").style; |
|
30 } |
|
31 |
|
32 let make_live_map = function () { |
|
33 let my_div_style = get_div_style(); |
|
34 let div_fail = false; |
|
35 try { |
|
36 live_map.set(my_div_style, 12345); |
|
37 } catch (e) { |
|
38 div_fail = true; |
|
39 } |
|
40 ok(!div_fail, "Using elem.style as a weak map key should not produce an exception."); |
|
41 |
|
42 is(live_map.get(get_div_style()), 12345, "Live map should have live style with right value before GC."); |
|
43 |
|
44 } |
|
45 |
|
46 make_live_map(); |
|
47 |
|
48 // RGBColor is a non-nsISupports refCounted class using WebIDL bindings. |
|
49 |
|
50 // non-nsISupports cycle-collected classes should fail as weak map keys. |
|
51 let context = window.getComputedStyle(document.documentElement, null).getPropertyCSSValue("color").getRGBColorValue(); |
|
52 let contextFail = false; |
|
53 try { |
|
54 live_map.set(context, 2); |
|
55 } catch (e) { |
|
56 contextFail = true; |
|
57 } |
|
58 |
|
59 ok(contextFail, "Cycle collected non-nsISupports classes aren't allowed as weak map keys."); |
|
60 |
|
61 /* Set up for running precise GC/CC then check the results. */ |
|
62 |
|
63 SimpleTest.waitForExplicitFinish(); |
|
64 |
|
65 Cu.schedulePreciseGC(function () { |
|
66 SpecialPowers.DOMWindowUtils.cycleCollect(); |
|
67 SpecialPowers.DOMWindowUtils.garbageCollect(); |
|
68 SpecialPowers.DOMWindowUtils.garbageCollect(); |
|
69 |
|
70 is(Cu.nondeterministicGetWeakMapKeys(live_map).length, 1, |
|
71 "Live nsISupports new DOM bindings wrappercached native weak map key should not be removed."); |
|
72 |
|
73 is(live_map.get(get_div_style()), 12345, "Live map should have live style with right value after GC."); |
|
74 |
|
75 SimpleTest.finish(); |
|
76 }); |
|
77 |
|
78 ]]> |
|
79 </script> |
|
80 </window> |