From 16c06cdb34b9828236bdc3ddc3f5765700c1d5d6 Mon Sep 17 00:00:00 2001 From: Marcelo Cabral Date: Mon, 27 Jan 2025 00:10:18 -0700 Subject: [PATCH] Simplified execute callback code and matched behavior with Roku --- src/brsTypes/components/RoSGNode.ts | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/brsTypes/components/RoSGNode.ts b/src/brsTypes/components/RoSGNode.ts index e3ff3926..a4b4efd5 100644 --- a/src/brsTypes/components/RoSGNode.ts +++ b/src/brsTypes/components/RoSGNode.ts @@ -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"; @@ -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)) {