From aa3e7246a1eae8f490e294521079ed8b94759a55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20=C5=BBelawski?= Date: Tue, 12 Nov 2024 14:33:30 +0100 Subject: [PATCH 1/2] chore: Describe isWorkletRuntime behavior on different runtimes --- packages/react-native-reanimated/src/commonTypes.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/react-native-reanimated/src/commonTypes.ts b/packages/react-native-reanimated/src/commonTypes.ts index 924650b8903..8104c1fc3e4 100644 --- a/packages/react-native-reanimated/src/commonTypes.ts +++ b/packages/react-native-reanimated/src/commonTypes.ts @@ -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 `true` in Worklet Runtimes. */ export function isWorkletFunction< Args extends unknown[] = unknown[], @@ -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).__workletHash ); From 5d992c54f808a30178f02f08d4aab071133f191e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20=C5=BBelawski?= <40713406+tjzel@users.noreply.github.com> Date: Tue, 19 Nov 2024 11:40:05 +0100 Subject: [PATCH 2/2] Update packages/react-native-reanimated/src/commonTypes.ts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bartłomiej Błoniarz <56109050+bartlomiejbloniarz@users.noreply.github.com> --- packages/react-native-reanimated/src/commonTypes.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-native-reanimated/src/commonTypes.ts b/packages/react-native-reanimated/src/commonTypes.ts index 8104c1fc3e4..5b3f2fd1f08 100644 --- a/packages/react-native-reanimated/src/commonTypes.ts +++ b/packages/react-native-reanimated/src/commonTypes.ts @@ -409,7 +409,7 @@ export type WorkletFunction< * ### Maintainer note * * This function is supposed to be used only in the React Runtime. It always - * returns `true` in Worklet Runtimes. + * returns `false` in Worklet Runtimes. */ export function isWorkletFunction< Args extends unknown[] = unknown[],