rokucommunity / rokucommunity/brighterscript

Make callfuncs safer

Open
#1,019 5 comments 1 reaction 1 assignee View on GitHub

@josephjunker is already working on this.

Since Mar 8, 2024.

enhancement
Dominant language
TypeScript
Stars
208
Forks
68
Avg merge
8h 39m
Merged PRs (30d)
39

Description

Callfuncs with mismatched arguments will silently fail (not even a console warning!).

To mitigate this, we should automatically append _p = invalid parameters to all callfunc-exposed functions for all components. That way, the functions will be much more likely to execute and cause a runtime error instead (so you can actually see what went wrong).

Key points:

  • pad all interface functions with up to 10 parameters that all default to invalid
  • do not change existing parameters
  • reuse the same name for all these padded parameters so that we don't blow out the crashlogs with many local vars

For example,

<component name="TestComponent">
    <interface>
        <function name="doSomething" />
    </interface>
</component>
function doSomething()
end function

would transpile to

function doSomething(__unused = invalid, __unused = invalid, __unused = invalid, __unused = invalid, __unused = invalid, __unused = invalid, __unused = invalid, __unused = invalid, __unused = invalid, __unused = invalid)
end function

BrightScript doesn't care if you use the same parameter name multiple times, so we can reduce the list of unused variables by naming it __unused over and over again.

This implementation will cause the code to fail INSIDE the function if you try to use any of the parameters.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.