tor-browser

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

test_resolve_dead_promise.js (1166B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 /* See https://bugzilla.mozilla.org/show_bug.cgi?id=1298597 */
      6 
      7 function run_test()
      8 {
      9  var sb = Cu.Sandbox("http://www.blah.com");
     10  var resolveFun;
     11  var p1 = new sb.Promise((res, rej) => {resolveFun = res});
     12  var rejectFun;
     13  var p2 = new sb.Promise((res, rej) => {rejectFun = rej});
     14  Cu.nukeSandbox(sb);
     15  Assert.ok(Cu.isDeadWrapper(sb), "sb should be dead");
     16  Assert.ok(Cu.isDeadWrapper(p1), "p1 should be dead");
     17  Assert.ok(Cu.isDeadWrapper(p2), "p2 should be dead");
     18 
     19  var exception;
     20 
     21  try{
     22    resolveFun(1);
     23    Assert.ok(false);
     24  } catch (e) {
     25    exception = e;
     26  }
     27  Assert.ok(exception.toString().includes("can't access dead object"),
     28            "Resolving dead wrapped promise should throw");
     29 
     30  exception = undefined;
     31  try{
     32    rejectFun(1);
     33    Assert.ok(false);
     34  } catch (e) {
     35    exception = e;
     36  }
     37  Assert.ok(exception.toString().includes("can't access dead object"),
     38            "Rejecting dead wrapped promise should throw");
     39 }