Bug 1517626 - Treat event handlers as eval'ed sources, r=lsmyth.
authorBrian Hackett <bhackett1024@gmail.com>
Thu, 10 Jan 2019 16:53:11 -1000
changeset 510500 b62455787e3f0de267d2bd99764e633ac470df72
parent 510499 ad851d4345c08f7e0e5d5578652004194a6e667f
child 510501 9cc1cf173fcee8c559488a0c5b8beda7d32a6734
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)
reviewerslsmyth
bugs1517626
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 1517626 - Treat event handlers as eval'ed sources, r=lsmyth.
devtools/client/debugger/new/test/mochitest/browser.ini
devtools/client/debugger/new/test/mochitest/browser_dbg-event-handler.js
devtools/client/debugger/new/test/mochitest/examples/doc-event-handler.html
devtools/server/actors/utils/TabSources.js
--- a/devtools/client/debugger/new/test/mochitest/browser.ini
+++ b/devtools/client/debugger/new/test/mochitest/browser.ini
@@ -649,16 +649,17 @@ support-files =
   examples/frames.js
   examples/pause-points.js
   examples/script-mutate.js
   examples/script-switching-02.js
   examples/script-switching-01.js
   examples/times2.js
   examples/doc-windowless-workers.html
   examples/simple-worker.js
+  examples/doc-event-handler.html
   examples/doc-eval-throw.html
   examples/doc_rr_basic.html
   examples/doc_rr_continuous.html
   examples/doc_rr_logs.html
   examples/doc_rr_recovery.html
   examples/doc_rr_error.html
 
 [browser_dbg-asm.js]
@@ -767,16 +768,17 @@ skip-if = os == "win"
 [browser_dbg-tabs-pretty-print.js]
 [browser_dbg-tabs-without-urls.js]
 [browser_dbg-toggling-tools.js]
 [browser_dbg-react-app.js]
 skip-if = os == "win"
 [browser_dbg-wasm-sourcemaps.js]
 skip-if = true
 [browser_dbg-windowless-workers.js]
+[browser_dbg-event-handler.js]
 [browser_dbg-eval-throw.js]
 [browser_dbg_rr_breakpoints-01.js]
 skip-if = os != "mac" || debug || !nightly_build
 [browser_dbg_rr_breakpoints-02.js]
 skip-if = os != "mac" || debug || !nightly_build
 [browser_dbg_rr_breakpoints-03.js]
 skip-if = os != "mac" || debug || !nightly_build
 [browser_dbg_rr_breakpoints-04.js]
new file mode 100644
--- /dev/null
+++ b/devtools/client/debugger/new/test/mochitest/browser_dbg-event-handler.js
@@ -0,0 +1,17 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+// Test that pausing within an event handler on an element does *not* show the
+// HTML page containing that element. It should show a sources tab containing
+// just the handler's text instead.
+add_task(async function() {
+  const dbg = await initDebugger("doc-event-handler.html");
+
+  invokeInTab("synthesizeClick");
+
+  await waitForPaused(dbg);
+
+  const state = dbg.store.getState();
+  const source = dbg.selectors.getSelectedSource(state);
+  ok(!source.url, "Selected source should not have a URL");
+});
new file mode 100644
--- /dev/null
+++ b/devtools/client/debugger/new/test/mochitest/examples/doc-event-handler.html
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<meta charset=UTF-8>
+<script>
+function synthesizeClick() {
+const elem = document.getElementById("clicky");
+const event = new MouseEvent("click", {});
+elem.dispatchEvent(event);
+}
+</script>
+<span onclick="debugger" id="clicky">click me</span>
--- a/devtools/server/actors/utils/TabSources.js
+++ b/devtools/server/actors/utils/TabSources.js
@@ -88,17 +88,17 @@ TabSources.prototype = {
       return null;
     }
 
     // It's a hack, but inline HTML scripts each have real sources,
     // but we want to represent all of them as one source as the
     // HTML page. The actor representing this fake HTML source is
     // stored in this array, which always has a URL, so check it
     // first.
-    if (source.url in this._htmlDocumentSourceActors) {
+    if (isInlineSource && source.url in this._htmlDocumentSourceActors) {
       return this._htmlDocumentSourceActors[source.url];
     }
 
     let originalUrl = null;
     if (isInlineSource) {
       // If it's an inline source, the fake HTML source hasn't been
       // created yet (would have returned above), so flip this source
       // into a sourcemapped state by giving it an `originalUrl` which
@@ -229,20 +229,20 @@ TabSources.prototype = {
 
     // XXX bug 915433: We can't rely on Debugger.Source.prototype.text
     // if the source is an HTML-embedded <script> tag. Since we don't
     // have an API implemented to detect whether this is the case, we
     // 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.
+    // Assume the source is inline if the element that introduced it is a
+    // script element and does not have a src attribute.
     const element = source.element ? source.element.unsafeDereference() : null;
-    if (element && (element.tagName !== "SCRIPT" || !element.hasAttribute("src"))) {
+    if (element && element.tagName === "SCRIPT" && !element.hasAttribute("src")) {
       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;
       }