@amazon-devices/react-native-worklets 1.0.0-rn-83

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 (348) hide show
  1. package/Common/cpp/worklets/AnimationFrameQueue/AnimationFrameBatchinator.cpp +71 -0
  2. package/Common/cpp/worklets/AnimationFrameQueue/AnimationFrameBatchinator.h +38 -0
  3. package/Common/cpp/worklets/NativeModules/JSIWorkletsModuleProxy.cpp +712 -0
  4. package/Common/cpp/worklets/NativeModules/JSIWorkletsModuleProxy.h +88 -0
  5. package/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.cpp +89 -0
  6. package/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.h +80 -0
  7. package/Common/cpp/worklets/Public/AsyncQueue.h +14 -0
  8. package/Common/cpp/worklets/Registries/EventHandlerRegistry.cpp +94 -0
  9. package/Common/cpp/worklets/Registries/EventHandlerRegistry.h +51 -0
  10. package/Common/cpp/worklets/Registries/WorkletRuntimeRegistry.cpp +8 -0
  11. package/Common/cpp/worklets/Registries/WorkletRuntimeRegistry.h +40 -0
  12. package/Common/cpp/worklets/Resources/SynchronizableUnpacker.cpp +49 -0
  13. package/Common/cpp/worklets/Resources/Unpackers.h +6 -0
  14. package/Common/cpp/worklets/Resources/ValueUnpacker.cpp +53 -0
  15. package/Common/cpp/worklets/RunLoop/AsyncQueueImpl.cpp +62 -0
  16. package/Common/cpp/worklets/RunLoop/AsyncQueueImpl.h +46 -0
  17. package/Common/cpp/worklets/RunLoop/EventLoop.cpp +112 -0
  18. package/Common/cpp/worklets/RunLoop/EventLoop.h +52 -0
  19. package/Common/cpp/worklets/SharedItems/Serializable.cpp +545 -0
  20. package/Common/cpp/worklets/SharedItems/Serializable.h +473 -0
  21. package/Common/cpp/worklets/SharedItems/Synchronizable.cpp +67 -0
  22. package/Common/cpp/worklets/SharedItems/Synchronizable.h +59 -0
  23. package/Common/cpp/worklets/SharedItems/SynchronizableAccess.cpp +81 -0
  24. package/Common/cpp/worklets/SharedItems/SynchronizableAccess.h +45 -0
  25. package/Common/cpp/worklets/Tools/Defs.h +10 -0
  26. package/Common/cpp/worklets/Tools/FeatureFlags.cpp +15 -0
  27. package/Common/cpp/worklets/Tools/FeatureFlags.h +44 -0
  28. package/Common/cpp/worklets/Tools/JSISerializer.cpp +342 -0
  29. package/Common/cpp/worklets/Tools/JSISerializer.h +51 -0
  30. package/Common/cpp/worklets/Tools/JSLogger.cpp +68 -0
  31. package/Common/cpp/worklets/Tools/JSLogger.h +37 -0
  32. package/Common/cpp/worklets/Tools/JSScheduler.cpp +24 -0
  33. package/Common/cpp/worklets/Tools/JSScheduler.h +39 -0
  34. package/Common/cpp/worklets/Tools/PlatformLogger.h +16 -0
  35. package/Common/cpp/worklets/Tools/SingleInstanceChecker.h +82 -0
  36. package/Common/cpp/worklets/Tools/ThreadSafeQueue.h +49 -0
  37. package/Common/cpp/worklets/Tools/UIScheduler.cpp +19 -0
  38. package/Common/cpp/worklets/Tools/UIScheduler.h +26 -0
  39. package/Common/cpp/worklets/Tools/VersionUtils.cpp +75 -0
  40. package/Common/cpp/worklets/Tools/VersionUtils.h +28 -0
  41. package/Common/cpp/worklets/Tools/WorkletEventHandler.cpp +29 -0
  42. package/Common/cpp/worklets/Tools/WorkletEventHandler.h +41 -0
  43. package/Common/cpp/worklets/Tools/WorkletsJSIUtils.cpp +46 -0
  44. package/Common/cpp/worklets/Tools/WorkletsJSIUtils.h +208 -0
  45. package/Common/cpp/worklets/Tools/WorkletsSystraceSection.h +161 -0
  46. package/Common/cpp/worklets/Tools/WorkletsVersion.cpp +54 -0
  47. package/Common/cpp/worklets/Tools/WorkletsVersion.h +20 -0
  48. package/Common/cpp/worklets/WorkletRuntime/RNRuntimeWorkletDecorator.cpp +38 -0
  49. package/Common/cpp/worklets/WorkletRuntime/RNRuntimeWorkletDecorator.h +21 -0
  50. package/Common/cpp/worklets/WorkletRuntime/RuntimeData.cpp +3 -0
  51. package/Common/cpp/worklets/WorkletRuntime/RuntimeData.h +12 -0
  52. package/Common/cpp/worklets/WorkletRuntime/RuntimeInitialization.md +191 -0
  53. package/Common/cpp/worklets/WorkletRuntime/RuntimeKind.h +16 -0
  54. package/Common/cpp/worklets/WorkletRuntime/RuntimeManager.cpp +105 -0
  55. package/Common/cpp/worklets/WorkletRuntime/RuntimeManager.h +63 -0
  56. package/Common/cpp/worklets/WorkletRuntime/UIRuntimeDecorator.cpp +23 -0
  57. package/Common/cpp/worklets/WorkletRuntime/UIRuntimeDecorator.h +16 -0
  58. package/Common/cpp/worklets/WorkletRuntime/WorkletHermesRuntime.cpp +119 -0
  59. package/Common/cpp/worklets/WorkletRuntime/WorkletHermesRuntime.h +134 -0
  60. package/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.cpp +244 -0
  61. package/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.h +102 -0
  62. package/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeCollector.h +36 -0
  63. package/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.cpp +308 -0
  64. package/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.h +26 -0
  65. package/LICENSE +7 -0
  66. package/README.md +31 -0
  67. package/RNWorklets.podspec +94 -0
  68. package/SystemBundles/cc12deac6e91c435b76698c8445aed85612f2f88e733218d14f88a35d06fb0f4.bundle +10512 -0
  69. package/SystemBundles/cc12deac6e91c435b76698c8445aed85612f2f88e733218d14f88a35d06fb0f4.map +3771 -0
  70. package/SystemModules/amzn__react-native-worklets-1.modules.txt +39 -0
  71. package/SystemModules/amzn__react-native-worklets-1.private.modules.txt +61 -0
  72. package/SystemModules/keplerscript-system-bundle-config.json +7 -0
  73. package/android/CMakeLists.txt +124 -0
  74. package/android/build.gradle +350 -0
  75. package/android/gradle.properties +5 -0
  76. package/android/proguard-rules.pro +3 -0
  77. package/android/spotless.gradle +9 -0
  78. package/android/src/experimentalBundling/com/swmansion/worklets/WorkletsModule.java +149 -0
  79. package/android/src/legacyBundling/com/swmansion/worklets/WorkletsModule.java +122 -0
  80. package/android/src/main/AndroidManifest.xml +2 -0
  81. package/android/src/main/cpp/worklets/android/AndroidUIScheduler.cpp +63 -0
  82. package/android/src/main/cpp/worklets/android/AndroidUIScheduler.h +43 -0
  83. package/android/src/main/cpp/worklets/android/AnimationFrameCallback.h +34 -0
  84. package/android/src/main/cpp/worklets/android/PlatformLogger.cpp +29 -0
  85. package/android/src/main/cpp/worklets/android/WorkletsModule.cpp +115 -0
  86. package/android/src/main/cpp/worklets/android/WorkletsModule.h +78 -0
  87. package/android/src/main/cpp/worklets/android/WorkletsOnLoad.cpp +13 -0
  88. package/android/src/main/java/com/swmansion/worklets/AndroidUIScheduler.java +60 -0
  89. package/android/src/main/java/com/swmansion/worklets/JSCallInvokerResolver.java +27 -0
  90. package/android/src/main/java/com/swmansion/worklets/WorkletsMessageQueueThread.java +16 -0
  91. package/android/src/main/java/com/swmansion/worklets/WorkletsMessageQueueThreadBase.java +73 -0
  92. package/android/src/main/java/com/swmansion/worklets/WorkletsPackage.java +48 -0
  93. package/android/src/main/java/com/swmansion/worklets/runloop/AnimationFrameCallback.java +19 -0
  94. package/android/src/main/java/com/swmansion/worklets/runloop/AnimationFrameQueue.java +113 -0
  95. package/apple/worklets/apple/AnimationFrameQueue.h +15 -0
  96. package/apple/worklets/apple/AnimationFrameQueue.mm +135 -0
  97. package/apple/worklets/apple/AssertJavaScriptQueue.h +14 -0
  98. package/apple/worklets/apple/AssertTurboModuleManagerQueue.h +16 -0
  99. package/apple/worklets/apple/IOSUIScheduler.h +15 -0
  100. package/apple/worklets/apple/IOSUIScheduler.mm +29 -0
  101. package/apple/worklets/apple/PlatformLogger.mm +31 -0
  102. package/apple/worklets/apple/SlowAnimations.h +8 -0
  103. package/apple/worklets/apple/SlowAnimations.mm +45 -0
  104. package/apple/worklets/apple/WorkletsDisplayLink.h +21 -0
  105. package/apple/worklets/apple/WorkletsMessageThread.h +16 -0
  106. package/apple/worklets/apple/WorkletsMessageThread.mm +31 -0
  107. package/apple/worklets/apple/WorkletsModule.h +28 -0
  108. package/apple/worklets/apple/WorkletsModule.mm +121 -0
  109. package/bundleMode/index.d.ts +3 -0
  110. package/bundleMode/index.js +59 -0
  111. package/compatibility.json +11 -0
  112. package/kepler-compatibility.json +5 -0
  113. package/kepler-transformed-package-info.json +3 -0
  114. package/lib/module/PlatformChecker/PlatformChecker.js +8 -0
  115. package/lib/module/PlatformChecker/PlatformChecker.js.map +1 -0
  116. package/lib/module/PlatformChecker/index.js +18 -0
  117. package/lib/module/PlatformChecker/index.js.map +1 -0
  118. package/lib/module/WorkletsError.js +29 -0
  119. package/lib/module/WorkletsError.js.map +1 -0
  120. package/lib/module/WorkletsModule/JSWorklets.js +111 -0
  121. package/lib/module/WorkletsModule/JSWorklets.js.map +1 -0
  122. package/lib/module/WorkletsModule/NativeWorklets.js +126 -0
  123. package/lib/module/WorkletsModule/NativeWorklets.js.map +1 -0
  124. package/lib/module/WorkletsModule/index.js +4 -0
  125. package/lib/module/WorkletsModule/index.js.map +1 -0
  126. package/lib/module/WorkletsModule/workletsModuleInstance.js +7 -0
  127. package/lib/module/WorkletsModule/workletsModuleInstance.js.map +1 -0
  128. package/lib/module/WorkletsModule/workletsModuleInstance.web.js +5 -0
  129. package/lib/module/WorkletsModule/workletsModuleInstance.web.js.map +1 -0
  130. package/lib/module/WorkletsModule/workletsModuleProxy.js +4 -0
  131. package/lib/module/WorkletsModule/workletsModuleProxy.js.map +1 -0
  132. package/lib/module/bundleUnpacker.js +47 -0
  133. package/lib/module/bundleUnpacker.js.map +1 -0
  134. package/lib/module/callGuard.js +30 -0
  135. package/lib/module/callGuard.js.map +1 -0
  136. package/lib/module/deprecated.js +20 -0
  137. package/lib/module/deprecated.js.map +1 -0
  138. package/lib/module/errors.js +69 -0
  139. package/lib/module/errors.js.map +1 -0
  140. package/lib/module/featureFlags/index.js +48 -0
  141. package/lib/module/featureFlags/index.js.map +1 -0
  142. package/lib/module/featureFlags/staticFlags.json +4 -0
  143. package/lib/module/index.js +26 -0
  144. package/lib/module/index.js.map +1 -0
  145. package/lib/module/initializers.js +221 -0
  146. package/lib/module/initializers.js.map +1 -0
  147. package/lib/module/isSynchronizable.js +6 -0
  148. package/lib/module/isSynchronizable.js.map +1 -0
  149. package/lib/module/logger.js +15 -0
  150. package/lib/module/logger.js.map +1 -0
  151. package/lib/module/privateGlobals.d.js +7 -0
  152. package/lib/module/privateGlobals.d.js.map +1 -0
  153. package/lib/module/publicGlobals.js +6 -0
  154. package/lib/module/publicGlobals.js.map +1 -0
  155. package/lib/module/runLoop/common/setImmediatePolyfill.js +15 -0
  156. package/lib/module/runLoop/common/setImmediatePolyfill.js.map +1 -0
  157. package/lib/module/runLoop/common/setIntervalPolyfill.js +26 -0
  158. package/lib/module/runLoop/common/setIntervalPolyfill.js.map +1 -0
  159. package/lib/module/runLoop/uiRuntime/mockedRequestAnimationFrame.js +10 -0
  160. package/lib/module/runLoop/uiRuntime/mockedRequestAnimationFrame.js.map +1 -0
  161. package/lib/module/runLoop/uiRuntime/requestAnimationFrame.js +52 -0
  162. package/lib/module/runLoop/uiRuntime/requestAnimationFrame.js.map +1 -0
  163. package/lib/module/runLoop/uiRuntime/setTimeoutPolyfill.js +32 -0
  164. package/lib/module/runLoop/uiRuntime/setTimeoutPolyfill.js.map +1 -0
  165. package/lib/module/runLoop/workletRuntime/index.js +19 -0
  166. package/lib/module/runLoop/workletRuntime/index.js.map +1 -0
  167. package/lib/module/runLoop/workletRuntime/queueMicrotask.js +11 -0
  168. package/lib/module/runLoop/workletRuntime/queueMicrotask.js.map +1 -0
  169. package/lib/module/runLoop/workletRuntime/requestAnimationFramePolyfill.js +48 -0
  170. package/lib/module/runLoop/workletRuntime/requestAnimationFramePolyfill.js.map +1 -0
  171. package/lib/module/runLoop/workletRuntime/setTimeout.js +28 -0
  172. package/lib/module/runLoop/workletRuntime/setTimeout.js.map +1 -0
  173. package/lib/module/runLoop/workletRuntime/taskQueue.js +37 -0
  174. package/lib/module/runLoop/workletRuntime/taskQueue.js.map +1 -0
  175. package/lib/module/runtimeKind.js +39 -0
  176. package/lib/module/runtimeKind.js.map +1 -0
  177. package/lib/module/runtimes.js +100 -0
  178. package/lib/module/runtimes.js.map +1 -0
  179. package/lib/module/serializable.js +568 -0
  180. package/lib/module/serializable.js.map +1 -0
  181. package/lib/module/serializableMappingCache.js +37 -0
  182. package/lib/module/serializableMappingCache.js.map +1 -0
  183. package/lib/module/specs/NativeWorkletsModule.js +5 -0
  184. package/lib/module/specs/NativeWorkletsModule.js.map +1 -0
  185. package/lib/module/specs/NativeWorkletsModule.kepler.js +7 -0
  186. package/lib/module/specs/NativeWorkletsModule.kepler.js.map +1 -0
  187. package/lib/module/specs/index.js +10 -0
  188. package/lib/module/specs/index.js.map +1 -0
  189. package/lib/module/synchronizable.js +9 -0
  190. package/lib/module/synchronizable.js.map +1 -0
  191. package/lib/module/synchronizableUnpacker.js +42 -0
  192. package/lib/module/synchronizableUnpacker.js.map +1 -0
  193. package/lib/module/threads.js +347 -0
  194. package/lib/module/threads.js.map +1 -0
  195. package/lib/module/utils/checkCppVersion.js +30 -0
  196. package/lib/module/utils/checkCppVersion.js.map +1 -0
  197. package/lib/module/utils/jsVersion.js +9 -0
  198. package/lib/module/utils/jsVersion.js.map +1 -0
  199. package/lib/module/valueUnpacker.js +60 -0
  200. package/lib/module/valueUnpacker.js.map +1 -0
  201. package/lib/module/workletFunction.js +37 -0
  202. package/lib/module/workletFunction.js.map +1 -0
  203. package/lib/module/workletRuntimeEntry.js +32 -0
  204. package/lib/module/workletRuntimeEntry.js.map +1 -0
  205. package/lib/module/workletTypes.js +12 -0
  206. package/lib/module/workletTypes.js.map +1 -0
  207. package/lib/typescript/PlatformChecker/PlatformChecker.d.ts +5 -0
  208. package/lib/typescript/PlatformChecker/PlatformChecker.d.ts.map +1 -0
  209. package/lib/typescript/PlatformChecker/index.d.ts +10 -0
  210. package/lib/typescript/PlatformChecker/index.d.ts.map +1 -0
  211. package/lib/typescript/WorkletsError.d.ts +15 -0
  212. package/lib/typescript/WorkletsError.d.ts.map +1 -0
  213. package/lib/typescript/WorkletsModule/JSWorklets.d.ts +3 -0
  214. package/lib/typescript/WorkletsModule/JSWorklets.d.ts.map +1 -0
  215. package/lib/typescript/WorkletsModule/NativeWorklets.d.ts +3 -0
  216. package/lib/typescript/WorkletsModule/NativeWorklets.d.ts.map +1 -0
  217. package/lib/typescript/WorkletsModule/index.d.ts +3 -0
  218. package/lib/typescript/WorkletsModule/index.d.ts.map +1 -0
  219. package/lib/typescript/WorkletsModule/workletsModuleInstance.d.ts +2 -0
  220. package/lib/typescript/WorkletsModule/workletsModuleInstance.d.ts.map +1 -0
  221. package/lib/typescript/WorkletsModule/workletsModuleInstance.web.d.ts +2 -0
  222. package/lib/typescript/WorkletsModule/workletsModuleInstance.web.d.ts.map +1 -0
  223. package/lib/typescript/WorkletsModule/workletsModuleProxy.d.ts +37 -0
  224. package/lib/typescript/WorkletsModule/workletsModuleProxy.d.ts.map +1 -0
  225. package/lib/typescript/bundleUnpacker.d.ts +7 -0
  226. package/lib/typescript/bundleUnpacker.d.ts.map +1 -0
  227. package/lib/typescript/callGuard.d.ts +4 -0
  228. package/lib/typescript/callGuard.d.ts.map +1 -0
  229. package/lib/typescript/deprecated.d.ts +20 -0
  230. package/lib/typescript/deprecated.d.ts.map +1 -0
  231. package/lib/typescript/errors.d.ts +16 -0
  232. package/lib/typescript/errors.d.ts.map +1 -0
  233. package/lib/typescript/featureFlags/index.d.ts +23 -0
  234. package/lib/typescript/featureFlags/index.d.ts.map +1 -0
  235. package/lib/typescript/index.d.ts +17 -0
  236. package/lib/typescript/index.d.ts.map +1 -0
  237. package/lib/typescript/initializers.d.ts +17 -0
  238. package/lib/typescript/initializers.d.ts.map +1 -0
  239. package/lib/typescript/isSynchronizable.d.ts +3 -0
  240. package/lib/typescript/isSynchronizable.d.ts.map +1 -0
  241. package/lib/typescript/logger.d.ts +5 -0
  242. package/lib/typescript/logger.d.ts.map +1 -0
  243. package/lib/typescript/publicGlobals.d.ts +31 -0
  244. package/lib/typescript/publicGlobals.d.ts.map +1 -0
  245. package/lib/typescript/runLoop/common/setImmediatePolyfill.d.ts +2 -0
  246. package/lib/typescript/runLoop/common/setImmediatePolyfill.d.ts.map +1 -0
  247. package/lib/typescript/runLoop/common/setIntervalPolyfill.d.ts +2 -0
  248. package/lib/typescript/runLoop/common/setIntervalPolyfill.d.ts.map +1 -0
  249. package/lib/typescript/runLoop/uiRuntime/mockedRequestAnimationFrame.d.ts +6 -0
  250. package/lib/typescript/runLoop/uiRuntime/mockedRequestAnimationFrame.d.ts.map +1 -0
  251. package/lib/typescript/runLoop/uiRuntime/requestAnimationFrame.d.ts +2 -0
  252. package/lib/typescript/runLoop/uiRuntime/requestAnimationFrame.d.ts.map +1 -0
  253. package/lib/typescript/runLoop/uiRuntime/setTimeoutPolyfill.d.ts +2 -0
  254. package/lib/typescript/runLoop/uiRuntime/setTimeoutPolyfill.d.ts.map +1 -0
  255. package/lib/typescript/runLoop/workletRuntime/index.d.ts +2 -0
  256. package/lib/typescript/runLoop/workletRuntime/index.d.ts.map +1 -0
  257. package/lib/typescript/runLoop/workletRuntime/queueMicrotask.d.ts +2 -0
  258. package/lib/typescript/runLoop/workletRuntime/queueMicrotask.d.ts.map +1 -0
  259. package/lib/typescript/runLoop/workletRuntime/requestAnimationFramePolyfill.d.ts +2 -0
  260. package/lib/typescript/runLoop/workletRuntime/requestAnimationFramePolyfill.d.ts.map +1 -0
  261. package/lib/typescript/runLoop/workletRuntime/setTimeout.d.ts +2 -0
  262. package/lib/typescript/runLoop/workletRuntime/setTimeout.d.ts.map +1 -0
  263. package/lib/typescript/runLoop/workletRuntime/taskQueue.d.ts +10 -0
  264. package/lib/typescript/runLoop/workletRuntime/taskQueue.d.ts.map +1 -0
  265. package/lib/typescript/runtimeKind.d.ts +25 -0
  266. package/lib/typescript/runtimeKind.d.ts.map +1 -0
  267. package/lib/typescript/runtimes.d.ts +77 -0
  268. package/lib/typescript/runtimes.d.ts.map +1 -0
  269. package/lib/typescript/serializable.d.ts +20 -0
  270. package/lib/typescript/serializable.d.ts.map +1 -0
  271. package/lib/typescript/serializableMappingCache.d.ts +16 -0
  272. package/lib/typescript/serializableMappingCache.d.ts.map +1 -0
  273. package/lib/typescript/specs/NativeWorkletsModule.d.ts +7 -0
  274. package/lib/typescript/specs/NativeWorkletsModule.d.ts.map +1 -0
  275. package/lib/typescript/specs/NativeWorkletsModule.kepler.d.ts +7 -0
  276. package/lib/typescript/specs/NativeWorkletsModule.kepler.d.ts.map +1 -0
  277. package/lib/typescript/specs/index.d.ts +3 -0
  278. package/lib/typescript/specs/index.d.ts.map +1 -0
  279. package/lib/typescript/synchronizable.d.ts +15 -0
  280. package/lib/typescript/synchronizable.d.ts.map +1 -0
  281. package/lib/typescript/synchronizableUnpacker.d.ts +4 -0
  282. package/lib/typescript/synchronizableUnpacker.d.ts.map +1 -0
  283. package/lib/typescript/threads.d.ts +138 -0
  284. package/lib/typescript/threads.d.ts.map +1 -0
  285. package/lib/typescript/utils/checkCppVersion.d.ts +3 -0
  286. package/lib/typescript/utils/checkCppVersion.d.ts.map +1 -0
  287. package/lib/typescript/utils/jsVersion.d.ts +7 -0
  288. package/lib/typescript/utils/jsVersion.d.ts.map +1 -0
  289. package/lib/typescript/valueUnpacker.d.ts +6 -0
  290. package/lib/typescript/valueUnpacker.d.ts.map +1 -0
  291. package/lib/typescript/workletFunction.d.ts +27 -0
  292. package/lib/typescript/workletFunction.d.ts.map +1 -0
  293. package/lib/typescript/workletRuntimeEntry.d.ts +14 -0
  294. package/lib/typescript/workletRuntimeEntry.d.ts.map +1 -0
  295. package/lib/typescript/workletTypes.d.ts +61 -0
  296. package/lib/typescript/workletTypes.d.ts.map +1 -0
  297. package/package.json +153 -0
  298. package/plugin/index.js +1761 -0
  299. package/react-native.config.js +21 -0
  300. package/scripts/validate-react-native-version.js +43 -0
  301. package/scripts/worklets_utils.rb +94 -0
  302. package/src/PlatformChecker/PlatformChecker.ts +7 -0
  303. package/src/PlatformChecker/index.ts +30 -0
  304. package/src/WorkletsError.ts +36 -0
  305. package/src/WorkletsModule/JSWorklets.ts +200 -0
  306. package/src/WorkletsModule/NativeWorklets.ts +256 -0
  307. package/src/WorkletsModule/index.ts +7 -0
  308. package/src/WorkletsModule/workletsModuleInstance.ts +9 -0
  309. package/src/WorkletsModule/workletsModuleInstance.web.ts +5 -0
  310. package/src/WorkletsModule/workletsModuleProxy.ts +126 -0
  311. package/src/bundleUnpacker.ts +75 -0
  312. package/src/callGuard.ts +33 -0
  313. package/src/deprecated.ts +32 -0
  314. package/src/errors.ts +80 -0
  315. package/src/featureFlags/index.ts +72 -0
  316. package/src/featureFlags/staticFlags.json +4 -0
  317. package/src/index.ts +53 -0
  318. package/src/initializers.ts +262 -0
  319. package/src/isSynchronizable.ts +13 -0
  320. package/src/logger.ts +16 -0
  321. package/src/privateGlobals.d.ts +79 -0
  322. package/src/publicGlobals.ts +39 -0
  323. package/src/runLoop/common/setImmediatePolyfill.ts +20 -0
  324. package/src/runLoop/common/setIntervalPolyfill.ts +38 -0
  325. package/src/runLoop/uiRuntime/mockedRequestAnimationFrame.ts +11 -0
  326. package/src/runLoop/uiRuntime/requestAnimationFrame.ts +66 -0
  327. package/src/runLoop/uiRuntime/setTimeoutPolyfill.ts +40 -0
  328. package/src/runLoop/workletRuntime/index.ts +18 -0
  329. package/src/runLoop/workletRuntime/queueMicrotask.ts +13 -0
  330. package/src/runLoop/workletRuntime/requestAnimationFramePolyfill.ts +61 -0
  331. package/src/runLoop/workletRuntime/setTimeout.ts +37 -0
  332. package/src/runLoop/workletRuntime/taskQueue.ts +44 -0
  333. package/src/runtimeKind.ts +37 -0
  334. package/src/runtimes.ts +193 -0
  335. package/src/serializable.ts +801 -0
  336. package/src/serializableMappingCache.ts +42 -0
  337. package/src/specs/NativeWorkletsModule.kepler.ts +11 -0
  338. package/src/specs/NativeWorkletsModule.ts +9 -0
  339. package/src/specs/index.ts +13 -0
  340. package/src/synchronizable.ts +32 -0
  341. package/src/synchronizableUnpacker.ts +67 -0
  342. package/src/threads.ts +452 -0
  343. package/src/utils/checkCppVersion.ts +34 -0
  344. package/src/utils/jsVersion.ts +7 -0
  345. package/src/valueUnpacker.ts +90 -0
  346. package/src/workletFunction.ts +42 -0
  347. package/src/workletRuntimeEntry.ts +35 -0
  348. package/src/workletTypes.ts +81 -0
@@ -0,0 +1,712 @@
1
+ #include <react/renderer/uimanager/UIManagerBinding.h>
2
+ #include <react/renderer/uimanager/primitives.h>
3
+
4
+ #include <worklets/NativeModules/JSIWorkletsModuleProxy.h>
5
+ #include <worklets/NativeModules/WorkletsModuleProxy.h>
6
+ #include <worklets/SharedItems/Serializable.h>
7
+ #include <worklets/SharedItems/Synchronizable.h>
8
+ #include <worklets/Tools/Defs.h>
9
+ #include <worklets/Tools/FeatureFlags.h>
10
+ #include <worklets/Tools/JSLogger.h>
11
+ #include <worklets/WorkletRuntime/UIRuntimeDecorator.h>
12
+
13
+ #ifdef __ANDROID__
14
+ #include <fbjni/fbjni.h>
15
+ #endif // __ANDROID__
16
+
17
+ #include <utility>
18
+
19
+ using namespace facebook;
20
+
21
+ namespace worklets {
22
+
23
+ inline void scheduleOnUI(
24
+ const std::shared_ptr<UIScheduler> &uiScheduler,
25
+ const std::weak_ptr<WorkletRuntime> &weakUIWorkletRuntime,
26
+ jsi::Runtime &rt,
27
+ const jsi::Value &worklet) {
28
+ auto serializableWorklet = extractSerializableOrThrow<SerializableWorklet>(
29
+ rt, worklet, "[Worklets] Only worklets can be scheduled to run on UI.");
30
+ uiScheduler->scheduleOnUI([serializableWorklet, weakUIWorkletRuntime]() {
31
+ // This callback can outlive the WorkletsModuleProxy object during the
32
+ // invalidation of React Native. This happens when WorkletsModuleProxy
33
+ // destructor is called on the JS thread and the UI thread is
34
+ // executing callbacks from the `scheduleOnUI` queue. Therefore, we
35
+ // need to make sure it's still alive before we try to access it.
36
+ auto uiWorkletRuntime = weakUIWorkletRuntime.lock();
37
+ if (!uiWorkletRuntime) {
38
+ return;
39
+ }
40
+
41
+ #if JS_RUNTIME_HERMES
42
+ // JSI's scope defined here allows for JSI-objects to be cleared up
43
+ // after each runtime loop. Within these loops we typically create
44
+ // some temporary JSI objects and hence it allows for such objects to
45
+ // be garbage collected much sooner. Apparently the scope API is only
46
+ // supported on Hermes at the moment.
47
+ const auto scope = jsi::Scope(uiWorkletRuntime->getJSIRuntime());
48
+ #endif // JS_RUNTIME_HERMES
49
+
50
+ uiWorkletRuntime->runGuarded(serializableWorklet);
51
+ });
52
+ }
53
+
54
+ inline jsi::Value executeOnUIRuntimeSync(
55
+ const std::weak_ptr<WorkletRuntime> &weakUIWorkletRuntime,
56
+ jsi::Runtime &rt,
57
+ const jsi::Value &worklet) {
58
+ if (auto uiWorkletRuntime = weakUIWorkletRuntime.lock()) {
59
+ return uiWorkletRuntime->executeSync(rt, worklet);
60
+ }
61
+ return jsi::Value::undefined();
62
+ }
63
+
64
+ inline jsi::Value createWorkletRuntime(
65
+ jsi::Runtime &originRuntime,
66
+ const std::shared_ptr<RuntimeManager> &runtimeManager,
67
+ const std::shared_ptr<MessageQueueThread> &jsQueue,
68
+ std::shared_ptr<JSIWorkletsModuleProxy> jsiWorkletsModuleProxy,
69
+ const std::string &name,
70
+ std::shared_ptr<SerializableWorklet> &initializer,
71
+ const std::shared_ptr<AsyncQueue> &queue,
72
+ bool enableEventLoop) {
73
+ const auto workletRuntime = runtimeManager->createWorkletRuntime(
74
+ jsiWorkletsModuleProxy, name, initializer, queue);
75
+ return jsi::Object::createFromHostObject(originRuntime, workletRuntime);
76
+ }
77
+
78
+ #ifdef WORKLETS_BUNDLE_MODE
79
+ inline jsi::Value propagateModuleUpdate(
80
+ const std::shared_ptr<RuntimeManager> &runtimeManager,
81
+ const std::string &code,
82
+ const std::string &sourceUrl) {
83
+ const auto runtimes = runtimeManager->getAllRuntimes();
84
+
85
+ for (auto runtime : runtimes) {
86
+ runtime->executeSync([code, sourceUrl](jsi::Runtime &rt) {
87
+ const auto buffer = std::make_shared<jsi::StringBuffer>(code);
88
+ rt.evaluateJavaScript(buffer, sourceUrl);
89
+ return jsi::Value::undefined();
90
+ });
91
+ }
92
+ return jsi::Value::undefined();
93
+ }
94
+ #endif // WORKLETS_BUNDLE_MODE
95
+
96
+ inline jsi::Value reportFatalErrorOnJS(
97
+ const std::shared_ptr<JSScheduler> &jsScheduler,
98
+ const std::string &message,
99
+ const std::string &stack,
100
+ const std::string &name,
101
+ const std::string &jsEngine) {
102
+ JSLogger::reportFatalErrorOnJS(
103
+ jsScheduler,
104
+ JSErrorData{
105
+ .message = message,
106
+ .stack = stack,
107
+ .name = name,
108
+ .jsEngine = jsEngine});
109
+ return jsi::Value::undefined();
110
+ }
111
+
112
+ inline std::shared_ptr<AsyncQueue> extractAsyncQueue(
113
+ jsi::Runtime &rt,
114
+ const jsi::Value &value) {
115
+ if (!value.isObject()) {
116
+ return nullptr;
117
+ }
118
+ const auto object = value.asObject(rt);
119
+
120
+ if (!object.hasNativeState(rt)) {
121
+ return nullptr;
122
+ }
123
+
124
+ const auto &nativeState = object.getNativeState(rt);
125
+ auto asyncQueue = std::dynamic_pointer_cast<AsyncQueue>(nativeState);
126
+
127
+ return asyncQueue;
128
+ }
129
+
130
+ JSIWorkletsModuleProxy::JSIWorkletsModuleProxy(
131
+ const bool isDevBundle,
132
+ const std::shared_ptr<const BigStringBuffer> &script,
133
+ const std::string &sourceUrl,
134
+ const std::shared_ptr<MessageQueueThread> &jsQueue,
135
+ const std::shared_ptr<JSScheduler> &jsScheduler,
136
+ const std::shared_ptr<UIScheduler> &uiScheduler,
137
+ const std::shared_ptr<RuntimeManager> &runtimeManager,
138
+ const std::weak_ptr<WorkletRuntime> &uiWorkletRuntime)
139
+ : jsi::HostObject(),
140
+ isDevBundle_(isDevBundle),
141
+ script_(script),
142
+ sourceUrl_(sourceUrl),
143
+ jsQueue_(jsQueue),
144
+ jsScheduler_(jsScheduler),
145
+ uiScheduler_(uiScheduler),
146
+ runtimeManager_(runtimeManager),
147
+ uiWorkletRuntime_(uiWorkletRuntime) {}
148
+
149
+ JSIWorkletsModuleProxy::JSIWorkletsModuleProxy(
150
+ const JSIWorkletsModuleProxy &other)
151
+ : jsi::HostObject(),
152
+ isDevBundle_(other.isDevBundle_),
153
+ script_(other.script_),
154
+ sourceUrl_(other.sourceUrl_),
155
+ jsQueue_(other.jsQueue_),
156
+ jsScheduler_(other.jsScheduler_),
157
+ uiScheduler_(other.uiScheduler_),
158
+ runtimeManager_(other.runtimeManager_),
159
+ uiWorkletRuntime_(other.uiWorkletRuntime_) {}
160
+
161
+ JSIWorkletsModuleProxy::~JSIWorkletsModuleProxy() = default;
162
+
163
+ std::vector<jsi::PropNameID> JSIWorkletsModuleProxy::getPropertyNames(
164
+ jsi::Runtime &rt) {
165
+ std::vector<jsi::PropNameID> propertyNames;
166
+
167
+ propertyNames.emplace_back(
168
+ jsi::PropNameID::forAscii(rt, "createSerializable"));
169
+ propertyNames.emplace_back(
170
+ jsi::PropNameID::forAscii(rt, "createSerializableBigInt"));
171
+ propertyNames.emplace_back(
172
+ jsi::PropNameID::forAscii(rt, "createSerializableBoolean"));
173
+ propertyNames.emplace_back(
174
+ jsi::PropNameID::forAscii(rt, "createSerializableImport"));
175
+ propertyNames.emplace_back(
176
+ jsi::PropNameID::forAscii(rt, "createSerializableNull"));
177
+ propertyNames.emplace_back(
178
+ jsi::PropNameID::forAscii(rt, "createSerializableNumber"));
179
+ propertyNames.emplace_back(
180
+ jsi::PropNameID::forAscii(rt, "createSerializableString"));
181
+ propertyNames.emplace_back(
182
+ jsi::PropNameID::forAscii(rt, "createSerializableUndefined"));
183
+ propertyNames.emplace_back(
184
+ jsi::PropNameID::forAscii(rt, "createSerializableHostObject"));
185
+ propertyNames.emplace_back(
186
+ jsi::PropNameID::forAscii(rt, "createSerializableInitializer"));
187
+ propertyNames.emplace_back(
188
+ jsi::PropNameID::forAscii(rt, "createSerializableArray"));
189
+ propertyNames.emplace_back(
190
+ jsi::PropNameID::forAscii(rt, "createSerializableFunction"));
191
+ propertyNames.emplace_back(
192
+ jsi::PropNameID::forAscii(rt, "createSerializableTurboModuleLike"));
193
+ propertyNames.emplace_back(
194
+ jsi::PropNameID::forAscii(rt, "createSerializableObject"));
195
+ propertyNames.emplace_back(
196
+ jsi::PropNameID::forAscii(rt, "createSerializableMap"));
197
+ propertyNames.emplace_back(
198
+ jsi::PropNameID::forAscii(rt, "createSerializableSet"));
199
+ propertyNames.emplace_back(
200
+ jsi::PropNameID::forAscii(rt, "createSerializableWorklet"));
201
+
202
+ propertyNames.emplace_back(jsi::PropNameID::forAscii(rt, "scheduleOnUI"));
203
+ propertyNames.emplace_back(
204
+ jsi::PropNameID::forAscii(rt, "executeOnUIRuntimeSync"));
205
+ propertyNames.emplace_back(
206
+ jsi::PropNameID::forAscii(rt, "createWorkletRuntime"));
207
+ propertyNames.emplace_back(
208
+ jsi::PropNameID::forAscii(rt, "scheduleOnRuntime"));
209
+ propertyNames.emplace_back(
210
+ jsi::PropNameID::forAscii(rt, "reportFatalErrorOnJS"));
211
+
212
+ propertyNames.emplace_back(
213
+ jsi::PropNameID::forAscii(rt, "getStaticFeatureFlag"));
214
+ propertyNames.emplace_back(
215
+ jsi::PropNameID::forAscii(rt, "setDynamicFeatureFlag"));
216
+
217
+ propertyNames.emplace_back(
218
+ jsi::PropNameID::forAscii(rt, "createSynchronizable"));
219
+ propertyNames.emplace_back(
220
+ jsi::PropNameID::forAscii(rt, "synchronizableGetDirty"));
221
+ propertyNames.emplace_back(
222
+ jsi::PropNameID::forAscii(rt, "synchronizableGetBlocking"));
223
+ propertyNames.emplace_back(
224
+ jsi::PropNameID::forAscii(rt, "synchronizableSetBlocking"));
225
+ propertyNames.emplace_back(
226
+ jsi::PropNameID::forAscii(rt, "synchronizableLock"));
227
+ propertyNames.emplace_back(
228
+ jsi::PropNameID::forAscii(rt, "synchronizableUnlock"));
229
+
230
+ #ifdef WORKLETS_BUNDLE_MODE
231
+ propertyNames.emplace_back(
232
+ jsi::PropNameID::forAscii(rt, "propagateModuleUpdate"));
233
+ #endif // WORKLETS_BUNDLE_MODE
234
+
235
+ return propertyNames;
236
+ }
237
+
238
+ jsi::Value JSIWorkletsModuleProxy::get(
239
+ jsi::Runtime &rt,
240
+ const jsi::PropNameID &propName) {
241
+ const auto name = propName.utf8(rt);
242
+
243
+ if (name == "createSerializable") {
244
+ return jsi::Function::createFromHostFunction(
245
+ rt,
246
+ propName,
247
+ 3,
248
+ [](jsi::Runtime &rt,
249
+ const jsi::Value &thisValue,
250
+ const jsi::Value *args,
251
+ size_t count) {
252
+ return makeSerializableClone(rt, args[0], args[1], args[2]);
253
+ });
254
+ }
255
+
256
+ if (name == "createSerializableBigInt") {
257
+ return jsi::Function::createFromHostFunction(
258
+ rt,
259
+ propName,
260
+ 1,
261
+ [](jsi::Runtime &rt,
262
+ const jsi::Value &thisValue,
263
+ const jsi::Value *args,
264
+ size_t count) {
265
+ return makeSerializableBigInt(rt, args[0].asBigInt(rt));
266
+ });
267
+ }
268
+
269
+ if (name == "createSerializableBoolean") {
270
+ return jsi::Function::createFromHostFunction(
271
+ rt,
272
+ propName,
273
+ 1,
274
+ [](jsi::Runtime &rt,
275
+ const jsi::Value &thisValue,
276
+ const jsi::Value *args,
277
+ size_t count) {
278
+ return makeSerializableBoolean(rt, args[0].asBool());
279
+ });
280
+ }
281
+
282
+ if (name == "createSerializableImport") {
283
+ return jsi::Function::createFromHostFunction(
284
+ rt,
285
+ propName,
286
+ 2,
287
+ [](jsi::Runtime &rt,
288
+ const jsi::Value &thisValue,
289
+ const jsi::Value *args,
290
+ size_t count) {
291
+ return makeSerializableImport(
292
+ rt, args[0].asNumber(), args[1].asString(rt));
293
+ });
294
+ }
295
+
296
+ if (name == "createSerializableNumber") {
297
+ return jsi::Function::createFromHostFunction(
298
+ rt,
299
+ propName,
300
+ 1,
301
+ [](jsi::Runtime &rt,
302
+ const jsi::Value &thisValue,
303
+ const jsi::Value *args,
304
+ size_t count) {
305
+ return makeSerializableNumber(rt, args[0].asNumber());
306
+ });
307
+ }
308
+
309
+ if (name == "createSerializableNull") {
310
+ return jsi::Function::createFromHostFunction(
311
+ rt,
312
+ propName,
313
+ 0,
314
+ [](jsi::Runtime &rt,
315
+ const jsi::Value &thisValue,
316
+ const jsi::Value *args,
317
+ size_t count) { return makeSerializableNull(rt); });
318
+ }
319
+
320
+ if (name == "createSerializableString") {
321
+ return jsi::Function::createFromHostFunction(
322
+ rt,
323
+ propName,
324
+ 1,
325
+ [](jsi::Runtime &rt,
326
+ const jsi::Value &thisValue,
327
+ const jsi::Value *args,
328
+ size_t count) {
329
+ return makeSerializableString(rt, args[0].asString(rt));
330
+ });
331
+ }
332
+
333
+ if (name == "createSerializableUndefined") {
334
+ return jsi::Function::createFromHostFunction(
335
+ rt,
336
+ propName,
337
+ 0,
338
+ [](jsi::Runtime &rt,
339
+ const jsi::Value &thisValue,
340
+ const jsi::Value *args,
341
+ size_t count) { return makeSerializableUndefined(rt); });
342
+ }
343
+
344
+ if (name == "createSerializableInitializer") {
345
+ return jsi::Function::createFromHostFunction(
346
+ rt,
347
+ propName,
348
+ 1,
349
+ [](jsi::Runtime &rt,
350
+ const jsi::Value &thisValue,
351
+ const jsi::Value *args,
352
+ size_t count) {
353
+ return makeSerializableInitializer(rt, args[0].asObject(rt));
354
+ });
355
+ }
356
+
357
+ if (name == "createSerializableArray") {
358
+ return jsi::Function::createFromHostFunction(
359
+ rt,
360
+ propName,
361
+ 2,
362
+ [](jsi::Runtime &rt,
363
+ const jsi::Value &thisValue,
364
+ const jsi::Value *args,
365
+ size_t count) {
366
+ return makeSerializableArray(
367
+ rt, args[0].asObject(rt).asArray(rt), args[1]);
368
+ });
369
+ }
370
+
371
+ if (name == "createSerializableMap") {
372
+ return jsi::Function::createFromHostFunction(
373
+ rt,
374
+ propName,
375
+ 2,
376
+ [](jsi::Runtime &rt,
377
+ const jsi::Value &thisValue,
378
+ const jsi::Value *args,
379
+ size_t count) {
380
+ return makeSerializableMap(
381
+ rt,
382
+ args[0].asObject(rt).asArray(rt),
383
+ args[1].asObject(rt).asArray(rt));
384
+ });
385
+ }
386
+
387
+ if (name == "createSerializableSet") {
388
+ return jsi::Function::createFromHostFunction(
389
+ rt,
390
+ propName,
391
+ 1,
392
+ [](jsi::Runtime &rt,
393
+ const jsi::Value &thisValue,
394
+ const jsi::Value *args,
395
+ size_t count) {
396
+ return makeSerializableSet(rt, args[0].asObject(rt).asArray(rt));
397
+ });
398
+ }
399
+
400
+ if (name == "createSerializableHostObject") {
401
+ return jsi::Function::createFromHostFunction(
402
+ rt,
403
+ propName,
404
+ 1,
405
+ [](jsi::Runtime &rt,
406
+ const jsi::Value &thisValue,
407
+ const jsi::Value *args,
408
+ size_t count) {
409
+ return makeSerializableHostObject(
410
+ rt, args[0].asObject(rt).asHostObject(rt));
411
+ });
412
+ }
413
+
414
+ if (name == "createSerializableFunction") {
415
+ return jsi::Function::createFromHostFunction(
416
+ rt,
417
+ propName,
418
+ 1,
419
+ [](jsi::Runtime &rt,
420
+ const jsi::Value &thisValue,
421
+ const jsi::Value *args,
422
+ size_t count) {
423
+ return makeSerializableFunction(
424
+ rt, args[0].asObject(rt).asFunction(rt));
425
+ });
426
+ }
427
+
428
+ if (name == "createSerializableTurboModuleLike") {
429
+ return jsi::Function::createFromHostFunction(
430
+ rt,
431
+ propName,
432
+ 2,
433
+ [](jsi::Runtime &rt,
434
+ const jsi::Value &thisValue,
435
+ const jsi::Value *args,
436
+ size_t count) {
437
+ return makeSerializableTurboModuleLike(
438
+ rt, args[0].asObject(rt), args[1].asObject(rt).asHostObject(rt));
439
+ });
440
+ }
441
+
442
+ if (name == "createSerializableObject") {
443
+ return jsi::Function::createFromHostFunction(
444
+ rt,
445
+ propName,
446
+ 1,
447
+ [](jsi::Runtime &rt,
448
+ const jsi::Value &thisValue,
449
+ const jsi::Value *args,
450
+ size_t count) {
451
+ return makeSerializableObject(
452
+ rt, args[0].getObject(rt), args[1].getBool(), args[2]);
453
+ });
454
+ }
455
+
456
+ if (name == "createSerializableWorklet") {
457
+ return jsi::Function::createFromHostFunction(
458
+ rt,
459
+ propName,
460
+ 2,
461
+ [](jsi::Runtime &rt,
462
+ const jsi::Value &thisValue,
463
+ const jsi::Value *args,
464
+ size_t count) {
465
+ return makeSerializableWorklet(
466
+ rt, args[0].getObject(rt), args[1].getBool());
467
+ });
468
+ }
469
+
470
+ if (name == "scheduleOnUI") {
471
+ return jsi::Function::createFromHostFunction(
472
+ rt,
473
+ propName,
474
+ 1,
475
+ [uiScheduler = uiScheduler_, uiWorkletRuntime = uiWorkletRuntime_](
476
+ jsi::Runtime &rt,
477
+ const jsi::Value &thisValue,
478
+ const jsi::Value *args,
479
+ size_t count) {
480
+ scheduleOnUI(uiScheduler, uiWorkletRuntime, rt, args[0]);
481
+ return jsi::Value::undefined();
482
+ });
483
+ }
484
+
485
+ if (name == "executeOnUIRuntimeSync") {
486
+ return jsi::Function::createFromHostFunction(
487
+ rt,
488
+ propName,
489
+ 1,
490
+ [uiWorkletRuntime = uiWorkletRuntime_](
491
+ jsi::Runtime &rt,
492
+ const jsi::Value &thisValue,
493
+ const jsi::Value *args,
494
+ size_t count) {
495
+ return executeOnUIRuntimeSync(uiWorkletRuntime, rt, args[0]);
496
+ });
497
+ }
498
+
499
+ if (name == "createWorkletRuntime") {
500
+ return jsi::Function::createFromHostFunction(
501
+ rt,
502
+ propName,
503
+ 5,
504
+ [clone = std::make_shared<JSIWorkletsModuleProxy>(*this)](
505
+ jsi::Runtime &rt,
506
+ const jsi::Value &thisValue,
507
+ const jsi::Value *args,
508
+ size_t count) {
509
+ const auto name = args[0].asString(rt).utf8(rt);
510
+ auto serializableInitializer =
511
+ extractSerializableOrThrow<SerializableWorklet>(
512
+ rt, args[1], "[Worklets] Initializer must be a worklet.");
513
+ const auto useDefaultQueue = args[2].asBool();
514
+
515
+ std::shared_ptr<AsyncQueue> asyncQueue;
516
+ if (useDefaultQueue) {
517
+ asyncQueue = std::make_shared<AsyncQueueImpl>(name + "_queue");
518
+ } else {
519
+ asyncQueue = extractAsyncQueue(rt, args[3]);
520
+ }
521
+
522
+ const auto enableEventLoop = args[4].asBool();
523
+
524
+ return createWorkletRuntime(
525
+ rt,
526
+ clone->getRuntimeManager(),
527
+ clone->getJSQueue(),
528
+ clone,
529
+ name,
530
+ serializableInitializer,
531
+ asyncQueue,
532
+ enableEventLoop);
533
+ });
534
+ }
535
+
536
+ if (name == "scheduleOnRuntime") {
537
+ return jsi::Function::createFromHostFunction(
538
+ rt,
539
+ propName,
540
+ 2,
541
+ [](jsi::Runtime &rt,
542
+ const jsi ::Value &thisValue,
543
+ const jsi::Value *args,
544
+ size_t count) {
545
+ worklets::scheduleOnRuntime(rt, args[0], args[1]);
546
+ return jsi::Value::undefined();
547
+ });
548
+ }
549
+
550
+ if (name == "reportFatalErrorOnJS") {
551
+ return jsi::Function::createFromHostFunction(
552
+ rt,
553
+ propName,
554
+ 4,
555
+ [jsScheduler = jsScheduler_](
556
+ jsi::Runtime &rt,
557
+ const jsi::Value &thisValue,
558
+ const jsi::Value *args,
559
+ size_t count) {
560
+ return reportFatalErrorOnJS(
561
+ jsScheduler,
562
+ /* message */ args[0].asString(rt).utf8(rt),
563
+ /* stack */ args[1].asString(rt).utf8(rt),
564
+ /* name */ args[2].asString(rt).utf8(rt),
565
+ /* jsEngine */ args[3].asString(rt).utf8(rt));
566
+ });
567
+ }
568
+
569
+ if (name == "createSynchronizable") {
570
+ return jsi::Function::createFromHostFunction(
571
+ rt,
572
+ propName,
573
+ 1,
574
+ [](jsi::Runtime &rt,
575
+ const jsi::Value &thisValue,
576
+ const jsi::Value *args,
577
+ size_t count) {
578
+ auto initial = extractSerializableOrThrow(
579
+ rt, args[0], "[Worklets] Value must be a Serializable.");
580
+ auto synchronizable = std::make_shared<Synchronizable>(initial);
581
+ return SerializableJSRef::newNativeStateObject(rt, synchronizable);
582
+ });
583
+ }
584
+
585
+ if (name == "synchronizableGetDirty") {
586
+ return jsi::Function::createFromHostFunction(
587
+ rt,
588
+ propName,
589
+ 1,
590
+ [](jsi::Runtime &rt,
591
+ const jsi::Value &thisValue,
592
+ const jsi::Value *args,
593
+ size_t count) {
594
+ auto synchronizable = extractSynchronizableOrThrow(rt, args[0]);
595
+ return synchronizable->getDirty()->toJSValue(rt);
596
+ });
597
+ }
598
+
599
+ if (name == "synchronizableGetBlocking") {
600
+ return jsi::Function::createFromHostFunction(
601
+ rt,
602
+ propName,
603
+ 1,
604
+ [](jsi::Runtime &rt,
605
+ const jsi::Value &thisValue,
606
+ const jsi::Value *args,
607
+ size_t count) {
608
+ auto synchronizable = extractSynchronizableOrThrow(rt, args[0]);
609
+ return synchronizable->getBlocking()->toJSValue(rt);
610
+ });
611
+ }
612
+
613
+ if (name == "synchronizableSetBlocking") {
614
+ return jsi::Function::createFromHostFunction(
615
+ rt,
616
+ propName,
617
+ 2,
618
+ [](jsi::Runtime &rt,
619
+ const jsi::Value &thisValue,
620
+ const jsi::Value *args,
621
+ size_t count) {
622
+ auto synchronizable = extractSynchronizableOrThrow(rt, args[0]);
623
+ auto newValue = extractSerializableOrThrow(
624
+ rt, args[1], "[Worklets] Value must be a Serializable.");
625
+ synchronizable->setBlocking(std::move(newValue));
626
+ return jsi::Value::undefined();
627
+ });
628
+ }
629
+
630
+ if (name == "synchronizableLock") {
631
+ return jsi::Function::createFromHostFunction(
632
+ rt,
633
+ propName,
634
+ 1,
635
+ [](jsi::Runtime &rt,
636
+ const jsi::Value &thisValue,
637
+ const jsi::Value *args,
638
+ size_t count) {
639
+ auto synchronizable = extractSynchronizableOrThrow(rt, args[0]);
640
+ synchronizable->lock();
641
+ return jsi::Value::undefined();
642
+ });
643
+ }
644
+
645
+ if (name == "synchronizableUnlock") {
646
+ return jsi::Function::createFromHostFunction(
647
+ rt,
648
+ propName,
649
+ 1,
650
+ [](jsi::Runtime &rt,
651
+ const jsi::Value &thisValue,
652
+ const jsi::Value *args,
653
+ size_t count) {
654
+ auto synchronizable = extractSynchronizableOrThrow(rt, args[0]);
655
+ synchronizable->unlock();
656
+ return jsi::Value::undefined();
657
+ });
658
+ }
659
+
660
+ #ifdef WORKLETS_BUNDLE_MODE
661
+ if (name == "propagateModuleUpdate") {
662
+ return jsi::Function::createFromHostFunction(
663
+ rt,
664
+ propName,
665
+ 2,
666
+ [runtimeManager = runtimeManager_](
667
+ jsi::Runtime &rt,
668
+ const jsi::Value &thisValue,
669
+ const jsi::Value *args,
670
+ size_t count) {
671
+ return propagateModuleUpdate(
672
+ runtimeManager,
673
+ /* code */ args[0].asString(rt).utf8(rt),
674
+ /* sourceURL */ args[1].asString(rt).utf8(rt));
675
+ });
676
+ }
677
+ #endif // WORKLETS_BUNDLE_MODE
678
+
679
+ if (name == "getStaticFeatureFlag") {
680
+ return jsi::Function::createFromHostFunction(
681
+ rt,
682
+ propName,
683
+ 2,
684
+ [](jsi::Runtime &rt,
685
+ const jsi::Value &thisValue,
686
+ const jsi::Value *args,
687
+ size_t count) {
688
+ return worklets::StaticFeatureFlags::getFlag(
689
+ /* name */ args[0].asString(rt).utf8(rt));
690
+ });
691
+ }
692
+
693
+ if (name == "setDynamicFeatureFlag") {
694
+ return jsi::Function::createFromHostFunction(
695
+ rt,
696
+ propName,
697
+ 2,
698
+ [](jsi::Runtime &rt,
699
+ const jsi::Value &thisValue,
700
+ const jsi::Value *args,
701
+ size_t count) {
702
+ worklets::DynamicFeatureFlags::setFlag(
703
+ /* name */ args[0].asString(rt).utf8(rt),
704
+ /* value */ args[1].asBool());
705
+ return jsi::Value::undefined();
706
+ });
707
+ }
708
+
709
+ return jsi::Value::undefined();
710
+ }
711
+
712
+ } // namespace worklets