Bug 1765817 - [devtools] Add getLocationSource selector to fetch source for a location r=nchevobbe

This cleanup helps support the subsequent work for breakpoints per url.

Depends on D146426

Differential Revision: https://phabricator.services.mozilla.com/D146427
This commit is contained in:
Hubert Boma Manilla 2022-05-17 11:10:21 +00:00
Родитель cad300b928
Коммит 9743602245
15 изменённых файлов: 51 добавлений и 37 удалений

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

@ -275,6 +275,10 @@ class DebuggerPanel {
return this._selectors.getSource(this._getState(), sourceId); return this._selectors.getSource(this._getState(), sourceId);
} }
getLocationSource(location) {
return this._selectors.getLocationSource(this._getState(), location);
}
destroy() { destroy() {
this.panelWin.Debugger.destroy(); this.panelWin.Debugger.destroy();
this.emit("destroyed"); this.emit("destroyed");

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

@ -4,7 +4,7 @@
import { import {
hasInScopeLines, hasInScopeLines,
getSource, getLocationSource,
getSourceTextContent, getSourceTextContent,
getVisibleSelectedFrame, getVisibleSelectedFrame,
} from "../../selectors"; } from "../../selectors";
@ -29,7 +29,7 @@ function getOutOfScopeLines(outOfScopeLocations) {
} }
async function getInScopeLines(cx, location, { dispatch, getState, parser }) { async function getInScopeLines(cx, location, { dispatch, getState, parser }) {
const source = getSource(getState(), location.sourceId); const source = getLocationSource(getState(), location);
const sourceTextContent = getSourceTextContent(getState(), source.id); const sourceTextContent = getSourceTextContent(getState(), source.id);
let locations = null; let locations = null;

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

@ -11,7 +11,7 @@ import {
getBreakpoint, getBreakpoint,
getBreakpointPositionsForLocation, getBreakpointPositionsForLocation,
getFirstBreakpointPosition, getFirstBreakpointPosition,
getSource, getLocationSource,
getSourceContent, getSourceContent,
getBreakpointsList, getBreakpointsList,
getPendingBreakpointList, getPendingBreakpointList,
@ -64,7 +64,7 @@ async function clientSetBreakpoint(
); );
const shouldMapBreakpointExpressions = const shouldMapBreakpointExpressions =
isMapScopesEnabled(getState()) && isMapScopesEnabled(getState()) &&
getSource(getState(), breakpoint.location?.sourceId).isOriginal && getLocationSource(getState(), breakpoint.location).isOriginal &&
(breakpoint.options.logValue || breakpoint.options.condition); (breakpoint.options.logValue || breakpoint.options.condition);
if (shouldMapBreakpointExpressions) { if (shouldMapBreakpointExpressions) {
@ -107,9 +107,12 @@ export function addBreakpoint(
const { dispatch, getState, client } = thunkArgs; const { dispatch, getState, client } = thunkArgs;
recordEvent("add_breakpoint"); recordEvent("add_breakpoint");
const { sourceId, column, line } = initialLocation; const { column, line } = initialLocation;
const initialSource = getLocationSource(getState(), initialLocation);
await dispatch(setBreakpointPositions({ cx, sourceId, line })); await dispatch(
setBreakpointPositions({ cx, sourceId: initialSource.id, line })
);
const position = column const position = column
? getBreakpointPositionsForLocation(getState(), initialLocation) ? getBreakpointPositionsForLocation(getState(), initialLocation)
@ -123,8 +126,8 @@ export function addBreakpoint(
const { location, generatedLocation } = position; const { location, generatedLocation } = position;
const source = getSource(getState(), location.sourceId); const source = getLocationSource(getState(), location);
const generatedSource = getSource(getState(), generatedLocation.sourceId); const generatedSource = getLocationSource(getState(), generatedLocation);
if (!source || !generatedSource) { if (!source || !generatedSource) {
return; return;

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

@ -7,7 +7,7 @@ import {
getExpressions, getExpressions,
getSelectedFrame, getSelectedFrame,
getSelectedFrameId, getSelectedFrameId,
getSourceFromId, getLocationSource,
getSelectedSource, getSelectedSource,
getSelectedScopeMappings, getSelectedScopeMappings,
getSelectedFrameBindings, getSelectedFrameBindings,
@ -133,8 +133,7 @@ function evaluateExpression(cx, expression) {
const frame = getSelectedFrame(getState(), cx.thread); const frame = getSelectedFrame(getState(), cx.thread);
if (frame) { if (frame) {
const { location } = frame; const source = getLocationSource(getState(), frame.location);
const source = getSourceFromId(getState(), location.sourceId);
const selectedSource = getSelectedSource(getState()); const selectedSource = getSelectedSource(getState());

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

@ -4,7 +4,7 @@
import { import {
getSymbols, getSymbols,
getSource, getLocationSource,
getSelectedFrame, getSelectedFrame,
getCurrentThread, getCurrentThread,
} from "../../selectors"; } from "../../selectors";
@ -46,7 +46,7 @@ export function highlightCalls(cx) {
return; return;
} }
const source = getSource(getState(), frame.location.sourceId); const source = getLocationSource(getState(), frame.location);
if (!source) { if (!source) {
return; return;
} }

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

@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/>. */ * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
import { getFrames, getSymbols, getSource } from "../../selectors"; import { getFrames, getSymbols, getLocationSource } from "../../selectors";
import { findClosestFunction } from "../../utils/ast"; import { findClosestFunction } from "../../utils/ast";
@ -11,7 +11,7 @@ function mapDisplayName(frame, { getState }) {
return frame; return frame;
} }
const source = getSource(getState(), frame.location.sourceId); const source = getLocationSource(getState(), frame.location);
if (!source) { if (!source) {
return frame; return frame;

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

@ -5,7 +5,7 @@
import { import {
getFrames, getFrames,
getBlackBoxRanges, getBlackBoxRanges,
getSource, getLocationSource,
getSelectedFrame, getSelectedFrame,
} from "../../selectors"; } from "../../selectors";
@ -23,7 +23,7 @@ function getSelectedFrameId(state, thread, frames) {
selectedFrame && selectedFrame &&
!isFrameBlackBoxed( !isFrameBlackBoxed(
selectedFrame, selectedFrame,
getSource(state, selectedFrame.location.sourceId), getLocationSource(state, selectedFrame.location),
blackboxedRanges blackboxedRanges
) )
) { ) {
@ -31,7 +31,7 @@ function getSelectedFrameId(state, thread, frames) {
} }
selectedFrame = frames.find(frame => { selectedFrame = frames.find(frame => {
const frameSource = getSource(state, frame.location.sourceId); const frameSource = getLocationSource(state, frame.location);
return !isFrameBlackBoxed(frame, frameSource, blackboxedRanges); return !isFrameBlackBoxed(frame, frameSource, blackboxedRanges);
}); });
return selectedFrame?.id; return selectedFrame?.id;
@ -62,9 +62,9 @@ function isWasmOriginalSourceFrame(frame, getState) {
if (isGeneratedId(frame.location.sourceId)) { if (isGeneratedId(frame.location.sourceId)) {
return false; return false;
} }
const generatedSource = getSource( const generatedSource = getLocationSource(
getState(), getState(),
frame.generatedLocation.sourceId frame.generatedLocation
); );
return Boolean(generatedSource?.isWasm); return Boolean(generatedSource?.isWasm);

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

@ -5,6 +5,7 @@
import { import {
getSelectedFrameId, getSelectedFrameId,
getSource, getSource,
getLocationSource,
getSourceContent, getSourceContent,
isMapScopesEnabled, isMapScopesEnabled,
getSelectedFrame, getSelectedFrame,
@ -129,12 +130,12 @@ export function mapScopes(cx, scopes, frame) {
export function getMappedScopes(cx, scopes, frame) { export function getMappedScopes(cx, scopes, frame) {
return async function(thunkArgs) { return async function(thunkArgs) {
const { getState, dispatch } = thunkArgs; const { getState, dispatch } = thunkArgs;
const generatedSource = getSource( const generatedSource = getLocationSource(
getState(), getState(),
frame.generatedLocation.sourceId frame.generatedLocation
); );
const source = getSource(getState(), frame.location.sourceId); const source = getLocationSource(getState(), frame.location);
if ( if (
!isMapScopesEnabled(getState()) || !isMapScopesEnabled(getState()) ||

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

@ -32,7 +32,7 @@ import {
getSelectedSource, getSelectedSource,
canPrettyPrintSource, canPrettyPrintSource,
getIsCurrentThreadPaused, getIsCurrentThreadPaused,
getSourceFromId, getLocationSource,
getSourceTextContent, getSourceTextContent,
tabExists, tabExists,
} from "../../selectors"; } from "../../selectors";
@ -127,7 +127,7 @@ export function selectLocation(cx, location, { keepContext = true } = {}) {
return; return;
} }
let source = getSource(getState(), location.sourceId); let source = getLocationSource(getState(), location);
if (!source) { if (!source) {
// If there is no source we deselect the current selected source // If there is no source we deselect the current selected source
@ -156,7 +156,7 @@ export function selectLocation(cx, location, { keepContext = true } = {}) {
// getRelatedMapLocation will just convert to the related generated/original location. // getRelatedMapLocation will just convert to the related generated/original location.
// i.e if the original location is passed, the related generated location will be returned and vice versa. // i.e if the original location is passed, the related generated location will be returned and vice versa.
location = await getRelatedMapLocation(getState(), sourceMaps, location); location = await getRelatedMapLocation(getState(), sourceMaps, location);
source = getSourceFromId(getState(), location.sourceId); source = getLocationSource(getState(), location);
} }
if (!tabExists(getState(), source.id)) { if (!tabExists(getState(), source.id)) {

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

@ -22,7 +22,7 @@ import {
getCurrentThread, getCurrentThread,
getThreadContext, getThreadContext,
getPauseReason, getPauseReason,
getSourceFromId, getLocationSource,
getSkipPausing, getSkipPausing,
shouldLogEventBreakpoints, shouldLogEventBreakpoints,
} from "../../selectors"; } from "../../selectors";
@ -466,8 +466,7 @@ const mapStateToProps = state => {
workers: getThreads(state), workers: getThreads(state),
skipPausing: getSkipPausing(state), skipPausing: getSkipPausing(state),
logEventBreakpoints: shouldLogEventBreakpoints(state), logEventBreakpoints: shouldLogEventBreakpoints(state),
source: source: selectedFrame && getLocationSource(state, selectedFrame.location),
selectedFrame && getSourceFromId(state, selectedFrame.location.sourceId),
pauseReason: pauseReason?.type ?? "", pauseReason: pauseReason?.type ?? "",
}; };
}; };

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

@ -47,6 +47,10 @@ export function getSourceFromId(state, id) {
return source; return source;
} }
export function getLocationSource(state, location) {
return getSource(state, location.sourceId);
}
export function getSourceByActorId(state, actorId) { export function getSourceByActorId(state, actorId) {
if (!hasSourceActor(state, actorId)) { if (!hasSourceActor(state, actorId)) {
return null; return null;

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

@ -6,7 +6,11 @@ import { createSelector } from "reselect";
import { shallowEqual } from "../utils/shallow-equal"; import { shallowEqual } from "../utils/shallow-equal";
import { getPrettySourceURL } from "../utils/source"; import { getPrettySourceURL } from "../utils/source";
import { getSource, getSpecificSourceByURL, getSourcesMap } from "./sources"; import {
getLocationSource,
getSpecificSourceByURL,
getSourcesMap,
} from "./sources";
import { isOriginalId } from "devtools-source-map"; import { isOriginalId } from "devtools-source-map";
import { isSimilarTab } from "../utils/tabs"; import { isSimilarTab } from "../utils/tabs";
@ -48,7 +52,7 @@ export function getNewSelectedSourceId(state, tabList) {
return ""; return "";
} }
const selectedTab = getSource(state, selectedLocation.sourceId); const selectedTab = getLocationSource(state, selectedLocation);
if (!selectedTab) { if (!selectedTab) {
return ""; return "";
} }

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

@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/>. */ * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
import { getSource, getSourceActorsForSource } from "../../selectors"; import { getLocationSource, getSourceActorsForSource } from "../../selectors";
import { isGenerated } from "../source"; import { isGenerated } from "../source";
import { sortSelectedLocations } from "../location"; import { sortSelectedLocations } from "../location";
import assert from "../assert"; import assert from "../assert";
@ -30,7 +30,7 @@ export function makePendingLocationId(location) {
} }
export function makeBreakpointLocation(state, location) { export function makeBreakpointLocation(state, location) {
const source = getSource(state, location.sourceId); const source = getLocationSource(state, location);
if (!source) { if (!source) {
throw new Error("no source"); throw new Error("no source");
} }

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

@ -3,7 +3,7 @@
* file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */ * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
import { isOriginalId } from "devtools-source-map"; import { isOriginalId } from "devtools-source-map";
import { getSource } from "../selectors"; import { getSource, getLocationSource } from "../selectors";
export async function getGeneratedLocation( export async function getGeneratedLocation(
state, state,
@ -41,7 +41,7 @@ export async function getOriginalLocation(generatedLocation, sourceMaps) {
} }
export async function getMappedLocation(state, sourceMaps, location) { export async function getMappedLocation(state, sourceMaps, location) {
const source = getSource(state, location.sourceId); const source = getLocationSource(state, location);
if (!source) { if (!source) {
throw new Error(`no source ${location.sourceId}`); throw new Error(`no source ${location.sourceId}`);
@ -74,7 +74,7 @@ export async function getMappedLocation(state, sourceMaps, location) {
* related location in the generated source. * related location in the generated source.
*/ */
export async function getRelatedMapLocation(state, sourceMaps, location) { export async function getRelatedMapLocation(state, sourceMaps, location) {
const source = getSource(state, location.sourceId); const source = getLocationSource(state, location);
if (!source) { if (!source) {
return location; return location;

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

@ -164,7 +164,7 @@ async function getViewSourceInDebuggerLocation(
return generatedLocation; return generatedLocation;
} }
const originalSource = dbg.getSource(originalLocation.sourceId); const originalSource = dbg.getLocationSource(originalLocation);
if (!originalSource) { if (!originalSource) {
return generatedLocation; return generatedLocation;