1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/xpconnect/tests/chrome/test_paris_weakmap_keys.xul Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,80 @@ 1.4 +<?xml version="1.0"?> 1.5 +<?xml-stylesheet type="text/css" href="chrome://global/skin"?> 1.6 +<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?> 1.7 +<!-- 1.8 +https://bugzilla.mozilla.org/show_bug.cgi?id=777385 1.9 +--> 1.10 +<window title="Mozilla Bug 777385" 1.11 + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> 1.12 + <div></div> 1.13 + <div id="mydivname"></div> 1.14 + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> 1.15 + 1.16 + <!-- test results are displayed in the html:body --> 1.17 + <body xmlns="http://www.w3.org/1999/xhtml"> 1.18 + <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=" 1.19 + target="_blank">Mozilla Bug 777385</a> 1.20 + </body> 1.21 + 1.22 + <!-- test code goes here --> 1.23 + <script type="application/javascript"> 1.24 + <![CDATA[ 1.25 + /** Test for Bug 777385 **/ 1.26 + 1.27 + let Cu = Components.utils; 1.28 + 1.29 + let live_map = new WeakMap; 1.30 + 1.31 + let get_div_style = function () { 1.32 + return document.getElementById("mydivname").style; 1.33 + } 1.34 + 1.35 + let make_live_map = function () { 1.36 + let my_div_style = get_div_style(); 1.37 + let div_fail = false; 1.38 + try { 1.39 + live_map.set(my_div_style, 12345); 1.40 + } catch (e) { 1.41 + div_fail = true; 1.42 + } 1.43 + ok(!div_fail, "Using elem.style as a weak map key should not produce an exception."); 1.44 + 1.45 + is(live_map.get(get_div_style()), 12345, "Live map should have live style with right value before GC."); 1.46 + 1.47 + } 1.48 + 1.49 + make_live_map(); 1.50 + 1.51 + // RGBColor is a non-nsISupports refCounted class using WebIDL bindings. 1.52 + 1.53 + // non-nsISupports cycle-collected classes should fail as weak map keys. 1.54 + let context = window.getComputedStyle(document.documentElement, null).getPropertyCSSValue("color").getRGBColorValue(); 1.55 + let contextFail = false; 1.56 + try { 1.57 + live_map.set(context, 2); 1.58 + } catch (e) { 1.59 + contextFail = true; 1.60 + } 1.61 + 1.62 + ok(contextFail, "Cycle collected non-nsISupports classes aren't allowed as weak map keys."); 1.63 + 1.64 + /* Set up for running precise GC/CC then check the results. */ 1.65 + 1.66 + SimpleTest.waitForExplicitFinish(); 1.67 + 1.68 + Cu.schedulePreciseGC(function () { 1.69 + SpecialPowers.DOMWindowUtils.cycleCollect(); 1.70 + SpecialPowers.DOMWindowUtils.garbageCollect(); 1.71 + SpecialPowers.DOMWindowUtils.garbageCollect(); 1.72 + 1.73 + is(Cu.nondeterministicGetWeakMapKeys(live_map).length, 1, 1.74 + "Live nsISupports new DOM bindings wrappercached native weak map key should not be removed."); 1.75 + 1.76 + is(live_map.get(get_div_style()), 12345, "Live map should have live style with right value after GC."); 1.77 + 1.78 + SimpleTest.finish(); 1.79 + }); 1.80 + 1.81 + ]]> 1.82 + </script> 1.83 +</window>