Bug 1556903 - Return null when source not found. r=loganfsmyth
authorAndrew Nicols <andrew@nicols.co.uk>
Thu, 09 Apr 2020 03:12:44 +0000
changeset 523037 7d4ac54cd44a76b04cd022a081f006691fdc3205
parent 523036 a876822484b0d51fd90decb354062d8c2868b0b7
child 523038 7d5a0c7bf181c579d7c59ce1e3782cf677451877
push id37296
push usercsabou@mozilla.com
push dateThu, 09 Apr 2020 09:55:00 +0000
treeherdermozilla-central@33d2485721c6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersloganfsmyth
bugs1556903
milestone77.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1556903 - Return null when source not found. r=loganfsmyth Differential Revision: https://phabricator.services.mozilla.com/D33755
devtools/client/debugger/packages/devtools-source-map/src/source-map.js
devtools/client/debugger/test/mochitest/browser.ini
devtools/client/debugger/test/mochitest/browser_dbg-sourcemaps-indexed.js
devtools/client/debugger/test/mochitest/examples/doc-sourcemaps-indexed.html
devtools/client/debugger/test/mochitest/examples/sourcemaps-indexed/main.js
devtools/client/debugger/test/mochitest/examples/sourcemaps-indexed/main.js.map
devtools/client/debugger/test/mochitest/examples/sourcemaps-indexed/main.min.js
devtools/client/shared/source-map/worker.js
--- a/devtools/client/debugger/packages/devtools-source-map/src/source-map.js
+++ b/devtools/client/debugger/packages/devtools-source-map/src/source-map.js
@@ -363,17 +363,17 @@ async function getOriginalSourceText(
   const generatedSourceId = originalToGeneratedId(originalSourceId);
   const data = await getSourceMapWithMetadata(generatedSourceId);
   if (!data) {
     return null;
   }
   const { urlsById, map } = data;
 
   const url = urlsById.get(originalSourceId);
-  let text = map.sourceContentFor(url);
+  let text = map.sourceContentFor(url, true);
   if (!text) {
     try {
       const response = await networkRequest(url, {
         loadFromCache: false,
       });
       text = response.content;
     } catch (err) {
       // Wrapper logic renders a notification about the specific URL that
--- a/devtools/client/debugger/test/mochitest/browser.ini
+++ b/devtools/client/debugger/test/mochitest/browser.ini
@@ -137,16 +137,17 @@ skip-if = os == "win" # Bug 1393121
 skip-if = os == "win"
 [browser_dbg-search-project.js]
 [browser_dbg-blackbox-all.js]
 [browser_dbg-blackbox-original.js]
 [browser_dbg-state-based-panels.js]
 [browser_dbg-sourcemaps.js]
 [browser_dbg-sourcemaps-breakpoints.js]
 [browser_dbg-sourcemaps-disabled.js]
+[browser_dbg-sourcemaps-indexed.js]
 [browser_dbg-sourcemaps-reload.js]
 skip-if = os == "win" || (verify) # Bug 1434792
 [browser_dbg-sourcemaps-reloading.js]
 [browser_dbg-sourcemaps-reloading-quickly.js]
 [browser_dbg-sourcemaps2.js]
 [browser_dbg-sourcemaps3.js]
 [browser_dbg-sourcemaps-bogus.js]
 skip-if = os == 'linux' && !asan # bug 1447118
new file mode 100644
--- /dev/null
+++ b/devtools/client/debugger/test/mochitest/browser_dbg-sourcemaps-indexed.js
@@ -0,0 +1,59 @@
+/* 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 <http://mozilla.org/MPL/2.0/>. */
+requestLongerTimeout(2);
+
+function assertBpInGutter(dbg, lineNumber) {
+  const el = findElement(dbg, "breakpoint");
+  const bpLineNumber = +el.querySelector(".CodeMirror-linenumber").innerText;
+  is(
+    bpLineNumber,
+    lineNumber,
+    "Breakpoint is on the correct line in the gutter"
+  );
+}
+
+// Tests loading sourcemapped sources, setting breakpoints, and
+// stepping in them.
+
+// This source map does not have source contents, so it's fetched separately
+add_task(async function() {
+  // NOTE: the CORS call makes the test run times inconsistent
+  const dbg = await initDebugger(
+    "doc-sourcemaps-indexed.html",
+    "main.js",
+    "main.min.js"
+  );
+  const {
+    selectors: { getBreakpoint, getBreakpointCount },
+    getState
+  } = dbg;
+
+  ok(true, "Original sources exist");
+  const mainSrc = findSource(dbg, "main.js");
+
+  await selectSource(dbg, mainSrc);
+
+  // Test that breakpoint is not off by a line.
+  await addBreakpoint(dbg, mainSrc, 4, 2);
+  is(getBreakpointCount(), 1, "One breakpoint exists");
+  ok(
+    getBreakpoint({ sourceId: mainSrc.id, line: 4, column: 2 }),
+    "Breakpoint has correct line"
+  );
+
+  assertBpInGutter(dbg, 4);
+  invokeInTab("logMessage");
+
+  await waitForPaused(dbg);
+  assertPausedLocation(dbg);
+
+  // Tests the existence of the sourcemap link in the original source.
+  ok(findElement(dbg, "sourceMapLink"), "Sourcemap link in original source");
+  await selectSource(dbg, "main.min.js");
+
+  ok(
+    !findElement(dbg, "sourceMapLink"),
+    "No Sourcemap link exists in generated source"
+  );
+});
new file mode 100644
--- /dev/null
+++ b/devtools/client/debugger/test/mochitest/examples/doc-sourcemaps-indexed.html
@@ -0,0 +1,21 @@
+ <!-- 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 http://mozilla.org/MPL/2.0/. -->
+<!DOCTYPE html>
+<html>
+  <head>
+    <meta charset="UTF-8">
+  </head>
+
+<body>
+
+  <section id="example">
+    <input id="message" type="text" name="submitButton" value="" />
+    <input id="log-message" type="button" name="submitButton" value="Log message!" />
+  </section>
+
+  <script type="text/javascript" src="sourcemaps-indexed/main.min.js"></script>
+
+</body>
+
+</html>
new file mode 100644
--- /dev/null
+++ b/devtools/client/debugger/test/mochitest/examples/sourcemaps-indexed/main.js
@@ -0,0 +1,15 @@
+var message = document.getElementById('message');
+
+function logMessage() {
+  console.log('message is: ' + message.value);
+}
+
+message.addEventListener('focus', function() {
+  message.value = '';
+}, false);
+
+var logMessageButton = document.getElementById('log-message');
+
+logMessageButton.addEventListener('click', function() {
+  logMessage();
+}, false);
new file mode 100644
--- /dev/null
+++ b/devtools/client/debugger/test/mochitest/examples/sourcemaps-indexed/main.js.map
@@ -0,0 +1,30 @@
+{
+  "version": 3,
+  "file": "main.js",
+  "sections": [
+    {
+      "offset": {
+        "line": 0,
+        "column": 0
+      },
+      "map": {
+        "version": 3,
+        "sources": [
+          "main.js"
+        ],
+        "names": [
+          "message",
+          "document",
+          "getElementById",
+          "logMessage",
+          "console",
+          "log",
+          "value",
+          "addEventListener",
+          "logMessageButton"
+        ],
+        "mappings": "AAAA,GAAIA,SAAUC,SAASC,eAAe,UAEtC,SAASC,cACPC,QAAQC,IAAI,eAAiBL,QAAQM,OAGvCN,QAAQO,iBAAiB,QAAS,WAChCP,QAAQM,MAAQ,IACf,MAEH,IAAIE,kBAAmBP,SAASC,eAAe,cAE/CM,kBAAiBD,iBAAiB,QAAS,WACzCJ,cACC"
+      }
+    }
+  ]
+}
new file mode 100644
--- /dev/null
+++ b/devtools/client/debugger/test/mochitest/examples/sourcemaps-indexed/main.min.js
@@ -0,0 +1,2 @@
+var message=document.getElementById("message");function logMessage(){console.log("message is: "+message.value)}message.addEventListener("focus",function(){message.value=""},false);var logMessageButton=document.getElementById("log-message");logMessageButton.addEventListener("click",function(){logMessage()},false);
+//# sourceMappingURL=main.js.map
--- a/devtools/client/shared/source-map/worker.js
+++ b/devtools/client/shared/source-map/worker.js
@@ -1781,17 +1781,17 @@ async function getOriginalSourceText(ori
     return null;
   }
 
   const {
     urlsById,
     map
   } = data;
   const url = urlsById.get(originalSourceId);
-  let text = map.sourceContentFor(url);
+  let text = map.sourceContentFor(url, true);
 
   if (!text) {
     try {
       const response = await networkRequest(url, {
         loadFromCache: false
       });
       text = response.content;
     } catch (err) {