js/xpconnect/tests/chrome/test_paris_weakmap_keys.xul

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial