Skip to content

Bind @JS functions and setters that return nothing through the Void overload - #81

Merged
tsapeta merged 1 commit into
mainfrom
tsapeta/void-host-functions
Oct 14, 2026
Merged

tsapeta merged 1 commit into
mainfrom
tsapeta/void-host-functions

Conversation

@tsapeta

@tsapeta tsapeta commented Oct 13, 2026 •

Copy link
Copy Markdown
Collaborator

A synchronous @JS function or setter that returns nothing now binds through the VoidFunctionClosure overload of setProperty(_:function:) from expo/expo#51498. That overload leaves the result as undefined without creating and writing a JavaScriptValue, which made these calls slower after JavaScriptValue became non-copyable.

The binding closure now declares -> Void and no longer ends with return .undefined(). The explicit -> Void is required: a closure body with several statements and no return is otherwise ambiguous between the two unowned-this overloads. Async functions don't change, because their body still resolves the promise with .undefined().

The generated code needs an expo-modules-core version that includes expo/expo#51498.

@JS function that returns nothing, no-op before after change
call from JavaScript 52.4 ns 42.1 ns -10.3 ns

Test Plan

… `Void` overload

The binding closure now declares `-> Void` and no longer returns `.undefined()`,
which selects the `Void` host function overload in `expo-modules-jsi`. That overload
leaves the result slot as `undefined` instead of building and writing a value.
@tsapeta
tsapeta marked this pull request as ready for review October 13, 2026 22:28
@tsapeta
tsapeta merged commit 5c86014 into main Oct 14, 2026
3 checks passed
@tsapeta
tsapeta deleted the tsapeta/void-host-functions branch October 14, 2026 14:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant