Skip to content

Commit

Permalink
Simplified execute callback code and matched behavior with Roku
Browse files Browse the repository at this point in the history
  • Loading branch information
lvcabral committed Jan 27, 2025
1 parent 2c6b8dc commit 16c06cd
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/brsTypes/components/RoSGNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { RoArray } from "./RoArray";
import { AAMember } from "./RoAssociativeArray";
import { ComponentDefinition, ComponentNode } from "../../scenegraph";
import { NodeFactory, BrsNodeType } from "../nodes/NodeFactory";
import { Environment } from "../../interpreter/Environment";
import { Environment, Scope } from "../../interpreter/Environment";
import { RoInvalid } from "./RoInvalid";
import type * as MockNodeModule from "../../extensions/MockNode";
import { BlockEnd } from "../../parser/Statement";
Expand Down Expand Up @@ -273,13 +273,21 @@ export class Field {
subInterpreter.environment.hostNode = hostNode;
subInterpreter.environment.setRootM(hostNode.m);

// Check whether the callback is expecting an event parameter.
try {
if (callable.getFirstSatisfiedSignature([event])) {
// m gets lost inside the subinterpreter block in callable.call ?
callable.call(subInterpreter, event);
// Check whether the callback is expecting an event parameter.
const satisfiedSignature = callable.getFirstSatisfiedSignature([event]);
if (satisfiedSignature) {
let { signature, impl } = satisfiedSignature;
subInterpreter.environment.define(
Scope.Function,
signature.args[0].name.text,
event
);
impl(subInterpreter, event);
} else {
callable.call(subInterpreter);
// Check whether the callback has a signature without parameters.
// Silently ignore if the callback has no signature that matches.
callable.getFirstSatisfiedSignature([])?.impl(subInterpreter);
}
} catch (err) {
if (!(err instanceof BlockEnd)) {
Expand Down

0 comments on commit 16c06cd

Please sign in to comment.