From dc3d6256aa29b787f23811b129ca54beba4dbc24 Mon Sep 17 00:00:00 2001 From: Logan Smyth Date: Wed, 3 Oct 2018 12:28:59 -0700 Subject: [PATCH 1/5] Update yarn.lock for recent package.json changes. --- yarn.lock | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/yarn.lock b/yarn.lock index 49146bad3f..e6b1558d85 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4111,12 +4111,11 @@ eslint-plugin-mozilla@^0.16.1: ini-parser "0.0.2" sax "1.2.4" -eslint-plugin-prettier@^2.3.1: - version "2.6.2" - resolved "https://registry.yarnpkg.com/eslint-plugin-prettier/-/eslint-plugin-prettier-2.6.2.tgz#71998c60aedfa2141f7bfcbf9d1c459bf98b4fad" +eslint-plugin-prettier@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/eslint-plugin-prettier/-/eslint-plugin-prettier-3.0.0.tgz#f6b823e065f8c36529918cdb766d7a0e975ec30c" dependencies: - fast-diff "^1.1.1" - jest-docblock "^21.0.0" + prettier-linter-helpers "^1.0.0" eslint-plugin-react@^7.2.1: version "7.10.0" @@ -4538,7 +4537,7 @@ fast-deep-equal@^2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-2.0.1.tgz#7b05218ddf9667bf7f370bf7fdb2cb15fdd0aa49" -fast-diff@^1.1.1: +fast-diff@^1.1.2: version "1.1.2" resolved "https://registry.yarnpkg.com/fast-diff/-/fast-diff-1.1.2.tgz#4b62c42b8e03de3f848460b639079920695d0154" @@ -6421,10 +6420,6 @@ jest-diff@^23.2.0: jest-get-type "^22.1.0" pretty-format "^23.2.0" -jest-docblock@^21.0.0: - version "21.2.0" - resolved "https://registry.yarnpkg.com/jest-docblock/-/jest-docblock-21.2.0.tgz#51529c3b30d5fd159da60c27ceedc195faf8d414" - jest-docblock@^23.2.0: version "23.2.0" resolved "https://registry.yarnpkg.com/jest-docblock/-/jest-docblock-23.2.0.tgz#f085e1f18548d99fdd69b20207e6fd55d91383a7" @@ -9089,6 +9084,12 @@ preserve@^0.2.0: version "0.2.0" resolved "https://registry.yarnpkg.com/preserve/-/preserve-0.2.0.tgz#815ed1f6ebc65926f865b310c0713bcb3315ce4b" +prettier-linter-helpers@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/prettier-linter-helpers/-/prettier-linter-helpers-1.0.0.tgz#d23d41fe1375646de2d0104d3454a3008802cf7b" + dependencies: + fast-diff "^1.1.2" + prettier@^1.12.1: version "1.14.0" resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.14.0.tgz#847c235522035fd988100f1f43cf20a7d24f9372" From b092d3cb12feb124f5555388305831af7a30d737 Mon Sep 17 00:00:00 2001 From: Logan Smyth Date: Thu, 27 Sep 2018 11:16:30 -0700 Subject: [PATCH 2/5] Remove unused wrapper function in Webpack config generation. --- webpack.config.js | 72 +++++++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 37 deletions(-) diff --git a/webpack.config.js b/webpack.config.js index b185afbcfe..23ab8db10f 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -2,7 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at . */ -const toolbox = require("./node_modules/devtools-launchpad/index"); +const toolbox = require("devtools-launchpad/index"); const getConfig = require("./bin/getConfig"); const mozillaCentralMappings = require("./configs/mozilla-central-mappings"); @@ -38,7 +38,9 @@ const webpackConfig = { path: path.join(__dirname, "assets/build"), filename: "[name].js", publicPath: "/assets/build" - } + }, + + plugins: [] }; if (isProduction) { @@ -49,43 +51,39 @@ if (isProduction) { webpackConfig.entry.reps = getEntry("packages/devtools-reps/src/index.js"); } -function buildConfig(envConfig) { - const extra = { - babelIncludes: ["react-aria-components"] - }; - - webpackConfig.plugins = [new ObjectRestSpreadPlugin()]; - - if (!isProduction) { - webpackConfig.module = webpackConfig.module || {}; - webpackConfig.module.rules = webpackConfig.module.rules || []; - } else { - webpackConfig.output.libraryTarget = "umd"; - - if (process.env.vis) { - const viz = new Visualizer({ - filename: "webpack-stats.html" - }); - webpackConfig.plugins.push(viz); - } - - const mappings = [ - [/\.\/mocha/, "./mochitest"], - [/\.\.\/utils\/mocha/, "../utils/mochitest"], - [/\.\/utils\/mocha/, "./utils/mochitest"], - [/\.\/percy-stub/, "./percy-webpack"] - ]; - - extra.excludeMap = mozillaCentralMappings; - - mappings.forEach(([regex, res]) => { - webpackConfig.plugins.push(new NormalModuleReplacementPlugin(regex, res)); +const envConfig = getConfig(); + +const extra = { + babelIncludes: ["react-aria-components"] +}; + +webpackConfig.plugins.push(new ObjectRestSpreadPlugin()); + +if (!isProduction) { + webpackConfig.module = webpackConfig.module || {}; + webpackConfig.module.rules = webpackConfig.module.rules || []; +} else { + webpackConfig.output.libraryTarget = "umd"; + + if (process.env.vis) { + const viz = new Visualizer({ + filename: "webpack-stats.html" }); + webpackConfig.plugins.push(viz); } - return toolbox.toolboxConfig(webpackConfig, envConfig, extra); -} + const mappings = [ + [/\.\/mocha/, "./mochitest"], + [/\.\.\/utils\/mocha/, "../utils/mochitest"], + [/\.\/utils\/mocha/, "./utils/mochitest"], + [/\.\/percy-stub/, "./percy-webpack"] + ]; -const envConfig = getConfig(); + extra.excludeMap = mozillaCentralMappings; + + mappings.forEach(([regex, res]) => { + webpackConfig.plugins.push(new NormalModuleReplacementPlugin(regex, res)); + }); +} -module.exports = buildConfig(envConfig); +module.exports = toolbox.toolboxConfig(webpackConfig, envConfig, extra); From f9bb2bdc19c1eb20ea7c6c33d05b8ab4f9e79649 Mon Sep 17 00:00:00 2001 From: Logan Smyth Date: Mon, 24 Sep 2018 16:19:08 -0700 Subject: [PATCH 3/5] Add a general concept of assets to the source-map worker. --- bin/copy-assets.js | 15 +++++---- bin/dev-server.js | 1 - package.json | 1 + packages/devtools-source-map/README.md | 4 ++- packages/devtools-source-map/assets.js | 8 +++++ packages/devtools-source-map/package.json | 3 ++ packages/devtools-source-map/src/index.js | 6 +++- .../src/utils/convertToJSON.js | 24 ++++++++------ .../src/utils/wasmAsset.js | 30 ++++++++++++++++++ .../src/utils/wasmAssetBrowser.js | 25 +++++++++++++++ packages/devtools-source-map/src/worker.js | 5 +-- .../wasm/dwarf_to_json.wasm | Bin src/utils/bootstrap.js | 6 +++- webpack.config.js | 11 ++++++- yarn.lock | 26 ++++++++++++++- 15 files changed, 140 insertions(+), 25 deletions(-) create mode 100644 packages/devtools-source-map/assets.js create mode 100644 packages/devtools-source-map/src/utils/wasmAsset.js create mode 100644 packages/devtools-source-map/src/utils/wasmAssetBrowser.js rename {assets => packages/devtools-source-map}/wasm/dwarf_to_json.wasm (100%) diff --git a/bin/copy-assets.js b/bin/copy-assets.js index ca381e28e3..f3c5529fc1 100644 --- a/bin/copy-assets.js +++ b/bin/copy-assets.js @@ -1,6 +1,7 @@ const { tools: { makeBundle, symlinkTests, copyFile } } = require("devtools-launchpad/index"); +const sourceMapAssets = require("devtools-source-map/assets"); const path = require("path"); const minimist = require("minimist"); var fs = require("fs"); @@ -210,13 +211,6 @@ function start() { { cwd: projectPath } ); - console.log("[copy-assets] - dwarf_to_json.wasm"); - copyFile( - path.join(projectPath, "./assets/wasm/dwarf_to_json.wasm"), - path.join(mcPath, "devtools/client/shared/source-map/dwarf_to_json.wasm"), - { cwd: projectPath } - ); - // Ensure /dist path exists. const bundlePath = "devtools/client/debugger/new/dist"; shell.mkdir("-p", path.join(mcPath, bundlePath)); @@ -274,6 +268,13 @@ function onBundleFinish({mcPath, bundlePath, projectPath}) { path.join(mcPath, "devtools/client/shared/source-map/worker.js"), {cwd: projectPath} ); + for (const filename of Object.keys(sourceMapAssets)) { + moveFile( + path.join(mcPath, bundlePath, "source-map-worker-assets", filename), + path.join(mcPath, "devtools/client/shared/source-map/assets", filename), + {cwd: projectPath} + ); + } moveFile( path.join(mcPath, bundlePath, "source-map-index.js"), diff --git a/bin/dev-server.js b/bin/dev-server.js index d9d5958d57..81e4eb8a6a 100644 --- a/bin/dev-server.js +++ b/bin/dev-server.js @@ -16,7 +16,6 @@ let { app } = toolbox.startDevServer(envConfig, webpackConfig, __dirname); app.use("/integration/examples", express.static("src/test/mochitest/examples")); app.use("/images", serve(path.join(__dirname, "../assets/images"))); -app.use("/wasm", serve(path.join(__dirname, "../assets/wasm"))); // Serve devtools-reps images app.use("/devtools-reps/images/", serve(path.join(__dirname, "../src/shared/images"))); diff --git a/package.json b/package.json index 3569bd0ce2..049030f8d0 100644 --- a/package.json +++ b/package.json @@ -114,6 +114,7 @@ "babel-preset-react": "^6.24.1", "chalk": "^2.1.0", "copy-paste": "^1.3.0", + "copy-webpack-plugin": "^4.5.2", "devtools-license-check": "^0.7.0", "documentation": "^5.2.1", "enzyme": "^3.3.0", diff --git a/packages/devtools-source-map/README.md b/packages/devtools-source-map/README.md index 6389e77959..f8ab86f86c 100644 --- a/packages/devtools-source-map/README.md +++ b/packages/devtools-source-map/README.md @@ -12,4 +12,6 @@ This is used in multiple contexts: # Application Requirements This package assumes that an application using this code will make the -`worker.js` file available at application specified URL `workers.sourceMapURL`. +`worker.js`, and `dwarf_to_json.wasm` files available and call +`startSourceMapWorker(workerURL, wasmRoot)` to initialize the worker and specify +the location of the wasm asset. diff --git a/packages/devtools-source-map/assets.js b/packages/devtools-source-map/assets.js new file mode 100644 index 0000000000..7454b042b0 --- /dev/null +++ b/packages/devtools-source-map/assets.js @@ -0,0 +1,8 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at . */ +// @flow + +module.exports = { + "dwarf_to_json.wasm": require.resolve("./wasm/dwarf_to_json.wasm") +}; diff --git a/packages/devtools-source-map/package.json b/packages/devtools-source-map/package.json index 7d305339a8..19c4f1b567 100644 --- a/packages/devtools-source-map/package.json +++ b/packages/devtools-source-map/package.json @@ -9,6 +9,9 @@ "homepage": "https://github.com/devtools-html/debugger.html/tree/master/packages/source-maps#readme", "main": "src/index.js", + "browser": { + "./src/utils/wasmAsset.js": "./src/utils/wasmAssetBrowser.js" + }, "scripts": { "license-check": "devtools-license-check", "test": "jest --projects jest.config.js" diff --git a/packages/devtools-source-map/src/index.js b/packages/devtools-source-map/src/index.js index dec42e8197..3ebac53152 100644 --- a/packages/devtools-source-map/src/index.js +++ b/packages/devtools-source-map/src/index.js @@ -17,6 +17,7 @@ const { const dispatcher = new WorkerDispatcher(); +const setAssetRootURL = dispatcher.task("setAssetRootURL"); const getOriginalURLs = dispatcher.task("getOriginalURLs"); const getOriginalRanges = dispatcher.task("getOriginalRanges"); const getGeneratedRanges = dispatcher.task("getGeneratedRanges", { @@ -53,6 +54,9 @@ module.exports = { applySourceMap, clearSourceMaps, getOriginalStackFrames, - startSourceMapWorker: dispatcher.start.bind(dispatcher), + startSourceMapWorker(url: string, assetRoot: string) { + dispatcher.start(url); + setAssetRootURL(assetRoot); + }, stopSourceMapWorker: dispatcher.stop.bind(dispatcher) }; diff --git a/packages/devtools-source-map/src/utils/convertToJSON.js b/packages/devtools-source-map/src/utils/convertToJSON.js index 90528b9df8..d4aff5b419 100644 --- a/packages/devtools-source-map/src/utils/convertToJSON.js +++ b/packages/devtools-source-map/src/utils/convertToJSON.js @@ -4,6 +4,8 @@ /* eslint camelcase: 0*/ +const { getDwarfToWasmData } = require("./wasmAsset.js"); + let cachedWasmModule; let utf8Decoder; @@ -38,16 +40,18 @@ function convertDwarf(wasm, instance) { } async function convertToJSON(buffer: ArrayBuffer): any { - if (!cachedWasmModule) { - const isFirefoxPanel = - typeof location !== "undefined" && location.protocol === "resource:"; - const wasmPath = `${isFirefoxPanel ? "." : "/wasm"}/dwarf_to_json.wasm`; - const wasm = await (await fetch(wasmPath)).arrayBuffer(); - const imports = {}; - const { instance } = await WebAssembly.instantiate(wasm, imports); - cachedWasmModule = instance; - } - return convertDwarf(buffer, cachedWasmModule); + // Note: We don't 'await' here because it could mean that multiple + // calls to 'convertToJSON' could cause multiple fetches to be started. + cachedWasmModule = cachedWasmModule || loadConverterModule(); + + return convertDwarf(buffer, await cachedWasmModule); +} + +async function loadConverterModule() { + const wasm = await getDwarfToWasmData(); + const imports = {}; + const { instance } = await WebAssembly.instantiate(wasm, imports); + return instance; } module.exports = { diff --git a/packages/devtools-source-map/src/utils/wasmAsset.js b/packages/devtools-source-map/src/utils/wasmAsset.js new file mode 100644 index 0000000000..13c0fc4fa4 --- /dev/null +++ b/packages/devtools-source-map/src/utils/wasmAsset.js @@ -0,0 +1,30 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at . */ +// @flow + +const fs = require("fs"); + +const assets = require("../../assets"); + +function setAssetRootURL(assetRoot: string): void { + // No-op on Node +} + +async function getDwarfToWasmData(): Promise { + const data = await new Promise((res, rej) => { + fs.readFile(assets["dwarf_to_json.wasm"], (err, result) => { + if (err) { + return rej(err); + } + res(result); + }); + }); + + return data.buffer; +} + +module.exports = { + setAssetRootURL, + getDwarfToWasmData +}; diff --git a/packages/devtools-source-map/src/utils/wasmAssetBrowser.js b/packages/devtools-source-map/src/utils/wasmAssetBrowser.js new file mode 100644 index 0000000000..21331f3dba --- /dev/null +++ b/packages/devtools-source-map/src/utils/wasmAssetBrowser.js @@ -0,0 +1,25 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at . */ +// @flow + +let root; +function setAssetRootURL(assetRoot: string): void { + // Remove any trailing slash so we don't generate a double-slash below. + root = assetRoot.replace(/\/$/, ""); +} + +async function getDwarfToWasmData(name: string): Promise { + if (!root) { + throw new Error(`No wasm path - Unable to resolve ${name}`); + } + + const response = await fetch(`${root}/dwarf_to_json.wasm`); + + return response.arrayBuffer(); +} + +module.exports = { + setAssetRootURL, + getDwarfToWasmData +}; diff --git a/packages/devtools-source-map/src/worker.js b/packages/devtools-source-map/src/worker.js index 48f58ac57f..678d7730cf 100644 --- a/packages/devtools-source-map/src/worker.js +++ b/packages/devtools-source-map/src/worker.js @@ -1,6 +1,7 @@ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at . */ +// @flow const { getOriginalURLs, @@ -10,13 +11,13 @@ const { getAllGeneratedLocations, getOriginalLocation, getOriginalSourceText, - getLocationScopes, hasMappedSource, clearSourceMaps, applySourceMap } = require("./source-map"); const { getOriginalStackFrames } = require("./utils/getOriginalStackFrames"); +const { setAssetRootURL } = require("./utils/wasmAsset"); const { workerUtils: { workerHandler } @@ -25,13 +26,13 @@ const { // The interface is implemented in source-map to be // easier to unit test. self.onmessage = workerHandler({ + setAssetRootURL, getOriginalURLs, getOriginalRanges, getGeneratedRanges, getGeneratedLocation, getAllGeneratedLocations, getOriginalLocation, - getLocationScopes, getOriginalSourceText, getOriginalStackFrames, hasMappedSource, diff --git a/assets/wasm/dwarf_to_json.wasm b/packages/devtools-source-map/wasm/dwarf_to_json.wasm similarity index 100% rename from assets/wasm/dwarf_to_json.wasm rename to packages/devtools-source-map/wasm/dwarf_to_json.wasm diff --git a/src/utils/bootstrap.js b/src/utils/bootstrap.js index 3861e821a5..57ef632984 100644 --- a/src/utils/bootstrap.js +++ b/src/utils/bootstrap.js @@ -68,7 +68,11 @@ export function bootstrapWorkers() { if (isDevelopment()) { // When used in Firefox, the toolbox manages the source map worker. - startSourceMapWorker(`${workerPath}/source-map-worker.js`); + startSourceMapWorker( + `${workerPath}/source-map-worker.js`, + // This is relative to the worker itself. + "./source-map-worker-assets/" + ); } prettyPrint.start(`${workerPath}/pretty-print-worker.js`); diff --git a/webpack.config.js b/webpack.config.js index 23ab8db10f..c370f16084 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -3,6 +3,8 @@ * file, You can obtain one at . */ const toolbox = require("devtools-launchpad/index"); +const sourceMapAssets = require("devtools-source-map/assets"); +const CopyWebpackPlugin = require("copy-webpack-plugin"); const getConfig = require("./bin/getConfig"); const mozillaCentralMappings = require("./configs/mozilla-central-mappings"); @@ -40,7 +42,14 @@ const webpackConfig = { publicPath: "/assets/build" }, - plugins: [] + plugins: [ + new CopyWebpackPlugin( + Object.entries(sourceMapAssets).map(([name, filePath]) => ({ + from: filePath, + to: `source-map-worker-assets/${name}` + })) + ) + ] }; if (isProduction) { diff --git a/yarn.lock b/yarn.lock index e6b1558d85..97038e477a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2903,6 +2903,19 @@ copy-paste@^1.3.0: optionalDependencies: sync-exec "~0.6.x" +copy-webpack-plugin@^4.5.2: + version "4.5.2" + resolved "https://registry.yarnpkg.com/copy-webpack-plugin/-/copy-webpack-plugin-4.5.2.tgz#d53444a8fea2912d806e78937390ddd7e632ee5c" + dependencies: + cacache "^10.0.4" + find-cache-dir "^1.0.0" + globby "^7.1.1" + is-glob "^4.0.0" + loader-utils "^1.1.0" + minimatch "^3.0.4" + p-limit "^1.0.0" + serialize-javascript "^1.4.0" + core-js@^1.0.0: version "1.2.7" resolved "https://registry.yarnpkg.com/core-js/-/core-js-1.2.7.tgz#652294c14651db28fa93bd2d5ff2983a4f08c636" @@ -5139,6 +5152,17 @@ globby@^5.0.0: pify "^2.0.0" pinkie-promise "^2.0.0" +globby@^7.1.1: + version "7.1.1" + resolved "https://registry.yarnpkg.com/globby/-/globby-7.1.1.tgz#fb2ccff9401f8600945dfada97440cca972b8680" + dependencies: + array-union "^1.0.1" + dir-glob "^2.0.0" + glob "^7.1.2" + ignore "^3.3.5" + pify "^3.0.0" + slash "^1.0.0" + globby@^8.0.0: version "8.0.1" resolved "https://registry.yarnpkg.com/globby/-/globby-8.0.1.tgz#b5ad48b8aa80b35b814fc1281ecc851f1d2b5b50" @@ -8337,7 +8361,7 @@ p-is-promise@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/p-is-promise/-/p-is-promise-1.1.0.tgz#9c9456989e9f6588017b0434d56097675c3da05e" -p-limit@^1.1.0: +p-limit@^1.0.0, p-limit@^1.1.0: version "1.3.0" resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-1.3.0.tgz#b86bd5f0c25690911c7590fcbfc2010d54b3ccb8" dependencies: From 0a3b6d4009f6daf1e6bfe5065cd3a92181eea9fa Mon Sep 17 00:00:00 2001 From: Logan Smyth Date: Thu, 27 Sep 2018 11:10:36 -0700 Subject: [PATCH 4/5] Centralize sourcemap consumer construction. --- packages/devtools-source-map/src/source-map.js | 3 ++- .../src/tests/wasm-source-map.js | 6 +++--- .../src/utils/createConsumer.js | 14 ++++++++++++++ .../src/utils/fetchSourceMap.js | 3 ++- 4 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 packages/devtools-source-map/src/utils/createConsumer.js diff --git a/packages/devtools-source-map/src/source-map.js b/packages/devtools-source-map/src/source-map.js index 3f7aa759a2..27dfcd92f4 100644 --- a/packages/devtools-source-map/src/source-map.js +++ b/packages/devtools-source-map/src/source-map.js @@ -12,6 +12,7 @@ const { networkRequest } = require("devtools-utils"); const { SourceMapConsumer, SourceMapGenerator } = require("source-map"); +const { createConsumer } = require("./utils/createConsumer"); const assert = require("./utils/assert"); const { fetchSourceMap } = require("./utils/fetchSourceMap"); const { @@ -305,7 +306,7 @@ function applySourceMap( mappings.forEach(mapping => generator.addMapping(mapping)); generator.setSourceContent(url, code); - const map = SourceMapConsumer(generator.toJSON()); + const map = createConsumer(generator.toJSON()); setSourceMap(generatedId, Promise.resolve(map)); } diff --git a/packages/devtools-source-map/src/tests/wasm-source-map.js b/packages/devtools-source-map/src/tests/wasm-source-map.js index fafd14dab4..5bc21da7ef 100644 --- a/packages/devtools-source-map/src/tests/wasm-source-map.js +++ b/packages/devtools-source-map/src/tests/wasm-source-map.js @@ -5,7 +5,7 @@ // Test WasmRemap const { WasmRemap } = require("../utils/wasmRemap"); -const { SourceMapConsumer } = require("source-map"); +const { createConsumer } = require("../utils/createConsumer"); jest.mock("devtools-utils/src/network-request"); @@ -26,7 +26,7 @@ describe("wasm source maps", () => { { offset: 17, line: 2, column: 18 } ]; - const map1 = new SourceMapConsumer(testMap1); + const map1 = await createConsumer(testMap1); const remap1 = new WasmRemap(map1); expect(remap1.file).toEqual("min.js"); @@ -81,7 +81,7 @@ describe("wasm source maps", () => { sourcesContent: ["//test"] }; - const map2 = new SourceMapConsumer(testMap2); + const map2 = await createConsumer(testMap2); const remap2 = new WasmRemap(map2); expect(remap2.file).toEqual("none.js"); expect(remap2.hasContentsOfAllSources()).toEqual(true); diff --git a/packages/devtools-source-map/src/utils/createConsumer.js b/packages/devtools-source-map/src/utils/createConsumer.js new file mode 100644 index 0000000000..2a578541c0 --- /dev/null +++ b/packages/devtools-source-map/src/utils/createConsumer.js @@ -0,0 +1,14 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at . */ + +// @flow +const { SourceMapConsumer } = require("source-map"); + +async function createConsumer(map: any, sourceMapUrl: any): SourceMapConsumer { + return new SourceMapConsumer(map, sourceMapUrl); +} + +module.exports = { + createConsumer +}; diff --git a/packages/devtools-source-map/src/utils/fetchSourceMap.js b/packages/devtools-source-map/src/utils/fetchSourceMap.js index a3dd6a168d..617a15b4c5 100644 --- a/packages/devtools-source-map/src/utils/fetchSourceMap.js +++ b/packages/devtools-source-map/src/utils/fetchSourceMap.js @@ -9,6 +9,7 @@ const { getSourceMap, setSourceMap } = require("./sourceMapRequests"); const { WasmRemap } = require("./wasmRemap"); const { SourceMapConsumer } = require("source-map"); const { convertToJSON } = require("./convertToJSON"); +const { createConsumer } = require("./createConsumer"); import type { Source } from "debugger-html"; @@ -44,7 +45,7 @@ async function _resolveAndFetch(generatedSource: Source): SourceMapConsumer { } // Create the source map and fix it up. - let map = new SourceMapConsumer(fetched.content, baseURL); + let map = await createConsumer(fetched.content, baseURL); if (generatedSource.isWasm) { map = new WasmRemap(map); // Check if experimental scope info exists. From fe6ee945d4e5bf42673cf7d50f16a4a5e8b6a93b Mon Sep 17 00:00:00 2001 From: Logan Smyth Date: Thu, 27 Sep 2018 11:07:41 -0700 Subject: [PATCH 5/5] 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"