diff --git a/devtools/client/debugger/panel.js b/devtools/client/debugger/panel.js index 8a1155cad874..4fa695d0bbbf 100644 --- a/devtools/client/debugger/panel.js +++ b/devtools/client/debugger/panel.js @@ -275,6 +275,10 @@ class DebuggerPanel { return this._selectors.getSource(this._getState(), sourceId); } + getLocationSource(location) { + return this._selectors.getLocationSource(this._getState(), location); + } + destroy() { this.panelWin.Debugger.destroy(); this.emit("destroyed"); diff --git a/devtools/client/debugger/src/actions/ast/setInScopeLines.js b/devtools/client/debugger/src/actions/ast/setInScopeLines.js index 6244c9277df0..f024f582960c 100644 --- a/devtools/client/debugger/src/actions/ast/setInScopeLines.js +++ b/devtools/client/debugger/src/actions/ast/setInScopeLines.js @@ -4,7 +4,7 @@ import { hasInScopeLines, - getSource, + getLocationSource, getSourceTextContent, getVisibleSelectedFrame, } from "../../selectors"; @@ -29,7 +29,7 @@ function getOutOfScopeLines(outOfScopeLocations) { } 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); let locations = null; diff --git a/devtools/client/debugger/src/actions/breakpoints/modify.js b/devtools/client/debugger/src/actions/breakpoints/modify.js index 685d7c80fc04..77f4587be50b 100644 --- a/devtools/client/debugger/src/actions/breakpoints/modify.js +++ b/devtools/client/debugger/src/actions/breakpoints/modify.js @@ -11,7 +11,7 @@ import { getBreakpoint, getBreakpointPositionsForLocation, getFirstBreakpointPosition, - getSource, + getLocationSource, getSourceContent, getBreakpointsList, getPendingBreakpointList, @@ -64,7 +64,7 @@ async function clientSetBreakpoint( ); const shouldMapBreakpointExpressions = isMapScopesEnabled(getState()) && - getSource(getState(), breakpoint.location?.sourceId).isOriginal && + getLocationSource(getState(), breakpoint.location).isOriginal && (breakpoint.options.logValue || breakpoint.options.condition); if (shouldMapBreakpointExpressions) { @@ -107,9 +107,12 @@ export function addBreakpoint( const { dispatch, getState, client } = thunkArgs; 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 ? getBreakpointPositionsForLocation(getState(), initialLocation) @@ -123,8 +126,8 @@ export function addBreakpoint( const { location, generatedLocation } = position; - const source = getSource(getState(), location.sourceId); - const generatedSource = getSource(getState(), generatedLocation.sourceId); + const source = getLocationSource(getState(), location); + const generatedSource = getLocationSource(getState(), generatedLocation); if (!source || !generatedSource) { return; diff --git a/devtools/client/debugger/src/actions/expressions.js b/devtools/client/debugger/src/actions/expressions.js index 2460cd6f3a7d..a548e8c5522d 100644 --- a/devtools/client/debugger/src/actions/expressions.js +++ b/devtools/client/debugger/src/actions/expressions.js @@ -7,7 +7,7 @@ import { getExpressions, getSelectedFrame, getSelectedFrameId, - getSourceFromId, + getLocationSource, getSelectedSource, getSelectedScopeMappings, getSelectedFrameBindings, @@ -133,8 +133,7 @@ function evaluateExpression(cx, expression) { const frame = getSelectedFrame(getState(), cx.thread); if (frame) { - const { location } = frame; - const source = getSourceFromId(getState(), location.sourceId); + const source = getLocationSource(getState(), frame.location); const selectedSource = getSelectedSource(getState()); diff --git a/devtools/client/debugger/src/actions/pause/highlightCalls.js b/devtools/client/debugger/src/actions/pause/highlightCalls.js index a32d11c40738..8ccfc8acdcb5 100644 --- a/devtools/client/debugger/src/actions/pause/highlightCalls.js +++ b/devtools/client/debugger/src/actions/pause/highlightCalls.js @@ -4,7 +4,7 @@ import { getSymbols, - getSource, + getLocationSource, getSelectedFrame, getCurrentThread, } from "../../selectors"; @@ -46,7 +46,7 @@ export function highlightCalls(cx) { return; } - const source = getSource(getState(), frame.location.sourceId); + const source = getLocationSource(getState(), frame.location); if (!source) { return; } diff --git a/devtools/client/debugger/src/actions/pause/mapDisplayNames.js b/devtools/client/debugger/src/actions/pause/mapDisplayNames.js index 1c9bfc3d85d1..d4a352ebb5d1 100644 --- a/devtools/client/debugger/src/actions/pause/mapDisplayNames.js +++ b/devtools/client/debugger/src/actions/pause/mapDisplayNames.js @@ -2,7 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at . */ -import { getFrames, getSymbols, getSource } from "../../selectors"; +import { getFrames, getSymbols, getLocationSource } from "../../selectors"; import { findClosestFunction } from "../../utils/ast"; @@ -11,7 +11,7 @@ function mapDisplayName(frame, { getState }) { return frame; } - const source = getSource(getState(), frame.location.sourceId); + const source = getLocationSource(getState(), frame.location); if (!source) { return frame; diff --git a/devtools/client/debugger/src/actions/pause/mapFrames.js b/devtools/client/debugger/src/actions/pause/mapFrames.js index a20fed546498..27c4c35c9134 100644 --- a/devtools/client/debugger/src/actions/pause/mapFrames.js +++ b/devtools/client/debugger/src/actions/pause/mapFrames.js @@ -5,7 +5,7 @@ import { getFrames, getBlackBoxRanges, - getSource, + getLocationSource, getSelectedFrame, } from "../../selectors"; @@ -23,7 +23,7 @@ function getSelectedFrameId(state, thread, frames) { selectedFrame && !isFrameBlackBoxed( selectedFrame, - getSource(state, selectedFrame.location.sourceId), + getLocationSource(state, selectedFrame.location), blackboxedRanges ) ) { @@ -31,7 +31,7 @@ function getSelectedFrameId(state, thread, frames) { } selectedFrame = frames.find(frame => { - const frameSource = getSource(state, frame.location.sourceId); + const frameSource = getLocationSource(state, frame.location); return !isFrameBlackBoxed(frame, frameSource, blackboxedRanges); }); return selectedFrame?.id; @@ -62,9 +62,9 @@ function isWasmOriginalSourceFrame(frame, getState) { if (isGeneratedId(frame.location.sourceId)) { return false; } - const generatedSource = getSource( + const generatedSource = getLocationSource( getState(), - frame.generatedLocation.sourceId + frame.generatedLocation ); return Boolean(generatedSource?.isWasm); diff --git a/devtools/client/debugger/src/actions/pause/mapScopes.js b/devtools/client/debugger/src/actions/pause/mapScopes.js index ce33b4e59da4..78afe32fa988 100644 --- a/devtools/client/debugger/src/actions/pause/mapScopes.js +++ b/devtools/client/debugger/src/actions/pause/mapScopes.js @@ -5,6 +5,7 @@ import { getSelectedFrameId, getSource, + getLocationSource, getSourceContent, isMapScopesEnabled, getSelectedFrame, @@ -129,12 +130,12 @@ export function mapScopes(cx, scopes, frame) { export function getMappedScopes(cx, scopes, frame) { return async function(thunkArgs) { const { getState, dispatch } = thunkArgs; - const generatedSource = getSource( + const generatedSource = getLocationSource( getState(), - frame.generatedLocation.sourceId + frame.generatedLocation ); - const source = getSource(getState(), frame.location.sourceId); + const source = getLocationSource(getState(), frame.location); if ( !isMapScopesEnabled(getState()) || diff --git a/devtools/client/debugger/src/actions/sources/select.js b/devtools/client/debugger/src/actions/sources/select.js index 9518199adb4d..5037b7302902 100644 --- a/devtools/client/debugger/src/actions/sources/select.js +++ b/devtools/client/debugger/src/actions/sources/select.js @@ -32,7 +32,7 @@ import { getSelectedSource, canPrettyPrintSource, getIsCurrentThreadPaused, - getSourceFromId, + getLocationSource, getSourceTextContent, tabExists, } from "../../selectors"; @@ -127,7 +127,7 @@ export function selectLocation(cx, location, { keepContext = true } = {}) { return; } - let source = getSource(getState(), location.sourceId); + let source = getLocationSource(getState(), location); if (!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. // i.e if the original location is passed, the related generated location will be returned and vice versa. location = await getRelatedMapLocation(getState(), sourceMaps, location); - source = getSourceFromId(getState(), location.sourceId); + source = getLocationSource(getState(), location); } if (!tabExists(getState(), source.id)) { diff --git a/devtools/client/debugger/src/components/SecondaryPanes/index.js b/devtools/client/debugger/src/components/SecondaryPanes/index.js index 45c56975c3a5..28a151b65eeb 100644 --- a/devtools/client/debugger/src/components/SecondaryPanes/index.js +++ b/devtools/client/debugger/src/components/SecondaryPanes/index.js @@ -22,7 +22,7 @@ import { getCurrentThread, getThreadContext, getPauseReason, - getSourceFromId, + getLocationSource, getSkipPausing, shouldLogEventBreakpoints, } from "../../selectors"; @@ -466,8 +466,7 @@ const mapStateToProps = state => { workers: getThreads(state), skipPausing: getSkipPausing(state), logEventBreakpoints: shouldLogEventBreakpoints(state), - source: - selectedFrame && getSourceFromId(state, selectedFrame.location.sourceId), + source: selectedFrame && getLocationSource(state, selectedFrame.location), pauseReason: pauseReason?.type ?? "", }; }; diff --git a/devtools/client/debugger/src/selectors/sources.js b/devtools/client/debugger/src/selectors/sources.js index db74f9415ef8..cddac95c3514 100644 --- a/devtools/client/debugger/src/selectors/sources.js +++ b/devtools/client/debugger/src/selectors/sources.js @@ -47,6 +47,10 @@ export function getSourceFromId(state, id) { return source; } +export function getLocationSource(state, location) { + return getSource(state, location.sourceId); +} + export function getSourceByActorId(state, actorId) { if (!hasSourceActor(state, actorId)) { return null; diff --git a/devtools/client/debugger/src/selectors/tabs.js b/devtools/client/debugger/src/selectors/tabs.js index baac579cc7f9..834ccafa997b 100644 --- a/devtools/client/debugger/src/selectors/tabs.js +++ b/devtools/client/debugger/src/selectors/tabs.js @@ -6,7 +6,11 @@ import { createSelector } from "reselect"; import { shallowEqual } from "../utils/shallow-equal"; import { getPrettySourceURL } from "../utils/source"; -import { getSource, getSpecificSourceByURL, getSourcesMap } from "./sources"; +import { + getLocationSource, + getSpecificSourceByURL, + getSourcesMap, +} from "./sources"; import { isOriginalId } from "devtools-source-map"; import { isSimilarTab } from "../utils/tabs"; @@ -48,7 +52,7 @@ export function getNewSelectedSourceId(state, tabList) { return ""; } - const selectedTab = getSource(state, selectedLocation.sourceId); + const selectedTab = getLocationSource(state, selectedLocation); if (!selectedTab) { return ""; } diff --git a/devtools/client/debugger/src/utils/breakpoint/index.js b/devtools/client/debugger/src/utils/breakpoint/index.js index bc7d432b9ef2..4dbe5741b7cd 100644 --- a/devtools/client/debugger/src/utils/breakpoint/index.js +++ b/devtools/client/debugger/src/utils/breakpoint/index.js @@ -2,7 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at . */ -import { getSource, getSourceActorsForSource } from "../../selectors"; +import { getLocationSource, getSourceActorsForSource } from "../../selectors"; import { isGenerated } from "../source"; import { sortSelectedLocations } from "../location"; import assert from "../assert"; @@ -30,7 +30,7 @@ export function makePendingLocationId(location) { } export function makeBreakpointLocation(state, location) { - const source = getSource(state, location.sourceId); + const source = getLocationSource(state, location); if (!source) { throw new Error("no source"); } diff --git a/devtools/client/debugger/src/utils/source-maps.js b/devtools/client/debugger/src/utils/source-maps.js index 368bd39b1736..071c7e372761 100644 --- a/devtools/client/debugger/src/utils/source-maps.js +++ b/devtools/client/debugger/src/utils/source-maps.js @@ -3,7 +3,7 @@ * file, You can obtain one at . */ import { isOriginalId } from "devtools-source-map"; -import { getSource } from "../selectors"; +import { getSource, getLocationSource } from "../selectors"; export async function getGeneratedLocation( state, @@ -41,7 +41,7 @@ export async function getOriginalLocation(generatedLocation, sourceMaps) { } export async function getMappedLocation(state, sourceMaps, location) { - const source = getSource(state, location.sourceId); + const source = getLocationSource(state, location); if (!source) { throw new Error(`no source ${location.sourceId}`); @@ -74,7 +74,7 @@ export async function getMappedLocation(state, sourceMaps, location) { * related location in the generated source. */ export async function getRelatedMapLocation(state, sourceMaps, location) { - const source = getSource(state, location.sourceId); + const source = getLocationSource(state, location); if (!source) { return location; diff --git a/devtools/client/shared/view-source.js b/devtools/client/shared/view-source.js index 731c4b0cd532..40e4bd248dda 100644 --- a/devtools/client/shared/view-source.js +++ b/devtools/client/shared/view-source.js @@ -164,7 +164,7 @@ async function getViewSourceInDebuggerLocation( return generatedLocation; } - const originalSource = dbg.getSource(originalLocation.sourceId); + const originalSource = dbg.getLocationSource(originalLocation); if (!originalSource) { return generatedLocation;