Bug 1517167 Part 2 - Watch for dynamically generated <scripts> in devtools server/client, NOT REVIEWED YET.
authorBrian Hackett <bhackett1024@gmail.com>
Thu, 03 Jan 2019 06:27:48 -1000
changeset 510087 f674573e791bc3393c43e72b60a454efbf92c45d
parent 510086 b0c9a3c8405d00a06a32c974c26fa939041ce74d
child 510088 c64a12a9b28538e62428b93e4a8ffa493215e3bc
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1517167
milestone66.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 1517167 Part 2 - Watch for dynamically generated <scripts> in devtools server/client, NOT REVIEWED YET.
devtools/client/debugger/new/src/actions/sources/newSources.js
devtools/client/debugger/new/src/client/firefox/create.js
devtools/server/actors/source.js
devtools/server/actors/utils/TabSources.js
--- a/devtools/client/debugger/new/src/actions/sources/newSources.js
+++ b/devtools/client/debugger/new/src/actions/sources/newSources.js
@@ -83,17 +83,26 @@ function loadSourceMap(sourceId: SourceI
     const source = getSource(getState(), sourceId);
 
     if (!source || isOriginal(source) || !source.sourceMapURL) {
       return [];
     }
 
     let urls = null;
     try {
-      urls = await sourceMaps.getOriginalURLs(source);
+      const urlInfo = { ...source };
+      if (!urlInfo.url) {
+        // If the source was dynamically generated (via eval, dynamically
+        // created script elements, and so forth), it won't have a URL, so that
+        // it is not collapsed into other sources from the same place. The
+        // introduction URL will include the point it was constructed at,
+        // however, so use that for resolving any source maps in the source.
+        urlInfo.url = urlInfo.introductionUrl;
+      }
+      urls = await sourceMaps.getOriginalURLs(urlInfo);
     } catch (e) {
       console.error(e);
     }
 
     if (!urls) {
       // The source might have changed while we looked up the URLs, so we need
       // to load it again before dispatching. We ran into an issue here because
       // this was previously using 'source' and was at risk of resetting the
--- a/devtools/client/debugger/new/src/client/firefox/create.js
+++ b/devtools/client/debugger/new/src/client/firefox/create.js
@@ -50,16 +50,17 @@ export function createSource(
   const createdSource = {
     id: source.actor,
     thread,
     url: source.url,
     relativeUrl: source.url,
     isPrettyPrinted: false,
     isWasm: false,
     sourceMapURL: source.sourceMapURL,
+    introductionUrl: source.introductionUrl,
     isBlackBoxed: false,
     loadedState: "unloaded"
   };
   clientCommands.registerSource(createdSource);
   return Object.assign(createdSource, {
     isWasm: supportsWasm && source.introductionType === "wasm"
   });
 }
--- a/devtools/server/actors/source.js
+++ b/devtools/server/actors/source.js
@@ -18,16 +18,24 @@ const { joinURI } = require("devtools/sh
 const { sourceSpec } = require("devtools/shared/specs/source");
 const { findClosestScriptBySource } = require("devtools/server/actors/utils/closest-scripts");
 
 loader.lazyRequireGetter(this, "mapURIToAddonID", "devtools/server/actors/utils/map-uri-to-addon-id");
 loader.lazyRequireGetter(this, "arrayBufferGrip", "devtools/server/actors/array-buffer", true);
 
 function isEvalSource(source) {
   const introType = source.introductionType;
+
+  // Script elements that are dynamically created are treated as eval sources.
+  // We detect these by looking at whether there was another script on the stack
+  // when the source was created.
+  if (introType == "scriptElement" && source.introductionScript) {
+    return true;
+  }
+
   // These are all the sources that are essentially eval-ed (either
   // by calling eval or passing a string to one of these functions).
   return (introType === "eval" ||
           introType === "debugger eval" ||
           introType === "Function" ||
           introType === "eventHandler" ||
           introType === "setTimeout" ||
           introType === "setInterval");
--- a/devtools/server/actors/utils/TabSources.js
+++ b/devtools/server/actors/utils/TabSources.js
@@ -233,17 +233,24 @@ TabSources.prototype = {
     // need to be conservative and only treat valid js files as real
     // sources. Otherwise, use the `originalUrl` property to treat it
     // as an HTML source that manages multiple inline sources.
 
     // Assume the source is inline if the element that introduced it is not a
     // script element, or does not have a src attribute.
     const element = source.element ? source.element.unsafeDereference() : null;
     if (element && (element.tagName !== "SCRIPT" || !element.hasAttribute("src"))) {
-      spec.isInlineSource = true;
+      if (source.introductionScript) {
+        // As for other evaluated sources, script elements which were
+        // dynamically generated when another script ran should have
+        // a javascript content-type.
+        spec.contentType = "text/javascript";
+      } else {
+        spec.isInlineSource = true;
+      }
     } else if (source.introductionType === "wasm") {
       // Wasm sources are not JavaScript. Give them their own content-type.
       spec.contentType = "text/wasm";
     } else if (source.introductionType === "debugger eval") {
       // All debugger eval code should have a text/javascript content-type.
       // See Bug 1399064
       spec.contentType = "text/javascript";
     } else if (url) {