@depup/react-native-worklets 0.12.2-depup.0 → 0.13.0-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 (311) hide show
  1. package/Common/cpp/worklets/AnimationFrameQueue/AnimationFrameBatchinator.cpp +1 -2
  2. package/Common/cpp/worklets/AnimationFrameQueue/AnimationFrameBatchinator.h +1 -1
  3. package/Common/cpp/worklets/Compat/StableApi.cpp +24 -8
  4. package/Common/cpp/worklets/Compat/StableApi.h +1 -1
  5. package/Common/cpp/worklets/NativeModules/JSIWorkletsModuleProxy.cpp +113 -50
  6. package/Common/cpp/worklets/NativeModules/JSIWorkletsModuleProxy.h +10 -1
  7. package/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.cpp +95 -37
  8. package/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.h +57 -7
  9. package/Common/cpp/worklets/NativeModules/WorkletsModuleProxyInitializer.cpp +94 -0
  10. package/Common/cpp/worklets/NativeModules/WorkletsModuleProxyInitializer.h +58 -0
  11. package/Common/cpp/worklets/Networking/Networking.cpp +283 -0
  12. package/Common/cpp/worklets/Networking/Networking.h +51 -0
  13. package/Common/cpp/worklets/Networking/NetworkingBackend.h +47 -0
  14. package/Common/cpp/worklets/Networking/NetworkingInstaller.cpp +127 -0
  15. package/Common/cpp/worklets/Networking/NetworkingInstaller.h +19 -0
  16. package/Common/cpp/worklets/Networking/NetworkingTypes.h +33 -0
  17. package/Common/cpp/worklets/Networking/TextDecoding.cpp +189 -0
  18. package/Common/cpp/worklets/Networking/TextDecoding.h +29 -0
  19. package/Common/cpp/worklets/RunLoop/AsyncQueue.h +28 -0
  20. package/Common/cpp/worklets/RunLoop/AsyncQueueImpl.cpp +9 -0
  21. package/Common/cpp/worklets/RunLoop/AsyncQueueImpl.h +6 -0
  22. package/Common/cpp/worklets/RunLoop/EventLoop.cpp +19 -4
  23. package/Common/cpp/worklets/RunLoop/EventLoop.h +3 -0
  24. package/Common/cpp/worklets/SharedItems/MemoryManager.cpp +1 -1
  25. package/Common/cpp/worklets/SharedItems/MemoryManager.h +2 -1
  26. package/Common/cpp/worklets/SharedItems/Serializable/CustomSerializable.cpp +37 -0
  27. package/Common/cpp/worklets/SharedItems/Serializable/CustomSerializable.h +33 -0
  28. package/Common/cpp/worklets/SharedItems/Serializable/RetainingSerializable.h +112 -0
  29. package/Common/cpp/worklets/SharedItems/Serializable/Serializable.cpp +129 -0
  30. package/Common/cpp/worklets/SharedItems/Serializable/Serializable.h +121 -0
  31. package/Common/cpp/worklets/SharedItems/Serializable/SerializableArray.cpp +38 -0
  32. package/Common/cpp/worklets/SharedItems/Serializable/SerializableArray.h +39 -0
  33. package/Common/cpp/worklets/SharedItems/Serializable/SerializableArrayBuffer.cpp +35 -0
  34. package/Common/cpp/worklets/SharedItems/Serializable/SerializableArrayBuffer.h +43 -0
  35. package/Common/cpp/worklets/SharedItems/Serializable/SerializableBigInt.cpp +23 -0
  36. package/Common/cpp/worklets/SharedItems/Serializable/SerializableBigInt.h +35 -0
  37. package/Common/cpp/worklets/SharedItems/Serializable/SerializableError.cpp +38 -0
  38. package/Common/cpp/worklets/SharedItems/Serializable/SerializableError.h +30 -0
  39. package/Common/cpp/worklets/SharedItems/Serializable/SerializableHostFunction.cpp +24 -0
  40. package/Common/cpp/worklets/SharedItems/Serializable/SerializableHostFunction.h +32 -0
  41. package/Common/cpp/worklets/SharedItems/Serializable/SerializableHostObject.cpp +19 -0
  42. package/Common/cpp/worklets/SharedItems/Serializable/SerializableHostObject.h +25 -0
  43. package/Common/cpp/worklets/SharedItems/Serializable/SerializableImport.cpp +29 -0
  44. package/Common/cpp/worklets/SharedItems/Serializable/SerializableImport.h +25 -0
  45. package/Common/cpp/worklets/SharedItems/Serializable/SerializableMap.cpp +44 -0
  46. package/Common/cpp/worklets/SharedItems/Serializable/SerializableMap.h +25 -0
  47. package/Common/cpp/worklets/SharedItems/Serializable/SerializableObject.cpp +80 -0
  48. package/Common/cpp/worklets/SharedItems/Serializable/SerializableObject.h +35 -0
  49. package/Common/cpp/worklets/SharedItems/Serializable/SerializableRegExp.cpp +22 -0
  50. package/Common/cpp/worklets/SharedItems/Serializable/SerializableRegExp.h +25 -0
  51. package/Common/cpp/worklets/SharedItems/{SerializableRemoteFunction.cpp → Serializable/SerializableRemoteFunction.cpp} +30 -2
  52. package/Common/cpp/worklets/SharedItems/{SerializableRemoteFunction.h → Serializable/SerializableRemoteFunction.h} +24 -10
  53. package/Common/cpp/worklets/SharedItems/Serializable/SerializableScalar.cpp +46 -0
  54. package/Common/cpp/worklets/SharedItems/Serializable/SerializableScalar.h +41 -0
  55. package/Common/cpp/worklets/SharedItems/Serializable/SerializableSet.cpp +36 -0
  56. package/Common/cpp/worklets/SharedItems/Serializable/SerializableSet.h +23 -0
  57. package/Common/cpp/worklets/SharedItems/Serializable/SerializableString.cpp +19 -0
  58. package/Common/cpp/worklets/SharedItems/Serializable/SerializableString.h +22 -0
  59. package/Common/cpp/worklets/SharedItems/Serializable/SerializableTurboModuleLike.cpp +26 -0
  60. package/Common/cpp/worklets/SharedItems/Serializable/SerializableTurboModuleLike.h +33 -0
  61. package/Common/cpp/worklets/SharedItems/Serializable/SerializableWorklet.cpp +31 -0
  62. package/Common/cpp/worklets/SharedItems/Serializable/SerializableWorklet.h +23 -0
  63. package/Common/cpp/worklets/SharedItems/Serializable.h +21 -409
  64. package/Common/cpp/worklets/SharedItems/Shareable.cpp +1 -1
  65. package/Common/cpp/worklets/SharedItems/Shareable.h +1 -1
  66. package/Common/cpp/worklets/SharedItems/Synchronizable.h +43 -20
  67. package/Common/cpp/worklets/SharedItems/SynchronizableAccess.cpp +24 -26
  68. package/Common/cpp/worklets/SharedItems/SynchronizableAccess.h +5 -7
  69. package/Common/cpp/worklets/SharedItems/SynchronizableDynamic.cpp +36 -0
  70. package/Common/cpp/worklets/SharedItems/SynchronizableDynamic.h +27 -0
  71. package/Common/cpp/worklets/SharedItems/SynchronizableFixed.cpp +76 -0
  72. package/Common/cpp/worklets/SharedItems/SynchronizableFixed.h +48 -0
  73. package/Common/cpp/worklets/Tools/ScriptBuffer.h +0 -5
  74. package/Common/cpp/worklets/Tools/WorkletsJSIUtils.h +16 -30
  75. package/Common/cpp/worklets/WorkletRuntime/RuntimeBindings.h +27 -30
  76. package/Common/cpp/worklets/WorkletRuntime/RuntimeManager.cpp +4 -3
  77. package/Common/cpp/worklets/WorkletRuntime/RuntimeManager.h +2 -1
  78. package/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.cpp +79 -29
  79. package/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.h +34 -19
  80. package/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.cpp +13 -86
  81. package/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.h +1 -7
  82. package/Package.swift +147 -0
  83. package/README.md +5 -5
  84. package/RNWorklets.podspec +1 -2
  85. package/android/CMakeLists.txt +7 -26
  86. package/android/build.gradle.kts +5 -31
  87. package/android/src/main/cpp/worklets/android/WorkletsModule.cpp +46 -129
  88. package/android/src/main/cpp/worklets/android/WorkletsModule.h +21 -11
  89. package/android/src/main/cpp/worklets/android/WorkletsOnLoad.cpp +2 -4
  90. package/android/src/main/cpp/worklets/android/networking/AndroidNetworkingBackend.cpp +82 -0
  91. package/android/src/main/cpp/worklets/android/networking/AndroidNetworkingBackend.h +32 -0
  92. package/android/src/main/cpp/worklets/android/networking/JNetworkRequestListener.cpp +73 -0
  93. package/android/src/main/cpp/worklets/android/networking/JNetworkRequestListener.h +38 -0
  94. package/android/src/{no-networking → main/java}/com/swmansion/worklets/WorkletsModule.kt +39 -28
  95. package/android/src/main/java/com/swmansion/worklets/networking/NetworkRequestListener.kt +37 -0
  96. package/android/src/main/java/com/swmansion/worklets/networking/Networking.kt +244 -0
  97. package/android/src/main/java/com/swmansion/worklets/runloop/AnimationFrameQueue.kt +3 -0
  98. package/apple/worklets/apple/AnimationFrameQueue.mm +9 -1
  99. package/apple/worklets/apple/AssertJavaScriptQueue.h +3 -2
  100. package/apple/worklets/apple/AssertTurboModuleManagerQueue.h +4 -0
  101. package/apple/worklets/apple/IOSUIScheduler.mm +3 -0
  102. package/apple/worklets/apple/Networking/AppleNetworkingBackend.h +29 -0
  103. package/apple/worklets/apple/Networking/AppleNetworkingBackend.mm +93 -0
  104. package/apple/worklets/apple/Networking/WorkletsURLSessionDelegate.h +37 -0
  105. package/apple/worklets/apple/Networking/WorkletsURLSessionDelegate.mm +447 -0
  106. package/apple/worklets/apple/WorkletsModule.h +3 -2
  107. package/apple/worklets/apple/WorkletsModule.mm +82 -74
  108. package/bundleMode/index.js +10 -47
  109. package/bundleMode/polyfills/prepareBundleMode.js +16 -0
  110. package/changes.json +4 -4
  111. package/compatibility.json +4 -1
  112. package/lib/module/WorkletsModule/NativeWorklets.native.js +12 -9
  113. package/lib/module/WorkletsModule/NativeWorklets.native.js.map +1 -1
  114. package/lib/module/debug/jsVersion.js +1 -1
  115. package/lib/module/featureFlags/staticFlags.json +0 -1
  116. package/lib/module/featureFlags/types.js +0 -1
  117. package/lib/module/featureFlags/types.js.map +1 -1
  118. package/lib/module/index.js +1 -1
  119. package/lib/module/index.js.map +1 -1
  120. package/lib/module/initializers/initializers.native.js +5 -12
  121. package/lib/module/initializers/initializers.native.js.map +1 -1
  122. package/lib/module/memory/bundleUnpacker.native.js +2 -10
  123. package/lib/module/memory/bundleUnpacker.native.js.map +1 -1
  124. package/lib/module/memory/serializable.native.js +1 -29
  125. package/lib/module/memory/serializable.native.js.map +1 -1
  126. package/lib/module/memory/synchronizable.js +1 -1
  127. package/lib/module/memory/synchronizable.js.map +1 -1
  128. package/lib/module/memory/synchronizable.native.js +7 -3
  129. package/lib/module/memory/synchronizable.native.js.map +1 -1
  130. package/lib/module/memory/synchronizableUnpacker.native.js +7 -2
  131. package/lib/module/memory/synchronizableUnpacker.native.js.map +1 -1
  132. package/lib/module/memory/valueUnpacker.native.js +0 -8
  133. package/lib/module/memory/valueUnpacker.native.js.map +1 -1
  134. package/lib/module/mock.js +22 -1
  135. package/lib/module/mock.js.map +1 -1
  136. package/lib/module/networking/AbortController.js +43 -0
  137. package/lib/module/networking/AbortController.js.map +1 -0
  138. package/lib/module/networking/Blob.js +60 -0
  139. package/lib/module/networking/Blob.js.map +1 -0
  140. package/lib/module/networking/DOMException.js +35 -0
  141. package/lib/module/networking/DOMException.js.map +1 -0
  142. package/lib/module/networking/FileReader.js +83 -0
  143. package/lib/module/networking/FileReader.js.map +1 -0
  144. package/lib/module/networking/FormData.js +105 -0
  145. package/lib/module/networking/FormData.js.map +1 -0
  146. package/lib/module/networking/XMLHttpRequest.js +450 -0
  147. package/lib/module/networking/XMLHttpRequest.js.map +1 -0
  148. package/lib/module/networking/bytes.js +6 -0
  149. package/lib/module/networking/bytes.js.map +1 -0
  150. package/lib/module/networking/events.js +44 -0
  151. package/lib/module/networking/events.js.map +1 -0
  152. package/lib/module/networking/http.js +100 -0
  153. package/lib/module/networking/http.js.map +1 -0
  154. package/lib/module/networking/install.js +37 -0
  155. package/lib/module/networking/install.js.map +1 -0
  156. package/lib/module/networking/utf8.js +99 -0
  157. package/lib/module/networking/utf8.js.map +1 -0
  158. package/lib/module/privateGlobals.d.js +0 -1
  159. package/lib/module/privateGlobals.d.js.map +1 -1
  160. package/lib/module/runLoop/common/queueMicrotaskPolyfill.js +9 -0
  161. package/lib/module/runLoop/common/queueMicrotaskPolyfill.js.map +1 -0
  162. package/lib/module/runLoop/uiRuntime/requestAnimationFrame.js +7 -3
  163. package/lib/module/runLoop/uiRuntime/requestAnimationFrame.js.map +1 -1
  164. package/lib/module/runLoop/workletRuntime/index.js +1 -1
  165. package/lib/module/runLoop/workletRuntime/index.js.map +1 -1
  166. package/lib/module/runLoop/workletRuntime/requestAnimationFramePolyfill.js +1 -1
  167. package/lib/module/runLoop/workletRuntime/requestAnimationFramePolyfill.js.map +1 -1
  168. package/lib/module/runLoop/workletRuntime/taskQueue.js +0 -13
  169. package/lib/module/runLoop/workletRuntime/taskQueue.js.map +1 -1
  170. package/lib/module/runtimes.native.js +8 -1
  171. package/lib/module/runtimes.native.js.map +1 -1
  172. package/lib/module/specs/NativeWorkletsModule.js.map +1 -1
  173. package/lib/module/threads.js +11 -0
  174. package/lib/module/threads.js.map +1 -1
  175. package/lib/module/threads.native.js +35 -42
  176. package/lib/module/threads.native.js.map +1 -1
  177. package/lib/typescript/WorkletsModule/NativeWorklets.native.d.ts.map +1 -1
  178. package/lib/typescript/WorkletsModule/workletsModuleProxy.d.ts +6 -5
  179. package/lib/typescript/WorkletsModule/workletsModuleProxy.d.ts.map +1 -1
  180. package/lib/typescript/debug/jsVersion.d.ts +1 -1
  181. package/lib/typescript/featureFlags/types.d.ts +0 -1
  182. package/lib/typescript/featureFlags/types.d.ts.map +1 -1
  183. package/lib/typescript/index.d.ts +2 -2
  184. package/lib/typescript/index.d.ts.map +1 -1
  185. package/lib/typescript/memory/bundleUnpacker.native.d.ts.map +1 -1
  186. package/lib/typescript/memory/serializable.native.d.ts.map +1 -1
  187. package/lib/typescript/memory/synchronizable.d.ts +6 -2
  188. package/lib/typescript/memory/synchronizable.d.ts.map +1 -1
  189. package/lib/typescript/memory/synchronizable.native.d.ts +6 -2
  190. package/lib/typescript/memory/synchronizable.native.d.ts.map +1 -1
  191. package/lib/typescript/memory/synchronizableUnpacker.native.d.ts +1 -1
  192. package/lib/typescript/memory/synchronizableUnpacker.native.d.ts.map +1 -1
  193. package/lib/typescript/memory/types.d.ts +6 -0
  194. package/lib/typescript/memory/types.d.ts.map +1 -1
  195. package/lib/typescript/memory/valueUnpacker.native.d.ts.map +1 -1
  196. package/lib/typescript/networking/AbortController.d.ts +16 -0
  197. package/lib/typescript/networking/AbortController.d.ts.map +1 -0
  198. package/lib/typescript/networking/Blob.d.ts +16 -0
  199. package/lib/typescript/networking/Blob.d.ts.map +1 -0
  200. package/lib/typescript/networking/DOMException.d.ts +5 -0
  201. package/lib/typescript/networking/DOMException.d.ts.map +1 -0
  202. package/lib/typescript/networking/FileReader.d.ts +19 -0
  203. package/lib/typescript/networking/FileReader.d.ts.map +1 -0
  204. package/lib/typescript/networking/FormData.d.ts +30 -0
  205. package/lib/typescript/networking/FormData.d.ts.map +1 -0
  206. package/lib/typescript/networking/XMLHttpRequest.d.ts +77 -0
  207. package/lib/typescript/networking/XMLHttpRequest.d.ts.map +1 -0
  208. package/lib/typescript/networking/bytes.d.ts +2 -0
  209. package/lib/typescript/networking/bytes.d.ts.map +1 -0
  210. package/lib/typescript/networking/events.d.ts +18 -0
  211. package/lib/typescript/networking/events.d.ts.map +1 -0
  212. package/lib/typescript/networking/http.d.ts +14 -0
  213. package/lib/typescript/networking/http.d.ts.map +1 -0
  214. package/lib/typescript/networking/install.d.ts +2 -0
  215. package/lib/typescript/networking/install.d.ts.map +1 -0
  216. package/lib/typescript/networking/utf8.d.ts +4 -0
  217. package/lib/typescript/networking/utf8.d.ts.map +1 -0
  218. package/lib/typescript/runLoop/{workletRuntime/queueMicrotask.d.ts → common/queueMicrotaskPolyfill.d.ts} +1 -1
  219. package/lib/typescript/runLoop/common/queueMicrotaskPolyfill.d.ts.map +1 -0
  220. package/lib/typescript/runLoop/uiRuntime/requestAnimationFrame.d.ts.map +1 -1
  221. package/lib/typescript/runLoop/workletRuntime/taskQueue.d.ts +0 -2
  222. package/lib/typescript/runLoop/workletRuntime/taskQueue.d.ts.map +1 -1
  223. package/lib/typescript/runtimes.native.d.ts.map +1 -1
  224. package/lib/typescript/specs/NativeWorkletsModule.d.ts +1 -0
  225. package/lib/typescript/specs/NativeWorkletsModule.d.ts.map +1 -1
  226. package/lib/typescript/threads.d.ts +8 -0
  227. package/lib/typescript/threads.d.ts.map +1 -1
  228. package/lib/typescript/threads.native.d.ts +8 -1
  229. package/lib/typescript/threads.native.d.ts.map +1 -1
  230. package/lib/typescript/types.d.ts +9 -5
  231. package/lib/typescript/types.d.ts.map +1 -1
  232. package/package.json +32 -18
  233. package/plugin/index.js +63 -93
  234. package/plugin-oxc/babel.d.ts +7 -0
  235. package/plugin-oxc/babel.js +200 -0
  236. package/plugin-oxc/index.d.ts +33 -0
  237. package/plugin-oxc/index.js +36 -0
  238. package/plugin-oxc/worklets-oxc-plugin.darwin-arm64.node +0 -0
  239. package/plugin-oxc/worklets-oxc-plugin.darwin-x64.node +0 -0
  240. package/plugin-oxc/worklets-oxc-plugin.linux-arm64.node +0 -0
  241. package/plugin-oxc/worklets-oxc-plugin.linux-x64.node +0 -0
  242. package/plugin-oxc/worklets-oxc-plugin.win32-arm64.node +0 -0
  243. package/plugin-oxc/worklets-oxc-plugin.win32-x64.node +0 -0
  244. package/react-native.config.js +5 -0
  245. package/scripts/worklets_utils.rb +0 -10
  246. package/src/WorkletsModule/NativeWorklets.native.ts +26 -9
  247. package/src/WorkletsModule/workletsModuleProxy.ts +15 -5
  248. package/src/debug/jsVersion.ts +1 -1
  249. package/src/featureFlags/staticFlags.json +0 -1
  250. package/src/featureFlags/types.ts +0 -1
  251. package/src/index.ts +3 -0
  252. package/src/initializers/initializers.native.ts +5 -13
  253. package/src/memory/bundleUnpacker.native.ts +6 -13
  254. package/src/memory/serializable.native.ts +1 -44
  255. package/src/memory/synchronizable.native.ts +38 -4
  256. package/src/memory/synchronizable.ts +22 -2
  257. package/src/memory/synchronizableUnpacker.native.ts +23 -4
  258. package/src/memory/types.ts +9 -0
  259. package/src/memory/valueUnpacker.native.ts +0 -8
  260. package/src/mock.ts +28 -1
  261. package/src/networking/AbortController.ts +57 -0
  262. package/src/networking/Blob.ts +74 -0
  263. package/src/networking/DOMException.ts +37 -0
  264. package/src/networking/FileReader.ts +99 -0
  265. package/src/networking/FormData.ts +135 -0
  266. package/src/networking/XMLHttpRequest.ts +557 -0
  267. package/src/networking/bytes.ts +8 -0
  268. package/src/networking/events.ts +61 -0
  269. package/src/networking/http.ts +173 -0
  270. package/src/networking/install.ts +38 -0
  271. package/src/networking/utf8.ts +122 -0
  272. package/src/privateGlobals.d.ts +20 -13
  273. package/src/runLoop/common/queueMicrotaskPolyfill.ts +12 -0
  274. package/src/runLoop/uiRuntime/requestAnimationFrame.ts +7 -4
  275. package/src/runLoop/workletRuntime/index.ts +1 -1
  276. package/src/runLoop/workletRuntime/requestAnimationFramePolyfill.ts +1 -1
  277. package/src/runLoop/workletRuntime/taskQueue.ts +0 -15
  278. package/src/runtimes.native.ts +10 -1
  279. package/src/specs/NativeWorkletsModule.ts +1 -0
  280. package/src/threads.native.ts +49 -54
  281. package/src/threads.ts +11 -0
  282. package/src/types.ts +9 -5
  283. package/Common/cpp/worklets/SharedItems/Serializable.cpp +0 -389
  284. package/Common/cpp/worklets/SharedItems/SerializableFactory.cpp +0 -172
  285. package/Common/cpp/worklets/SharedItems/SerializableFactory.h +0 -85
  286. package/Common/cpp/worklets/SharedItems/Synchronizable.cpp +0 -59
  287. package/android/src/main/cpp/worklets/android/JWorkletRuntimeWrapper.cpp +0 -51
  288. package/android/src/main/cpp/worklets/android/JWorkletRuntimeWrapper.h +0 -43
  289. package/android/src/networking/com/swmansion/worklets/WorkletRuntimeWrapper.kt +0 -27
  290. package/android/src/networking/com/swmansion/worklets/WorkletsHeaderUtil.kt +0 -30
  291. package/android/src/networking/com/swmansion/worklets/WorkletsModule.kt +0 -204
  292. package/android/src/networking/com/swmansion/worklets/WorkletsNetworkEventUtil.kt +0 -272
  293. package/android/src/networking/com/swmansion/worklets/WorkletsNetworking.kt +0 -1124
  294. package/android/src/networking/com/swmansion/worklets/WorkletsOkHttpCallUtil.kt +0 -40
  295. package/android/src/networking/com/swmansion/worklets/WorkletsProgressListener.kt +0 -13
  296. package/android/src/networking/com/swmansion/worklets/WorkletsProgressRequestBody.kt +0 -98
  297. package/android/src/networking/com/swmansion/worklets/WorkletsProgressResponseBody.kt +0 -60
  298. package/android/src/networking/com/swmansion/worklets/WorkletsProgressiveStringDecoder.kt +0 -87
  299. package/android/src/networking/com/swmansion/worklets/WorkletsRequestBodyUtil.kt +0 -181
  300. package/apple/worklets/apple/Networking/WorkletsNetworking.h +0 -25
  301. package/apple/worklets/apple/Networking/WorkletsNetworking.mm +0 -707
  302. package/bundleMode/shims/turboModuleRegistryShim.js +0 -47
  303. package/lib/module/bundleMode/network.native.js +0 -44
  304. package/lib/module/bundleMode/network.native.js.map +0 -1
  305. package/lib/module/runLoop/workletRuntime/queueMicrotask.js +0 -11
  306. package/lib/module/runLoop/workletRuntime/queueMicrotask.js.map +0 -1
  307. package/lib/typescript/bundleMode/network.native.d.ts +0 -7
  308. package/lib/typescript/bundleMode/network.native.d.ts.map +0 -1
  309. package/lib/typescript/runLoop/workletRuntime/queueMicrotask.d.ts.map +0 -1
  310. package/src/bundleMode/network.native.ts +0 -63
  311. package/src/runLoop/workletRuntime/queueMicrotask.ts +0 -13
@@ -0,0 +1,112 @@
1
+ #pragma once
2
+
3
+ #include <jsi/jsi.h>
4
+ #include <worklets/Compat/StableApi.h>
5
+ #include <worklets/Registries/WorkletRuntimeRegistry.h>
6
+ #include <worklets/SharedItems/Serializable/Serializable.h>
7
+ #include <worklets/Tools/JSScheduler.h>
8
+ #include <worklets/Tools/WorkletsSystraceSection.h>
9
+ #include <worklets/WorkletRuntime/RuntimeData.h>
10
+
11
+ #include <array>
12
+ #include <atomic>
13
+ #include <cstddef>
14
+ #include <memory>
15
+ #include <type_traits>
16
+ #include <utility>
17
+
18
+ namespace worklets {
19
+
20
+ template <typename TSerializable>
21
+ requires std::is_base_of_v<Serializable, TSerializable>
22
+ class RetainingSerializableStore {
23
+ private:
24
+ static constexpr std::size_t kSlotsPerChunk = 4;
25
+
26
+ struct Slot {
27
+ std::atomic<facebook::jsi::Runtime *> runtime{nullptr};
28
+ facebook::jsi::Value value{facebook::jsi::Value::undefined()};
29
+ };
30
+
31
+ std::array<Slot, kSlotsPerChunk> slots_{};
32
+
33
+ std::atomic<RetainingSerializableStore *> nextChunk_{nullptr};
34
+ std::unique_ptr<RetainingSerializableStore> nextChunkOwner_{};
35
+
36
+ const facebook::jsi::Value *find(facebook::jsi::Runtime *rt) {
37
+ for (auto &slot : slots_) {
38
+ if (slot.runtime.load(std::memory_order_acquire) == rt) {
39
+ return &slot.value;
40
+ }
41
+ }
42
+ if (auto *next = nextChunk_.load(std::memory_order_acquire)) {
43
+ return next->find(rt);
44
+ }
45
+ return nullptr;
46
+ }
47
+
48
+ void store(facebook::jsi::Runtime *rt, facebook::jsi::Value value) {
49
+ for (auto &slot : slots_) {
50
+ if (slot.runtime.load(std::memory_order_relaxed) != nullptr) {
51
+ continue;
52
+ }
53
+ facebook::jsi::Runtime *expected = nullptr;
54
+ if (slot.runtime.compare_exchange_strong(expected, rt, std::memory_order_acq_rel)) {
55
+ slot.value = std::move(value);
56
+ return;
57
+ }
58
+ }
59
+
60
+ auto *next = nextChunk_.load(std::memory_order_acquire);
61
+ if (next == nullptr) {
62
+ auto fresh = std::make_unique<RetainingSerializableStore>();
63
+ auto *freshChunk = fresh.get();
64
+ if (nextChunk_.compare_exchange_strong(next, freshChunk, std::memory_order_acq_rel)) {
65
+ nextChunkOwner_ = std::move(fresh);
66
+ next = freshChunk;
67
+ }
68
+ }
69
+ next->store(rt, std::move(value));
70
+ }
71
+
72
+ public:
73
+ RetainingSerializableStore() = default;
74
+
75
+ ~RetainingSerializableStore() {
76
+ for (auto &slot : slots_) {
77
+ cleanupRuntimeAware(slot.runtime.load(std::memory_order_relaxed), slot.value);
78
+ }
79
+ }
80
+
81
+ facebook::jsi::Value getOrStore(facebook::jsi::Runtime &rt, TSerializable &serializable) {
82
+ if (const auto *cachedValue = find(&rt)) {
83
+ return facebook::jsi::Value(rt, *cachedValue);
84
+ }
85
+
86
+ auto jsValue = serializable.TSerializable::toJSValue(rt);
87
+ store(&rt, facebook::jsi::Value(rt, jsValue));
88
+
89
+ return jsValue;
90
+ }
91
+ };
92
+
93
+ template <typename TSerializable>
94
+ requires std::is_base_of_v<Serializable, TSerializable>
95
+ class RetainingSerializable : virtual public TSerializable {
96
+ private:
97
+ std::unique_ptr<RetainingSerializableStore<TSerializable>> store_{
98
+ std::make_unique<RetainingSerializableStore<TSerializable>>()};
99
+
100
+ public:
101
+ template <typename... Args>
102
+ explicit RetainingSerializable(facebook::jsi::Runtime &rt, Args &&...args)
103
+ : TSerializable(rt, std::forward<Args>(args)...) {}
104
+
105
+ ~RetainingSerializable() override = default;
106
+
107
+ facebook::jsi::Value toJSValue(facebook::jsi::Runtime &rt) override {
108
+ return store_->getOrStore(rt, *this);
109
+ }
110
+ };
111
+
112
+ } // namespace worklets
@@ -0,0 +1,129 @@
1
+ #include <jsi/jsi.h>
2
+ #include <react/debug/react_native_assert.h>
3
+ #include <worklets/SharedItems/Serializable/RetainingSerializable.h>
4
+ #include <worklets/SharedItems/Serializable/Serializable.h>
5
+ #include <worklets/SharedItems/Serializable/SerializableArray.h>
6
+ #include <worklets/SharedItems/Serializable/SerializableArrayBuffer.h>
7
+ #include <worklets/SharedItems/Serializable/SerializableBigInt.h>
8
+ #include <worklets/SharedItems/Serializable/SerializableHostFunction.h>
9
+ #include <worklets/SharedItems/Serializable/SerializableHostObject.h>
10
+ #include <worklets/SharedItems/Serializable/SerializableObject.h>
11
+ #include <worklets/SharedItems/Serializable/SerializableScalar.h>
12
+ #include <worklets/SharedItems/Serializable/SerializableString.h>
13
+ #include <worklets/SharedItems/Serializable/SerializableWorklet.h>
14
+
15
+ #include <memory>
16
+ #include <stdexcept>
17
+ #include <string>
18
+
19
+ using namespace facebook;
20
+
21
+ namespace worklets {
22
+
23
+ jsi::Function getValueUnpacker(jsi::Runtime &rt) {
24
+ auto valueUnpacker = rt.global().getProperty(rt, "__valueUnpacker");
25
+ react_native_assert(valueUnpacker.isObject() && "valueUnpacker not found");
26
+ return valueUnpacker.asObject(rt).asFunction(rt);
27
+ }
28
+
29
+ jsi::Value makeSerializableClone(
30
+ jsi::Runtime &rt,
31
+ const jsi::Value &value,
32
+ const jsi::Value &shouldRetainRemote,
33
+ const jsi::Value &nativeStateSource) {
34
+ std::shared_ptr<Serializable> serializable;
35
+ if (value.isObject()) {
36
+ auto object = value.asObject(rt);
37
+ if (!object.getProperty(rt, "__workletHash").isUndefined()) {
38
+ // We pass `false` because this function is invoked only
39
+ // by `makeSerializableCloneOnUIRecursive` which doesn't
40
+ // make Retaining Serializables.
41
+ return makeSerializableWorklet(rt, object, false);
42
+ } else if (object.isFunction(rt)) {
43
+ auto fun = object.asFunction(rt);
44
+ if (fun.isHostFunction(rt)) {
45
+ auto name = fun.getProperty(rt, "name").asString(rt).utf8(rt);
46
+ return makeSerializableHostFunction(
47
+ rt, fun.getHostFunction(rt), name, fun.getProperty(rt, "length").asNumber());
48
+ } else {
49
+ throw std::runtime_error(
50
+ "[Worklets] Cloning remote functions from Worklet Runtimes is only available in Bundle Mode.");
51
+ }
52
+ } else if (object.isArray(rt)) {
53
+ if (shouldRetainRemote.isBool() && shouldRetainRemote.getBool()) {
54
+ serializable = std::make_shared<RetainingSerializable<SerializableArray>>(rt, object.asArray(rt));
55
+ } else {
56
+ serializable = std::make_shared<SerializableArray>(rt, object.asArray(rt));
57
+ }
58
+ } else if (object.isArrayBuffer(rt)) {
59
+ serializable = std::make_shared<SerializableArrayBuffer>(rt, object.getArrayBuffer(rt));
60
+ } else if (object.isHostObject(rt)) {
61
+ if (object.isHostObject<SerializableJSRef>(rt)) {
62
+ return object;
63
+ }
64
+ serializable = std::make_shared<SerializableHostObject>(rt, object.getHostObject(rt));
65
+ } else {
66
+ if (shouldRetainRemote.isBool() && shouldRetainRemote.getBool()) {
67
+ serializable = std::make_shared<RetainingSerializable<SerializableObject>>(rt, object, nativeStateSource);
68
+ } else {
69
+ serializable = std::make_shared<SerializableObject>(rt, object, nativeStateSource);
70
+ }
71
+ }
72
+ } else if (value.isString()) {
73
+ serializable = std::make_shared<SerializableString>(value.asString(rt).utf8(rt));
74
+ } else if (value.isUndefined()) {
75
+ serializable = std::make_shared<SerializableScalar>();
76
+ } else if (value.isNull()) {
77
+ serializable = std::make_shared<SerializableScalar>(nullptr);
78
+ } else if (value.isBool()) {
79
+ serializable = std::make_shared<SerializableScalar>(value.getBool());
80
+ } else if (value.isNumber()) {
81
+ serializable = std::make_shared<SerializableScalar>(value.getNumber());
82
+ } else if (value.isBigInt()) {
83
+ serializable = std::make_shared<SerializableBigInt>(rt, value.getBigInt(rt));
84
+ } else if (value.isSymbol()) {
85
+ // TODO: this is only a placeholder implementation, here we replace symbols
86
+ // with strings in order to make certain objects to be captured. There isn't
87
+ // yet any use-case for using symbols on the UI runtime so it is fine to keep
88
+ // it like this for now.
89
+ serializable = std::make_shared<SerializableString>(value.getSymbol(rt).toString(rt));
90
+ } else {
91
+ throw std::runtime_error("[Worklets] Attempted to convert an unsupported value type.");
92
+ }
93
+ return SerializableJSRef::newNativeStateObject(rt, serializable);
94
+ }
95
+
96
+ std::shared_ptr<Serializable> extractSerializableOrThrow(
97
+ jsi::Runtime &rt,
98
+ const jsi::Value &maybeSerializableValue,
99
+ const std::string &errorMessage) {
100
+ if (maybeSerializableValue.isObject()) {
101
+ auto object = maybeSerializableValue.getObject(rt);
102
+ return extractSerializableOrThrow(rt, object, errorMessage);
103
+ } else if (maybeSerializableValue.isUndefined()) {
104
+ return Serializable::undefined();
105
+ }
106
+ throw std::runtime_error(errorMessage);
107
+ }
108
+
109
+ std::shared_ptr<Serializable> extractSerializableOrThrow(
110
+ jsi::Runtime &rt,
111
+ const jsi::Object &maybeSerializableValue,
112
+ const std::string &errorMessage) {
113
+ if (maybeSerializableValue.hasNativeState(rt)) {
114
+ auto nativeState = maybeSerializableValue.getNativeState(rt);
115
+ return std::dynamic_pointer_cast<SerializableJSRef>(nativeState)->value();
116
+ }
117
+ throw std::runtime_error(errorMessage);
118
+ }
119
+
120
+ Serializable::~Serializable() = default;
121
+
122
+ std::shared_ptr<Serializable> Serializable::undefined() {
123
+ static auto undefined = std::make_shared<SerializableScalar>();
124
+ return undefined;
125
+ }
126
+
127
+ SerializableJSRef::~SerializableJSRef() = default;
128
+
129
+ } // namespace worklets
@@ -0,0 +1,121 @@
1
+ #pragma once
2
+
3
+ #include <jsi/jsi.h>
4
+ #include <worklets/Compat/StableApi.h>
5
+ #include <worklets/Registries/WorkletRuntimeRegistry.h>
6
+
7
+ #include <memory>
8
+ #include <new>
9
+ #include <stdexcept>
10
+ #include <string>
11
+
12
+ namespace worklets {
13
+
14
+ // Frees the heap-allocated facebook::jsi::Value wrapper without running ~facebook::jsi::Value.
15
+ // Use when the runtime that owns the JSI handle is already gone. When the
16
+ // owning runtime is terminated, the orphaned JSI objects would crash the app
17
+ // if their destructors ran, because they call into memory managed by the
18
+ // terminated runtime. The JS object itself lived inside the runtime's heap
19
+ // and was reclaimed with the runtime; only the C++ wrapper allocation
20
+ // remains, and we free it here without invoking ~facebook::jsi::Value.
21
+ // See https://github.com/facebook/hermes/blob/75b617a/API/jsi/jsi/jsi.h#L833
22
+ inline void freeWithoutCallingDestructor(std::unique_ptr<facebook::jsi::Value> &value) {
23
+ ::operator delete(value.release());
24
+ }
25
+
26
+ inline void cleanupRuntimeAware(facebook::jsi::Runtime *rt, std::unique_ptr<facebook::jsi::Value> &value) {
27
+ if (value == nullptr || rt == nullptr) {
28
+ return;
29
+ }
30
+ WorkletRuntimeRegistry::runWhileLocked(rt, [&value](bool isAlive) {
31
+ if (isAlive) {
32
+ value.reset();
33
+ } else {
34
+ freeWithoutCallingDestructor(value);
35
+ }
36
+ });
37
+ }
38
+
39
+ inline void cleanupRuntimeAware(facebook::jsi::Runtime *rt, facebook::jsi::Value &value) {
40
+ if (rt == nullptr || value.isUndefined()) {
41
+ return;
42
+ }
43
+ WorkletRuntimeRegistry::runWhileLocked(rt, [&value](bool isAlive) {
44
+ if (isAlive) {
45
+ value.~Value();
46
+ }
47
+ new (&value) facebook::jsi::Value(facebook::jsi::Value::undefined());
48
+ });
49
+ }
50
+
51
+ class SerializableJSRef : public facebook::jsi::NativeState {
52
+ private:
53
+ const std::shared_ptr<Serializable> value_;
54
+
55
+ public:
56
+ explicit SerializableJSRef(const std::shared_ptr<Serializable> &value) : value_(value) {}
57
+
58
+ ~SerializableJSRef() override;
59
+
60
+ std::shared_ptr<Serializable> value() const {
61
+ return value_;
62
+ }
63
+
64
+ static facebook::jsi::Object newNativeStateObject(
65
+ facebook::jsi::Runtime &rt,
66
+ const std::shared_ptr<Serializable> &value) {
67
+ auto object = facebook::jsi::Object(rt);
68
+ object.setNativeState(rt, std::make_shared<SerializableJSRef>(value));
69
+ object.setProperty(rt, "__serializableRef", true);
70
+ return object;
71
+ }
72
+ };
73
+
74
+ facebook::jsi::Function getValueUnpacker(facebook::jsi::Runtime &rt);
75
+
76
+ [[nodiscard]]
77
+ facebook::jsi::Value makeSerializableClone(
78
+ facebook::jsi::Runtime &rt,
79
+ const facebook::jsi::Value &value,
80
+ const facebook::jsi::Value &shouldRetainRemote,
81
+ const facebook::jsi::Value &nativeStateSource);
82
+
83
+ [[nodiscard]]
84
+ std::shared_ptr<Serializable> extractSerializableOrThrow(
85
+ facebook::jsi::Runtime &rt,
86
+ const facebook::jsi::Value &maybeSerializableValue,
87
+ const std::string &errorMessage = "[Worklets] Expecting the object to be of type SerializableJSRef.");
88
+
89
+ [[nodiscard]]
90
+ std::shared_ptr<Serializable> extractSerializableOrThrow(
91
+ facebook::jsi::Runtime &rt,
92
+ const facebook::jsi::Object &maybeSerializableValue,
93
+ const std::string &errorMessage = "[Worklets] Expecting the object to be of type SerializableJSRef.");
94
+
95
+ template <typename TSerializable>
96
+ [[nodiscard]]
97
+ std::shared_ptr<TSerializable> extractSerializableOrThrow(
98
+ facebook::jsi::Runtime &rt,
99
+ const facebook::jsi::Value &serializableRef,
100
+ const std::string &errorMessage = "[Worklets] Provided serializable object is of an incompatible type.") {
101
+ auto res = std::dynamic_pointer_cast<TSerializable>(extractSerializableOrThrow(rt, serializableRef, errorMessage));
102
+ if (!res) {
103
+ throw std::runtime_error(errorMessage);
104
+ }
105
+ return res;
106
+ }
107
+
108
+ template <typename TSerializable>
109
+ [[nodiscard]]
110
+ std::shared_ptr<TSerializable> extractSerializableOrThrow(
111
+ facebook::jsi::Runtime &rt,
112
+ const facebook::jsi::Object &serializableRef,
113
+ const std::string &errorMessage = "[Worklets] Provided serializable object is of an incompatible type.") {
114
+ auto res = std::dynamic_pointer_cast<TSerializable>(extractSerializableOrThrow(rt, serializableRef, errorMessage));
115
+ if (!res) {
116
+ throw std::runtime_error(errorMessage);
117
+ }
118
+ return res;
119
+ }
120
+
121
+ } // namespace worklets
@@ -0,0 +1,38 @@
1
+ #include <jsi/jsi.h>
2
+ #include <worklets/SharedItems/Serializable/RetainingSerializable.h>
3
+ #include <worklets/SharedItems/Serializable/SerializableArray.h>
4
+
5
+ #include <memory>
6
+
7
+ using namespace facebook;
8
+
9
+ namespace worklets {
10
+
11
+ SerializableArray::SerializableArray(jsi::Runtime &rt, const jsi::Array &array) : Serializable(ValueType::ArrayType) {
12
+ auto size = array.size(rt);
13
+ data_.reserve(size);
14
+ for (size_t i = 0; i < size; i++) {
15
+ data_.push_back(extractSerializableOrThrow(rt, array.getValueAtIndex(rt, i)));
16
+ }
17
+ }
18
+
19
+ jsi::Value SerializableArray::toJSValue(jsi::Runtime &rt) {
20
+ auto size = data_.size();
21
+ auto ary = jsi::Array(rt, size);
22
+ for (size_t i = 0; i < size; i++) {
23
+ ary.setValueAtIndex(rt, i, data_[i]->toJSValue(rt));
24
+ }
25
+ return ary;
26
+ }
27
+
28
+ jsi::Value makeSerializableArray(jsi::Runtime &rt, const jsi::Array &array, const jsi::Value &shouldRetainRemote) {
29
+ std::shared_ptr<Serializable> serializable;
30
+ if (shouldRetainRemote.isBool() && shouldRetainRemote.getBool()) {
31
+ serializable = std::make_shared<RetainingSerializable<SerializableArray>>(rt, array);
32
+ } else {
33
+ serializable = std::make_shared<SerializableArray>(rt, array);
34
+ }
35
+ return SerializableJSRef::newNativeStateObject(rt, serializable);
36
+ }
37
+
38
+ } // namespace worklets
@@ -0,0 +1,39 @@
1
+ #pragma once
2
+
3
+ #include <jsi/jsi.h>
4
+ #include <worklets/SharedItems/Serializable/Serializable.h>
5
+
6
+ #include <memory>
7
+ #include <vector>
8
+
9
+ namespace worklets {
10
+
11
+ class SerializableArray : public Serializable {
12
+ public:
13
+ SerializableArray(facebook::jsi::Runtime &rt, const facebook::jsi::Array &array);
14
+
15
+ facebook::jsi::Value toJSValue(facebook::jsi::Runtime &rt) override;
16
+
17
+ std::vector<facebook::jsi::Value> getJSIValueArr(facebook::jsi::Runtime &rt) {
18
+ std::vector<facebook::jsi::Value> args;
19
+ args.reserve(data_.size());
20
+ for (const auto &item : data_) {
21
+ args.push_back(item->toJSValue(rt));
22
+ }
23
+ return args;
24
+ }
25
+
26
+ [[nodiscard]] const std::vector<std::shared_ptr<Serializable>> &getList() const {
27
+ return data_;
28
+ }
29
+
30
+ protected:
31
+ std::vector<std::shared_ptr<Serializable>> data_;
32
+ };
33
+
34
+ facebook::jsi::Value makeSerializableArray(
35
+ facebook::jsi::Runtime &rt,
36
+ const facebook::jsi::Array &array,
37
+ const facebook::jsi::Value &shouldRetainRemote);
38
+
39
+ } // namespace worklets
@@ -0,0 +1,35 @@
1
+ #include <jsi/jsi.h>
2
+ #include <worklets/SharedItems/Serializable/SerializableArrayBuffer.h>
3
+
4
+ #include <cstring>
5
+ #include <memory>
6
+ #include <optional>
7
+ #include <utility>
8
+
9
+ using namespace facebook;
10
+
11
+ namespace worklets {
12
+
13
+ jsi::Value SerializableArrayBuffer::toJSValue(jsi::Runtime &rt) {
14
+ auto size = static_cast<int>(data_.size());
15
+ auto arrayBuffer =
16
+ rt.global().getPropertyAsFunction(rt, "ArrayBuffer").callAsConstructor(rt, size).getObject(rt).getArrayBuffer(rt);
17
+ memcpy(arrayBuffer.data(rt), data_.data(), size);
18
+ if (!metadata_.has_value()) {
19
+ return arrayBuffer;
20
+ }
21
+
22
+ auto constructor = rt.global().getPropertyAsFunction(rt, metadata_->typeName.c_str());
23
+ return constructor.callAsConstructor(
24
+ rt, arrayBuffer, static_cast<double>(metadata_->byteOffset), static_cast<double>(metadata_->length));
25
+ }
26
+
27
+ jsi::Value makeSerializableArrayBuffer(
28
+ jsi::Runtime &rt,
29
+ const jsi::ArrayBuffer &arrayBuffer,
30
+ std::optional<ArrayBufferMetadata> metadata) {
31
+ auto serializable = std::make_shared<SerializableArrayBuffer>(rt, arrayBuffer, std::move(metadata));
32
+ return SerializableJSRef::newNativeStateObject(rt, serializable);
33
+ }
34
+
35
+ } // namespace worklets
@@ -0,0 +1,43 @@
1
+ #pragma once
2
+
3
+ #include <jsi/jsi.h>
4
+ #include <worklets/SharedItems/Serializable/Serializable.h>
5
+
6
+ #include <cstddef>
7
+ #include <cstdint>
8
+ #include <optional>
9
+ #include <string>
10
+ #include <utility>
11
+ #include <vector>
12
+
13
+ namespace worklets {
14
+
15
+ struct ArrayBufferMetadata {
16
+ std::string typeName;
17
+ size_t byteOffset;
18
+ size_t length;
19
+ };
20
+
21
+ class SerializableArrayBuffer : public Serializable {
22
+ public:
23
+ SerializableArrayBuffer(
24
+ facebook::jsi::Runtime &rt,
25
+ const facebook::jsi::ArrayBuffer &arrayBuffer,
26
+ std::optional<ArrayBufferMetadata> metadata = std::nullopt)
27
+ : Serializable(ValueType::ArrayBufferType),
28
+ metadata_(std::move(metadata)),
29
+ data_(arrayBuffer.data(rt), arrayBuffer.data(rt) + arrayBuffer.size(rt)) {}
30
+
31
+ facebook::jsi::Value toJSValue(facebook::jsi::Runtime &rt) override;
32
+
33
+ protected:
34
+ std::optional<ArrayBufferMetadata> metadata_;
35
+ std::vector<uint8_t> data_;
36
+ };
37
+
38
+ facebook::jsi::Value makeSerializableArrayBuffer(
39
+ facebook::jsi::Runtime &rt,
40
+ const facebook::jsi::ArrayBuffer &arrayBuffer,
41
+ std::optional<ArrayBufferMetadata> metadata = std::nullopt);
42
+
43
+ } // namespace worklets
@@ -0,0 +1,23 @@
1
+ #include <jsi/jsi.h>
2
+ #include <worklets/SharedItems/Serializable/SerializableBigInt.h>
3
+
4
+ #include <memory>
5
+
6
+ using namespace facebook;
7
+
8
+ namespace worklets {
9
+
10
+ jsi::Value SerializableBigInt::toJSValue(jsi::Runtime &rt) {
11
+ if (fastValue_.has_value()) {
12
+ return jsi::BigInt::fromInt64(rt, fastValue_.value());
13
+ } else {
14
+ return rt.global().getPropertyAsFunction(rt, "BigInt").call(rt, jsi::String::createFromUtf8(rt, slowValue_));
15
+ }
16
+ }
17
+
18
+ jsi::Value makeSerializableBigInt(jsi::Runtime &rt, const jsi::BigInt &bigint) {
19
+ const auto serializable = std::make_shared<SerializableBigInt>(rt, bigint);
20
+ return SerializableJSRef::newNativeStateObject(rt, serializable);
21
+ }
22
+
23
+ } // namespace worklets
@@ -0,0 +1,35 @@
1
+ #pragma once
2
+
3
+ #include <jsi/jsi.h>
4
+ #include <worklets/SharedItems/Serializable/Serializable.h>
5
+
6
+ #include <cstdint>
7
+ #include <optional>
8
+ #include <string>
9
+
10
+ namespace worklets {
11
+
12
+ class SerializableBigInt : public Serializable {
13
+ public:
14
+ explicit SerializableBigInt(facebook::jsi::Runtime &rt, const facebook::jsi::BigInt &bigInt)
15
+ : Serializable(ValueType::BigIntType) {
16
+ if (bigInt.isInt64(rt)) {
17
+ fastValue_ = bigInt.getInt64(rt);
18
+ } else {
19
+ slowValue_ = bigInt.toString(rt).utf8(rt);
20
+ }
21
+ }
22
+
23
+ facebook::jsi::Value toJSValue(facebook::jsi::Runtime &rt) override;
24
+
25
+ protected:
26
+ /**
27
+ * This member is used only when the BigInt fits into int64_t range.
28
+ */
29
+ std::optional<int64_t> fastValue_{};
30
+ std::string slowValue_{};
31
+ };
32
+
33
+ facebook::jsi::Value makeSerializableBigInt(facebook::jsi::Runtime &rt, const facebook::jsi::BigInt &bigint);
34
+
35
+ } // namespace worklets
@@ -0,0 +1,38 @@
1
+ #include <jsi/jsi.h>
2
+ #include <worklets/SharedItems/Serializable/SerializableError.h>
3
+
4
+ #include <memory>
5
+ #include <optional>
6
+ #include <string>
7
+
8
+ using namespace facebook;
9
+
10
+ namespace worklets {
11
+
12
+ jsi::Value SerializableError::toJSValue(jsi::Runtime &rt) {
13
+ auto error = rt.global()
14
+ .getPropertyAsFunction(rt, "Error")
15
+ .callAsConstructor(rt, jsi::String::createFromUtf8(rt, message_))
16
+ .getObject(rt);
17
+
18
+ error.setProperty(rt, "name", jsi::String::createFromUtf8(rt, name_));
19
+
20
+ if (stack_.has_value()) {
21
+ error.setProperty(rt, "stack", jsi::String::createFromUtf8(rt, stack_.value()));
22
+ } else {
23
+ error.setProperty(rt, "stack", jsi::String::createFromUtf8(rt, ""));
24
+ }
25
+
26
+ return error;
27
+ }
28
+
29
+ jsi::Value makeSerializableError(
30
+ jsi::Runtime &rt,
31
+ const std::string &name,
32
+ const std::string &message,
33
+ const std::optional<std::string> &stack) {
34
+ auto serializable = std::make_shared<SerializableError>(name, message, stack);
35
+ return SerializableJSRef::newNativeStateObject(rt, serializable);
36
+ }
37
+
38
+ } // namespace worklets
@@ -0,0 +1,30 @@
1
+ #pragma once
2
+
3
+ #include <jsi/jsi.h>
4
+ #include <worklets/SharedItems/Serializable/Serializable.h>
5
+
6
+ #include <optional>
7
+ #include <string>
8
+
9
+ namespace worklets {
10
+
11
+ class SerializableError : public Serializable {
12
+ public:
13
+ SerializableError(const std::string &name, const std::string &message, const std::optional<std::string> &stack)
14
+ : Serializable(ValueType::ErrorType), name_(name), message_(message), stack_(stack) {}
15
+
16
+ facebook::jsi::Value toJSValue(facebook::jsi::Runtime &rt) override;
17
+
18
+ protected:
19
+ const std::string name_;
20
+ const std::string message_;
21
+ const std::optional<std::string> stack_;
22
+ };
23
+
24
+ facebook::jsi::Value makeSerializableError(
25
+ facebook::jsi::Runtime &rt,
26
+ const std::string &name,
27
+ const std::string &message,
28
+ const std::optional<std::string> &stack);
29
+
30
+ } // namespace worklets
@@ -0,0 +1,24 @@
1
+ #include <jsi/jsi.h>
2
+ #include <worklets/SharedItems/Serializable/SerializableHostFunction.h>
3
+
4
+ #include <memory>
5
+ #include <string>
6
+
7
+ using namespace facebook;
8
+
9
+ namespace worklets {
10
+
11
+ jsi::Value SerializableHostFunction::toJSValue(jsi::Runtime &rt) {
12
+ return jsi::Function::createFromHostFunction(rt, jsi::PropNameID::forUtf8(rt, name_), paramCount_, hostFunction_);
13
+ }
14
+
15
+ jsi::Value makeSerializableHostFunction(
16
+ jsi::Runtime &rt,
17
+ const jsi::HostFunctionType &function,
18
+ const std::string &name,
19
+ unsigned int paramCount) {
20
+ auto serializable = std::make_shared<SerializableHostFunction>(function, name, paramCount);
21
+ return SerializableJSRef::newNativeStateObject(rt, serializable);
22
+ }
23
+
24
+ } // namespace worklets