1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/xpconnect/tests/chrome/test_weakmap_keys_preserved2.xul Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,84 @@ 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=673468 1.9 +--> 1.10 +<window title="Mozilla Bug " 1.11 + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> 1.12 + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> 1.13 + 1.14 + <!-- test results are displayed in the html:body --> 1.15 + <body xmlns="http://www.w3.org/1999/xhtml"> 1.16 + <a id="testelem" href="https://bugzilla.mozilla.org/show_bug.cgi?id=" 1.17 + target="_blank">Mozilla Bug 673468</a> 1.18 + </body> 1.19 + 1.20 + <!-- test code goes here --> 1.21 + <script type="application/javascript"> 1.22 + <![CDATA[ 1.23 + /** Test for Bug 673468 **/ 1.24 + 1.25 + let Cc = Components.classes; 1.26 + let Cu = Components.utils; 1.27 + let Ci = Components.interfaces; 1.28 + 1.29 + SpecialPowers.DOMWindowUtils.garbageCollect(); 1.30 + 1.31 + let get_live_dom = function () { 1.32 + return document.getElementById("testelem"); 1.33 + }; 1.34 + 1.35 + let wrappers_as_keys_test = function () { 1.36 + let e = new MessageEvent("foo", { bubbles: false, cancellable: false, 1.37 + data: { dummy: document.createElement("foo") }}); 1.38 + window.eeeevent = e; 1.39 + 1.40 + let live_dom = e.data.dummy; 1.41 + let dead_dom = document.createElement("div"); 1.42 + let dead_child = document.createElement("div"); 1.43 + dead_dom.appendChild(dead_child); 1.44 + is(dead_dom.children.length, 1, "children have wrong length"); 1.45 + let wrappee = new Object(); 1.46 + 1.47 + dead_dom.abcxyz = wrappee; 1.48 + 1.49 + let system = Cc["@mozilla.org/systemprincipal;1"].createInstance(); 1.50 + let sandbox = Cu.Sandbox(system); 1.51 + 1.52 + sandbox.wrapper = wrappee; 1.53 + sandbox.value = dead_dom; 1.54 + let map = Cu.evalInSandbox("wm = new WeakMap(); wm.set(wrapper, value); wm", sandbox); 1.55 + sandbox.wrapper = null; 1.56 + sandbox.value = null; 1.57 + 1.58 + live_dom.xyzabc = {wrappee: wrappee, m: map, sb: sandbox}; 1.59 + 1.60 + let key = Cu.nondeterministicGetWeakMapKeys(map)[0]; 1.61 + let value = map.get(key); 1.62 + is(value.children.length, 1, "children have wrong length"); 1.63 + } 1.64 + 1.65 + wrappers_as_keys_test(); 1.66 + 1.67 + let check_wrappers_as_keys = function () { 1.68 + let live_dom = window.eeeevent.data.dummy; 1.69 + let live_map = live_dom.xyzabc.m; 1.70 + let sandbox = live_dom.xyzabc.sb; 1.71 + is(Cu.nondeterministicGetWeakMapKeys(live_map).length, 1, 1.72 + "Map should not be empty."); 1.73 + let key = Cu.nondeterministicGetWeakMapKeys(live_map)[0]; 1.74 + let value = live_map.get(key); 1.75 + is(value.children.length, 1, "children have wrong length"); 1.76 + } 1.77 + 1.78 + Cu.schedulePreciseGC(function () { 1.79 + SpecialPowers.DOMWindowUtils.cycleCollect(); 1.80 + SpecialPowers.DOMWindowUtils.garbageCollect(); 1.81 + 1.82 + check_wrappers_as_keys(); 1.83 + }); 1.84 + 1.85 + ]]> 1.86 + </script> 1.87 +</window>