Skip to content

Commit 7b354c1

Browse files
committed
Make it clear that the highlight will be unset when not specified.
1 parent 4cb91b5 commit 7b354c1

File tree

14 files changed

+78
-52
lines changed

14 files changed

+78
-52
lines changed

src/actions/profile-view.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1923,12 +1923,12 @@ export function updateBottomBoxContentsAndMaybeOpen(
19231923
const {
19241924
libIndex,
19251925
sourceIndex,
1926-
scrollToLineNumber,
1927-
highlightLineNumber,
1926+
nativeSymbols,
19281927
initialNativeSymbol,
1928+
scrollToLineNumber,
19291929
scrollToInstructionAddress,
1930-
highlightInstructionAddress,
1931-
nativeSymbols,
1930+
highlightedLineNumber,
1931+
highlightedInstructionAddress,
19321932
} = bottomBoxInfo;
19331933

19341934
const haveSource = sourceIndex !== null;
@@ -1950,9 +1950,9 @@ export function updateBottomBoxContentsAndMaybeOpen(
19501950
shouldOpenBottomBox,
19511951
shouldOpenAssemblyView,
19521952
scrollToLineNumber,
1953-
highlightLineNumber,
19541953
scrollToInstructionAddress,
1955-
highlightInstructionAddress,
1954+
highlightedLineNumber,
1955+
highlightedInstructionAddress,
19561956
};
19571957
}
19581958

src/app-logic/url-handling.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,12 +511,14 @@ export function stateFromLocation(
511511
scrollGeneration: 0,
512512
libIndex: null,
513513
sourceIndex: null,
514+
highlightedLine: null,
514515
};
515516
const assemblyView: AssemblyViewState = {
516517
isOpen: false,
517518
scrollGeneration: 0,
518519
nativeSymbols: [],
519520
currentNativeSymbol: null,
521+
highlightedInstruction: null,
520522
};
521523
const isBottomBoxOpenPerPanel: any = {};
522524
tabSlugs.forEach((tabSlug) => (isBottomBoxOpenPerPanel[tabSlug] = false));

src/components/app/BottomBox.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,14 @@ type StateProps = {
5353
readonly sourceViewCode: SourceCodeStatus | void;
5454
readonly sourceViewScrollGeneration: number;
5555
readonly sourceViewScrollToLineNumber?: number;
56-
readonly sourceViewHighlightedLine?: number;
56+
readonly sourceViewHighlightedLine: number | null;
5757
readonly globalLineTimings: LineTimings;
5858
readonly assemblyViewIsOpen: boolean;
5959
readonly assemblyViewNativeSymbol: NativeSymbolInfo | null;
6060
readonly assemblyViewCode: AssemblyCodeStatus | void;
6161
readonly assemblyViewScrollGeneration: number;
6262
readonly assemblyViewScrollToInstructionAddress?: number;
63-
readonly assemblyViewHighlightedInstruction?: number;
63+
readonly assemblyViewHighlightedInstruction: number | null;
6464
readonly globalAddressTimings: AddressTimings;
6565
};
6666

src/components/shared/AssemblyView.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ type AssemblyViewProps = {
4646
readonly nativeSymbol: NativeSymbolInfo | null;
4747
readonly scrollGeneration: number;
4848
readonly scrollToInstructionAddress?: number;
49-
readonly highlightedInstruction?: number;
49+
readonly highlightedInstruction: number | null;
5050
};
5151

5252
let editorModulePromise: Promise<any> | null = null;
@@ -119,7 +119,7 @@ export class AssemblyView extends React.PureComponent<AssemblyViewProps> {
119119
const editor = new AssemblyViewEditor(
120120
this._getAssemblyCodeOrFallback(),
121121
this.props.timings,
122-
this.props.highlightedInstruction ?? null,
122+
this.props.highlightedInstruction,
123123
domParent
124124
);
125125
this._editor = editor;
@@ -169,9 +169,7 @@ export class AssemblyView extends React.PureComponent<AssemblyViewProps> {
169169
if (
170170
this.props.highlightedInstruction !== prevProps.highlightedInstruction
171171
) {
172-
this._editor.setHighlightedInstruction(
173-
this.props.highlightedInstruction ?? null
174-
);
172+
this._editor.setHighlightedInstruction(this.props.highlightedInstruction);
175173
}
176174
}
177175
}

src/components/shared/SourceView.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ type SourceViewProps = {
4242
readonly filePath: string | null;
4343
readonly scrollGeneration: number;
4444
readonly scrollToLineNumber?: number;
45-
readonly highlightedLine?: number;
45+
readonly highlightedLine: number | null;
4646
};
4747

4848
let editorModulePromise: Promise<any> | null = null;
@@ -109,7 +109,7 @@ export class SourceView extends React.PureComponent<SourceViewProps> {
109109
this._getSourceCodeOrFallback(),
110110
this.props.filePath,
111111
this.props.timings,
112-
this.props.highlightedLine ?? null,
112+
this.props.highlightedLine,
113113
domParent
114114
);
115115
this._editor = editor;
@@ -157,7 +157,7 @@ export class SourceView extends React.PureComponent<SourceViewProps> {
157157
}
158158

159159
if (this.props.highlightedLine !== prevProps.highlightedLine) {
160-
this._editor.setHighlightedLine(this.props.highlightedLine ?? null);
160+
this._editor.setHighlightedLine(this.props.highlightedLine);
161161
}
162162
}
163163
}

src/profile-logic/bottom-box.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ export function getBottomBoxInfoForCallNode(
110110
initialNativeSymbol,
111111
scrollToLineNumber: hottestLine,
112112
scrollToInstructionAddress: hottestInstructionAddress,
113+
highlightedLineNumber: null,
114+
highlightedInstructionAddress: null,
113115
};
114116
}
115117

@@ -154,19 +156,21 @@ export function getBottomBoxInfoForStackFrame(
154156
: [];
155157

156158
const instructionAddress =
157-
nativeSymbol !== null ? frameTable.address[frameIndex] : undefined;
159+
nativeSymbol !== null ? frameTable.address[frameIndex] : -1;
158160

159161
// Extract line number from the frame
160-
const lineNumber = frameTable.line[frameIndex] ?? undefined;
162+
const lineNumber = frameTable.line[frameIndex];
161163

162164
return {
163165
libIndex,
164166
sourceIndex,
165167
nativeSymbols: nativeSymbolInfos,
166168
initialNativeSymbol: 0,
167-
scrollToLineNumber: lineNumber,
168-
highlightLineNumber: lineNumber,
169-
scrollToInstructionAddress: instructionAddress,
170-
highlightInstructionAddress: instructionAddress,
169+
scrollToLineNumber: lineNumber ?? undefined,
170+
highlightedLineNumber: lineNumber,
171+
scrollToInstructionAddress:
172+
instructionAddress !== -1 ? instructionAddress : undefined,
173+
highlightedInstructionAddress:
174+
instructionAddress !== -1 ? instructionAddress : null,
171175
};
172176
}

src/reducers/url-state.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,12 @@ const profileName: Reducer<string | null> = (state = null, action) => {
565565
};
566566

567567
const sourceView: Reducer<SourceViewState> = (
568-
state = { scrollGeneration: 0, libIndex: null, sourceIndex: null },
568+
state = {
569+
scrollGeneration: 0,
570+
libIndex: null,
571+
sourceIndex: null,
572+
highlightedLine: null,
573+
},
569574
action
570575
) => {
571576
switch (action.type) {
@@ -578,7 +583,7 @@ const sourceView: Reducer<SourceViewState> = (
578583
libIndex: action.libIndex,
579584
sourceIndex: action.sourceIndex,
580585
scrollToLineNumber: action.scrollToLineNumber,
581-
highlightedLine: action.highlightLineNumber,
586+
highlightedLine: action.highlightedLineNumber,
582587
};
583588
}
584589
default:
@@ -588,10 +593,11 @@ const sourceView: Reducer<SourceViewState> = (
588593

589594
const assemblyView: Reducer<AssemblyViewState> = (
590595
state = {
596+
isOpen: false,
591597
scrollGeneration: 0,
598+
highlightedInstruction: null,
592599
nativeSymbols: [],
593600
currentNativeSymbol: null,
594-
isOpen: false,
595601
},
596602
action
597603
) => {
@@ -608,7 +614,7 @@ const assemblyView: Reducer<AssemblyViewState> = (
608614
currentNativeSymbol,
609615
isOpen: state.isOpen || shouldOpenAssemblyView,
610616
scrollToInstructionAddress: action.scrollToInstructionAddress,
611-
highlightedInstruction: action.highlightInstructionAddress,
617+
highlightedInstruction: action.highlightedInstructionAddress,
612618
};
613619
}
614620
case 'OPEN_ASSEMBLY_VIEW': {

src/selectors/url-state.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,8 @@ export const getSourceViewScrollGeneration: Selector<number> = (state) =>
7878
export const getSourceViewScrollToLineNumber: Selector<number | undefined> = (
7979
state
8080
) => getProfileSpecificState(state).sourceView.scrollToLineNumber;
81-
export const getSourceViewHighlightedLine: Selector<number | undefined> = (
82-
state
83-
) => getProfileSpecificState(state).sourceView.highlightedLine;
81+
export const getSourceViewHighlightedLine: Selector<number | null> = (state) =>
82+
getProfileSpecificState(state).sourceView.highlightedLine;
8483
export const getAssemblyViewIsOpen: Selector<boolean> = (state) =>
8584
getProfileSpecificState(state).assemblyView.isOpen;
8685
export const getAssemblyViewNativeSymbol: Selector<NativeSymbolInfo | null> = (
@@ -98,10 +97,9 @@ export const getAssemblyViewScrollToInstructionAddress: Selector<
9897
number | undefined
9998
> = (state) =>
10099
getProfileSpecificState(state).assemblyView.scrollToInstructionAddress;
101-
export const getAssemblyViewHighlightedInstruction: Selector<
102-
number | undefined
103-
> = (state) =>
104-
getProfileSpecificState(state).assemblyView.highlightedInstruction;
100+
export const getAssemblyViewHighlightedInstruction: Selector<number | null> = (
101+
state
102+
) => getProfileSpecificState(state).assemblyView.highlightedInstruction;
105103
export const getShowJsTracerSummary: Selector<boolean> = (state) =>
106104
getProfileSpecificState(state).showJsTracerSummary;
107105

src/test/store/bottom-box.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ describe('bottom box', function () {
250250
62
251251
);
252252
expect(UrlStateSelectors.getSourceViewHighlightedLine(getState())).toBe(
253-
undefined
253+
null
254254
);
255255
expect(UrlStateSelectors.getAssemblyViewIsOpen(getState())).toBeFalse();
256256
expect(
@@ -295,7 +295,7 @@ describe('bottom box', function () {
295295
).toEqual(new Map([[0x51, 1]]));
296296
expect(
297297
UrlStateSelectors.getAssemblyViewHighlightedInstruction(getState())
298-
).toBe(undefined);
298+
).toBe(null);
299299
expect(
300300
UrlStateSelectors.getAssemblyViewScrollToInstructionAddress(getState())
301301
).toBe(0x51);
@@ -339,7 +339,7 @@ describe('bottom box', function () {
339339
);
340340
expect(
341341
UrlStateSelectors.getAssemblyViewHighlightedInstruction(getState())
342-
).toBe(undefined);
342+
).toBe(null);
343343
expect(
344344
UrlStateSelectors.getAssemblyViewScrollToInstructionAddress(getState())
345345
).toBeOneOf([0x40, 0x45]);

src/test/url-handling.test.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import type {
3939
State,
4040
ThreadIndex,
4141
IndexIntoSourceTable,
42+
BottomBoxInfo,
4243
} from 'firefox-profiler/types';
4344
import getNiceProfile from './fixtures/profiles/call-nodes';
4445
import queryString from 'query-string';
@@ -1797,11 +1798,13 @@ describe('URL persistence of bottom box (source view and assembly view)', functi
17971798
const sourceFile =
17981799
'hg:hg.mozilla.org/mozilla-central:xpcom/threads/nsThread.cpp:5bb3e281dc9ec8a619c781d52882adb1cacf20bb';
17991800
const sourceIndex = getSourceIndex(sourceFile);
1800-
const bottomBoxInfo = {
1801+
const bottomBoxInfo: BottomBoxInfo = {
18011802
libIndex: 0,
18021803
sourceIndex,
18031804
nativeSymbols: [],
18041805
initialNativeSymbol: null,
1806+
highlightedLineNumber: null,
1807+
highlightedInstructionAddress: null,
18051808
};
18061809
dispatch(updateBottomBoxContentsAndMaybeOpen('calltree', bottomBoxInfo));
18071810
const newStore = _getStoreFromStateAfterUrlRoundtrip(getState());
@@ -1830,11 +1833,13 @@ describe('URL persistence of bottom box (source view and assembly view)', functi
18301833
const sourceFile =
18311834
'hg:hg.mozilla.org/mozilla-central:xpcom/threads/nsThread.cpp:5bb3e281dc9ec8a619c781d52882adb1cacf20bb';
18321835
const sourceIndex = getSourceIndex(sourceFile);
1833-
const bottomBoxInfo = {
1836+
const bottomBoxInfo: BottomBoxInfo = {
18341837
libIndex: 0,
18351838
sourceIndex,
18361839
nativeSymbols: [],
18371840
initialNativeSymbol: null,
1841+
highlightedLineNumber: null,
1842+
highlightedInstructionAddress: null,
18381843
};
18391844
dispatch(updateBottomBoxContentsAndMaybeOpen('calltree', bottomBoxInfo));
18401845
dispatch(closeBottomBox());
@@ -1859,11 +1864,13 @@ describe('URL persistence of bottom box (source view and assembly view)', functi
18591864
functionSize: 14,
18601865
functionSizeIsKnown: false,
18611866
};
1862-
const bottomBoxInfo = {
1867+
const bottomBoxInfo: BottomBoxInfo = {
18631868
libIndex: 0,
18641869
sourceIndex: null,
18651870
nativeSymbols: [nativeSymbolInfo],
18661871
initialNativeSymbol: 0,
1872+
highlightedLineNumber: null,
1873+
highlightedInstructionAddress: null,
18671874
};
18681875
dispatch(updateBottomBoxContentsAndMaybeOpen('calltree', bottomBoxInfo));
18691876
const newStore = _getStoreFromStateAfterUrlRoundtrip(getState());
@@ -1902,11 +1909,13 @@ describe('URL persistence of bottom box (source view and assembly view)', functi
19021909
functionSize: 14,
19031910
functionSizeIsKnown: false,
19041911
};
1905-
const bottomBoxInfo = {
1912+
const bottomBoxInfo: BottomBoxInfo = {
19061913
libIndex: 0,
19071914
sourceIndex,
19081915
nativeSymbols: [nativeSymbolInfo],
19091916
initialNativeSymbol: 0,
1917+
highlightedLineNumber: null,
1918+
highlightedInstructionAddress: null,
19101919
};
19111920
dispatch(updateBottomBoxContentsAndMaybeOpen('calltree', bottomBoxInfo));
19121921
const newStore = _getStoreFromStateAfterUrlRoundtrip(getState());

0 commit comments

Comments
 (0)