@depup/react-native-worklets 0.11.3-depup.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (457) hide show
  1. package/.worklets/dummy.md +1 -0
  2. package/Common/cpp/worklets/AnimationFrameQueue/AnimationFrameBatchinator.cpp +64 -0
  3. package/Common/cpp/worklets/AnimationFrameQueue/AnimationFrameBatchinator.h +38 -0
  4. package/Common/cpp/worklets/Compat/Holders.h +25 -0
  5. package/Common/cpp/worklets/Compat/StableApi.cpp +145 -0
  6. package/Common/cpp/worklets/Compat/StableApi.h +128 -0
  7. package/Common/cpp/worklets/NativeModules/JSIWorkletsModuleProxy.cpp +729 -0
  8. package/Common/cpp/worklets/NativeModules/JSIWorkletsModuleProxy.h +126 -0
  9. package/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.cpp +81 -0
  10. package/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.h +76 -0
  11. package/Common/cpp/worklets/Registries/EventHandlerRegistry.cpp +95 -0
  12. package/Common/cpp/worklets/Registries/EventHandlerRegistry.h +44 -0
  13. package/Common/cpp/worklets/Registries/WorkletRuntimeRegistry.cpp +10 -0
  14. package/Common/cpp/worklets/Registries/WorkletRuntimeRegistry.h +43 -0
  15. package/Common/cpp/worklets/RunLoop/AsyncQueue.h +14 -0
  16. package/Common/cpp/worklets/RunLoop/AsyncQueueImpl.cpp +69 -0
  17. package/Common/cpp/worklets/RunLoop/AsyncQueueImpl.h +48 -0
  18. package/Common/cpp/worklets/RunLoop/EventLoop.cpp +103 -0
  19. package/Common/cpp/worklets/RunLoop/EventLoop.h +52 -0
  20. package/Common/cpp/worklets/SharedItems/MemoryManager.cpp +60 -0
  21. package/Common/cpp/worklets/SharedItems/MemoryManager.h +29 -0
  22. package/Common/cpp/worklets/SharedItems/Serializable.cpp +373 -0
  23. package/Common/cpp/worklets/SharedItems/Serializable.h +413 -0
  24. package/Common/cpp/worklets/SharedItems/SerializableFactory.cpp +172 -0
  25. package/Common/cpp/worklets/SharedItems/SerializableFactory.h +85 -0
  26. package/Common/cpp/worklets/SharedItems/SerializableRemoteFunction.cpp +71 -0
  27. package/Common/cpp/worklets/SharedItems/SerializableRemoteFunction.h +75 -0
  28. package/Common/cpp/worklets/SharedItems/Shareable.cpp +84 -0
  29. package/Common/cpp/worklets/SharedItems/Shareable.h +43 -0
  30. package/Common/cpp/worklets/SharedItems/Synchronizable.cpp +59 -0
  31. package/Common/cpp/worklets/SharedItems/Synchronizable.h +57 -0
  32. package/Common/cpp/worklets/SharedItems/SynchronizableAccess.cpp +78 -0
  33. package/Common/cpp/worklets/SharedItems/SynchronizableAccess.h +45 -0
  34. package/Common/cpp/worklets/SharedItems/UnpackerLoader.h +78 -0
  35. package/Common/cpp/worklets/Tools/FeatureFlags.cpp +18 -0
  36. package/Common/cpp/worklets/Tools/FeatureFlags.h +44 -0
  37. package/Common/cpp/worklets/Tools/JSISerializer.cpp +312 -0
  38. package/Common/cpp/worklets/Tools/JSISerializer.h +42 -0
  39. package/Common/cpp/worklets/Tools/JSLogger.cpp +92 -0
  40. package/Common/cpp/worklets/Tools/JSLogger.h +48 -0
  41. package/Common/cpp/worklets/Tools/JSScheduler.cpp +21 -0
  42. package/Common/cpp/worklets/Tools/JSScheduler.h +35 -0
  43. package/Common/cpp/worklets/Tools/PlatformLogger.h +16 -0
  44. package/Common/cpp/worklets/Tools/RNRuntimeStatus.h +27 -0
  45. package/Common/cpp/worklets/Tools/ScriptBuffer.h +56 -0
  46. package/Common/cpp/worklets/Tools/SingleInstanceChecker.h +75 -0
  47. package/Common/cpp/worklets/Tools/ThreadSafeQueue.h +49 -0
  48. package/Common/cpp/worklets/Tools/UIScheduler.cpp +19 -0
  49. package/Common/cpp/worklets/Tools/UIScheduler.h +22 -0
  50. package/Common/cpp/worklets/Tools/VersionUtils.cpp +61 -0
  51. package/Common/cpp/worklets/Tools/VersionUtils.h +24 -0
  52. package/Common/cpp/worklets/Tools/WorkletEventHandler.cpp +34 -0
  53. package/Common/cpp/worklets/Tools/WorkletEventHandler.h +44 -0
  54. package/Common/cpp/worklets/Tools/WorkletsJSIUtils.cpp +30 -0
  55. package/Common/cpp/worklets/Tools/WorkletsJSIUtils.h +222 -0
  56. package/Common/cpp/worklets/Tools/WorkletsSystraceSection.h +116 -0
  57. package/Common/cpp/worklets/Tools/WorkletsVersion.cpp +46 -0
  58. package/Common/cpp/worklets/Tools/WorkletsVersion.h +18 -0
  59. package/Common/cpp/worklets/WorkletRuntime/BundleModeConfig.h +17 -0
  60. package/Common/cpp/worklets/WorkletRuntime/HermesProfiling.cpp +45 -0
  61. package/Common/cpp/worklets/WorkletRuntime/HermesProfiling.h +12 -0
  62. package/Common/cpp/worklets/WorkletRuntime/RNRuntimeWorkletDecorator.cpp +68 -0
  63. package/Common/cpp/worklets/WorkletRuntime/RNRuntimeWorkletDecorator.h +24 -0
  64. package/Common/cpp/worklets/WorkletRuntime/RuntimeBindings.h +59 -0
  65. package/Common/cpp/worklets/WorkletRuntime/RuntimeData.h +38 -0
  66. package/Common/cpp/worklets/WorkletRuntime/RuntimeHolder.h +19 -0
  67. package/Common/cpp/worklets/WorkletRuntime/RuntimeManager.cpp +122 -0
  68. package/Common/cpp/worklets/WorkletRuntime/RuntimeManager.h +75 -0
  69. package/Common/cpp/worklets/WorkletRuntime/ScriptLoader.h +116 -0
  70. package/Common/cpp/worklets/WorkletRuntime/UIRuntimeDecorator.cpp +14 -0
  71. package/Common/cpp/worklets/WorkletRuntime/UIRuntimeDecorator.h +15 -0
  72. package/Common/cpp/worklets/WorkletRuntime/WorkletHermesRuntime.cpp +58 -0
  73. package/Common/cpp/worklets/WorkletRuntime/WorkletHermesRuntime.h +100 -0
  74. package/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.cpp +327 -0
  75. package/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.h +256 -0
  76. package/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeCollector.h +36 -0
  77. package/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.cpp +320 -0
  78. package/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.h +36 -0
  79. package/LICENSE +20 -0
  80. package/README.md +43 -0
  81. package/RNWorklets.podspec +94 -0
  82. package/android/CMakeLists.txt +108 -0
  83. package/android/build.gradle.kts +369 -0
  84. package/android/fix-prefab.gradle.kts +56 -0
  85. package/android/generate-stub-pch.gradle.kts +84 -0
  86. package/android/gradle.properties +25 -0
  87. package/android/proguard-rules.pro +3 -0
  88. package/android/settings.gradle.kts +21 -0
  89. package/android/src/main/AndroidManifest.xml +2 -0
  90. package/android/src/main/cpp/WorkletsPCH.h +26 -0
  91. package/android/src/main/cpp/worklets/android/AndroidUIScheduler.cpp +66 -0
  92. package/android/src/main/cpp/worklets/android/AndroidUIScheduler.h +38 -0
  93. package/android/src/main/cpp/worklets/android/AnimationFrameCallback.h +30 -0
  94. package/android/src/main/cpp/worklets/android/JScriptBufferWrapper.cpp +66 -0
  95. package/android/src/main/cpp/worklets/android/JScriptBufferWrapper.h +48 -0
  96. package/android/src/main/cpp/worklets/android/JWorkletRuntimeWrapper.cpp +51 -0
  97. package/android/src/main/cpp/worklets/android/JWorkletRuntimeWrapper.h +43 -0
  98. package/android/src/main/cpp/worklets/android/PlatformLogger.cpp +31 -0
  99. package/android/src/main/cpp/worklets/android/WorkletsModule.cpp +203 -0
  100. package/android/src/main/cpp/worklets/android/WorkletsModule.h +75 -0
  101. package/android/src/main/cpp/worklets/android/WorkletsOnLoad.cpp +19 -0
  102. package/android/src/main/java/com/swmansion/worklets/AndroidUIScheduler.kt +56 -0
  103. package/android/src/main/java/com/swmansion/worklets/ScriptBufferWrapper.kt +103 -0
  104. package/android/src/main/java/com/swmansion/worklets/WorkletsPackage.kt +42 -0
  105. package/android/src/main/java/com/swmansion/worklets/runloop/AnimationFrameCallback.kt +14 -0
  106. package/android/src/main/java/com/swmansion/worklets/runloop/AnimationFrameQueue.kt +112 -0
  107. package/android/src/networking/com/swmansion/worklets/WorkletRuntimeWrapper.kt +27 -0
  108. package/android/src/networking/com/swmansion/worklets/WorkletsHeaderUtil.kt +30 -0
  109. package/android/src/networking/com/swmansion/worklets/WorkletsModule.kt +187 -0
  110. package/android/src/networking/com/swmansion/worklets/WorkletsNetworkEventUtil.kt +272 -0
  111. package/android/src/networking/com/swmansion/worklets/WorkletsNetworking.kt +1124 -0
  112. package/android/src/networking/com/swmansion/worklets/WorkletsOkHttpCallUtil.kt +40 -0
  113. package/android/src/networking/com/swmansion/worklets/WorkletsProgressListener.kt +13 -0
  114. package/android/src/networking/com/swmansion/worklets/WorkletsProgressRequestBody.kt +98 -0
  115. package/android/src/networking/com/swmansion/worklets/WorkletsProgressResponseBody.kt +60 -0
  116. package/android/src/networking/com/swmansion/worklets/WorkletsProgressiveStringDecoder.kt +87 -0
  117. package/android/src/networking/com/swmansion/worklets/WorkletsRequestBodyUtil.kt +181 -0
  118. package/android/src/no-networking/com/swmansion/worklets/WorkletsModule.kt +143 -0
  119. package/apple/worklets/apple/AnimationFrameQueue.h +15 -0
  120. package/apple/worklets/apple/AnimationFrameQueue.mm +145 -0
  121. package/apple/worklets/apple/AssertJavaScriptQueue.h +14 -0
  122. package/apple/worklets/apple/AssertTurboModuleManagerQueue.h +12 -0
  123. package/apple/worklets/apple/IOSUIScheduler.h +14 -0
  124. package/apple/worklets/apple/IOSUIScheduler.mm +29 -0
  125. package/apple/worklets/apple/Networking/WorkletsNetworking.h +25 -0
  126. package/apple/worklets/apple/Networking/WorkletsNetworking.mm +707 -0
  127. package/apple/worklets/apple/PlatformLogger.mm +31 -0
  128. package/apple/worklets/apple/SlowAnimations.h +8 -0
  129. package/apple/worklets/apple/SlowAnimations.mm +45 -0
  130. package/apple/worklets/apple/WorkletsDisplayLink.h +21 -0
  131. package/apple/worklets/apple/WorkletsModule.h +28 -0
  132. package/apple/worklets/apple/WorkletsModule.mm +177 -0
  133. package/bundleMode/index.d.ts +6 -0
  134. package/bundleMode/index.js +182 -0
  135. package/bundleMode/shims/reactNativeShim.js +21 -0
  136. package/bundleMode/shims/turboModuleRegistryShim.js +47 -0
  137. package/changes.json +58 -0
  138. package/compatibility.json +29 -0
  139. package/jest/pluginTestUtils.ts +16 -0
  140. package/jest/resolver.js +18 -0
  141. package/lib/module/WorkletsModule/NativeWorklets.js +4 -0
  142. package/lib/module/WorkletsModule/NativeWorklets.js.map +1 -0
  143. package/lib/module/WorkletsModule/NativeWorklets.native.js +199 -0
  144. package/lib/module/WorkletsModule/NativeWorklets.native.js.map +1 -0
  145. package/lib/module/WorkletsModule/workletsModuleProxy.js +4 -0
  146. package/lib/module/WorkletsModule/workletsModuleProxy.js.map +1 -0
  147. package/lib/module/bundleMode/metroOverrides.native.js +26 -0
  148. package/lib/module/bundleMode/metroOverrides.native.js.map +1 -0
  149. package/lib/module/bundleMode/network.native.js +44 -0
  150. package/lib/module/bundleMode/network.native.js.map +1 -0
  151. package/lib/module/debug/bundleMode.js +6 -0
  152. package/lib/module/debug/bundleMode.js.map +1 -0
  153. package/lib/module/debug/bundleMode.native.js +11 -0
  154. package/lib/module/debug/bundleMode.native.js.map +1 -0
  155. package/lib/module/debug/checkCppVersion.js +29 -0
  156. package/lib/module/debug/checkCppVersion.js.map +1 -0
  157. package/lib/module/debug/errors.native.js +67 -0
  158. package/lib/module/debug/errors.native.js.map +1 -0
  159. package/lib/module/debug/jsVersion.js +9 -0
  160. package/lib/module/debug/jsVersion.js.map +1 -0
  161. package/lib/module/debug/logger.js +15 -0
  162. package/lib/module/debug/logger.js.map +1 -0
  163. package/lib/module/debug/slowAnimations.js +7 -0
  164. package/lib/module/debug/slowAnimations.js.map +1 -0
  165. package/lib/module/debug/slowAnimations.native.js +17 -0
  166. package/lib/module/debug/slowAnimations.native.js.map +1 -0
  167. package/lib/module/deprecated.js +27 -0
  168. package/lib/module/deprecated.js.map +1 -0
  169. package/lib/module/featureFlags/featureFlags.js +12 -0
  170. package/lib/module/featureFlags/featureFlags.js.map +1 -0
  171. package/lib/module/featureFlags/featureFlags.native.js +51 -0
  172. package/lib/module/featureFlags/featureFlags.native.js.map +1 -0
  173. package/lib/module/featureFlags/staticFlags.json +6 -0
  174. package/lib/module/featureFlags/types.js +16 -0
  175. package/lib/module/featureFlags/types.js.map +1 -0
  176. package/lib/module/guardImplementation.native.js +17 -0
  177. package/lib/module/guardImplementation.native.js.map +1 -0
  178. package/lib/module/index.js +26 -0
  179. package/lib/module/index.js.map +1 -0
  180. package/lib/module/initializers/initializers.js +24 -0
  181. package/lib/module/initializers/initializers.js.map +1 -0
  182. package/lib/module/initializers/initializers.native.js +195 -0
  183. package/lib/module/initializers/initializers.native.js.map +1 -0
  184. package/lib/module/memory/bundleUnpacker.native.js +38 -0
  185. package/lib/module/memory/bundleUnpacker.native.js.map +1 -0
  186. package/lib/module/memory/customSerializableUnpacker.native.js +20 -0
  187. package/lib/module/memory/customSerializableUnpacker.native.js.map +1 -0
  188. package/lib/module/memory/isShareable.js +8 -0
  189. package/lib/module/memory/isShareable.js.map +1 -0
  190. package/lib/module/memory/isSynchronizable.js +8 -0
  191. package/lib/module/memory/isSynchronizable.js.map +1 -0
  192. package/lib/module/memory/remoteFunctionUnpacker.native.js +18 -0
  193. package/lib/module/memory/remoteFunctionUnpacker.native.js.map +1 -0
  194. package/lib/module/memory/serializable.js +18 -0
  195. package/lib/module/memory/serializable.js.map +1 -0
  196. package/lib/module/memory/serializable.native.js +619 -0
  197. package/lib/module/memory/serializable.native.js.map +1 -0
  198. package/lib/module/memory/serializableMappingCache.js +11 -0
  199. package/lib/module/memory/serializableMappingCache.js.map +1 -0
  200. package/lib/module/memory/serializableMappingCache.native.js +29 -0
  201. package/lib/module/memory/serializableMappingCache.native.js.map +1 -0
  202. package/lib/module/memory/shareable.js +18 -0
  203. package/lib/module/memory/shareable.js.map +1 -0
  204. package/lib/module/memory/shareable.native.js +42 -0
  205. package/lib/module/memory/shareable.native.js.map +1 -0
  206. package/lib/module/memory/shareableGuestUnpacker.native.js +105 -0
  207. package/lib/module/memory/shareableGuestUnpacker.native.js.map +1 -0
  208. package/lib/module/memory/shareableHostUnpacker.native.js +20 -0
  209. package/lib/module/memory/shareableHostUnpacker.native.js.map +1 -0
  210. package/lib/module/memory/synchronizable.js +6 -0
  211. package/lib/module/memory/synchronizable.js.map +1 -0
  212. package/lib/module/memory/synchronizable.native.js +9 -0
  213. package/lib/module/memory/synchronizable.native.js.map +1 -0
  214. package/lib/module/memory/synchronizableUnpacker.native.js +47 -0
  215. package/lib/module/memory/synchronizableUnpacker.native.js.map +1 -0
  216. package/lib/module/memory/types.js +12 -0
  217. package/lib/module/memory/types.js.map +1 -0
  218. package/lib/module/memory/valueUnpacker.native.js +52 -0
  219. package/lib/module/memory/valueUnpacker.native.js.map +1 -0
  220. package/lib/module/mock.js +85 -0
  221. package/lib/module/mock.js.map +1 -0
  222. package/lib/module/package.json +1 -0
  223. package/lib/module/platformChecker.js +4 -0
  224. package/lib/module/platformChecker.js.map +1 -0
  225. package/lib/module/platformChecker.native.js +4 -0
  226. package/lib/module/platformChecker.native.js.map +1 -0
  227. package/lib/module/privateGlobals.d.js +7 -0
  228. package/lib/module/privateGlobals.d.js.map +1 -0
  229. package/lib/module/runLoop/common/setImmediatePolyfill.js +15 -0
  230. package/lib/module/runLoop/common/setImmediatePolyfill.js.map +1 -0
  231. package/lib/module/runLoop/common/setIntervalPolyfill.js +26 -0
  232. package/lib/module/runLoop/common/setIntervalPolyfill.js.map +1 -0
  233. package/lib/module/runLoop/uiRuntime/mockedRequestAnimationFrame.js +10 -0
  234. package/lib/module/runLoop/uiRuntime/mockedRequestAnimationFrame.js.map +1 -0
  235. package/lib/module/runLoop/uiRuntime/requestAnimationFrame.js +71 -0
  236. package/lib/module/runLoop/uiRuntime/requestAnimationFrame.js.map +1 -0
  237. package/lib/module/runLoop/uiRuntime/setTimeoutPolyfill.js +32 -0
  238. package/lib/module/runLoop/uiRuntime/setTimeoutPolyfill.js.map +1 -0
  239. package/lib/module/runLoop/workletRuntime/index.js +19 -0
  240. package/lib/module/runLoop/workletRuntime/index.js.map +1 -0
  241. package/lib/module/runLoop/workletRuntime/queueMicrotask.js +11 -0
  242. package/lib/module/runLoop/workletRuntime/queueMicrotask.js.map +1 -0
  243. package/lib/module/runLoop/workletRuntime/requestAnimationFramePolyfill.js +48 -0
  244. package/lib/module/runLoop/workletRuntime/requestAnimationFramePolyfill.js.map +1 -0
  245. package/lib/module/runLoop/workletRuntime/setTimeout.js +28 -0
  246. package/lib/module/runLoop/workletRuntime/setTimeout.js.map +1 -0
  247. package/lib/module/runLoop/workletRuntime/taskQueue.js +37 -0
  248. package/lib/module/runLoop/workletRuntime/taskQueue.js.map +1 -0
  249. package/lib/module/runtimeKind.js +92 -0
  250. package/lib/module/runtimeKind.js.map +1 -0
  251. package/lib/module/runtimes.js +36 -0
  252. package/lib/module/runtimes.js.map +1 -0
  253. package/lib/module/runtimes.native.js +379 -0
  254. package/lib/module/runtimes.native.js.map +1 -0
  255. package/lib/module/specs/NativeWorkletsModule.js +5 -0
  256. package/lib/module/specs/NativeWorkletsModule.js.map +1 -0
  257. package/lib/module/specs/index.js +10 -0
  258. package/lib/module/specs/index.js.map +1 -0
  259. package/lib/module/threads.js +60 -0
  260. package/lib/module/threads.js.map +1 -0
  261. package/lib/module/threads.native.js +295 -0
  262. package/lib/module/threads.native.js.map +1 -0
  263. package/lib/module/types.js +5 -0
  264. package/lib/module/types.js.map +1 -0
  265. package/lib/module/workletFunction.js +36 -0
  266. package/lib/module/workletFunction.js.map +1 -0
  267. package/lib/typescript/WorkletsModule/NativeWorklets.d.ts +3 -0
  268. package/lib/typescript/WorkletsModule/NativeWorklets.d.ts.map +1 -0
  269. package/lib/typescript/WorkletsModule/NativeWorklets.native.d.ts +3 -0
  270. package/lib/typescript/WorkletsModule/NativeWorklets.native.d.ts.map +1 -0
  271. package/lib/typescript/WorkletsModule/workletsModuleProxy.d.ts +59 -0
  272. package/lib/typescript/WorkletsModule/workletsModuleProxy.d.ts.map +1 -0
  273. package/lib/typescript/bundleMode/metroOverrides.native.d.ts +9 -0
  274. package/lib/typescript/bundleMode/metroOverrides.native.d.ts.map +1 -0
  275. package/lib/typescript/bundleMode/network.native.d.ts +7 -0
  276. package/lib/typescript/bundleMode/network.native.d.ts.map +1 -0
  277. package/lib/typescript/debug/bundleMode.d.ts +2 -0
  278. package/lib/typescript/debug/bundleMode.d.ts.map +1 -0
  279. package/lib/typescript/debug/bundleMode.native.d.ts +2 -0
  280. package/lib/typescript/debug/bundleMode.native.d.ts.map +1 -0
  281. package/lib/typescript/debug/checkCppVersion.d.ts +3 -0
  282. package/lib/typescript/debug/checkCppVersion.d.ts.map +1 -0
  283. package/lib/typescript/debug/errors.native.d.ts +13 -0
  284. package/lib/typescript/debug/errors.native.d.ts.map +1 -0
  285. package/lib/typescript/debug/jsVersion.d.ts +7 -0
  286. package/lib/typescript/debug/jsVersion.d.ts.map +1 -0
  287. package/lib/typescript/debug/logger.d.ts +5 -0
  288. package/lib/typescript/debug/logger.d.ts.map +1 -0
  289. package/lib/typescript/debug/slowAnimations.d.ts +2 -0
  290. package/lib/typescript/debug/slowAnimations.d.ts.map +1 -0
  291. package/lib/typescript/debug/slowAnimations.native.d.ts +11 -0
  292. package/lib/typescript/debug/slowAnimations.native.d.ts.map +1 -0
  293. package/lib/typescript/deprecated.d.ts +19 -0
  294. package/lib/typescript/deprecated.d.ts.map +1 -0
  295. package/lib/typescript/featureFlags/featureFlags.d.ts +5 -0
  296. package/lib/typescript/featureFlags/featureFlags.d.ts.map +1 -0
  297. package/lib/typescript/featureFlags/featureFlags.native.d.ts +6 -0
  298. package/lib/typescript/featureFlags/featureFlags.native.d.ts.map +1 -0
  299. package/lib/typescript/featureFlags/types.d.ts +23 -0
  300. package/lib/typescript/featureFlags/types.d.ts.map +1 -0
  301. package/lib/typescript/guardImplementation.native.d.ts +3 -0
  302. package/lib/typescript/guardImplementation.native.d.ts.map +1 -0
  303. package/lib/typescript/index.d.ts +19 -0
  304. package/lib/typescript/index.d.ts.map +1 -0
  305. package/lib/typescript/initializers/initializers.d.ts +2 -0
  306. package/lib/typescript/initializers/initializers.d.ts.map +1 -0
  307. package/lib/typescript/initializers/initializers.native.d.ts +19 -0
  308. package/lib/typescript/initializers/initializers.native.d.ts.map +1 -0
  309. package/lib/typescript/memory/bundleUnpacker.native.d.ts +7 -0
  310. package/lib/typescript/memory/bundleUnpacker.native.d.ts.map +1 -0
  311. package/lib/typescript/memory/customSerializableUnpacker.native.d.ts +3 -0
  312. package/lib/typescript/memory/customSerializableUnpacker.native.d.ts.map +1 -0
  313. package/lib/typescript/memory/isShareable.d.ts +3 -0
  314. package/lib/typescript/memory/isShareable.d.ts.map +1 -0
  315. package/lib/typescript/memory/isSynchronizable.d.ts +3 -0
  316. package/lib/typescript/memory/isSynchronizable.d.ts.map +1 -0
  317. package/lib/typescript/memory/remoteFunctionUnpacker.native.d.ts +3 -0
  318. package/lib/typescript/memory/remoteFunctionUnpacker.native.d.ts.map +1 -0
  319. package/lib/typescript/memory/serializable.d.ts +7 -0
  320. package/lib/typescript/memory/serializable.d.ts.map +1 -0
  321. package/lib/typescript/memory/serializable.native.d.ts +37 -0
  322. package/lib/typescript/memory/serializable.native.d.ts.map +1 -0
  323. package/lib/typescript/memory/serializableMappingCache.d.ts +6 -0
  324. package/lib/typescript/memory/serializableMappingCache.d.ts.map +1 -0
  325. package/lib/typescript/memory/serializableMappingCache.native.d.ts +13 -0
  326. package/lib/typescript/memory/serializableMappingCache.native.d.ts.map +1 -0
  327. package/lib/typescript/memory/shareable.d.ts +15 -0
  328. package/lib/typescript/memory/shareable.d.ts.map +1 -0
  329. package/lib/typescript/memory/shareable.native.d.ts +15 -0
  330. package/lib/typescript/memory/shareable.native.d.ts.map +1 -0
  331. package/lib/typescript/memory/shareableGuestUnpacker.native.d.ts +4 -0
  332. package/lib/typescript/memory/shareableGuestUnpacker.native.d.ts.map +1 -0
  333. package/lib/typescript/memory/shareableHostUnpacker.native.d.ts +4 -0
  334. package/lib/typescript/memory/shareableHostUnpacker.native.d.ts.map +1 -0
  335. package/lib/typescript/memory/synchronizable.d.ts +3 -0
  336. package/lib/typescript/memory/synchronizable.d.ts.map +1 -0
  337. package/lib/typescript/memory/synchronizable.native.d.ts +3 -0
  338. package/lib/typescript/memory/synchronizable.native.d.ts.map +1 -0
  339. package/lib/typescript/memory/synchronizableUnpacker.native.d.ts +4 -0
  340. package/lib/typescript/memory/synchronizableUnpacker.native.d.ts.map +1 -0
  341. package/lib/typescript/memory/types.d.ts +136 -0
  342. package/lib/typescript/memory/types.d.ts.map +1 -0
  343. package/lib/typescript/memory/valueUnpacker.native.d.ts +7 -0
  344. package/lib/typescript/memory/valueUnpacker.native.d.ts.map +1 -0
  345. package/lib/typescript/mock.d.ts +2 -0
  346. package/lib/typescript/mock.d.ts.map +1 -0
  347. package/lib/typescript/package.json +1 -0
  348. package/lib/typescript/platformChecker.d.ts +2 -0
  349. package/lib/typescript/platformChecker.d.ts.map +1 -0
  350. package/lib/typescript/platformChecker.native.d.ts +2 -0
  351. package/lib/typescript/platformChecker.native.d.ts.map +1 -0
  352. package/lib/typescript/runLoop/common/setImmediatePolyfill.d.ts +2 -0
  353. package/lib/typescript/runLoop/common/setImmediatePolyfill.d.ts.map +1 -0
  354. package/lib/typescript/runLoop/common/setIntervalPolyfill.d.ts +2 -0
  355. package/lib/typescript/runLoop/common/setIntervalPolyfill.d.ts.map +1 -0
  356. package/lib/typescript/runLoop/uiRuntime/mockedRequestAnimationFrame.d.ts +6 -0
  357. package/lib/typescript/runLoop/uiRuntime/mockedRequestAnimationFrame.d.ts.map +1 -0
  358. package/lib/typescript/runLoop/uiRuntime/requestAnimationFrame.d.ts +2 -0
  359. package/lib/typescript/runLoop/uiRuntime/requestAnimationFrame.d.ts.map +1 -0
  360. package/lib/typescript/runLoop/uiRuntime/setTimeoutPolyfill.d.ts +2 -0
  361. package/lib/typescript/runLoop/uiRuntime/setTimeoutPolyfill.d.ts.map +1 -0
  362. package/lib/typescript/runLoop/workletRuntime/index.d.ts +2 -0
  363. package/lib/typescript/runLoop/workletRuntime/index.d.ts.map +1 -0
  364. package/lib/typescript/runLoop/workletRuntime/queueMicrotask.d.ts +2 -0
  365. package/lib/typescript/runLoop/workletRuntime/queueMicrotask.d.ts.map +1 -0
  366. package/lib/typescript/runLoop/workletRuntime/requestAnimationFramePolyfill.d.ts +2 -0
  367. package/lib/typescript/runLoop/workletRuntime/requestAnimationFramePolyfill.d.ts.map +1 -0
  368. package/lib/typescript/runLoop/workletRuntime/setTimeout.d.ts +2 -0
  369. package/lib/typescript/runLoop/workletRuntime/setTimeout.d.ts.map +1 -0
  370. package/lib/typescript/runLoop/workletRuntime/taskQueue.d.ts +10 -0
  371. package/lib/typescript/runLoop/workletRuntime/taskQueue.d.ts.map +1 -0
  372. package/lib/typescript/runtimeKind.d.ts +56 -0
  373. package/lib/typescript/runtimeKind.d.ts.map +1 -0
  374. package/lib/typescript/runtimes.d.ts +15 -0
  375. package/lib/typescript/runtimes.d.ts.map +1 -0
  376. package/lib/typescript/runtimes.native.d.ts +155 -0
  377. package/lib/typescript/runtimes.native.d.ts.map +1 -0
  378. package/lib/typescript/specs/NativeWorkletsModule.d.ts +9 -0
  379. package/lib/typescript/specs/NativeWorkletsModule.d.ts.map +1 -0
  380. package/lib/typescript/specs/index.d.ts +3 -0
  381. package/lib/typescript/specs/index.d.ts.map +1 -0
  382. package/lib/typescript/threads.d.ts +8 -0
  383. package/lib/typescript/threads.d.ts.map +1 -0
  384. package/lib/typescript/threads.native.d.ts +125 -0
  385. package/lib/typescript/threads.native.d.ts.map +1 -0
  386. package/lib/typescript/types.d.ts +136 -0
  387. package/lib/typescript/types.d.ts.map +1 -0
  388. package/lib/typescript/workletFunction.d.ts +26 -0
  389. package/lib/typescript/workletFunction.d.ts.map +1 -0
  390. package/package.json +220 -0
  391. package/plugin/index.d.ts +168 -0
  392. package/plugin/index.js +2188 -0
  393. package/scripts/validate-react-native-version.js +43 -0
  394. package/scripts/worklets_utils.rb +94 -0
  395. package/src/WorkletsModule/NativeWorklets.native.ts +461 -0
  396. package/src/WorkletsModule/NativeWorklets.ts +5 -0
  397. package/src/WorkletsModule/workletsModuleProxy.ts +247 -0
  398. package/src/bundleMode/metroOverrides.native.ts +33 -0
  399. package/src/bundleMode/network.native.ts +63 -0
  400. package/src/debug/bundleMode.native.ts +18 -0
  401. package/src/debug/bundleMode.ts +5 -0
  402. package/src/debug/checkCppVersion.ts +34 -0
  403. package/src/debug/errors.native.ts +74 -0
  404. package/src/debug/jsVersion.ts +8 -0
  405. package/src/debug/logger.ts +16 -0
  406. package/src/debug/slowAnimations.native.ts +15 -0
  407. package/src/debug/slowAnimations.ts +6 -0
  408. package/src/deprecated.ts +38 -0
  409. package/src/featureFlags/featureFlags.native.ts +70 -0
  410. package/src/featureFlags/featureFlags.ts +20 -0
  411. package/src/featureFlags/staticFlags.json +6 -0
  412. package/src/featureFlags/types.ts +32 -0
  413. package/src/guardImplementation.native.ts +26 -0
  414. package/src/index.ts +95 -0
  415. package/src/initializers/initializers.native.ts +218 -0
  416. package/src/initializers/initializers.ts +24 -0
  417. package/src/memory/bundleUnpacker.native.ts +59 -0
  418. package/src/memory/customSerializableUnpacker.native.ts +30 -0
  419. package/src/memory/isShareable.ts +16 -0
  420. package/src/memory/isSynchronizable.ts +14 -0
  421. package/src/memory/remoteFunctionUnpacker.native.ts +27 -0
  422. package/src/memory/serializable.native.ts +889 -0
  423. package/src/memory/serializable.ts +36 -0
  424. package/src/memory/serializableMappingCache.native.ts +37 -0
  425. package/src/memory/serializableMappingCache.ts +12 -0
  426. package/src/memory/shareable.native.ts +68 -0
  427. package/src/memory/shareable.ts +27 -0
  428. package/src/memory/shareableGuestUnpacker.native.ts +168 -0
  429. package/src/memory/shareableHostUnpacker.native.ts +31 -0
  430. package/src/memory/synchronizable.native.ts +17 -0
  431. package/src/memory/synchronizable.ts +9 -0
  432. package/src/memory/synchronizableUnpacker.native.ts +65 -0
  433. package/src/memory/types.ts +191 -0
  434. package/src/memory/valueUnpacker.native.ts +79 -0
  435. package/src/mock.ts +111 -0
  436. package/src/platformChecker.native.ts +3 -0
  437. package/src/platformChecker.ts +4 -0
  438. package/src/privateGlobals.d.ts +127 -0
  439. package/src/runLoop/common/setImmediatePolyfill.ts +20 -0
  440. package/src/runLoop/common/setIntervalPolyfill.ts +38 -0
  441. package/src/runLoop/uiRuntime/mockedRequestAnimationFrame.ts +11 -0
  442. package/src/runLoop/uiRuntime/requestAnimationFrame.ts +87 -0
  443. package/src/runLoop/uiRuntime/setTimeoutPolyfill.ts +40 -0
  444. package/src/runLoop/workletRuntime/index.ts +18 -0
  445. package/src/runLoop/workletRuntime/queueMicrotask.ts +13 -0
  446. package/src/runLoop/workletRuntime/requestAnimationFramePolyfill.ts +61 -0
  447. package/src/runLoop/workletRuntime/setTimeout.ts +37 -0
  448. package/src/runLoop/workletRuntime/taskQueue.ts +44 -0
  449. package/src/runtimeKind.ts +85 -0
  450. package/src/runtimes.native.ts +572 -0
  451. package/src/runtimes.ts +107 -0
  452. package/src/specs/NativeWorkletsModule.ts +11 -0
  453. package/src/specs/index.ts +13 -0
  454. package/src/threads.native.ts +408 -0
  455. package/src/threads.ts +110 -0
  456. package/src/types.ts +164 -0
  457. package/src/workletFunction.ts +41 -0
@@ -0,0 +1,729 @@
1
+ #include <jsi/jsi.h>
2
+ #include <react/debug/react_native_assert.h>
3
+ #include <worklets/Compat/Holders.h>
4
+ #include <worklets/Compat/StableApi.h>
5
+ #include <worklets/NativeModules/JSIWorkletsModuleProxy.h>
6
+ #include <worklets/SharedItems/Serializable.h>
7
+ #include <worklets/SharedItems/SerializableFactory.h>
8
+ #include <worklets/SharedItems/SerializableRemoteFunction.h>
9
+ #include <worklets/SharedItems/Shareable.h>
10
+ #include <worklets/SharedItems/Synchronizable.h>
11
+ #include <worklets/Tools/FeatureFlags.h>
12
+ #include <worklets/Tools/JSLogger.h>
13
+ #include <worklets/Tools/WorkletsJSIUtils.h>
14
+ #include <worklets/WorkletRuntime/BundleModeConfig.h>
15
+ #include <worklets/WorkletRuntime/RuntimeData.h>
16
+
17
+ #ifndef NDEBUG
18
+ #include <algorithm>
19
+ #endif // NDEBUG
20
+ #include <memory>
21
+ #include <optional>
22
+ #include <stdexcept>
23
+ #include <string>
24
+ #include <utility>
25
+ #include <vector>
26
+
27
+ using namespace facebook;
28
+
29
+ namespace worklets {
30
+
31
+ namespace {
32
+
33
+ inline void scheduleOnUI(
34
+ const std::weak_ptr<WorkletRuntime> &weakUIWorkletRuntime,
35
+ jsi::Runtime &rt,
36
+ const jsi::Value &serializableArrayOfWorkletsValue
37
+ #ifndef NDEBUG
38
+ ,
39
+ const jsi::Value &scheduleStacksValue
40
+ #endif // NDEBUG
41
+ ) {
42
+ auto serializable = extractSerializableOrThrow(
43
+ rt, serializableArrayOfWorkletsValue, "[Worklets] scheduleOnUI expects a serializable array of worklets.");
44
+ auto serializableArrayOfWorklets = std::static_pointer_cast<SerializableArray>(serializable);
45
+
46
+ const auto &workletsList = serializableArrayOfWorklets->getList();
47
+ std::vector<std::shared_ptr<SerializableWorklet>> worklets;
48
+ worklets.reserve(workletsList.size());
49
+ for (const auto &item : workletsList) {
50
+ worklets.push_back(std::static_pointer_cast<SerializableWorklet>(item));
51
+ }
52
+
53
+ #ifndef NDEBUG
54
+ std::vector<std::optional<std::string>> scheduleStacks(worklets.size());
55
+ if (scheduleStacksValue.isObject()) {
56
+ auto stacksObject = scheduleStacksValue.asObject(rt);
57
+ if (stacksObject.isArray(rt)) {
58
+ auto stacksArray = stacksObject.asArray(rt);
59
+ auto count = std::min<size_t>(stacksArray.size(rt), scheduleStacks.size());
60
+ for (size_t i = 0; i < count; i++) {
61
+ auto stackValue = stacksArray.getValueAtIndex(rt, i);
62
+ if (stackValue.isString()) {
63
+ scheduleStacks[i] = stackValue.asString(rt).utf8(rt);
64
+ }
65
+ }
66
+ }
67
+ }
68
+ #endif // NDEBUG
69
+
70
+ auto uiWorkletRuntime = weakUIWorkletRuntime.lock();
71
+ if (!uiWorkletRuntime) {
72
+ return;
73
+ }
74
+ uiWorkletRuntime->schedule([worklets = std::move(worklets),
75
+ #ifndef NDEBUG
76
+ scheduleStacks = std::move(scheduleStacks),
77
+ #endif // NDEBUG
78
+ weakUIWorkletRuntime]() {
79
+ // This callback can outlive the WorkletsModuleProxy object during the
80
+ // invalidation of React Native. This happens when WorkletsModuleProxy
81
+ // destructor is called on the JS thread and the UI thread is
82
+ // executing callbacks from the `scheduleOnUI` queue. Therefore, we
83
+ // need to make sure it's still alive before we try to access it.
84
+ auto uiWorkletRuntime = weakUIWorkletRuntime.lock();
85
+ if (!uiWorkletRuntime) {
86
+ return;
87
+ }
88
+
89
+ // JSI's scope defined here allows for JSI-objects to be cleared up
90
+ // after each runtime loop. Within these loops we typically create
91
+ // some temporary JSI objects and hence it allows for such objects to
92
+ // be garbage collected much sooner.
93
+ const auto scope = jsi::Scope(uiWorkletRuntime->getJSIRuntime());
94
+
95
+ for (size_t i = 0; i < worklets.size(); i++) {
96
+ #ifndef NDEBUG
97
+ uiWorkletRuntime->runSyncWithStack(worklets[i], scheduleStacks[i]);
98
+ #else
99
+ uiWorkletRuntime->runSync(worklets[i]);
100
+ #endif // NDEBUG
101
+ }
102
+
103
+ uiWorkletRuntime->callMicrotasks();
104
+ });
105
+ }
106
+
107
+ #ifndef NDEBUG
108
+ inline jsi::Value runOnUISync(
109
+ const std::weak_ptr<WorkletRuntime> &weakUIWorkletRuntime,
110
+ jsi::Runtime &rt,
111
+ const jsi::Value &worklet,
112
+ const std::optional<std::string> &scheduleStack) {
113
+ if (auto uiWorkletRuntime = weakUIWorkletRuntime.lock()) {
114
+ auto serializableWorklet = extractSerializableOrThrow<SerializableWorklet>(
115
+ rt, worklet, "[Worklets] Only worklets can be executed on UI runtime.");
116
+ auto serializedResult = uiWorkletRuntime->runSyncSerializedWithStack(serializableWorklet, scheduleStack);
117
+ return serializedResult->toJSValue(rt);
118
+ }
119
+ return jsi::Value::undefined();
120
+ }
121
+ #else
122
+ inline jsi::Value
123
+ runOnUISync(const std::weak_ptr<WorkletRuntime> &weakUIWorkletRuntime, jsi::Runtime &rt, const jsi::Value &worklet) {
124
+ if (auto uiWorkletRuntime = weakUIWorkletRuntime.lock()) {
125
+ auto serializableWorklet = extractSerializableOrThrow<SerializableWorklet>(
126
+ rt, worklet, "[Worklets] Only worklets can be executed on UI runtime.");
127
+ auto serializedResult = uiWorkletRuntime->runSyncSerialized(serializableWorklet);
128
+ return serializedResult->toJSValue(rt);
129
+ }
130
+ return jsi::Value::undefined();
131
+ }
132
+ #endif // NDEBUG
133
+
134
+ #ifndef NDEBUG
135
+ jsi::Value runOnRuntimeSync(
136
+ jsi::Runtime &rt,
137
+ const jsi::Value &workletRuntimeValue,
138
+ const jsi::Value &serializableWorkletValue,
139
+ const std::optional<std::string> &scheduleStack) {
140
+ auto workletRuntime = workletRuntimeValue.getObject(rt).getHostObject<WorkletRuntime>(rt);
141
+ auto worklet = extractSerializableOrThrow<SerializableWorklet>(
142
+ rt, serializableWorkletValue, "[Worklets] Only worklets can be executed on a worklet runtime.");
143
+ return workletRuntime->runSyncSerializedWithStack(worklet, scheduleStack)->toJSValue(rt);
144
+ }
145
+ #else
146
+ jsi::Value
147
+ runOnRuntimeSync(jsi::Runtime &rt, const jsi::Value &workletRuntimeValue, const jsi::Value &serializableWorkletValue) {
148
+ auto workletRuntime = workletRuntimeValue.getObject(rt).getHostObject<WorkletRuntime>(rt);
149
+ auto worklet = extractSerializableOrThrow<SerializableWorklet>(
150
+ rt, serializableWorkletValue, "[Worklets] Only worklets can be executed on a worklet runtime.");
151
+ return workletRuntime->runSyncSerialized(worklet)->toJSValue(rt);
152
+ }
153
+ #endif // NDEBUG
154
+
155
+ inline jsi::Value createWorkletRuntime(
156
+ jsi::Runtime &originRuntime,
157
+ const std::shared_ptr<RuntimeManager> &runtimeManager,
158
+ const std::shared_ptr<const JSIWorkletsModuleProxy> &sourceProxy,
159
+ const std::string &name,
160
+ std::shared_ptr<SerializableWorklet> &initializer,
161
+ const std::shared_ptr<AsyncQueue> &queue,
162
+ bool enableEventLoop) {
163
+ const auto workletRuntime =
164
+ runtimeManager->createWorkletRuntime(sourceProxy, name, initializer, queue, enableEventLoop);
165
+ return jsi::Object::createFromHostObject(originRuntime, workletRuntime);
166
+ }
167
+
168
+ inline jsi::Value reportFatalErrorOnJS(
169
+ const std::shared_ptr<JSScheduler> &jsScheduler,
170
+ const std::string &message,
171
+ const std::string &stack,
172
+ const std::string &name) {
173
+ JSLogger::reportFatalErrorOnJS(jsScheduler, JSErrorData{.message = message, .stack = stack, .name = name});
174
+ return jsi::Value::undefined();
175
+ }
176
+
177
+ inline std::shared_ptr<AsyncQueue> extractAsyncQueue(jsi::Runtime &rt, const jsi::Value &value) {
178
+ if (!value.isObject()) {
179
+ return nullptr;
180
+ }
181
+ const auto object = value.asObject(rt);
182
+
183
+ if (!object.hasNativeState(rt)) {
184
+ return nullptr;
185
+ }
186
+
187
+ const auto &nativeState = object.getNativeState(rt);
188
+ auto asyncQueue = std::dynamic_pointer_cast<AsyncQueue>(nativeState);
189
+
190
+ return asyncQueue;
191
+ }
192
+
193
+ inline void registerCustomSerializable(
194
+ const std::shared_ptr<RuntimeManager> &runtimeManager,
195
+ const std::shared_ptr<MemoryManager> &memoryManager,
196
+ const std::shared_ptr<SerializableWorklet> &determine,
197
+ const std::shared_ptr<SerializableWorklet> &pack,
198
+ const std::shared_ptr<SerializableWorklet> &unpack,
199
+ const int typeId) {
200
+ const SerializationData data{.determine = determine, .pack = pack, .unpack = unpack, .typeId = typeId};
201
+ // Prevent registering new worklet runtimes while we are updating existing ones to prevent inconsistencies.
202
+ runtimeManager->withRegistrationPaused([&] {
203
+ memoryManager->registerCustomSerializable(data);
204
+ for (const auto &runtime : runtimeManager->getAllRuntimes()) {
205
+ memoryManager->loadCustomSerializable(runtime, data);
206
+ }
207
+ });
208
+ }
209
+
210
+ } // namespace
211
+
212
+ jsi::Object JSIWorkletsModuleProxy::toOptimizedObject(jsi::Runtime &rt) const {
213
+ auto obj = jsi::Object(rt);
214
+ using jsi_utils::at;
215
+
216
+ jsi_utils::addMethod<18>(
217
+ rt,
218
+ obj,
219
+ "loadUnpackersWithCode",
220
+ [unpackerLoader = unpackerLoader_](jsi::Runtime &rt, const jsi::Value &, const jsi::Value(&args)[18]) {
221
+ const auto str = [&](size_t i) {
222
+ return args[i].getString(rt).utf8(rt);
223
+ };
224
+ unpackerLoader->loadCodeUnpackers({
225
+ CodeUnpacker{.code = str(0), .location = str(1), .sourceMap = str(2)},
226
+ CodeUnpacker{.code = str(3), .location = str(4), .sourceMap = str(5)},
227
+ CodeUnpacker{.code = str(6), .location = str(7), .sourceMap = str(8)},
228
+ CodeUnpacker{.code = str(9), .location = str(10), .sourceMap = str(11)},
229
+ CodeUnpacker{.code = str(12), .location = str(13), .sourceMap = str(14)},
230
+ CodeUnpacker{.code = str(15), .location = str(16), .sourceMap = str(17)},
231
+ });
232
+ });
233
+
234
+ jsi_utils::addMethod<6>(
235
+ rt,
236
+ obj,
237
+ "loadUnpackersWithBytecode",
238
+ [unpackerLoader = unpackerLoader_](jsi::Runtime &rt, const jsi::Value &, const jsi::Value(&args)[6]) {
239
+ const auto bytecode = [&](size_t i) {
240
+ const auto buffer = args[i].getObject(rt).getArrayBuffer(rt);
241
+ return std::vector<uint8_t>(buffer.data(rt), buffer.data(rt) + buffer.size(rt));
242
+ };
243
+ unpackerLoader->loadBytecodeUnpackers({
244
+ BytecodeUnpacker{.bytecode = bytecode(0)},
245
+ BytecodeUnpacker{.bytecode = bytecode(1)},
246
+ BytecodeUnpacker{.bytecode = bytecode(2)},
247
+ BytecodeUnpacker{.bytecode = bytecode(3)},
248
+ BytecodeUnpacker{.bytecode = bytecode(4)},
249
+ BytecodeUnpacker{.bytecode = bytecode(5)},
250
+ });
251
+ });
252
+
253
+ jsi_utils::addMethod<1>(
254
+ rt, obj, "createSerializableBigInt", [](jsi::Runtime &rt, const jsi::Value &, const jsi::Value(&args)[1]) {
255
+ return makeSerializableBigInt(rt, at<0>(args).asBigInt(rt));
256
+ });
257
+
258
+ jsi_utils::addMethod<1>(
259
+ rt, obj, "createSerializableBoolean", [](jsi::Runtime &rt, const jsi::Value &, const jsi::Value(&args)[1]) {
260
+ return makeSerializableBoolean(rt, at<0>(args).asBool());
261
+ });
262
+
263
+ jsi_utils::addMethod<2>(
264
+ rt, obj, "createSerializableImport", [](jsi::Runtime &rt, const jsi::Value &, const jsi::Value(&args)[2]) {
265
+ return makeSerializableImport(rt, at<0>(args).asNumber(), at<1>(args).asString(rt));
266
+ });
267
+
268
+ jsi_utils::addMethod<0>(
269
+ rt, obj, "createSerializableNull", [](jsi::Runtime &rt, const jsi::Value &) { return makeSerializableNull(rt); });
270
+
271
+ jsi_utils::addMethod<1>(
272
+ rt, obj, "createSerializableNumber", [](jsi::Runtime &rt, const jsi::Value &, const jsi::Value(&args)[1]) {
273
+ return makeSerializableNumber(rt, at<0>(args).asNumber());
274
+ });
275
+
276
+ jsi_utils::addMethod<1>(
277
+ rt, obj, "createSerializableString", [](jsi::Runtime &rt, const jsi::Value &, const jsi::Value(&args)[1]) {
278
+ return makeSerializableString(rt, at<0>(args).asString(rt));
279
+ });
280
+
281
+ jsi_utils::addMethod<0>(rt, obj, "createSerializableUndefined", [](jsi::Runtime &rt, const jsi::Value &) {
282
+ return makeSerializableUndefined(rt);
283
+ });
284
+
285
+ jsi_utils::addMethod<1>(
286
+ rt, obj, "createSerializableHostObject", [](jsi::Runtime &rt, const jsi::Value &, const jsi::Value(&args)[1]) {
287
+ return makeSerializableHostObject(rt, at<0>(args).asObject(rt).asHostObject(rt));
288
+ });
289
+
290
+ jsi_utils::addMethod<1>(
291
+ rt, obj, "createSerializableInitializer", [](jsi::Runtime &rt, const jsi::Value &, const jsi::Value(&args)[1]) {
292
+ return makeSerializableInitializer(rt, at<0>(args).asObject(rt));
293
+ });
294
+
295
+ jsi_utils::addMethod<2>(
296
+ rt, obj, "createSerializableArray", [](jsi::Runtime &rt, const jsi::Value &, const jsi::Value(&args)[2]) {
297
+ return makeSerializableArray(rt, at<0>(args).asObject(rt).asArray(rt), at<1>(args));
298
+ });
299
+
300
+ jsi_utils::addMethod<1>(
301
+ rt, obj, "createSerializableArrayBuffer", [](jsi::Runtime &rt, const jsi::Value &, const jsi::Value(&args)[1]) {
302
+ const auto buffer = at<0>(args).getObject(rt).getArrayBuffer(rt);
303
+ return makeSerializableArrayBuffer(rt, buffer);
304
+ });
305
+
306
+ jsi_utils::addMethod<2>(
307
+ rt,
308
+ obj,
309
+ "createSerializableNonWorkletFunction",
310
+ [jsScheduler = jsScheduler_, hostRuntimeId = hostRuntimeId_, rnRuntimeStatus = rnRuntimeStatus_](
311
+ jsi::Runtime &rt, const jsi::Value &, const jsi::Value(&args)[2]) {
312
+ auto fun = at<0>(args).getObject(rt).getFunction(rt);
313
+ const auto name = at<1>(args).isUndefined() ? "" : at<1>(args).getString(rt).utf8(rt);
314
+ if (fun.isHostFunction(rt)) {
315
+ return makeSerializableHostFunction(
316
+ rt, fun.getHostFunction(rt), name, fun.getProperty(rt, "length").getNumber());
317
+ } else if (hostRuntimeId == RuntimeData::rnRuntimeId) {
318
+ return makeRNRuntimeSerializableRemoteFunction(rt, name, fun, jsScheduler, rnRuntimeStatus);
319
+ } else {
320
+ return makeWorkletRuntimeSerializableRemoteFunction(rt, name, fun, hostRuntimeId);
321
+ }
322
+ });
323
+
324
+ jsi_utils::addMethod<2>(
325
+ rt,
326
+ obj,
327
+ "createSerializableTurboModuleLike",
328
+ [](jsi::Runtime &rt, const jsi::Value &, const jsi::Value(&args)[2]) {
329
+ return makeSerializableTurboModuleLike(rt, at<0>(args).asObject(rt), at<1>(args).asObject(rt).asHostObject(rt));
330
+ });
331
+
332
+ jsi_utils::addMethod<3>(
333
+ rt, obj, "createSerializableObject", [](jsi::Runtime &rt, const jsi::Value &, const jsi::Value(&args)[3]) {
334
+ return makeSerializableObject(rt, at<0>(args).getObject(rt), at<1>(args).getBool(), at<2>(args));
335
+ });
336
+
337
+ jsi_utils::addMethod<2>(
338
+ rt, obj, "createSerializableMap", [](jsi::Runtime &rt, const jsi::Value &, const jsi::Value(&args)[2]) {
339
+ return makeSerializableMap(rt, at<0>(args).asObject(rt).asArray(rt), at<1>(args).asObject(rt).asArray(rt));
340
+ });
341
+
342
+ jsi_utils::addMethod<1>(
343
+ rt, obj, "createSerializableSet", [](jsi::Runtime &rt, const jsi::Value &, const jsi::Value(&args)[1]) {
344
+ return makeSerializableSet(rt, at<0>(args).asObject(rt).asArray(rt));
345
+ });
346
+
347
+ jsi_utils::addMethod<3>(
348
+ rt, obj, "createSerializableError", [](jsi::Runtime &rt, const jsi::Value &, const jsi::Value(&args)[3]) {
349
+ auto name = at<0>(args).getString(rt).utf8(rt);
350
+ auto message = at<1>(args).getString(rt).utf8(rt);
351
+
352
+ std::optional<std::string> stack{};
353
+ if (at<2>(args).isString()) {
354
+ stack = at<2>(args).getString(rt).utf8(rt);
355
+ }
356
+
357
+ return makeSerializableError(rt, name, message, stack);
358
+ });
359
+
360
+ jsi_utils::addMethod<2>(
361
+ rt, obj, "createSerializableRegExp", [](jsi::Runtime &rt, const jsi::Value &, const jsi::Value(&args)[2]) {
362
+ const auto pattern = at<0>(args).getString(rt).utf8(rt);
363
+ const auto flags = at<1>(args).getString(rt).utf8(rt);
364
+ return makeSerializableRegExp(rt, pattern, flags);
365
+ });
366
+
367
+ jsi_utils::addMethod<4>(
368
+ rt,
369
+ obj,
370
+ "createSerializableArrayBufferView",
371
+ [](jsi::Runtime &rt, const jsi::Value &, const jsi::Value(&args)[4]) {
372
+ const auto typeName = at<0>(args).getString(rt).utf8(rt);
373
+ const auto arrayBuffer = at<1>(args).getObject(rt).getArrayBuffer(rt);
374
+ const auto byteOffset = static_cast<size_t>(at<2>(args).getNumber());
375
+ const auto length = static_cast<size_t>(at<3>(args).getNumber());
376
+ return makeSerializableArrayBuffer(rt, arrayBuffer, ArrayBufferMetadata{typeName, byteOffset, length});
377
+ });
378
+
379
+ jsi_utils::addMethod<2>(
380
+ rt, obj, "createSerializableWorklet", [](jsi::Runtime &rt, const jsi::Value &, const jsi::Value(&args)[2]) {
381
+ return makeSerializableWorklet(rt, at<0>(args).getObject(rt), at<1>(args).getBool());
382
+ });
383
+
384
+ jsi_utils::addMethod<2>(
385
+ rt, obj, "createCustomSerializable", [](jsi::Runtime &rt, const jsi::Value &, const jsi::Value(&args)[2]) {
386
+ return makeCustomSerializable(rt, at<0>(args), at<1>(args).asNumber());
387
+ });
388
+
389
+ jsi_utils::addMethod<4>(
390
+ rt,
391
+ obj,
392
+ "registerCustomSerializable",
393
+ [memoryManager = memoryManager_, runtimeManager = runtimeManager_](
394
+ jsi::Runtime &rt, const jsi::Value &, const jsi::Value(&args)[4]) {
395
+ const auto determine = extractSerializableOrThrow<SerializableWorklet>(
396
+ rt, at<0>(args), "[Worklets] Determine function must be a worklet.");
397
+ const auto pack = extractSerializableOrThrow<SerializableWorklet>(
398
+ rt, at<1>(args), "[Worklets] Pack function must be a worklet.");
399
+ const auto unpack = extractSerializableOrThrow<SerializableWorklet>(
400
+ rt, at<2>(args), "[Worklets] Unpack function must be a worklet.");
401
+ const auto typeId = at<3>(args).asNumber();
402
+ registerCustomSerializable(runtimeManager, memoryManager, determine, pack, unpack, typeId);
403
+ });
404
+
405
+ jsi_utils::addMethod<2>(
406
+ rt,
407
+ obj,
408
+ "scheduleOnRN",
409
+ [jsScheduler = jsScheduler_](jsi::Runtime &rt, const jsi::Value &, const jsi::Value(&args)[2]) {
410
+ const auto &fun = at<0>(args).getObject(rt).getFunction(rt);
411
+ const auto &remoteArgs = at<1>(args);
412
+
413
+ auto serializableArgs = remoteArgs.isUndefined()
414
+ ? nullptr
415
+ : extractSerializableOrThrow<SerializableArray>(rt, remoteArgs, "[Worklets] Args must be an array.");
416
+
417
+ if (!fun.getProperty(rt, "__remoteFunction").isUndefined()) [[likely]] { // NOLINT(readability/braces)
418
+ const auto remoteFunction = extractSerializableOrThrow<SerializableRemoteFunction>(rt, fun);
419
+ jsScheduler->scheduleOnJS([remoteFunction, serializableArgs](jsi::Runtime &rnRuntime) {
420
+ const auto unpackedFun = remoteFunction->toJSValue(rnRuntime).getObject(rnRuntime).getFunction(rnRuntime);
421
+ if (serializableArgs == nullptr) {
422
+ // fast path for remote function w/o arguments
423
+ unpackedFun.call(rnRuntime);
424
+ } else {
425
+ const auto args = serializableArgs->getJSIValueArr(rnRuntime);
426
+ unpackedFun.call(rnRuntime, args.data(), args.size());
427
+ }
428
+ });
429
+ } else if (fun.isHostFunction(rt)) {
430
+ auto hostFun = fun.getHostFunction(rt);
431
+ jsScheduler->scheduleOnJS([hostFun = std::move(hostFun), serializableArgs](jsi::Runtime &rnRuntime) {
432
+ if (serializableArgs == nullptr) {
433
+ // fast path for host function w/o arguments
434
+ hostFun(rnRuntime, jsi::Value::undefined(), nullptr, 0);
435
+ } else {
436
+ const auto args = serializableArgs->getJSIValueArr(rnRuntime);
437
+ hostFun(rnRuntime, jsi::Value::undefined(), args.data(), args.size());
438
+ }
439
+ });
440
+ } else {
441
+ const auto fnName = fun.getProperty(rt, "name").getString(rt).utf8(rt);
442
+ const auto nameInError = fnName.empty() ? "" : " (" + fnName + ")";
443
+ throw std::runtime_error(
444
+ "[Worklets] Locally defined function passed to scheduleOnRN" + nameInError +
445
+ ". Only functions defined on the RN Runtime or host functions can be scheduled on the RN Runtime. Define the function on the RN Runtime and pass it as a reference. See https://docs.swmansion.com/react-native-worklets/docs/guides/troubleshooting#locally-defined-function-passed-to-scheduleonrn for more details.");
446
+ }
447
+ });
448
+
449
+ jsi_utils::addMethod<2>(
450
+ rt,
451
+ obj,
452
+ "scheduleOnUI",
453
+ [uiWorkletRuntime = uiWorkletRuntime_](jsi::Runtime &rt, const jsi::Value &, const jsi::Value(&args)[2]) {
454
+ #ifndef NDEBUG
455
+ scheduleOnUI(uiWorkletRuntime, rt, at<0>(args), at<1>(args));
456
+ #else
457
+ scheduleOnUI(uiWorkletRuntime, rt, at<0>(args));
458
+ #endif // NDEBUG
459
+ });
460
+
461
+ jsi_utils::addMethod<2>(
462
+ rt,
463
+ obj,
464
+ "runOnUISync",
465
+ [uiWorkletRuntime = uiWorkletRuntime_](jsi::Runtime &rt, const jsi::Value &, const jsi::Value(&args)[2]) {
466
+ #ifndef NDEBUG
467
+ std::optional<std::string> scheduleStack;
468
+ if (at<1>(args).isString()) {
469
+ scheduleStack = at<1>(args).asString(rt).utf8(rt);
470
+ }
471
+ return runOnUISync(uiWorkletRuntime, rt, at<0>(args), scheduleStack);
472
+ #else
473
+ return runOnUISync(uiWorkletRuntime, rt, at<0>(args));
474
+ #endif // NDEBUG
475
+ });
476
+
477
+ jsi_utils::addMethod<3>(
478
+ rt, obj, "runOnRuntimeSync", [](jsi::Runtime &rt, const jsi::Value &, const jsi::Value(&args)[3]) {
479
+ #ifndef NDEBUG
480
+ std::optional<std::string> scheduleStack;
481
+ if (at<2>(args).isString()) {
482
+ scheduleStack = at<2>(args).asString(rt).utf8(rt);
483
+ }
484
+ return runOnRuntimeSync(rt, at<0>(args), at<1>(args), scheduleStack);
485
+ #else
486
+ return runOnRuntimeSync(rt, at<0>(args), at<1>(args));
487
+ #endif // NDEBUG
488
+ });
489
+
490
+ jsi_utils::addMethod<3>(
491
+ rt,
492
+ obj,
493
+ "runOnRuntimeSyncWithId",
494
+ [runtimeManager = runtimeManager_](jsi::Runtime &rt, const jsi::Value &, const jsi::Value(&args)[3]) {
495
+ const int runtimeId = at<0>(args).asNumber();
496
+ const auto workletRuntime = runtimeManager->getRuntime(runtimeId);
497
+ if (!workletRuntime) {
498
+ throw jsi::JSError(
499
+ rt, "[Worklets] runOnRuntimeSyncWithId: no worklet runtime found for id " + std::to_string(runtimeId));
500
+ }
501
+ auto serializableWorklet = extractSerializableOrThrow<SerializableWorklet>(
502
+ rt, at<1>(args), "[Worklets] Only worklets can be executed on a worklet runtime.");
503
+ #ifndef NDEBUG
504
+ std::optional<std::string> scheduleStack;
505
+ if (at<2>(args).isString()) {
506
+ scheduleStack = at<2>(args).asString(rt).utf8(rt);
507
+ }
508
+ return workletRuntime->runSyncSerializedWithStack(serializableWorklet, scheduleStack)->toJSValue(rt);
509
+ #else
510
+ return workletRuntime->runSyncSerialized(serializableWorklet)->toJSValue(rt);
511
+ #endif // NDEBUG
512
+ });
513
+
514
+ jsi_utils::addMethod<5>(
515
+ rt,
516
+ obj,
517
+ "createWorkletRuntime",
518
+ [sourceProxy = shared_from_this()](jsi::Runtime &rt, const jsi::Value &, const jsi::Value(&args)[5]) {
519
+ const auto name = at<0>(args).asString(rt).utf8(rt);
520
+ auto serializableInitializer = extractSerializableOrThrow<SerializableWorklet>(
521
+ rt, at<1>(args), "[Worklets] Initializer must be a worklet.");
522
+ const auto useDefaultQueue = at<2>(args).asBool();
523
+
524
+ std::shared_ptr<AsyncQueue> asyncQueue;
525
+ if (useDefaultQueue) {
526
+ asyncQueue = std::make_shared<AsyncQueueImpl>(name + "_queue");
527
+ } else {
528
+ asyncQueue = extractAsyncQueue(rt, at<3>(args));
529
+ }
530
+
531
+ const auto enableEventLoop = at<4>(args).asBool();
532
+ const auto runtimeManager = sourceProxy->getRuntimeManager();
533
+
534
+ return createWorkletRuntime(
535
+ rt, runtimeManager, sourceProxy, name, serializableInitializer, asyncQueue, enableEventLoop);
536
+ });
537
+
538
+ jsi_utils::addMethod<3>(
539
+ rt, obj, "scheduleOnRuntime", [](jsi::Runtime &rt, const jsi::Value &, const jsi::Value(&args)[3]) {
540
+ #ifndef NDEBUG
541
+ std::optional<std::string> scheduleStack;
542
+ if (at<2>(args).isString()) {
543
+ scheduleStack = at<2>(args).asString(rt).utf8(rt);
544
+ }
545
+ worklets::scheduleOnRuntime(rt, at<0>(args), at<1>(args), scheduleStack);
546
+ #else
547
+ worklets::scheduleOnRuntime(rt, at<0>(args), at<1>(args));
548
+ #endif // NDEBUG
549
+ });
550
+
551
+ jsi_utils::addMethod<3>(
552
+ rt,
553
+ obj,
554
+ "scheduleOnRuntimeWithId",
555
+ [runtimeManager = runtimeManager_](jsi::Runtime &rt, const jsi::Value &, const jsi::Value(&args)[3]) {
556
+ const int runtimeId = at<0>(args).asNumber();
557
+ const auto workletRuntime = runtimeManager->getRuntime(runtimeId);
558
+ if (!workletRuntime) {
559
+ throw jsi::JSError(
560
+ rt, "[Worklets] scheduleOnRuntimeWithId: no worklet runtime found for id " + std::to_string(runtimeId));
561
+ }
562
+ const auto worklet = extractSerializableOrThrow<SerializableWorklet>(
563
+ rt, at<1>(args), "[Worklets] Only worklets can be scheduled to run on a worklet runtime.");
564
+ #ifndef NDEBUG
565
+ std::optional<std::string> scheduleStack;
566
+ if (at<2>(args).isString()) {
567
+ scheduleStack = at<2>(args).asString(rt).utf8(rt);
568
+ }
569
+ workletRuntime->schedule(worklet, scheduleStack);
570
+ #else
571
+ workletRuntime->schedule(worklet);
572
+ #endif // NDEBUG
573
+ });
574
+
575
+ jsi_utils::addMethod<2>(
576
+ rt,
577
+ obj,
578
+ "handlePromise",
579
+ [runtimeManager = runtimeManager_](jsi::Runtime &rt, const jsi::Value &, const jsi::Value(&args)[2]) {
580
+ const auto fun = at<0>(args).getObject(rt).getFunction(rt);
581
+ // NOLINTNEXTLINE(readability/braces)
582
+ if (fun.getProperty(rt, "__remoteFunction").isUndefined()) [[unlikely]] {
583
+ // TODO: add a fast path for it in TypeScript
584
+ fun.call(rt, extractSerializableOrThrow(rt, at<1>(args))->toJSValue(rt));
585
+ } else {
586
+ auto resolveOrReject = extractSerializableOrThrow<SerializableRemoteFunction>(rt, at<0>(args));
587
+ auto valueOrError = extractSerializableOrThrow(rt, at<1>(args));
588
+ resolveOrReject->resolveOrRejectPromise(valueOrError, runtimeManager);
589
+ }
590
+ });
591
+
592
+ jsi_utils::addMethod<3>(
593
+ rt,
594
+ obj,
595
+ "reportFatalErrorOnJS",
596
+ [jsScheduler = jsScheduler_](jsi::Runtime &rt, const jsi::Value &, const jsi::Value(&args)[3]) {
597
+ return reportFatalErrorOnJS(
598
+ jsScheduler,
599
+ /* message */ at<0>(args).asString(rt).utf8(rt),
600
+ /* stack */ at<1>(args).asString(rt).utf8(rt),
601
+ /* name */ at<2>(args).asString(rt).utf8(rt));
602
+ });
603
+
604
+ jsi_utils::addMethod<1>(
605
+ rt, obj, "getStaticFeatureFlag", [](jsi::Runtime &rt, const jsi::Value &, const jsi::Value(&args)[1]) {
606
+ return worklets::StaticFeatureFlags::getFlag(/* name */ at<0>(args).asString(rt).utf8(rt));
607
+ });
608
+
609
+ jsi_utils::addMethod<2>(
610
+ rt, obj, "setDynamicFeatureFlag", [](jsi::Runtime &rt, const jsi::Value &, const jsi::Value(&args)[2]) {
611
+ worklets::DynamicFeatureFlags::setFlag(
612
+ /* name */ at<0>(args).asString(rt).utf8(rt),
613
+ /* value */ at<1>(args).asBool());
614
+ });
615
+
616
+ jsi_utils::addMethod<1>(
617
+ rt, obj, "createSynchronizable", [](jsi::Runtime &rt, const jsi::Value &, const jsi::Value(&args)[1]) {
618
+ auto initial = extractSerializableOrThrow(rt, at<0>(args), "[Worklets] Value must be a Serializable.");
619
+ auto synchronizable = std::make_shared<Synchronizable>(initial);
620
+ return SerializableJSRef::newNativeStateObject(rt, synchronizable);
621
+ });
622
+
623
+ jsi_utils::addMethod<1>(
624
+ rt, obj, "synchronizableGetDirty", [](jsi::Runtime &rt, const jsi::Value &, const jsi::Value(&args)[1]) {
625
+ auto synchronizable = extractSynchronizableOrThrow(rt, at<0>(args));
626
+ return synchronizable->getDirty()->toJSValue(rt);
627
+ });
628
+
629
+ jsi_utils::addMethod<1>(
630
+ rt, obj, "synchronizableGetBlocking", [](jsi::Runtime &rt, const jsi::Value &, const jsi::Value(&args)[1]) {
631
+ auto synchronizable = extractSynchronizableOrThrow(rt, at<0>(args));
632
+ return synchronizable->getBlocking()->toJSValue(rt);
633
+ });
634
+
635
+ jsi_utils::addMethod<2>(
636
+ rt, obj, "synchronizableSetBlocking", [](jsi::Runtime &rt, const jsi::Value &, const jsi::Value(&args)[2]) {
637
+ auto synchronizable = extractSynchronizableOrThrow(rt, at<0>(args));
638
+ auto newValue = extractSerializableOrThrow(rt, at<1>(args), "[Worklets] Value must be a Serializable.");
639
+ synchronizable->setBlocking(newValue);
640
+ });
641
+
642
+ jsi_utils::addMethod<1>(
643
+ rt, obj, "synchronizableLock", [](jsi::Runtime &rt, const jsi::Value &, const jsi::Value(&args)[1]) {
644
+ auto synchronizable = extractSynchronizableOrThrow(rt, at<0>(args));
645
+ synchronizable->lock();
646
+ });
647
+
648
+ jsi_utils::addMethod<1>(
649
+ rt, obj, "synchronizableUnlock", [](jsi::Runtime &rt, const jsi::Value &, const jsi::Value(&args)[1]) {
650
+ auto synchronizable = extractSynchronizableOrThrow(rt, at<0>(args));
651
+ synchronizable->unlock();
652
+ });
653
+
654
+ jsi_utils::addMethod<5>(
655
+ rt,
656
+ obj,
657
+ "createShareable",
658
+ [runtimeManager = runtimeManager_](
659
+ jsi::Runtime &rt, const jsi::Value &, const jsi::Value(&args)[5]) -> jsi::Value {
660
+ const int hostRuntimeId = at<0>(args).asNumber();
661
+ const auto hostRuntime = runtimeManager->getRuntime(hostRuntimeId);
662
+ if (!hostRuntime) {
663
+ throw jsi::JSError(
664
+ rt, "[Worklets] createShareable: no worklet runtime found for id " + std::to_string(hostRuntimeId));
665
+ }
666
+ const auto initial = extractSerializableOrThrow(rt, at<1>(args), "[Worklets] Value must be a Serializable.");
667
+ const auto initSynchronously = at<2>(args).asBool();
668
+ const auto decorateHost = extractSerializableOrThrow(rt, at<3>(args));
669
+ const auto decorateGuest = extractSerializableOrThrow(rt, at<4>(args));
670
+ const auto shareable =
671
+ std::make_shared<Shareable>(hostRuntime, initial, initSynchronously, decorateHost, decorateGuest);
672
+ return SerializableJSRef::newNativeStateObject(rt, shareable);
673
+ });
674
+
675
+ #ifndef NDEBUG
676
+ jsi_utils::addMethod<2>(
677
+ rt,
678
+ obj,
679
+ "propagateModuleUpdate",
680
+ [runtimeManager = runtimeManager_](jsi::Runtime &rt, const jsi::Value &, const jsi::Value(&args)[2]) {
681
+ const auto code = at<0>(args).getString(rt).utf8(rt);
682
+ const auto sourceUrl = at<1>(args).getString(rt).utf8(rt);
683
+ runtimeManager->propagateModuleUpdate(code, sourceUrl);
684
+ });
685
+ #endif // NDEBUG
686
+
687
+ jsi_utils::addMethod<0>(
688
+ rt, obj, "getUIRuntimeHolder", [uiWorkletRuntime = uiWorkletRuntime_](jsi::Runtime &rt, const jsi::Value &) {
689
+ const auto strongUIWorkletRuntime = uiWorkletRuntime.lock();
690
+ if (!strongUIWorkletRuntime) {
691
+ throw jsi::JSError(rt, "[Worklets] UI Worklet Runtime is not available.");
692
+ }
693
+ auto nativeState = std::make_shared<WorkletRuntimeHolder>(strongUIWorkletRuntime);
694
+ auto obj = jsi::Object(rt);
695
+ obj.setNativeState(rt, std::move(nativeState));
696
+ return jsi::Value(std::move(obj));
697
+ });
698
+
699
+ jsi_utils::addMethod<0>(
700
+ rt, obj, "getUISchedulerHolder", [uiScheduler = uiScheduler_](jsi::Runtime &rt, const jsi::Value &) {
701
+ auto nativeState = std::make_shared<UISchedulerHolder>(uiScheduler);
702
+ auto obj = jsi::Object(rt);
703
+ obj.setNativeState(rt, std::move(nativeState));
704
+ return jsi::Value(std::move(obj));
705
+ });
706
+
707
+ /* #region deprecated */
708
+
709
+ jsi_utils::addMethod<2>(
710
+ rt,
711
+ obj,
712
+ "createSerializableLEGACY",
713
+ [hostRuntimeId = hostRuntimeId_](jsi::Runtime &rt, const jsi::Value &, const jsi::Value(&args)[2]) {
714
+ react_native_assert(
715
+ hostRuntimeId != RuntimeData::rnRuntimeId &&
716
+ "createSerializableLEGACY should never be called on the React Native runtime.");
717
+ (void)hostRuntimeId;
718
+ const auto &value = at<0>(args);
719
+ const auto shouldRetainRemote = jsi::Value::undefined();
720
+ const auto &nativeStateSource = at<1>(args);
721
+ return makeSerializableClone(rt, value, shouldRetainRemote, nativeStateSource);
722
+ });
723
+
724
+ /* #endregion deprecated */
725
+
726
+ return obj;
727
+ }
728
+
729
+ } // namespace worklets