@depup/react-native-worklets 0.11.3-depup.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.worklets/dummy.md +1 -0
- package/Common/cpp/worklets/AnimationFrameQueue/AnimationFrameBatchinator.cpp +64 -0
- package/Common/cpp/worklets/AnimationFrameQueue/AnimationFrameBatchinator.h +38 -0
- package/Common/cpp/worklets/Compat/Holders.h +25 -0
- package/Common/cpp/worklets/Compat/StableApi.cpp +145 -0
- package/Common/cpp/worklets/Compat/StableApi.h +128 -0
- package/Common/cpp/worklets/NativeModules/JSIWorkletsModuleProxy.cpp +729 -0
- package/Common/cpp/worklets/NativeModules/JSIWorkletsModuleProxy.h +126 -0
- package/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.cpp +81 -0
- package/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.h +76 -0
- package/Common/cpp/worklets/Registries/EventHandlerRegistry.cpp +95 -0
- package/Common/cpp/worklets/Registries/EventHandlerRegistry.h +44 -0
- package/Common/cpp/worklets/Registries/WorkletRuntimeRegistry.cpp +10 -0
- package/Common/cpp/worklets/Registries/WorkletRuntimeRegistry.h +43 -0
- package/Common/cpp/worklets/RunLoop/AsyncQueue.h +14 -0
- package/Common/cpp/worklets/RunLoop/AsyncQueueImpl.cpp +69 -0
- package/Common/cpp/worklets/RunLoop/AsyncQueueImpl.h +48 -0
- package/Common/cpp/worklets/RunLoop/EventLoop.cpp +103 -0
- package/Common/cpp/worklets/RunLoop/EventLoop.h +52 -0
- package/Common/cpp/worklets/SharedItems/MemoryManager.cpp +60 -0
- package/Common/cpp/worklets/SharedItems/MemoryManager.h +29 -0
- package/Common/cpp/worklets/SharedItems/Serializable.cpp +373 -0
- package/Common/cpp/worklets/SharedItems/Serializable.h +413 -0
- package/Common/cpp/worklets/SharedItems/SerializableFactory.cpp +172 -0
- package/Common/cpp/worklets/SharedItems/SerializableFactory.h +85 -0
- package/Common/cpp/worklets/SharedItems/SerializableRemoteFunction.cpp +71 -0
- package/Common/cpp/worklets/SharedItems/SerializableRemoteFunction.h +75 -0
- package/Common/cpp/worklets/SharedItems/Shareable.cpp +84 -0
- package/Common/cpp/worklets/SharedItems/Shareable.h +43 -0
- package/Common/cpp/worklets/SharedItems/Synchronizable.cpp +59 -0
- package/Common/cpp/worklets/SharedItems/Synchronizable.h +57 -0
- package/Common/cpp/worklets/SharedItems/SynchronizableAccess.cpp +78 -0
- package/Common/cpp/worklets/SharedItems/SynchronizableAccess.h +45 -0
- package/Common/cpp/worklets/SharedItems/UnpackerLoader.h +78 -0
- package/Common/cpp/worklets/Tools/FeatureFlags.cpp +18 -0
- package/Common/cpp/worklets/Tools/FeatureFlags.h +44 -0
- package/Common/cpp/worklets/Tools/JSISerializer.cpp +312 -0
- package/Common/cpp/worklets/Tools/JSISerializer.h +42 -0
- package/Common/cpp/worklets/Tools/JSLogger.cpp +92 -0
- package/Common/cpp/worklets/Tools/JSLogger.h +48 -0
- package/Common/cpp/worklets/Tools/JSScheduler.cpp +21 -0
- package/Common/cpp/worklets/Tools/JSScheduler.h +35 -0
- package/Common/cpp/worklets/Tools/PlatformLogger.h +16 -0
- package/Common/cpp/worklets/Tools/RNRuntimeStatus.h +27 -0
- package/Common/cpp/worklets/Tools/ScriptBuffer.h +56 -0
- package/Common/cpp/worklets/Tools/SingleInstanceChecker.h +75 -0
- package/Common/cpp/worklets/Tools/ThreadSafeQueue.h +49 -0
- package/Common/cpp/worklets/Tools/UIScheduler.cpp +19 -0
- package/Common/cpp/worklets/Tools/UIScheduler.h +22 -0
- package/Common/cpp/worklets/Tools/VersionUtils.cpp +61 -0
- package/Common/cpp/worklets/Tools/VersionUtils.h +24 -0
- package/Common/cpp/worklets/Tools/WorkletEventHandler.cpp +34 -0
- package/Common/cpp/worklets/Tools/WorkletEventHandler.h +44 -0
- package/Common/cpp/worklets/Tools/WorkletsJSIUtils.cpp +30 -0
- package/Common/cpp/worklets/Tools/WorkletsJSIUtils.h +222 -0
- package/Common/cpp/worklets/Tools/WorkletsSystraceSection.h +116 -0
- package/Common/cpp/worklets/Tools/WorkletsVersion.cpp +46 -0
- package/Common/cpp/worklets/Tools/WorkletsVersion.h +18 -0
- package/Common/cpp/worklets/WorkletRuntime/BundleModeConfig.h +17 -0
- package/Common/cpp/worklets/WorkletRuntime/HermesProfiling.cpp +45 -0
- package/Common/cpp/worklets/WorkletRuntime/HermesProfiling.h +12 -0
- package/Common/cpp/worklets/WorkletRuntime/RNRuntimeWorkletDecorator.cpp +68 -0
- package/Common/cpp/worklets/WorkletRuntime/RNRuntimeWorkletDecorator.h +24 -0
- package/Common/cpp/worklets/WorkletRuntime/RuntimeBindings.h +59 -0
- package/Common/cpp/worklets/WorkletRuntime/RuntimeData.h +38 -0
- package/Common/cpp/worklets/WorkletRuntime/RuntimeHolder.h +19 -0
- package/Common/cpp/worklets/WorkletRuntime/RuntimeManager.cpp +122 -0
- package/Common/cpp/worklets/WorkletRuntime/RuntimeManager.h +75 -0
- package/Common/cpp/worklets/WorkletRuntime/ScriptLoader.h +116 -0
- package/Common/cpp/worklets/WorkletRuntime/UIRuntimeDecorator.cpp +14 -0
- package/Common/cpp/worklets/WorkletRuntime/UIRuntimeDecorator.h +15 -0
- package/Common/cpp/worklets/WorkletRuntime/WorkletHermesRuntime.cpp +58 -0
- package/Common/cpp/worklets/WorkletRuntime/WorkletHermesRuntime.h +100 -0
- package/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.cpp +327 -0
- package/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.h +256 -0
- package/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeCollector.h +36 -0
- package/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.cpp +320 -0
- package/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.h +36 -0
- package/LICENSE +20 -0
- package/README.md +43 -0
- package/RNWorklets.podspec +94 -0
- package/android/CMakeLists.txt +108 -0
- package/android/build.gradle.kts +369 -0
- package/android/fix-prefab.gradle.kts +56 -0
- package/android/generate-stub-pch.gradle.kts +84 -0
- package/android/gradle.properties +25 -0
- package/android/proguard-rules.pro +3 -0
- package/android/settings.gradle.kts +21 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/cpp/WorkletsPCH.h +26 -0
- package/android/src/main/cpp/worklets/android/AndroidUIScheduler.cpp +66 -0
- package/android/src/main/cpp/worklets/android/AndroidUIScheduler.h +38 -0
- package/android/src/main/cpp/worklets/android/AnimationFrameCallback.h +30 -0
- package/android/src/main/cpp/worklets/android/JScriptBufferWrapper.cpp +66 -0
- package/android/src/main/cpp/worklets/android/JScriptBufferWrapper.h +48 -0
- package/android/src/main/cpp/worklets/android/JWorkletRuntimeWrapper.cpp +51 -0
- package/android/src/main/cpp/worklets/android/JWorkletRuntimeWrapper.h +43 -0
- package/android/src/main/cpp/worklets/android/PlatformLogger.cpp +31 -0
- package/android/src/main/cpp/worklets/android/WorkletsModule.cpp +203 -0
- package/android/src/main/cpp/worklets/android/WorkletsModule.h +75 -0
- package/android/src/main/cpp/worklets/android/WorkletsOnLoad.cpp +19 -0
- package/android/src/main/java/com/swmansion/worklets/AndroidUIScheduler.kt +56 -0
- package/android/src/main/java/com/swmansion/worklets/ScriptBufferWrapper.kt +103 -0
- package/android/src/main/java/com/swmansion/worklets/WorkletsPackage.kt +42 -0
- package/android/src/main/java/com/swmansion/worklets/runloop/AnimationFrameCallback.kt +14 -0
- package/android/src/main/java/com/swmansion/worklets/runloop/AnimationFrameQueue.kt +112 -0
- package/android/src/networking/com/swmansion/worklets/WorkletRuntimeWrapper.kt +27 -0
- package/android/src/networking/com/swmansion/worklets/WorkletsHeaderUtil.kt +30 -0
- package/android/src/networking/com/swmansion/worklets/WorkletsModule.kt +187 -0
- package/android/src/networking/com/swmansion/worklets/WorkletsNetworkEventUtil.kt +272 -0
- package/android/src/networking/com/swmansion/worklets/WorkletsNetworking.kt +1124 -0
- package/android/src/networking/com/swmansion/worklets/WorkletsOkHttpCallUtil.kt +40 -0
- package/android/src/networking/com/swmansion/worklets/WorkletsProgressListener.kt +13 -0
- package/android/src/networking/com/swmansion/worklets/WorkletsProgressRequestBody.kt +98 -0
- package/android/src/networking/com/swmansion/worklets/WorkletsProgressResponseBody.kt +60 -0
- package/android/src/networking/com/swmansion/worklets/WorkletsProgressiveStringDecoder.kt +87 -0
- package/android/src/networking/com/swmansion/worklets/WorkletsRequestBodyUtil.kt +181 -0
- package/android/src/no-networking/com/swmansion/worklets/WorkletsModule.kt +143 -0
- package/apple/worklets/apple/AnimationFrameQueue.h +15 -0
- package/apple/worklets/apple/AnimationFrameQueue.mm +145 -0
- package/apple/worklets/apple/AssertJavaScriptQueue.h +14 -0
- package/apple/worklets/apple/AssertTurboModuleManagerQueue.h +12 -0
- package/apple/worklets/apple/IOSUIScheduler.h +14 -0
- package/apple/worklets/apple/IOSUIScheduler.mm +29 -0
- package/apple/worklets/apple/Networking/WorkletsNetworking.h +25 -0
- package/apple/worklets/apple/Networking/WorkletsNetworking.mm +707 -0
- package/apple/worklets/apple/PlatformLogger.mm +31 -0
- package/apple/worklets/apple/SlowAnimations.h +8 -0
- package/apple/worklets/apple/SlowAnimations.mm +45 -0
- package/apple/worklets/apple/WorkletsDisplayLink.h +21 -0
- package/apple/worklets/apple/WorkletsModule.h +28 -0
- package/apple/worklets/apple/WorkletsModule.mm +177 -0
- package/bundleMode/index.d.ts +6 -0
- package/bundleMode/index.js +182 -0
- package/bundleMode/shims/reactNativeShim.js +21 -0
- package/bundleMode/shims/turboModuleRegistryShim.js +47 -0
- package/changes.json +58 -0
- package/compatibility.json +29 -0
- package/jest/pluginTestUtils.ts +16 -0
- package/jest/resolver.js +18 -0
- package/lib/module/WorkletsModule/NativeWorklets.js +4 -0
- package/lib/module/WorkletsModule/NativeWorklets.js.map +1 -0
- package/lib/module/WorkletsModule/NativeWorklets.native.js +199 -0
- package/lib/module/WorkletsModule/NativeWorklets.native.js.map +1 -0
- package/lib/module/WorkletsModule/workletsModuleProxy.js +4 -0
- package/lib/module/WorkletsModule/workletsModuleProxy.js.map +1 -0
- package/lib/module/bundleMode/metroOverrides.native.js +26 -0
- package/lib/module/bundleMode/metroOverrides.native.js.map +1 -0
- package/lib/module/bundleMode/network.native.js +44 -0
- package/lib/module/bundleMode/network.native.js.map +1 -0
- package/lib/module/debug/bundleMode.js +6 -0
- package/lib/module/debug/bundleMode.js.map +1 -0
- package/lib/module/debug/bundleMode.native.js +11 -0
- package/lib/module/debug/bundleMode.native.js.map +1 -0
- package/lib/module/debug/checkCppVersion.js +29 -0
- package/lib/module/debug/checkCppVersion.js.map +1 -0
- package/lib/module/debug/errors.native.js +67 -0
- package/lib/module/debug/errors.native.js.map +1 -0
- package/lib/module/debug/jsVersion.js +9 -0
- package/lib/module/debug/jsVersion.js.map +1 -0
- package/lib/module/debug/logger.js +15 -0
- package/lib/module/debug/logger.js.map +1 -0
- package/lib/module/debug/slowAnimations.js +7 -0
- package/lib/module/debug/slowAnimations.js.map +1 -0
- package/lib/module/debug/slowAnimations.native.js +17 -0
- package/lib/module/debug/slowAnimations.native.js.map +1 -0
- package/lib/module/deprecated.js +27 -0
- package/lib/module/deprecated.js.map +1 -0
- package/lib/module/featureFlags/featureFlags.js +12 -0
- package/lib/module/featureFlags/featureFlags.js.map +1 -0
- package/lib/module/featureFlags/featureFlags.native.js +51 -0
- package/lib/module/featureFlags/featureFlags.native.js.map +1 -0
- package/lib/module/featureFlags/staticFlags.json +6 -0
- package/lib/module/featureFlags/types.js +16 -0
- package/lib/module/featureFlags/types.js.map +1 -0
- package/lib/module/guardImplementation.native.js +17 -0
- package/lib/module/guardImplementation.native.js.map +1 -0
- package/lib/module/index.js +26 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/initializers/initializers.js +24 -0
- package/lib/module/initializers/initializers.js.map +1 -0
- package/lib/module/initializers/initializers.native.js +195 -0
- package/lib/module/initializers/initializers.native.js.map +1 -0
- package/lib/module/memory/bundleUnpacker.native.js +38 -0
- package/lib/module/memory/bundleUnpacker.native.js.map +1 -0
- package/lib/module/memory/customSerializableUnpacker.native.js +20 -0
- package/lib/module/memory/customSerializableUnpacker.native.js.map +1 -0
- package/lib/module/memory/isShareable.js +8 -0
- package/lib/module/memory/isShareable.js.map +1 -0
- package/lib/module/memory/isSynchronizable.js +8 -0
- package/lib/module/memory/isSynchronizable.js.map +1 -0
- package/lib/module/memory/remoteFunctionUnpacker.native.js +18 -0
- package/lib/module/memory/remoteFunctionUnpacker.native.js.map +1 -0
- package/lib/module/memory/serializable.js +18 -0
- package/lib/module/memory/serializable.js.map +1 -0
- package/lib/module/memory/serializable.native.js +619 -0
- package/lib/module/memory/serializable.native.js.map +1 -0
- package/lib/module/memory/serializableMappingCache.js +11 -0
- package/lib/module/memory/serializableMappingCache.js.map +1 -0
- package/lib/module/memory/serializableMappingCache.native.js +29 -0
- package/lib/module/memory/serializableMappingCache.native.js.map +1 -0
- package/lib/module/memory/shareable.js +18 -0
- package/lib/module/memory/shareable.js.map +1 -0
- package/lib/module/memory/shareable.native.js +42 -0
- package/lib/module/memory/shareable.native.js.map +1 -0
- package/lib/module/memory/shareableGuestUnpacker.native.js +105 -0
- package/lib/module/memory/shareableGuestUnpacker.native.js.map +1 -0
- package/lib/module/memory/shareableHostUnpacker.native.js +20 -0
- package/lib/module/memory/shareableHostUnpacker.native.js.map +1 -0
- package/lib/module/memory/synchronizable.js +6 -0
- package/lib/module/memory/synchronizable.js.map +1 -0
- package/lib/module/memory/synchronizable.native.js +9 -0
- package/lib/module/memory/synchronizable.native.js.map +1 -0
- package/lib/module/memory/synchronizableUnpacker.native.js +47 -0
- package/lib/module/memory/synchronizableUnpacker.native.js.map +1 -0
- package/lib/module/memory/types.js +12 -0
- package/lib/module/memory/types.js.map +1 -0
- package/lib/module/memory/valueUnpacker.native.js +52 -0
- package/lib/module/memory/valueUnpacker.native.js.map +1 -0
- package/lib/module/mock.js +85 -0
- package/lib/module/mock.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/platformChecker.js +4 -0
- package/lib/module/platformChecker.js.map +1 -0
- package/lib/module/platformChecker.native.js +4 -0
- package/lib/module/platformChecker.native.js.map +1 -0
- package/lib/module/privateGlobals.d.js +7 -0
- package/lib/module/privateGlobals.d.js.map +1 -0
- package/lib/module/runLoop/common/setImmediatePolyfill.js +15 -0
- package/lib/module/runLoop/common/setImmediatePolyfill.js.map +1 -0
- package/lib/module/runLoop/common/setIntervalPolyfill.js +26 -0
- package/lib/module/runLoop/common/setIntervalPolyfill.js.map +1 -0
- package/lib/module/runLoop/uiRuntime/mockedRequestAnimationFrame.js +10 -0
- package/lib/module/runLoop/uiRuntime/mockedRequestAnimationFrame.js.map +1 -0
- package/lib/module/runLoop/uiRuntime/requestAnimationFrame.js +71 -0
- package/lib/module/runLoop/uiRuntime/requestAnimationFrame.js.map +1 -0
- package/lib/module/runLoop/uiRuntime/setTimeoutPolyfill.js +32 -0
- package/lib/module/runLoop/uiRuntime/setTimeoutPolyfill.js.map +1 -0
- package/lib/module/runLoop/workletRuntime/index.js +19 -0
- package/lib/module/runLoop/workletRuntime/index.js.map +1 -0
- package/lib/module/runLoop/workletRuntime/queueMicrotask.js +11 -0
- package/lib/module/runLoop/workletRuntime/queueMicrotask.js.map +1 -0
- package/lib/module/runLoop/workletRuntime/requestAnimationFramePolyfill.js +48 -0
- package/lib/module/runLoop/workletRuntime/requestAnimationFramePolyfill.js.map +1 -0
- package/lib/module/runLoop/workletRuntime/setTimeout.js +28 -0
- package/lib/module/runLoop/workletRuntime/setTimeout.js.map +1 -0
- package/lib/module/runLoop/workletRuntime/taskQueue.js +37 -0
- package/lib/module/runLoop/workletRuntime/taskQueue.js.map +1 -0
- package/lib/module/runtimeKind.js +92 -0
- package/lib/module/runtimeKind.js.map +1 -0
- package/lib/module/runtimes.js +36 -0
- package/lib/module/runtimes.js.map +1 -0
- package/lib/module/runtimes.native.js +379 -0
- package/lib/module/runtimes.native.js.map +1 -0
- package/lib/module/specs/NativeWorkletsModule.js +5 -0
- package/lib/module/specs/NativeWorkletsModule.js.map +1 -0
- package/lib/module/specs/index.js +10 -0
- package/lib/module/specs/index.js.map +1 -0
- package/lib/module/threads.js +60 -0
- package/lib/module/threads.js.map +1 -0
- package/lib/module/threads.native.js +295 -0
- package/lib/module/threads.native.js.map +1 -0
- package/lib/module/types.js +5 -0
- package/lib/module/types.js.map +1 -0
- package/lib/module/workletFunction.js +36 -0
- package/lib/module/workletFunction.js.map +1 -0
- package/lib/typescript/WorkletsModule/NativeWorklets.d.ts +3 -0
- package/lib/typescript/WorkletsModule/NativeWorklets.d.ts.map +1 -0
- package/lib/typescript/WorkletsModule/NativeWorklets.native.d.ts +3 -0
- package/lib/typescript/WorkletsModule/NativeWorklets.native.d.ts.map +1 -0
- package/lib/typescript/WorkletsModule/workletsModuleProxy.d.ts +59 -0
- package/lib/typescript/WorkletsModule/workletsModuleProxy.d.ts.map +1 -0
- package/lib/typescript/bundleMode/metroOverrides.native.d.ts +9 -0
- package/lib/typescript/bundleMode/metroOverrides.native.d.ts.map +1 -0
- package/lib/typescript/bundleMode/network.native.d.ts +7 -0
- package/lib/typescript/bundleMode/network.native.d.ts.map +1 -0
- package/lib/typescript/debug/bundleMode.d.ts +2 -0
- package/lib/typescript/debug/bundleMode.d.ts.map +1 -0
- package/lib/typescript/debug/bundleMode.native.d.ts +2 -0
- package/lib/typescript/debug/bundleMode.native.d.ts.map +1 -0
- package/lib/typescript/debug/checkCppVersion.d.ts +3 -0
- package/lib/typescript/debug/checkCppVersion.d.ts.map +1 -0
- package/lib/typescript/debug/errors.native.d.ts +13 -0
- package/lib/typescript/debug/errors.native.d.ts.map +1 -0
- package/lib/typescript/debug/jsVersion.d.ts +7 -0
- package/lib/typescript/debug/jsVersion.d.ts.map +1 -0
- package/lib/typescript/debug/logger.d.ts +5 -0
- package/lib/typescript/debug/logger.d.ts.map +1 -0
- package/lib/typescript/debug/slowAnimations.d.ts +2 -0
- package/lib/typescript/debug/slowAnimations.d.ts.map +1 -0
- package/lib/typescript/debug/slowAnimations.native.d.ts +11 -0
- package/lib/typescript/debug/slowAnimations.native.d.ts.map +1 -0
- package/lib/typescript/deprecated.d.ts +19 -0
- package/lib/typescript/deprecated.d.ts.map +1 -0
- package/lib/typescript/featureFlags/featureFlags.d.ts +5 -0
- package/lib/typescript/featureFlags/featureFlags.d.ts.map +1 -0
- package/lib/typescript/featureFlags/featureFlags.native.d.ts +6 -0
- package/lib/typescript/featureFlags/featureFlags.native.d.ts.map +1 -0
- package/lib/typescript/featureFlags/types.d.ts +23 -0
- package/lib/typescript/featureFlags/types.d.ts.map +1 -0
- package/lib/typescript/guardImplementation.native.d.ts +3 -0
- package/lib/typescript/guardImplementation.native.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +19 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/initializers/initializers.d.ts +2 -0
- package/lib/typescript/initializers/initializers.d.ts.map +1 -0
- package/lib/typescript/initializers/initializers.native.d.ts +19 -0
- package/lib/typescript/initializers/initializers.native.d.ts.map +1 -0
- package/lib/typescript/memory/bundleUnpacker.native.d.ts +7 -0
- package/lib/typescript/memory/bundleUnpacker.native.d.ts.map +1 -0
- package/lib/typescript/memory/customSerializableUnpacker.native.d.ts +3 -0
- package/lib/typescript/memory/customSerializableUnpacker.native.d.ts.map +1 -0
- package/lib/typescript/memory/isShareable.d.ts +3 -0
- package/lib/typescript/memory/isShareable.d.ts.map +1 -0
- package/lib/typescript/memory/isSynchronizable.d.ts +3 -0
- package/lib/typescript/memory/isSynchronizable.d.ts.map +1 -0
- package/lib/typescript/memory/remoteFunctionUnpacker.native.d.ts +3 -0
- package/lib/typescript/memory/remoteFunctionUnpacker.native.d.ts.map +1 -0
- package/lib/typescript/memory/serializable.d.ts +7 -0
- package/lib/typescript/memory/serializable.d.ts.map +1 -0
- package/lib/typescript/memory/serializable.native.d.ts +37 -0
- package/lib/typescript/memory/serializable.native.d.ts.map +1 -0
- package/lib/typescript/memory/serializableMappingCache.d.ts +6 -0
- package/lib/typescript/memory/serializableMappingCache.d.ts.map +1 -0
- package/lib/typescript/memory/serializableMappingCache.native.d.ts +13 -0
- package/lib/typescript/memory/serializableMappingCache.native.d.ts.map +1 -0
- package/lib/typescript/memory/shareable.d.ts +15 -0
- package/lib/typescript/memory/shareable.d.ts.map +1 -0
- package/lib/typescript/memory/shareable.native.d.ts +15 -0
- package/lib/typescript/memory/shareable.native.d.ts.map +1 -0
- package/lib/typescript/memory/shareableGuestUnpacker.native.d.ts +4 -0
- package/lib/typescript/memory/shareableGuestUnpacker.native.d.ts.map +1 -0
- package/lib/typescript/memory/shareableHostUnpacker.native.d.ts +4 -0
- package/lib/typescript/memory/shareableHostUnpacker.native.d.ts.map +1 -0
- package/lib/typescript/memory/synchronizable.d.ts +3 -0
- package/lib/typescript/memory/synchronizable.d.ts.map +1 -0
- package/lib/typescript/memory/synchronizable.native.d.ts +3 -0
- package/lib/typescript/memory/synchronizable.native.d.ts.map +1 -0
- package/lib/typescript/memory/synchronizableUnpacker.native.d.ts +4 -0
- package/lib/typescript/memory/synchronizableUnpacker.native.d.ts.map +1 -0
- package/lib/typescript/memory/types.d.ts +136 -0
- package/lib/typescript/memory/types.d.ts.map +1 -0
- package/lib/typescript/memory/valueUnpacker.native.d.ts +7 -0
- package/lib/typescript/memory/valueUnpacker.native.d.ts.map +1 -0
- package/lib/typescript/mock.d.ts +2 -0
- package/lib/typescript/mock.d.ts.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/platformChecker.d.ts +2 -0
- package/lib/typescript/platformChecker.d.ts.map +1 -0
- package/lib/typescript/platformChecker.native.d.ts +2 -0
- package/lib/typescript/platformChecker.native.d.ts.map +1 -0
- package/lib/typescript/runLoop/common/setImmediatePolyfill.d.ts +2 -0
- package/lib/typescript/runLoop/common/setImmediatePolyfill.d.ts.map +1 -0
- package/lib/typescript/runLoop/common/setIntervalPolyfill.d.ts +2 -0
- package/lib/typescript/runLoop/common/setIntervalPolyfill.d.ts.map +1 -0
- package/lib/typescript/runLoop/uiRuntime/mockedRequestAnimationFrame.d.ts +6 -0
- package/lib/typescript/runLoop/uiRuntime/mockedRequestAnimationFrame.d.ts.map +1 -0
- package/lib/typescript/runLoop/uiRuntime/requestAnimationFrame.d.ts +2 -0
- package/lib/typescript/runLoop/uiRuntime/requestAnimationFrame.d.ts.map +1 -0
- package/lib/typescript/runLoop/uiRuntime/setTimeoutPolyfill.d.ts +2 -0
- package/lib/typescript/runLoop/uiRuntime/setTimeoutPolyfill.d.ts.map +1 -0
- package/lib/typescript/runLoop/workletRuntime/index.d.ts +2 -0
- package/lib/typescript/runLoop/workletRuntime/index.d.ts.map +1 -0
- package/lib/typescript/runLoop/workletRuntime/queueMicrotask.d.ts +2 -0
- package/lib/typescript/runLoop/workletRuntime/queueMicrotask.d.ts.map +1 -0
- package/lib/typescript/runLoop/workletRuntime/requestAnimationFramePolyfill.d.ts +2 -0
- package/lib/typescript/runLoop/workletRuntime/requestAnimationFramePolyfill.d.ts.map +1 -0
- package/lib/typescript/runLoop/workletRuntime/setTimeout.d.ts +2 -0
- package/lib/typescript/runLoop/workletRuntime/setTimeout.d.ts.map +1 -0
- package/lib/typescript/runLoop/workletRuntime/taskQueue.d.ts +10 -0
- package/lib/typescript/runLoop/workletRuntime/taskQueue.d.ts.map +1 -0
- package/lib/typescript/runtimeKind.d.ts +56 -0
- package/lib/typescript/runtimeKind.d.ts.map +1 -0
- package/lib/typescript/runtimes.d.ts +15 -0
- package/lib/typescript/runtimes.d.ts.map +1 -0
- package/lib/typescript/runtimes.native.d.ts +155 -0
- package/lib/typescript/runtimes.native.d.ts.map +1 -0
- package/lib/typescript/specs/NativeWorkletsModule.d.ts +9 -0
- package/lib/typescript/specs/NativeWorkletsModule.d.ts.map +1 -0
- package/lib/typescript/specs/index.d.ts +3 -0
- package/lib/typescript/specs/index.d.ts.map +1 -0
- package/lib/typescript/threads.d.ts +8 -0
- package/lib/typescript/threads.d.ts.map +1 -0
- package/lib/typescript/threads.native.d.ts +125 -0
- package/lib/typescript/threads.native.d.ts.map +1 -0
- package/lib/typescript/types.d.ts +136 -0
- package/lib/typescript/types.d.ts.map +1 -0
- package/lib/typescript/workletFunction.d.ts +26 -0
- package/lib/typescript/workletFunction.d.ts.map +1 -0
- package/package.json +220 -0
- package/plugin/index.d.ts +168 -0
- package/plugin/index.js +2188 -0
- package/scripts/validate-react-native-version.js +43 -0
- package/scripts/worklets_utils.rb +94 -0
- package/src/WorkletsModule/NativeWorklets.native.ts +461 -0
- package/src/WorkletsModule/NativeWorklets.ts +5 -0
- package/src/WorkletsModule/workletsModuleProxy.ts +247 -0
- package/src/bundleMode/metroOverrides.native.ts +33 -0
- package/src/bundleMode/network.native.ts +63 -0
- package/src/debug/bundleMode.native.ts +18 -0
- package/src/debug/bundleMode.ts +5 -0
- package/src/debug/checkCppVersion.ts +34 -0
- package/src/debug/errors.native.ts +74 -0
- package/src/debug/jsVersion.ts +8 -0
- package/src/debug/logger.ts +16 -0
- package/src/debug/slowAnimations.native.ts +15 -0
- package/src/debug/slowAnimations.ts +6 -0
- package/src/deprecated.ts +38 -0
- package/src/featureFlags/featureFlags.native.ts +70 -0
- package/src/featureFlags/featureFlags.ts +20 -0
- package/src/featureFlags/staticFlags.json +6 -0
- package/src/featureFlags/types.ts +32 -0
- package/src/guardImplementation.native.ts +26 -0
- package/src/index.ts +95 -0
- package/src/initializers/initializers.native.ts +218 -0
- package/src/initializers/initializers.ts +24 -0
- package/src/memory/bundleUnpacker.native.ts +59 -0
- package/src/memory/customSerializableUnpacker.native.ts +30 -0
- package/src/memory/isShareable.ts +16 -0
- package/src/memory/isSynchronizable.ts +14 -0
- package/src/memory/remoteFunctionUnpacker.native.ts +27 -0
- package/src/memory/serializable.native.ts +889 -0
- package/src/memory/serializable.ts +36 -0
- package/src/memory/serializableMappingCache.native.ts +37 -0
- package/src/memory/serializableMappingCache.ts +12 -0
- package/src/memory/shareable.native.ts +68 -0
- package/src/memory/shareable.ts +27 -0
- package/src/memory/shareableGuestUnpacker.native.ts +168 -0
- package/src/memory/shareableHostUnpacker.native.ts +31 -0
- package/src/memory/synchronizable.native.ts +17 -0
- package/src/memory/synchronizable.ts +9 -0
- package/src/memory/synchronizableUnpacker.native.ts +65 -0
- package/src/memory/types.ts +191 -0
- package/src/memory/valueUnpacker.native.ts +79 -0
- package/src/mock.ts +111 -0
- package/src/platformChecker.native.ts +3 -0
- package/src/platformChecker.ts +4 -0
- package/src/privateGlobals.d.ts +127 -0
- package/src/runLoop/common/setImmediatePolyfill.ts +20 -0
- package/src/runLoop/common/setIntervalPolyfill.ts +38 -0
- package/src/runLoop/uiRuntime/mockedRequestAnimationFrame.ts +11 -0
- package/src/runLoop/uiRuntime/requestAnimationFrame.ts +87 -0
- package/src/runLoop/uiRuntime/setTimeoutPolyfill.ts +40 -0
- package/src/runLoop/workletRuntime/index.ts +18 -0
- package/src/runLoop/workletRuntime/queueMicrotask.ts +13 -0
- package/src/runLoop/workletRuntime/requestAnimationFramePolyfill.ts +61 -0
- package/src/runLoop/workletRuntime/setTimeout.ts +37 -0
- package/src/runLoop/workletRuntime/taskQueue.ts +44 -0
- package/src/runtimeKind.ts +85 -0
- package/src/runtimes.native.ts +572 -0
- package/src/runtimes.ts +107 -0
- package/src/specs/NativeWorkletsModule.ts +11 -0
- package/src/specs/index.ts +13 -0
- package/src/threads.native.ts +408 -0
- package/src/threads.ts +110 -0
- package/src/types.ts +164 -0
- package/src/workletFunction.ts +41 -0
|
@@ -0,0 +1,413 @@
|
|
|
1
|
+
#pragma once
|
|
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 <memory>
|
|
10
|
+
#include <mutex>
|
|
11
|
+
#include <optional>
|
|
12
|
+
#include <string>
|
|
13
|
+
#include <utility>
|
|
14
|
+
#include <vector>
|
|
15
|
+
|
|
16
|
+
using namespace facebook;
|
|
17
|
+
|
|
18
|
+
namespace worklets {
|
|
19
|
+
|
|
20
|
+
// Frees the heap-allocated jsi::Value wrapper without running ~jsi::Value.
|
|
21
|
+
// Use when the runtime that owns the JSI handle is already gone. When the
|
|
22
|
+
// owning runtime is terminated, the orphaned JSI objects would crash the app
|
|
23
|
+
// if their destructors ran, because they call into memory managed by the
|
|
24
|
+
// terminated runtime. The JS object itself lived inside the runtime's heap
|
|
25
|
+
// and was reclaimed with the runtime; only the C++ wrapper allocation
|
|
26
|
+
// remains, and we free it here without invoking ~jsi::Value.
|
|
27
|
+
// See https://github.com/facebook/hermes/blob/75b617a/API/jsi/jsi/jsi.h#L833
|
|
28
|
+
inline void freeWithoutCallingDestructor(std::unique_ptr<jsi::Value> &value) {
|
|
29
|
+
::operator delete(value.release());
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
inline void cleanupRuntimeAware(jsi::Runtime *rt, std::unique_ptr<jsi::Value> &value) {
|
|
33
|
+
if (value == nullptr || rt == nullptr) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
WorkletRuntimeRegistry::runWhileLocked(rt, [&value](bool isAlive) {
|
|
37
|
+
if (isAlive) {
|
|
38
|
+
value.reset();
|
|
39
|
+
} else {
|
|
40
|
+
freeWithoutCallingDestructor(value);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
template <typename BaseClass>
|
|
46
|
+
class RetainingSerializable : virtual public BaseClass {
|
|
47
|
+
private:
|
|
48
|
+
jsi::Runtime *primaryRuntime_;
|
|
49
|
+
jsi::Runtime *secondaryRuntime_;
|
|
50
|
+
std::unique_ptr<jsi::Value> secondaryValue_;
|
|
51
|
+
|
|
52
|
+
public:
|
|
53
|
+
template <typename... Args>
|
|
54
|
+
explicit RetainingSerializable(jsi::Runtime &rt, Args &&...args)
|
|
55
|
+
: BaseClass(rt, std::forward<Args>(args)...), primaryRuntime_(&rt) {}
|
|
56
|
+
|
|
57
|
+
jsi::Value toJSValue(jsi::Runtime &rt) override {
|
|
58
|
+
if (&rt == primaryRuntime_) {
|
|
59
|
+
// TODO: it is suboptimal to generate new object every time getJS is
|
|
60
|
+
// called on host runtime – the objects we are generating already exists
|
|
61
|
+
// and we should possibly just grab a hold of such object and use it here
|
|
62
|
+
// instead of creating a new JS representation. As far as I understand the
|
|
63
|
+
// only case where it can be realistically called this way is when a
|
|
64
|
+
// shared value is created and then accessed on the same runtime
|
|
65
|
+
return BaseClass::toJSValue(rt);
|
|
66
|
+
}
|
|
67
|
+
if (secondaryValue_ == nullptr) {
|
|
68
|
+
auto value = BaseClass::toJSValue(rt);
|
|
69
|
+
secondaryValue_ = std::make_unique<jsi::Value>(rt, value);
|
|
70
|
+
secondaryRuntime_ = &rt;
|
|
71
|
+
return value;
|
|
72
|
+
}
|
|
73
|
+
if (&rt == secondaryRuntime_) {
|
|
74
|
+
return jsi::Value(rt, *secondaryValue_);
|
|
75
|
+
}
|
|
76
|
+
return BaseClass::toJSValue(rt);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
~RetainingSerializable() override {
|
|
80
|
+
cleanupRuntimeAware(secondaryRuntime_, secondaryValue_);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
class SerializableJSRef : public jsi::NativeState {
|
|
85
|
+
private:
|
|
86
|
+
const std::shared_ptr<Serializable> value_;
|
|
87
|
+
|
|
88
|
+
public:
|
|
89
|
+
explicit SerializableJSRef(const std::shared_ptr<Serializable> &value) : value_(value) {}
|
|
90
|
+
|
|
91
|
+
~SerializableJSRef() override;
|
|
92
|
+
|
|
93
|
+
std::shared_ptr<Serializable> value() const {
|
|
94
|
+
return value_;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
static jsi::Object newNativeStateObject(jsi::Runtime &rt, const std::shared_ptr<Serializable> &value) {
|
|
98
|
+
auto object = jsi::Object(rt);
|
|
99
|
+
object.setNativeState(rt, std::make_shared<SerializableJSRef>(value));
|
|
100
|
+
object.setProperty(rt, "__serializableRef", true);
|
|
101
|
+
return object;
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
[[nodiscard]]
|
|
106
|
+
jsi::Value makeSerializableClone(
|
|
107
|
+
jsi::Runtime &rt,
|
|
108
|
+
const jsi::Value &value,
|
|
109
|
+
const jsi::Value &shouldRetainRemote,
|
|
110
|
+
const jsi::Value &nativeStateSource);
|
|
111
|
+
|
|
112
|
+
[[nodiscard]]
|
|
113
|
+
std::shared_ptr<Serializable> extractSerializableOrThrow(
|
|
114
|
+
jsi::Runtime &rt,
|
|
115
|
+
const jsi::Value &maybeSerializableValue,
|
|
116
|
+
const std::string &errorMessage = "[Worklets] Expecting the object to be of type SerializableJSRef.");
|
|
117
|
+
|
|
118
|
+
[[nodiscard]]
|
|
119
|
+
std::shared_ptr<Serializable> extractSerializableOrThrow(
|
|
120
|
+
jsi::Runtime &rt,
|
|
121
|
+
const jsi::Object &maybeSerializableValue,
|
|
122
|
+
const std::string &errorMessage = "[Worklets] Expecting the object to be of type SerializableJSRef.");
|
|
123
|
+
|
|
124
|
+
template <typename TSerializable>
|
|
125
|
+
[[nodiscard]]
|
|
126
|
+
std::shared_ptr<TSerializable> extractSerializableOrThrow(
|
|
127
|
+
jsi::Runtime &rt,
|
|
128
|
+
const jsi::Value &serializableRef,
|
|
129
|
+
const std::string &errorMessage = "[Worklets] Provided serializable object is of an incompatible type.") {
|
|
130
|
+
auto res = std::dynamic_pointer_cast<TSerializable>(extractSerializableOrThrow(rt, serializableRef, errorMessage));
|
|
131
|
+
if (!res) {
|
|
132
|
+
throw std::runtime_error(errorMessage);
|
|
133
|
+
}
|
|
134
|
+
return res;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
template <typename TSerializable>
|
|
138
|
+
[[nodiscard]]
|
|
139
|
+
std::shared_ptr<TSerializable> extractSerializableOrThrow(
|
|
140
|
+
jsi::Runtime &rt,
|
|
141
|
+
const jsi::Object &serializableRef,
|
|
142
|
+
const std::string &errorMessage = "[Worklets] Provided serializable object is of an incompatible type.") {
|
|
143
|
+
auto res = std::dynamic_pointer_cast<TSerializable>(extractSerializableOrThrow(rt, serializableRef, errorMessage));
|
|
144
|
+
if (!res) {
|
|
145
|
+
throw std::runtime_error(errorMessage);
|
|
146
|
+
}
|
|
147
|
+
return res;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
class SerializableArray : public Serializable {
|
|
151
|
+
public:
|
|
152
|
+
SerializableArray(jsi::Runtime &rt, const jsi::Array &array);
|
|
153
|
+
|
|
154
|
+
jsi::Value toJSValue(jsi::Runtime &rt) override;
|
|
155
|
+
|
|
156
|
+
std::vector<jsi::Value> getJSIValueArr(jsi::Runtime &rt) {
|
|
157
|
+
std::vector<jsi::Value> args;
|
|
158
|
+
args.reserve(data_.size());
|
|
159
|
+
for (const auto &item : data_) {
|
|
160
|
+
args.push_back(item->toJSValue(rt));
|
|
161
|
+
}
|
|
162
|
+
return args;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
[[nodiscard]] const std::vector<std::shared_ptr<Serializable>> &getList() const {
|
|
166
|
+
return data_;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
protected:
|
|
170
|
+
std::vector<std::shared_ptr<Serializable>> data_;
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
class SerializableObject : public Serializable {
|
|
174
|
+
public:
|
|
175
|
+
SerializableObject(jsi::Runtime &rt, const jsi::Object &object);
|
|
176
|
+
|
|
177
|
+
SerializableObject(jsi::Runtime &rt, const jsi::Object &object, const jsi::Value &nativeStateSource);
|
|
178
|
+
|
|
179
|
+
jsi::Value toJSValue(jsi::Runtime &rt) override;
|
|
180
|
+
|
|
181
|
+
protected:
|
|
182
|
+
std::vector<std::pair<std::string, std::shared_ptr<Serializable>>> data_;
|
|
183
|
+
std::shared_ptr<jsi::NativeState> nativeState_;
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
class SerializableMap : public Serializable {
|
|
187
|
+
public:
|
|
188
|
+
SerializableMap(jsi::Runtime &rt, const jsi::Array &keys, const jsi::Array &values);
|
|
189
|
+
|
|
190
|
+
jsi::Value toJSValue(jsi::Runtime &rt) override;
|
|
191
|
+
|
|
192
|
+
protected:
|
|
193
|
+
std::vector<std::pair<std::shared_ptr<Serializable>, std::shared_ptr<Serializable>>> data_;
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
class SerializableSet : public Serializable {
|
|
197
|
+
public:
|
|
198
|
+
SerializableSet(jsi::Runtime &rt, const jsi::Array &values);
|
|
199
|
+
|
|
200
|
+
jsi::Value toJSValue(jsi::Runtime &rt) override;
|
|
201
|
+
|
|
202
|
+
protected:
|
|
203
|
+
std::vector<std::shared_ptr<Serializable>> data_;
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
class SerializableError : public Serializable {
|
|
207
|
+
public:
|
|
208
|
+
SerializableError(const std::string &name, const std::string &message, const std::optional<std::string> &stack)
|
|
209
|
+
: Serializable(ValueType::ErrorType), name_(name), message_(message), stack_(stack) {}
|
|
210
|
+
|
|
211
|
+
jsi::Value toJSValue(jsi::Runtime &rt) override;
|
|
212
|
+
|
|
213
|
+
protected:
|
|
214
|
+
const std::string name_;
|
|
215
|
+
const std::string message_;
|
|
216
|
+
const std::optional<std::string> stack_;
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
class SerializableRegExp : public Serializable {
|
|
220
|
+
public:
|
|
221
|
+
SerializableRegExp(const std::string &pattern, const std::string &flags)
|
|
222
|
+
: Serializable(ValueType::RegExpType), pattern_(pattern), flags_(flags) {}
|
|
223
|
+
|
|
224
|
+
jsi::Value toJSValue(jsi::Runtime &rt) override;
|
|
225
|
+
|
|
226
|
+
protected:
|
|
227
|
+
const std::string pattern_;
|
|
228
|
+
const std::string flags_;
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
class SerializableHostObject : public Serializable {
|
|
232
|
+
public:
|
|
233
|
+
SerializableHostObject(jsi::Runtime &, const std::shared_ptr<jsi::HostObject> &hostObject)
|
|
234
|
+
: Serializable(ValueType::HostObjectType), hostObject_(hostObject) {}
|
|
235
|
+
|
|
236
|
+
jsi::Value toJSValue(jsi::Runtime &rt) override;
|
|
237
|
+
|
|
238
|
+
protected:
|
|
239
|
+
const std::shared_ptr<jsi::HostObject> hostObject_;
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
class SerializableHostFunction : public Serializable {
|
|
243
|
+
public:
|
|
244
|
+
SerializableHostFunction(const jsi::HostFunctionType &function, const std::string &name, unsigned int paramCount)
|
|
245
|
+
: Serializable(ValueType::HostFunctionType), hostFunction_(function), name_(name), paramCount_(paramCount) {}
|
|
246
|
+
|
|
247
|
+
jsi::Value toJSValue(jsi::Runtime &rt) override;
|
|
248
|
+
|
|
249
|
+
protected:
|
|
250
|
+
const jsi::HostFunctionType hostFunction_;
|
|
251
|
+
const std::string name_;
|
|
252
|
+
const unsigned int paramCount_;
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
struct ArrayBufferMetadata {
|
|
256
|
+
std::string typeName;
|
|
257
|
+
size_t byteOffset;
|
|
258
|
+
size_t length;
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
class SerializableArrayBuffer : public Serializable {
|
|
262
|
+
public:
|
|
263
|
+
SerializableArrayBuffer(
|
|
264
|
+
jsi::Runtime &rt,
|
|
265
|
+
const jsi::ArrayBuffer &arrayBuffer,
|
|
266
|
+
std::optional<ArrayBufferMetadata> metadata = std::nullopt)
|
|
267
|
+
: Serializable(ValueType::ArrayBufferType),
|
|
268
|
+
metadata_(std::move(metadata)),
|
|
269
|
+
data_(arrayBuffer.data(rt), arrayBuffer.data(rt) + arrayBuffer.size(rt)) {}
|
|
270
|
+
|
|
271
|
+
jsi::Value toJSValue(jsi::Runtime &rt) override;
|
|
272
|
+
|
|
273
|
+
protected:
|
|
274
|
+
std::optional<ArrayBufferMetadata> metadata_;
|
|
275
|
+
std::vector<uint8_t> data_;
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
class SerializableWorklet : public SerializableObject {
|
|
279
|
+
public:
|
|
280
|
+
SerializableWorklet(jsi::Runtime &rt, const jsi::Object &worklet) : SerializableObject(rt, worklet) {
|
|
281
|
+
valueType_ = ValueType::WorkletType;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
jsi::Value toJSValue(jsi::Runtime &rt) override;
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
class SerializableImport : public Serializable {
|
|
288
|
+
public:
|
|
289
|
+
SerializableImport(jsi::Runtime &rt, const double source, const jsi::String &imported)
|
|
290
|
+
: Serializable(ValueType::ImportType), source_(source), imported_(imported.utf8(rt)) {}
|
|
291
|
+
|
|
292
|
+
jsi::Value toJSValue(jsi::Runtime &rt) override;
|
|
293
|
+
|
|
294
|
+
protected:
|
|
295
|
+
const double source_;
|
|
296
|
+
const std::string imported_;
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
class SerializableInitializer : public Serializable {
|
|
300
|
+
private:
|
|
301
|
+
// We don't release the initializer since the handle can get
|
|
302
|
+
// initialized in parallel on multiple threads. However this is not a problem,
|
|
303
|
+
// since the final value is taken from a cache on the runtime which guarantees
|
|
304
|
+
// sequential access.
|
|
305
|
+
std::unique_ptr<SerializableObject> initializer_;
|
|
306
|
+
std::unique_ptr<jsi::Value> remoteValue_;
|
|
307
|
+
mutable std::mutex initializationMutex_;
|
|
308
|
+
jsi::Runtime *remoteRuntime_;
|
|
309
|
+
|
|
310
|
+
public:
|
|
311
|
+
SerializableInitializer(jsi::Runtime &rt, const jsi::Object &initializerObject)
|
|
312
|
+
: Serializable(ValueType::HandleType),
|
|
313
|
+
initializer_(std::make_unique<SerializableObject>(rt, initializerObject)) {}
|
|
314
|
+
|
|
315
|
+
~SerializableInitializer() override {
|
|
316
|
+
cleanupRuntimeAware(remoteRuntime_, remoteValue_);
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
jsi::Value toJSValue(jsi::Runtime &rt) override;
|
|
320
|
+
};
|
|
321
|
+
|
|
322
|
+
class SerializableString : public Serializable {
|
|
323
|
+
public:
|
|
324
|
+
explicit SerializableString(const std::string &string) : Serializable(ValueType::StringType), data_(string) {}
|
|
325
|
+
|
|
326
|
+
jsi::Value toJSValue(jsi::Runtime &rt) override;
|
|
327
|
+
|
|
328
|
+
protected:
|
|
329
|
+
const std::string data_;
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
class SerializableBigInt : public Serializable {
|
|
333
|
+
public:
|
|
334
|
+
explicit SerializableBigInt(jsi::Runtime &rt, const jsi::BigInt &bigInt) : Serializable(ValueType::BigIntType) {
|
|
335
|
+
if (bigInt.isInt64(rt)) {
|
|
336
|
+
fastValue_ = bigInt.getInt64(rt);
|
|
337
|
+
} else {
|
|
338
|
+
slowValue_ = bigInt.toString(rt).utf8(rt);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
jsi::Value toJSValue(jsi::Runtime &rt) override;
|
|
343
|
+
|
|
344
|
+
protected:
|
|
345
|
+
/**
|
|
346
|
+
* This member is used only when the BigInt fits into int64_t range.
|
|
347
|
+
*/
|
|
348
|
+
std::optional<int64_t> fastValue_{};
|
|
349
|
+
std::string slowValue_{};
|
|
350
|
+
};
|
|
351
|
+
|
|
352
|
+
class SerializableScalar : public Serializable {
|
|
353
|
+
public:
|
|
354
|
+
explicit SerializableScalar(double number) : Serializable(ValueType::NumberType) {
|
|
355
|
+
data_.number = number;
|
|
356
|
+
}
|
|
357
|
+
explicit SerializableScalar(bool boolean) : Serializable(ValueType::BooleanType) {
|
|
358
|
+
data_.boolean = boolean;
|
|
359
|
+
}
|
|
360
|
+
SerializableScalar() : Serializable(ValueType::UndefinedType) {}
|
|
361
|
+
explicit SerializableScalar(std::nullptr_t) : Serializable(ValueType::NullType) {}
|
|
362
|
+
|
|
363
|
+
jsi::Value toJSValue(jsi::Runtime &) override;
|
|
364
|
+
|
|
365
|
+
protected:
|
|
366
|
+
union Data {
|
|
367
|
+
bool boolean;
|
|
368
|
+
double number;
|
|
369
|
+
};
|
|
370
|
+
|
|
371
|
+
private:
|
|
372
|
+
Data data_;
|
|
373
|
+
};
|
|
374
|
+
|
|
375
|
+
class SerializableTurboModuleLike : public Serializable {
|
|
376
|
+
public:
|
|
377
|
+
SerializableTurboModuleLike(
|
|
378
|
+
jsi::Runtime &rt,
|
|
379
|
+
const jsi::Object &object,
|
|
380
|
+
const std::shared_ptr<jsi::HostObject> &proto)
|
|
381
|
+
: Serializable(ValueType::TurboModuleLikeType),
|
|
382
|
+
proto_(std::make_unique<SerializableHostObject>(rt, proto)),
|
|
383
|
+
properties_(std::make_unique<SerializableObject>(rt, object)) {}
|
|
384
|
+
|
|
385
|
+
jsi::Value toJSValue(jsi::Runtime &rt) override;
|
|
386
|
+
|
|
387
|
+
private:
|
|
388
|
+
const std::unique_ptr<SerializableHostObject> proto_;
|
|
389
|
+
const std::unique_ptr<SerializableObject> properties_;
|
|
390
|
+
};
|
|
391
|
+
|
|
392
|
+
jsi::Function getCustomSerializableUnpacker(jsi::Runtime &rt);
|
|
393
|
+
|
|
394
|
+
class CustomSerializable : public Serializable {
|
|
395
|
+
public:
|
|
396
|
+
CustomSerializable(std::shared_ptr<Serializable> data, const int typeId)
|
|
397
|
+
: Serializable(ValueType::CustomType), data_(std::move(data)), typeId_(typeId) {}
|
|
398
|
+
|
|
399
|
+
jsi::Value toJSValue(jsi::Runtime &rt) override;
|
|
400
|
+
|
|
401
|
+
private:
|
|
402
|
+
const std::shared_ptr<Serializable> data_;
|
|
403
|
+
const int typeId_;
|
|
404
|
+
};
|
|
405
|
+
|
|
406
|
+
struct SerializationData {
|
|
407
|
+
std::shared_ptr<SerializableWorklet> determine;
|
|
408
|
+
std::shared_ptr<SerializableWorklet> pack;
|
|
409
|
+
std::shared_ptr<SerializableWorklet> unpack;
|
|
410
|
+
int typeId;
|
|
411
|
+
};
|
|
412
|
+
|
|
413
|
+
} // namespace worklets
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
#include <jsi/jsi.h>
|
|
2
|
+
#include <worklets/SharedItems/SerializableFactory.h>
|
|
3
|
+
#include <worklets/SharedItems/SerializableRemoteFunction.h>
|
|
4
|
+
|
|
5
|
+
#include <memory>
|
|
6
|
+
#include <utility>
|
|
7
|
+
|
|
8
|
+
namespace worklets {
|
|
9
|
+
|
|
10
|
+
jsi::Value makeSerializableString(jsi::Runtime &rt, const jsi::String &string) {
|
|
11
|
+
const auto serializable = std::make_shared<SerializableString>(string.utf8(rt));
|
|
12
|
+
return SerializableJSRef::newNativeStateObject(rt, serializable);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
jsi::Value makeSerializableNumber(jsi::Runtime &rt, double number) {
|
|
16
|
+
const auto serializable = std::make_shared<SerializableScalar>(number);
|
|
17
|
+
return SerializableJSRef::newNativeStateObject(rt, serializable);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
jsi::Value makeSerializableBoolean(jsi::Runtime &rt, bool boolean) {
|
|
21
|
+
const auto serializable = std::make_shared<SerializableScalar>(boolean);
|
|
22
|
+
return SerializableJSRef::newNativeStateObject(rt, serializable);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
jsi::Value makeSerializableBigInt(jsi::Runtime &rt, const jsi::BigInt &bigint) {
|
|
26
|
+
const auto serializable = std::make_shared<SerializableBigInt>(rt, bigint);
|
|
27
|
+
return SerializableJSRef::newNativeStateObject(rt, serializable);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
jsi::Value makeSerializableUndefined(jsi::Runtime &rt) {
|
|
31
|
+
const auto serializable = std::make_shared<SerializableScalar>();
|
|
32
|
+
return SerializableJSRef::newNativeStateObject(rt, serializable);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
jsi::Value makeSerializableNull(jsi::Runtime &rt) {
|
|
36
|
+
const auto serializable = std::make_shared<SerializableScalar>(nullptr);
|
|
37
|
+
return SerializableJSRef::newNativeStateObject(rt, serializable);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
jsi::Value makeSerializableWorklet(jsi::Runtime &rt, const jsi::Object &object, const bool &shouldRetainRemote) {
|
|
41
|
+
std::shared_ptr<Serializable> serializable;
|
|
42
|
+
if (shouldRetainRemote) {
|
|
43
|
+
serializable = std::make_shared<RetainingSerializable<SerializableWorklet>>(rt, object);
|
|
44
|
+
} else {
|
|
45
|
+
serializable = std::make_shared<SerializableWorklet>(rt, object);
|
|
46
|
+
}
|
|
47
|
+
return SerializableJSRef::newNativeStateObject(rt, serializable);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
jsi::Value makeSerializableInitializer(jsi::Runtime &rt, const jsi::Object &initializerObject) {
|
|
51
|
+
const auto serializable = std::make_shared<SerializableInitializer>(rt, initializerObject);
|
|
52
|
+
return SerializableJSRef::newNativeStateObject(rt, serializable);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
jsi::Value makeSerializableHostFunction(
|
|
56
|
+
jsi::Runtime &rt,
|
|
57
|
+
const jsi::HostFunctionType &function,
|
|
58
|
+
const std::string &name,
|
|
59
|
+
unsigned int paramCount) {
|
|
60
|
+
auto serializable = std::make_shared<SerializableHostFunction>(function, name, paramCount);
|
|
61
|
+
return SerializableJSRef::newNativeStateObject(rt, serializable);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
jsi::Value makeRNRuntimeSerializableRemoteFunction(
|
|
65
|
+
jsi::Runtime &rnRuntime,
|
|
66
|
+
const std::string &name,
|
|
67
|
+
const jsi::Function &function,
|
|
68
|
+
const std::shared_ptr<JSScheduler> &jsScheduler,
|
|
69
|
+
const std::shared_ptr<RNRuntimeStatus> &rnRuntimeStatus) {
|
|
70
|
+
auto serializable = std::make_shared<SerializableRemoteFunction>(
|
|
71
|
+
rnRuntime,
|
|
72
|
+
name,
|
|
73
|
+
jsi::Value(rnRuntime, function).getObject(rnRuntime).getFunction(rnRuntime),
|
|
74
|
+
jsScheduler,
|
|
75
|
+
rnRuntimeStatus);
|
|
76
|
+
return SerializableJSRef::newNativeStateObject(rnRuntime, serializable);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
jsi::Value makeWorkletRuntimeSerializableRemoteFunction(
|
|
80
|
+
jsi::Runtime &workletRuntime,
|
|
81
|
+
const std::string &name,
|
|
82
|
+
const jsi::Function &function,
|
|
83
|
+
RuntimeData::RuntimeId hostRuntimeId) {
|
|
84
|
+
auto serializable = std::make_shared<SerializableRemoteFunction>(
|
|
85
|
+
workletRuntime,
|
|
86
|
+
name,
|
|
87
|
+
jsi::Value(workletRuntime, function).getObject(workletRuntime).getFunction(workletRuntime),
|
|
88
|
+
hostRuntimeId);
|
|
89
|
+
return SerializableJSRef::newNativeStateObject(workletRuntime, serializable);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
jsi::Value makeSerializableArray(jsi::Runtime &rt, const jsi::Array &array, const jsi::Value &shouldRetainRemote) {
|
|
93
|
+
std::shared_ptr<Serializable> serializable;
|
|
94
|
+
if (shouldRetainRemote.isBool() && shouldRetainRemote.getBool()) {
|
|
95
|
+
serializable = std::make_shared<RetainingSerializable<SerializableArray>>(rt, array);
|
|
96
|
+
} else {
|
|
97
|
+
serializable = std::make_shared<SerializableArray>(rt, array);
|
|
98
|
+
}
|
|
99
|
+
return SerializableJSRef::newNativeStateObject(rt, serializable);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
jsi::Value makeSerializableArrayBuffer(
|
|
103
|
+
jsi::Runtime &rt,
|
|
104
|
+
const jsi::ArrayBuffer &arrayBuffer,
|
|
105
|
+
std::optional<ArrayBufferMetadata> metadata) {
|
|
106
|
+
auto serializable = std::make_shared<SerializableArrayBuffer>(rt, arrayBuffer, std::move(metadata));
|
|
107
|
+
return SerializableJSRef::newNativeStateObject(rt, serializable);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
jsi::Value makeSerializableMap(jsi::Runtime &rt, const jsi::Array &keys, const jsi::Array &values) {
|
|
111
|
+
auto serializable = std::make_shared<SerializableMap>(rt, keys, values);
|
|
112
|
+
return SerializableJSRef::newNativeStateObject(rt, serializable);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
jsi::Value makeSerializableSet(jsi::Runtime &rt, const jsi::Array &values) {
|
|
116
|
+
auto serializable = std::make_shared<SerializableSet>(rt, values);
|
|
117
|
+
return SerializableJSRef::newNativeStateObject(rt, serializable);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
jsi::Value makeSerializableError(
|
|
121
|
+
jsi::Runtime &rt,
|
|
122
|
+
const std::string &name,
|
|
123
|
+
const std::string &message,
|
|
124
|
+
const std::optional<std::string> &stack) {
|
|
125
|
+
auto serializable = std::make_shared<SerializableError>(name, message, stack);
|
|
126
|
+
return SerializableJSRef::newNativeStateObject(rt, serializable);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
jsi::Value makeSerializableRegExp(jsi::Runtime &rt, const std::string &pattern, const std::string &flags) {
|
|
130
|
+
auto serializable = std::make_shared<SerializableRegExp>(pattern, flags);
|
|
131
|
+
return SerializableJSRef::newNativeStateObject(rt, serializable);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
jsi::Value makeSerializableHostObject(jsi::Runtime &rt, const std::shared_ptr<jsi::HostObject> &value) {
|
|
135
|
+
const auto serializable = std::make_shared<SerializableHostObject>(rt, value);
|
|
136
|
+
return SerializableJSRef::newNativeStateObject(rt, serializable);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
jsi::Value makeSerializableTurboModuleLike(
|
|
140
|
+
jsi::Runtime &rt,
|
|
141
|
+
const jsi::Object &object,
|
|
142
|
+
const std::shared_ptr<jsi::HostObject> &proto) {
|
|
143
|
+
const auto serializable = std::make_shared<SerializableTurboModuleLike>(rt, object, proto);
|
|
144
|
+
return SerializableJSRef::newNativeStateObject(rt, serializable);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
jsi::Value makeSerializableImport(jsi::Runtime &rt, const double source, const jsi::String &imported) {
|
|
148
|
+
auto serializable = std::make_shared<SerializableImport>(rt, source, imported);
|
|
149
|
+
return SerializableJSRef::newNativeStateObject(rt, serializable);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
jsi::Value makeSerializableObject(
|
|
153
|
+
jsi::Runtime &rt,
|
|
154
|
+
jsi::Object object,
|
|
155
|
+
bool shouldRetainRemote,
|
|
156
|
+
const jsi::Value &nativeStateSource) {
|
|
157
|
+
std::shared_ptr<Serializable> serializable;
|
|
158
|
+
if (shouldRetainRemote) {
|
|
159
|
+
serializable = std::make_shared<RetainingSerializable<SerializableObject>>(rt, object, nativeStateSource);
|
|
160
|
+
} else {
|
|
161
|
+
serializable = std::make_shared<SerializableObject>(rt, object, nativeStateSource);
|
|
162
|
+
}
|
|
163
|
+
return SerializableJSRef::newNativeStateObject(rt, serializable);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
jsi::Value makeCustomSerializable(jsi::Runtime &rt, const jsi::Value &data, const int typeId) {
|
|
167
|
+
auto rawData = extractSerializableOrThrow(rt, data, "[Worklets] Data must be a Serializable object.");
|
|
168
|
+
auto customSerializable = std::make_shared<CustomSerializable>(rawData, typeId);
|
|
169
|
+
return SerializableJSRef::newNativeStateObject(rt, customSerializable);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
} // namespace worklets
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <jsi/jsi.h>
|
|
4
|
+
#include <worklets/SharedItems/Serializable.h>
|
|
5
|
+
|
|
6
|
+
#include <memory>
|
|
7
|
+
#include <optional>
|
|
8
|
+
#include <string>
|
|
9
|
+
|
|
10
|
+
namespace worklets {
|
|
11
|
+
|
|
12
|
+
class RNRuntimeStatus;
|
|
13
|
+
|
|
14
|
+
jsi::Value makeSerializableString(jsi::Runtime &rt, const jsi::String &string);
|
|
15
|
+
|
|
16
|
+
jsi::Value makeSerializableNumber(jsi::Runtime &rt, double number);
|
|
17
|
+
|
|
18
|
+
jsi::Value makeSerializableBoolean(jsi::Runtime &rt, bool boolean);
|
|
19
|
+
|
|
20
|
+
jsi::Value makeSerializableBigInt(jsi::Runtime &rt, const jsi::BigInt &bigint);
|
|
21
|
+
|
|
22
|
+
jsi::Value makeSerializableUndefined(jsi::Runtime &rt);
|
|
23
|
+
|
|
24
|
+
jsi::Value makeSerializableNull(jsi::Runtime &rt);
|
|
25
|
+
|
|
26
|
+
jsi::Value makeSerializableTurboModuleLike(
|
|
27
|
+
jsi::Runtime &rt,
|
|
28
|
+
const jsi::Object &object,
|
|
29
|
+
const std::shared_ptr<jsi::HostObject> &proto);
|
|
30
|
+
|
|
31
|
+
jsi::Value makeSerializableObject(
|
|
32
|
+
jsi::Runtime &rt,
|
|
33
|
+
jsi::Object object,
|
|
34
|
+
bool shouldRetainRemote,
|
|
35
|
+
const jsi::Value &nativeStateSource);
|
|
36
|
+
|
|
37
|
+
jsi::Value makeSerializableImport(jsi::Runtime &rt, double source, const jsi::String &imported);
|
|
38
|
+
|
|
39
|
+
jsi::Value makeSerializableHostObject(jsi::Runtime &rt, const std::shared_ptr<jsi::HostObject> &value);
|
|
40
|
+
|
|
41
|
+
jsi::Value makeSerializableArray(jsi::Runtime &rt, const jsi::Array &array, const jsi::Value &shouldRetainRemote);
|
|
42
|
+
|
|
43
|
+
jsi::Value makeSerializableArrayBuffer(
|
|
44
|
+
jsi::Runtime &rt,
|
|
45
|
+
const jsi::ArrayBuffer &arrayBuffer,
|
|
46
|
+
std::optional<ArrayBufferMetadata> metadata = std::nullopt);
|
|
47
|
+
|
|
48
|
+
jsi::Value makeSerializableMap(jsi::Runtime &rt, const jsi::Array &keys, const jsi::Array &values);
|
|
49
|
+
|
|
50
|
+
jsi::Value makeSerializableSet(jsi::Runtime &rt, const jsi::Array &values);
|
|
51
|
+
|
|
52
|
+
jsi::Value makeSerializableError(
|
|
53
|
+
jsi::Runtime &rt,
|
|
54
|
+
const std::string &name,
|
|
55
|
+
const std::string &message,
|
|
56
|
+
const std::optional<std::string> &stack);
|
|
57
|
+
|
|
58
|
+
jsi::Value makeSerializableRegExp(jsi::Runtime &rt, const std::string &pattern, const std::string &flags);
|
|
59
|
+
|
|
60
|
+
jsi::Value makeSerializableInitializer(jsi::Runtime &rt, const jsi::Object &initializerObject);
|
|
61
|
+
|
|
62
|
+
jsi::Value makeSerializableHostFunction(
|
|
63
|
+
jsi::Runtime &rt,
|
|
64
|
+
const jsi::HostFunctionType &function,
|
|
65
|
+
const std::string &name,
|
|
66
|
+
unsigned int paramCount);
|
|
67
|
+
|
|
68
|
+
jsi::Value makeRNRuntimeSerializableRemoteFunction(
|
|
69
|
+
jsi::Runtime &rnRuntime,
|
|
70
|
+
const std::string &name,
|
|
71
|
+
const jsi::Function &function,
|
|
72
|
+
const std::shared_ptr<JSScheduler> &jsScheduler,
|
|
73
|
+
const std::shared_ptr<RNRuntimeStatus> &rnRuntimeStatus);
|
|
74
|
+
|
|
75
|
+
jsi::Value makeWorkletRuntimeSerializableRemoteFunction(
|
|
76
|
+
jsi::Runtime &workletRuntime,
|
|
77
|
+
const std::string &name,
|
|
78
|
+
const jsi::Function &function,
|
|
79
|
+
RuntimeData::RuntimeId hostRuntimeId);
|
|
80
|
+
|
|
81
|
+
jsi::Value makeSerializableWorklet(jsi::Runtime &rt, const jsi::Object &object, const bool &shouldRetainRemote);
|
|
82
|
+
|
|
83
|
+
jsi::Value makeCustomSerializable(jsi::Runtime &rt, const jsi::Value &data, int typeId);
|
|
84
|
+
|
|
85
|
+
} // namespace worklets
|