Skip to content

Commit

Permalink
Code review recommendations
Browse files Browse the repository at this point in the history
  • Loading branch information
lvcabral committed May 1, 2024
1 parent 25532d8 commit 427175e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 23 deletions.
7 changes: 4 additions & 3 deletions src/brsTypes/components/RoSGNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
)
);
}
Expand Down
12 changes: 7 additions & 5 deletions src/extensions/GetStackTrace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
}
});
Expand All @@ -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}`
);
Expand Down
9 changes: 1 addition & 8 deletions src/interpreter/Environment.ts
Original file line number Diff line number Diff line change
@@ -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. */
Expand Down
14 changes: 7 additions & 7 deletions src/interpreter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -1220,8 +1220,8 @@ export class Interpreter implements Expr.Visitor<BrsType>, Stmt.Visitor<BrsType>
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 {
Expand Down Expand Up @@ -1750,19 +1750,19 @@ export class Interpreter implements Expr.Visitor<BrsType>, Stmt.Visitor<BrsType>
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([
{
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);
Expand Down

0 comments on commit 427175e

Please sign in to comment.