js/xpconnect/tests/chrome/test_watchpoints.xul

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/xpconnect/tests/chrome/test_watchpoints.xul	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,75 @@
     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=693527
     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 href="https://bugzilla.mozilla.org/show_bug.cgi?id="
    1.17 +     target="_blank">Mozilla Bug 693527</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 693527 **/
    1.24 +
    1.25 +  let Cu = Components.utils;
    1.26 +  let Ci = Components.interfaces;
    1.27 +
    1.28 +  /* Create a weak reference, with a single-element weak map. */
    1.29 +  let make_weak_ref = function (obj) {
    1.30 +    let m = new WeakMap;
    1.31 +    m.set(obj, {});
    1.32 +    return m;
    1.33 +  };
    1.34 +
    1.35 +  /* Check to see if a weak reference is dead. */
    1.36 +  let weak_ref_dead = function (r) {
    1.37 +    return Cu.nondeterministicGetWeakMapKeys(r).length == 0;
    1.38 +  }
    1.39 +
    1.40 +
    1.41 +  let make_cycle = function () {
    1.42 +    var p = document.createElement("p");
    1.43 +    p.children.x = p;
    1.44 +    var f = function() { };
    1.45 +    p.watch("y", f);
    1.46 +    var d = document.createElement("div");
    1.47 +    d.appendChild(p);
    1.48 +    f.loop = d;
    1.49 +    f.bar = {}; // observing f directly makes the leak go away even without the CC somehow
    1.50 +    return make_weak_ref(f.bar);
    1.51 +  };
    1.52 +
    1.53 +  var cycle_ref = make_cycle();
    1.54 +
    1.55 +
    1.56 +  /* set up for running precise GC/CC then checking the results */
    1.57 +
    1.58 +  SimpleTest.waitForExplicitFinish();
    1.59 +
    1.60 +  Cu.schedulePreciseGC(function () {
    1.61 +    window.QueryInterface(Ci.nsIInterfaceRequestor)
    1.62 +         .getInterface(Ci.nsIDOMWindowUtils)
    1.63 +         .cycleCollect();
    1.64 +    window.QueryInterface(Ci.nsIInterfaceRequestor)
    1.65 +         .getInterface(Ci.nsIDOMWindowUtils)
    1.66 +         .garbageCollect();
    1.67 +    window.QueryInterface(Ci.nsIInterfaceRequestor)
    1.68 +         .getInterface(Ci.nsIDOMWindowUtils)
    1.69 +         .garbageCollect();
    1.70 +  
    1.71 +    ok(weak_ref_dead(cycle_ref), "Garbage gray watchpoint cycle should be collected.");
    1.72 +
    1.73 +    SimpleTest.finish();
    1.74 +  });
    1.75 +
    1.76 +  ]]>
    1.77 +  </script>
    1.78 +</window>

mercurial