Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Describe isWorkletRuntime behavior on different runtimes #6692

Merged
merged 3 commits into from
Nov 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/react-native-reanimated/src/commonTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,10 +408,8 @@ export type WorkletFunction<
*
* ### Maintainer note
*
* This function works well on the JS thread performance-wise, since the JIT can
* inline it. However, on other threads it will not get optimized and we will
* get a function call overhead. We want to change it in the future, but it's
* not feasible at the moment.
* This function is supposed to be used only in the React Runtime. It always
* returns `false` in Worklet Runtimes.
*/
export function isWorkletFunction<
Args extends unknown[] = unknown[],
Expand All @@ -421,7 +419,9 @@ export function isWorkletFunction<
'worklet';
// Since host objects always return true for `in` operator, we have to use dot notation to check if the property exists.
// See https://github.com/facebook/hermes/blob/340726ef8cf666a7cce75bc60b02fa56b3e54560/lib/VM/JSObject.cpp#L1276.

return (
// `__workletHash` isn't extracted in Worklet Runtimes.
typeof value === 'function' &&
!!(value as unknown as Record<string, unknown>).__workletHash
);
Expand Down