@depup/react-native-worklets 0.12.1-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 +7 -7
  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 +40 -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 +40 -5
  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 +6 -6
  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 +3 -31
  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 +22 -9
  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 +36 -22
  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 +6 -46
  255. package/src/memory/synchronizable.native.ts +38 -4
  256. package/src/memory/synchronizable.ts +22 -2
  257. package/src/memory/synchronizableUnpacker.native.ts +38 -13
  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 -373
  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 -203
  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,22 @@
1
+ #pragma once
2
+
3
+ #include <jsi/jsi.h>
4
+ #include <worklets/SharedItems/Serializable/Serializable.h>
5
+
6
+ #include <string>
7
+
8
+ namespace worklets {
9
+
10
+ class SerializableString : public Serializable {
11
+ public:
12
+ explicit SerializableString(const std::string &string) : Serializable(ValueType::StringType), data_(string) {}
13
+
14
+ facebook::jsi::Value toJSValue(facebook::jsi::Runtime &rt) override;
15
+
16
+ protected:
17
+ const std::string data_;
18
+ };
19
+
20
+ facebook::jsi::Value makeSerializableString(facebook::jsi::Runtime &rt, const facebook::jsi::String &string);
21
+
22
+ } // namespace worklets
@@ -0,0 +1,26 @@
1
+ #include <jsi/jsi.h>
2
+ #include <worklets/SharedItems/Serializable/SerializableTurboModuleLike.h>
3
+
4
+ #include <memory>
5
+
6
+ using namespace facebook;
7
+
8
+ namespace worklets {
9
+
10
+ jsi::Value SerializableTurboModuleLike::toJSValue(jsi::Runtime &rt) {
11
+ auto obj = properties_->toJSValue(rt).asObject(rt);
12
+ const auto prototype = proto_->toJSValue(rt);
13
+ rt.global().getPropertyAsObject(rt, "Object").getPropertyAsFunction(rt, "setPrototypeOf").call(rt, obj, prototype);
14
+
15
+ return obj;
16
+ }
17
+
18
+ jsi::Value makeSerializableTurboModuleLike(
19
+ jsi::Runtime &rt,
20
+ const jsi::Object &object,
21
+ const std::shared_ptr<jsi::HostObject> &proto) {
22
+ const auto serializable = std::make_shared<SerializableTurboModuleLike>(rt, object, proto);
23
+ return SerializableJSRef::newNativeStateObject(rt, serializable);
24
+ }
25
+
26
+ } // namespace worklets
@@ -0,0 +1,33 @@
1
+ #pragma once
2
+
3
+ #include <jsi/jsi.h>
4
+ #include <worklets/SharedItems/Serializable/SerializableHostObject.h>
5
+ #include <worklets/SharedItems/Serializable/SerializableObject.h>
6
+
7
+ #include <memory>
8
+
9
+ namespace worklets {
10
+
11
+ class SerializableTurboModuleLike : public Serializable {
12
+ public:
13
+ SerializableTurboModuleLike(
14
+ facebook::jsi::Runtime &rt,
15
+ const facebook::jsi::Object &object,
16
+ const std::shared_ptr<facebook::jsi::HostObject> &proto)
17
+ : Serializable(ValueType::TurboModuleLikeType),
18
+ proto_(std::make_unique<SerializableHostObject>(rt, proto)),
19
+ properties_(std::make_unique<SerializableObject>(rt, object)) {}
20
+
21
+ facebook::jsi::Value toJSValue(facebook::jsi::Runtime &rt) override;
22
+
23
+ private:
24
+ const std::unique_ptr<SerializableHostObject> proto_;
25
+ const std::unique_ptr<SerializableObject> properties_;
26
+ };
27
+
28
+ facebook::jsi::Value makeSerializableTurboModuleLike(
29
+ facebook::jsi::Runtime &rt,
30
+ const facebook::jsi::Object &object,
31
+ const std::shared_ptr<facebook::jsi::HostObject> &proto);
32
+
33
+ } // namespace worklets
@@ -0,0 +1,31 @@
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/SerializableWorklet.h>
5
+
6
+ #include <algorithm>
7
+ #include <memory>
8
+
9
+ using namespace facebook;
10
+
11
+ namespace worklets {
12
+
13
+ jsi::Value SerializableWorklet::toJSValue(jsi::Runtime &rt) {
14
+ react_native_assert(
15
+ std::any_of(data_.cbegin(), data_.cend(), [](const auto &item) { return item.first == "__workletHash"; }) &&
16
+ "SerializableWorklet doesn't have `__workletHash` property");
17
+ jsi::Value obj = SerializableObject::toJSValue(rt);
18
+ return getValueUnpacker(rt).call(rt, obj, jsi::String::createFromAscii(rt, "Worklet"));
19
+ }
20
+
21
+ jsi::Value makeSerializableWorklet(jsi::Runtime &rt, const jsi::Object &object, const bool &shouldRetainRemote) {
22
+ std::shared_ptr<Serializable> serializable;
23
+ if (shouldRetainRemote) {
24
+ serializable = std::make_shared<RetainingSerializable<SerializableWorklet>>(rt, object);
25
+ } else {
26
+ serializable = std::make_shared<SerializableWorklet>(rt, object);
27
+ }
28
+ return SerializableJSRef::newNativeStateObject(rt, serializable);
29
+ }
30
+
31
+ } // namespace worklets
@@ -0,0 +1,23 @@
1
+ #pragma once
2
+
3
+ #include <jsi/jsi.h>
4
+ #include <worklets/SharedItems/Serializable/SerializableObject.h>
5
+
6
+ namespace worklets {
7
+
8
+ class SerializableWorklet : public SerializableObject {
9
+ public:
10
+ SerializableWorklet(facebook::jsi::Runtime &rt, const facebook::jsi::Object &worklet)
11
+ : SerializableObject(rt, worklet) {
12
+ valueType_ = ValueType::WorkletType;
13
+ }
14
+
15
+ facebook::jsi::Value toJSValue(facebook::jsi::Runtime &rt) override;
16
+ };
17
+
18
+ facebook::jsi::Value makeSerializableWorklet(
19
+ facebook::jsi::Runtime &rt,
20
+ const facebook::jsi::Object &object,
21
+ const bool &shouldRetainRemote);
22
+
23
+ } // namespace worklets
@@ -1,411 +1,23 @@
1
1
  #pragma once
2
2
 
3
- #include <jsi/jsi.h>
4
- #include <worklets/Compat/StableApi.h>
5
- #include <worklets/Registries/WorkletRuntimeRegistry.h>
6
- #include <worklets/Tools/JSScheduler.h>
7
- #include <worklets/WorkletRuntime/RuntimeData.h>
8
-
9
- #include <atomic>
10
- #include <memory>
11
- #include <mutex>
12
- #include <optional>
13
- #include <string>
14
- #include <utility>
15
- #include <vector>
16
-
17
- using namespace facebook;
18
-
19
- namespace worklets {
20
-
21
- // Frees the heap-allocated jsi::Value wrapper without running ~jsi::Value.
22
- // Use when the runtime that owns the JSI handle is already gone. When the
23
- // owning runtime is terminated, the orphaned JSI objects would crash the app
24
- // if their destructors ran, because they call into memory managed by the
25
- // terminated runtime. The JS object itself lived inside the runtime's heap
26
- // and was reclaimed with the runtime; only the C++ wrapper allocation
27
- // remains, and we free it here without invoking ~jsi::Value.
28
- // See https://github.com/facebook/hermes/blob/75b617a/API/jsi/jsi/jsi.h#L833
29
- inline void freeWithoutCallingDestructor(std::unique_ptr<jsi::Value> &value) {
30
- ::operator delete(value.release());
31
- }
32
-
33
- inline void cleanupRuntimeAware(jsi::Runtime *rt, std::unique_ptr<jsi::Value> &value) {
34
- if (value == nullptr || rt == nullptr) {
35
- return;
36
- }
37
- WorkletRuntimeRegistry::runWhileLocked(rt, [&value](bool isAlive) {
38
- if (isAlive) {
39
- value.reset();
40
- } else {
41
- freeWithoutCallingDestructor(value);
42
- }
43
- });
44
- }
45
-
46
- template <typename BaseClass>
47
- class RetainingSerializable : virtual public BaseClass {
48
- private:
49
- jsi::Runtime *primaryRuntime_;
50
- std::unique_ptr<jsi::Value> secondaryValue_;
51
- std::atomic<jsi::Runtime *> secondaryRuntime_{nullptr};
52
- std::mutex secondaryCacheMutex_;
53
-
54
- public:
55
- template <typename... Args>
56
- explicit RetainingSerializable(jsi::Runtime &rt, Args &&...args)
57
- : BaseClass(rt, std::forward<Args>(args)...), primaryRuntime_(&rt) {}
58
-
59
- jsi::Value toJSValue(jsi::Runtime &rt) override {
60
- if (&rt == primaryRuntime_) {
61
- return BaseClass::toJSValue(rt);
62
- }
63
- if (secondaryRuntime_.load(std::memory_order_acquire) == &rt) {
64
- return jsi::Value(rt, *secondaryValue_);
65
- }
66
- auto value = BaseClass::toJSValue(rt);
67
- {
68
- std::lock_guard<std::mutex> lock(secondaryCacheMutex_);
69
- if (secondaryRuntime_.load(std::memory_order_relaxed) == nullptr) {
70
- secondaryValue_ = std::make_unique<jsi::Value>(rt, value);
71
- secondaryRuntime_.store(&rt, std::memory_order_release);
72
- }
73
- }
74
- return value;
75
- }
76
-
77
- ~RetainingSerializable() override {
78
- cleanupRuntimeAware(secondaryRuntime_.load(std::memory_order_relaxed), secondaryValue_);
79
- }
80
- };
81
-
82
- class SerializableJSRef : public jsi::NativeState {
83
- private:
84
- const std::shared_ptr<Serializable> value_;
85
-
86
- public:
87
- explicit SerializableJSRef(const std::shared_ptr<Serializable> &value) : value_(value) {}
88
-
89
- ~SerializableJSRef() override;
90
-
91
- std::shared_ptr<Serializable> value() const {
92
- return value_;
93
- }
94
-
95
- static jsi::Object newNativeStateObject(jsi::Runtime &rt, const std::shared_ptr<Serializable> &value) {
96
- auto object = jsi::Object(rt);
97
- object.setNativeState(rt, std::make_shared<SerializableJSRef>(value));
98
- object.setProperty(rt, "__serializableRef", true);
99
- return object;
100
- }
101
- };
102
-
103
- [[nodiscard]]
104
- jsi::Value makeSerializableClone(
105
- jsi::Runtime &rt,
106
- const jsi::Value &value,
107
- const jsi::Value &shouldRetainRemote,
108
- const jsi::Value &nativeStateSource);
109
-
110
- [[nodiscard]]
111
- std::shared_ptr<Serializable> extractSerializableOrThrow(
112
- jsi::Runtime &rt,
113
- const jsi::Value &maybeSerializableValue,
114
- const std::string &errorMessage = "[Worklets] Expecting the object to be of type SerializableJSRef.");
115
-
116
- [[nodiscard]]
117
- std::shared_ptr<Serializable> extractSerializableOrThrow(
118
- jsi::Runtime &rt,
119
- const jsi::Object &maybeSerializableValue,
120
- const std::string &errorMessage = "[Worklets] Expecting the object to be of type SerializableJSRef.");
121
-
122
- template <typename TSerializable>
123
- [[nodiscard]]
124
- std::shared_ptr<TSerializable> extractSerializableOrThrow(
125
- jsi::Runtime &rt,
126
- const jsi::Value &serializableRef,
127
- const std::string &errorMessage = "[Worklets] Provided serializable object is of an incompatible type.") {
128
- auto res = std::dynamic_pointer_cast<TSerializable>(extractSerializableOrThrow(rt, serializableRef, errorMessage));
129
- if (!res) {
130
- throw std::runtime_error(errorMessage);
131
- }
132
- return res;
133
- }
134
-
135
- template <typename TSerializable>
136
- [[nodiscard]]
137
- std::shared_ptr<TSerializable> extractSerializableOrThrow(
138
- jsi::Runtime &rt,
139
- const jsi::Object &serializableRef,
140
- const std::string &errorMessage = "[Worklets] Provided serializable object is of an incompatible type.") {
141
- auto res = std::dynamic_pointer_cast<TSerializable>(extractSerializableOrThrow(rt, serializableRef, errorMessage));
142
- if (!res) {
143
- throw std::runtime_error(errorMessage);
144
- }
145
- return res;
146
- }
147
-
148
- class SerializableArray : public Serializable {
149
- public:
150
- SerializableArray(jsi::Runtime &rt, const jsi::Array &array);
151
-
152
- jsi::Value toJSValue(jsi::Runtime &rt) override;
153
-
154
- std::vector<jsi::Value> getJSIValueArr(jsi::Runtime &rt) {
155
- std::vector<jsi::Value> args;
156
- args.reserve(data_.size());
157
- for (const auto &item : data_) {
158
- args.push_back(item->toJSValue(rt));
159
- }
160
- return args;
161
- }
162
-
163
- [[nodiscard]] const std::vector<std::shared_ptr<Serializable>> &getList() const {
164
- return data_;
165
- }
166
-
167
- protected:
168
- std::vector<std::shared_ptr<Serializable>> data_;
169
- };
170
-
171
- class SerializableObject : public Serializable {
172
- public:
173
- SerializableObject(jsi::Runtime &rt, const jsi::Object &object);
174
-
175
- SerializableObject(jsi::Runtime &rt, const jsi::Object &object, const jsi::Value &nativeStateSource);
176
-
177
- jsi::Value toJSValue(jsi::Runtime &rt) override;
178
-
179
- protected:
180
- std::vector<std::pair<std::string, std::shared_ptr<Serializable>>> data_;
181
- std::shared_ptr<jsi::NativeState> nativeState_;
182
- };
183
-
184
- class SerializableMap : public Serializable {
185
- public:
186
- SerializableMap(jsi::Runtime &rt, const jsi::Array &keys, const jsi::Array &values);
187
-
188
- jsi::Value toJSValue(jsi::Runtime &rt) override;
189
-
190
- protected:
191
- std::vector<std::pair<std::shared_ptr<Serializable>, std::shared_ptr<Serializable>>> data_;
192
- };
193
-
194
- class SerializableSet : public Serializable {
195
- public:
196
- SerializableSet(jsi::Runtime &rt, const jsi::Array &values);
197
-
198
- jsi::Value toJSValue(jsi::Runtime &rt) override;
199
-
200
- protected:
201
- std::vector<std::shared_ptr<Serializable>> data_;
202
- };
203
-
204
- class SerializableError : public Serializable {
205
- public:
206
- SerializableError(const std::string &name, const std::string &message, const std::optional<std::string> &stack)
207
- : Serializable(ValueType::ErrorType), name_(name), message_(message), stack_(stack) {}
208
-
209
- jsi::Value toJSValue(jsi::Runtime &rt) override;
210
-
211
- protected:
212
- const std::string name_;
213
- const std::string message_;
214
- const std::optional<std::string> stack_;
215
- };
216
-
217
- class SerializableRegExp : public Serializable {
218
- public:
219
- SerializableRegExp(const std::string &pattern, const std::string &flags)
220
- : Serializable(ValueType::RegExpType), pattern_(pattern), flags_(flags) {}
221
-
222
- jsi::Value toJSValue(jsi::Runtime &rt) override;
223
-
224
- protected:
225
- const std::string pattern_;
226
- const std::string flags_;
227
- };
228
-
229
- class SerializableHostObject : public Serializable {
230
- public:
231
- SerializableHostObject(jsi::Runtime &, const std::shared_ptr<jsi::HostObject> &hostObject)
232
- : Serializable(ValueType::HostObjectType), hostObject_(hostObject) {}
233
-
234
- jsi::Value toJSValue(jsi::Runtime &rt) override;
235
-
236
- protected:
237
- const std::shared_ptr<jsi::HostObject> hostObject_;
238
- };
239
-
240
- class SerializableHostFunction : public Serializable {
241
- public:
242
- SerializableHostFunction(const jsi::HostFunctionType &function, const std::string &name, unsigned int paramCount)
243
- : Serializable(ValueType::HostFunctionType), hostFunction_(function), name_(name), paramCount_(paramCount) {}
244
-
245
- jsi::Value toJSValue(jsi::Runtime &rt) override;
246
-
247
- protected:
248
- const jsi::HostFunctionType hostFunction_;
249
- const std::string name_;
250
- const unsigned int paramCount_;
251
- };
252
-
253
- struct ArrayBufferMetadata {
254
- std::string typeName;
255
- size_t byteOffset;
256
- size_t length;
257
- };
258
-
259
- class SerializableArrayBuffer : public Serializable {
260
- public:
261
- SerializableArrayBuffer(
262
- jsi::Runtime &rt,
263
- const jsi::ArrayBuffer &arrayBuffer,
264
- std::optional<ArrayBufferMetadata> metadata = std::nullopt)
265
- : Serializable(ValueType::ArrayBufferType),
266
- metadata_(std::move(metadata)),
267
- data_(arrayBuffer.data(rt), arrayBuffer.data(rt) + arrayBuffer.size(rt)) {}
268
-
269
- jsi::Value toJSValue(jsi::Runtime &rt) override;
270
-
271
- protected:
272
- std::optional<ArrayBufferMetadata> metadata_;
273
- std::vector<uint8_t> data_;
274
- };
275
-
276
- class SerializableWorklet : public SerializableObject {
277
- public:
278
- SerializableWorklet(jsi::Runtime &rt, const jsi::Object &worklet) : SerializableObject(rt, worklet) {
279
- valueType_ = ValueType::WorkletType;
280
- }
281
-
282
- jsi::Value toJSValue(jsi::Runtime &rt) override;
283
- };
284
-
285
- class SerializableImport : public Serializable {
286
- public:
287
- SerializableImport(jsi::Runtime &rt, const double source, const jsi::String &imported)
288
- : Serializable(ValueType::ImportType), source_(source), imported_(imported.utf8(rt)) {}
289
-
290
- jsi::Value toJSValue(jsi::Runtime &rt) override;
291
-
292
- protected:
293
- const double source_;
294
- const std::string imported_;
295
- };
296
-
297
- class SerializableInitializer : public Serializable {
298
- private:
299
- // We don't release the initializer since the handle can get
300
- // initialized in parallel on multiple threads. However this is not a problem,
301
- // since the final value is taken from a cache on the runtime which guarantees
302
- // sequential access.
303
- std::unique_ptr<SerializableObject> initializer_;
304
- std::unique_ptr<jsi::Value> remoteValue_;
305
- mutable std::mutex initializationMutex_;
306
- jsi::Runtime *remoteRuntime_;
307
-
308
- public:
309
- SerializableInitializer(jsi::Runtime &rt, const jsi::Object &initializerObject)
310
- : Serializable(ValueType::HandleType),
311
- initializer_(std::make_unique<SerializableObject>(rt, initializerObject)) {}
312
-
313
- ~SerializableInitializer() override {
314
- cleanupRuntimeAware(remoteRuntime_, remoteValue_);
315
- }
316
-
317
- jsi::Value toJSValue(jsi::Runtime &rt) override;
318
- };
319
-
320
- class SerializableString : public Serializable {
321
- public:
322
- explicit SerializableString(const std::string &string) : Serializable(ValueType::StringType), data_(string) {}
323
-
324
- jsi::Value toJSValue(jsi::Runtime &rt) override;
325
-
326
- protected:
327
- const std::string data_;
328
- };
329
-
330
- class SerializableBigInt : public Serializable {
331
- public:
332
- explicit SerializableBigInt(jsi::Runtime &rt, const jsi::BigInt &bigInt) : Serializable(ValueType::BigIntType) {
333
- if (bigInt.isInt64(rt)) {
334
- fastValue_ = bigInt.getInt64(rt);
335
- } else {
336
- slowValue_ = bigInt.toString(rt).utf8(rt);
337
- }
338
- }
339
-
340
- jsi::Value toJSValue(jsi::Runtime &rt) override;
341
-
342
- protected:
343
- /**
344
- * This member is used only when the BigInt fits into int64_t range.
345
- */
346
- std::optional<int64_t> fastValue_{};
347
- std::string slowValue_{};
348
- };
349
-
350
- class SerializableScalar : public Serializable {
351
- public:
352
- explicit SerializableScalar(double number) : Serializable(ValueType::NumberType) {
353
- data_.number = number;
354
- }
355
- explicit SerializableScalar(bool boolean) : Serializable(ValueType::BooleanType) {
356
- data_.boolean = boolean;
357
- }
358
- SerializableScalar() : Serializable(ValueType::UndefinedType) {}
359
- explicit SerializableScalar(std::nullptr_t) : Serializable(ValueType::NullType) {}
360
-
361
- jsi::Value toJSValue(jsi::Runtime &) override;
362
-
363
- protected:
364
- union Data {
365
- bool boolean;
366
- double number;
367
- };
368
-
369
- private:
370
- Data data_;
371
- };
372
-
373
- class SerializableTurboModuleLike : public Serializable {
374
- public:
375
- SerializableTurboModuleLike(
376
- jsi::Runtime &rt,
377
- const jsi::Object &object,
378
- const std::shared_ptr<jsi::HostObject> &proto)
379
- : Serializable(ValueType::TurboModuleLikeType),
380
- proto_(std::make_unique<SerializableHostObject>(rt, proto)),
381
- properties_(std::make_unique<SerializableObject>(rt, object)) {}
382
-
383
- jsi::Value toJSValue(jsi::Runtime &rt) override;
384
-
385
- private:
386
- const std::unique_ptr<SerializableHostObject> proto_;
387
- const std::unique_ptr<SerializableObject> properties_;
388
- };
389
-
390
- jsi::Function getCustomSerializableUnpacker(jsi::Runtime &rt);
391
-
392
- class CustomSerializable : public Serializable {
393
- public:
394
- CustomSerializable(std::shared_ptr<Serializable> data, const int typeId)
395
- : Serializable(ValueType::CustomType), data_(std::move(data)), typeId_(typeId) {}
396
-
397
- jsi::Value toJSValue(jsi::Runtime &rt) override;
398
-
399
- private:
400
- const std::shared_ptr<Serializable> data_;
401
- const int typeId_;
402
- };
403
-
404
- struct SerializationData {
405
- std::shared_ptr<SerializableWorklet> determine;
406
- std::shared_ptr<SerializableWorklet> pack;
407
- std::shared_ptr<SerializableWorklet> unpack;
408
- int typeId;
409
- };
410
-
411
- } // namespace worklets
3
+ #warning Do not include this file directly, it will be removed in the future. Prefer including specific Serializable headers.
4
+
5
+ #include <worklets/SharedItems/Serializable/CustomSerializable.h>
6
+ #include <worklets/SharedItems/Serializable/RetainingSerializable.h>
7
+ #include <worklets/SharedItems/Serializable/Serializable.h>
8
+ #include <worklets/SharedItems/Serializable/SerializableArray.h>
9
+ #include <worklets/SharedItems/Serializable/SerializableArrayBuffer.h>
10
+ #include <worklets/SharedItems/Serializable/SerializableBigInt.h>
11
+ #include <worklets/SharedItems/Serializable/SerializableError.h>
12
+ #include <worklets/SharedItems/Serializable/SerializableHostFunction.h>
13
+ #include <worklets/SharedItems/Serializable/SerializableHostObject.h>
14
+ #include <worklets/SharedItems/Serializable/SerializableImport.h>
15
+ #include <worklets/SharedItems/Serializable/SerializableMap.h>
16
+ #include <worklets/SharedItems/Serializable/SerializableObject.h>
17
+ #include <worklets/SharedItems/Serializable/SerializableRegExp.h>
18
+ #include <worklets/SharedItems/Serializable/SerializableRemoteFunction.h>
19
+ #include <worklets/SharedItems/Serializable/SerializableScalar.h>
20
+ #include <worklets/SharedItems/Serializable/SerializableSet.h>
21
+ #include <worklets/SharedItems/Serializable/SerializableString.h>
22
+ #include <worklets/SharedItems/Serializable/SerializableTurboModuleLike.h>
23
+ #include <worklets/SharedItems/Serializable/SerializableWorklet.h>
@@ -1,5 +1,5 @@
1
1
  #include <jsi/jsi.h>
2
- #include <worklets/SharedItems/Serializable.h>
2
+ #include <worklets/SharedItems/Serializable/Serializable.h>
3
3
  #include <worklets/SharedItems/Shareable.h>
4
4
  #include <worklets/WorkletRuntime/WorkletRuntime.h>
5
5
 
@@ -1,7 +1,7 @@
1
1
  #pragma once
2
2
 
3
3
  #include <jsi/jsi.h>
4
- #include <worklets/SharedItems/Serializable.h>
4
+ #include <worklets/SharedItems/Serializable/Serializable.h>
5
5
  #include <worklets/WorkletRuntime/WorkletRuntime.h>
6
6
 
7
7
  #include <memory>
@@ -1,57 +1,80 @@
1
1
  #pragma once
2
2
 
3
3
  #include <jsi/jsi.h>
4
- #include <worklets/SharedItems/Serializable.h>
4
+ #include <react/debug/react_native_assert.h>
5
+ #include <worklets/SharedItems/Serializable/Serializable.h>
5
6
  #include <worklets/SharedItems/SynchronizableAccess.h>
6
7
 
7
8
  #include <memory>
8
-
9
- using namespace facebook;
9
+ #include <utility>
10
+ #include <variant>
10
11
 
11
12
  namespace worklets {
12
13
 
14
+ using SynchronizableValue = std::variant<std::shared_ptr<Serializable>, double, bool>;
15
+ using SynchronizableFixedValue = std::variant<double, bool>;
16
+
13
17
  class Synchronizable : public SynchronizableAccess,
14
18
  public Serializable,
15
- public jsi::NativeState,
19
+ public facebook::jsi::NativeState,
16
20
  public std::enable_shared_from_this<Synchronizable> {
17
21
  public:
22
+ static std::shared_ptr<Synchronizable> extractSynchronizableOrThrow(
23
+ facebook::jsi::Runtime &rt,
24
+ const facebook::jsi::Value &value) {
25
+ auto serializable =
26
+ extractSerializableOrThrow(rt, value, "[Worklets] Expecting the object to be of type SerializableJSRef.");
27
+
28
+ auto synchronizable = std::dynamic_pointer_cast<Synchronizable>(serializable);
29
+ react_native_assert(synchronizable != nullptr && "[Worklets] Expected the object to be a Synchronizable.");
30
+
31
+ return synchronizable;
32
+ }
33
+
34
+ bool isFixed() const {
35
+ return isFixed_;
36
+ }
37
+
18
38
  /**
19
39
  * Can run concurrently with getDirty, setDirty, getBlocking, setBlocking.
20
40
  */
21
- std::shared_ptr<Serializable> getDirty();
41
+ virtual SynchronizableValue getDirty() = 0;
22
42
 
23
43
  /**
24
44
  * Can run concurrently with getDirty, getBlocking.
25
45
  * Can't run concurrently with setDirty, setBlocking.
26
46
  */
27
- std::shared_ptr<Serializable> getBlocking();
47
+ virtual SynchronizableValue getBlocking() = 0;
28
48
 
29
- // TODO: Shared pointer members (unless they're atomic) can't be assigned
30
- // in a non thread-safe manner, therefore `setDirty` has little sense now.
31
49
  /**
32
- * Can run concurrently with getDirty, getBlocking.
33
- * Can't run concurrently with setDirty, setBlocking.
50
+ * Can run concurrently with getDirty, setDirty.
51
+ * Can't run concurrently with getBlocking, setBlocking.
34
52
  */
35
- // void setDirty(const std::shared_ptr<Serializable> &value);
53
+ virtual void setDirty(const SynchronizableFixedValue &value) = 0;
36
54
 
37
55
  /**
38
56
  * Can run concurrently with getDirty.
39
57
  * Can't run concurrently with getBlocking, setDirty, setBlocking.
40
58
  */
41
- void setBlocking(const std::shared_ptr<Serializable> &value);
59
+ virtual void setBlocking(const std::shared_ptr<Serializable> &value) = 0;
42
60
 
43
- jsi::Value toJSValue(jsi::Runtime &rt) override;
61
+ virtual void setBlocking(const SynchronizableFixedValue &value) = 0;
44
62
 
45
- explicit Synchronizable(const std::shared_ptr<Serializable> &value);
63
+ facebook::jsi::Value toJSValue(facebook::jsi::Runtime &rt) final {
64
+ auto synchronizableUnpacker = rt.global().getProperty(rt, "__synchronizableUnpacker");
65
+ react_native_assert(synchronizableUnpacker.isObject() && "synchronizableUnpacker not found");
66
+ auto ref = SerializableJSRef::newNativeStateObject(rt, this->shared_from_this());
67
+ return synchronizableUnpacker.getObject(rt).getFunction(rt).call(
68
+ rt, std::move(ref), facebook::jsi::Value(isFixed()));
69
+ }
46
70
 
47
71
  ~Synchronizable() override = default;
48
72
 
73
+ protected:
74
+ explicit Synchronizable(bool isFixed) : Serializable(ValueType::SynchronizableType), isFixed_(isFixed) {}
75
+
49
76
  private:
50
- std::shared_ptr<Serializable> value_;
77
+ const bool isFixed_;
51
78
  };
52
79
 
53
- jsi::Function getSynchronizableUnpacker(jsi::Runtime &rt);
54
-
55
- std::shared_ptr<Synchronizable> extractSynchronizableOrThrow(jsi::Runtime &rt, const jsi::Value &value);
56
-
57
- }; // namespace worklets
80
+ } // namespace worklets