@amazon-devices/react-native-worklets 1.0.0-rn-83
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/Common/cpp/worklets/AnimationFrameQueue/AnimationFrameBatchinator.cpp +71 -0
- package/Common/cpp/worklets/AnimationFrameQueue/AnimationFrameBatchinator.h +38 -0
- package/Common/cpp/worklets/NativeModules/JSIWorkletsModuleProxy.cpp +712 -0
- package/Common/cpp/worklets/NativeModules/JSIWorkletsModuleProxy.h +88 -0
- package/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.cpp +89 -0
- package/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.h +80 -0
- package/Common/cpp/worklets/Public/AsyncQueue.h +14 -0
- package/Common/cpp/worklets/Registries/EventHandlerRegistry.cpp +94 -0
- package/Common/cpp/worklets/Registries/EventHandlerRegistry.h +51 -0
- package/Common/cpp/worklets/Registries/WorkletRuntimeRegistry.cpp +8 -0
- package/Common/cpp/worklets/Registries/WorkletRuntimeRegistry.h +40 -0
- package/Common/cpp/worklets/Resources/SynchronizableUnpacker.cpp +49 -0
- package/Common/cpp/worklets/Resources/Unpackers.h +6 -0
- package/Common/cpp/worklets/Resources/ValueUnpacker.cpp +53 -0
- package/Common/cpp/worklets/RunLoop/AsyncQueueImpl.cpp +62 -0
- package/Common/cpp/worklets/RunLoop/AsyncQueueImpl.h +46 -0
- package/Common/cpp/worklets/RunLoop/EventLoop.cpp +112 -0
- package/Common/cpp/worklets/RunLoop/EventLoop.h +52 -0
- package/Common/cpp/worklets/SharedItems/Serializable.cpp +545 -0
- package/Common/cpp/worklets/SharedItems/Serializable.h +473 -0
- package/Common/cpp/worklets/SharedItems/Synchronizable.cpp +67 -0
- package/Common/cpp/worklets/SharedItems/Synchronizable.h +59 -0
- package/Common/cpp/worklets/SharedItems/SynchronizableAccess.cpp +81 -0
- package/Common/cpp/worklets/SharedItems/SynchronizableAccess.h +45 -0
- package/Common/cpp/worklets/Tools/Defs.h +10 -0
- package/Common/cpp/worklets/Tools/FeatureFlags.cpp +15 -0
- package/Common/cpp/worklets/Tools/FeatureFlags.h +44 -0
- package/Common/cpp/worklets/Tools/JSISerializer.cpp +342 -0
- package/Common/cpp/worklets/Tools/JSISerializer.h +51 -0
- package/Common/cpp/worklets/Tools/JSLogger.cpp +68 -0
- package/Common/cpp/worklets/Tools/JSLogger.h +37 -0
- package/Common/cpp/worklets/Tools/JSScheduler.cpp +24 -0
- package/Common/cpp/worklets/Tools/JSScheduler.h +39 -0
- package/Common/cpp/worklets/Tools/PlatformLogger.h +16 -0
- package/Common/cpp/worklets/Tools/SingleInstanceChecker.h +82 -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 +26 -0
- package/Common/cpp/worklets/Tools/VersionUtils.cpp +75 -0
- package/Common/cpp/worklets/Tools/VersionUtils.h +28 -0
- package/Common/cpp/worklets/Tools/WorkletEventHandler.cpp +29 -0
- package/Common/cpp/worklets/Tools/WorkletEventHandler.h +41 -0
- package/Common/cpp/worklets/Tools/WorkletsJSIUtils.cpp +46 -0
- package/Common/cpp/worklets/Tools/WorkletsJSIUtils.h +208 -0
- package/Common/cpp/worklets/Tools/WorkletsSystraceSection.h +161 -0
- package/Common/cpp/worklets/Tools/WorkletsVersion.cpp +54 -0
- package/Common/cpp/worklets/Tools/WorkletsVersion.h +20 -0
- package/Common/cpp/worklets/WorkletRuntime/RNRuntimeWorkletDecorator.cpp +38 -0
- package/Common/cpp/worklets/WorkletRuntime/RNRuntimeWorkletDecorator.h +21 -0
- package/Common/cpp/worklets/WorkletRuntime/RuntimeData.cpp +3 -0
- package/Common/cpp/worklets/WorkletRuntime/RuntimeData.h +12 -0
- package/Common/cpp/worklets/WorkletRuntime/RuntimeInitialization.md +191 -0
- package/Common/cpp/worklets/WorkletRuntime/RuntimeKind.h +16 -0
- package/Common/cpp/worklets/WorkletRuntime/RuntimeManager.cpp +105 -0
- package/Common/cpp/worklets/WorkletRuntime/RuntimeManager.h +63 -0
- package/Common/cpp/worklets/WorkletRuntime/UIRuntimeDecorator.cpp +23 -0
- package/Common/cpp/worklets/WorkletRuntime/UIRuntimeDecorator.h +16 -0
- package/Common/cpp/worklets/WorkletRuntime/WorkletHermesRuntime.cpp +119 -0
- package/Common/cpp/worklets/WorkletRuntime/WorkletHermesRuntime.h +134 -0
- package/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.cpp +244 -0
- package/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.h +102 -0
- package/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeCollector.h +36 -0
- package/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.cpp +308 -0
- package/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.h +26 -0
- package/LICENSE +7 -0
- package/README.md +31 -0
- package/RNWorklets.podspec +94 -0
- package/SystemBundles/cc12deac6e91c435b76698c8445aed85612f2f88e733218d14f88a35d06fb0f4.bundle +10512 -0
- package/SystemBundles/cc12deac6e91c435b76698c8445aed85612f2f88e733218d14f88a35d06fb0f4.map +3771 -0
- package/SystemModules/amzn__react-native-worklets-1.modules.txt +39 -0
- package/SystemModules/amzn__react-native-worklets-1.private.modules.txt +61 -0
- package/SystemModules/keplerscript-system-bundle-config.json +7 -0
- package/android/CMakeLists.txt +124 -0
- package/android/build.gradle +350 -0
- package/android/gradle.properties +5 -0
- package/android/proguard-rules.pro +3 -0
- package/android/spotless.gradle +9 -0
- package/android/src/experimentalBundling/com/swmansion/worklets/WorkletsModule.java +149 -0
- package/android/src/legacyBundling/com/swmansion/worklets/WorkletsModule.java +122 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/cpp/worklets/android/AndroidUIScheduler.cpp +63 -0
- package/android/src/main/cpp/worklets/android/AndroidUIScheduler.h +43 -0
- package/android/src/main/cpp/worklets/android/AnimationFrameCallback.h +34 -0
- package/android/src/main/cpp/worklets/android/PlatformLogger.cpp +29 -0
- package/android/src/main/cpp/worklets/android/WorkletsModule.cpp +115 -0
- package/android/src/main/cpp/worklets/android/WorkletsModule.h +78 -0
- package/android/src/main/cpp/worklets/android/WorkletsOnLoad.cpp +13 -0
- package/android/src/main/java/com/swmansion/worklets/AndroidUIScheduler.java +60 -0
- package/android/src/main/java/com/swmansion/worklets/JSCallInvokerResolver.java +27 -0
- package/android/src/main/java/com/swmansion/worklets/WorkletsMessageQueueThread.java +16 -0
- package/android/src/main/java/com/swmansion/worklets/WorkletsMessageQueueThreadBase.java +73 -0
- package/android/src/main/java/com/swmansion/worklets/WorkletsPackage.java +48 -0
- package/android/src/main/java/com/swmansion/worklets/runloop/AnimationFrameCallback.java +19 -0
- package/android/src/main/java/com/swmansion/worklets/runloop/AnimationFrameQueue.java +113 -0
- package/apple/worklets/apple/AnimationFrameQueue.h +15 -0
- package/apple/worklets/apple/AnimationFrameQueue.mm +135 -0
- package/apple/worklets/apple/AssertJavaScriptQueue.h +14 -0
- package/apple/worklets/apple/AssertTurboModuleManagerQueue.h +16 -0
- package/apple/worklets/apple/IOSUIScheduler.h +15 -0
- package/apple/worklets/apple/IOSUIScheduler.mm +29 -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/WorkletsMessageThread.h +16 -0
- package/apple/worklets/apple/WorkletsMessageThread.mm +31 -0
- package/apple/worklets/apple/WorkletsModule.h +28 -0
- package/apple/worklets/apple/WorkletsModule.mm +121 -0
- package/bundleMode/index.d.ts +3 -0
- package/bundleMode/index.js +59 -0
- package/compatibility.json +11 -0
- package/kepler-compatibility.json +5 -0
- package/kepler-transformed-package-info.json +3 -0
- package/lib/module/PlatformChecker/PlatformChecker.js +8 -0
- package/lib/module/PlatformChecker/PlatformChecker.js.map +1 -0
- package/lib/module/PlatformChecker/index.js +18 -0
- package/lib/module/PlatformChecker/index.js.map +1 -0
- package/lib/module/WorkletsError.js +29 -0
- package/lib/module/WorkletsError.js.map +1 -0
- package/lib/module/WorkletsModule/JSWorklets.js +111 -0
- package/lib/module/WorkletsModule/JSWorklets.js.map +1 -0
- package/lib/module/WorkletsModule/NativeWorklets.js +126 -0
- package/lib/module/WorkletsModule/NativeWorklets.js.map +1 -0
- package/lib/module/WorkletsModule/index.js +4 -0
- package/lib/module/WorkletsModule/index.js.map +1 -0
- package/lib/module/WorkletsModule/workletsModuleInstance.js +7 -0
- package/lib/module/WorkletsModule/workletsModuleInstance.js.map +1 -0
- package/lib/module/WorkletsModule/workletsModuleInstance.web.js +5 -0
- package/lib/module/WorkletsModule/workletsModuleInstance.web.js.map +1 -0
- package/lib/module/WorkletsModule/workletsModuleProxy.js +4 -0
- package/lib/module/WorkletsModule/workletsModuleProxy.js.map +1 -0
- package/lib/module/bundleUnpacker.js +47 -0
- package/lib/module/bundleUnpacker.js.map +1 -0
- package/lib/module/callGuard.js +30 -0
- package/lib/module/callGuard.js.map +1 -0
- package/lib/module/deprecated.js +20 -0
- package/lib/module/deprecated.js.map +1 -0
- package/lib/module/errors.js +69 -0
- package/lib/module/errors.js.map +1 -0
- package/lib/module/featureFlags/index.js +48 -0
- package/lib/module/featureFlags/index.js.map +1 -0
- package/lib/module/featureFlags/staticFlags.json +4 -0
- package/lib/module/index.js +26 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/initializers.js +221 -0
- package/lib/module/initializers.js.map +1 -0
- package/lib/module/isSynchronizable.js +6 -0
- package/lib/module/isSynchronizable.js.map +1 -0
- package/lib/module/logger.js +15 -0
- package/lib/module/logger.js.map +1 -0
- package/lib/module/privateGlobals.d.js +7 -0
- package/lib/module/privateGlobals.d.js.map +1 -0
- package/lib/module/publicGlobals.js +6 -0
- package/lib/module/publicGlobals.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 +52 -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 +39 -0
- package/lib/module/runtimeKind.js.map +1 -0
- package/lib/module/runtimes.js +100 -0
- package/lib/module/runtimes.js.map +1 -0
- package/lib/module/serializable.js +568 -0
- package/lib/module/serializable.js.map +1 -0
- package/lib/module/serializableMappingCache.js +37 -0
- package/lib/module/serializableMappingCache.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/NativeWorkletsModule.kepler.js +7 -0
- package/lib/module/specs/NativeWorkletsModule.kepler.js.map +1 -0
- package/lib/module/specs/index.js +10 -0
- package/lib/module/specs/index.js.map +1 -0
- package/lib/module/synchronizable.js +9 -0
- package/lib/module/synchronizable.js.map +1 -0
- package/lib/module/synchronizableUnpacker.js +42 -0
- package/lib/module/synchronizableUnpacker.js.map +1 -0
- package/lib/module/threads.js +347 -0
- package/lib/module/threads.js.map +1 -0
- package/lib/module/utils/checkCppVersion.js +30 -0
- package/lib/module/utils/checkCppVersion.js.map +1 -0
- package/lib/module/utils/jsVersion.js +9 -0
- package/lib/module/utils/jsVersion.js.map +1 -0
- package/lib/module/valueUnpacker.js +60 -0
- package/lib/module/valueUnpacker.js.map +1 -0
- package/lib/module/workletFunction.js +37 -0
- package/lib/module/workletFunction.js.map +1 -0
- package/lib/module/workletRuntimeEntry.js +32 -0
- package/lib/module/workletRuntimeEntry.js.map +1 -0
- package/lib/module/workletTypes.js +12 -0
- package/lib/module/workletTypes.js.map +1 -0
- package/lib/typescript/PlatformChecker/PlatformChecker.d.ts +5 -0
- package/lib/typescript/PlatformChecker/PlatformChecker.d.ts.map +1 -0
- package/lib/typescript/PlatformChecker/index.d.ts +10 -0
- package/lib/typescript/PlatformChecker/index.d.ts.map +1 -0
- package/lib/typescript/WorkletsError.d.ts +15 -0
- package/lib/typescript/WorkletsError.d.ts.map +1 -0
- package/lib/typescript/WorkletsModule/JSWorklets.d.ts +3 -0
- package/lib/typescript/WorkletsModule/JSWorklets.d.ts.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/index.d.ts +3 -0
- package/lib/typescript/WorkletsModule/index.d.ts.map +1 -0
- package/lib/typescript/WorkletsModule/workletsModuleInstance.d.ts +2 -0
- package/lib/typescript/WorkletsModule/workletsModuleInstance.d.ts.map +1 -0
- package/lib/typescript/WorkletsModule/workletsModuleInstance.web.d.ts +2 -0
- package/lib/typescript/WorkletsModule/workletsModuleInstance.web.d.ts.map +1 -0
- package/lib/typescript/WorkletsModule/workletsModuleProxy.d.ts +37 -0
- package/lib/typescript/WorkletsModule/workletsModuleProxy.d.ts.map +1 -0
- package/lib/typescript/bundleUnpacker.d.ts +7 -0
- package/lib/typescript/bundleUnpacker.d.ts.map +1 -0
- package/lib/typescript/callGuard.d.ts +4 -0
- package/lib/typescript/callGuard.d.ts.map +1 -0
- package/lib/typescript/deprecated.d.ts +20 -0
- package/lib/typescript/deprecated.d.ts.map +1 -0
- package/lib/typescript/errors.d.ts +16 -0
- package/lib/typescript/errors.d.ts.map +1 -0
- package/lib/typescript/featureFlags/index.d.ts +23 -0
- package/lib/typescript/featureFlags/index.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +17 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/initializers.d.ts +17 -0
- package/lib/typescript/initializers.d.ts.map +1 -0
- package/lib/typescript/isSynchronizable.d.ts +3 -0
- package/lib/typescript/isSynchronizable.d.ts.map +1 -0
- package/lib/typescript/logger.d.ts +5 -0
- package/lib/typescript/logger.d.ts.map +1 -0
- package/lib/typescript/publicGlobals.d.ts +31 -0
- package/lib/typescript/publicGlobals.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 +25 -0
- package/lib/typescript/runtimeKind.d.ts.map +1 -0
- package/lib/typescript/runtimes.d.ts +77 -0
- package/lib/typescript/runtimes.d.ts.map +1 -0
- package/lib/typescript/serializable.d.ts +20 -0
- package/lib/typescript/serializable.d.ts.map +1 -0
- package/lib/typescript/serializableMappingCache.d.ts +16 -0
- package/lib/typescript/serializableMappingCache.d.ts.map +1 -0
- package/lib/typescript/specs/NativeWorkletsModule.d.ts +7 -0
- package/lib/typescript/specs/NativeWorkletsModule.d.ts.map +1 -0
- package/lib/typescript/specs/NativeWorkletsModule.kepler.d.ts +7 -0
- package/lib/typescript/specs/NativeWorkletsModule.kepler.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/synchronizable.d.ts +15 -0
- package/lib/typescript/synchronizable.d.ts.map +1 -0
- package/lib/typescript/synchronizableUnpacker.d.ts +4 -0
- package/lib/typescript/synchronizableUnpacker.d.ts.map +1 -0
- package/lib/typescript/threads.d.ts +138 -0
- package/lib/typescript/threads.d.ts.map +1 -0
- package/lib/typescript/utils/checkCppVersion.d.ts +3 -0
- package/lib/typescript/utils/checkCppVersion.d.ts.map +1 -0
- package/lib/typescript/utils/jsVersion.d.ts +7 -0
- package/lib/typescript/utils/jsVersion.d.ts.map +1 -0
- package/lib/typescript/valueUnpacker.d.ts +6 -0
- package/lib/typescript/valueUnpacker.d.ts.map +1 -0
- package/lib/typescript/workletFunction.d.ts +27 -0
- package/lib/typescript/workletFunction.d.ts.map +1 -0
- package/lib/typescript/workletRuntimeEntry.d.ts +14 -0
- package/lib/typescript/workletRuntimeEntry.d.ts.map +1 -0
- package/lib/typescript/workletTypes.d.ts +61 -0
- package/lib/typescript/workletTypes.d.ts.map +1 -0
- package/package.json +153 -0
- package/plugin/index.js +1761 -0
- package/react-native.config.js +21 -0
- package/scripts/validate-react-native-version.js +43 -0
- package/scripts/worklets_utils.rb +94 -0
- package/src/PlatformChecker/PlatformChecker.ts +7 -0
- package/src/PlatformChecker/index.ts +30 -0
- package/src/WorkletsError.ts +36 -0
- package/src/WorkletsModule/JSWorklets.ts +200 -0
- package/src/WorkletsModule/NativeWorklets.ts +256 -0
- package/src/WorkletsModule/index.ts +7 -0
- package/src/WorkletsModule/workletsModuleInstance.ts +9 -0
- package/src/WorkletsModule/workletsModuleInstance.web.ts +5 -0
- package/src/WorkletsModule/workletsModuleProxy.ts +126 -0
- package/src/bundleUnpacker.ts +75 -0
- package/src/callGuard.ts +33 -0
- package/src/deprecated.ts +32 -0
- package/src/errors.ts +80 -0
- package/src/featureFlags/index.ts +72 -0
- package/src/featureFlags/staticFlags.json +4 -0
- package/src/index.ts +53 -0
- package/src/initializers.ts +262 -0
- package/src/isSynchronizable.ts +13 -0
- package/src/logger.ts +16 -0
- package/src/privateGlobals.d.ts +79 -0
- package/src/publicGlobals.ts +39 -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 +66 -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 +37 -0
- package/src/runtimes.ts +193 -0
- package/src/serializable.ts +801 -0
- package/src/serializableMappingCache.ts +42 -0
- package/src/specs/NativeWorkletsModule.kepler.ts +11 -0
- package/src/specs/NativeWorkletsModule.ts +9 -0
- package/src/specs/index.ts +13 -0
- package/src/synchronizable.ts +32 -0
- package/src/synchronizableUnpacker.ts +67 -0
- package/src/threads.ts +452 -0
- package/src/utils/checkCppVersion.ts +34 -0
- package/src/utils/jsVersion.ts +7 -0
- package/src/valueUnpacker.ts +90 -0
- package/src/workletFunction.ts +42 -0
- package/src/workletRuntimeEntry.ts +35 -0
- package/src/workletTypes.ts +81 -0
|
@@ -0,0 +1,473 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
// amznmod_react - export symbols for reanimated
|
|
4
|
+
#include <keplerui-083/keplerscript-export.h>
|
|
5
|
+
|
|
6
|
+
#include <worklets/Registries/WorkletRuntimeRegistry.h>
|
|
7
|
+
|
|
8
|
+
#include <jsi/jsi.h>
|
|
9
|
+
|
|
10
|
+
#include <memory>
|
|
11
|
+
#include <string>
|
|
12
|
+
#include <utility>
|
|
13
|
+
#include <vector>
|
|
14
|
+
|
|
15
|
+
using namespace facebook;
|
|
16
|
+
|
|
17
|
+
namespace worklets {
|
|
18
|
+
|
|
19
|
+
jsi::Function getValueUnpacker(jsi::Runtime &rt);
|
|
20
|
+
|
|
21
|
+
#ifndef NDEBUG
|
|
22
|
+
// amznmod_react - export symbols for reanimated
|
|
23
|
+
jsi::Function KEPLERSCRIPT_EXPORT getCallGuard(jsi::Runtime &rt);
|
|
24
|
+
#endif // NDEBUG
|
|
25
|
+
|
|
26
|
+
// If possible, please use `WorkletRuntime::runGuarded` instead.
|
|
27
|
+
template <typename... Args>
|
|
28
|
+
inline jsi::Value runOnRuntimeGuarded(
|
|
29
|
+
jsi::Runtime &rt,
|
|
30
|
+
const jsi::Value &function,
|
|
31
|
+
Args &&...args) {
|
|
32
|
+
// We only use callGuard in debug mode, otherwise we call the provided
|
|
33
|
+
// function directly. CallGuard provides a way of capturing exceptions in
|
|
34
|
+
// JavaScript and propagating them to the main React Native thread such that
|
|
35
|
+
// they can be presented using RN's LogBox.
|
|
36
|
+
#ifndef NDEBUG
|
|
37
|
+
return getCallGuard(rt).call(rt, function, args...);
|
|
38
|
+
#else
|
|
39
|
+
return function.asObject(rt).asFunction(rt).call(rt, args...);
|
|
40
|
+
#endif // NDEBUG
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
inline void cleanupIfRuntimeExists(
|
|
44
|
+
jsi::Runtime *rt,
|
|
45
|
+
std::unique_ptr<jsi::Value> &value) {
|
|
46
|
+
if (rt != nullptr && !WorkletRuntimeRegistry::isRuntimeAlive(rt)) {
|
|
47
|
+
// The below use of unique_ptr.release prevents the smart pointer from
|
|
48
|
+
// calling the destructor of the kept object. This effectively results in
|
|
49
|
+
// leaking some memory. We do this on purpose, as sometimes we would keep
|
|
50
|
+
// references to JSI objects past the lifetime of its runtime (e.g.,
|
|
51
|
+
// shared values references from the RN VM holds reference to JSI objects
|
|
52
|
+
// on the UI runtime). When the UI runtime is terminated, the orphaned JSI
|
|
53
|
+
// objects would crash the app when their destructors are called, because
|
|
54
|
+
// they call into a memory that's managed by the terminated runtime. We
|
|
55
|
+
// accept the tradeoff of leaking memory here, as it has a limited impact.
|
|
56
|
+
// This scenario can only occur when the React instance is torn down which
|
|
57
|
+
// happens in development mode during app reloads, or in production when
|
|
58
|
+
// the app is being shut down gracefully by the system. An alternative
|
|
59
|
+
// solution would require us to keep track of all JSI values that are in
|
|
60
|
+
// use which would require additional data structure and compute spent on
|
|
61
|
+
// bookkeeping that only for the sake of destroying the values in time
|
|
62
|
+
// before the runtime is terminated. Note that the underlying memory that
|
|
63
|
+
// jsi::Value refers to is managed by the VM and gets freed along with the
|
|
64
|
+
// runtime.
|
|
65
|
+
value.release();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// amznmod_react - export symbols for reanimated
|
|
70
|
+
class KEPLERSCRIPT_EXPORT Serializable {
|
|
71
|
+
public:
|
|
72
|
+
virtual jsi::Value toJSValue(jsi::Runtime &rt) = 0;
|
|
73
|
+
|
|
74
|
+
virtual ~Serializable();
|
|
75
|
+
|
|
76
|
+
enum ValueType {
|
|
77
|
+
UndefinedType,
|
|
78
|
+
NullType,
|
|
79
|
+
BooleanType,
|
|
80
|
+
NumberType,
|
|
81
|
+
// SymbolType, TODO
|
|
82
|
+
BigIntType,
|
|
83
|
+
StringType,
|
|
84
|
+
ObjectType,
|
|
85
|
+
ArrayType,
|
|
86
|
+
MapType,
|
|
87
|
+
SetType,
|
|
88
|
+
WorkletType,
|
|
89
|
+
RemoteFunctionType,
|
|
90
|
+
HandleType,
|
|
91
|
+
HostObjectType,
|
|
92
|
+
HostFunctionType,
|
|
93
|
+
ArrayBufferType,
|
|
94
|
+
TurboModuleLikeType,
|
|
95
|
+
ImportType,
|
|
96
|
+
SynchronizableType,
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
explicit Serializable(ValueType valueType) : valueType_(valueType) {}
|
|
100
|
+
|
|
101
|
+
inline ValueType valueType() const {
|
|
102
|
+
return valueType_;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
static std::shared_ptr<Serializable> undefined();
|
|
106
|
+
|
|
107
|
+
protected:
|
|
108
|
+
ValueType valueType_;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
template <typename BaseClass>
|
|
112
|
+
class RetainingSerializable : virtual public BaseClass {
|
|
113
|
+
private:
|
|
114
|
+
jsi::Runtime *primaryRuntime_;
|
|
115
|
+
jsi::Runtime *secondaryRuntime_;
|
|
116
|
+
std::unique_ptr<jsi::Value> secondaryValue_;
|
|
117
|
+
|
|
118
|
+
public:
|
|
119
|
+
template <typename... Args>
|
|
120
|
+
explicit RetainingSerializable(jsi::Runtime &rt, Args &&...args)
|
|
121
|
+
: BaseClass(rt, std::forward<Args>(args)...), primaryRuntime_(&rt) {}
|
|
122
|
+
|
|
123
|
+
jsi::Value toJSValue(jsi::Runtime &rt);
|
|
124
|
+
|
|
125
|
+
~RetainingSerializable() {
|
|
126
|
+
cleanupIfRuntimeExists(secondaryRuntime_, secondaryValue_);
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
class SerializableJSRef : public jsi::NativeState {
|
|
131
|
+
private:
|
|
132
|
+
const std::shared_ptr<Serializable> value_;
|
|
133
|
+
|
|
134
|
+
public:
|
|
135
|
+
explicit SerializableJSRef(const std::shared_ptr<Serializable> &value)
|
|
136
|
+
: value_(value) {}
|
|
137
|
+
|
|
138
|
+
virtual ~SerializableJSRef();
|
|
139
|
+
|
|
140
|
+
std::shared_ptr<Serializable> value() const {
|
|
141
|
+
return value_;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
static jsi::Object newNativeStateObject(
|
|
145
|
+
jsi::Runtime &rt,
|
|
146
|
+
const std::shared_ptr<Serializable> &value) {
|
|
147
|
+
auto object = jsi::Object(rt);
|
|
148
|
+
object.setNativeState(rt, std::make_shared<SerializableJSRef>(value));
|
|
149
|
+
object.setProperty(rt, "__serializableRef", true);
|
|
150
|
+
return object;
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
jsi::Value makeSerializableClone(
|
|
155
|
+
jsi::Runtime &rt,
|
|
156
|
+
const jsi::Value &value,
|
|
157
|
+
const jsi::Value &shouldRetainRemote,
|
|
158
|
+
const jsi::Value &nativeStateSource);
|
|
159
|
+
|
|
160
|
+
jsi::Value makeSerializableString(jsi::Runtime &rt, const jsi::String &string);
|
|
161
|
+
|
|
162
|
+
jsi::Value makeSerializableNumber(jsi::Runtime &rt, double number);
|
|
163
|
+
|
|
164
|
+
jsi::Value makeSerializableBoolean(jsi::Runtime &rt, bool boolean);
|
|
165
|
+
|
|
166
|
+
jsi::Value makeSerializableBigInt(jsi::Runtime &rt, const jsi::BigInt &bigint);
|
|
167
|
+
|
|
168
|
+
jsi::Value makeSerializableUndefined(jsi::Runtime &rt);
|
|
169
|
+
|
|
170
|
+
jsi::Value makeSerializableNull(jsi::Runtime &rt);
|
|
171
|
+
|
|
172
|
+
jsi::Value makeSerializableTurboModuleLike(
|
|
173
|
+
jsi::Runtime &rt,
|
|
174
|
+
const jsi::Object &object,
|
|
175
|
+
const std::shared_ptr<jsi::HostObject> &proto);
|
|
176
|
+
|
|
177
|
+
jsi::Value makeSerializableObject(
|
|
178
|
+
jsi::Runtime &rt,
|
|
179
|
+
jsi::Object object,
|
|
180
|
+
bool shouldRetainRemote,
|
|
181
|
+
const jsi::Value &nativeStateSource);
|
|
182
|
+
|
|
183
|
+
jsi::Value makeSerializableImport(
|
|
184
|
+
jsi::Runtime &rt,
|
|
185
|
+
const double source,
|
|
186
|
+
const jsi::String &imported);
|
|
187
|
+
|
|
188
|
+
jsi::Value makeSerializableHostObject(
|
|
189
|
+
jsi::Runtime &rt,
|
|
190
|
+
const std::shared_ptr<jsi::HostObject> &value);
|
|
191
|
+
|
|
192
|
+
jsi::Value makeSerializableArray(
|
|
193
|
+
jsi::Runtime &rt,
|
|
194
|
+
const jsi::Array &array,
|
|
195
|
+
const jsi::Value &shouldRetainRemote);
|
|
196
|
+
|
|
197
|
+
jsi::Value makeSerializableMap(
|
|
198
|
+
jsi::Runtime &rt,
|
|
199
|
+
const jsi::Array &keys,
|
|
200
|
+
const jsi::Array &values);
|
|
201
|
+
|
|
202
|
+
jsi::Value makeSerializableSet(jsi::Runtime &rt, const jsi::Array &values);
|
|
203
|
+
|
|
204
|
+
jsi::Value makeSerializableInitializer(
|
|
205
|
+
jsi::Runtime &rt,
|
|
206
|
+
const jsi::Object &initializerObject);
|
|
207
|
+
|
|
208
|
+
jsi::Value makeSerializableFunction(jsi::Runtime &rt, jsi::Function function);
|
|
209
|
+
|
|
210
|
+
jsi::Value makeSerializableWorklet(
|
|
211
|
+
jsi::Runtime &rt,
|
|
212
|
+
const jsi::Object &object,
|
|
213
|
+
const bool &shouldRetainRemote);
|
|
214
|
+
|
|
215
|
+
// amznmod_react - export symbols for reanimated
|
|
216
|
+
std::shared_ptr<Serializable> KEPLERSCRIPT_EXPORT extractSerializableOrThrow(
|
|
217
|
+
jsi::Runtime &rt,
|
|
218
|
+
const jsi::Value &maybeSerializableValue,
|
|
219
|
+
const std::string &errorMessage =
|
|
220
|
+
"[Worklets] Expecting the object to be of type SerializableJSRef.");
|
|
221
|
+
|
|
222
|
+
template <typename T>
|
|
223
|
+
std::shared_ptr<T> extractSerializableOrThrow(
|
|
224
|
+
jsi::Runtime &rt,
|
|
225
|
+
const jsi::Value &serializableRef,
|
|
226
|
+
const std::string &errorMessage =
|
|
227
|
+
"[Worklets] Provided serializable object is of an incompatible type.") {
|
|
228
|
+
auto res = std::dynamic_pointer_cast<T>(
|
|
229
|
+
extractSerializableOrThrow(rt, serializableRef, errorMessage));
|
|
230
|
+
if (!res) {
|
|
231
|
+
throw std::runtime_error(errorMessage);
|
|
232
|
+
}
|
|
233
|
+
return res;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
class SerializableArray : public Serializable {
|
|
237
|
+
public:
|
|
238
|
+
SerializableArray(jsi::Runtime &rt, const jsi::Array &array);
|
|
239
|
+
|
|
240
|
+
jsi::Value toJSValue(jsi::Runtime &rt) override;
|
|
241
|
+
|
|
242
|
+
protected:
|
|
243
|
+
std::vector<std::shared_ptr<Serializable>> data_;
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
// amznmod_react - export symbols for reanimated
|
|
247
|
+
class KEPLERSCRIPT_EXPORT SerializableObject : public Serializable {
|
|
248
|
+
public:
|
|
249
|
+
SerializableObject(jsi::Runtime &rt, const jsi::Object &object);
|
|
250
|
+
|
|
251
|
+
SerializableObject(
|
|
252
|
+
jsi::Runtime &rt,
|
|
253
|
+
const jsi::Object &object,
|
|
254
|
+
const jsi::Value &nativeStateSource);
|
|
255
|
+
|
|
256
|
+
jsi::Value toJSValue(jsi::Runtime &rt) override;
|
|
257
|
+
|
|
258
|
+
protected:
|
|
259
|
+
std::vector<std::pair<std::string, std::shared_ptr<Serializable>>> data_;
|
|
260
|
+
std::shared_ptr<jsi::NativeState> nativeState_;
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
class SerializableMap : public Serializable {
|
|
264
|
+
public:
|
|
265
|
+
SerializableMap(
|
|
266
|
+
jsi::Runtime &rt,
|
|
267
|
+
const jsi::Array &keys,
|
|
268
|
+
const jsi::Array &values);
|
|
269
|
+
|
|
270
|
+
jsi::Value toJSValue(jsi::Runtime &rt) override;
|
|
271
|
+
|
|
272
|
+
protected:
|
|
273
|
+
std::vector<
|
|
274
|
+
std::pair<std::shared_ptr<Serializable>, std::shared_ptr<Serializable>>>
|
|
275
|
+
data_;
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
class SerializableSet : public Serializable {
|
|
279
|
+
public:
|
|
280
|
+
SerializableSet(jsi::Runtime &rt, const jsi::Array &values);
|
|
281
|
+
|
|
282
|
+
jsi::Value toJSValue(jsi::Runtime &rt) override;
|
|
283
|
+
|
|
284
|
+
protected:
|
|
285
|
+
std::vector<std::shared_ptr<Serializable>> data_;
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
class SerializableHostObject : public Serializable {
|
|
289
|
+
public:
|
|
290
|
+
SerializableHostObject(
|
|
291
|
+
jsi::Runtime &,
|
|
292
|
+
const std::shared_ptr<jsi::HostObject> &hostObject)
|
|
293
|
+
: Serializable(HostObjectType), hostObject_(hostObject) {}
|
|
294
|
+
|
|
295
|
+
jsi::Value toJSValue(jsi::Runtime &rt) override;
|
|
296
|
+
|
|
297
|
+
protected:
|
|
298
|
+
const std::shared_ptr<jsi::HostObject> hostObject_;
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
class SerializableHostFunction : public Serializable {
|
|
302
|
+
public:
|
|
303
|
+
SerializableHostFunction(jsi::Runtime &rt, jsi::Function function)
|
|
304
|
+
: Serializable(HostFunctionType),
|
|
305
|
+
hostFunction_(function.getHostFunction(rt)),
|
|
306
|
+
name_(function.getProperty(rt, "name").asString(rt).utf8(rt)),
|
|
307
|
+
paramCount_(function.getProperty(rt, "length").asNumber()) {}
|
|
308
|
+
|
|
309
|
+
jsi::Value toJSValue(jsi::Runtime &rt) override;
|
|
310
|
+
|
|
311
|
+
protected:
|
|
312
|
+
const jsi::HostFunctionType hostFunction_;
|
|
313
|
+
const std::string name_;
|
|
314
|
+
const unsigned int paramCount_;
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
class SerializableArrayBuffer : public Serializable {
|
|
318
|
+
public:
|
|
319
|
+
SerializableArrayBuffer(jsi::Runtime &rt, const jsi::ArrayBuffer &arrayBuffer)
|
|
320
|
+
: Serializable(ArrayBufferType),
|
|
321
|
+
data_(
|
|
322
|
+
arrayBuffer.data(rt),
|
|
323
|
+
arrayBuffer.data(rt) + arrayBuffer.size(rt)) {}
|
|
324
|
+
|
|
325
|
+
jsi::Value toJSValue(jsi::Runtime &rt) override;
|
|
326
|
+
|
|
327
|
+
protected:
|
|
328
|
+
const std::vector<uint8_t> data_;
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
class KEPLERSCRIPT_EXPORT SerializableWorklet : public SerializableObject {
|
|
332
|
+
public:
|
|
333
|
+
SerializableWorklet(jsi::Runtime &rt, const jsi::Object &worklet)
|
|
334
|
+
: SerializableObject(rt, worklet) {
|
|
335
|
+
valueType_ = WorkletType;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
jsi::Value toJSValue(jsi::Runtime &rt) override;
|
|
339
|
+
};
|
|
340
|
+
|
|
341
|
+
class SerializableImport : public Serializable {
|
|
342
|
+
public:
|
|
343
|
+
SerializableImport(
|
|
344
|
+
jsi::Runtime &rt,
|
|
345
|
+
const double source,
|
|
346
|
+
const jsi::String &imported)
|
|
347
|
+
: Serializable(ImportType),
|
|
348
|
+
source_(source),
|
|
349
|
+
imported_(imported.utf8(rt)) {}
|
|
350
|
+
|
|
351
|
+
jsi::Value toJSValue(jsi::Runtime &rt) override;
|
|
352
|
+
|
|
353
|
+
protected:
|
|
354
|
+
const double source_;
|
|
355
|
+
const std::string imported_;
|
|
356
|
+
};
|
|
357
|
+
|
|
358
|
+
class SerializableRemoteFunction
|
|
359
|
+
: public Serializable,
|
|
360
|
+
public std::enable_shared_from_this<SerializableRemoteFunction> {
|
|
361
|
+
private:
|
|
362
|
+
jsi::Runtime *runtime_;
|
|
363
|
+
#ifndef NDEBUG
|
|
364
|
+
const std::string name_;
|
|
365
|
+
#endif
|
|
366
|
+
std::unique_ptr<jsi::Value> function_;
|
|
367
|
+
|
|
368
|
+
public:
|
|
369
|
+
SerializableRemoteFunction(jsi::Runtime &rt, jsi::Function &&function)
|
|
370
|
+
: Serializable(RemoteFunctionType),
|
|
371
|
+
runtime_(&rt),
|
|
372
|
+
#ifndef NDEBUG
|
|
373
|
+
name_(function.getProperty(rt, "name").asString(rt).utf8(rt)),
|
|
374
|
+
#endif
|
|
375
|
+
function_(std::make_unique<jsi::Value>(rt, std::move(function))) {
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
~SerializableRemoteFunction() {
|
|
379
|
+
cleanupIfRuntimeExists(runtime_, function_);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
jsi::Value toJSValue(jsi::Runtime &rt) override;
|
|
383
|
+
};
|
|
384
|
+
|
|
385
|
+
class SerializableInitializer : public Serializable {
|
|
386
|
+
private:
|
|
387
|
+
// We don't release the initializer since the handle can get
|
|
388
|
+
// initialized in parallel on multiple threads. However this is not a problem,
|
|
389
|
+
// since the final value is taken from a cache on the runtime which guarantees
|
|
390
|
+
// sequential access.
|
|
391
|
+
std::unique_ptr<SerializableObject> initializer_;
|
|
392
|
+
std::unique_ptr<jsi::Value> remoteValue_;
|
|
393
|
+
mutable std::mutex initializationMutex_;
|
|
394
|
+
jsi::Runtime *remoteRuntime_;
|
|
395
|
+
|
|
396
|
+
public:
|
|
397
|
+
SerializableInitializer(
|
|
398
|
+
jsi::Runtime &rt,
|
|
399
|
+
const jsi::Object &initializerObject)
|
|
400
|
+
: Serializable(HandleType),
|
|
401
|
+
initializer_(
|
|
402
|
+
std::make_unique<SerializableObject>(rt, initializerObject)) {}
|
|
403
|
+
|
|
404
|
+
~SerializableInitializer() {
|
|
405
|
+
cleanupIfRuntimeExists(remoteRuntime_, remoteValue_);
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
jsi::Value toJSValue(jsi::Runtime &rt) override;
|
|
409
|
+
};
|
|
410
|
+
|
|
411
|
+
class SerializableString : public Serializable {
|
|
412
|
+
public:
|
|
413
|
+
explicit SerializableString(const std::string &string)
|
|
414
|
+
: Serializable(StringType), data_(string) {}
|
|
415
|
+
|
|
416
|
+
jsi::Value toJSValue(jsi::Runtime &rt) override;
|
|
417
|
+
|
|
418
|
+
protected:
|
|
419
|
+
const std::string data_;
|
|
420
|
+
};
|
|
421
|
+
|
|
422
|
+
class SerializableBigInt : public Serializable {
|
|
423
|
+
public:
|
|
424
|
+
explicit SerializableBigInt(jsi::Runtime &rt, const jsi::BigInt &bigint)
|
|
425
|
+
: Serializable(BigIntType), string_(bigint.toString(rt).utf8(rt)) {}
|
|
426
|
+
|
|
427
|
+
jsi::Value toJSValue(jsi::Runtime &rt) override;
|
|
428
|
+
|
|
429
|
+
protected:
|
|
430
|
+
const std::string string_;
|
|
431
|
+
};
|
|
432
|
+
|
|
433
|
+
class SerializableScalar : public Serializable {
|
|
434
|
+
public:
|
|
435
|
+
explicit SerializableScalar(double number) : Serializable(NumberType) {
|
|
436
|
+
data_.number = number;
|
|
437
|
+
}
|
|
438
|
+
explicit SerializableScalar(bool boolean) : Serializable(BooleanType) {
|
|
439
|
+
data_.boolean = boolean;
|
|
440
|
+
}
|
|
441
|
+
SerializableScalar() : Serializable(UndefinedType) {}
|
|
442
|
+
explicit SerializableScalar(std::nullptr_t) : Serializable(NullType) {}
|
|
443
|
+
|
|
444
|
+
jsi::Value toJSValue(jsi::Runtime &);
|
|
445
|
+
|
|
446
|
+
protected:
|
|
447
|
+
union Data {
|
|
448
|
+
bool boolean;
|
|
449
|
+
double number;
|
|
450
|
+
};
|
|
451
|
+
|
|
452
|
+
private:
|
|
453
|
+
Data data_;
|
|
454
|
+
};
|
|
455
|
+
|
|
456
|
+
class SerializableTurboModuleLike : public Serializable {
|
|
457
|
+
public:
|
|
458
|
+
SerializableTurboModuleLike(
|
|
459
|
+
jsi::Runtime &rt,
|
|
460
|
+
const jsi::Object &object,
|
|
461
|
+
const std::shared_ptr<jsi::HostObject> &proto)
|
|
462
|
+
: Serializable(TurboModuleLikeType),
|
|
463
|
+
proto_(std::make_unique<SerializableHostObject>(rt, proto)),
|
|
464
|
+
properties_(std::make_unique<SerializableObject>(rt, object)) {}
|
|
465
|
+
|
|
466
|
+
jsi::Value toJSValue(jsi::Runtime &rt) override;
|
|
467
|
+
|
|
468
|
+
private:
|
|
469
|
+
const std::unique_ptr<SerializableHostObject> proto_;
|
|
470
|
+
const std::unique_ptr<SerializableObject> properties_;
|
|
471
|
+
};
|
|
472
|
+
|
|
473
|
+
} // namespace worklets
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
#include <react/debug/react_native_assert.h>
|
|
2
|
+
#include <worklets/SharedItems/Synchronizable.h>
|
|
3
|
+
|
|
4
|
+
#include <utility>
|
|
5
|
+
|
|
6
|
+
namespace worklets {
|
|
7
|
+
|
|
8
|
+
std::shared_ptr<Serializable> Synchronizable::getDirty() {
|
|
9
|
+
return value_;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
std::shared_ptr<Serializable> Synchronizable::getBlocking() {
|
|
13
|
+
getBlockingBefore();
|
|
14
|
+
auto value = value_;
|
|
15
|
+
getBlockingAfter();
|
|
16
|
+
return value;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// TODO: Shared pointer members (unless they're atomic) can't be assigned
|
|
20
|
+
// in a non thread-safe manner, therefore `setDirty` has little sense now.
|
|
21
|
+
// void Synchronizable::setDirty(const std::shared_ptr<Serializable> &value) {
|
|
22
|
+
// setDirtyBefore();
|
|
23
|
+
// value_ = value;
|
|
24
|
+
// setDirtyAfter();
|
|
25
|
+
// }
|
|
26
|
+
|
|
27
|
+
void Synchronizable::setBlocking(const std::shared_ptr<Serializable> &value) {
|
|
28
|
+
setBlockingBefore();
|
|
29
|
+
value_ = value;
|
|
30
|
+
setBlockingAfter();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
jsi::Value Synchronizable::toJSValue(jsi::Runtime &rt) {
|
|
34
|
+
auto synchronizableUnpacker = getSynchronizableUnpacker(rt);
|
|
35
|
+
auto ref =
|
|
36
|
+
SerializableJSRef::newNativeStateObject(rt, this->shared_from_this());
|
|
37
|
+
return synchronizableUnpacker.call(rt, std::move(ref));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
Synchronizable::Synchronizable(const std::shared_ptr<Serializable> &value)
|
|
41
|
+
: Serializable(ValueType::SynchronizableType), value_(value) {}
|
|
42
|
+
|
|
43
|
+
jsi::Function getSynchronizableUnpacker(jsi::Runtime &rt) {
|
|
44
|
+
auto synchronizableUnpacker =
|
|
45
|
+
rt.global().getProperty(rt, "__synchronizableUnpacker");
|
|
46
|
+
react_native_assert(
|
|
47
|
+
synchronizableUnpacker.isObject() && "synchronizableUnpacker not found");
|
|
48
|
+
return synchronizableUnpacker.asObject(rt).asFunction(rt);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
std::shared_ptr<Synchronizable> extractSynchronizableOrThrow(
|
|
52
|
+
jsi::Runtime &rt,
|
|
53
|
+
const jsi::Value &value) {
|
|
54
|
+
auto serializable = extractSerializableOrThrow(
|
|
55
|
+
rt,
|
|
56
|
+
value,
|
|
57
|
+
"[Worklets] Expecting the object to be of type SerializableJSRef.");
|
|
58
|
+
|
|
59
|
+
auto synchronizable = std::dynamic_pointer_cast<Synchronizable>(serializable);
|
|
60
|
+
react_native_assert(
|
|
61
|
+
synchronizable != nullptr &&
|
|
62
|
+
"[Worklets] Expected the object to be a Synchronizable.");
|
|
63
|
+
|
|
64
|
+
return synchronizable;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
} // namespace worklets
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <jsi/jsi.h>
|
|
4
|
+
#include <worklets/SharedItems/Serializable.h>
|
|
5
|
+
#include <worklets/SharedItems/SynchronizableAccess.h>
|
|
6
|
+
|
|
7
|
+
#include <memory>
|
|
8
|
+
|
|
9
|
+
using namespace facebook;
|
|
10
|
+
|
|
11
|
+
namespace worklets {
|
|
12
|
+
|
|
13
|
+
class Synchronizable : public SynchronizableAccess,
|
|
14
|
+
public Serializable,
|
|
15
|
+
public jsi::NativeState,
|
|
16
|
+
public std::enable_shared_from_this<Synchronizable> {
|
|
17
|
+
public:
|
|
18
|
+
/**
|
|
19
|
+
* Can run concurrently with getDirty, setDirty, getBlocking, setBlocking.
|
|
20
|
+
*/
|
|
21
|
+
std::shared_ptr<Serializable> getDirty();
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Can run concurrently with getDirty, getBlocking.
|
|
25
|
+
* Can't run concurrently with setDirty, setBlocking.
|
|
26
|
+
*/
|
|
27
|
+
std::shared_ptr<Serializable> getBlocking();
|
|
28
|
+
|
|
29
|
+
// TODO: Shared pointer members (unless they're atomic) can't be assigned
|
|
30
|
+
// in a non thread-safe manner, therefore `setDirty` has little sense now.
|
|
31
|
+
/**
|
|
32
|
+
* Can run concurrently with getDirty, getBlocking.
|
|
33
|
+
* Can't run concurrently with setDirty, setBlocking.
|
|
34
|
+
*/
|
|
35
|
+
// void setDirty(const std::shared_ptr<Serializable> &value);
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Can run concurrently with getDirty.
|
|
39
|
+
* Can't run concurrently with getBlocking, setDirty, setBlocking.
|
|
40
|
+
*/
|
|
41
|
+
void setBlocking(const std::shared_ptr<Serializable> &value);
|
|
42
|
+
|
|
43
|
+
jsi::Value toJSValue(jsi::Runtime &rt) override;
|
|
44
|
+
|
|
45
|
+
explicit Synchronizable(const std::shared_ptr<Serializable> &value);
|
|
46
|
+
|
|
47
|
+
virtual ~Synchronizable() = default;
|
|
48
|
+
|
|
49
|
+
private:
|
|
50
|
+
std::shared_ptr<Serializable> value_;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
jsi::Function getSynchronizableUnpacker(jsi::Runtime &rt);
|
|
54
|
+
|
|
55
|
+
std::shared_ptr<Synchronizable> extractSynchronizableOrThrow(
|
|
56
|
+
jsi::Runtime &rt,
|
|
57
|
+
const jsi::Value &value);
|
|
58
|
+
|
|
59
|
+
}; // namespace worklets
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
#include <worklets/SharedItems/SynchronizableAccess.h>
|
|
2
|
+
|
|
3
|
+
#include <mutex>
|
|
4
|
+
|
|
5
|
+
namespace worklets {
|
|
6
|
+
void SynchronizableAccess::getBlockingBefore() {
|
|
7
|
+
std::unique_lock<std::mutex> lock(accessLock_);
|
|
8
|
+
queue_.wait(lock, [this]() {
|
|
9
|
+
return !blockingWriter_ /* && dirtyWriters_ == 0 */ &&
|
|
10
|
+
(!imperativelyLocked_ || imperativeOwner_ == pthread_self());
|
|
11
|
+
});
|
|
12
|
+
blockingReaders_++;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
void SynchronizableAccess::getBlockingAfter() {
|
|
16
|
+
std::unique_lock<std::mutex> lock(accessLock_);
|
|
17
|
+
blockingReaders_--;
|
|
18
|
+
if (blockingReaders_ == 0) {
|
|
19
|
+
queue_.notify_all();
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// TODO: Shared pointer members (unless they're atomic) can't be assigned
|
|
24
|
+
// in a non thread-safe manner, therefore `setDirty` has little sense now.
|
|
25
|
+
// void SynchronizableAccess::setDirtyBefore() {
|
|
26
|
+
// std::unique_lock<std::mutex> lock(accessLock_);
|
|
27
|
+
// queue_.wait(lock, [this]() {
|
|
28
|
+
// return !blockingWriter_ && blockingReaders_ == 0 &&
|
|
29
|
+
// (!imperativelyLocked_ || imperativeOwner_ == pthread_self());
|
|
30
|
+
// });
|
|
31
|
+
// dirtyWriters_++;
|
|
32
|
+
// }
|
|
33
|
+
|
|
34
|
+
// TODO: Shared pointer members (unless they're atomic) can't be assigned
|
|
35
|
+
// in a non thread-safe manner, therefore `setDirty` has little sense now.
|
|
36
|
+
// void SynchronizableAccess::setDirtyAfter() {
|
|
37
|
+
// std::unique_lock<std::mutex> lock(accessLock_);
|
|
38
|
+
// dirtyWriters_--;
|
|
39
|
+
// if (dirtyWriters_ == 0) {
|
|
40
|
+
// queue_.notify_all();
|
|
41
|
+
// }
|
|
42
|
+
// }
|
|
43
|
+
|
|
44
|
+
void SynchronizableAccess::setBlockingBefore() {
|
|
45
|
+
std::unique_lock<std::mutex> lock(accessLock_);
|
|
46
|
+
queue_.wait(lock, [this]() {
|
|
47
|
+
return !blockingWriter_ &&
|
|
48
|
+
blockingReaders_ == 0 /* && dirtyWriters_ == 0 */ &&
|
|
49
|
+
(!imperativelyLocked_ || imperativeOwner_ == pthread_self());
|
|
50
|
+
});
|
|
51
|
+
blockingWriter_ = true;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
void SynchronizableAccess::setBlockingAfter() {
|
|
55
|
+
std::unique_lock<std::mutex> lock(accessLock_);
|
|
56
|
+
blockingWriter_ = false;
|
|
57
|
+
queue_.notify_all();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
void SynchronizableAccess::lock() {
|
|
61
|
+
std::unique_lock<std::mutex> lock(accessLock_);
|
|
62
|
+
queue_.wait(lock, [this]() {
|
|
63
|
+
return !blockingWriter_ &&
|
|
64
|
+
blockingReaders_ == 0 /* && dirtyWriters_ == 0 */ &&
|
|
65
|
+
(!imperativelyLocked_ || imperativeOwner_ == pthread_self());
|
|
66
|
+
});
|
|
67
|
+
imperativelyLocked_ = true;
|
|
68
|
+
imperativeOwner_ = pthread_self();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
void SynchronizableAccess::unlock() {
|
|
72
|
+
std::unique_lock<std::mutex> lock(accessLock_);
|
|
73
|
+
if (imperativeOwner_ != pthread_self()) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
imperativelyLocked_ = false;
|
|
77
|
+
imperativeOwner_ = {};
|
|
78
|
+
queue_.notify_all();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
} // namespace worklets
|