tor-browser

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

test_on_promise_settled_duplicates.html (1572B)


      1 <!--
      2  Any copyright is dedicated to the Public Domain.
      3  http://creativecommons.org/publicdomain/zero/1.0/
      4 -->
      5 
      6 <!--
      7 Bug 1084065 - Test that Debugger.prototype.onPromiseResolved doesn't get dupes.
      8 -->
      9 
     10 <html>
     11 <head>
     12  <title>Test for interaction with SpiderMonkey's Debugger.prototype.onNewPromise</title>
     13  <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
     14  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
     15 </head>
     16 <body>
     17 <p id="display"></p>
     18 <div id="content" style="display: none">
     19 
     20 </div>
     21 <pre id="test">
     22  <script type="application/javascript">
     23  SimpleTest.waitForExplicitFinish();
     24 
     25  is(Object.prototype.toString.call(new Promise(function() {})),
     26     "[object Promise]",
     27     "We should have the native DOM promise implementation.");
     28 
     29  const {addDebuggerToGlobal} = ChromeUtils.importESModule("resource://gre/modules/jsdebugger.sys.mjs");
     30  var dbgGlobal = new Cu.Sandbox(document.nodePrincipal,
     31                                 {freshCompartment: true});
     32  addDebuggerToGlobal(dbgGlobal);
     33  var dbg = new dbgGlobal.Debugger(this);
     34 
     35  var seen = new Set();
     36  dbg.onPromiseSettled = function(wp) {
     37    is(seen.has(wp), false);
     38    seen.add(wp);
     39  };
     40 
     41  var promise = new Promise(function(fulfill) {
     42    fulfill(1);
     43    fulfill(2);
     44    fulfill(3);
     45  });
     46 
     47  promise
     48    .then(function() {
     49      dbg.onPromiseSettled = undefined;
     50    })
     51    .catch(function(e) {
     52      ok(false, "Got an unexpected error: " + e);
     53    })
     54    .then(SimpleTest.finish);
     55  </script>
     56 </pre>
     57 </body>
     58 </html>