js/xpconnect/tests/chrome/test_getweakmapkeys.xul

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/xpconnect/tests/chrome/test_getweakmapkeys.xul	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,67 @@
     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=688277
     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 688277</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 688277 **/
    1.24 +
    1.25 +  let Cu = Components.utils;
    1.26 +
    1.27 +  /* Fail gracefully if junk is passed in. */
    1.28 +  is(Cu.nondeterministicGetWeakMapKeys(11), undefined,
    1.29 +    "nondeterministicGetWeakMapKeys should return undefined for non-objects");
    1.30 +  is(Cu.nondeterministicGetWeakMapKeys({}), undefined,
    1.31 +    "nondeterministicGetWeakMapKeys should return undefined for non-weakmap objects");
    1.32 +  is(Cu.nondeterministicGetWeakMapKeys(null), undefined,
    1.33 +    "nondeterministicGetWeakMapKeys should return undefined for null");
    1.34 +
    1.35 +  /* return an empty array for an empty WeakMap */
    1.36 +  let mempty = WeakMap();
    1.37 +  is(Cu.nondeterministicGetWeakMapKeys(mempty).length, 0,
    1.38 +    "nondeterministicGetWeakMapKeys should return empty array for empty weakmap");
    1.39 +
    1.40 +  /* Test freeing/nonfreeing. */
    1.41 +  let m = WeakMap();
    1.42 +  let liveKeys = new Array();
    1.43 +
    1.44 +  let add_elements = function () {
    1.45 +    let k1 = {};
    1.46 +    m.set(k1, "live1");
    1.47 +    liveKeys.push(k1);
    1.48 +
    1.49 +    let k2 = {};
    1.50 +    m.set(k2, "dead1");
    1.51 +
    1.52 +    let k = {};
    1.53 +    m.set(k, k); /* simple cycle */
    1.54 +  };
    1.55 +
    1.56 +  add_elements();
    1.57 +
    1.58 +  Cu.schedulePreciseGC(function () {
    1.59 +    let keys = Cu.nondeterministicGetWeakMapKeys(m);
    1.60 +    is(liveKeys.length, 1, "Wrong number of live keys.");
    1.61 +    is(keys.length, 1, "Should have one weak map key.");
    1.62 +    is(m.get(keys[0]), "live1", "live1 should be live");
    1.63 +    SimpleTest.finish();
    1.64 +  });
    1.65 +
    1.66 +  SimpleTest.waitForExplicitFinish();
    1.67 +
    1.68 +  ]]>
    1.69 +  </script>
    1.70 +</window>

mercurial