Enforce JSON-serializable runtime function args and returns#7
Draft
V3RON wants to merge 2 commits into
Draft
Conversation
Collaborator
Author
|
There's a small catch: validation is now implemented on the JS side, but there's also a native way to run JS functions, and that path is not validated at the moment. One option is to duplicate the validation logic. Another option is to expose the validation function so it can be called from native code. Alternatively, we could drop validation on the native side, assuming people will mainly use the JS API. WDYT? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Runtime functions (
runtimeFunction,ThreadedRuntime.run,call, etc.) now require arguments and return values to be JSON-serializable.ThreadableFunction/RuntimeFunctionconstrain args toreadonly JsonValue[]and returns toJsonValue | void. Passing functions, class instances,undefinedin object fields, and other non-JSON values should fail at compile time. New helper types (ThreadableFunctionArgs,ThreadableFunctionAwaitedReturn) are exported from@react-native-runtimes/core.__DEV__only):assertJsonvalidates the args tuple before a cross-runtime call and the resolved return value before it is sent back (skipped when the handler returnsundefined). Production builds skip these checks; invalid values may still slip through viaJSON.stringifybehavior.Scope
This applies to runtime functions only. Headless tasks and other threaded APIs are unchanged.
Test plan
__DEV__, verify passing a function as an arg or return throws with a clear error messagevoid/undefinedreturns still work without triggering result validationMade with Cursor