From fe6ee945d4e5bf42673cf7d50f16a4a5e8b6a93b Mon Sep 17 00:00:00 2001 From: Logan Smyth Date: Thu, 27 Sep 2018 11:07:41 -0700 Subject: [PATCH] Upgrade the source-map module for WASM performance. --- .travis.yml | 2 +- packages/devtools-source-map/assets.js | 3 +- packages/devtools-source-map/package.json | 2 +- .../devtools-source-map/src/source-map.js | 29 +++++++++++++++---- .../src/utils/wasmAssetBrowser.js | 6 ++++ yarn.lock | 4 +++ 6 files changed, 38 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2c43c321b3..7491c8e953 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,7 +13,7 @@ env: global: - DISPLAY=':99.0' - YARN_VERSION='1.9.4' - - MC_COMMIT='156f9442db84' # https://hg.mozilla.org/mozilla-central/shortlog + - MC_COMMIT='13b0256be449' # https://hg.mozilla.org/mozilla-central/shortlog notifications: slack: diff --git a/packages/devtools-source-map/assets.js b/packages/devtools-source-map/assets.js index 7454b042b0..a911626402 100644 --- a/packages/devtools-source-map/assets.js +++ b/packages/devtools-source-map/assets.js @@ -4,5 +4,6 @@ // @flow module.exports = { - "dwarf_to_json.wasm": require.resolve("./wasm/dwarf_to_json.wasm") + "dwarf_to_json.wasm": require.resolve("./wasm/dwarf_to_json.wasm"), + "source-map-mappings.wasm": require.resolve("source-map/lib/mappings.wasm") }; diff --git a/packages/devtools-source-map/package.json b/packages/devtools-source-map/package.json index 19c4f1b567..bd1a55df13 100644 --- a/packages/devtools-source-map/package.json +++ b/packages/devtools-source-map/package.json @@ -22,6 +22,6 @@ "devtools-utils": "0.0.14", "md5": "^2.2.1", "regenerator-runtime": "^0.10.3", - "source-map": "^0.6.1" + "source-map": "^0.7.3" } } diff --git a/packages/devtools-source-map/src/source-map.js b/packages/devtools-source-map/src/source-map.js index 27dfcd92f4..ea33d388dd 100644 --- a/packages/devtools-source-map/src/source-map.js +++ b/packages/devtools-source-map/src/source-map.js @@ -171,17 +171,36 @@ async function getGeneratedLocation( return location; } - const { line, column } = map.generatedPositionFor({ + const positions = map.allGeneratedPositionsFor({ source: originalSource.url, line: location.line, - column: location.column == null ? 0 : location.column, - bias: SourceMapConsumer.LEAST_UPPER_BOUND + column: location.column == null ? 0 : location.column }); + // Prior to source-map 0.7, the source-map module returned the earliest + // generated location in the file when there were multiple generated + // locations. The current comparison fn in 0.7 does not appear to take + // generated location into account properly. + let match; + for (const pos of positions) { + if (!match || pos.line < match.line || pos.column < match.column) { + match = pos; + } + } + + if (!match) { + match = map.generatedPositionFor({ + source: originalSource.url, + line: location.line, + column: location.column == null ? 0 : location.column, + bias: SourceMapConsumer.LEAST_UPPER_BOUND + }); + } + return { sourceId: generatedSourceId, - line, - column + line: match.line, + column: match.column }; } diff --git a/packages/devtools-source-map/src/utils/wasmAssetBrowser.js b/packages/devtools-source-map/src/utils/wasmAssetBrowser.js index 21331f3dba..e123c278bd 100644 --- a/packages/devtools-source-map/src/utils/wasmAssetBrowser.js +++ b/packages/devtools-source-map/src/utils/wasmAssetBrowser.js @@ -3,10 +3,16 @@ * file, You can obtain one at . */ // @flow +const { SourceMapConsumer } = require("source-map"); + let root; function setAssetRootURL(assetRoot: string): void { // Remove any trailing slash so we don't generate a double-slash below. root = assetRoot.replace(/\/$/, ""); + + SourceMapConsumer.initialize({ + "lib/mappings.wasm": `${root}/source-map-mappings.wasm` + }); } async function getDwarfToWasmData(name: string): Promise { diff --git a/yarn.lock b/yarn.lock index 97038e477a..4de0e8993d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -11025,6 +11025,10 @@ source-map@^0.6.0, source-map@^0.6.1, source-map@~0.6.1: version "0.6.1" resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263" +source-map@^0.7.3: + version "0.7.3" + resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.7.3.tgz#5302f8169031735226544092e64981f751750383" + space-separated-tokens@^1.0.0: version "1.1.2" resolved "https://registry.yarnpkg.com/space-separated-tokens/-/space-separated-tokens-1.1.2.tgz#e95ab9d19ae841e200808cd96bc7bd0adbbb3412"