From 427175e337420338ec5410c7068cdc95d607cfcf Mon Sep 17 00:00:00 2001 From: Marcelo Cabral Date: Wed, 1 May 2024 08:28:23 -0700 Subject: [PATCH] Code review recommendations --- src/brsTypes/components/RoSGNode.ts | 7 ++++--- src/extensions/GetStackTrace.ts | 12 +++++++----- src/interpreter/Environment.ts | 9 +-------- src/interpreter/index.ts | 14 +++++++------- 4 files changed, 19 insertions(+), 23 deletions(-) diff --git a/src/brsTypes/components/RoSGNode.ts b/src/brsTypes/components/RoSGNode.ts index 9846f634..19e40f64 100644 --- a/src/brsTypes/components/RoSGNode.ts +++ b/src/brsTypes/components/RoSGNode.ts @@ -654,8 +654,8 @@ export class RoSGNode extends BrsComponent implements BrsValue, BrsIterable { functionToCall.getLocation() ?? interpreter.location; interpreter.addToStack({ functionName: functionName.value, - functionLoc: funcLoc, - callLoc: funcLoc, + functionLocation: funcLoc, + callLocation: funcLoc, signature: satisfiedSignature.signature, }); try { @@ -673,7 +673,8 @@ export class RoSGNode extends BrsComponent implements BrsValue, BrsIterable { generateArgumentMismatchError( functionToCall, functionArgs, - interpreter.stack[interpreter.stack.length - 1].functionLoc + interpreter.stack[interpreter.stack.length - 1] + .functionLocation ) ); } diff --git a/src/extensions/GetStackTrace.ts b/src/extensions/GetStackTrace.ts index d12f9d9f..b53afd45 100644 --- a/src/extensions/GetStackTrace.ts +++ b/src/extensions/GetStackTrace.ts @@ -37,7 +37,7 @@ export const GetStackTrace = new Callable("GetStackTrace", { if (isBrsString(pattern)) { let regexFilter = new RegExp(pattern.value); stack = stack.filter( - (tracePoint) => !regexFilter.test(tracePoint.functionLoc.file) + (tracePoint) => !regexFilter.test(tracePoint.functionLocation.file) ); } }); @@ -48,15 +48,17 @@ export const GetStackTrace = new Callable("GetStackTrace", { return new RoArray( stack // Filter out any internal stack traces. - .filter((tracePoint) => !INTERNAL_REGEX_FILTER.test(tracePoint.functionLoc.file)) + .filter( + (tracePoint) => !INTERNAL_REGEX_FILTER.test(tracePoint.functionLocation.file) + ) // Remove any duplicate entries that appear next to each other in the stack. .filter((tracePoint, index, backTrace) => { if (index === 0) return true; - let prevLocation = backTrace[index - 1].functionLoc; - return !Location.equalTo(tracePoint.functionLoc, prevLocation); + let prevLocation = backTrace[index - 1].functionLocation; + return !Location.equalTo(tracePoint.functionLocation, prevLocation); }) .map((tracePoint) => { - const location = tracePoint.functionLoc; + const location = tracePoint.functionLocation; return new BrsString( `${location.file}:${location.start.line}:${location.start.column}` ); diff --git a/src/interpreter/Environment.ts b/src/interpreter/Environment.ts index 815fa7a4..84ac5b99 100644 --- a/src/interpreter/Environment.ts +++ b/src/interpreter/Environment.ts @@ -1,12 +1,5 @@ import { Identifier } from "../lexer"; -import { - BrsType, - RoAssociativeArray, - Int32, - BrsInvalid, - RoSGNode, - Callable, -} from "../brsTypes"; +import { BrsType, RoAssociativeArray, Int32, BrsInvalid, RoSGNode, Callable } from "../brsTypes"; import { ComponentDefinition } from "../componentprocessor"; /** The logical region from a particular variable or function that defines where it may be accessed from. */ diff --git a/src/interpreter/index.ts b/src/interpreter/index.ts index 3617c432..22ceaba0 100644 --- a/src/interpreter/index.ts +++ b/src/interpreter/index.ts @@ -91,8 +91,8 @@ Object.freeze(defaultExecutionOptions); /** The definition of a trace point to be added to the stack trace */ export interface TracePoint { functionName: string; - functionLoc: Location; - callLoc: Location; + functionLocation: Location; + callLocation: Location; signature?: Signature; } @@ -1220,8 +1220,8 @@ export class Interpreter implements Expr.Visitor, Stmt.Visitor subInterpreter.environment.setM(mPointer); this._stack.push({ functionName: functionName, - functionLoc: callee.getLocation() ?? this.location, - callLoc: expression.callee.location, + functionLocation: callee.getLocation() ?? this.location, + callLocation: expression.callee.location, signature: signature, }); try { @@ -1750,7 +1750,7 @@ export class Interpreter implements Expr.Visitor, Stmt.Visitor args += args !== "" ? "," : ""; args += `${arg.name.text} As ${ValueKind.toString(arg.type.kind)}`; }); - const funcSign = `${func.functionName}(${args}) As ${kind}`; + const funcSignature = `${func.functionName}(${args}) As ${kind}`; const line = loc.start.line; btArray.unshift( new RoAssociativeArray([ @@ -1758,11 +1758,11 @@ export class Interpreter implements Expr.Visitor, Stmt.Visitor name: new BrsString("filename"), value: new BrsString(loc?.file ?? "()"), }, - { name: new BrsString("function"), value: new BrsString(funcSign) }, + { name: new BrsString("function"), value: new BrsString(funcSignature) }, { name: new BrsString("line_number"), value: new Int32(line) }, ]) ); - loc = func.callLoc; + loc = func.callLocation; } } return new RoArray(btArray);