зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1815937 - [devtools] Remove inline script displacement handling in source actor. r=devtools-reviewers,ochameau.
This is all made unnecessary by the previous patch of the stack. Differential Revision: https://phabricator.services.mozilla.com/D170581
This commit is contained in:
Родитель
1de610bd27
Коммит
babc10bc6c
|
@ -117,7 +117,6 @@ class SourceActor extends Actor {
|
|||
this._url = undefined;
|
||||
this._source = source;
|
||||
this.__isInlineSource = undefined;
|
||||
this._startLineColumnDisplacement = null;
|
||||
}
|
||||
|
||||
get _isInlineSource() {
|
||||
|
@ -295,8 +294,8 @@ class SourceActor extends Actor {
|
|||
return true;
|
||||
}
|
||||
|
||||
async getBreakableLines() {
|
||||
const positions = await this._getBreakpointPositions();
|
||||
getBreakableLines() {
|
||||
const positions = this._getBreakpointPositions();
|
||||
const lines = new Set();
|
||||
for (const position of positions) {
|
||||
if (!lines.has(position.line)) {
|
||||
|
@ -307,106 +306,6 @@ class SourceActor extends Actor {
|
|||
return Array.from(lines);
|
||||
}
|
||||
|
||||
// For inline <script> tags in HTML pages, the column numbers of the start
|
||||
// line are relative to the column immediately after the opening <script> tag,
|
||||
// rather than the start of the line itself. Calculate the start line and any
|
||||
// column displacement from the start of that line in the HTML file.
|
||||
_getStartLineColumnDisplacement() {
|
||||
if (this._startLineColumnDisplacement) {
|
||||
return this._startLineColumnDisplacement;
|
||||
}
|
||||
|
||||
// Allow fetching the partial contents of the HTML file. When getting the
|
||||
// displacement to install breakpoints on an inline source that just
|
||||
// appeared, we don't expect the HTML file to be completely loaded, and if
|
||||
// we wait for it to load then the script will have already started running.
|
||||
// Fetching the partial contents will only return a promise if we haven't
|
||||
// seen any data for the file, which will only be the case when the debugger
|
||||
// attaches to an existing page. In this case we don't need to get the
|
||||
// displacement synchronously, so it's OK if we yield to the event loop
|
||||
// while the promise resolves.
|
||||
const fileContents = this.sourcesManager.urlContents(
|
||||
this.url,
|
||||
/* partial */ true,
|
||||
/* canUseCache */ this._isInlineSource
|
||||
);
|
||||
if (fileContents.then) {
|
||||
return fileContents.then(contents =>
|
||||
this._setStartLineColumnDisplacement(contents)
|
||||
);
|
||||
}
|
||||
return this._setStartLineColumnDisplacement(fileContents);
|
||||
}
|
||||
|
||||
_setStartLineColumnDisplacement(fileContents) {
|
||||
const d = this._calculateStartLineColumnDisplacement(fileContents);
|
||||
this._startLineColumnDisplacement = d;
|
||||
return d;
|
||||
}
|
||||
|
||||
_calculateStartLineColumnDisplacement(fileContents) {
|
||||
const startLine = this._source.startLine;
|
||||
|
||||
const lineBreak = /\r\n?|\n|\u2028|\u2029/;
|
||||
const fileStartLine =
|
||||
fileContents.content.split(lineBreak)[startLine - 1] || "";
|
||||
|
||||
const sourceContents = this._source.text;
|
||||
|
||||
if (lineBreak.test(sourceContents)) {
|
||||
// The inline script must end the HTML file's line.
|
||||
const firstLine = sourceContents.split(lineBreak)[0];
|
||||
if (firstLine.length && fileStartLine.endsWith(firstLine)) {
|
||||
const column = fileStartLine.length - firstLine.length;
|
||||
return { startLine, column };
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
// The inline script could be anywhere on the line. Search for its
|
||||
// contents in the line's text. This is a best-guess method and may return
|
||||
// the wrong result if the text appears multiple times on the line, but
|
||||
// the result should make some sense to the user in any case.
|
||||
const column = fileStartLine.indexOf(sourceContents);
|
||||
if (column != -1) {
|
||||
return { startLine, column };
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
// If a { line, column } location is on the starting line of an inline source,
|
||||
// adjust it upwards or downwards (per |upward|) according to the starting
|
||||
// column displacement.
|
||||
_adjustInlineScriptLocation(location, upward) {
|
||||
if (!this._isInlineSource) {
|
||||
return location;
|
||||
}
|
||||
|
||||
const info = this._getStartLineColumnDisplacement();
|
||||
if (info.then) {
|
||||
return info.then(i =>
|
||||
this._adjustInlineScriptLocationFromDisplacement(i, location, upward)
|
||||
);
|
||||
}
|
||||
return this._adjustInlineScriptLocationFromDisplacement(
|
||||
info,
|
||||
location,
|
||||
upward
|
||||
);
|
||||
}
|
||||
|
||||
_adjustInlineScriptLocationFromDisplacement(info, location, upward) {
|
||||
const { line, column } = location;
|
||||
if (this._startLineColumnDisplacement.startLine == line) {
|
||||
let displacement = this._startLineColumnDisplacement.column;
|
||||
if (!upward) {
|
||||
displacement = -displacement;
|
||||
}
|
||||
return { line, column: column + displacement };
|
||||
}
|
||||
return location;
|
||||
}
|
||||
|
||||
// Get all toplevel scripts in the source. Transitive child scripts must be
|
||||
// found by traversing the child script tree.
|
||||
_getTopLevelDebuggeeScripts() {
|
||||
|
@ -540,7 +439,7 @@ class SourceActor extends Actor {
|
|||
}
|
||||
}
|
||||
|
||||
async _getBreakpointPositions(query) {
|
||||
_getBreakpointPositions(query) {
|
||||
const scripts = this._findDebuggeeScripts(
|
||||
query,
|
||||
/* forBreakpointPositions */ true
|
||||
|
@ -548,7 +447,7 @@ class SourceActor extends Actor {
|
|||
|
||||
const positions = [];
|
||||
for (const script of scripts) {
|
||||
await this._addScriptBreakpointPositions(query, script, positions);
|
||||
this._addScriptBreakpointPositions(query, script, positions);
|
||||
}
|
||||
|
||||
return (
|
||||
|
@ -561,7 +460,7 @@ class SourceActor extends Actor {
|
|||
);
|
||||
}
|
||||
|
||||
async _addScriptBreakpointPositions(query, script, positions) {
|
||||
_addScriptBreakpointPositions(query, script, positions) {
|
||||
const {
|
||||
start: { line: startLine = 0, column: startColumn = 0 } = {},
|
||||
end: { line: endLine = Infinity, column: endColumn = Infinity } = {},
|
||||
|
@ -578,22 +477,15 @@ class SourceActor extends Actor {
|
|||
continue;
|
||||
}
|
||||
|
||||
// Adjust columns according to any inline script start column, so that
|
||||
// column breakpoints show up correctly in the UI.
|
||||
const position = await this._adjustInlineScriptLocation(
|
||||
{
|
||||
line: lineNumber,
|
||||
column: columnNumber,
|
||||
},
|
||||
/* upward */ true
|
||||
);
|
||||
|
||||
positions.push(position);
|
||||
positions.push({
|
||||
line: lineNumber,
|
||||
column: columnNumber,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async getBreakpointPositionsCompressed(query) {
|
||||
const items = await this._getBreakpointPositions(query);
|
||||
getBreakpointPositionsCompressed(query) {
|
||||
const items = this._getBreakpointPositions(query);
|
||||
const compressed = {};
|
||||
for (const { line, column } of items) {
|
||||
if (!compressed[line]) {
|
||||
|
@ -703,7 +595,7 @@ class SourceActor extends Actor {
|
|||
* @returns A Promise that resolves to the given BreakpointActor.
|
||||
*/
|
||||
async applyBreakpoint(actor) {
|
||||
let { line, column } = actor.location;
|
||||
const { line, column } = actor.location;
|
||||
|
||||
// Find all entry points that correspond to the given location.
|
||||
const entryPoints = [];
|
||||
|
@ -741,20 +633,6 @@ class SourceActor extends Actor {
|
|||
}
|
||||
}
|
||||
} else {
|
||||
// Adjust columns according to any inline script start column, to undo
|
||||
// the adjustment performed when sending the breakpoint to the client and
|
||||
// allow the breakpoint to be set correctly in the source (which treats
|
||||
// the location after the <script> tag as column 0).
|
||||
let adjusted = this._adjustInlineScriptLocation(
|
||||
{ line, column },
|
||||
/* upward */ false
|
||||
);
|
||||
if (adjusted.then) {
|
||||
adjusted = await adjusted;
|
||||
}
|
||||
line = adjusted.line;
|
||||
column = adjusted.column;
|
||||
|
||||
// Find all scripts that match the given source actor, line,
|
||||
// and column number.
|
||||
const query = { start: { line, column }, end: { line, column } };
|
||||
|
|
Загрузка…
Ссылка в новой задаче