Bug 907278 - only attach breakpoints to offsets that are entry points to their line; r=past
authorNick Fitzgerald <fitzgen@gmail.com>
Mon, 09 Sep 2013 10:06:08 -0700
changeset 146210 cca2a6def878aa90a9b69160fda4422ef45da250
parent 146209 493dd25e60c2a89ba9630089487453c9a74eb9ec
child 146211 4d0f4b412d32131bddfb4c47fd158203d285c072
push id25245
push userryanvm@gmail.com
push dateMon, 09 Sep 2013 20:57:55 +0000
treeherdermozilla-central@a468b2e34b04 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspast
bugs907278
milestone26.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 907278 - only attach breakpoints to offsets that are entry points to their line; r=past
toolkit/devtools/server/actors/script.js
toolkit/devtools/server/tests/unit/test_breakpoint-18.js
toolkit/devtools/server/tests/unit/xpcshell.ini
--- a/toolkit/devtools/server/actors/script.js
+++ b/toolkit/devtools/server/actors/script.js
@@ -1391,29 +1391,34 @@ ThreadActor.prototype = {
    *        The script in which we are searching for offsets.
    * @param Map aScriptsAndOffsetMappings
    *        A Map object which maps Debugger.Script instances to arrays of
    *        offset mappings. This is an out param.
    */
   _findClosestOffsetMappings: function TA__findClosestOffsetMappings(aTargetLocation,
                                                                      aScript,
                                                                      aScriptsAndOffsetMappings) {
-    let offsetMappings = aScript.getAllColumnOffsets()
-      .filter(({ lineNumber }) => lineNumber === aTargetLocation.line);
-
     // If we are given a column, we will try and break only at that location,
     // otherwise we will break anytime we get on that line.
 
     if (aTargetLocation.column == null) {
+      let offsetMappings = aScript.getLineOffsets(aTargetLocation.line)
+        .map(o => ({
+          line: aTargetLocation.line,
+          offset: o
+        }));
       if (offsetMappings.length) {
         aScriptsAndOffsetMappings.set(aScript, offsetMappings);
       }
       return;
     }
 
+    let offsetMappings = aScript.getAllColumnOffsets()
+      .filter(({ lineNumber }) => lineNumber === aTargetLocation.line);
+
     // Attempt to find the current closest offset distance from the target
     // location by grabbing any offset mapping in the map by doing one iteration
     // and then breaking (they all have the same distance from the target
     // location).
     let closestDistance = Infinity;
     if (aScriptsAndOffsetMappings.size) {
       for (let mappings of aScriptsAndOffsetMappings.values()) {
         closestDistance = Math.abs(aTargetLocation.column - mappings[0].columnNumber);
new file mode 100644
--- /dev/null
+++ b/toolkit/devtools/server/tests/unit/test_breakpoint-18.js
@@ -0,0 +1,73 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+/**
+ * Check that we only break on offsets that are entry points for the line we are
+ * breaking on. Bug 907278.
+ */
+
+var gDebuggee;
+var gClient;
+var gThreadClient;
+
+function run_test()
+{
+  initTestDebuggerServer();
+  gDebuggee = addTestGlobal("test-breakpoints");
+  gDebuggee.console = { log: x => void x };
+  gClient = new DebuggerClient(DebuggerServer.connectPipe());
+  gClient.connect(function () {
+    attachTestTabAndResume(gClient,
+                           "test-breakpoints",
+                           function (aResponse, aTabClient, aThreadClient) {
+      gThreadClient = aThreadClient;
+      setUpCode();
+    });
+  });
+  do_test_pending();
+}
+
+const URL = "test.js";
+
+function setUpCode() {
+  gClient.addOneTimeListener("newSource", setBreakpoint);
+  Cu.evalInSandbox(
+    "" + function test() {
+      console.log("foo bar");
+      debugger;
+    },
+    gDebuggee,
+    "1.8",
+    URL
+  );
+}
+
+function setBreakpoint() {
+  gThreadClient.setBreakpoint({
+    url: URL,
+    line: 1
+  }, ({ error }) => {
+    do_check_true(!error);
+    gThreadClient.resume(runCode);
+  });
+}
+
+function runCode() {
+  gClient.addOneTimeListener("paused", testBPHit);
+  gDebuggee.test();
+}
+
+function testBPHit(event, { why }) {
+  do_check_eq(why.type, "breakpoint");
+  gClient.addOneTimeListener("paused", testDbgStatement);
+  gThreadClient.resume();
+}
+
+function testDbgStatement(event, { why }) {
+  // Should continue to the debugger statement.
+  do_check_eq(why.type, "debuggerStatement");
+  // Not break on another offset from the same line (that isn't an entry point
+  // to the line)
+  do_check_neq(why.type, "breakpoint");
+  finishClient(gClient);
+}
--- a/toolkit/devtools/server/tests/unit/xpcshell.ini
+++ b/toolkit/devtools/server/tests/unit/xpcshell.ini
@@ -91,16 +91,17 @@ reason = bug 820380
 skip-if = toolkit == "gonk"
 reason = bug 820380
 [test_breakpoint-14.js]
 skip-if = toolkit == "gonk"
 reason = bug 820380
 [test_breakpoint-15.js]
 [test_breakpoint-16.js]
 [test_breakpoint-17.js]
+[test_breakpoint-18.js]
 [test_listsources-01.js]
 [test_listsources-02.js]
 [test_listsources-03.js]
 [test_new_source-01.js]
 [test_sources_backwards_compat-01.js]
 [test_sources_backwards_compat-02.js]
 [test_sourcemaps-01.js]
 [test_sourcemaps-02.js]