sjbarag / brs

An interpreter for the BrightScript language that runs on non-Roku platforms.
MIT License
113 stars 43 forks source link

Inherited interface fields that reference a non-existent callback results in exception #448

Closed kirkyoder closed 4 years ago

kirkyoder commented 4 years ago

When a derived component object is created whose parent's interface defines observable fields (e.g. onChange), an exception will be thrown unless the given observable's callback exists on the derived component.

Example Setup

DerivedComponent.xml

<component name="DerivedComponent" extends="ParentComponent">
</component>

DerivedComponent.brs

sub init()
    ' some initialization logic here
end sub

' Note that no "exitPage" subroutine is defined

ParentComponent.xml

<component name="ParentComponent">
    <interface>
        <field id="exitPage" type="boolean" onChange="exitPage" alwaysNotify="true" />
    </interface>
</component>

Exception

Runtime error encountered in BRS implementation:

Error: exitPage was not found in scope
    at Interpreter.getCallableFunction (/Users/kirk.yoder/enlistments/cube-roku/node_modules/brs/lib/interpreter/index.js:210:15)
    at impl (/Users/kirk.yoder/enlistments/cube-roku/node_modules/brs/lib/brsTypes/components/RoSGNode.js:324:64)
    at interpreter.inSubEnv.subInterpreter (/Users/kirk.yoder/enlistments/cube-roku/node_modules/brs/lib/brsTypes/Callable.js:107:20)
    at Interpreter.inSubEnv (/Users/kirk.yoder/enlistments/cube-roku/node_modules/brs/lib/interpreter/index.js:138:20)
    at Callable.call (/Users/kirk.yoder/enlistments/cube-roku/node_modules/brs/lib/brsTypes/Callable.js:97:28)
    at addFields (/Users/kirk.yoder/enlistments/cube-roku/node_modules/brs/lib/brsTypes/components/RoSGNode.js:1140:30)
    at interpreter.inSubEnv.subInterpreter (/Users/kirk.yoder/enlistments/cube-roku/node_modules/brs/lib/brsTypes/components/RoSGNode.js:1097:17)
    at Interpreter.inSubEnv (/Users/kirk.yoder/enlistments/cube-roku/node_modules/brs/lib/interpreter/index.js:138:20)
    at Object.createNodeByType (/Users/kirk.yoder/enlistments/cube-roku/node_modules/brs/lib/brsTypes/components/RoSGNode.js:1095:25)
    at exports.BrsObjects.Map (/Users/kirk.yoder/enlistments/cube-roku/node_modules/brs/lib/brsTypes/components/BrsObjects.js:24:47)
kirkyoder commented 4 years ago

Evidently BrightScript doesn't care about this, but we're throwing an exception whenever we parse the observable fields and are unable to find the appropriate callable function: https://github.com/sjbarag/brs/blob/25437e2d3d070d270e2c3aef28d8d85d94d2ff0a/src/interpreter/index.ts#L255