@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,312 @@
1
+ #include <worklets/Tools/JSISerializer.h>
2
+
3
+ #include <cxxabi.h>
4
+
5
+ #include <memory>
6
+ #include <sstream>
7
+ #include <string>
8
+ #include <vector>
9
+
10
+ namespace worklets {
11
+
12
+ const std::vector<std::string> SUPPORTED_ERROR_TYPES = {
13
+ "Error",
14
+ "AggregateError",
15
+ "EvalError",
16
+ "RangeError",
17
+ "ReferenceError",
18
+ "SyntaxError",
19
+ "TypeError",
20
+ "URIError",
21
+ "InternalError"};
22
+
23
+ const std::vector<std::string> SUPPORTED_INDEXED_COLLECTION_TYPES = {
24
+ "Int8Array",
25
+ "Uint8Array",
26
+ "Uint8ClampedArray",
27
+ "Int16Array",
28
+ "Uint16Array",
29
+ "Int32Array",
30
+ "Uint32Array",
31
+ "BigInt64Array",
32
+ "BigUint64Array",
33
+ "Float32Array",
34
+ "Float64Array",
35
+ };
36
+
37
+ const std::vector<std::string> SUPPORTED_STRUCTURED_DATA_TYPES = {
38
+ "ArrayBuffer",
39
+ "SharedArrayBuffer",
40
+ "DataView",
41
+ "Atomics",
42
+ "JSON",
43
+ };
44
+
45
+ const std::vector<std::string> SUPPORTED_MANAGING_MEMORY_TYPES = {
46
+ "WeakRef",
47
+ "FinalizationRegistry",
48
+ };
49
+
50
+ const std::vector<std::string> SUPPORTED_ABSTRACTION_OBJECT_TYPES = {
51
+ "Iterator",
52
+ "AsyncIterator",
53
+ "Promise",
54
+ "GeneratorFunction",
55
+ "AsyncGeneratorFunction",
56
+ "Generator",
57
+ "AsyncGenerator",
58
+ "AsyncFunction",
59
+ };
60
+
61
+ const std::vector<std::string> SUPPORTED_REFLECTION_TYPES = {
62
+ "Reflect",
63
+ "Proxy",
64
+ };
65
+
66
+ static inline std::string getObjectTypeName(jsi::Runtime &rt, const jsi::Object &object) {
67
+ return object.getPropertyAsObject(rt, "constructor").getProperty(rt, "name").toString(rt).utf8(rt);
68
+ }
69
+
70
+ static inline bool isInstanceOf(jsi::Runtime &rt, const jsi::Object &object, const std::string &type) {
71
+ return getObjectTypeName(rt, object) == type;
72
+ }
73
+
74
+ static inline bool
75
+ isInstanceOfAny(jsi::Runtime &rt, const jsi::Object &object, const std::vector<std::string> &supportedTypes) {
76
+ auto instanceType = getObjectTypeName(rt, object);
77
+
78
+ return std::find(supportedTypes.begin(), supportedTypes.end(), instanceType) != supportedTypes.end();
79
+ }
80
+
81
+ JSISerializer::JSISerializer(jsi::Runtime &rt)
82
+ : rt_(rt), visitedNodes_(rt_.global().getPropertyAsFunction(rt_, "Set").callAsConstructor(rt_).asObject(rt_)) {}
83
+
84
+ std::string JSISerializer::stringifyWithName(const jsi::Object &object) {
85
+ std::stringstream ss;
86
+ ss << '[' << getObjectTypeName(rt_, object) << ']';
87
+
88
+ return ss.str();
89
+ }
90
+
91
+ std::string JSISerializer::stringifyArray(const jsi::Array &arr) {
92
+ std::stringstream ss;
93
+ ss << '[';
94
+
95
+ for (size_t i = 0, length = arr.size(rt_); i < length; i++) {
96
+ jsi::Value element = arr.getValueAtIndex(rt_, i);
97
+ ss << stringifyJSIValueRecursively(element);
98
+ if (i != length - 1) {
99
+ ss << ", ";
100
+ }
101
+ }
102
+
103
+ ss << ']';
104
+
105
+ return ss.str();
106
+ }
107
+
108
+ std::string JSISerializer::stringifyFunction(const jsi::Function &func) {
109
+ std::stringstream ss;
110
+ auto kind = (func.isHostFunction(rt_) ? "jsi::HostFunction" : "Function");
111
+ auto name = func.getProperty(rt_, "name").toString(rt_).utf8(rt_);
112
+ name = name.empty() ? "anonymous" : name;
113
+
114
+ ss << '[' << kind << ' ' << name << ']';
115
+ return ss.str();
116
+ }
117
+
118
+ std::string JSISerializer::stringifyHostObject(jsi::HostObject &hostObject) {
119
+ int status = -1;
120
+ std::unique_ptr<char, decltype(&std::free)> hostObjClassName(
121
+ abi::__cxa_demangle(typeid(hostObject).name(), nullptr, nullptr, &status), std::free);
122
+ if (status != 0) {
123
+ return "[jsi::HostObject]";
124
+ }
125
+
126
+ std::stringstream ss;
127
+ ss << "[jsi::HostObject(" << hostObjClassName.get() << ")";
128
+
129
+ auto props = hostObject.getPropertyNames(rt_);
130
+ auto propsCount = props.size();
131
+
132
+ if (propsCount > 0) {
133
+ ss << " {";
134
+ auto lastKey = props.back().utf8(rt_);
135
+ for (const auto &key : props) {
136
+ auto formattedKey = key.utf8(rt_);
137
+ auto value = hostObject.get(rt_, key);
138
+ ss << '"' << formattedKey << '"' << ": " << stringifyJSIValueRecursively(value);
139
+ if (formattedKey != lastKey) {
140
+ ss << ", ";
141
+ }
142
+ }
143
+ ss << '}';
144
+ }
145
+ ss << ']';
146
+
147
+ return ss.str();
148
+ }
149
+
150
+ std::string JSISerializer::stringifyObject(const jsi::Object &object) {
151
+ std::stringstream ss;
152
+ ss << '{';
153
+
154
+ auto props = object.getPropertyNames(rt_);
155
+
156
+ for (size_t i = 0, propsCount = props.size(rt_); i < propsCount; i++) {
157
+ jsi::String propName = props.getValueAtIndex(rt_, i).toString(rt_);
158
+ ss << '"' << propName.utf8(rt_) << '"' << ": " << stringifyJSIValueRecursively(object.getProperty(rt_, propName));
159
+ if (i != propsCount - 1) {
160
+ ss << ", ";
161
+ }
162
+ }
163
+
164
+ ss << '}';
165
+
166
+ return ss.str();
167
+ }
168
+
169
+ std::string JSISerializer::stringifyError(const jsi::Object &object) {
170
+ std::stringstream ss;
171
+ ss << '[' << object.getProperty(rt_, "name").toString(rt_).utf8(rt_) << ": "
172
+ << object.getProperty(rt_, "message").toString(rt_).utf8(rt_) << ']';
173
+ return ss.str();
174
+ }
175
+
176
+ std::string JSISerializer::stringifySet(const jsi::Object &object) {
177
+ std::stringstream ss;
178
+ jsi::Function arrayFrom = rt_.global().getPropertyAsObject(rt_, "Array").getPropertyAsFunction(rt_, "from");
179
+ jsi::Object result = arrayFrom.call(rt_, object).asObject(rt_);
180
+
181
+ if (!result.isArray(rt_)) {
182
+ return "[Set]";
183
+ }
184
+
185
+ auto arr = result.asArray(rt_);
186
+ ss << "Set {";
187
+
188
+ for (size_t i = 0, length = arr.size(rt_); i < length; i++) {
189
+ ss << stringifyJSIValueRecursively(arr.getValueAtIndex(rt_, i));
190
+ if (i != length - 1) {
191
+ ss << ", ";
192
+ }
193
+ }
194
+
195
+ ss << '}';
196
+
197
+ return ss.str();
198
+ }
199
+
200
+ std::string JSISerializer::stringifyMap(const jsi::Object &object) {
201
+ std::stringstream ss;
202
+ jsi::Function arrayFrom = rt_.global().getPropertyAsObject(rt_, "Array").getPropertyAsFunction(rt_, "from");
203
+ jsi::Object result = arrayFrom.call(rt_, object).asObject(rt_);
204
+
205
+ if (!result.isArray(rt_)) {
206
+ return "[Map]";
207
+ }
208
+
209
+ auto arr = result.asArray(rt_);
210
+ ss << "Map {";
211
+
212
+ for (size_t i = 0, length = arr.size(rt_); i < length; i++) {
213
+ auto pair = arr.getValueAtIndex(rt_, i).asObject(rt_).getArray(rt_);
214
+ auto key = pair.getValueAtIndex(rt_, 0);
215
+ auto value = pair.getValueAtIndex(rt_, 1);
216
+ ss << stringifyJSIValueRecursively(key) << ": " << stringifyJSIValueRecursively(value);
217
+ if (i != length - 1) {
218
+ ss << ", ";
219
+ }
220
+ }
221
+
222
+ ss << '}';
223
+
224
+ return ss.str();
225
+ }
226
+
227
+ std::string JSISerializer::stringifyRecursiveType(const jsi::Object &object) {
228
+ auto type = getObjectTypeName(rt_, object);
229
+
230
+ if (type == "Array") {
231
+ return "[...]";
232
+ }
233
+ if (type == "Object") {
234
+ return "{...}";
235
+ }
236
+ return "...";
237
+ }
238
+
239
+ std::string JSISerializer::stringifyWithToString(const jsi::Object &object) {
240
+ return object.getPropertyAsFunction(rt_, "toString").callWithThis(rt_, object).toString(rt_).utf8(rt_);
241
+ }
242
+
243
+ std::string JSISerializer::stringifyJSIValueRecursively(const jsi::Value &value, bool isTopLevel) {
244
+ if (value.isBool() || value.isNumber()) {
245
+ return value.toString(rt_).utf8(rt_);
246
+ }
247
+ if (value.isString()) {
248
+ return isTopLevel ? value.getString(rt_).utf8(rt_) : '"' + value.getString(rt_).utf8(rt_) + '"';
249
+ }
250
+ if (value.isSymbol()) {
251
+ return value.getSymbol(rt_).toString(rt_);
252
+ }
253
+ if (value.isBigInt()) {
254
+ return value.getBigInt(rt_).toString(rt_).utf8(rt_) + 'n';
255
+ }
256
+ if (value.isUndefined()) {
257
+ return "undefined";
258
+ }
259
+ if (value.isNull()) {
260
+ return "null";
261
+ }
262
+ if (value.isObject()) {
263
+ jsi::Object object = value.asObject(rt_);
264
+
265
+ if (hasBeenVisited(object)) {
266
+ return stringifyRecursiveType(object);
267
+ }
268
+ markAsVisited(object);
269
+
270
+ if (object.isArray(rt_)) {
271
+ return stringifyArray(object.getArray(rt_));
272
+ }
273
+ if (object.isFunction(rt_)) {
274
+ return stringifyFunction(object.getFunction(rt_));
275
+ }
276
+ if (object.isHostObject(rt_)) {
277
+ return stringifyHostObject(*object.getHostObject(rt_));
278
+ }
279
+ if (isInstanceOfAny(rt_, object, SUPPORTED_ERROR_TYPES)) {
280
+ return stringifyError(object);
281
+ }
282
+ if (isInstanceOfAny(rt_, object, SUPPORTED_INDEXED_COLLECTION_TYPES) ||
283
+ isInstanceOfAny(rt_, object, SUPPORTED_STRUCTURED_DATA_TYPES) ||
284
+ isInstanceOfAny(rt_, object, SUPPORTED_MANAGING_MEMORY_TYPES) ||
285
+ isInstanceOfAny(rt_, object, SUPPORTED_ABSTRACTION_OBJECT_TYPES) ||
286
+ isInstanceOfAny(rt_, object, SUPPORTED_REFLECTION_TYPES) || isInstanceOf(rt_, object, "Intl") ||
287
+ isInstanceOf(rt_, object, "WeakMap") || isInstanceOf(rt_, object, "WeakSet")) {
288
+ // TODO: Consider extending this log info
289
+ return stringifyWithName(object);
290
+ }
291
+ if (isInstanceOf(rt_, object, "Date") || isInstanceOf(rt_, object, "RegExp")) {
292
+ return stringifyWithToString(object);
293
+ }
294
+ if (isInstanceOf(rt_, object, "Map")) {
295
+ return stringifyMap(object);
296
+ }
297
+ if (isInstanceOf(rt_, object, "Set")) {
298
+ return stringifySet(object);
299
+ }
300
+ return stringifyObject(object);
301
+ }
302
+
303
+ throw std::runtime_error("[Worklets] Unsupported value type.");
304
+ }
305
+
306
+ std::string stringifyJSIValue(jsi::Runtime &rt, const jsi::Value &value) {
307
+ JSISerializer serializer(rt);
308
+
309
+ return serializer.stringifyJSIValueRecursively(value, true);
310
+ }
311
+
312
+ } // namespace worklets
@@ -0,0 +1,42 @@
1
+ #pragma once
2
+
3
+ #include <jsi/jsi.h>
4
+ #include <string>
5
+ #include <vector>
6
+
7
+ using namespace facebook;
8
+
9
+ namespace worklets {
10
+
11
+ class JSISerializer {
12
+ public:
13
+ explicit JSISerializer(jsi::Runtime &rt);
14
+ std::string stringifyJSIValueRecursively(const jsi::Value &value, bool isTopLevel = false);
15
+
16
+ private:
17
+ std::string stringifyArray(const jsi::Array &arr);
18
+ std::string stringifyFunction(const jsi::Function &func);
19
+ std::string stringifyHostObject(jsi::HostObject &hostObject);
20
+ std::string stringifyObject(const jsi::Object &object);
21
+ std::string stringifyError(const jsi::Object &object);
22
+ std::string stringifySet(const jsi::Object &object);
23
+ std::string stringifyMap(const jsi::Object &object);
24
+ std::string stringifyWithName(const jsi::Object &object);
25
+ std::string stringifyWithToString(const jsi::Object &object);
26
+ std::string stringifyRecursiveType(const jsi::Object &object);
27
+
28
+ bool hasBeenVisited(const jsi::Object &object) {
29
+ return visitedNodes_.getPropertyAsFunction(rt_, "has").callWithThis(rt_, visitedNodes_, object).getBool();
30
+ }
31
+
32
+ void markAsVisited(const jsi::Object &object) {
33
+ visitedNodes_.getPropertyAsFunction(rt_, "add").callWithThis(rt_, visitedNodes_, object);
34
+ }
35
+
36
+ jsi::Runtime &rt_;
37
+ jsi::Object visitedNodes_;
38
+ };
39
+
40
+ std::string stringifyJSIValue(jsi::Runtime &rt, const jsi::Value &value);
41
+
42
+ } // namespace worklets
@@ -0,0 +1,92 @@
1
+ #include <worklets/Tools/JSLogger.h>
2
+
3
+ #include <memory>
4
+ #include <string>
5
+ #include <utility>
6
+
7
+ namespace worklets {
8
+
9
+ void JSLogger::warnOnJS(const std::string &warning) const {
10
+ #ifndef NDEBUG
11
+ jsScheduler_->scheduleOnJS([warning](jsi::Runtime &rnRuntime) {
12
+ auto console = rnRuntime.global().getPropertyAsObject(rnRuntime, "console");
13
+ auto warn = console.getPropertyAsFunction(rnRuntime, "warn");
14
+ warn.call(rnRuntime, jsi::String::createFromUtf8(rnRuntime, warning));
15
+ });
16
+ #endif // NDEBUG
17
+ }
18
+
19
+ void JSLogger::reportFatalErrorOnJS(
20
+ const std::shared_ptr<JSScheduler> &jsScheduler,
21
+ JSErrorData &&jsErrorData,
22
+ bool force) {
23
+ auto job = [jsErrorData = std::move(jsErrorData), force](jsi::Runtime &rnRuntime) {
24
+ reportFatalErrorOnJS(rnRuntime, jsErrorData, force);
25
+ };
26
+ if (jsScheduler->canInvokeSyncOnJS()) {
27
+ jsScheduler->invokeSyncOnJS(job);
28
+ } else {
29
+ jsScheduler->scheduleOnJS(job);
30
+ }
31
+ }
32
+
33
+ void JSLogger::reportFatalErrorOnJS(jsi::Runtime &rnRuntime, const JSErrorData &jsErrorData, bool force) {
34
+ const auto &global = rnRuntime.global();
35
+ const auto errorInstance =
36
+ rnRuntime.global().getPropertyAsFunction(rnRuntime, "Error").callAsConstructor(rnRuntime).asObject(rnRuntime);
37
+
38
+ errorInstance.setProperty(rnRuntime, "message", jsi::String::createFromUtf8(rnRuntime, jsErrorData.message));
39
+
40
+ errorInstance.setProperty(rnRuntime, "stack", jsi::String::createFromUtf8(rnRuntime, jsErrorData.stack));
41
+
42
+ errorInstance.setProperty(rnRuntime, "name", jsi::String::createFromUtf8(rnRuntime, jsErrorData.name));
43
+
44
+ const auto &reportFatalErrorFunction = global.getPropertyAsFunction(rnRuntime, "__reportFatalRemoteError");
45
+ reportFatalErrorFunction.call(rnRuntime, errorInstance, force);
46
+ }
47
+
48
+ #ifndef NDEBUG
49
+ static std::string labelStackFrames(const std::string &rawStack, const std::string &label) {
50
+ static const std::string sep = "\n at";
51
+ std::string result;
52
+ size_t pos = rawStack.find(sep);
53
+ while (pos != std::string::npos) {
54
+ size_t next = rawStack.find(sep, pos + sep.size());
55
+ size_t end = (next == std::string::npos) ? rawStack.size() : next;
56
+ result += "\n at [" + label + "]:" + rawStack.substr(pos + sep.size(), end - (pos + sep.size()));
57
+ pos = next;
58
+ }
59
+ return result;
60
+ }
61
+
62
+ void JSLogger::handleJSError(
63
+ const std::shared_ptr<JSScheduler> &jsScheduler,
64
+ jsi::Runtime &workletRuntime,
65
+ const std::string &runtimeName,
66
+ jsi::JSError &error,
67
+ const std::optional<std::string> &scheduleStack) {
68
+ std::string name = "WorkletsError";
69
+ const auto &errVal = error.value();
70
+ if (errVal.isObject()) {
71
+ auto errObj = errVal.asObject(workletRuntime);
72
+ if (errObj.hasProperty(workletRuntime, "name")) {
73
+ auto nameVal = errObj.getProperty(workletRuntime, "name");
74
+ if (nameVal.isString()) {
75
+ name = nameVal.asString(workletRuntime).utf8(workletRuntime);
76
+ }
77
+ }
78
+ }
79
+
80
+ const auto &message = error.getMessage();
81
+ std::string combined = message + labelStackFrames(error.getStack(), runtimeName);
82
+ if (scheduleStack.has_value()) {
83
+ auto pos = scheduleStack->find("\n at");
84
+ if (pos != std::string::npos) {
85
+ combined += scheduleStack->substr(pos);
86
+ }
87
+ }
88
+ reportFatalErrorOnJS(jsScheduler, JSErrorData{.message = message, .stack = combined, .name = name});
89
+ }
90
+ #endif // NDEBUG
91
+
92
+ } // namespace worklets
@@ -0,0 +1,48 @@
1
+ #pragma once
2
+
3
+ #include <jsi/jsi.h>
4
+ #include <worklets/Tools/JSScheduler.h>
5
+
6
+ #include <memory>
7
+ #include <optional>
8
+ #include <string>
9
+
10
+ namespace worklets {
11
+
12
+ struct JSErrorData {
13
+ std::string message;
14
+ std::string stack;
15
+ std::string name;
16
+ };
17
+
18
+ class JSLogger {
19
+ public:
20
+ explicit JSLogger(const std::shared_ptr<JSScheduler> &jsScheduler) : jsScheduler_(jsScheduler) {}
21
+ void warnOnJS(const std::string &warning) const;
22
+
23
+ static void
24
+ reportFatalErrorOnJS(const std::shared_ptr<JSScheduler> &jsScheduler, JSErrorData &&jsErrorData, bool force = false);
25
+
26
+ #ifndef NDEBUG
27
+ /**
28
+ * Forwards a `jsi::JSError` raised on a worklet runtime to the RN runtime so
29
+ * RN's LogBox can display it. The reported stack is rewritten to label each
30
+ * frame with `runtimeName` and, when present, the `scheduleStack` is appended
31
+ * so users can trace the error back to the JS call site that scheduled the
32
+ * worklet.
33
+ */
34
+ static void handleJSError(
35
+ const std::shared_ptr<JSScheduler> &jsScheduler,
36
+ facebook::jsi::Runtime &workletRuntime,
37
+ const std::string &runtimeName,
38
+ facebook::jsi::JSError &error,
39
+ const std::optional<std::string> &scheduleStack);
40
+ #endif // NDEBUG
41
+
42
+ private:
43
+ static void reportFatalErrorOnJS(jsi::Runtime &rnRuntime, const JSErrorData &jsErrorData, bool force = false);
44
+
45
+ const std::shared_ptr<JSScheduler> jsScheduler_;
46
+ };
47
+
48
+ } // namespace worklets
@@ -0,0 +1,21 @@
1
+ #include <react/debug/react_native_assert.h>
2
+ #include <worklets/Tools/JSScheduler.h>
3
+
4
+ #include <utility>
5
+
6
+ namespace worklets {
7
+
8
+ void JSScheduler::scheduleOnJS(Job job) {
9
+ jsCallInvoker_->invokeAsync([job = std::move(job), &rt = rnRuntime_] { job(rt); });
10
+ }
11
+
12
+ bool JSScheduler::canInvokeSyncOnJS() {
13
+ return isJavaScriptQueue_();
14
+ }
15
+
16
+ void JSScheduler::invokeSyncOnJS(const Job &job) {
17
+ react_native_assert(canInvokeSyncOnJS() && "JSScheduler::invokeSyncOnJS should only be called from the JS thread");
18
+ job(rnRuntime_);
19
+ }
20
+
21
+ } // namespace worklets
@@ -0,0 +1,35 @@
1
+ #pragma once
2
+
3
+ #include <ReactCommon/CallInvoker.h>
4
+ #include <jsi/jsi.h>
5
+
6
+ #include <memory>
7
+
8
+ using namespace facebook;
9
+ using namespace react;
10
+
11
+ namespace worklets {
12
+
13
+ class JSScheduler {
14
+ using Job = std::function<void(jsi::Runtime &rt)>;
15
+
16
+ public:
17
+ explicit JSScheduler(
18
+ jsi::Runtime &rnRuntime,
19
+ const std::shared_ptr<CallInvoker> &jsCallInvoker,
20
+ std::function<bool()> &&isJavaScriptQueue)
21
+ : rnRuntime_(rnRuntime), jsCallInvoker_(jsCallInvoker), isJavaScriptQueue_(isJavaScriptQueue) {}
22
+
23
+ void scheduleOnJS(std::function<void(jsi::Runtime &rt)> job);
24
+
25
+ void invokeSyncOnJS(const std::function<void(jsi::Runtime &rt)> &job);
26
+
27
+ bool canInvokeSyncOnJS();
28
+
29
+ protected:
30
+ jsi::Runtime &rnRuntime_;
31
+ const std::shared_ptr<CallInvoker> jsCallInvoker_;
32
+ const std::function<bool()> isJavaScriptQueue_;
33
+ };
34
+
35
+ } // namespace worklets
@@ -0,0 +1,16 @@
1
+ #pragma once
2
+
3
+ #include <string>
4
+
5
+ namespace worklets {
6
+
7
+ class PlatformLogger {
8
+ public:
9
+ static void log(const char *str);
10
+ static void log(const std::string &str);
11
+ static void log(const double d);
12
+ static void log(const int i);
13
+ static void log(const bool b);
14
+ };
15
+
16
+ } // namespace worklets
@@ -0,0 +1,27 @@
1
+ #pragma once
2
+
3
+ #include <shared_mutex>
4
+ #include <utility>
5
+
6
+ namespace worklets {
7
+
8
+ class RNRuntimeStatus {
9
+ public:
10
+ void setDead() {
11
+ std::lock_guard<std::shared_mutex> lock(mutex_);
12
+ isDead_ = true;
13
+ }
14
+
15
+ template <typename TFn>
16
+ void runWhileLocked(TFn &&fn) {
17
+ std::shared_lock<std::shared_mutex> lock(mutex_);
18
+ const bool isDead = isDead_;
19
+ std::forward<TFn>(fn)(isDead);
20
+ }
21
+
22
+ private:
23
+ bool isDead_ = false;
24
+ std::shared_mutex mutex_;
25
+ };
26
+
27
+ } // namespace worklets
@@ -0,0 +1,56 @@
1
+ #pragma once
2
+
3
+ #include <cxxreact/ReactNativeVersion.h>
4
+ #include <jsi/jsi.h>
5
+
6
+ #if REACT_NATIVE_VERSION_MINOR >= 84
7
+ #include <cxxreact/JSBigString.h>
8
+ #else
9
+ #include <jsireact/JSIExecutor.h>
10
+ #endif
11
+
12
+ #include <memory>
13
+ #include <utility>
14
+
15
+ namespace worklets {
16
+
17
+ using namespace facebook;
18
+ using namespace facebook::react;
19
+
20
+ /**
21
+ * Our custom copyable structure that is accepted by
22
+ * Hermes Runtime for evaluation.
23
+ */
24
+ class ScriptBuffer : public jsi::Buffer {
25
+ public:
26
+ explicit ScriptBuffer(std::shared_ptr<const JSBigString> script) : script_(std::move(script)) {}
27
+
28
+ size_t size() const override {
29
+ return script_->size();
30
+ }
31
+
32
+ const uint8_t *data() const override {
33
+ return reinterpret_cast<const uint8_t *>(script_->c_str());
34
+ }
35
+
36
+ private:
37
+ std::shared_ptr<const JSBigString> script_;
38
+ };
39
+
40
+ class BytecodeBuffer : public jsi::Buffer {
41
+ public:
42
+ explicit BytecodeBuffer(const std::vector<uint8_t> &bytecode) : bytecode_(bytecode) {}
43
+
44
+ size_t size() const override {
45
+ return bytecode_.size();
46
+ }
47
+
48
+ const uint8_t *data() const override {
49
+ return bytecode_.data();
50
+ }
51
+
52
+ private:
53
+ std::vector<uint8_t> bytecode_;
54
+ };
55
+
56
+ } // namespace worklets