tor-browser

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

browser_dbg-sourcemapped-stepping.js (4423B)


      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 "use strict";
      6 
      7 // Tests for stepping through Babel's compile output.
      8 requestLongerTimeout(4);
      9 
     10 add_task(async function () {
     11  const dbg = await initDebugger("doc-sourcemapped.html");
     12 
     13  await testStepOverForOf(dbg);
     14  await testStepOverForOfArray(dbg);
     15  await testStepOveForOfClosure(dbg);
     16  await testStepOverForOfArrayClosure(dbg);
     17  await testStepOverFunctionParams(dbg);
     18  await testStepOverRegeneratorAwait(dbg);
     19 });
     20 
     21 async function breakpointSteps(dbg, target, fixture, { line, column }, steps) {
     22  const filename = `${target}://./${fixture}/input.`;
     23  const fnName = `${target}-${fixture}`.replace(/-([a-z])/g, (s, c) =>
     24    c.toUpperCase()
     25  );
     26 
     27  await invokeWithBreakpoint(
     28    dbg,
     29    fnName,
     30    filename,
     31    { line, column },
     32    async source => {
     33      await runSteps(dbg, source, steps);
     34    }
     35  );
     36 
     37  ok(true, `Ran tests for ${fixture} at line ${line} column ${column}`);
     38 }
     39 
     40 async function runSteps(dbg, source, steps) {
     41  for (const [i, [type, position]] of steps.entries()) {
     42    info(`Step ${i}`);
     43    switch (type) {
     44      case "stepOver":
     45        await stepOver(dbg);
     46        break;
     47      case "stepIn":
     48        await stepIn(dbg);
     49        break;
     50      default:
     51        throw new Error("Unknown stepping type");
     52    }
     53 
     54    await assertPausedAtSourceAndLine(
     55      dbg,
     56      source.id,
     57      position.line,
     58      position.column
     59    );
     60  }
     61 }
     62 
     63 function testStepOverForOf(dbg) {
     64  return breakpointSteps(
     65    dbg,
     66    "webpack3-babel6",
     67    "step-over-for-of",
     68    { line: 4, column: 2 },
     69    [
     70      ["stepOver", { line: 6, column: 20 }],
     71      ["stepOver", { line: 6, column: 2 }],
     72      ["stepOver", { line: 7, column: 4 }],
     73      ["stepOver", { line: 6, column: 2 }],
     74      ["stepOver", { line: 7, column: 4 }],
     75      ["stepOver", { line: 6, column: 2 }],
     76      ["stepOver", { line: 10, column: 2 }],
     77    ]
     78  );
     79 }
     80 
     81 // This codifies the current behavior, but stepping twice over the for
     82 // header isn't ideal.
     83 function testStepOverForOfArray(dbg) {
     84  return breakpointSteps(
     85    dbg,
     86    "webpack3-babel6",
     87    "step-over-for-of-array",
     88    { line: 3, column: 2 },
     89    [
     90      ["stepOver", { line: 5, column: 2 }],
     91      ["stepOver", { line: 5, column: 13 }],
     92      ["stepOver", { line: 6, column: 4 }],
     93      ["stepOver", { line: 5, column: 2 }],
     94      ["stepOver", { line: 5, column: 13 }],
     95      ["stepOver", { line: 6, column: 4 }],
     96      ["stepOver", { line: 5, column: 2 }],
     97      ["stepOver", { line: 9, column: 2 }],
     98    ]
     99  );
    100 }
    101 
    102 // The closure means it isn't actually possible to step into the for body,
    103 // and Babel doesn't map the _loop() call, so we step past it automatically.
    104 function testStepOveForOfClosure(dbg) {
    105  return breakpointSteps(
    106    dbg,
    107    "webpack3-babel6",
    108    "step-over-for-of-closure",
    109    { line: 6, column: 2 },
    110    [
    111      ["stepOver", { line: 8, column: 20 }],
    112      ["stepOver", { line: 8, column: 2 }],
    113      ["stepOver", { line: 12, column: 2 }],
    114    ]
    115  );
    116 }
    117 
    118 // Same as the previous, not possible to step into the body. The less
    119 // complicated array logic makes it possible to step into the header at least,
    120 // but this does end up double-visiting the for head.
    121 function testStepOverForOfArrayClosure(dbg) {
    122  return breakpointSteps(
    123    dbg,
    124    "webpack3-babel6",
    125    "step-over-for-of-array-closure",
    126    { line: 3, column: 2 },
    127    [
    128      ["stepOver", { line: 5, column: 2 }],
    129      ["stepOver", { line: 5, column: 13 }],
    130      ["stepOver", { line: 5, column: 2 }],
    131      ["stepOver", { line: 5, column: 13 }],
    132      ["stepOver", { line: 5, column: 2 }],
    133      ["stepOver", { line: 9, column: 2 }],
    134    ]
    135  );
    136 }
    137 
    138 function testStepOverFunctionParams(dbg) {
    139  return breakpointSteps(
    140    dbg,
    141    "webpack3-babel6",
    142    "step-over-function-params",
    143    { line: 6, column: 2 },
    144    [
    145      ["stepOver", { line: 7, column: 2 }],
    146      ["stepIn", { line: 2, column: 2 }],
    147    ]
    148  );
    149 }
    150 
    151 function testStepOverRegeneratorAwait(dbg) {
    152  return breakpointSteps(
    153    dbg,
    154    "webpack3-babel6",
    155    "step-over-regenerator-await",
    156    { line: 2, column: 2 },
    157    [
    158      // Won't work until a fix to regenerator lands and we rebuild.
    159      // https://github.com/facebook/regenerator/issues/342
    160      // ["stepOver", { line: 4, column: 2 }],
    161    ]
    162  );
    163 }