tor-browser

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

test_stepping-18.js (2594B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 /**
      7 * Check scenarios where we're leaving function a and
      8 * going to the function b's call-site.
      9 */
     10 
     11 async function testFinish({ devToolsClient }) {
     12  await close(devToolsClient);
     13 
     14  do_test_finished();
     15 }
     16 
     17 async function invokeAndPause({ global, threadFront }, expression) {
     18  return executeOnNextTickAndWaitForPause(
     19    () => global.eval(expression),
     20    threadFront
     21  );
     22 }
     23 
     24 async function steps(threadFront, sequence) {
     25  const locations = [];
     26  for (const cmd of sequence) {
     27    const packet = await step(threadFront, cmd);
     28    locations.push(getPauseLocation(packet));
     29  }
     30  return locations;
     31 }
     32 
     33 async function step(threadFront, cmd) {
     34  return cmd(threadFront);
     35 }
     36 
     37 function getPauseLocation(packet) {
     38  const { line, column } = packet.frame.where;
     39  return { line, column };
     40 }
     41 
     42 async function stepOutOfA(dbg, func, frameIndex, expectedLocation) {
     43  const { threadFront } = dbg;
     44 
     45  info("pause and step into a()");
     46  await invokeAndPause(dbg, `${func}()`);
     47  await steps(threadFront, [stepOver, stepIn, stepIn]);
     48 
     49  const { frames } = await threadFront.frames(0, 5);
     50  const frameActorID = frames[frameIndex].actorID;
     51  const packet = await stepOut(threadFront, frameActorID);
     52 
     53  deepEqual(
     54    getPauseLocation(packet),
     55    expectedLocation,
     56    `step over location in ${func}`
     57  );
     58 
     59  await dbg.threadFront.resume();
     60 }
     61 
     62 async function stepOverInA(dbg, func, frameIndex, expectedLocation) {
     63  const { threadFront } = dbg;
     64 
     65  info("pause and step into a()");
     66  await invokeAndPause(dbg, `${func}()`);
     67  await steps(threadFront, [stepOver, stepIn]);
     68 
     69  const { frames } = await threadFront.frames(0, 5);
     70  const frameActorID = frames[frameIndex].actorID;
     71  const packet = await stepOver(threadFront, frameActorID);
     72 
     73  deepEqual(
     74    getPauseLocation(packet),
     75    expectedLocation,
     76    `step over location in ${func}`
     77  );
     78 
     79  await dbg.threadFront.resume();
     80 }
     81 
     82 function run_test() {
     83  return (async function () {
     84    const dbg = await setupTestFromUrl("stepping.js");
     85 
     86    info(`Test step over with the 1st frame`);
     87    await stepOverInA(dbg, "arithmetic", 0, { line: 8, column: 0 });
     88 
     89    info(`Test step over with the 2nd frame`);
     90    await stepOverInA(dbg, "arithmetic", 1, { line: 17, column: 0 });
     91 
     92    info(`Test step out with the 1st frame`);
     93    await stepOutOfA(dbg, "nested", 0, { line: 31, column: 0 });
     94 
     95    info(`Test step out with the 2nd frame`);
     96    await stepOutOfA(dbg, "nested", 1, { line: 36, column: 0 });
     97 
     98    await testFinish(dbg);
     99  })();
    100 }