diff --git a/src/backend/gdb_expansion.ts b/src/backend/gdb_expansion.ts index ba81fb8c..32b248ec 100644 --- a/src/backend/gdb_expansion.ts +++ b/src/backend/gdb_expansion.ts @@ -15,9 +15,9 @@ const pointerCombineChar = "."; export function isExpandable(value: string): number { let match; value = value.trim(); - if (value.length == 0) return 0; + if (value.length === 0) return 0; else if (value.startsWith("{...}")) return 2; // lldb string/array - else if (value[0] == '{') return 1; // object + else if (value[0] === '{') return 1; // object else if (value.startsWith("true")) return 0; else if (value.startsWith("false")) return 0; else if (match = nullpointerRegex.exec(value)) return 0; @@ -33,7 +33,7 @@ export function isExpandable(value: string): number { export function expandValue(variableCreate: (arg: VariableObject | string, options?: any) => any, value: string, root: string = "", extra: any = undefined): any { const parseCString = () => { value = value.trim(); - if (value[0] != '"' && value[0] != '\'') + if (value[0] !== '"' && value[0] !== '\'') return ""; let stringEnd = 1; let inString = true; @@ -43,9 +43,9 @@ export function expandValue(variableCreate: (arg: VariableObject | string, optio while (inString) { if (escaped) escaped = false; - else if (remaining[0] == '\\') + else if (remaining[0] === '\\') escaped = true; - else if (remaining[0] == charStr) + else if (remaining[0] === charStr) inString = false; remaining = remaining.substring(1); @@ -87,17 +87,17 @@ export function expandValue(variableCreate: (arg: VariableObject | string, optio const parseTupleOrList = () => { value = value.trim(); - if (value[0] != '{') + if (value[0] !== '{') return undefined; const oldContent = value; value = value.substring(1).trim(); - if (value[0] == '}') { + if (value[0] === '}') { value = value.substring(1).trim(); return []; } if (value.startsWith("...")) { value = value.substring(3).trim(); - if (value[0] == '}') { + if (value[0] === '}') { value = value.substring(1).trim(); return "<...>"; } @@ -107,14 +107,14 @@ export function expandValue(variableCreate: (arg: VariableObject | string, optio const newValPos2 = value.indexOf(","); const newValPos3 = value.indexOf("}"); let newValPos = newValPos1; - if (newValPos2 != -1 && newValPos2 < newValPos1) + if (newValPos2 !== -1 && newValPos2 < newValPos1) newValPos = newValPos2; - if (newValPos != -1 && eqPos > newValPos || eqPos == -1 || eqPos > newValPos3 && newValPos2 != -1 || value.startsWith("std::")) { // is value list + if (newValPos !== -1 && eqPos > newValPos || eqPos === -1 || eqPos > newValPos3 && newValPos2 !== -1 || value.startsWith("std::")) { // is value list const values = []; stack.push("[0]"); let val = parseValue(); stack.pop(); - if(typeof val == "string" && val.endsWith('>')){ + if(typeof val === "string" && val.endsWith('>')){ val = val.substring(0, val.length - 2); } values.push(createValue("[0]", val)); @@ -150,7 +150,7 @@ export function expandValue(variableCreate: (arg: VariableObject | string, optio let primitive: any; let match; value = value.trim(); - if (value.length == 0) + if (value.length === 0) primitive = undefined; else if (value.startsWith("true")) { primitive = "true"; @@ -191,9 +191,9 @@ export function expandValue(variableCreate: (arg: VariableObject | string, optio parseValue = () => { value = value.trim(); - if (value[0] == '"') + if (value[0] === '"') return parseCString(); - else if (value[0] == '{') + else if (value[0] === '{') return parseTupleOrList(); else if(value.startsWith("std::")){ const eqPos = value.indexOf("="); @@ -225,10 +225,10 @@ export function expandValue(variableCreate: (arg: VariableObject | string, optio createValue = (name: string, val: any) => { let ref = 0; - if (typeof val == "object") { + if (typeof val === "object") { ref = variableCreate(val); val = "Object"; - } else if (typeof val == "string" && val.startsWith("*0x")) { + } else if (typeof val === "string" && val.startsWith("*0x")) { if (extra && MINode.valueOf(extra, "arg") == "1") { ref = variableCreate(getNamespace("*(" + name), { arg: true }); val = ""; @@ -236,10 +236,10 @@ export function expandValue(variableCreate: (arg: VariableObject | string, optio ref = variableCreate(getNamespace("*" + name)); val = "Object@" + val; } - } else if (typeof val == "string" && val.startsWith("@0x")) { + } else if (typeof val === "string" && val.startsWith("@0x")) { ref = variableCreate(getNamespace("*&" + name.substring(1))); val = "Ref" + val; - } else if (typeof val == "string" && val.startsWith("<...>")) { + } else if (typeof val === "string" && val.startsWith("<...>")) { ref = variableCreate(getNamespace(name)); val = "..."; } @@ -255,7 +255,7 @@ export function expandValue(variableCreate: (arg: VariableObject | string, optio parseCommaValue = () => { value = value.trim(); - if (value[0] != ',') + if (value[0] !== ',') return undefined; value = value.substring(1).trim(); return parseValue(); @@ -263,7 +263,7 @@ export function expandValue(variableCreate: (arg: VariableObject | string, optio parseCommaResult = (pushToStack: boolean = false) => { value = value.trim(); - if (value[0] != ',') + if (value[0] !== ',') return undefined; value = value.substring(1).trim(); return parseResult(pushToStack); diff --git a/src/backend/mi2/mi2.ts b/src/backend/mi2/mi2.ts index 9a32193f..1a5c2b7c 100644 --- a/src/backend/mi2/mi2.ts +++ b/src/backend/mi2/mi2.ts @@ -42,7 +42,7 @@ class LogMessage { const value = content.substr(variableMatch[1].length).trim(); this.logMsgRplItem.push(value); this.logMsgRplNum--; - if(this.logMsgRplNum == 0){ + if(this.logMsgRplNum === 0){ for(let i = 0; i < this.logMsgRplItem.length; i++){ this.logMsgVarProcess = this.logMsgVarProcess.replace("placeHolderForVariable", this.logMsgRplItem[i]); } @@ -56,7 +56,7 @@ class LogMessage { logMsgProcess(parsed:MINode){ this.logMsgBrkList.forEach((brk)=>{ - if(parsed.outOfBandRecord[0].output[0][1] == "breakpoint-hit" && parsed.outOfBandRecord[0].output[2][1] == brk.id){ + if(parsed.outOfBandRecord[0].output[0][1] === "breakpoint-hit" && parsed.outOfBandRecord[0].output[2][1] === brk.id){ this.logMsgVar = brk?.logMessage; const matches = this.logMsgVar.match(this.logReplaceTest); const count = matches ? matches.length : 0; @@ -107,7 +107,7 @@ export class MI2 extends EventEmitter implements IBackend { const promises = this.initCommands(target, cwd); if (procArgs && procArgs.length) promises.push(this.sendCommand("exec-arguments " + procArgs)); - if (process.platform == "win32") { + if (process.platform === "win32") { if (separateConsole !== undefined) promises.push(this.sendCommand("gdb-set new-console on")); promises.push(...autorun.map(value => { return this.sendUserInput(value); })); @@ -332,12 +332,12 @@ export class MI2 extends EventEmitter implements IBackend { stdout(data: any) { if (trace) this.log("stderr", "stdout: " + data); - if (typeof data == "string") + if (typeof data === "string") this.buffer += data; else this.buffer += data.toString("utf8"); const end = this.buffer.lastIndexOf('\n'); - if (end != -1) { + if (end !== -1) { this.onOutput(this.buffer.substring(0, end)); this.buffer = this.buffer.substring(end + 1); } @@ -349,12 +349,12 @@ export class MI2 extends EventEmitter implements IBackend { } stderr(data: any) { - if (typeof data == "string") + if (typeof data === "string") this.errbuf += data; else this.errbuf += data.toString("utf8"); const end = this.errbuf.lastIndexOf('\n'); - if (end != -1) { + if (end !== -1) { this.onOutputStderr(this.errbuf.substring(0, end)); this.errbuf = this.errbuf.substring(end + 1); } @@ -397,7 +397,7 @@ export class MI2 extends EventEmitter implements IBackend { handled = true; } } - if (!handled && parsed.resultRecords && parsed.resultRecords.resultClass == "error") { + if (!handled && parsed.resultRecords && parsed.resultRecords.resultClass === "error") { this.log("stderr", parsed.result("msg") || line); } if (parsed.outOfBandRecord) { @@ -409,11 +409,11 @@ export class MI2 extends EventEmitter implements IBackend { this.log("console", logOutput); } } else { - if (record.type == "exec") { + if (record.type === "exec") { this.emit("exec-async-output", parsed); - if (record.asyncClass == "running") + if (record.asyncClass === "running") this.emit("running", parsed); - else if (record.asyncClass == "stopped") { + else if (record.asyncClass === "stopped") { const reason = parsed.record("reason"); if (reason === undefined) { if (trace) @@ -478,10 +478,10 @@ export class MI2 extends EventEmitter implements IBackend { } } else this.log("log", JSON.stringify(parsed)); - } else if (record.type == "notify") { - if (record.asyncClass == "thread-created") { + } else if (record.type === "notify") { + if (record.asyncClass === "thread-created") { this.emit("thread-created", parsed); - } else if (record.asyncClass == "thread-exited") { + } else if (record.asyncClass === "thread-exited") { this.emit("thread-exited", parsed); } } @@ -489,7 +489,7 @@ export class MI2 extends EventEmitter implements IBackend { }); handled = true; } - if (parsed.token == undefined && parsed.resultRecords == undefined && parsed.outOfBandRecord.length == 0) + if (parsed.token == undefined && parsed.resultRecords == undefined && parsed.outOfBandRecord.length === 0) handled = true; if (!handled) this.log("log", "Unhandled: " + JSON.stringify(parsed)); @@ -505,7 +505,7 @@ export class MI2 extends EventEmitter implements IBackend { return new Promise((resolve, reject) => { this.log("console", "Running executable"); this.sendCommand(startCommand).then((info) => { - if (info.resultRecords.resultClass == "running") + if (info.resultRecords.resultClass === "running") resolve(undefined); else reject(); @@ -551,7 +551,7 @@ export class MI2 extends EventEmitter implements IBackend { this.log("stderr", "interrupt"); return new Promise((resolve, reject) => { this.sendCommand("exec-interrupt").then((info) => { - resolve(info.resultRecords.resultClass == "done"); + resolve(info.resultRecords.resultClass === "done"); }, reject); }); } @@ -561,7 +561,7 @@ export class MI2 extends EventEmitter implements IBackend { this.log("stderr", "continue"); return new Promise((resolve, reject) => { this.sendCommand("exec-continue" + (reverse ? " --reverse" : "")).then((info) => { - resolve(info.resultRecords.resultClass == "running"); + resolve(info.resultRecords.resultClass === "running"); }, reject); }); } @@ -571,7 +571,7 @@ export class MI2 extends EventEmitter implements IBackend { this.log("stderr", "next"); return new Promise((resolve, reject) => { this.sendCommand("exec-next" + (reverse ? " --reverse" : "")).then((info) => { - resolve(info.resultRecords.resultClass == "running"); + resolve(info.resultRecords.resultClass === "running"); }, reject); }); } @@ -581,7 +581,7 @@ export class MI2 extends EventEmitter implements IBackend { this.log("stderr", "step"); return new Promise((resolve, reject) => { this.sendCommand("exec-step" + (reverse ? " --reverse" : "")).then((info) => { - resolve(info.resultRecords.resultClass == "running"); + resolve(info.resultRecords.resultClass === "running"); }, reject); }); } @@ -591,7 +591,7 @@ export class MI2 extends EventEmitter implements IBackend { this.log("stderr", "stepOut"); return new Promise((resolve, reject) => { this.sendCommand("exec-finish" + (reverse ? " --reverse" : "")).then((info) => { - resolve(info.resultRecords.resultClass == "running"); + resolve(info.resultRecords.resultClass === "running"); }, reject); }); } @@ -603,7 +603,7 @@ export class MI2 extends EventEmitter implements IBackend { const target: string = '"' + (filename ? escape(filename) + ":" : "") + line + '"'; this.sendCommand("break-insert -t " + target).then(() => { this.sendCommand("exec-jump " + target).then((info) => { - resolve(info.resultRecords.resultClass == "running"); + resolve(info.resultRecords.resultClass === "running"); }, reject); }, reject); }); @@ -659,14 +659,14 @@ export class MI2 extends EventEmitter implements IBackend { return resolve([false, undefined]); let location = ""; if (breakpoint.countCondition) { - if (breakpoint.countCondition[0] == ">") + if (breakpoint.countCondition[0] === ">") location += "-i " + numRegex.exec(breakpoint.countCondition.substring(1))[0] + " "; else { const match = numRegex.exec(breakpoint.countCondition)[0]; - if (match.length != breakpoint.countCondition.length) { + if (match.length !== breakpoint.countCondition.length) { this.log("stderr", "Unsupported break count expression: '" + breakpoint.countCondition + "'. Only supports 'X' for breaking once after X times or '>X' for ignoring the first X breaks"); location += "-t "; - } else if (parseInt(match) != 0) + } else if (parseInt(match) !== 0) location += "-t -i " + parseInt(match) + " "; } } @@ -675,7 +675,7 @@ export class MI2 extends EventEmitter implements IBackend { else location += '"' + escape(breakpoint.file) + ":" + breakpoint.line + '"'; this.sendCommand("break-insert -f " + location).then((result) => { - if (result.resultRecords.resultClass == "done") { + if (result.resultRecords.resultClass === "done") { const bkptNum = parseInt(result.result("bkpt.number")); const newBrk = { id: bkptNum, @@ -687,7 +687,7 @@ export class MI2 extends EventEmitter implements IBackend { }; if (breakpoint.condition) { this.setBreakPointCondition(bkptNum, breakpoint.condition).then((result) => { - if (result.resultRecords.resultClass == "done") { + if (result.resultRecords.resultClass === "done") { this.breakpoints.set(newBrk, bkptNum); resolve([true, newBrk]); } else { @@ -696,7 +696,7 @@ export class MI2 extends EventEmitter implements IBackend { }, reject); } else if (breakpoint.logMessage) { this.setLogPoint(bkptNum, breakpoint.logMessage).then((result) => { - if (result.resultRecords.resultClass == "done") { + if (result.resultRecords.resultClass === "done") { breakpoint.id = newBrk.id; this.breakpoints.set(newBrk, bkptNum); this.logMessage.logMsgBrkList.push(breakpoint); @@ -723,7 +723,7 @@ export class MI2 extends EventEmitter implements IBackend { if (!this.breakpoints.has(breakpoint)) return resolve(false); this.sendCommand("break-delete " + this.breakpoints.get(breakpoint)).then((result) => { - if (result.resultRecords.resultClass == "done") { + if (result.resultRecords.resultClass === "done") { this.breakpoints.delete(breakpoint); resolve(true); } else resolve(false); @@ -741,7 +741,7 @@ export class MI2 extends EventEmitter implements IBackend { breakpoints.forEach((k, index) => { if (index.file === source) { promises.push(this.sendCommand("break-delete " + k).then((result) => { - if (result.resultRecords.resultClass == "done") resolve(true); + if (result.resultRecords.resultClass === "done") resolve(true); else resolve(false); })); } else { @@ -778,7 +778,7 @@ export class MI2 extends EventEmitter implements IBackend { const options: string[] = []; - if (thread != 0) + if (thread !== 0) options.push("--thread " + thread); const depth: number = (await this.sendCommand(["stack-info-depth"].concat(options).join(" "))).result("depth").valueOf(); @@ -914,7 +914,7 @@ export class MI2 extends EventEmitter implements IBackend { this.log("stderr", "evalExpression"); let command = "data-evaluate-expression "; - if (thread != 0) { + if (thread !== 0) { command += `--thread ${thread} --frame ${frame} `; } command += name; @@ -926,7 +926,7 @@ export class MI2 extends EventEmitter implements IBackend { if (trace) this.log("stderr", "varCreate"); let miCommand = "var-create "; - if (threadId != 0) { + if (threadId !== 0) { miCommand += `--thread ${threadId} --frame ${frameLevel}`; } const res = await this.sendCommand(`${miCommand} ${this.quote(name)} ${frame} "${expression}"`); @@ -966,7 +966,7 @@ export class MI2 extends EventEmitter implements IBackend { } log(type: string, msg: string) { - this.emit("msg", type, msg[msg.length - 1] == '\n' ? msg : (msg + "\n")); + this.emit("msg", type, msg[msg.length - 1] === '\n' ? msg : (msg + "\n")); } sendUserInput(command: string, threadId: number = 0, frameLevel: number = 0): Thenable { @@ -988,7 +988,7 @@ export class MI2 extends EventEmitter implements IBackend { sendCliCommand(command: string, threadId: number = 0, frameLevel: number = 0): Thenable { let miCommand = "interpreter-exec "; - if (threadId != 0) { + if (threadId !== 0) { miCommand += `--thread ${threadId} --frame ${frameLevel} `; } miCommand += `console "${command.replace(/[\\"']/g, '\\$&')}"`; diff --git a/src/backend/mi2/mi2mago.ts b/src/backend/mi2/mi2mago.ts index fc63d6a6..848ae854 100644 --- a/src/backend/mi2/mi2mago.ts +++ b/src/backend/mi2/mi2mago.ts @@ -32,7 +32,7 @@ export class MI2_Mago extends MI2_LLDB { }; stack.forEach(element => { if (element) - if (element[0] == "stack") { + if (element[0] === "stack") { addToStack(element[1]); } else remaining.push(element); }); diff --git a/src/backend/mi_parse.ts b/src/backend/mi_parse.ts index f3f4cf8b..9b761c9d 100644 --- a/src/backend/mi_parse.ts +++ b/src/backend/mi_parse.ts @@ -9,32 +9,32 @@ function parseString(str: string): string { const ret = Buffer.alloc(str.length * 4); let bufIndex = 0; - if (str[0] != '"' || str[str.length - 1] != '"') + if (str[0] !== '"' || str[str.length - 1] !== '"') throw new Error("Not a valid string"); str = str.slice(1, -1); let escaped = false; for (let i = 0; i < str.length; i++) { if (escaped) { let m; - if (str[i] == '\\') + if (str[i] === '\\') bufIndex += ret.write('\\', bufIndex); - else if (str[i] == '"') + else if (str[i] === '"') bufIndex += ret.write('"', bufIndex); - else if (str[i] == '\'') + else if (str[i] === '\'') bufIndex += ret.write('\'', bufIndex); - else if (str[i] == 'n') + else if (str[i] === 'n') bufIndex += ret.write('\n', bufIndex); - else if (str[i] == 'r') + else if (str[i] === 'r') bufIndex += ret.write('\r', bufIndex); - else if (str[i] == 't') + else if (str[i] === 't') bufIndex += ret.write('\t', bufIndex); - else if (str[i] == 'b') + else if (str[i] === 'b') bufIndex += ret.write('\b', bufIndex); - else if (str[i] == 'f') + else if (str[i] === 'f') bufIndex += ret.write('\f', bufIndex); - else if (str[i] == 'v') + else if (str[i] === 'v') bufIndex += ret.write('\v', bufIndex); - else if (str[i] == '0') + else if (str[i] === '0') bufIndex += ret.write('\0', bufIndex); else if (m = octalMatch.exec(str.substring(i))) { ret.writeUInt8(parseInt(m[0], 8), bufIndex++); @@ -43,9 +43,9 @@ function parseString(str: string): string { bufIndex += ret.write(str[i], bufIndex); escaped = false; } else { - if (str[i] == '\\') + if (str[i] === '\\') escaped = true; - else if (str[i] == '"') + else if (str[i] === '"') throw new Error("Not a valid string"); else bufIndex += ret.write(str[i], bufIndex); @@ -90,20 +90,20 @@ export class MINode implements MIInfo { let target = pathRegex.exec(path); if (target) { path = path.substring(target[0].length); - if (current.length && typeof current != "string") { + if (current.length && typeof current !== "string") { const found = []; for (const element of current) { - if (element[0] == target[1]) { + if (element[0] === target[1]) { found.push(element[1]); } } if (found.length > 1) { current = found; - } else if (found.length == 1) { + } else if (found.length === 1) { current = found[0]; } else return undefined; } else return undefined; - } else if (path[0] == '@') { + } else if (path[0] === '@') { current = [current]; path = path.substring(1); } else { @@ -111,9 +111,9 @@ export class MINode implements MIInfo { if (target) { path = path.substring(target[0].length); const i = parseInt(target[1]); - if (current.length && typeof current != "string" && i >= 0 && i < current.length) { + if (current.length && typeof current !== "string" && i >= 0 && i < current.length) { current = current[i]; - } else if (i == 0) { + } else if (i === 0) { // empty } else return undefined; } else return undefined; @@ -165,7 +165,7 @@ export function parseMI(output: string): MINode { } as const; const parseCString = () => { - if (output[0] != '"') + if (output[0] !== '"') return ""; let stringEnd = 1; let inString = true; @@ -174,9 +174,9 @@ export function parseMI(output: string): MINode { while (inString) { if (escaped) escaped = false; - else if (remaining[0] == '\\') + else if (remaining[0] === '\\') escaped = true; - else if (remaining[0] == '"') + else if (remaining[0] === '"') inString = false; remaining = remaining.substring(1); @@ -195,12 +195,12 @@ export function parseMI(output: string): MINode { let parseValue: () => any, parseCommaResult: () => any, parseCommaValue: () => any, parseResult: () => any; const parseTupleOrList = () => { - if (output[0] != '{' && output[0] != '[') + if (output[0] !== '{' && output[0] !== '[') return undefined; const oldContent = output; - const canBeValueList = output[0] == '['; + const canBeValueList = output[0] === '['; output = output.substring(1); - if (output[0] == '}' || output[0] == ']') { + if (output[0] === '}' || output[0] === ']') { output = output.substring(1); // ] or } return []; } @@ -230,9 +230,9 @@ export function parseMI(output: string): MINode { }; parseValue = () => { - if (output[0] == '"') + if (output[0] === '"') return parseCString(); - else if (output[0] == '{' || output[0] == '[') + else if (output[0] === '{' || output[0] === '[') return parseTupleOrList(); else return undefined; @@ -248,14 +248,14 @@ export function parseMI(output: string): MINode { }; parseCommaValue = () => { - if (output[0] != ',') + if (output[0] !== ',') return undefined; output = output.substring(1); return parseValue(); }; parseCommaResult = () => { - if (output[0] != ',') + if (output[0] !== ',') return undefined; output = output.substring(1); return parseResult(); diff --git a/src/frontend/extension.ts b/src/frontend/extension.ts index eaa65583..46ad022b 100644 --- a/src/frontend/extension.ts +++ b/src/frontend/extension.ts @@ -34,7 +34,7 @@ function getMemoryRange(range: string) { return undefined; range = range.replace(/\s+/g, "").toLowerCase(); let index; - if ((index = range.indexOf("+")) != -1) { + if ((index = range.indexOf("+")) !== -1) { const from = range.substring(0, index); let length = range.substring(index + 1); if (!memoryLocationRegex.exec(from)) @@ -42,7 +42,7 @@ function getMemoryRange(range: string) { if (memoryLocationRegex.exec(length)) length = parseInt(length.substring(2), 16).toString(); return "from=" + encodeURIComponent(from) + "&length=" + encodeURIComponent(length); - } else if ((index = range.indexOf("-")) != -1) { + } else if ((index = range.indexOf("-")) !== -1) { const from = range.substring(0, index); const to = range.substring(index + 1); if (!memoryLocationRegex.exec(from)) @@ -58,14 +58,14 @@ function getMemoryRange(range: string) { function examineMemory() { const socketlists = path.join(os.tmpdir(), "code-debug-sockets"); if (!fs.existsSync(socketlists)) { - if (process.platform == "win32") + if (process.platform === "win32") return vscode.window.showErrorMessage("This command is not available on windows"); else return vscode.window.showErrorMessage("No debugging sessions available"); } fs.readdir(socketlists, (err, files) => { if (err) { - if (process.platform == "win32") + if (process.platform === "win32") return vscode.window.showErrorMessage("This command is not available on windows"); else return vscode.window.showErrorMessage("No debugging sessions available"); @@ -75,11 +75,11 @@ function examineMemory() { vscode.window.showTextDocument(vscode.Uri.parse("debugmemory://" + file + "?" + getMemoryRange(range))); }); }; - if (files.length == 1) + if (files.length === 1) pickedFile(files[0]); else if (files.length > 0) vscode.window.showQuickPick(files, { placeHolder: "Running debugging instance" }).then(file => pickedFile(file)); - else if (process.platform == "win32") + else if (process.platform === "win32") return vscode.window.showErrorMessage("This command is not available on windows"); else vscode.window.showErrorMessage("No debugging sessions available"); @@ -93,16 +93,16 @@ class MemoryContentProvider implements vscode.TextDocumentContentProvider { let from: number, to: number; let highlightAt = -1; const splits = uri.query.split("&"); - if (splits[0].split("=")[0] == "at") { + if (splits[0].split("=")[0] === "at") { const loc = parseInt(splits[0].split("=")[1].substring(2), 16); highlightAt = 64; from = Math.max(loc - 64, 0); to = Math.max(loc + 768, 0); - } else if (splits[0].split("=")[0] == "from") { + } else if (splits[0].split("=")[0] === "from") { from = parseInt(splits[0].split("=")[1].substring(2), 16); - if (splits[1].split("=")[0] == "to") { + if (splits[1].split("=")[0] === "to") { to = parseInt(splits[1].split("=")[1].substring(2), 16); - } else if (splits[1].split("=")[0] == "length") { + } else if (splits[1].split("=")[0] === "length") { to = from + parseInt(splits[1].split("=")[1]); } else return reject("Invalid Range"); } else return reject("Invalid Range"); @@ -117,7 +117,7 @@ class MemoryContentProvider implements vscode.TextDocumentContentProvider { let asciiLine = ""; let byteNo = 0; for (let i = 0; i < hexString.length; i += 2) { - if (x == 0) { + if (x === 0) { let addr = index.toString(16); while (addr.length < 16) addr = '0' + addr; formattedCode += addr + " "; @@ -131,13 +131,13 @@ class MemoryContentProvider implements vscode.TextDocumentContentProvider { else asciiLine += "."; - if (highlightAt == byteNo) { + if (highlightAt === byteNo) { formattedCode = formattedCode.slice(0, -1) + "[" + digit + "]"; } else { formattedCode += digit + " "; } - if (x == 7) + if (x === 7) formattedCode += " "; if (++x >= 16) { diff --git a/src/mibase.ts b/src/mibase.ts index ba3fbeb5..ef2b83e3 100644 --- a/src/mibase.ts +++ b/src/mibase.ts @@ -71,7 +71,7 @@ export class MI2DebugSession extends DebugSession { const spaceIndex = rawCmd.indexOf(" "); let func = rawCmd; let args = []; - if (spaceIndex != -1) { + if (spaceIndex !== -1) { func = rawCmd.substring(0, spaceIndex); args = JSON.parse(rawCmd.substring(spaceIndex + 1)); } @@ -81,14 +81,14 @@ export class MI2DebugSession extends DebugSession { }); }); this.commandServer.on("error", err => { - if (process.platform != "win32") + if (process.platform !== "win32") this.handleMsg("stderr", "Code-Debug WARNING: Utility Command Server: Error in command socket " + err.toString() + "\nCode-Debug WARNING: The examine memory location command won't work"); }); if (!fs.existsSync(systemPath.join(os.tmpdir(), "code-debug-sockets"))) fs.mkdirSync(systemPath.join(os.tmpdir(), "code-debug-sockets")); this.commandServer.listen(this.serverPath = systemPath.join(os.tmpdir(), "code-debug-sockets", ("Debug-Instance-" + Math.floor(Math.random() * 36 * 36 * 36 * 36).toString(36)).toLowerCase())); } catch (e) { - if (process.platform != "win32") + if (process.platform !== "win32") this.handleMsg("stderr", "Code-Debug WARNING: Utility Command Server: Failed to start " + e.toString() + "\nCode-Debug WARNING: The examine memory location command won't work"); } } @@ -122,28 +122,28 @@ export class MI2DebugSession extends DebugSession { } protected handleMsg(type: string, msg: string) { - if (type == "target") + if (type === "target") type = "stdout"; - if (type == "log") + if (type === "log") type = "stderr"; this.sendEvent(new OutputEvent(msg, type)); } protected handleBreakpoint(info: MINode) { const event = new StoppedEvent("breakpoint", parseInt(info.record("thread-id"))); - (event as DebugProtocol.StoppedEvent).body.allThreadsStopped = info.record("stopped-threads") == "all"; + (event as DebugProtocol.StoppedEvent).body.allThreadsStopped = info.record("stopped-threads") === "all"; this.sendEvent(event); } protected handleBreak(info?: MINode) { const event = new StoppedEvent("step", info ? parseInt(info.record("thread-id")) : 1); - (event as DebugProtocol.StoppedEvent).body.allThreadsStopped = info ? info.record("stopped-threads") == "all" : true; + (event as DebugProtocol.StoppedEvent).body.allThreadsStopped = info ? info.record("stopped-threads") === "all" : true; this.sendEvent(event); } protected handlePause(info: MINode) { const event = new StoppedEvent("user request", parseInt(info.record("thread-id"))); - (event as DebugProtocol.StoppedEvent).body.allThreadsStopped = info.record("stopped-threads") == "all"; + (event as DebugProtocol.StoppedEvent).body.allThreadsStopped = info.record("stopped-threads") === "all"; this.sendEvent(event); } @@ -152,7 +152,7 @@ export class MI2DebugSession extends DebugSession { this.crashed = true; if (!this.quit) { const event = new StoppedEvent("exception", parseInt(info.record("thread-id"))); - (event as DebugProtocol.StoppedEvent).body.allThreadsStopped = info.record("stopped-threads") == "all"; + (event as DebugProtocol.StoppedEvent).body.allThreadsStopped = info.record("stopped-threads") === "all"; this.sendEvent(event); } } @@ -342,18 +342,18 @@ export class MI2DebugSession extends DebugSession { switch (this.initialRunCommand) { case RunCommand.CONTINUE: case RunCommand.NONE: - if (typeof this.stopAtEntry == 'boolean' && this.stopAtEntry) + if (typeof this.stopAtEntry === 'boolean' && this.stopAtEntry) entryPoint = "main"; // sensible default - else if (typeof this.stopAtEntry == 'string') + else if (typeof this.stopAtEntry === 'string') entryPoint = this.stopAtEntry; break; case RunCommand.RUN: - if (typeof this.stopAtEntry == 'boolean' && this.stopAtEntry) { + if (typeof this.stopAtEntry === 'boolean' && this.stopAtEntry) { if (this.miDebugger.features.includes("exec-run-start-option")) runToStart = true; else entryPoint = "main"; // sensible fallback - } else if (typeof this.stopAtEntry == 'string') + } else if (typeof this.stopAtEntry === 'string') entryPoint = this.stopAtEntry; break; default: @@ -454,7 +454,7 @@ export class MI2DebugSession extends DebugSession { if (id instanceof VariableScope) { try { - if (id.name == "Registers") { + if (id.name === "Registers") { const registers = await this.miDebugger.getRegisters(); for (const reg of registers) { variables.push({ @@ -482,7 +482,7 @@ export class MI2DebugSession extends DebugSession { const varId = this.variableHandlesReverse[varObjName]; varObj = this.variableHandles.get(varId) as any; } catch (err) { - if (err instanceof MIError && (err.message == "Variable object not found" || err.message.endsWith("does not exist"))) { + if (err instanceof MIError && (err.message === "Variable object not found" || err.message.endsWith("does not exist"))) { varObj = await this.miDebugger.varCreate(id.threadId, id.level, variable.name, varObjName); const varId = findOrCreateVariable(varObj); varObj.exp = variable.name; @@ -503,7 +503,7 @@ export class MI2DebugSession extends DebugSession { if (variable.valueStr !== undefined) { let expanded = expandValue(createVariable, `{${variable.name}=${variable.valueStr})`, "", variable.raw); if (expanded) { - if (typeof expanded[0] == "string") + if (typeof expanded[0] === "string") expanded = [ { name: "", @@ -530,7 +530,7 @@ export class MI2DebugSession extends DebugSession { } catch (err) { this.sendErrorResponse(response, 1, `Could not expand variable: ${err}`); } - } else if (typeof id == "string") { + } else if (typeof id === "string") { // Variable members let variable; try { @@ -548,7 +548,7 @@ export class MI2DebugSession extends DebugSession { if (!expanded) { this.sendErrorResponse(response, 2, `Could not expand variable`); } else { - if (typeof expanded[0] == "string") + if (typeof expanded[0] === "string") expanded = [ { name: "", @@ -567,7 +567,7 @@ export class MI2DebugSession extends DebugSession { } catch (err) { this.sendErrorResponse(response, 1, `Could not expand variable: ${err}`); } - } else if (typeof id == "object") { + } else if (typeof id === "object") { if (id instanceof VariableObject) { // Variable members let children: VariableObject[]; @@ -606,13 +606,13 @@ export class MI2DebugSession extends DebugSession { if (!expanded) { this.sendErrorResponse(response, 15, `Could not expand variable`); } else { - if (typeof expanded == "string") { - if (expanded == "") { + if (typeof expanded === "string") { + if (expanded === "") { if (argsPart) argsPart = false; else return submit(); - } else if (expanded[0] != '"') { + } else if (expanded[0] !== '"') { strArr.push({ name: "[err]", value: expanded, @@ -714,7 +714,7 @@ export class MI2DebugSession extends DebugSession { protected override evaluateRequest(response: DebugProtocol.EvaluateResponse, args: DebugProtocol.EvaluateArguments): void { const [threadId, level] = this.frameIdToThreadAndLevel(args.frameId); - if (args.context == "watch" || args.context == "hover") { + if (args.context === "watch" || args.context === "hover") { this.miDebugger.evalExpression(args.expression, threadId, level).then((res) => { response.body = { variablesReference: 0, @@ -722,7 +722,7 @@ export class MI2DebugSession extends DebugSession { }; this.sendResponse(response); }, msg => { - if (args.context == "hover") { + if (args.context === "hover") { // suppress error for hover as the user may just play with the mouse this.sendResponse(response); } else { @@ -731,7 +731,7 @@ export class MI2DebugSession extends DebugSession { }); } else { this.miDebugger.sendUserInput(args.expression, threadId, level).then(output => { - if (typeof output == "undefined") + if (typeof output === "undefined") response.body = { result: "", variablesReference: 0 @@ -780,7 +780,7 @@ export class MI2DebugSession extends DebugSession { } function prettyStringArray(strings: any) { - if (typeof strings == "object") { + if (typeof strings === "object") { if (strings.length !== undefined) return strings.join(", "); else diff --git a/src/source_file_map.ts b/src/source_file_map.ts index b33424be..49ddcf39 100755 --- a/src/source_file_map.ts +++ b/src/source_file_map.ts @@ -38,7 +38,7 @@ export class SourceFileMap { // allowing non-native path types to be tested by overriding this method in // a subclass in the test harness. protected getNativePath(): PathKind { - if (process.platform == "win32") + if (process.platform === "win32") return PathWin32.getInstance(); else return PathPosix.getInstance(); diff --git a/src/test/unit/source_file_map.test.ts b/src/test/unit/source_file_map.test.ts index 450c2b00..162a984f 100755 --- a/src/test/unit/source_file_map.test.ts +++ b/src/test/unit/source_file_map.test.ts @@ -25,7 +25,7 @@ suite("Source File Map", () => { } } const fileMap: NativeSourceFileMap = new NativeSourceFileMap({}); - if (process.platform == "win32") + if (process.platform === "win32") assert.ok(fileMap.getNativePathTest() instanceof PathWin32); else assert.ok(fileMap.getNativePathTest() instanceof PathPosix);