4 https://bugzilla.mozilla.org/show_bug.cgi?id=777385
8 <title>Tests for WebIDL objects as weak map keys
</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">
13 /** Test for Bug
777385 **/
15 SimpleTest.waitForExplicitFinish();
17 // We wait to run this until the load event because it needs to access an element.
20 let live_map = new WeakMap;
22 let get_div_style = function () {
23 return document.getElementById(
"mydivname").style;
26 let make_live_map = function () {
27 let my_div_style = get_div_style();
30 live_map.set(my_div_style,
12345);
34 ok(!div_fail,
"Using elem.style as a weak map key should not produce an exception.");
36 is(live_map.get(get_div_style()),
12345,
"Live map should have live style with right value before GC.");
42 let tf = new TestFunctions;
44 let add_non_isupports2 = function () {
45 let testKey = tf.wrapperCachedNonISupportsObject;
49 live_map.set(testKey,
23456);
54 ok(!testFail,
"Using a wrapper cached non-nsISupports class as a weak map key should not produce an exception.");
56 is(live_map.get(testKey),
23456,
"Live map should have wrapper cached non-nsISupports class right value before GC.");
62 /* Set up for running precise GC/CC then check the results. */
64 SpecialPowers.exactGC(function () {
65 SpecialPowers.forceCC();
66 SpecialPowers.forceGC();
67 SpecialPowers.forceGC();
69 is(SpecialPowers.nondeterministicGetWeakMapKeys(live_map).length,
2,
70 "Live WebIDL bindings keys should not be removed from a weak map.");
72 is(live_map.get(get_div_style()),
12345,
"Live weak map should have live style with right value after GC.");
73 is(live_map.get(tf.wrapperCachedNonISupportsObject),
23456,
74 "Live weak map should have live wrapper cached non-nsISupports class with right value after GC.");
81 SimpleTest.waitForExplicitFinish();
83 addLoadEvent(function() {
84 SpecialPowers.pushPrefEnv({set: [['dom.expose_test_interfaces', true]]},
90 <div id=
"mydivname"></div>