@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,103 @@
|
|
|
1
|
+
#include <worklets/RunLoop/EventLoop.h>
|
|
2
|
+
|
|
3
|
+
#include <memory>
|
|
4
|
+
#include <string>
|
|
5
|
+
#include <thread>
|
|
6
|
+
#include <utility>
|
|
7
|
+
#include <vector>
|
|
8
|
+
|
|
9
|
+
namespace worklets {
|
|
10
|
+
|
|
11
|
+
EventLoop::EventLoop(
|
|
12
|
+
const std::string &name,
|
|
13
|
+
const std::shared_ptr<jsi::Runtime> &runtime,
|
|
14
|
+
const std::shared_ptr<AsyncQueue> &queue)
|
|
15
|
+
: runtime_(runtime), queue_(queue), timeoutsQueueState_(std::make_shared<TimeoutsQueueState>()), name_(name) {}
|
|
16
|
+
|
|
17
|
+
EventLoop::~EventLoop() {
|
|
18
|
+
{
|
|
19
|
+
std::unique_lock<std::mutex> lock(timeoutsQueueState_->mutex);
|
|
20
|
+
timeoutsQueueState_->running = false;
|
|
21
|
+
timeoutsQueueState_->queue = {};
|
|
22
|
+
}
|
|
23
|
+
timeoutsQueueState_->cv.notify_all();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
void EventLoop::run() {
|
|
27
|
+
const auto threadName = name_ + "(timeout)";
|
|
28
|
+
auto thread = std::thread([threadName, state = timeoutsQueueState_, weakThis = weak_from_this()] {
|
|
29
|
+
#if __APPLE__
|
|
30
|
+
pthread_setname_np(threadName.c_str());
|
|
31
|
+
#endif
|
|
32
|
+
while (state->running) {
|
|
33
|
+
std::unique_lock<std::mutex> lock(state->mutex);
|
|
34
|
+
|
|
35
|
+
if (state->queue.empty()) {
|
|
36
|
+
state->cv.wait(lock);
|
|
37
|
+
} else {
|
|
38
|
+
const auto &nextTimeout = state->queue[0];
|
|
39
|
+
const auto timeToWait = nextTimeout.targetTime - getCurrentTimeInMs();
|
|
40
|
+
state->cv.wait_for(lock, std::chrono::milliseconds(timeToWait));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Early return if the Event Loop got destroyed already.
|
|
44
|
+
if (!state->running) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const auto currentTime = getCurrentTimeInMs();
|
|
49
|
+
std::vector<std::function<void(jsi::Runtime & rt)>> jobs;
|
|
50
|
+
auto &timeouts = state->queue;
|
|
51
|
+
timeouts.erase(
|
|
52
|
+
std::remove_if(
|
|
53
|
+
timeouts.begin(),
|
|
54
|
+
timeouts.end(),
|
|
55
|
+
[currentTime, &jobs](const Timeout &timeout) {
|
|
56
|
+
if (currentTime >= timeout.targetTime) {
|
|
57
|
+
jobs.emplace_back(timeout.callback);
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
return false;
|
|
61
|
+
}),
|
|
62
|
+
timeouts.end());
|
|
63
|
+
lock.unlock();
|
|
64
|
+
|
|
65
|
+
if (auto strongThis = weakThis.lock()) {
|
|
66
|
+
for (auto &job : jobs) {
|
|
67
|
+
strongThis->pushTask(std::move(job));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
#ifdef ANDROID
|
|
73
|
+
pthread_setname_np(thread.native_handle(), threadName.c_str());
|
|
74
|
+
#endif
|
|
75
|
+
thread.detach();
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
void EventLoop::pushTask(std::function<void(jsi::Runtime &rt)> &&job) {
|
|
79
|
+
queue_->push([weakRuntime = std::weak_ptr<jsi::Runtime>{runtime_}, job = std::move(job)] {
|
|
80
|
+
if (auto runtime = weakRuntime.lock()) {
|
|
81
|
+
job(*runtime);
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
void EventLoop::pushTimeout(std::function<void(jsi::Runtime &rt)> &&job, int64_t delay) {
|
|
87
|
+
{
|
|
88
|
+
std::unique_lock<std::mutex> lock(timeoutsQueueState_->mutex);
|
|
89
|
+
const auto targetTime = getCurrentTimeInMs() + delay;
|
|
90
|
+
const auto timeout = Timeout{std::move(job), targetTime};
|
|
91
|
+
auto &queue = timeoutsQueueState_->queue;
|
|
92
|
+
auto it = std::upper_bound(queue.begin(), queue.end(), timeout);
|
|
93
|
+
queue.insert(it, timeout);
|
|
94
|
+
}
|
|
95
|
+
timeoutsQueueState_->cv.notify_one();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
int64_t EventLoop::getCurrentTimeInMs() {
|
|
99
|
+
const auto currentTime = std::chrono::system_clock::now().time_since_epoch();
|
|
100
|
+
return std::chrono::duration_cast<std::chrono::milliseconds>(currentTime).count();
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
} // namespace worklets
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <jsi/jsi.h>
|
|
4
|
+
#include <worklets/RunLoop/AsyncQueue.h>
|
|
5
|
+
|
|
6
|
+
#include <atomic>
|
|
7
|
+
#include <condition_variable>
|
|
8
|
+
#include <memory>
|
|
9
|
+
#include <queue>
|
|
10
|
+
#include <string>
|
|
11
|
+
#include <vector>
|
|
12
|
+
|
|
13
|
+
using namespace facebook;
|
|
14
|
+
|
|
15
|
+
namespace worklets {
|
|
16
|
+
|
|
17
|
+
struct Timeout {
|
|
18
|
+
std::function<void(jsi::Runtime &rt)> callback;
|
|
19
|
+
int64_t targetTime;
|
|
20
|
+
bool operator<(const Timeout &v) const {
|
|
21
|
+
return targetTime < v.targetTime;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
struct TimeoutsQueueState {
|
|
26
|
+
std::atomic_bool running{true};
|
|
27
|
+
std::mutex mutex;
|
|
28
|
+
std::condition_variable cv;
|
|
29
|
+
std::vector<Timeout> queue;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
class EventLoop : public std::enable_shared_from_this<EventLoop> {
|
|
33
|
+
public:
|
|
34
|
+
EventLoop(
|
|
35
|
+
const std::string &name,
|
|
36
|
+
const std::shared_ptr<jsi::Runtime> &runtime,
|
|
37
|
+
const std::shared_ptr<AsyncQueue> &queue);
|
|
38
|
+
~EventLoop();
|
|
39
|
+
void run();
|
|
40
|
+
void pushTask(std::function<void(jsi::Runtime &rt)> &&job);
|
|
41
|
+
void pushTimeout(std::function<void(jsi::Runtime &rt)> &&job, int64_t delay);
|
|
42
|
+
|
|
43
|
+
private:
|
|
44
|
+
const std::shared_ptr<jsi::Runtime> runtime_;
|
|
45
|
+
const std::shared_ptr<AsyncQueue> queue_;
|
|
46
|
+
const std::shared_ptr<TimeoutsQueueState> timeoutsQueueState_;
|
|
47
|
+
const std::string name_;
|
|
48
|
+
|
|
49
|
+
static int64_t getCurrentTimeInMs();
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
} // namespace worklets
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
#include <jsi/jsi.h>
|
|
2
|
+
#include <react/debug/react_native_assert.h>
|
|
3
|
+
#include <worklets/SharedItems/MemoryManager.h>
|
|
4
|
+
#include <worklets/SharedItems/Serializable.h>
|
|
5
|
+
#include <worklets/WorkletRuntime/WorkletRuntime.h>
|
|
6
|
+
|
|
7
|
+
namespace worklets {
|
|
8
|
+
void MemoryManager::loadAllCustomSerializables(const std::shared_ptr<WorkletRuntime> &runtime) {
|
|
9
|
+
std::lock_guard lock(customSerializationDataMutex_);
|
|
10
|
+
runtime->executeSync([&](jsi::Runtime &rt) -> jsi::Value {
|
|
11
|
+
const auto registry = getCustomSerializationRegistry(rt);
|
|
12
|
+
for (const auto &data : customSerializationData_) {
|
|
13
|
+
loadCustomSerializable(rt, registry, data);
|
|
14
|
+
}
|
|
15
|
+
return jsi::Value::undefined();
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
void MemoryManager::loadCustomSerializable(
|
|
20
|
+
const std::shared_ptr<WorkletRuntime> &runtime,
|
|
21
|
+
const SerializationData &data) {
|
|
22
|
+
std::lock_guard lock(customSerializationDataMutex_);
|
|
23
|
+
runtime->executeSync([this, data](jsi::Runtime &rt) -> jsi::Value {
|
|
24
|
+
const auto registry = getCustomSerializationRegistry(rt);
|
|
25
|
+
loadCustomSerializable(rt, registry, data);
|
|
26
|
+
return jsi::Value::undefined();
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
void MemoryManager::loadCustomSerializable(
|
|
31
|
+
jsi::Runtime &runtime,
|
|
32
|
+
const jsi::Array ®istry,
|
|
33
|
+
const SerializationData &data) {
|
|
34
|
+
react_native_assert(
|
|
35
|
+
registry.length(runtime) == data.typeId &&
|
|
36
|
+
("Custom serializable type ID must match registry length. Expected typeId: " + std::to_string(data.typeId) +
|
|
37
|
+
", got registry length: " + std::to_string(registry.length(runtime)) +
|
|
38
|
+
". Custom serializables must be registered in the same order across all runtimes.")
|
|
39
|
+
.c_str());
|
|
40
|
+
|
|
41
|
+
const auto item = jsi::Object(runtime);
|
|
42
|
+
item.setProperty(runtime, "determine", data.determine->toJSValue(runtime));
|
|
43
|
+
item.setProperty(runtime, "pack", data.pack->toJSValue(runtime));
|
|
44
|
+
item.setProperty(runtime, "unpack", data.unpack->toJSValue(runtime));
|
|
45
|
+
item.setProperty(runtime, "typeId", data.typeId);
|
|
46
|
+
|
|
47
|
+
registry.getPropertyAsFunction(runtime, "push").callWithThis(runtime, registry, item);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
void MemoryManager::registerCustomSerializable(const SerializationData &data) {
|
|
51
|
+
std::lock_guard lock(customSerializationDataMutex_);
|
|
52
|
+
customSerializationData_.emplace_back(data);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
jsi::Array MemoryManager::getCustomSerializationRegistry(jsi::Runtime &rt) {
|
|
56
|
+
const auto data = rt.global().getProperty(rt, "__customSerializationRegistry");
|
|
57
|
+
return data.asObject(rt).asArray(rt);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
} // namespace worklets
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <jsi/jsi.h>
|
|
4
|
+
#include <react/debug/react_native_assert.h>
|
|
5
|
+
#include <worklets/SharedItems/Serializable.h>
|
|
6
|
+
#include <worklets/WorkletRuntime/WorkletRuntime.h>
|
|
7
|
+
|
|
8
|
+
#include <memory>
|
|
9
|
+
#include <mutex>
|
|
10
|
+
#include <vector>
|
|
11
|
+
|
|
12
|
+
namespace worklets {
|
|
13
|
+
class MemoryManager {
|
|
14
|
+
public:
|
|
15
|
+
void loadAllCustomSerializables(const std::shared_ptr<WorkletRuntime> &workletRuntime);
|
|
16
|
+
|
|
17
|
+
void loadCustomSerializable(const std::shared_ptr<WorkletRuntime> &workletRuntime, const SerializationData &data);
|
|
18
|
+
|
|
19
|
+
void registerCustomSerializable(const SerializationData &data);
|
|
20
|
+
|
|
21
|
+
private:
|
|
22
|
+
static jsi::Array getCustomSerializationRegistry(jsi::Runtime &rt);
|
|
23
|
+
|
|
24
|
+
void loadCustomSerializable(jsi::Runtime &runtime, const jsi::Array ®istry, const SerializationData &data);
|
|
25
|
+
|
|
26
|
+
std::mutex customSerializationDataMutex_;
|
|
27
|
+
std::vector<SerializationData> customSerializationData_;
|
|
28
|
+
};
|
|
29
|
+
} // namespace worklets
|
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
#include <jsi/jsi.h>
|
|
2
|
+
#include <react/debug/react_native_assert.h>
|
|
3
|
+
#include <worklets/SharedItems/Serializable.h>
|
|
4
|
+
#include <worklets/SharedItems/SerializableFactory.h>
|
|
5
|
+
#include <worklets/WorkletRuntime/RuntimeData.h>
|
|
6
|
+
#include <worklets/WorkletRuntime/RuntimeManager.h>
|
|
7
|
+
#include <worklets/WorkletRuntime/WorkletRuntime.h>
|
|
8
|
+
|
|
9
|
+
#include <memory>
|
|
10
|
+
#include <stdexcept>
|
|
11
|
+
#include <string>
|
|
12
|
+
#include <utility>
|
|
13
|
+
|
|
14
|
+
using namespace facebook;
|
|
15
|
+
|
|
16
|
+
namespace worklets {
|
|
17
|
+
|
|
18
|
+
namespace {
|
|
19
|
+
|
|
20
|
+
jsi::Function getValueUnpacker(jsi::Runtime &rt) {
|
|
21
|
+
auto valueUnpacker = rt.global().getProperty(rt, "__valueUnpacker");
|
|
22
|
+
react_native_assert(valueUnpacker.isObject() && "valueUnpacker not found");
|
|
23
|
+
return valueUnpacker.asObject(rt).asFunction(rt);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
} // namespace
|
|
27
|
+
|
|
28
|
+
jsi::Value makeSerializableClone(
|
|
29
|
+
jsi::Runtime &rt,
|
|
30
|
+
const jsi::Value &value,
|
|
31
|
+
const jsi::Value &shouldRetainRemote,
|
|
32
|
+
const jsi::Value &nativeStateSource) {
|
|
33
|
+
std::shared_ptr<Serializable> serializable;
|
|
34
|
+
if (value.isObject()) {
|
|
35
|
+
auto object = value.asObject(rt);
|
|
36
|
+
if (!object.getProperty(rt, "__workletHash").isUndefined()) {
|
|
37
|
+
// We pass `false` because this function is invoked only
|
|
38
|
+
// by `makeSerializableCloneOnUIRecursive` which doesn't
|
|
39
|
+
// make Retaining Serializables.
|
|
40
|
+
return makeSerializableWorklet(rt, object, false);
|
|
41
|
+
} else if (!object.getProperty(rt, "__init").isUndefined()) {
|
|
42
|
+
return makeSerializableInitializer(rt, object);
|
|
43
|
+
} else if (object.isFunction(rt)) {
|
|
44
|
+
auto fun = object.asFunction(rt);
|
|
45
|
+
if (fun.isHostFunction(rt)) {
|
|
46
|
+
auto name = fun.getProperty(rt, "name").asString(rt).utf8(rt);
|
|
47
|
+
return makeSerializableHostFunction(
|
|
48
|
+
rt, fun.getHostFunction(rt), name, fun.getProperty(rt, "length").asNumber());
|
|
49
|
+
} else {
|
|
50
|
+
throw std::runtime_error(
|
|
51
|
+
"[Worklets] Cloning remote functions from Worklet Runtimes is only available in Bundle Mode.");
|
|
52
|
+
}
|
|
53
|
+
} else if (object.isArray(rt)) {
|
|
54
|
+
if (shouldRetainRemote.isBool() && shouldRetainRemote.getBool()) {
|
|
55
|
+
serializable = std::make_shared<RetainingSerializable<SerializableArray>>(rt, object.asArray(rt));
|
|
56
|
+
} else {
|
|
57
|
+
serializable = std::make_shared<SerializableArray>(rt, object.asArray(rt));
|
|
58
|
+
}
|
|
59
|
+
} else if (object.isArrayBuffer(rt)) {
|
|
60
|
+
serializable = std::make_shared<SerializableArrayBuffer>(rt, object.getArrayBuffer(rt));
|
|
61
|
+
} else if (object.isHostObject(rt)) {
|
|
62
|
+
if (object.isHostObject<SerializableJSRef>(rt)) {
|
|
63
|
+
return object;
|
|
64
|
+
}
|
|
65
|
+
serializable = std::make_shared<SerializableHostObject>(rt, object.getHostObject(rt));
|
|
66
|
+
} else {
|
|
67
|
+
if (shouldRetainRemote.isBool() && shouldRetainRemote.getBool()) {
|
|
68
|
+
serializable = std::make_shared<RetainingSerializable<SerializableObject>>(rt, object, nativeStateSource);
|
|
69
|
+
} else {
|
|
70
|
+
serializable = std::make_shared<SerializableObject>(rt, object, nativeStateSource);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
} else if (value.isString()) {
|
|
74
|
+
serializable = std::make_shared<SerializableString>(value.asString(rt).utf8(rt));
|
|
75
|
+
} else if (value.isUndefined()) {
|
|
76
|
+
serializable = std::make_shared<SerializableScalar>();
|
|
77
|
+
} else if (value.isNull()) {
|
|
78
|
+
serializable = std::make_shared<SerializableScalar>(nullptr);
|
|
79
|
+
} else if (value.isBool()) {
|
|
80
|
+
serializable = std::make_shared<SerializableScalar>(value.getBool());
|
|
81
|
+
} else if (value.isNumber()) {
|
|
82
|
+
serializable = std::make_shared<SerializableScalar>(value.getNumber());
|
|
83
|
+
} else if (value.isBigInt()) {
|
|
84
|
+
serializable = std::make_shared<SerializableBigInt>(rt, value.getBigInt(rt));
|
|
85
|
+
} else if (value.isSymbol()) {
|
|
86
|
+
// TODO: this is only a placeholder implementation, here we replace symbols
|
|
87
|
+
// with strings in order to make certain objects to be captured. There isn't
|
|
88
|
+
// yet any use-case for using symbols on the UI runtime so it is fine to keep
|
|
89
|
+
// it like this for now.
|
|
90
|
+
serializable = std::make_shared<SerializableString>(value.getSymbol(rt).toString(rt));
|
|
91
|
+
} else {
|
|
92
|
+
throw std::runtime_error("[Worklets] Attempted to convert an unsupported value type.");
|
|
93
|
+
}
|
|
94
|
+
return SerializableJSRef::newNativeStateObject(rt, serializable);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
std::shared_ptr<Serializable> extractSerializableOrThrow(
|
|
98
|
+
jsi::Runtime &rt,
|
|
99
|
+
const jsi::Value &maybeSerializableValue,
|
|
100
|
+
const std::string &errorMessage) {
|
|
101
|
+
if (maybeSerializableValue.isObject()) {
|
|
102
|
+
auto object = maybeSerializableValue.getObject(rt);
|
|
103
|
+
return extractSerializableOrThrow(rt, object, errorMessage);
|
|
104
|
+
} else if (maybeSerializableValue.isUndefined()) {
|
|
105
|
+
return Serializable::undefined();
|
|
106
|
+
}
|
|
107
|
+
throw std::runtime_error(errorMessage);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
std::shared_ptr<Serializable> extractSerializableOrThrow(
|
|
111
|
+
jsi::Runtime &rt,
|
|
112
|
+
const jsi::Object &maybeSerializableValue,
|
|
113
|
+
const std::string &errorMessage) {
|
|
114
|
+
if (maybeSerializableValue.hasNativeState(rt)) {
|
|
115
|
+
auto nativeState = maybeSerializableValue.getNativeState(rt);
|
|
116
|
+
return std::dynamic_pointer_cast<SerializableJSRef>(nativeState)->value();
|
|
117
|
+
}
|
|
118
|
+
throw std::runtime_error(errorMessage);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
Serializable::~Serializable() = default;
|
|
122
|
+
|
|
123
|
+
std::shared_ptr<Serializable> Serializable::undefined() {
|
|
124
|
+
static auto undefined = std::make_shared<SerializableScalar>();
|
|
125
|
+
return undefined;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
SerializableJSRef::~SerializableJSRef() = default;
|
|
129
|
+
|
|
130
|
+
SerializableArray::SerializableArray(jsi::Runtime &rt, const jsi::Array &array) : Serializable(ValueType::ArrayType) {
|
|
131
|
+
auto size = array.size(rt);
|
|
132
|
+
data_.reserve(size);
|
|
133
|
+
for (size_t i = 0; i < size; i++) {
|
|
134
|
+
data_.push_back(extractSerializableOrThrow(rt, array.getValueAtIndex(rt, i)));
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
jsi::Value SerializableArray::toJSValue(jsi::Runtime &rt) {
|
|
139
|
+
auto size = data_.size();
|
|
140
|
+
auto ary = jsi::Array(rt, size);
|
|
141
|
+
for (size_t i = 0; i < size; i++) {
|
|
142
|
+
ary.setValueAtIndex(rt, i, data_[i]->toJSValue(rt));
|
|
143
|
+
}
|
|
144
|
+
return ary;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
jsi::Value SerializableArrayBuffer::toJSValue(jsi::Runtime &rt) {
|
|
148
|
+
auto size = static_cast<int>(data_.size());
|
|
149
|
+
auto arrayBuffer =
|
|
150
|
+
rt.global().getPropertyAsFunction(rt, "ArrayBuffer").callAsConstructor(rt, size).getObject(rt).getArrayBuffer(rt);
|
|
151
|
+
memcpy(arrayBuffer.data(rt), data_.data(), size);
|
|
152
|
+
if (!metadata_.has_value()) {
|
|
153
|
+
return arrayBuffer;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
auto constructor = rt.global().getPropertyAsFunction(rt, metadata_->typeName.c_str());
|
|
157
|
+
return constructor.callAsConstructor(
|
|
158
|
+
rt, arrayBuffer, static_cast<double>(metadata_->byteOffset), static_cast<double>(metadata_->length));
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
SerializableObject::SerializableObject(jsi::Runtime &rt, const jsi::Object &object)
|
|
162
|
+
: Serializable(ValueType::ObjectType) {
|
|
163
|
+
auto propertyNames = object.getPropertyNames(rt);
|
|
164
|
+
auto size = propertyNames.size(rt);
|
|
165
|
+
data_.reserve(size);
|
|
166
|
+
for (size_t i = 0; i < size; i++) {
|
|
167
|
+
auto key = propertyNames.getValueAtIndex(rt, i).asString(rt);
|
|
168
|
+
auto value = extractSerializableOrThrow(rt, object.getProperty(rt, key));
|
|
169
|
+
data_.emplace_back(key.utf8(rt), value);
|
|
170
|
+
}
|
|
171
|
+
if (object.hasNativeState(rt)) {
|
|
172
|
+
nativeState_ = object.getNativeState(rt);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
SerializableObject::SerializableObject(jsi::Runtime &rt, const jsi::Object &object, const jsi::Value &nativeStateSource)
|
|
177
|
+
: SerializableObject(rt, object) {
|
|
178
|
+
if (nativeStateSource.isObject() && nativeStateSource.asObject(rt).hasNativeState(rt)) {
|
|
179
|
+
nativeState_ = nativeStateSource.asObject(rt).getNativeState(rt);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
jsi::Value SerializableObject::toJSValue(jsi::Runtime &rt) {
|
|
184
|
+
auto obj = jsi::Object(rt);
|
|
185
|
+
for (const auto &i : data_) {
|
|
186
|
+
obj.setProperty(rt, jsi::String::createFromUtf8(rt, i.first), i.second->toJSValue(rt));
|
|
187
|
+
}
|
|
188
|
+
if (nativeState_ != nullptr) {
|
|
189
|
+
obj.setNativeState(rt, nativeState_);
|
|
190
|
+
}
|
|
191
|
+
return obj;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
SerializableMap::SerializableMap(jsi::Runtime &rt, const jsi::Array &keys, const jsi::Array &values)
|
|
195
|
+
: Serializable(ValueType::MapType) {
|
|
196
|
+
auto size = keys.size(rt);
|
|
197
|
+
react_native_assert(size == values.size(rt) && "Keys and values arrays must have the same size.");
|
|
198
|
+
data_.reserve(size);
|
|
199
|
+
for (size_t i = 0; i < size; i++) {
|
|
200
|
+
auto key = extractSerializableOrThrow(rt, keys.getValueAtIndex(rt, i));
|
|
201
|
+
auto value = extractSerializableOrThrow(rt, values.getValueAtIndex(rt, i));
|
|
202
|
+
data_.emplace_back(key, value);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
jsi::Value SerializableMap::toJSValue(jsi::Runtime &rt) {
|
|
207
|
+
const auto keyValues = jsi::Array(rt, data_.size());
|
|
208
|
+
for (size_t i = 0, size = data_.size(); i < size; i++) {
|
|
209
|
+
const auto pair = jsi::Array(rt, 2);
|
|
210
|
+
pair.setValueAtIndex(rt, 0, data_[i].first->toJSValue(rt));
|
|
211
|
+
pair.setValueAtIndex(rt, 1, data_[i].second->toJSValue(rt));
|
|
212
|
+
keyValues.setValueAtIndex(rt, i, std::move(pair));
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const auto &global = rt.global();
|
|
216
|
+
auto map = global.getPropertyAsFunction(rt, "Map").callAsConstructor(rt, std::move(keyValues));
|
|
217
|
+
|
|
218
|
+
return map;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
SerializableSet::SerializableSet(jsi::Runtime &rt, const jsi::Array &values) : Serializable(ValueType::SetType) {
|
|
222
|
+
auto size = values.size(rt);
|
|
223
|
+
data_.reserve(size);
|
|
224
|
+
for (size_t i = 0; i < size; i++) {
|
|
225
|
+
data_.push_back(extractSerializableOrThrow(rt, values.getValueAtIndex(rt, i)));
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
jsi::Value SerializableSet::toJSValue(jsi::Runtime &rt) {
|
|
230
|
+
const auto values = jsi::Array(rt, data_.size());
|
|
231
|
+
for (size_t i = 0, size = data_.size(); i < size; i++) {
|
|
232
|
+
values.setValueAtIndex(rt, i, data_[i]->toJSValue(rt));
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
const auto &global = rt.global();
|
|
236
|
+
auto set = global.getPropertyAsFunction(rt, "Set").callAsConstructor(rt, std::move(values));
|
|
237
|
+
|
|
238
|
+
return set;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
jsi::Value SerializableRegExp::toJSValue(jsi::Runtime &rt) {
|
|
242
|
+
return rt.global()
|
|
243
|
+
.getPropertyAsFunction(rt, "RegExp")
|
|
244
|
+
.callAsConstructor(rt, jsi::String::createFromUtf8(rt, pattern_), jsi::String::createFromUtf8(rt, flags_));
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
jsi::Value SerializableError::toJSValue(jsi::Runtime &rt) {
|
|
248
|
+
auto error = rt.global()
|
|
249
|
+
.getPropertyAsFunction(rt, "Error")
|
|
250
|
+
.callAsConstructor(rt, jsi::String::createFromUtf8(rt, message_))
|
|
251
|
+
.getObject(rt);
|
|
252
|
+
|
|
253
|
+
error.setProperty(rt, "name", jsi::String::createFromUtf8(rt, name_));
|
|
254
|
+
|
|
255
|
+
if (stack_.has_value()) {
|
|
256
|
+
error.setProperty(rt, "stack", jsi::String::createFromUtf8(rt, stack_.value()));
|
|
257
|
+
} else {
|
|
258
|
+
error.setProperty(rt, "stack", jsi::String::createFromUtf8(rt, ""));
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
return error;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
jsi::Value SerializableHostObject::toJSValue(jsi::Runtime &rt) {
|
|
265
|
+
return jsi::Object::createFromHostObject(rt, hostObject_);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
jsi::Value SerializableHostFunction::toJSValue(jsi::Runtime &rt) {
|
|
269
|
+
return jsi::Function::createFromHostFunction(rt, jsi::PropNameID::forUtf8(rt, name_), paramCount_, hostFunction_);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
jsi::Value SerializableWorklet::toJSValue(jsi::Runtime &rt) {
|
|
273
|
+
react_native_assert(
|
|
274
|
+
std::any_of(data_.cbegin(), data_.cend(), [](const auto &item) { return item.first == "__workletHash"; }) &&
|
|
275
|
+
"SerializableWorklet doesn't have `__workletHash` property");
|
|
276
|
+
jsi::Value obj = SerializableObject::toJSValue(rt);
|
|
277
|
+
return getValueUnpacker(rt).call(rt, obj, jsi::String::createFromAscii(rt, "Worklet"));
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
jsi::Value SerializableImport::toJSValue(jsi::Runtime &rt) {
|
|
281
|
+
/**
|
|
282
|
+
* The only way to obtain a module in runtime is to use the Metro's require
|
|
283
|
+
* method implementation, which is injected into the global object as `__r`.
|
|
284
|
+
*/
|
|
285
|
+
const auto metroRequire = rt.global().getProperty(rt, "__r");
|
|
286
|
+
if (metroRequire.isUndefined()) {
|
|
287
|
+
return jsi::Value::undefined();
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
const auto imported = jsi::String::createFromUtf8(rt, imported_);
|
|
291
|
+
return metroRequire.asObject(rt).asFunction(rt).call(rt, source_).asObject(rt).getProperty(rt, imported);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
jsi::Value SerializableInitializer::toJSValue(jsi::Runtime &rt) {
|
|
295
|
+
if (remoteValue_ == nullptr) {
|
|
296
|
+
auto initObj = initializer_->toJSValue(rt);
|
|
297
|
+
auto value = std::make_unique<jsi::Value>(
|
|
298
|
+
getValueUnpacker(rt).call(rt, initObj, jsi::String::createFromAscii(rt, "Handle")));
|
|
299
|
+
|
|
300
|
+
// We are locking the initialization here since the thread that is
|
|
301
|
+
// initializing can be preempted on runtime lock. E.g.
|
|
302
|
+
// UI thread can be preempted on initialization of a shared value and then
|
|
303
|
+
// JS thread can try to access the shared value, locking the whole runtime.
|
|
304
|
+
// If we put the lock on `getValueUnpacker` part (basically any part that
|
|
305
|
+
// requires runtime) we would get a deadlock since UI thread would never
|
|
306
|
+
// release it.
|
|
307
|
+
std::unique_lock<std::mutex> lock(initializationMutex_);
|
|
308
|
+
if (remoteValue_ == nullptr) {
|
|
309
|
+
remoteValue_ = std::move(value);
|
|
310
|
+
remoteRuntime_ = &rt;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
if (&rt == remoteRuntime_) {
|
|
314
|
+
return jsi::Value(rt, *remoteValue_);
|
|
315
|
+
}
|
|
316
|
+
auto initObj = initializer_->toJSValue(rt);
|
|
317
|
+
return getValueUnpacker(rt).call(rt, initObj, jsi::String::createFromAscii(rt, "Handle"));
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
jsi::Value SerializableString::toJSValue(jsi::Runtime &rt) {
|
|
321
|
+
return jsi::String::createFromUtf8(rt, data_);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
jsi::Value SerializableBigInt::toJSValue(jsi::Runtime &rt) {
|
|
325
|
+
if (fastValue_.has_value()) {
|
|
326
|
+
return jsi::BigInt::fromInt64(rt, fastValue_.value());
|
|
327
|
+
} else {
|
|
328
|
+
return rt.global().getPropertyAsFunction(rt, "BigInt").call(rt, jsi::String::createFromUtf8(rt, slowValue_));
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
jsi::Value SerializableScalar::toJSValue(jsi::Runtime &) {
|
|
333
|
+
switch (valueType_) {
|
|
334
|
+
case Serializable::ValueType::UndefinedType:
|
|
335
|
+
return jsi::Value();
|
|
336
|
+
case Serializable::ValueType::NullType:
|
|
337
|
+
return jsi::Value(nullptr);
|
|
338
|
+
case Serializable::ValueType::BooleanType:
|
|
339
|
+
return jsi::Value(data_.boolean);
|
|
340
|
+
case Serializable::ValueType::NumberType:
|
|
341
|
+
return jsi::Value(data_.number);
|
|
342
|
+
default:
|
|
343
|
+
throw std::runtime_error("[Worklets] Attempted to convert object that's not of a scalar type.");
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
jsi::Value SerializableTurboModuleLike::toJSValue(jsi::Runtime &rt) {
|
|
348
|
+
auto obj = properties_->toJSValue(rt).asObject(rt);
|
|
349
|
+
const auto prototype = proto_->toJSValue(rt);
|
|
350
|
+
rt.global().getPropertyAsObject(rt, "Object").getPropertyAsFunction(rt, "setPrototypeOf").call(rt, obj, prototype);
|
|
351
|
+
|
|
352
|
+
return obj;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
jsi::Function getCustomSerializableUnpacker(jsi::Runtime &rt) {
|
|
356
|
+
auto customSerializableUnpacker = rt.global().getProperty(rt, "__customSerializableUnpacker");
|
|
357
|
+
react_native_assert(customSerializableUnpacker.isObject() && "customSerializableUnpacker not found");
|
|
358
|
+
return customSerializableUnpacker.asObject(rt).asFunction(rt);
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
jsi::Value CustomSerializable::toJSValue(jsi::Runtime &rt) {
|
|
362
|
+
try {
|
|
363
|
+
auto unpack = getCustomSerializableUnpacker(rt);
|
|
364
|
+
auto data = data_->toJSValue(rt);
|
|
365
|
+
|
|
366
|
+
return unpack.call(rt, data, jsi::Value(typeId_));
|
|
367
|
+
} catch (jsi::JSError &e) {
|
|
368
|
+
throw std::runtime_error(
|
|
369
|
+
std::string("[Worklets] Failed to deserialize CustomSerializable. Reason: ") + e.getMessage());
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
} // namespace worklets
|