Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

Commit

Permalink
Upgrade the source-map module for WASM performance.
Browse files Browse the repository at this point in the history
  • Loading branch information
loganfsmyth committed Oct 3, 2018
1 parent 0a3b6d4 commit fe6ee94
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion packages/devtools-source-map/assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")
};
2 changes: 1 addition & 1 deletion packages/devtools-source-map/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
29 changes: 24 additions & 5 deletions packages/devtools-source-map/src/source-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
}

Expand Down
6 changes: 6 additions & 0 deletions packages/devtools-source-map/src/utils/wasmAssetBrowser.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@
* file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
// @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<ArrayBuffer> {
Expand Down
4 changes: 4 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit fe6ee94

Please sign in to comment.