diff --git a/devtools/server/actors/source.js b/devtools/server/actors/source.js index cf05f70fb2c8..99a04aae9343 100644 --- a/devtools/server/actors/source.js +++ b/devtools/server/actors/source.js @@ -14,7 +14,6 @@ const DevToolsUtils = require("devtools/shared/DevToolsUtils"); const { assert, fetch } = DevToolsUtils; const { joinURI } = require("devtools/shared/path"); const { sourceSpec } = require("devtools/shared/specs/source"); -const { findClosestScriptBySource } = require("devtools/server/actors/utils/closest-scripts"); loader.lazyRequireGetter(this, "arrayBufferGrip", "devtools/server/actors/array-buffer", true); @@ -433,14 +432,14 @@ const SourceActor = ActorClassWithSpec(sourceSpec, { applyBreakpoint: function(actor) { const { line, column } = actor.location; - // Find all scripts that match the given source actor and line - // number. - let scripts = this._findDebuggeeScripts({ line }); - scripts = scripts.filter((script) => !actor.hasScript(script)); - // Find all entry points that correspond to the given location. const entryPoints = []; if (column === undefined) { + // Find all scripts that match the given source actor and line + // number. + const scripts = this._findDebuggeeScripts({ line }) + .filter((script) => !actor.hasScript(script)); + // This is a line breakpoint, so we add a breakpoint on the first // breakpoint on the line. const lineMatches = []; @@ -466,54 +465,23 @@ const SourceActor = ActorClassWithSpec(sourceSpec, { } } } else { - // Compute columnToOffsetMaps for each script so that we can - // find matching entrypoints for the column breakpoint. - const columnToOffsetMaps = scripts.map(script => - [ - script, - script.getPossibleBreakpoints({ line }), - ] - ); + // Find all scripts that match the given source actor, line, + // and column number. + const scripts = this._findDebuggeeScripts({ line, column }) + .filter((script) => !actor.hasScript(script)); - // This is a column breakpoint, so we are interested in all column - // offsets that correspond to the given line *and* column number. - for (const [script, columnToOffsetMap] of columnToOffsetMaps) { - for (const { columnNumber, offset } of columnToOffsetMap) { - if (columnNumber >= column && columnNumber <= column + 1) { - entryPoints.push({ script, offsets: [offset] }); - } - } - } - - // If we don't find any matching entrypoints, - // then we should see if the breakpoint comes before or after the column offsets. - if (entryPoints.length === 0) { - // It's not entirely clear if the scripts that make it here can come - // from a variety of sources. This function allows filtering by URL - // so it seems like it may be possible and we are erring on the side - // of caution by handling it here. - const closestScripts = findClosestScriptBySource( - columnToOffsetMaps.map(pair => pair[0]), + for (const script of scripts) { + // Check to see if the script contains a breakpoint position at + // this line and column. + const possibleBreakpoint = script.getPossibleBreakpoints({ line, - column, - ); + minColumn: column, + maxColumn: column + 1, + }).pop(); - const columnToOffsetLookup = new Map(columnToOffsetMaps); - for (const script of closestScripts) { - const columnToOffsetMap = columnToOffsetLookup.get(script); - - if (columnToOffsetMap.length > 0) { - const firstColumnOffset = columnToOffsetMap[0]; - const lastColumnOffset = columnToOffsetMap[columnToOffsetMap.length - 1]; - - if (column < firstColumnOffset.columnNumber) { - entryPoints.push({ script, offsets: [firstColumnOffset.offset] }); - } - - if (column > lastColumnOffset.columnNumber) { - entryPoints.push({ script, offsets: [lastColumnOffset.offset] }); - } - } + if (possibleBreakpoint) { + const { offset } = possibleBreakpoint; + entryPoints.push({ script, offsets: [offset] }); } } } diff --git a/devtools/server/actors/utils/closest-scripts.js b/devtools/server/actors/utils/closest-scripts.js deleted file mode 100644 index 4437c9cb5709..000000000000 --- a/devtools/server/actors/utils/closest-scripts.js +++ /dev/null @@ -1,65 +0,0 @@ -/* 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/. */ - -"use strict"; - -const { findSourceOffset } = require("devtools/server/actors/utils/dbg-source"); - -function findClosestScriptBySource(scripts, generatedLine, generatedColumn) { - const bySource = new Map(); - for (const script of scripts) { - const { source } = script; - if (script.format !== "js" || !source) { - continue; - } - - let sourceScripts = bySource.get(source); - if (!sourceScripts) { - sourceScripts = []; - bySource.set(source, sourceScripts); - } - - sourceScripts.push(script); - } - - const closestScripts = []; - for (const sourceScripts of bySource.values()) { - const closest = findClosestScript(sourceScripts, generatedLine, generatedColumn); - if (closest) { - closestScripts.push(closest); - } - } - return closestScripts; -} -exports.findClosestScriptBySource = findClosestScriptBySource; - -function findClosestScript(scripts, generatedLine, generatedColumn) { - if (scripts.length === 0) { - return null; - } - const { source } = scripts[0]; - - const offset = findSourceOffset( - source, - generatedLine, - generatedColumn, - ); - - let closest = null; - for (const script of scripts) { - if (script.source !== source) { - throw new Error("All scripts must be from a single source."); - } - - if ( - offset >= script.sourceStart && - offset < script.sourceStart + script.sourceLength && - (!closest || script.sourceLength < closest.sourceLength) - ) { - closest = script; - } - } - - return closest; -} diff --git a/devtools/server/actors/utils/moz.build b/devtools/server/actors/utils/moz.build index 515f370c7a18..e72d890b38b4 100644 --- a/devtools/server/actors/utils/moz.build +++ b/devtools/server/actors/utils/moz.build @@ -9,7 +9,6 @@ DevToolsModules( 'actor-registry-utils.js', 'actor-registry.js', 'breakpoint-actor-map.js', - 'closest-scripts.js', 'css-grid-utils.js', 'dbg-source.js', 'event-breakpoints.js', diff --git a/devtools/server/tests/unit/test_setBreakpoint-at-the-beginning-of-a-line.js b/devtools/server/tests/unit/test_setBreakpoint-at-the-beginning-of-a-line.js deleted file mode 100644 index 8439a81ca4dd..000000000000 --- a/devtools/server/tests/unit/test_setBreakpoint-at-the-beginning-of-a-line.js +++ /dev/null @@ -1,33 +0,0 @@ -"use strict"; - -const SOURCE_URL = getFileUrl("setBreakpoint-on-column.js"); - -add_task(threadClientTest(async ({ threadClient, debuggee, client }) => { - const promise = waitForNewSource(threadClient, SOURCE_URL); - loadSubScript(SOURCE_URL, debuggee); - const { source } = await promise; - - const location = { sourceUrl: source.url, line: 4, column: 2 }; - setBreakpoint(threadClient, location); - - const packet = await executeOnNextTickAndWaitForPause(function() { - Cu.evalInSandbox("f()", debuggee); - }, client); - - Assert.equal(packet.type, "paused"); - const why = packet.why; - Assert.equal(why.type, "breakpoint"); - Assert.equal(why.actors.length, 1); - - const frame = packet.frame; - Assert.equal(frame.where.actor, source.actor); - Assert.equal(frame.where.line, location.line); - Assert.equal(frame.where.column, 10); - - const variables = frame.environment.bindings.variables; - Assert.equal(variables.a.value.type, "undefined"); - Assert.equal(variables.b.value.type, "undefined"); - Assert.equal(variables.c.value.type, "undefined"); - - await resume(threadClient); -}, { doNotRunWorker: true })); diff --git a/devtools/server/tests/unit/test_setBreakpoint-at-the-end-of-a-line.js b/devtools/server/tests/unit/test_setBreakpoint-at-the-end-of-a-line.js deleted file mode 100644 index 16496e4a4497..000000000000 --- a/devtools/server/tests/unit/test_setBreakpoint-at-the-end-of-a-line.js +++ /dev/null @@ -1,34 +0,0 @@ -"use strict"; - -const SOURCE_URL = getFileUrl("setBreakpoint-on-column.js"); - -add_task(threadClientTest(async ({ threadClient, debuggee, client }) => { - const promise = waitForNewSource(threadClient, SOURCE_URL); - loadSubScript(SOURCE_URL, debuggee); - const { source } = await promise; - - const location = { sourceUrl: source.url, line: 4, column: 42 }; - setBreakpoint(threadClient, location); - - const packet = await executeOnNextTickAndWaitForPause(function() { - Cu.evalInSandbox("f()", debuggee); - }, client); - - Assert.equal(packet.type, "paused"); - const why = packet.why; - Assert.equal(why.type, "breakpoint"); - Assert.equal(why.actors.length, 1); - - const frame = packet.frame; - const where = frame.where; - Assert.equal(where.actor, source.actor); - Assert.equal(where.line, location.line); - Assert.equal(where.column, 32); - - const variables = frame.environment.bindings.variables; - Assert.equal(variables.a.value, 1); - Assert.equal(variables.b.value, 2); - Assert.equal(variables.c.value.type, "undefined"); - - await resume(threadClient); -}, { doNotRunWorker: true })); diff --git a/devtools/server/tests/unit/xpcshell.ini b/devtools/server/tests/unit/xpcshell.ini index 94835fe3334c..11d0d5499549 100644 --- a/devtools/server/tests/unit/xpcshell.ini +++ b/devtools/server/tests/unit/xpcshell.ini @@ -220,9 +220,7 @@ reason = bug 937197 [test_get-executable-lines.js] [test_xpcshell_debugging.js] support-files = xpcshell_debugging_script.js -[test_setBreakpoint-at-the-beginning-of-a-line.js] [test_setBreakpoint-at-the-beginning-of-a-minified-fn.js] -[test_setBreakpoint-at-the-end-of-a-line.js] [test_setBreakpoint-at-the-end-of-a-minified-fn.js] [test_setBreakpoint-on-column.js] [test_setBreakpoint-on-column-in-gcd-script.js]