tor-browser

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

index.js (1490B)


      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 import { truncateString } from "devtools/shared/string";
      6 import { WorkerDispatcher } from "devtools/client/shared/worker-utils";
      7 
      8 const MAX_SCRIPT_LOG_LENGTH = 500;
      9 const WORKER_URL =
     10  "resource://devtools/client/debugger/dist/pretty-print-worker.js";
     11 
     12 export class PrettyPrintDispatcher extends WorkerDispatcher {
     13  constructor(jestUrl) {
     14    super(jestUrl || WORKER_URL);
     15  }
     16 
     17  #prettyPrintTask = this.task("prettyPrint");
     18  #prettyPrintInlineScriptTask = this.task("prettyPrintInlineScript");
     19  #getSourceMapForTask = this.task("getSourceMapForTask");
     20 
     21  async prettyPrint(options) {
     22    try {
     23      return await this.#prettyPrintTask(options);
     24    } catch (e) {
     25      console.error(
     26        `[pretty-print] Failed to pretty print script (${options.url}):\n`,
     27        truncateString(options.sourceText, MAX_SCRIPT_LOG_LENGTH)
     28      );
     29      throw e;
     30    }
     31  }
     32 
     33  async prettyPrintInlineScript(options) {
     34    try {
     35      return await this.#prettyPrintInlineScriptTask(options);
     36    } catch (e) {
     37      console.error(
     38        `[pretty-print] Failed to pretty print inline script (${options.url}):\n`,
     39        truncateString(options.sourceText, MAX_SCRIPT_LOG_LENGTH)
     40      );
     41      throw e;
     42    }
     43  }
     44 
     45  getSourceMap(taskId) {
     46    return this.#getSourceMapForTask(taskId);
     47  }
     48 }