js/xpconnect/tests/mochitest/test_crosscompartment_weakmap.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/xpconnect/tests/mochitest/test_crosscompartment_weakmap.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,44 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<head>
     1.7 +  <title>Test Cross-Compartment DOM WeakMaps</title>
     1.8 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     1.9 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.10 +</head>
    1.11 +<body>
    1.12 +<p id="display"></p>
    1.13 +<script type="application/javascript">
    1.14 +
    1.15 +var my_map = WeakMap();
    1.16 +
    1.17 +function setup() {
    1.18 +  var item = window.frames[0].document.querySelector("body");
    1.19 +
    1.20 +  my_map.set(item, "success_string");
    1.21 +
    1.22 +  var rule_fail = false;
    1.23 +  try {
    1.24 +    my_map.set(window.frames[0].document.styleSheets[0].cssRules[0], 1);
    1.25 +  } catch (e) {
    1.26 +    rule_fail = true;
    1.27 +  }
    1.28 +  ok(rule_fail, "Using rule as a weak map key across compartments should produce an exception because it can't be wrapper preserved.");
    1.29 +}
    1.30 +
    1.31 +function runTest() {
    1.32 +  setup();
    1.33 +  SpecialPowers.forceGC();
    1.34 +  SpecialPowers.forceCC();
    1.35 +  SpecialPowers.forceGC();
    1.36 +  SpecialPowers.forceCC();
    1.37 +  var item = window.frames[0].document.querySelector("body");
    1.38 +  is(my_map.get(item), "success_string", "Preserve reflectors used cross-compartment as weak map keys.");
    1.39 +}
    1.40 +
    1.41 +</script>
    1.42 +<iframe src="file_crosscompartment_weakmap.html" onload="runTest()"></iframe>
    1.43 +
    1.44 +
    1.45 +</pre>
    1.46 +</body>
    1.47 +</html>

mercurial