tor-browser

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

test_promise_state-03.js (1755B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 /* eslint-disable max-nested-callbacks */
      4 
      5 "use strict";
      6 
      7 /**
      8 * Test that the preview in a Promise's grip is correct when the Promise is
      9 * rejected.
     10 */
     11 
     12 add_task(
     13  threadFrontTest(async ({ threadFront, debuggee }) => {
     14    const packet = await executeOnNextTickAndWaitForPause(
     15      () => evalCode(debuggee),
     16      threadFront
     17    );
     18 
     19    const environment = await packet.frame.getEnvironment();
     20    const grip = environment.bindings.variables.p.value;
     21    ok(grip.preview);
     22    equal(grip.class, "Promise");
     23    equal(grip.preview.ownProperties["<state>"].value, "rejected");
     24    equal(
     25      grip.preview.ownProperties["<reason>"].value.actorID,
     26      packet.frame.arguments[0].actorID,
     27      "The promise's rejected state reason in the preview should be the same " +
     28        "value passed to the then function"
     29    );
     30 
     31    const objClient = threadFront.pauseGrip(grip);
     32    const { promiseState } = await objClient.getPromiseState();
     33    equal(promiseState.state, "rejected");
     34    equal(
     35      promiseState.reason.getGrip().actorID,
     36      packet.frame.arguments[0].actorID,
     37      "The promise's rejected state value in getPromiseState() should be " +
     38        "the same value passed to the then function"
     39    );
     40  })
     41 );
     42 
     43 function evalCode(debuggee) {
     44  /* eslint-disable mozilla/var-only-at-top-level, no-unused-vars */
     45  // prettier-ignore
     46  Cu.evalInSandbox(
     47    "doTest();\n" +
     48    function doTest() {
     49      var resolved = Promise.reject(new Error("uh oh"));
     50      resolved.catch(() => {
     51        var p = resolved;
     52        debugger;
     53      });
     54    },
     55    debuggee
     56  );
     57  /* eslint-enable mozilla/var-only-at-top-level, no-unused-vars */
     58 }