tor-browser

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

browser_dbg-features-asm.js (3639B)


      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 /**
      6 * This test covers all specifics of debugging ASM.js files.
      7 *
      8 * ASM.js is a subset of the Javascript syntax.
      9 * Thanks to these limitations, the JS engine is able to compile this code
     10 * into machine instructions and execute it faster.
     11 *
     12 * When the DevTools are opened, ThreadConfiguration's `observeAsmJS` is set to true,
     13 * which sets DebuggerAPI's `allowUnobservedAsmJS` to false,
     14 * which disables the compilation of ASM.js files and make them run as regular JS code.
     15 * Thus, allowing to debug them as regular JS code.
     16 *
     17 * This behavior introduces some limitations when opening the debugger against
     18 * and already loaded page. The ASM.js file won't be debuggable.
     19 */
     20 
     21 "use strict";
     22 
     23 add_task(async function () {
     24  // Load the test page before opening the debugger
     25  // and also force a GC before opening the debugger
     26  // so that ASM.js is fully garbaged collected.
     27  // Otherwise on debug builds, the thread actor is able to intermittently
     28  // retrieve the ASM.js sources and retrieve the breakable lines.
     29  const tab = await addTab(EXAMPLE_URL + "doc-asm.html");
     30  await SpecialPowers.spawn(tab.linkedBrowser, [], function () {
     31    Cu.forceGC();
     32  });
     33  const toolbox = await openToolboxForTab(tab, "jsdebugger");
     34  const dbg = createDebuggerContext(toolbox);
     35 
     36  // There is the legit and the spurious wasm source (see following comment)
     37  await waitForSourcesInSourceTree(dbg, ["doc-asm.html", "asm.js", "asm.js"]);
     38  is(dbg.selectors.getSourceCount(), 3, "There are only three sources");
     39 
     40  const legitSource = findSource(dbg, EXAMPLE_URL + "asm.js");
     41  ok(
     42    legitSource.url.startsWith("https://"),
     43    "We got the legit source that works, not the spurious WASM one"
     44  );
     45  is(legitSource.isWasm, false, "ASM.js sources are *not* flagged as WASM");
     46 
     47  // XXX Bug 1759573 - There is a spurious wasm source reported which is broken
     48  // and ideally shouldn't exists at all in UI.
     49  // The Thread Actor is notified by the Debugger API about a WASM
     50  // source when calling Debugger.findSources in ThreadActor.addAllSources.
     51  const wasmUrl = "wasm:" + legitSource.url;
     52  ok(
     53    sourceExists(dbg, wasmUrl),
     54    `There is a spurious wasm:// source displayed: ${wasmUrl}`
     55  );
     56 
     57  await selectSource(dbg, legitSource);
     58 
     59  assertTextContentOnLine(dbg, 7, "return 1 | 0;");
     60 
     61  info(
     62    "Before reloading, ThreadConfiguration's 'observedAsmJS' was false while the page was loading"
     63  );
     64  info(
     65    "So that we miss info about the ASM sources and lines are not breakables"
     66  );
     67  await assertLineIsBreakable(dbg, legitSource.url, 7, false);
     68 
     69  info("Reload and assert that ASM.js file are then debuggable");
     70  await reload(dbg, "doc-asm.html", "asm.js");
     71 
     72  info("After reloading, ASM lines are breakable");
     73  // Ensure selecting the source before asserting breakable lines
     74  // otherwise the gutter may not be yet updated
     75  await selectSource(dbg, "asm.js");
     76  await assertLineIsBreakable(dbg, legitSource.url, 7, true);
     77 
     78  await waitForSourcesInSourceTree(dbg, ["doc-asm.html", "asm.js"]);
     79  is(dbg.selectors.getSourceCount(), 2, "There is only the two sources");
     80 
     81  assertTextContentOnLine(dbg, 7, "return 1 | 0;");
     82 
     83  await addBreakpoint(dbg, "asm.js", 7);
     84  invokeInTab("runAsm");
     85 
     86  await waitForPaused(dbg);
     87  await assertPausedAtSourceAndLine(dbg, findSource(dbg, "asm.js").id, 7);
     88  await assertBreakpoint(dbg, 7);
     89 
     90  await removeBreakpoint(dbg, findSource(dbg, "asm.js").id, 7);
     91  await resume(dbg);
     92 });