tor-browser

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

test_proxy_accessors.html (2280B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=1700052
      5 -->
      6 <head>
      7  <meta charset="utf-8">
      8  <title>Test for Bug 1700052</title>
      9  <script src="/tests/SimpleTest/SimpleTest.js"></script>
     10  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
     11 </head>
     12 <body>
     13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1700052">Mozilla Bug 1700052</a>
     14 <p id="display"></p>
     15 <form id="theform"></form>
     16 <pre id="test">
     17 <script>
     18 function expandoTests() {
     19  // Get a DOM proxy with an expando object. Define/redefine a "foo" getter/setter
     20  // and ensure the right function is called.
     21 
     22  var obj = document.getElementById("theform");
     23  var count1 = 0, count2 = 0, count3 = 0;
     24  var fun1 = function() { count1++; };
     25  var fun2 = function() { count2++; };
     26  var fun3 = function() { count3++; };
     27 
     28  Object.defineProperty(obj, "foo", {configurable: true, get: fun1, set: fun1});
     29 
     30  for (var i = 0; i < 100; i++) {
     31    obj.foo;
     32    obj.foo = i;
     33    if (i === 50) {
     34      Object.defineProperty(obj, "foo", {configurable: true, get: fun2, set: fun2});
     35    } else if (i === 80) {
     36      Object.defineProperty(obj, "foo", {configurable: true, get: fun3, set: fun3});
     37    }
     38  }
     39 
     40  is(count1, 102, "call count for fun1 must match");
     41  is(count2, 60, "call count for fun2 must match");
     42  is(count3, 38, "call count for fun3 must match");
     43 }
     44 expandoTests();
     45 
     46 function unshadowedTests() {
     47  // Same as above, but for non-shadowing properties on the prototype.
     48 
     49  var obj = document.getElementById("theform");
     50  var proto = Object.getPrototypeOf(obj);
     51 
     52  var count1 = 0, count2 = 0;
     53  var fun1 = function() { count1++; };
     54  var fun2 = function() { count2++; };
     55 
     56  for (var i = 0; i < 100; i++) {
     57    obj.name;
     58    obj.name = "test";
     59    if (i === 50) {
     60      let desc = Object.getOwnPropertyDescriptor(proto, "name");
     61      desc.get = desc.set = fun1;
     62      Object.defineProperty(proto, "name", desc);
     63    }
     64    if (i === 90) {
     65      let desc = Object.getOwnPropertyDescriptor(proto, "name");
     66      desc.get = desc.set = fun2;
     67      Object.defineProperty(proto, "name", desc);
     68    }
     69  }
     70 
     71  is(count1, 80, "call count for fun1 must match");
     72  is(count2, 18, "call count for fun2 must match");
     73 }
     74 unshadowedTests();
     75 </script>
     76 </pre>
     77 </body>
     78 </html>