tor-browser

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

wasm-source-map.js (2610B)


      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 /**
      8 * SourceMapConsumer for WebAssembly source maps. It transposes columns with
      9 * lines, which allows mapping data to be used with SpiderMonkey Debugger API.
     10 */
     11 class WasmRemap {
     12  /**
     13   * @param map SourceMapConsumer
     14   */
     15  constructor(map) {
     16    this._map = map;
     17    this.version = map.version;
     18    this.file = map.file;
     19    this._computeColumnSpans = false;
     20  }
     21 
     22  get sources() {
     23    return this._map.sources;
     24  }
     25 
     26  get sourceRoot() {
     27    return this._map.sourceRoot;
     28  }
     29 
     30  /**
     31   * @param url string
     32   */
     33  set sourceRoot(url) {
     34    // important, since sources are using this.
     35    this._map.sourceRoot = url;
     36  }
     37 
     38  get names() {
     39    return this._map.names;
     40  }
     41 
     42  get sourcesContent() {
     43    return this._map.sourcesContent;
     44  }
     45 
     46  get mappings() {
     47    throw new Error("not supported");
     48  }
     49 
     50  computeColumnSpans() {
     51    this._computeColumnSpans = true;
     52  }
     53 
     54  originalPositionFor(generatedPosition) {
     55    const result = this._map.originalPositionFor({
     56      line: 1,
     57      column: generatedPosition.line,
     58      bias: generatedPosition.bias,
     59    });
     60    return result;
     61  }
     62 
     63  _remapGeneratedPosition(position) {
     64    const generatedPosition = {
     65      line: position.column,
     66      column: 0,
     67    };
     68    if (this._computeColumnSpans) {
     69      generatedPosition.lastColumn = Infinity;
     70    }
     71    return generatedPosition;
     72  }
     73 
     74  generatedPositionFor(originalPosition) {
     75    const position = this._map.generatedPositionFor(originalPosition);
     76    return this._remapGeneratedPosition(position);
     77  }
     78 
     79  allGeneratedPositionsFor(originalPosition) {
     80    const positions = this._map.allGeneratedPositionsFor(originalPosition);
     81    return positions.map(position => {
     82      return this._remapGeneratedPosition(position);
     83    });
     84  }
     85 
     86  hasContentsOfAllSources() {
     87    return this._map.hasContentsOfAllSources();
     88  }
     89 
     90  sourceContentFor(source, returnNullOnMissing) {
     91    return this._map.sourceContentFor(source, returnNullOnMissing);
     92  }
     93 
     94  eachMapping(callback, context, order) {
     95    this._map.eachMapping(
     96      entry => {
     97        const { source, generatedColumn, originalLine, originalColumn, name } =
     98          entry;
     99        callback({
    100          source,
    101          generatedLine: generatedColumn,
    102          generatedColumn: 0,
    103          originalLine,
    104          originalColumn,
    105          name,
    106        });
    107      },
    108      context,
    109      order
    110    );
    111  }
    112 }
    113 
    114 exports.WasmRemap = WasmRemap;