@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,63 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <jsi/jsi.h>
|
|
4
|
+
#include <worklets/Tools/UIScheduler.h>
|
|
5
|
+
#include <worklets/WorkletRuntime/RuntimeData.h>
|
|
6
|
+
#include <worklets/WorkletRuntime/WorkletRuntime.h>
|
|
7
|
+
|
|
8
|
+
#include <atomic>
|
|
9
|
+
#include <cstdint>
|
|
10
|
+
#include <map>
|
|
11
|
+
#include <memory>
|
|
12
|
+
#include <shared_mutex>
|
|
13
|
+
#include <string>
|
|
14
|
+
#include <vector>
|
|
15
|
+
|
|
16
|
+
namespace worklets {
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Forward declaration to avoid circular dependencies.
|
|
20
|
+
*/
|
|
21
|
+
class JSIWorkletsModuleProxy;
|
|
22
|
+
|
|
23
|
+
class RuntimeManager {
|
|
24
|
+
public:
|
|
25
|
+
std::shared_ptr<WorkletRuntime> getRuntime(uint64_t runtimeId);
|
|
26
|
+
std::shared_ptr<WorkletRuntime> getRuntime(const std::string &name);
|
|
27
|
+
#ifdef WORKLETS_BUNDLE_MODE
|
|
28
|
+
std::shared_ptr<WorkletRuntime> getRuntime(jsi::Runtime *runtime);
|
|
29
|
+
#endif // WORKLETS_BUNDLE_MODE
|
|
30
|
+
|
|
31
|
+
std::vector<std::shared_ptr<WorkletRuntime>> getAllRuntimes();
|
|
32
|
+
|
|
33
|
+
std::shared_ptr<WorkletRuntime> getUIRuntime();
|
|
34
|
+
|
|
35
|
+
std::shared_ptr<WorkletRuntime> createWorkletRuntime(
|
|
36
|
+
std::shared_ptr<JSIWorkletsModuleProxy> jsiWorkletsModuleProxy,
|
|
37
|
+
const std::string &name,
|
|
38
|
+
std::shared_ptr<SerializableWorklet> initializer = nullptr,
|
|
39
|
+
const std::shared_ptr<AsyncQueue> &queue = nullptr,
|
|
40
|
+
bool enableEventLoop = true);
|
|
41
|
+
|
|
42
|
+
std::shared_ptr<WorkletRuntime> createUninitializedUIRuntime(
|
|
43
|
+
const std::shared_ptr<MessageQueueThread> &jsQueue,
|
|
44
|
+
const std::shared_ptr<AsyncQueue> &uiAsyncQueue);
|
|
45
|
+
|
|
46
|
+
private:
|
|
47
|
+
uint64_t getNextRuntimeId();
|
|
48
|
+
|
|
49
|
+
void registerRuntime(
|
|
50
|
+
const uint64_t runtimeId,
|
|
51
|
+
const std::string &name,
|
|
52
|
+
const std::shared_ptr<WorkletRuntime> &workletRuntime);
|
|
53
|
+
|
|
54
|
+
std::atomic_uint64_t nextRuntimeId_{uiRuntimeId + 1};
|
|
55
|
+
std::map<uint64_t, std::weak_ptr<WorkletRuntime>> weakRuntimes_;
|
|
56
|
+
std::shared_mutex weakRuntimesMutex_;
|
|
57
|
+
std::map<std::string, uint64_t> nameToRuntimeId_;
|
|
58
|
+
#ifdef WORKLETS_BUNDLE_MODE
|
|
59
|
+
std::map<jsi::Runtime *, uint64_t> runtimeAddressToRuntimeId_;
|
|
60
|
+
#endif // WORKLETS_BUNDLE_MODE
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
} // namespace worklets
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
#include <worklets/Tools/WorkletsJSIUtils.h>
|
|
2
|
+
#include <worklets/WorkletRuntime/RuntimeKind.h>
|
|
3
|
+
#include <worklets/WorkletRuntime/UIRuntimeDecorator.h>
|
|
4
|
+
|
|
5
|
+
#include <utility>
|
|
6
|
+
|
|
7
|
+
namespace worklets {
|
|
8
|
+
|
|
9
|
+
void UIRuntimeDecorator::decorate(
|
|
10
|
+
facebook::jsi::Runtime &uiRuntime,
|
|
11
|
+
std::function<
|
|
12
|
+
void(facebook::jsi::Runtime &rt, const facebook::jsi::Value &callback)>
|
|
13
|
+
&&requestAnimationFrame) {
|
|
14
|
+
uiRuntime.global().setProperty(
|
|
15
|
+
uiRuntime, runtimeKindBindingName, static_cast<int>(RuntimeKind::UI));
|
|
16
|
+
|
|
17
|
+
uiRuntime.global().setProperty(uiRuntime, "_UI", true);
|
|
18
|
+
|
|
19
|
+
jsi_utils::installJsiFunction(
|
|
20
|
+
uiRuntime, "requestAnimationFrame", std::move(requestAnimationFrame));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
} // namespace worklets
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <jsi/jsi.h>
|
|
4
|
+
|
|
5
|
+
namespace worklets {
|
|
6
|
+
|
|
7
|
+
class UIRuntimeDecorator {
|
|
8
|
+
public:
|
|
9
|
+
static void decorate(
|
|
10
|
+
facebook::jsi::Runtime &uiRuntime,
|
|
11
|
+
std::function<void(
|
|
12
|
+
facebook::jsi::Runtime &rt,
|
|
13
|
+
const facebook::jsi::Value &callback)> &&requestAnimationFrame);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
} // namespace worklets
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
#include <worklets/WorkletRuntime/WorkletHermesRuntime.h>
|
|
2
|
+
|
|
3
|
+
// Only include this file in Hermes-enabled builds as some platforms (like tvOS)
|
|
4
|
+
// don't support hermes and it causes the compilation to fail.
|
|
5
|
+
#if JS_RUNTIME_HERMES
|
|
6
|
+
|
|
7
|
+
#include <cxxreact/MessageQueueThread.h>
|
|
8
|
+
#include <jsi/decorator.h>
|
|
9
|
+
#include <jsi/jsi.h>
|
|
10
|
+
|
|
11
|
+
#include <memory>
|
|
12
|
+
#include <string>
|
|
13
|
+
#include <utility>
|
|
14
|
+
|
|
15
|
+
namespace worklets {
|
|
16
|
+
|
|
17
|
+
using namespace facebook;
|
|
18
|
+
using namespace react;
|
|
19
|
+
// amznmod_react - cherry-pick f312abe
|
|
20
|
+
#if HERMES_ENABLE_DEBUGGER && !defined(HERMES_V1_ENABLED)
|
|
21
|
+
using namespace facebook::hermes::inspector_modern;
|
|
22
|
+
#endif // HERMES_ENABLE_DEBUGGER && !defined(HERMES_V1_ENABLED)
|
|
23
|
+
|
|
24
|
+
#if HERMES_ENABLE_DEBUGGER
|
|
25
|
+
|
|
26
|
+
// amznmod_react - cherry-pick f312abe
|
|
27
|
+
class HermesExecutorRuntimeAdapter
|
|
28
|
+
#if HERMES_ENABLE_DEBUGGER && !defined(HERMES_V1_ENABLED)
|
|
29
|
+
: public RuntimeAdapter
|
|
30
|
+
#endif // HERMES_ENABLE_DEBUGGER && !defined(HERMES_V1_ENABLED)
|
|
31
|
+
{
|
|
32
|
+
public:
|
|
33
|
+
explicit HermesExecutorRuntimeAdapter(
|
|
34
|
+
facebook::hermes::HermesRuntime &hermesRuntime,
|
|
35
|
+
const std::shared_ptr<MessageQueueThread> &thread)
|
|
36
|
+
: hermesRuntime_(hermesRuntime), thread_(std::move(thread)) {}
|
|
37
|
+
|
|
38
|
+
virtual ~HermesExecutorRuntimeAdapter() {
|
|
39
|
+
// This is required by iOS, because there is an assertion in the destructor
|
|
40
|
+
// that the thread was indeed `quit` before
|
|
41
|
+
thread_->quitSynchronous();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// amznmod_react - cherry-pick f312abe
|
|
45
|
+
#if HERMES_ENABLE_DEBUGGER && !defined(HERMES_V1_ENABLED)
|
|
46
|
+
facebook::hermes::HermesRuntime &getRuntime() override {
|
|
47
|
+
return hermesRuntime_;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// This is not empty in the original implementation, but we decided to tickle
|
|
51
|
+
// the runtime by running a small piece of code on every frame as using this
|
|
52
|
+
// required us to hold a refernce to the runtime inside this adapter which
|
|
53
|
+
// caused issues while reloading the app.
|
|
54
|
+
void tickleJs() override {}
|
|
55
|
+
#endif // HERMES_ENABLE_DEBUGGER && !defined(HERMES_V1_ENABLED)
|
|
56
|
+
|
|
57
|
+
public:
|
|
58
|
+
facebook::hermes::HermesRuntime &hermesRuntime_;
|
|
59
|
+
std::shared_ptr<MessageQueueThread> thread_;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
#endif // HERMES_ENABLE_DEBUGGER
|
|
63
|
+
|
|
64
|
+
WorkletHermesRuntime::WorkletHermesRuntime(
|
|
65
|
+
std::unique_ptr<facebook::hermes::HermesRuntime> runtime,
|
|
66
|
+
const std::shared_ptr<MessageQueueThread> &jsQueue,
|
|
67
|
+
const std::string &name)
|
|
68
|
+
: jsi::WithRuntimeDecorator<WorkletsReentrancyCheck>(
|
|
69
|
+
*runtime,
|
|
70
|
+
reentrancyCheck_),
|
|
71
|
+
runtime_(std::move(runtime)) {
|
|
72
|
+
// amznmod_react - cherry-pick f312abe
|
|
73
|
+
#if HERMES_ENABLE_DEBUGGER && !defined(HERMES_V1_ENABLED)
|
|
74
|
+
auto adapter =
|
|
75
|
+
std::make_unique<HermesExecutorRuntimeAdapter>(*runtime_, jsQueue);
|
|
76
|
+
debugToken_ = chrome::enableDebugging(std::move(adapter), name);
|
|
77
|
+
#endif // HERMES_ENABLE_DEBUGGER && !defined(HERMES_V1_ENABLED)
|
|
78
|
+
|
|
79
|
+
#ifndef NDEBUG
|
|
80
|
+
facebook::hermes::HermesRuntime *wrappedRuntime = runtime_.get();
|
|
81
|
+
jsi::Value evalWithSourceMap = jsi::Function::createFromHostFunction(
|
|
82
|
+
*runtime_,
|
|
83
|
+
jsi::PropNameID::forAscii(*runtime_, "evalWithSourceMap"),
|
|
84
|
+
3,
|
|
85
|
+
[wrappedRuntime](
|
|
86
|
+
jsi::Runtime &rt,
|
|
87
|
+
const jsi::Value &thisValue,
|
|
88
|
+
const jsi::Value *args,
|
|
89
|
+
size_t count) -> jsi::Value {
|
|
90
|
+
auto code = std::make_shared<const jsi::StringBuffer>(
|
|
91
|
+
args[0].asString(rt).utf8(rt));
|
|
92
|
+
std::string sourceURL;
|
|
93
|
+
if (count > 1 && args[1].isString()) {
|
|
94
|
+
sourceURL = args[1].asString(rt).utf8(rt);
|
|
95
|
+
}
|
|
96
|
+
std::shared_ptr<const jsi::Buffer> sourceMap;
|
|
97
|
+
if (count > 2 && args[2].isString()) {
|
|
98
|
+
sourceMap = std::make_shared<const jsi::StringBuffer>(
|
|
99
|
+
args[2].asString(rt).utf8(rt));
|
|
100
|
+
}
|
|
101
|
+
return wrappedRuntime->evaluateJavaScriptWithSourceMap(
|
|
102
|
+
code, sourceMap, sourceURL);
|
|
103
|
+
});
|
|
104
|
+
runtime_->global().setProperty(
|
|
105
|
+
*runtime_, "evalWithSourceMap", evalWithSourceMap);
|
|
106
|
+
#endif // NDEBUG
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
WorkletHermesRuntime::~WorkletHermesRuntime() {
|
|
110
|
+
// amznmod_react - cherry-pick f312abe
|
|
111
|
+
#if HERMES_ENABLE_DEBUGGER && !defined(HERMES_V1_ENABLED)
|
|
112
|
+
// We have to disable debugging before the runtime is destroyed.
|
|
113
|
+
chrome::disableDebugging(debugToken_);
|
|
114
|
+
#endif // HERMES_ENABLE_DEBUGGER && !defined(HERMES_V1_ENABLED)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
} // namespace worklets
|
|
118
|
+
|
|
119
|
+
#endif // JS_RUNTIME_HERMES
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <worklets/Tools/Defs.h>
|
|
4
|
+
|
|
5
|
+
// Only include this file in Hermes-enabled builds as some platforms (like tvOS)
|
|
6
|
+
// don't support hermes and it causes the compilation to fail.
|
|
7
|
+
#if JS_RUNTIME_HERMES
|
|
8
|
+
|
|
9
|
+
#include <cxxreact/MessageQueueThread.h>
|
|
10
|
+
#include <hermes/hermes.h>
|
|
11
|
+
#include <jsi/decorator.h>
|
|
12
|
+
#include <jsi/jsi.h>
|
|
13
|
+
#include <react/debug/react_native_assert.h>
|
|
14
|
+
|
|
15
|
+
#include <atomic>
|
|
16
|
+
#include <memory>
|
|
17
|
+
#include <string>
|
|
18
|
+
#include <thread>
|
|
19
|
+
|
|
20
|
+
// amznmod_react - cherry-pick f312abe
|
|
21
|
+
#if HERMES_ENABLE_DEBUGGER && !defined(HERMES_V1_ENABLED)
|
|
22
|
+
#include <hermes/inspector-modern/chrome/Registration.h>
|
|
23
|
+
#endif // HERMES_ENABLE_DEBUGGER && !defined(HERMES_V1_ENABLED)
|
|
24
|
+
|
|
25
|
+
namespace worklets {
|
|
26
|
+
|
|
27
|
+
using namespace facebook;
|
|
28
|
+
using namespace react;
|
|
29
|
+
// amznmod_react - cherry-pick f312abe
|
|
30
|
+
#if HERMES_ENABLE_DEBUGGER && !defined(HERMES_V1_ENABLED)
|
|
31
|
+
using namespace facebook::hermes::inspector_modern;
|
|
32
|
+
#endif // HERMES_ENABLE_DEBUGGER && !defined(HERMES_V1_ENABLED)
|
|
33
|
+
|
|
34
|
+
// ReentrancyCheck is copied from React Native
|
|
35
|
+
// from ReactCommon/hermes/executor/HermesExecutorFactory.cpp
|
|
36
|
+
// https://github.com/facebook/react-native/blob/main/packages/react-native/ReactCommon/hermes/executor/HermesExecutorFactory.cpp
|
|
37
|
+
struct WorkletsReentrancyCheck {
|
|
38
|
+
// This is effectively a very subtle and complex assert, so only
|
|
39
|
+
// include it in builds which would include asserts.
|
|
40
|
+
#ifndef NDEBUG
|
|
41
|
+
WorkletsReentrancyCheck() : tid(std::thread::id()), depth(0) {}
|
|
42
|
+
|
|
43
|
+
void before() {
|
|
44
|
+
std::thread::id this_id = std::this_thread::get_id();
|
|
45
|
+
std::thread::id expected = std::thread::id();
|
|
46
|
+
|
|
47
|
+
// A note on memory ordering: the main purpose of these checks is
|
|
48
|
+
// to observe a before/before race, without an intervening after.
|
|
49
|
+
// This will be detected by the compare_exchange_strong atomicity
|
|
50
|
+
// properties, regardless of memory order.
|
|
51
|
+
//
|
|
52
|
+
// For everything else, it is easiest to think of 'depth' as a
|
|
53
|
+
// proxy for any access made inside the VM. If access to depth
|
|
54
|
+
// are reordered incorrectly, the same could be true of any other
|
|
55
|
+
// operation made by the VM. In fact, using acquire/release
|
|
56
|
+
// memory ordering could create barriers which mask a programmer
|
|
57
|
+
// error. So, we use relaxed memory order, to avoid masking
|
|
58
|
+
// actual ordering errors. Although, in practice, ordering errors
|
|
59
|
+
// of this sort would be surprising, because the decorator would
|
|
60
|
+
// need to call after() without before().
|
|
61
|
+
|
|
62
|
+
if (tid.compare_exchange_strong(
|
|
63
|
+
expected, this_id, std::memory_order_relaxed)) {
|
|
64
|
+
// Returns true if tid and expected were the same. If they
|
|
65
|
+
// were, then the stored tid referred to no thread, and we
|
|
66
|
+
// atomically saved this thread's tid. Now increment depth.
|
|
67
|
+
react_native_assert(
|
|
68
|
+
depth == 0 && "[Worklets] No thread id, but depth != 0");
|
|
69
|
+
++depth;
|
|
70
|
+
} else if (expected == this_id) {
|
|
71
|
+
// If the stored tid referred to a thread, expected was set to
|
|
72
|
+
// that value. If that value is this thread's tid, that's ok,
|
|
73
|
+
// just increment depth again.
|
|
74
|
+
react_native_assert(
|
|
75
|
+
depth != 0 && "[Worklets] Thread id was set, but depth == 0");
|
|
76
|
+
++depth;
|
|
77
|
+
} else {
|
|
78
|
+
// The stored tid was some other thread. This indicates a bad
|
|
79
|
+
// programmer error, where VM methods were called on two
|
|
80
|
+
// different threads unsafely. Fail fast (and hard) so the
|
|
81
|
+
// crash can be analyzed.
|
|
82
|
+
__builtin_trap();
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
void after() {
|
|
87
|
+
react_native_assert(
|
|
88
|
+
tid.load(std::memory_order_relaxed) == std::this_thread::get_id() &&
|
|
89
|
+
"[Worklets] No thread id in after()");
|
|
90
|
+
if (--depth == 0) {
|
|
91
|
+
// If we decremented depth to zero, store no-thread into tid.
|
|
92
|
+
std::thread::id expected = std::this_thread::get_id();
|
|
93
|
+
bool didWrite = tid.compare_exchange_strong(
|
|
94
|
+
expected, std::thread::id(), std::memory_order_relaxed);
|
|
95
|
+
react_native_assert(
|
|
96
|
+
didWrite && "[Worklets] Decremented to zero, but no tid write");
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
std::atomic<std::thread::id> tid;
|
|
101
|
+
// This is not atomic, as it is only written or read from the owning
|
|
102
|
+
// thread.
|
|
103
|
+
unsigned int depth;
|
|
104
|
+
#endif // NDEBUG
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
// This is in fact a subclass of jsi::Runtime! WithRuntimeDecorator is a
|
|
108
|
+
// template class that is a subclass of DecoratedRuntime which is also a
|
|
109
|
+
// template class that then inherits its template, which in this case is
|
|
110
|
+
// jsi::Runtime. So the inheritance is: WorkletHermesRuntime ->
|
|
111
|
+
// WithRuntimeDecorator -> DecoratedRuntime -> jsi::Runtime You can find out
|
|
112
|
+
// more about this in ReactCommon/jsi/jsi/Decorator.h or by following this link:
|
|
113
|
+
// https://github.com/facebook/react-native/blob/main/packages/react-native/ReactCommon/jsi/jsi/decorator.h
|
|
114
|
+
class WorkletHermesRuntime
|
|
115
|
+
: public jsi::WithRuntimeDecorator<WorkletsReentrancyCheck> {
|
|
116
|
+
public:
|
|
117
|
+
WorkletHermesRuntime(
|
|
118
|
+
std::unique_ptr<facebook::hermes::HermesRuntime> runtime,
|
|
119
|
+
const std::shared_ptr<MessageQueueThread> &jsQueue,
|
|
120
|
+
const std::string &name);
|
|
121
|
+
~WorkletHermesRuntime();
|
|
122
|
+
|
|
123
|
+
private:
|
|
124
|
+
std::unique_ptr<facebook::hermes::HermesRuntime> runtime_;
|
|
125
|
+
WorkletsReentrancyCheck reentrancyCheck_;
|
|
126
|
+
// amznmod_react - cherry-pick f312abe
|
|
127
|
+
#if HERMES_ENABLE_DEBUGGER && !defined(HERMES_V1_ENABLED)
|
|
128
|
+
chrome::DebugSessionToken debugToken_;
|
|
129
|
+
#endif // HERMES_ENABLE_DEBUGGER && !defined(HERMES_V1_ENABLED)
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
} // namespace worklets
|
|
133
|
+
|
|
134
|
+
#endif // JS_RUNTIME_HERMES
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
#include <worklets/NativeModules/JSIWorkletsModuleProxy.h>
|
|
2
|
+
#include <worklets/Resources/Unpackers.h>
|
|
3
|
+
#include <worklets/Tools/Defs.h>
|
|
4
|
+
#include <worklets/Tools/JSISerializer.h>
|
|
5
|
+
#include <worklets/Tools/JSLogger.h>
|
|
6
|
+
#include <worklets/Tools/WorkletsJSIUtils.h>
|
|
7
|
+
#include <worklets/WorkletRuntime/WorkletRuntime.h>
|
|
8
|
+
#include <worklets/WorkletRuntime/WorkletRuntimeCollector.h>
|
|
9
|
+
#include <worklets/WorkletRuntime/WorkletRuntimeDecorator.h>
|
|
10
|
+
|
|
11
|
+
#include <cxxreact/MessageQueueThread.h>
|
|
12
|
+
#include <jsi/decorator.h>
|
|
13
|
+
#include <jsi/jsi.h>
|
|
14
|
+
|
|
15
|
+
#include <memory>
|
|
16
|
+
#include <utility>
|
|
17
|
+
|
|
18
|
+
#if JS_RUNTIME_HERMES
|
|
19
|
+
#include <worklets/WorkletRuntime/WorkletHermesRuntime.h>
|
|
20
|
+
#else
|
|
21
|
+
#include <jsc/JSCRuntime.h>
|
|
22
|
+
#endif // JS_RUNTIME
|
|
23
|
+
|
|
24
|
+
namespace worklets {
|
|
25
|
+
|
|
26
|
+
class AroundLock {
|
|
27
|
+
const std::shared_ptr<std::recursive_mutex> mutex_;
|
|
28
|
+
|
|
29
|
+
public:
|
|
30
|
+
explicit AroundLock(const std::shared_ptr<std::recursive_mutex> &mutex)
|
|
31
|
+
: mutex_(mutex) {}
|
|
32
|
+
|
|
33
|
+
void before() const {
|
|
34
|
+
mutex_->lock();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
void after() const {
|
|
38
|
+
mutex_->unlock();
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
class LockableRuntime : public jsi::WithRuntimeDecorator<AroundLock> {
|
|
43
|
+
AroundLock aroundLock_;
|
|
44
|
+
std::shared_ptr<jsi::Runtime> runtime_;
|
|
45
|
+
|
|
46
|
+
public:
|
|
47
|
+
explicit LockableRuntime(
|
|
48
|
+
std::shared_ptr<jsi::Runtime> &runtime,
|
|
49
|
+
const std::shared_ptr<std::recursive_mutex> &runtimeMutex)
|
|
50
|
+
: jsi::WithRuntimeDecorator<AroundLock>(*runtime, aroundLock_),
|
|
51
|
+
aroundLock_(runtimeMutex),
|
|
52
|
+
runtime_(std::move(runtime)) {}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
static std::shared_ptr<jsi::Runtime> makeRuntime(
|
|
56
|
+
const std::shared_ptr<MessageQueueThread> &jsQueue,
|
|
57
|
+
const std::string &name,
|
|
58
|
+
const std::shared_ptr<std::recursive_mutex> &runtimeMutex) {
|
|
59
|
+
std::shared_ptr<jsi::Runtime> jsiRuntime;
|
|
60
|
+
#if JS_RUNTIME_HERMES
|
|
61
|
+
auto hermesRuntime = facebook::hermes::makeHermesRuntime();
|
|
62
|
+
jsiRuntime = std::make_shared<WorkletHermesRuntime>(
|
|
63
|
+
std::move(hermesRuntime), jsQueue, name);
|
|
64
|
+
#else
|
|
65
|
+
jsiRuntime = facebook::jsc::makeJSCRuntime();
|
|
66
|
+
#endif
|
|
67
|
+
|
|
68
|
+
return std::make_shared<LockableRuntime>(jsiRuntime, runtimeMutex);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
WorkletRuntime::WorkletRuntime(
|
|
72
|
+
uint64_t runtimeId,
|
|
73
|
+
const std::shared_ptr<MessageQueueThread> &jsQueue,
|
|
74
|
+
const std::string &name,
|
|
75
|
+
const std::shared_ptr<AsyncQueue> &queue,
|
|
76
|
+
bool enableEventLoop)
|
|
77
|
+
: runtimeId_(runtimeId),
|
|
78
|
+
runtimeMutex_(std::make_shared<std::recursive_mutex>()),
|
|
79
|
+
runtime_(makeRuntime(jsQueue, name, runtimeMutex_)),
|
|
80
|
+
name_(name),
|
|
81
|
+
queue_(queue) {
|
|
82
|
+
jsi::Runtime &rt = *runtime_;
|
|
83
|
+
WorkletRuntimeCollector::install(rt);
|
|
84
|
+
if (enableEventLoop && name != uiRuntimeName) {
|
|
85
|
+
eventLoop_ = std::make_shared<EventLoop>(name_, runtime_, queue_);
|
|
86
|
+
eventLoop_->run();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
void WorkletRuntime::init(
|
|
91
|
+
std::shared_ptr<JSIWorkletsModuleProxy> jsiWorkletsModuleProxy) {
|
|
92
|
+
jsi::Runtime &rt = *runtime_;
|
|
93
|
+
const auto jsScheduler = jsiWorkletsModuleProxy->getJSScheduler();
|
|
94
|
+
const auto isDevBundle = jsiWorkletsModuleProxy->isDevBundle();
|
|
95
|
+
#ifdef WORKLETS_BUNDLE_MODE
|
|
96
|
+
auto script = jsiWorkletsModuleProxy->getScript();
|
|
97
|
+
const auto &sourceUrl = jsiWorkletsModuleProxy->getSourceUrl();
|
|
98
|
+
#endif // WORKLETS_BUNDLE_MODE
|
|
99
|
+
|
|
100
|
+
auto optimizedJsiWorkletsModuleProxy =
|
|
101
|
+
jsi_utils::optimizedFromHostObject(rt, std::move(jsiWorkletsModuleProxy));
|
|
102
|
+
|
|
103
|
+
WorkletRuntimeDecorator::decorate(
|
|
104
|
+
rt,
|
|
105
|
+
name_,
|
|
106
|
+
jsScheduler,
|
|
107
|
+
isDevBundle,
|
|
108
|
+
std::move(optimizedJsiWorkletsModuleProxy),
|
|
109
|
+
eventLoop_);
|
|
110
|
+
|
|
111
|
+
#ifdef WORKLETS_BUNDLE_MODE
|
|
112
|
+
if (!script) {
|
|
113
|
+
throw std::runtime_error(
|
|
114
|
+
"[Worklets] Expected to receive the bundle, but got nullptr instead.");
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
try {
|
|
118
|
+
rt.evaluateJavaScript(script, sourceUrl);
|
|
119
|
+
} catch (facebook::jsi::JSError error) {
|
|
120
|
+
const auto &message = error.getMessage();
|
|
121
|
+
const auto &stack = error.getStack();
|
|
122
|
+
if (!message.starts_with("[Worklets] Worklets initialized successfully")) {
|
|
123
|
+
const auto newMessage =
|
|
124
|
+
"[Worklets] Failed to initialize runtime. Reason: " + message;
|
|
125
|
+
JSLogger::reportFatalErrorOnJS(
|
|
126
|
+
jsScheduler,
|
|
127
|
+
{.message = newMessage,
|
|
128
|
+
.stack = stack,
|
|
129
|
+
.name = "WorkletsError",
|
|
130
|
+
.jsEngine = "Worklets"});
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
#else
|
|
134
|
+
// Legacy behavior
|
|
135
|
+
auto valueUnpackerBuffer =
|
|
136
|
+
std::make_shared<const jsi::StringBuffer>(ValueUnpackerCode);
|
|
137
|
+
rt.evaluateJavaScript(valueUnpackerBuffer, "valueUnpacker");
|
|
138
|
+
|
|
139
|
+
auto synchronizableUnpackerBuffer =
|
|
140
|
+
std::make_shared<const jsi::StringBuffer>(SynchronizableUnpackerCode);
|
|
141
|
+
rt.evaluateJavaScript(synchronizableUnpackerBuffer, "synchronizableUnpacker");
|
|
142
|
+
#endif // WORKLETS_BUNDLE_MODE
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
void WorkletRuntime::runAsyncGuarded(
|
|
146
|
+
const std::shared_ptr<SerializableWorklet> &worklet) {
|
|
147
|
+
react_native_assert(
|
|
148
|
+
"[Worklets] Tried to invoke `runAsyncGuarded` on a Worklet Runtime but "
|
|
149
|
+
"the async queue is not set. Recreate the runtime with a valid async queue.");
|
|
150
|
+
|
|
151
|
+
queue_->push([worklet, weakThis = weak_from_this()] {
|
|
152
|
+
auto strongThis = weakThis.lock();
|
|
153
|
+
if (!strongThis) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
strongThis->runGuarded(worklet);
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
jsi::Value WorkletRuntime::executeSync(
|
|
162
|
+
jsi::Runtime &rt,
|
|
163
|
+
const jsi::Value &worklet) const {
|
|
164
|
+
auto serializableWorklet = extractSerializableOrThrow<SerializableWorklet>(
|
|
165
|
+
rt,
|
|
166
|
+
worklet,
|
|
167
|
+
"[Worklets] Only worklets can be executed synchronously on UI runtime.");
|
|
168
|
+
auto lock = std::unique_lock<std::recursive_mutex>(*runtimeMutex_);
|
|
169
|
+
jsi::Runtime &uiRuntime = getJSIRuntime();
|
|
170
|
+
auto result = runGuarded(serializableWorklet);
|
|
171
|
+
auto serializableResult = extractSerializableOrThrow(uiRuntime, result);
|
|
172
|
+
lock.unlock();
|
|
173
|
+
return serializableResult->toJSValue(rt);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
#ifdef WORKLETS_BUNDLE_MODE
|
|
177
|
+
jsi::Value WorkletRuntime::executeSync(
|
|
178
|
+
std::function<jsi::Value(jsi::Runtime &)> &&job) const {
|
|
179
|
+
auto lock = std::unique_lock<std::recursive_mutex>(*runtimeMutex_);
|
|
180
|
+
jsi::Runtime &uiRuntime = getJSIRuntime();
|
|
181
|
+
return job(uiRuntime);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
jsi::Value WorkletRuntime::executeSync(
|
|
185
|
+
const std::function<jsi::Value(jsi::Runtime &)> &job) const {
|
|
186
|
+
auto lock = std::unique_lock<std::recursive_mutex>(*runtimeMutex_);
|
|
187
|
+
jsi::Runtime &uiRuntime = getJSIRuntime();
|
|
188
|
+
return job(uiRuntime);
|
|
189
|
+
}
|
|
190
|
+
#endif // WORKLETS_BUNDLE_MODE
|
|
191
|
+
|
|
192
|
+
jsi::Value WorkletRuntime::get(
|
|
193
|
+
jsi::Runtime &rt,
|
|
194
|
+
const jsi::PropNameID &propName) {
|
|
195
|
+
auto name = propName.utf8(rt);
|
|
196
|
+
if (name == "toString") {
|
|
197
|
+
return jsi::Function::createFromHostFunction(
|
|
198
|
+
rt,
|
|
199
|
+
propName,
|
|
200
|
+
0,
|
|
201
|
+
[weakThis = weak_from_this()](
|
|
202
|
+
jsi::Runtime &rt, const jsi::Value &, const jsi::Value *, size_t)
|
|
203
|
+
-> jsi::Value {
|
|
204
|
+
auto strongThis = weakThis.lock();
|
|
205
|
+
if (!strongThis) {
|
|
206
|
+
return jsi::String::createFromUtf8(rt, "");
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
return jsi::String::createFromUtf8(rt, strongThis->toString());
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
if (name == "name") {
|
|
213
|
+
return jsi::String::createFromUtf8(rt, name_);
|
|
214
|
+
}
|
|
215
|
+
return jsi::Value::undefined();
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
std::vector<jsi::PropNameID> WorkletRuntime::getPropertyNames(
|
|
219
|
+
jsi::Runtime &rt) {
|
|
220
|
+
std::vector<jsi::PropNameID> result;
|
|
221
|
+
result.push_back(jsi::PropNameID::forUtf8(rt, "toString"));
|
|
222
|
+
result.push_back(jsi::PropNameID::forUtf8(rt, "name"));
|
|
223
|
+
return result;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
std::shared_ptr<WorkletRuntime> extractWorkletRuntime(
|
|
227
|
+
jsi::Runtime &rt,
|
|
228
|
+
const jsi::Value &value) {
|
|
229
|
+
return value.getObject(rt).getHostObject<WorkletRuntime>(rt);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
void scheduleOnRuntime(
|
|
233
|
+
jsi::Runtime &rt,
|
|
234
|
+
const jsi::Value &workletRuntimeValue,
|
|
235
|
+
const jsi::Value &serializableWorkletValue) {
|
|
236
|
+
auto workletRuntime = extractWorkletRuntime(rt, workletRuntimeValue);
|
|
237
|
+
auto serializableWorklet = extractSerializableOrThrow<SerializableWorklet>(
|
|
238
|
+
rt,
|
|
239
|
+
serializableWorkletValue,
|
|
240
|
+
"[Worklets] Function passed to `_scheduleOnRuntime` is not a serializable worklet.");
|
|
241
|
+
workletRuntime->runAsyncGuarded(serializableWorklet);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
} // namespace worklets
|