summaryrefslogtreecommitdiffstats
path: root/devtools/client/framework/source-map.js
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /devtools/client/framework/source-map.js
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'devtools/client/framework/source-map.js')
-rw-r--r--devtools/client/framework/source-map.js84
1 files changed, 84 insertions, 0 deletions
diff --git a/devtools/client/framework/source-map.js b/devtools/client/framework/source-map.js
new file mode 100644
index 000000000..7c6805c85
--- /dev/null
+++ b/devtools/client/framework/source-map.js
@@ -0,0 +1,84 @@
+// @flow
+
+const {
+ originalToGeneratedId,
+ generatedToOriginalId,
+ isGeneratedId,
+ isOriginalId
+} = require("./source-map-util");
+
+function workerTask(worker, method) {
+ return function(...args: any) {
+ return new Promise((resolve, reject) => {
+ const id = msgId++;
+ worker.postMessage({ id, method, args });
+
+ const listener = ({ data: result }) => {
+ if (result.id !== id) {
+ return;
+ }
+
+ worker.removeEventListener("message", listener);
+ if (result.error) {
+ reject(result.error);
+ } else {
+ resolve(result.response);
+ }
+ };
+
+ worker.addEventListener("message", listener);
+ });
+ };
+}
+
+let sourceMapWorker;
+function restartWorker() {
+ if (sourceMapWorker) {
+ sourceMapWorker.terminate();
+ }
+ sourceMapWorker = new Worker(
+ "resource://devtools/client/framework/source-map-worker.js"
+ );
+
+ if (Services.prefs.getBoolPref("devtools.debugger.client-source-maps-enabled")) {
+ sourceMapWorker.postMessage({ id: 0, method: "enableSourceMaps" });
+ }
+}
+restartWorker();
+
+function destroyWorker() {
+ if (sourceMapWorker) {
+ sourceMapWorker.terminate();
+ sourceMapWorker = null;
+ }
+}
+
+function shouldSourceMap() {
+ return Services.prefs.getBoolPref("devtools.debugger.client-source-maps-enabled");
+}
+
+const getOriginalURLs = workerTask(sourceMapWorker, "getOriginalURLs");
+const getGeneratedLocation = workerTask(sourceMapWorker,
+ "getGeneratedLocation");
+const getOriginalLocation = workerTask(sourceMapWorker,
+ "getOriginalLocation");
+const getOriginalSourceText = workerTask(sourceMapWorker,
+ "getOriginalSourceText");
+const applySourceMap = workerTask(sourceMapWorker, "applySourceMap");
+const clearSourceMaps = workerTask(sourceMapWorker, "clearSourceMaps");
+
+module.exports = {
+ originalToGeneratedId,
+ generatedToOriginalId,
+ isGeneratedId,
+ isOriginalId,
+
+ getOriginalURLs,
+ getGeneratedLocation,
+ getOriginalLocation,
+ getOriginalSourceText,
+ applySourceMap,
+ clearSourceMaps,
+ destroyWorker,
+ shouldSourceMap
+};