Bug 1763386 - [devtools] Cleanup up remaping breakpoints r=ochameau

Differential Revision: https://phabricator.services.mozilla.com/D141341
This commit is contained in:
Hubert Boma Manilla 2022-04-08 09:23:33 +00:00
Родитель 20f36004f4
Коммит c9cdcab8b2
4 изменённых файлов: 29 добавлений и 24 удалений

Просмотреть файл

@ -23,8 +23,8 @@ import {
enableBreakpoint,
disableBreakpoint,
} from "./modify";
import remapLocations from "./remapLocations";
import { isOriginalId } from "devtools-source-map";
// this will need to be changed so that addCLientBreakpoint is removed
export * from "./breakpointPositions";
@ -163,13 +163,34 @@ export function removeBreakpointsInSource(cx, source) {
};
}
export function remapBreakpoints(cx, sourceId) {
/**
* Update the original location information of breakpoints.
/*
* Update breakpoints for a source that just got pretty printed.
* This method maps the breakpoints currently set only against the
* non-pretty-printed (generated) source to the related pretty-printed
* (original) source by querying the SourceMap service.
*
* @param {Objeect} cx
* @param {String} sourceId - the generated source id
*/
export function updateBreakpointsForNewPrettyPrintedSource(cx, sourceId) {
return async ({ dispatch, getState, sourceMaps }) => {
if (isOriginalId(sourceId)) {
console.error("Can't update breakpoints on original sources");
return;
}
const breakpoints = getBreakpointsForSource(getState(), sourceId);
const newBreakpoints = await remapLocations(
breakpoints,
sourceId,
sourceMaps
// Remap the breakpoints with the original location information from
// the pretty-printed source.
const newBreakpoints = await Promise.all(
breakpoints.map(async breakpoint => {
const location = await sourceMaps.getOriginalLocation(
breakpoint.generatedLocation
);
return { ...breakpoint, location };
})
);
// Normally old breakpoints will be clobbered if we re-add them, but when

Просмотреть файл

@ -9,6 +9,5 @@ CompiledModules(
"breakpointPositions.js",
"index.js",
"modify.js",
"remapLocations.js",
"syncBreakpoint.js",
)

Просмотреть файл

@ -1,15 +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/>. */
export default function remapLocations(breakpoints, sourceId, sourceMaps) {
const sourceBreakpoints = breakpoints.map(async breakpoint => {
if (breakpoint.location.sourceId !== sourceId) {
return breakpoint;
}
const location = await sourceMaps.getOriginalLocation(breakpoint.location);
return { ...breakpoint, location };
});
return Promise.all(sourceBreakpoints);
}

Просмотреть файл

@ -6,7 +6,7 @@ import { generatedToOriginalId } from "devtools-source-map";
import assert from "../../utils/assert";
import { recordEvent } from "../../utils/telemetry";
import { remapBreakpoints } from "../breakpoints";
import { updateBreakpointsForNewPrettyPrintedSource } from "../breakpoints";
import { setSymbols } from "./symbols";
import { prettyPrint } from "../../workers/pretty-print";
@ -144,7 +144,7 @@ export function togglePrettyPrint(cx, sourceId) {
await dispatch(setSymbols({ cx, source: newPrettySource }));
await dispatch(remapBreakpoints(cx, sourceId));
await dispatch(updateBreakpointsForNewPrettyPrintedSource(cx, sourceId));
return newPrettySource;
};