tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_paris_weakmap_keys.html (2549B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=777385
      5 -->
      6 <head>
      7  <meta charset="utf-8">
      8  <title>Tests for WebIDL objects as weak map keys</title>
      9  <script src="/tests/SimpleTest/SimpleTest.js"></script>
     10  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
     11  <script type="application/javascript">
     12 
     13  /** Test for Bug 777385 **/
     14 
     15  SimpleTest.waitForExplicitFinish();
     16 
     17  // We wait to run this until the load event because it needs to access an element.
     18  function go() {
     19 
     20  let live_map = new WeakMap;
     21 
     22  let get_div_style = function () {
     23    return document.getElementById("mydivname").style;
     24  }
     25 
     26  let make_live_map = function () {
     27    let my_div_style = get_div_style();
     28    let div_fail = false;
     29    try {
     30      live_map.set(my_div_style, 12345);
     31    } catch (e) {
     32      div_fail = true;
     33    }
     34    ok(!div_fail, "Using elem.style as a weak map key should not produce an exception.");
     35 
     36    is(live_map.get(get_div_style()), 12345, "Live map should have live style with right value before GC.");
     37 
     38  }
     39 
     40  make_live_map();
     41 
     42  let tf = new TestFunctions;
     43 
     44  let add_non_isupports2 = function () {
     45    let testKey = tf.wrapperCachedNonISupportsObject;
     46 
     47    let testFail = false;
     48    try {
     49      live_map.set(testKey, 23456);
     50    } catch (e) {
     51      testFail = true;
     52    }
     53 
     54    ok(!testFail, "Using a wrapper cached non-nsISupports class as a weak map key should not produce an exception.");
     55 
     56    is(live_map.get(testKey), 23456, "Live map should have wrapper cached non-nsISupports class right value before GC.");
     57  }
     58 
     59  add_non_isupports2();
     60 
     61 
     62  /* Set up for running precise GC/CC then check the results. */
     63 
     64  SpecialPowers.exactGC(function () {
     65    SpecialPowers.forceCC();
     66    SpecialPowers.forceGC();
     67    SpecialPowers.forceGC();
     68 
     69    is(SpecialPowers.nondeterministicGetWeakMapKeys(live_map).length, 2,
     70       "Live WebIDL bindings keys should not be removed from a weak map.");
     71 
     72    is(live_map.get(get_div_style()), 12345, "Live weak map should have live style with right value after GC.");
     73    is(live_map.get(tf.wrapperCachedNonISupportsObject), 23456,
     74       "Live weak map should have live wrapper cached non-nsISupports class with right value after GC.");
     75 
     76    SimpleTest.finish();
     77  });
     78 
     79  }
     80 
     81  SimpleTest.waitForExplicitFinish();
     82 
     83  addLoadEvent(function() {
     84    SpecialPowers.pushPrefEnv({set: [['dom.expose_test_interfaces', true]]},
     85                              go);
     86  });
     87  </script>
     88 </head>
     89 <div></div>
     90 <div id="mydivname"></div>
     91 <body>
     92 <p id="display"></p>
     93 </body>
     94 </html>