Commit 2a9a60a5 authored by Sigurd Schneider's avatar Sigurd Schneider Committed by Commit Bot

[turbolizer] Various clean-ups

This CL enables noImplicitReturns and noImplicitThis warnings in
TypeScript, another step on the road to stricter types.

Drive-by: Fix bug in search function.

Change-Id: Iafb528b5f0e7ccc8774bc218fd0dcdb206a0de31
Notry: true
Bug: v8:7327
Reviewed-on: https://chromium-review.googlesource.com/c/1396422
Commit-Queue: Sigurd Schneider <sigurds@chromium.org>
Reviewed-by: 's avatarGeorg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58576}
parent 8a338597
......@@ -135,8 +135,9 @@ export class DisassemblyView extends TextView {
const linkHandler = (e: MouseEvent) => {
if (!(e.target instanceof HTMLElement)) return;
const offset = e.target.dataset.pcOffset ? e.target.dataset.pcOffset : e.target.parentElement.dataset.pcOffset;
if ((typeof offset) != "undefined" && !Number.isNaN(Number(offset))) {
const offsetAsString = e.target.dataset.pcOffset ? e.target.dataset.pcOffset : e.target.parentElement.dataset.pcOffset;
const offset = Number.parseInt(offsetAsString);
if ((typeof offsetAsString) != "undefined" && !Number.isNaN(offset)) {
view.offsetSelection.select([offset], true);
const nodes = view.sourceResolver.nodesForPCOffset(offset)[0]
if (nodes.length > 0) {
......
......@@ -159,6 +159,7 @@ export class GraphView extends View implements PhaseView {
function zoomed() {
if (d3.event.shiftKey) return false;
view.graphElement.attr("transform", d3.event.transform);
return true;
}
const zoomSvg = d3.zoom<SVGElement, any>()
......@@ -408,7 +409,7 @@ export class GraphView extends View implements PhaseView {
view.toggleTypes();
}
searchInputAction(searchBar, e: KeyboardEvent) {
searchInputAction(searchBar: HTMLInputElement, e: KeyboardEvent) {
if (e.keyCode == 13) {
this.selectionHandler.clear();
const query = searchBar.value;
......@@ -416,11 +417,11 @@ export class GraphView extends View implements PhaseView {
if (query.length == 0) return;
const reg = new RegExp(query);
const filterFunction = function (n) {
const filterFunction = (n: GNode) => {
return (reg.exec(n.getDisplayLabel()) != null ||
(this.state.showTypes && reg.exec(n.getDisplayType())) ||
(reg.exec(n.getTitle())) ||
reg.exec(n.opcode) != null);
reg.exec(n.nodeLabel.opcode) != null);
};
const selection = this.graph.nodes((n) => {
......@@ -706,7 +707,7 @@ export class GraphView extends View implements PhaseView {
.attr("transform", function (d) {
return "translate(" + x + "," + y + ")";
})
.on("click", function (d) {
.on("click", function (this: SVGCircleElement, d) {
const components = this.id.split(',');
const node = graph.nodeMap[components[3]];
const edge = node.inputs[components[2]];
......
......@@ -234,11 +234,11 @@ export class SourceResolver {
return sourcePositionArray;
}
forEachSource(f) {
forEachSource(f: (value: Source, index: number, array: Source[]) => void) {
this.sources.forEach(f);
}
translateToSourceId(sourceId, location) {
translateToSourceId(sourceId: number, location?: SourcePosition) {
for (const position of this.getInlineStack(location)) {
let inlining = this.inlinings[position.inliningId];
if (!inlining) continue;
......@@ -249,7 +249,7 @@ export class SourceResolver {
return location;
}
addInliningPositions(sourcePosition, locations) {
addInliningPositions(sourcePosition: AnyPosition, locations: Array<SourcePosition>) {
let inlining = this.inliningsMap.get(sourcePositionToStringKey(sourcePosition));
if (!inlining) return;
let sourceId = inlining.sourceId
......@@ -260,20 +260,20 @@ export class SourceResolver {
}
}
getInliningForPosition(sourcePosition) {
getInliningForPosition(sourcePosition: AnyPosition) {
return this.inliningsMap.get(sourcePositionToStringKey(sourcePosition));
}
getSource(sourceId) {
getSource(sourceId: number) {
return this.sources[sourceId];
}
getSourceName(sourceId) {
getSourceName(sourceId: number) {
const source = this.sources[sourceId];
return `${source.sourceName}:${source.functionName}`;
}
sourcePositionFor(sourceId, scriptOffset) {
sourcePositionFor(sourceId: number, scriptOffset: number) {
if (!this.sources[sourceId]) {
return null;
}
......@@ -289,7 +289,7 @@ export class SourceResolver {
return null;
}
sourcePositionsInRange(sourceId, start, end) {
sourcePositionsInRange(sourceId: number, start: number, end: number) {
if (!this.sources[sourceId]) return [];
const res = [];
const list = this.sources[sourceId].sourcePositions;
......@@ -302,10 +302,9 @@ export class SourceResolver {
return res;
}
getInlineStack(sourcePosition) {
if (!sourcePosition) {
return [];
}
getInlineStack(sourcePosition?: SourcePosition) {
if (!sourcePosition) return [];
let inliningStack = [];
let cur = sourcePosition;
while (cur && cur.inliningId != -1) {
......@@ -342,7 +341,6 @@ export class SourceResolver {
if (typeof node.pos === "number") {
node.sourcePosition = { scriptOffset: node.pos, inliningId: -1 };
}
}
}
......@@ -358,13 +356,13 @@ export class SourceResolver {
}
}
getInstruction(nodeId): [number, number] {
getInstruction(nodeId: number): [number, number] {
const X = this.nodeIdToInstructionRange[nodeId];
if (X === undefined) return [-1, -1];
return X;
}
getInstructionRangeForBlock(blockId): [number, number] {
getInstructionRangeForBlock(blockId: number): [number, number] {
const X = this.blockIdToInstructionRange[blockId];
if (X === undefined) return [-1, -1];
return X;
......@@ -385,21 +383,22 @@ export class SourceResolver {
return this.pcOffsetToInstructions.size > 0;
}
getKeyPcOffset(offset): number {
getKeyPcOffset(offset: number): number {
if (this.pcOffsets.length === 0) return -1;
for (const key of this.pcOffsets) {
if (key <= offset) {
return key;
}
}
return -1;
}
instructionRangeToKeyPcOffsets([start, end]) {
instructionRangeToKeyPcOffsets([start, end]: [number, number]) {
if (start == end) return [this.instructionToPCOffset[start]];
return this.instructionToPCOffset.slice(start, end);
}
instructionsToKeyPcOffsets(instructionIds) {
instructionsToKeyPcOffsets(instructionIds: Iterable<number>) {
const keyPcOffsets = [];
for (const instructionId of instructionIds) {
keyPcOffsets.push(this.instructionToPCOffset[instructionId]);
......@@ -417,7 +416,7 @@ export class SourceResolver {
return offsets;
}
nodesForPCOffset(offset): [Array<String>, Array<String>] {
nodesForPCOffset(offset: number): [Array<String>, Array<String>] {
if (this.pcOffsets.length === 0) return [[], []];
for (const key of this.pcOffsets) {
if (key <= offset) {
......@@ -496,14 +495,14 @@ export class SourceResolver {
}
repairPhaseId(anyPhaseId) {
return Math.max(0, Math.min(anyPhaseId, this.phases.length - 1))
return Math.max(0, Math.min(anyPhaseId | 0, this.phases.length - 1))
}
getPhase(phaseId) {
getPhase(phaseId: number) {
return this.phases[phaseId];
}
getPhaseIdByName(phaseName) {
getPhaseIdByName(phaseName: string) {
return this.phaseNames.get(phaseName);
}
......
......@@ -60,9 +60,8 @@ export function sortUnique<T>(arr: Array<T>, f: (a: T, b: T) => number, equal: (
}
// Partial application without binding the receiver
export function partial(f, ...arguments1) {
return function (...arguments2) {
var arguments2 = Array.from(arguments);
export function partial(f: any, ...arguments1: any[]) {
return function (this: any, ...arguments2: any[]) {
f.apply(this, [...arguments1, ...arguments2]);
}
}
......@@ -85,6 +84,7 @@ export function measureText(text: string) {
height: textMeasure.getBBox().height,
};
}
return { width: 0, height: 0 };
}
// Interpolate between the given start and end values by a fraction of val/max.
......
......@@ -9,6 +9,8 @@
"emitDecoratorMetadata": true,
"moduleResolution": "node",
"noUnusedLocals": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"lib": ["dom", "es6", "dom.iterable", "scripthost", "es2018"]
},
"files": [
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment