tor-browser

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

test_stepping-19.js (2375B)


      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 that step out stops at the async parent's frame.
      8 */
      9 
     10 async function testFinish({ devToolsClient }) {
     11  await close(devToolsClient);
     12 
     13  do_test_finished();
     14 }
     15 
     16 async function invokeAndPause({ global, threadFront }, expression) {
     17  return executeOnNextTickAndWaitForPause(
     18    () => global.eval(expression),
     19    threadFront
     20  );
     21 }
     22 
     23 async function steps(threadFront, sequence) {
     24  const locations = [];
     25  for (const cmd of sequence) {
     26    const packet = await step(threadFront, cmd);
     27    locations.push(getPauseLocation(packet));
     28  }
     29  return locations;
     30 }
     31 
     32 async function step(threadFront, cmd) {
     33  return cmd(threadFront);
     34 }
     35 
     36 function getPauseLocation(packet) {
     37  const { line, column } = packet.frame.where;
     38  return { line, column };
     39 }
     40 
     41 async function stepOutBeforeTimer(dbg, func, frameIndex, expectedLocation) {
     42  const { threadFront } = dbg;
     43 
     44  await invokeAndPause(dbg, `${func}()`);
     45  await steps(threadFront, [stepOver, stepIn]);
     46 
     47  const { frames } = await threadFront.frames(0, 5);
     48  const frameActorID = frames[frameIndex].actorID;
     49  const packet = await stepOut(threadFront, frameActorID);
     50 
     51  deepEqual(
     52    getPauseLocation(packet),
     53    expectedLocation,
     54    `step out location in ${func}`
     55  );
     56 
     57  await resumeAndWaitForPause(threadFront);
     58  await resume(threadFront);
     59 }
     60 
     61 async function stepOutAfterTimer(dbg, func, frameIndex, expectedLocation) {
     62  const { threadFront } = dbg;
     63 
     64  await invokeAndPause(dbg, `${func}()`);
     65  await steps(threadFront, [stepOver, stepIn, stepOver, stepOver]);
     66 
     67  const { frames } = await threadFront.frames(0, 5);
     68  const frameActorID = frames[frameIndex].actorID;
     69  const packet = await stepOut(threadFront, frameActorID);
     70 
     71  deepEqual(
     72    getPauseLocation(packet),
     73    expectedLocation,
     74    `step out location in ${func}`
     75  );
     76 
     77  await resumeAndWaitForPause(threadFront);
     78  await dbg.threadFront.resume();
     79 }
     80 
     81 function run_test() {
     82  return (async function () {
     83    const dbg = await setupTestFromUrl("stepping-async.js");
     84 
     85    info(`Test stepping out before timer;`);
     86    await stepOutBeforeTimer(dbg, "stuff", 0, { line: 27, column: 2 });
     87 
     88    info(`Test stepping out after timer;`);
     89    await stepOutAfterTimer(dbg, "stuff", 0, { line: 29, column: 2 });
     90 
     91    await testFinish(dbg);
     92  })();
     93 }