rokucommunity / rokucommunity/brighterscript
Make callfuncs safer
@josephjunker is already working on this.
Since Mar 8, 2024.
- 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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.