tor-browser

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

wasmRemap.js (2495B)


      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  get names() {
     31    return this._map.names;
     32  }
     33 
     34  get sourcesContent() {
     35    return this._map.sourcesContent;
     36  }
     37 
     38  get mappings() {
     39    throw new Error("not supported");
     40  }
     41 
     42  computeColumnSpans() {
     43    this._computeColumnSpans = true;
     44  }
     45 
     46  originalPositionFor(generatedPosition) {
     47    const result = this._map.originalPositionFor({
     48      line: 1,
     49      column: generatedPosition.line,
     50      bias: generatedPosition.bias,
     51    });
     52    return result;
     53  }
     54 
     55  _remapGeneratedPosition(position) {
     56    const generatedPosition = {
     57      line: position.column,
     58      column: 0,
     59    };
     60    if (this._computeColumnSpans) {
     61      generatedPosition.lastColumn = 0;
     62    }
     63    return generatedPosition;
     64  }
     65 
     66  generatedPositionFor(originalPosition) {
     67    const position = this._map.generatedPositionFor(originalPosition);
     68    return this._remapGeneratedPosition(position);
     69  }
     70 
     71  allGeneratedPositionsFor(originalPosition) {
     72    const positions = this._map.allGeneratedPositionsFor(originalPosition);
     73    return positions.map(position => {
     74      return this._remapGeneratedPosition(position);
     75    });
     76  }
     77 
     78  hasContentsOfAllSources() {
     79    return this._map.hasContentsOfAllSources();
     80  }
     81 
     82  sourceContentFor(source, returnNullOnMissing) {
     83    return this._map.sourceContentFor(source, returnNullOnMissing);
     84  }
     85 
     86  eachMapping(callback, context, order) {
     87    this._map.eachMapping(
     88      entry => {
     89        const { source, generatedColumn, originalLine, originalColumn, name } =
     90          entry;
     91        callback({
     92          source,
     93          generatedLine: generatedColumn,
     94          generatedColumn: 0,
     95          lastGeneratedColumn: 0,
     96          originalLine,
     97          originalColumn,
     98          name,
     99        });
    100      },
    101      context,
    102      order
    103    );
    104  }
    105 }
    106 
    107 exports.WasmRemap = WasmRemap;