Skip to content

Commit f8d9f04

Browse files
Lightning00BladeDevtools-frontend LUCI CQ
authored andcommitted
Code quality improvements for the Memory panel
While working on extracting the parsing I noticed small changes that we can make. Bug: 454624251 Change-Id: If8434349d63d118bda717327fb1c07ce5e1d6669 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/7693137 Auto-Submit: Nikolay Vitkov <nvitkov@chromium.org> Reviewed-by: Simon Zünd <szuend@chromium.org> Commit-Queue: Simon Zünd <szuend@chromium.org>
1 parent 55979de commit f8d9f04

File tree

5 files changed

+47
-48
lines changed

5 files changed

+47
-48
lines changed

front_end/panels/profiler/HeapDetachedElementsView.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,16 @@ export class DetachedElementsProfileHeader extends WritableProfileHeader {
168168
readonly #heapProfilerModel: SDK.HeapProfilerModel.HeapProfilerModel|null;
169169
readonly detachedElements: Protocol.DOM.DetachedElementInfo[]|null;
170170
constructor(
171-
heapProfilerModel: SDK.HeapProfilerModel.HeapProfilerModel|null, type: DetachedElementsProfileType,
172-
detachedElements: Protocol.DOM.DetachedElementInfo[]|null, title?: string) {
171+
heapProfilerModel: SDK.HeapProfilerModel.HeapProfilerModel|null,
172+
type: DetachedElementsProfileType,
173+
detachedElements: Protocol.DOM.DetachedElementInfo[]|null,
174+
title?: string,
175+
) {
173176
super(
174-
heapProfilerModel?.debuggerModel() ?? null, type,
175-
title || i18nString(UIStrings.detachedElementProfile, {PH1: type.nextProfileUid()}));
177+
heapProfilerModel?.debuggerModel() ?? null,
178+
type,
179+
title || i18nString(UIStrings.detachedElementProfile, {PH1: type.nextProfileUid()}),
180+
);
176181
this.detachedElements = detachedElements;
177182
this.#heapProfilerModel = heapProfilerModel;
178183
}

front_end/panels/profiler/HeapProfileView.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -457,11 +457,15 @@ export class SamplingHeapProfileHeader extends WritableProfileHeader {
457457
nodes: never[],
458458
};
459459
constructor(
460-
heapProfilerModel: SDK.HeapProfilerModel.HeapProfilerModel|null, type: SamplingHeapProfileTypeBase,
461-
title?: string) {
460+
heapProfilerModel: SDK.HeapProfilerModel.HeapProfilerModel|null,
461+
type: SamplingHeapProfileTypeBase,
462+
title?: string,
463+
) {
462464
super(
463-
heapProfilerModel?.debuggerModel() ?? null, type,
464-
title || i18nString(UIStrings.profileD, {PH1: type.nextProfileUid()}));
465+
heapProfilerModel?.debuggerModel() ?? null,
466+
type,
467+
title || i18nString(UIStrings.profileD, {PH1: type.nextProfileUid()}),
468+
);
465469
this.heapProfilerModelInternal = heapProfilerModel;
466470
this.protocolProfileInternal = {
467471
head: {

front_end/panels/profiler/HeapSnapshotView.ts

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -964,8 +964,6 @@ export class HeapSnapshotView extends UI.View.SimpleView implements DataDisplayD
964964
}
965965
let objectPopoverHelper: ObjectUI.ObjectPopoverHelper.ObjectPopoverHelper|null;
966966
return {
967-
// TODO(crbug.com/1172300) Ignored during the jsdoc to ts migration)
968-
// @ts-expect-error
969967
box: span.boxInWindow(),
970968
show: async (popover: UI.GlassPane.GlassPane) => {
971969
if (!heapProfilerModel) {
@@ -1364,7 +1362,7 @@ export class HeapSnapshotProfileType extends
13641362
return;
13651363
}
13661364

1367-
let profile: HeapProfileHeader = new HeapProfileHeader(heapProfilerModel, this);
1365+
let profile = new HeapProfileHeader(heapProfilerModel, this);
13681366
this.setProfileBeingRecorded(profile);
13691367
this.addProfile(profile);
13701368
profile.updateStatus(i18nString(UIStrings.snapshotting));
@@ -1649,33 +1647,29 @@ export interface TrackingHeapSnapshotProfileTypeEventTypes {
16491647

16501648
export class HeapProfileHeader extends ProfileHeader {
16511649
readonly heapProfilerModelInternal: SDK.HeapProfilerModel.HeapProfilerModel|null;
1652-
maxJSObjectId: number;
1653-
workerProxy: HeapSnapshotWorkerProxy|null;
1654-
receiver: Common.StringOutputStream.OutputStream|null;
1655-
snapshotProxy: HeapSnapshotProxy|null;
1650+
maxJSObjectId = -1;
1651+
workerProxy: HeapSnapshotWorkerProxy|null = null;
1652+
receiver: Common.StringOutputStream.OutputStream|null = null;
1653+
snapshotProxy: HeapSnapshotProxy|null = null;
16561654
readonly loadPromise: Promise<HeapSnapshotProxy>;
16571655
fulfillLoad: (value: HeapSnapshotProxy|PromiseLike<HeapSnapshotProxy>) => void;
1658-
totalNumberOfChunks: number;
1659-
bufferedWriter: Bindings.TempFile.TempFile|null;
1660-
onTempFileReady: (() => void)|null;
1656+
totalNumberOfChunks = 0;
1657+
bufferedWriter: Bindings.TempFile.TempFile|null = null;
1658+
onTempFileReady: (() => void)|null = null;
16611659
failedToCreateTempFile?: boolean;
16621660
wasDisposed?: boolean;
16631661
fileName?: Platform.DevToolsPath.RawPathString;
16641662

16651663
constructor(
1666-
heapProfilerModel: SDK.HeapProfilerModel.HeapProfilerModel|null, type: HeapSnapshotProfileType, title?: string) {
1664+
heapProfilerModel: SDK.HeapProfilerModel.HeapProfilerModel|null,
1665+
type: HeapSnapshotProfileType,
1666+
title?: string,
1667+
) {
16671668
super(type, title || i18nString(UIStrings.snapshotD, {PH1: type.nextProfileUid()}));
16681669
this.heapProfilerModelInternal = heapProfilerModel;
1669-
this.maxJSObjectId = -1;
1670-
this.workerProxy = null;
1671-
this.receiver = null;
1672-
this.snapshotProxy = null;
16731670
const {promise, resolve} = Promise.withResolvers<HeapSnapshotProxy>();
16741671
this.loadPromise = promise;
16751672
this.fulfillLoad = resolve;
1676-
this.totalNumberOfChunks = 0;
1677-
this.bufferedWriter = null;
1678-
this.onTempFileReady = null;
16791673
}
16801674

16811675
heapProfilerModel(): SDK.HeapProfilerModel.HeapProfilerModel|null {

front_end/panels/profiler/ProfileHeader.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,14 @@ export class ProfileHeader extends Common.ObjectWrapper.ObjectWrapper<EventTypes
1111
readonly #profileType: ProfileType;
1212
title: string;
1313
uid: number;
14-
#fromFile: boolean;
15-
tempFile: Bindings.TempFile.TempFile|null;
14+
#fromFile = false;
15+
tempFile: Bindings.TempFile.TempFile|null = null;
1616

1717
constructor(profileType: ProfileType, title: string) {
1818
super();
1919
this.#profileType = profileType;
2020
this.title = title;
2121
this.uid = profileType.incrementProfileUid();
22-
this.#fromFile = false;
23-
24-
this.tempFile = null;
2522
}
2623

2724
setTitle(title: string): void {
@@ -103,17 +100,14 @@ export interface EventTypes {
103100
export class ProfileType extends Common.ObjectWrapper.ObjectWrapper<ProfileEventTypes> {
104101
readonly #id: string;
105102
readonly #name: string;
106-
profiles: ProfileHeader[];
107-
#profileBeingRecorded: ProfileHeader|null;
108-
#nextProfileUid: number;
103+
profiles: ProfileHeader[] = [];
104+
#profileBeingRecorded: ProfileHeader|null = null;
105+
#nextProfileUid = 1;
109106

110107
constructor(id: string, name: string) {
111108
super();
112109
this.#id = id;
113110
this.#name = name;
114-
this.profiles = [];
115-
this.#profileBeingRecorded = null;
116-
this.#nextProfileUid = 1;
117111

118112
if (!window.opener) {
119113
window.addEventListener('pagehide', this.clearTempStorage.bind(this), false);

front_end/ui/legacy/UIUtils.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1691,19 +1691,21 @@ export function createSVGChild<K extends keyof SVGElementTagNameMap>(
16911691
return child;
16921692
}
16931693

1694-
export const enclosingNodeOrSelfWithNodeNameInArray = (initialNode: Node, nameArray: string[]): Node|null => {
1695-
let node: (Node|null)|Node = initialNode;
1696-
for (; node && node !== initialNode.ownerDocument; node = node.parentNodeOrShadowHost()) {
1697-
for (let i = 0; i < nameArray.length; ++i) {
1698-
if (node.nodeName.toLowerCase() === nameArray[i].toLowerCase()) {
1699-
return node;
1694+
export const enclosingNodeOrSelfWithNodeNameInArray =
1695+
<T extends keyof HTMLElementTagNameMap>(initialNode: Node, nameArray: T[]): HTMLElementTagNameMap[T]|null => {
1696+
let node: (Node|null)|Node = initialNode;
1697+
for (; node && node !== initialNode.ownerDocument; node = node.parentNodeOrShadowHost()) {
1698+
for (let i = 0; i < nameArray.length; ++i) {
1699+
if (node.nodeName.toLowerCase() === nameArray[i].toLowerCase()) {
1700+
return node as HTMLElementTagNameMap[T];
1701+
}
1702+
}
17001703
}
1701-
}
1702-
}
1703-
return null;
1704-
};
1704+
return null;
1705+
};
17051706

1706-
export const enclosingNodeOrSelfWithNodeName = function(node: Node, nodeName: string): Node|null {
1707+
export const enclosingNodeOrSelfWithNodeName = function<T extends keyof HTMLElementTagNameMap>(
1708+
node: Node, nodeName: T): HTMLElementTagNameMap[T]|null {
17071709
return enclosingNodeOrSelfWithNodeNameInArray(node, [nodeName]);
17081710
};
17091711

0 commit comments

Comments
 (0)