@depup/react-native-worklets 0.11.3-depup.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.worklets/dummy.md +1 -0
- package/Common/cpp/worklets/AnimationFrameQueue/AnimationFrameBatchinator.cpp +64 -0
- package/Common/cpp/worklets/AnimationFrameQueue/AnimationFrameBatchinator.h +38 -0
- package/Common/cpp/worklets/Compat/Holders.h +25 -0
- package/Common/cpp/worklets/Compat/StableApi.cpp +145 -0
- package/Common/cpp/worklets/Compat/StableApi.h +128 -0
- package/Common/cpp/worklets/NativeModules/JSIWorkletsModuleProxy.cpp +729 -0
- package/Common/cpp/worklets/NativeModules/JSIWorkletsModuleProxy.h +126 -0
- package/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.cpp +81 -0
- package/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.h +76 -0
- package/Common/cpp/worklets/Registries/EventHandlerRegistry.cpp +95 -0
- package/Common/cpp/worklets/Registries/EventHandlerRegistry.h +44 -0
- package/Common/cpp/worklets/Registries/WorkletRuntimeRegistry.cpp +10 -0
- package/Common/cpp/worklets/Registries/WorkletRuntimeRegistry.h +43 -0
- package/Common/cpp/worklets/RunLoop/AsyncQueue.h +14 -0
- package/Common/cpp/worklets/RunLoop/AsyncQueueImpl.cpp +69 -0
- package/Common/cpp/worklets/RunLoop/AsyncQueueImpl.h +48 -0
- package/Common/cpp/worklets/RunLoop/EventLoop.cpp +103 -0
- package/Common/cpp/worklets/RunLoop/EventLoop.h +52 -0
- package/Common/cpp/worklets/SharedItems/MemoryManager.cpp +60 -0
- package/Common/cpp/worklets/SharedItems/MemoryManager.h +29 -0
- package/Common/cpp/worklets/SharedItems/Serializable.cpp +373 -0
- package/Common/cpp/worklets/SharedItems/Serializable.h +413 -0
- package/Common/cpp/worklets/SharedItems/SerializableFactory.cpp +172 -0
- package/Common/cpp/worklets/SharedItems/SerializableFactory.h +85 -0
- package/Common/cpp/worklets/SharedItems/SerializableRemoteFunction.cpp +71 -0
- package/Common/cpp/worklets/SharedItems/SerializableRemoteFunction.h +75 -0
- package/Common/cpp/worklets/SharedItems/Shareable.cpp +84 -0
- package/Common/cpp/worklets/SharedItems/Shareable.h +43 -0
- package/Common/cpp/worklets/SharedItems/Synchronizable.cpp +59 -0
- package/Common/cpp/worklets/SharedItems/Synchronizable.h +57 -0
- package/Common/cpp/worklets/SharedItems/SynchronizableAccess.cpp +78 -0
- package/Common/cpp/worklets/SharedItems/SynchronizableAccess.h +45 -0
- package/Common/cpp/worklets/SharedItems/UnpackerLoader.h +78 -0
- package/Common/cpp/worklets/Tools/FeatureFlags.cpp +18 -0
- package/Common/cpp/worklets/Tools/FeatureFlags.h +44 -0
- package/Common/cpp/worklets/Tools/JSISerializer.cpp +312 -0
- package/Common/cpp/worklets/Tools/JSISerializer.h +42 -0
- package/Common/cpp/worklets/Tools/JSLogger.cpp +92 -0
- package/Common/cpp/worklets/Tools/JSLogger.h +48 -0
- package/Common/cpp/worklets/Tools/JSScheduler.cpp +21 -0
- package/Common/cpp/worklets/Tools/JSScheduler.h +35 -0
- package/Common/cpp/worklets/Tools/PlatformLogger.h +16 -0
- package/Common/cpp/worklets/Tools/RNRuntimeStatus.h +27 -0
- package/Common/cpp/worklets/Tools/ScriptBuffer.h +56 -0
- package/Common/cpp/worklets/Tools/SingleInstanceChecker.h +75 -0
- package/Common/cpp/worklets/Tools/ThreadSafeQueue.h +49 -0
- package/Common/cpp/worklets/Tools/UIScheduler.cpp +19 -0
- package/Common/cpp/worklets/Tools/UIScheduler.h +22 -0
- package/Common/cpp/worklets/Tools/VersionUtils.cpp +61 -0
- package/Common/cpp/worklets/Tools/VersionUtils.h +24 -0
- package/Common/cpp/worklets/Tools/WorkletEventHandler.cpp +34 -0
- package/Common/cpp/worklets/Tools/WorkletEventHandler.h +44 -0
- package/Common/cpp/worklets/Tools/WorkletsJSIUtils.cpp +30 -0
- package/Common/cpp/worklets/Tools/WorkletsJSIUtils.h +222 -0
- package/Common/cpp/worklets/Tools/WorkletsSystraceSection.h +116 -0
- package/Common/cpp/worklets/Tools/WorkletsVersion.cpp +46 -0
- package/Common/cpp/worklets/Tools/WorkletsVersion.h +18 -0
- package/Common/cpp/worklets/WorkletRuntime/BundleModeConfig.h +17 -0
- package/Common/cpp/worklets/WorkletRuntime/HermesProfiling.cpp +45 -0
- package/Common/cpp/worklets/WorkletRuntime/HermesProfiling.h +12 -0
- package/Common/cpp/worklets/WorkletRuntime/RNRuntimeWorkletDecorator.cpp +68 -0
- package/Common/cpp/worklets/WorkletRuntime/RNRuntimeWorkletDecorator.h +24 -0
- package/Common/cpp/worklets/WorkletRuntime/RuntimeBindings.h +59 -0
- package/Common/cpp/worklets/WorkletRuntime/RuntimeData.h +38 -0
- package/Common/cpp/worklets/WorkletRuntime/RuntimeHolder.h +19 -0
- package/Common/cpp/worklets/WorkletRuntime/RuntimeManager.cpp +122 -0
- package/Common/cpp/worklets/WorkletRuntime/RuntimeManager.h +75 -0
- package/Common/cpp/worklets/WorkletRuntime/ScriptLoader.h +116 -0
- package/Common/cpp/worklets/WorkletRuntime/UIRuntimeDecorator.cpp +14 -0
- package/Common/cpp/worklets/WorkletRuntime/UIRuntimeDecorator.h +15 -0
- package/Common/cpp/worklets/WorkletRuntime/WorkletHermesRuntime.cpp +58 -0
- package/Common/cpp/worklets/WorkletRuntime/WorkletHermesRuntime.h +100 -0
- package/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.cpp +327 -0
- package/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.h +256 -0
- package/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeCollector.h +36 -0
- package/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.cpp +320 -0
- package/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.h +36 -0
- package/LICENSE +20 -0
- package/README.md +43 -0
- package/RNWorklets.podspec +94 -0
- package/android/CMakeLists.txt +108 -0
- package/android/build.gradle.kts +369 -0
- package/android/fix-prefab.gradle.kts +56 -0
- package/android/generate-stub-pch.gradle.kts +84 -0
- package/android/gradle.properties +25 -0
- package/android/proguard-rules.pro +3 -0
- package/android/settings.gradle.kts +21 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/cpp/WorkletsPCH.h +26 -0
- package/android/src/main/cpp/worklets/android/AndroidUIScheduler.cpp +66 -0
- package/android/src/main/cpp/worklets/android/AndroidUIScheduler.h +38 -0
- package/android/src/main/cpp/worklets/android/AnimationFrameCallback.h +30 -0
- package/android/src/main/cpp/worklets/android/JScriptBufferWrapper.cpp +66 -0
- package/android/src/main/cpp/worklets/android/JScriptBufferWrapper.h +48 -0
- package/android/src/main/cpp/worklets/android/JWorkletRuntimeWrapper.cpp +51 -0
- package/android/src/main/cpp/worklets/android/JWorkletRuntimeWrapper.h +43 -0
- package/android/src/main/cpp/worklets/android/PlatformLogger.cpp +31 -0
- package/android/src/main/cpp/worklets/android/WorkletsModule.cpp +203 -0
- package/android/src/main/cpp/worklets/android/WorkletsModule.h +75 -0
- package/android/src/main/cpp/worklets/android/WorkletsOnLoad.cpp +19 -0
- package/android/src/main/java/com/swmansion/worklets/AndroidUIScheduler.kt +56 -0
- package/android/src/main/java/com/swmansion/worklets/ScriptBufferWrapper.kt +103 -0
- package/android/src/main/java/com/swmansion/worklets/WorkletsPackage.kt +42 -0
- package/android/src/main/java/com/swmansion/worklets/runloop/AnimationFrameCallback.kt +14 -0
- package/android/src/main/java/com/swmansion/worklets/runloop/AnimationFrameQueue.kt +112 -0
- package/android/src/networking/com/swmansion/worklets/WorkletRuntimeWrapper.kt +27 -0
- package/android/src/networking/com/swmansion/worklets/WorkletsHeaderUtil.kt +30 -0
- package/android/src/networking/com/swmansion/worklets/WorkletsModule.kt +187 -0
- package/android/src/networking/com/swmansion/worklets/WorkletsNetworkEventUtil.kt +272 -0
- package/android/src/networking/com/swmansion/worklets/WorkletsNetworking.kt +1124 -0
- package/android/src/networking/com/swmansion/worklets/WorkletsOkHttpCallUtil.kt +40 -0
- package/android/src/networking/com/swmansion/worklets/WorkletsProgressListener.kt +13 -0
- package/android/src/networking/com/swmansion/worklets/WorkletsProgressRequestBody.kt +98 -0
- package/android/src/networking/com/swmansion/worklets/WorkletsProgressResponseBody.kt +60 -0
- package/android/src/networking/com/swmansion/worklets/WorkletsProgressiveStringDecoder.kt +87 -0
- package/android/src/networking/com/swmansion/worklets/WorkletsRequestBodyUtil.kt +181 -0
- package/android/src/no-networking/com/swmansion/worklets/WorkletsModule.kt +143 -0
- package/apple/worklets/apple/AnimationFrameQueue.h +15 -0
- package/apple/worklets/apple/AnimationFrameQueue.mm +145 -0
- package/apple/worklets/apple/AssertJavaScriptQueue.h +14 -0
- package/apple/worklets/apple/AssertTurboModuleManagerQueue.h +12 -0
- package/apple/worklets/apple/IOSUIScheduler.h +14 -0
- package/apple/worklets/apple/IOSUIScheduler.mm +29 -0
- package/apple/worklets/apple/Networking/WorkletsNetworking.h +25 -0
- package/apple/worklets/apple/Networking/WorkletsNetworking.mm +707 -0
- package/apple/worklets/apple/PlatformLogger.mm +31 -0
- package/apple/worklets/apple/SlowAnimations.h +8 -0
- package/apple/worklets/apple/SlowAnimations.mm +45 -0
- package/apple/worklets/apple/WorkletsDisplayLink.h +21 -0
- package/apple/worklets/apple/WorkletsModule.h +28 -0
- package/apple/worklets/apple/WorkletsModule.mm +177 -0
- package/bundleMode/index.d.ts +6 -0
- package/bundleMode/index.js +182 -0
- package/bundleMode/shims/reactNativeShim.js +21 -0
- package/bundleMode/shims/turboModuleRegistryShim.js +47 -0
- package/changes.json +58 -0
- package/compatibility.json +29 -0
- package/jest/pluginTestUtils.ts +16 -0
- package/jest/resolver.js +18 -0
- package/lib/module/WorkletsModule/NativeWorklets.js +4 -0
- package/lib/module/WorkletsModule/NativeWorklets.js.map +1 -0
- package/lib/module/WorkletsModule/NativeWorklets.native.js +199 -0
- package/lib/module/WorkletsModule/NativeWorklets.native.js.map +1 -0
- package/lib/module/WorkletsModule/workletsModuleProxy.js +4 -0
- package/lib/module/WorkletsModule/workletsModuleProxy.js.map +1 -0
- package/lib/module/bundleMode/metroOverrides.native.js +26 -0
- package/lib/module/bundleMode/metroOverrides.native.js.map +1 -0
- package/lib/module/bundleMode/network.native.js +44 -0
- package/lib/module/bundleMode/network.native.js.map +1 -0
- package/lib/module/debug/bundleMode.js +6 -0
- package/lib/module/debug/bundleMode.js.map +1 -0
- package/lib/module/debug/bundleMode.native.js +11 -0
- package/lib/module/debug/bundleMode.native.js.map +1 -0
- package/lib/module/debug/checkCppVersion.js +29 -0
- package/lib/module/debug/checkCppVersion.js.map +1 -0
- package/lib/module/debug/errors.native.js +67 -0
- package/lib/module/debug/errors.native.js.map +1 -0
- package/lib/module/debug/jsVersion.js +9 -0
- package/lib/module/debug/jsVersion.js.map +1 -0
- package/lib/module/debug/logger.js +15 -0
- package/lib/module/debug/logger.js.map +1 -0
- package/lib/module/debug/slowAnimations.js +7 -0
- package/lib/module/debug/slowAnimations.js.map +1 -0
- package/lib/module/debug/slowAnimations.native.js +17 -0
- package/lib/module/debug/slowAnimations.native.js.map +1 -0
- package/lib/module/deprecated.js +27 -0
- package/lib/module/deprecated.js.map +1 -0
- package/lib/module/featureFlags/featureFlags.js +12 -0
- package/lib/module/featureFlags/featureFlags.js.map +1 -0
- package/lib/module/featureFlags/featureFlags.native.js +51 -0
- package/lib/module/featureFlags/featureFlags.native.js.map +1 -0
- package/lib/module/featureFlags/staticFlags.json +6 -0
- package/lib/module/featureFlags/types.js +16 -0
- package/lib/module/featureFlags/types.js.map +1 -0
- package/lib/module/guardImplementation.native.js +17 -0
- package/lib/module/guardImplementation.native.js.map +1 -0
- package/lib/module/index.js +26 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/initializers/initializers.js +24 -0
- package/lib/module/initializers/initializers.js.map +1 -0
- package/lib/module/initializers/initializers.native.js +195 -0
- package/lib/module/initializers/initializers.native.js.map +1 -0
- package/lib/module/memory/bundleUnpacker.native.js +38 -0
- package/lib/module/memory/bundleUnpacker.native.js.map +1 -0
- package/lib/module/memory/customSerializableUnpacker.native.js +20 -0
- package/lib/module/memory/customSerializableUnpacker.native.js.map +1 -0
- package/lib/module/memory/isShareable.js +8 -0
- package/lib/module/memory/isShareable.js.map +1 -0
- package/lib/module/memory/isSynchronizable.js +8 -0
- package/lib/module/memory/isSynchronizable.js.map +1 -0
- package/lib/module/memory/remoteFunctionUnpacker.native.js +18 -0
- package/lib/module/memory/remoteFunctionUnpacker.native.js.map +1 -0
- package/lib/module/memory/serializable.js +18 -0
- package/lib/module/memory/serializable.js.map +1 -0
- package/lib/module/memory/serializable.native.js +619 -0
- package/lib/module/memory/serializable.native.js.map +1 -0
- package/lib/module/memory/serializableMappingCache.js +11 -0
- package/lib/module/memory/serializableMappingCache.js.map +1 -0
- package/lib/module/memory/serializableMappingCache.native.js +29 -0
- package/lib/module/memory/serializableMappingCache.native.js.map +1 -0
- package/lib/module/memory/shareable.js +18 -0
- package/lib/module/memory/shareable.js.map +1 -0
- package/lib/module/memory/shareable.native.js +42 -0
- package/lib/module/memory/shareable.native.js.map +1 -0
- package/lib/module/memory/shareableGuestUnpacker.native.js +105 -0
- package/lib/module/memory/shareableGuestUnpacker.native.js.map +1 -0
- package/lib/module/memory/shareableHostUnpacker.native.js +20 -0
- package/lib/module/memory/shareableHostUnpacker.native.js.map +1 -0
- package/lib/module/memory/synchronizable.js +6 -0
- package/lib/module/memory/synchronizable.js.map +1 -0
- package/lib/module/memory/synchronizable.native.js +9 -0
- package/lib/module/memory/synchronizable.native.js.map +1 -0
- package/lib/module/memory/synchronizableUnpacker.native.js +47 -0
- package/lib/module/memory/synchronizableUnpacker.native.js.map +1 -0
- package/lib/module/memory/types.js +12 -0
- package/lib/module/memory/types.js.map +1 -0
- package/lib/module/memory/valueUnpacker.native.js +52 -0
- package/lib/module/memory/valueUnpacker.native.js.map +1 -0
- package/lib/module/mock.js +85 -0
- package/lib/module/mock.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/platformChecker.js +4 -0
- package/lib/module/platformChecker.js.map +1 -0
- package/lib/module/platformChecker.native.js +4 -0
- package/lib/module/platformChecker.native.js.map +1 -0
- package/lib/module/privateGlobals.d.js +7 -0
- package/lib/module/privateGlobals.d.js.map +1 -0
- package/lib/module/runLoop/common/setImmediatePolyfill.js +15 -0
- package/lib/module/runLoop/common/setImmediatePolyfill.js.map +1 -0
- package/lib/module/runLoop/common/setIntervalPolyfill.js +26 -0
- package/lib/module/runLoop/common/setIntervalPolyfill.js.map +1 -0
- package/lib/module/runLoop/uiRuntime/mockedRequestAnimationFrame.js +10 -0
- package/lib/module/runLoop/uiRuntime/mockedRequestAnimationFrame.js.map +1 -0
- package/lib/module/runLoop/uiRuntime/requestAnimationFrame.js +71 -0
- package/lib/module/runLoop/uiRuntime/requestAnimationFrame.js.map +1 -0
- package/lib/module/runLoop/uiRuntime/setTimeoutPolyfill.js +32 -0
- package/lib/module/runLoop/uiRuntime/setTimeoutPolyfill.js.map +1 -0
- package/lib/module/runLoop/workletRuntime/index.js +19 -0
- package/lib/module/runLoop/workletRuntime/index.js.map +1 -0
- package/lib/module/runLoop/workletRuntime/queueMicrotask.js +11 -0
- package/lib/module/runLoop/workletRuntime/queueMicrotask.js.map +1 -0
- package/lib/module/runLoop/workletRuntime/requestAnimationFramePolyfill.js +48 -0
- package/lib/module/runLoop/workletRuntime/requestAnimationFramePolyfill.js.map +1 -0
- package/lib/module/runLoop/workletRuntime/setTimeout.js +28 -0
- package/lib/module/runLoop/workletRuntime/setTimeout.js.map +1 -0
- package/lib/module/runLoop/workletRuntime/taskQueue.js +37 -0
- package/lib/module/runLoop/workletRuntime/taskQueue.js.map +1 -0
- package/lib/module/runtimeKind.js +92 -0
- package/lib/module/runtimeKind.js.map +1 -0
- package/lib/module/runtimes.js +36 -0
- package/lib/module/runtimes.js.map +1 -0
- package/lib/module/runtimes.native.js +379 -0
- package/lib/module/runtimes.native.js.map +1 -0
- package/lib/module/specs/NativeWorkletsModule.js +5 -0
- package/lib/module/specs/NativeWorkletsModule.js.map +1 -0
- package/lib/module/specs/index.js +10 -0
- package/lib/module/specs/index.js.map +1 -0
- package/lib/module/threads.js +60 -0
- package/lib/module/threads.js.map +1 -0
- package/lib/module/threads.native.js +295 -0
- package/lib/module/threads.native.js.map +1 -0
- package/lib/module/types.js +5 -0
- package/lib/module/types.js.map +1 -0
- package/lib/module/workletFunction.js +36 -0
- package/lib/module/workletFunction.js.map +1 -0
- package/lib/typescript/WorkletsModule/NativeWorklets.d.ts +3 -0
- package/lib/typescript/WorkletsModule/NativeWorklets.d.ts.map +1 -0
- package/lib/typescript/WorkletsModule/NativeWorklets.native.d.ts +3 -0
- package/lib/typescript/WorkletsModule/NativeWorklets.native.d.ts.map +1 -0
- package/lib/typescript/WorkletsModule/workletsModuleProxy.d.ts +59 -0
- package/lib/typescript/WorkletsModule/workletsModuleProxy.d.ts.map +1 -0
- package/lib/typescript/bundleMode/metroOverrides.native.d.ts +9 -0
- package/lib/typescript/bundleMode/metroOverrides.native.d.ts.map +1 -0
- package/lib/typescript/bundleMode/network.native.d.ts +7 -0
- package/lib/typescript/bundleMode/network.native.d.ts.map +1 -0
- package/lib/typescript/debug/bundleMode.d.ts +2 -0
- package/lib/typescript/debug/bundleMode.d.ts.map +1 -0
- package/lib/typescript/debug/bundleMode.native.d.ts +2 -0
- package/lib/typescript/debug/bundleMode.native.d.ts.map +1 -0
- package/lib/typescript/debug/checkCppVersion.d.ts +3 -0
- package/lib/typescript/debug/checkCppVersion.d.ts.map +1 -0
- package/lib/typescript/debug/errors.native.d.ts +13 -0
- package/lib/typescript/debug/errors.native.d.ts.map +1 -0
- package/lib/typescript/debug/jsVersion.d.ts +7 -0
- package/lib/typescript/debug/jsVersion.d.ts.map +1 -0
- package/lib/typescript/debug/logger.d.ts +5 -0
- package/lib/typescript/debug/logger.d.ts.map +1 -0
- package/lib/typescript/debug/slowAnimations.d.ts +2 -0
- package/lib/typescript/debug/slowAnimations.d.ts.map +1 -0
- package/lib/typescript/debug/slowAnimations.native.d.ts +11 -0
- package/lib/typescript/debug/slowAnimations.native.d.ts.map +1 -0
- package/lib/typescript/deprecated.d.ts +19 -0
- package/lib/typescript/deprecated.d.ts.map +1 -0
- package/lib/typescript/featureFlags/featureFlags.d.ts +5 -0
- package/lib/typescript/featureFlags/featureFlags.d.ts.map +1 -0
- package/lib/typescript/featureFlags/featureFlags.native.d.ts +6 -0
- package/lib/typescript/featureFlags/featureFlags.native.d.ts.map +1 -0
- package/lib/typescript/featureFlags/types.d.ts +23 -0
- package/lib/typescript/featureFlags/types.d.ts.map +1 -0
- package/lib/typescript/guardImplementation.native.d.ts +3 -0
- package/lib/typescript/guardImplementation.native.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +19 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/initializers/initializers.d.ts +2 -0
- package/lib/typescript/initializers/initializers.d.ts.map +1 -0
- package/lib/typescript/initializers/initializers.native.d.ts +19 -0
- package/lib/typescript/initializers/initializers.native.d.ts.map +1 -0
- package/lib/typescript/memory/bundleUnpacker.native.d.ts +7 -0
- package/lib/typescript/memory/bundleUnpacker.native.d.ts.map +1 -0
- package/lib/typescript/memory/customSerializableUnpacker.native.d.ts +3 -0
- package/lib/typescript/memory/customSerializableUnpacker.native.d.ts.map +1 -0
- package/lib/typescript/memory/isShareable.d.ts +3 -0
- package/lib/typescript/memory/isShareable.d.ts.map +1 -0
- package/lib/typescript/memory/isSynchronizable.d.ts +3 -0
- package/lib/typescript/memory/isSynchronizable.d.ts.map +1 -0
- package/lib/typescript/memory/remoteFunctionUnpacker.native.d.ts +3 -0
- package/lib/typescript/memory/remoteFunctionUnpacker.native.d.ts.map +1 -0
- package/lib/typescript/memory/serializable.d.ts +7 -0
- package/lib/typescript/memory/serializable.d.ts.map +1 -0
- package/lib/typescript/memory/serializable.native.d.ts +37 -0
- package/lib/typescript/memory/serializable.native.d.ts.map +1 -0
- package/lib/typescript/memory/serializableMappingCache.d.ts +6 -0
- package/lib/typescript/memory/serializableMappingCache.d.ts.map +1 -0
- package/lib/typescript/memory/serializableMappingCache.native.d.ts +13 -0
- package/lib/typescript/memory/serializableMappingCache.native.d.ts.map +1 -0
- package/lib/typescript/memory/shareable.d.ts +15 -0
- package/lib/typescript/memory/shareable.d.ts.map +1 -0
- package/lib/typescript/memory/shareable.native.d.ts +15 -0
- package/lib/typescript/memory/shareable.native.d.ts.map +1 -0
- package/lib/typescript/memory/shareableGuestUnpacker.native.d.ts +4 -0
- package/lib/typescript/memory/shareableGuestUnpacker.native.d.ts.map +1 -0
- package/lib/typescript/memory/shareableHostUnpacker.native.d.ts +4 -0
- package/lib/typescript/memory/shareableHostUnpacker.native.d.ts.map +1 -0
- package/lib/typescript/memory/synchronizable.d.ts +3 -0
- package/lib/typescript/memory/synchronizable.d.ts.map +1 -0
- package/lib/typescript/memory/synchronizable.native.d.ts +3 -0
- package/lib/typescript/memory/synchronizable.native.d.ts.map +1 -0
- package/lib/typescript/memory/synchronizableUnpacker.native.d.ts +4 -0
- package/lib/typescript/memory/synchronizableUnpacker.native.d.ts.map +1 -0
- package/lib/typescript/memory/types.d.ts +136 -0
- package/lib/typescript/memory/types.d.ts.map +1 -0
- package/lib/typescript/memory/valueUnpacker.native.d.ts +7 -0
- package/lib/typescript/memory/valueUnpacker.native.d.ts.map +1 -0
- package/lib/typescript/mock.d.ts +2 -0
- package/lib/typescript/mock.d.ts.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/platformChecker.d.ts +2 -0
- package/lib/typescript/platformChecker.d.ts.map +1 -0
- package/lib/typescript/platformChecker.native.d.ts +2 -0
- package/lib/typescript/platformChecker.native.d.ts.map +1 -0
- package/lib/typescript/runLoop/common/setImmediatePolyfill.d.ts +2 -0
- package/lib/typescript/runLoop/common/setImmediatePolyfill.d.ts.map +1 -0
- package/lib/typescript/runLoop/common/setIntervalPolyfill.d.ts +2 -0
- package/lib/typescript/runLoop/common/setIntervalPolyfill.d.ts.map +1 -0
- package/lib/typescript/runLoop/uiRuntime/mockedRequestAnimationFrame.d.ts +6 -0
- package/lib/typescript/runLoop/uiRuntime/mockedRequestAnimationFrame.d.ts.map +1 -0
- package/lib/typescript/runLoop/uiRuntime/requestAnimationFrame.d.ts +2 -0
- package/lib/typescript/runLoop/uiRuntime/requestAnimationFrame.d.ts.map +1 -0
- package/lib/typescript/runLoop/uiRuntime/setTimeoutPolyfill.d.ts +2 -0
- package/lib/typescript/runLoop/uiRuntime/setTimeoutPolyfill.d.ts.map +1 -0
- package/lib/typescript/runLoop/workletRuntime/index.d.ts +2 -0
- package/lib/typescript/runLoop/workletRuntime/index.d.ts.map +1 -0
- package/lib/typescript/runLoop/workletRuntime/queueMicrotask.d.ts +2 -0
- package/lib/typescript/runLoop/workletRuntime/queueMicrotask.d.ts.map +1 -0
- package/lib/typescript/runLoop/workletRuntime/requestAnimationFramePolyfill.d.ts +2 -0
- package/lib/typescript/runLoop/workletRuntime/requestAnimationFramePolyfill.d.ts.map +1 -0
- package/lib/typescript/runLoop/workletRuntime/setTimeout.d.ts +2 -0
- package/lib/typescript/runLoop/workletRuntime/setTimeout.d.ts.map +1 -0
- package/lib/typescript/runLoop/workletRuntime/taskQueue.d.ts +10 -0
- package/lib/typescript/runLoop/workletRuntime/taskQueue.d.ts.map +1 -0
- package/lib/typescript/runtimeKind.d.ts +56 -0
- package/lib/typescript/runtimeKind.d.ts.map +1 -0
- package/lib/typescript/runtimes.d.ts +15 -0
- package/lib/typescript/runtimes.d.ts.map +1 -0
- package/lib/typescript/runtimes.native.d.ts +155 -0
- package/lib/typescript/runtimes.native.d.ts.map +1 -0
- package/lib/typescript/specs/NativeWorkletsModule.d.ts +9 -0
- package/lib/typescript/specs/NativeWorkletsModule.d.ts.map +1 -0
- package/lib/typescript/specs/index.d.ts +3 -0
- package/lib/typescript/specs/index.d.ts.map +1 -0
- package/lib/typescript/threads.d.ts +8 -0
- package/lib/typescript/threads.d.ts.map +1 -0
- package/lib/typescript/threads.native.d.ts +125 -0
- package/lib/typescript/threads.native.d.ts.map +1 -0
- package/lib/typescript/types.d.ts +136 -0
- package/lib/typescript/types.d.ts.map +1 -0
- package/lib/typescript/workletFunction.d.ts +26 -0
- package/lib/typescript/workletFunction.d.ts.map +1 -0
- package/package.json +220 -0
- package/plugin/index.d.ts +168 -0
- package/plugin/index.js +2188 -0
- package/scripts/validate-react-native-version.js +43 -0
- package/scripts/worklets_utils.rb +94 -0
- package/src/WorkletsModule/NativeWorklets.native.ts +461 -0
- package/src/WorkletsModule/NativeWorklets.ts +5 -0
- package/src/WorkletsModule/workletsModuleProxy.ts +247 -0
- package/src/bundleMode/metroOverrides.native.ts +33 -0
- package/src/bundleMode/network.native.ts +63 -0
- package/src/debug/bundleMode.native.ts +18 -0
- package/src/debug/bundleMode.ts +5 -0
- package/src/debug/checkCppVersion.ts +34 -0
- package/src/debug/errors.native.ts +74 -0
- package/src/debug/jsVersion.ts +8 -0
- package/src/debug/logger.ts +16 -0
- package/src/debug/slowAnimations.native.ts +15 -0
- package/src/debug/slowAnimations.ts +6 -0
- package/src/deprecated.ts +38 -0
- package/src/featureFlags/featureFlags.native.ts +70 -0
- package/src/featureFlags/featureFlags.ts +20 -0
- package/src/featureFlags/staticFlags.json +6 -0
- package/src/featureFlags/types.ts +32 -0
- package/src/guardImplementation.native.ts +26 -0
- package/src/index.ts +95 -0
- package/src/initializers/initializers.native.ts +218 -0
- package/src/initializers/initializers.ts +24 -0
- package/src/memory/bundleUnpacker.native.ts +59 -0
- package/src/memory/customSerializableUnpacker.native.ts +30 -0
- package/src/memory/isShareable.ts +16 -0
- package/src/memory/isSynchronizable.ts +14 -0
- package/src/memory/remoteFunctionUnpacker.native.ts +27 -0
- package/src/memory/serializable.native.ts +889 -0
- package/src/memory/serializable.ts +36 -0
- package/src/memory/serializableMappingCache.native.ts +37 -0
- package/src/memory/serializableMappingCache.ts +12 -0
- package/src/memory/shareable.native.ts +68 -0
- package/src/memory/shareable.ts +27 -0
- package/src/memory/shareableGuestUnpacker.native.ts +168 -0
- package/src/memory/shareableHostUnpacker.native.ts +31 -0
- package/src/memory/synchronizable.native.ts +17 -0
- package/src/memory/synchronizable.ts +9 -0
- package/src/memory/synchronizableUnpacker.native.ts +65 -0
- package/src/memory/types.ts +191 -0
- package/src/memory/valueUnpacker.native.ts +79 -0
- package/src/mock.ts +111 -0
- package/src/platformChecker.native.ts +3 -0
- package/src/platformChecker.ts +4 -0
- package/src/privateGlobals.d.ts +127 -0
- package/src/runLoop/common/setImmediatePolyfill.ts +20 -0
- package/src/runLoop/common/setIntervalPolyfill.ts +38 -0
- package/src/runLoop/uiRuntime/mockedRequestAnimationFrame.ts +11 -0
- package/src/runLoop/uiRuntime/requestAnimationFrame.ts +87 -0
- package/src/runLoop/uiRuntime/setTimeoutPolyfill.ts +40 -0
- package/src/runLoop/workletRuntime/index.ts +18 -0
- package/src/runLoop/workletRuntime/queueMicrotask.ts +13 -0
- package/src/runLoop/workletRuntime/requestAnimationFramePolyfill.ts +61 -0
- package/src/runLoop/workletRuntime/setTimeout.ts +37 -0
- package/src/runLoop/workletRuntime/taskQueue.ts +44 -0
- package/src/runtimeKind.ts +85 -0
- package/src/runtimes.native.ts +572 -0
- package/src/runtimes.ts +107 -0
- package/src/specs/NativeWorkletsModule.ts +11 -0
- package/src/specs/index.ts +13 -0
- package/src/threads.native.ts +408 -0
- package/src/threads.ts +110 -0
- package/src/types.ts +164 -0
- package/src/workletFunction.ts +41 -0
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <jsi/jsi.h>
|
|
4
|
+
#include <worklets/Tools/ScriptBuffer.h>
|
|
5
|
+
|
|
6
|
+
#include <memory>
|
|
7
|
+
#include <string>
|
|
8
|
+
#include <utility>
|
|
9
|
+
|
|
10
|
+
namespace worklets {
|
|
11
|
+
|
|
12
|
+
class ScriptLoader {
|
|
13
|
+
|
|
14
|
+
public:
|
|
15
|
+
/**
|
|
16
|
+
* Safely loads the bundle into the Worklet Runtime and executes Worklets' entry point.
|
|
17
|
+
*/
|
|
18
|
+
static void loadScript(
|
|
19
|
+
facebook::jsi::Runtime &rt,
|
|
20
|
+
const std::shared_ptr<const ScriptBuffer> &script,
|
|
21
|
+
const std::string &sourceUrl) {
|
|
22
|
+
ScriptLoader loader{};
|
|
23
|
+
loader.interceptEntryPoints(rt);
|
|
24
|
+
rt.evaluateJavaScript(script, sourceUrl);
|
|
25
|
+
loader.allowEntryPoints(rt);
|
|
26
|
+
loader.loadWorkletsEntryPoint(rt);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
private:
|
|
30
|
+
/**
|
|
31
|
+
* Sets the `require` function on the global object with a noop getter
|
|
32
|
+
* and a setter that saves the actual implementation of `require` for later use.
|
|
33
|
+
*
|
|
34
|
+
* This is necessary to prevent running the App and React Native entry-points when evaluating the bundle.
|
|
35
|
+
*/
|
|
36
|
+
void interceptEntryPoints(facebook::jsi::Runtime &rt) {
|
|
37
|
+
facebook::jsi::Object descriptor(rt);
|
|
38
|
+
descriptor.setProperty(rt, "configurable", true);
|
|
39
|
+
descriptor.setProperty(rt, "enumerable", false);
|
|
40
|
+
descriptor.setProperty(
|
|
41
|
+
rt,
|
|
42
|
+
"get",
|
|
43
|
+
facebook::jsi::Function::createFromHostFunction(
|
|
44
|
+
rt,
|
|
45
|
+
facebook::jsi::PropNameID::forUtf8(rt, "get"),
|
|
46
|
+
0,
|
|
47
|
+
[](facebook::jsi::Runtime &rt, const facebook::jsi::Value &, const facebook::jsi::Value *, size_t)
|
|
48
|
+
-> facebook::jsi::Value {
|
|
49
|
+
return facebook::jsi::Function::createFromHostFunction(
|
|
50
|
+
rt,
|
|
51
|
+
facebook::jsi::PropNameID::forUtf8(rt, "noop"),
|
|
52
|
+
0,
|
|
53
|
+
[](facebook::jsi::Runtime &, const facebook::jsi::Value &, const facebook::jsi::Value *, size_t)
|
|
54
|
+
-> facebook::jsi::Value { return facebook::jsi::Value::undefined(); });
|
|
55
|
+
}));
|
|
56
|
+
descriptor.setProperty(
|
|
57
|
+
rt,
|
|
58
|
+
"set",
|
|
59
|
+
facebook::jsi::Function::createFromHostFunction(
|
|
60
|
+
rt,
|
|
61
|
+
facebook::jsi::PropNameID::forUtf8(rt, "set"),
|
|
62
|
+
1,
|
|
63
|
+
[&](facebook::jsi::Runtime &rt,
|
|
64
|
+
const facebook::jsi::Value &,
|
|
65
|
+
const facebook::jsi::Value *args,
|
|
66
|
+
size_t count) -> facebook::jsi::Value {
|
|
67
|
+
metroRequire_ = jsi::Value(rt, args[0]);
|
|
68
|
+
return facebook::jsi::Value::undefined();
|
|
69
|
+
}));
|
|
70
|
+
|
|
71
|
+
const auto globalObj = rt.global();
|
|
72
|
+
const auto objectCtor = globalObj.getPropertyAsObject(rt, "Object");
|
|
73
|
+
const auto defineProperty = objectCtor.getPropertyAsFunction(rt, "defineProperty");
|
|
74
|
+
defineProperty.call(
|
|
75
|
+
rt,
|
|
76
|
+
facebook::jsi::Value(rt, globalObj),
|
|
77
|
+
facebook::jsi::String::createFromUtf8(rt, kRequireName_),
|
|
78
|
+
std::move(descriptor));
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Restores the original `require` function on the global object after evaluating the bundle.
|
|
83
|
+
* This way we can use worklets as entry points.
|
|
84
|
+
*/
|
|
85
|
+
void allowEntryPoints(facebook::jsi::Runtime &rt) {
|
|
86
|
+
facebook::jsi::Object descriptor(rt);
|
|
87
|
+
|
|
88
|
+
descriptor.setProperty(rt, "configurable", true);
|
|
89
|
+
descriptor.setProperty(rt, "enumerable", false);
|
|
90
|
+
descriptor.setProperty(rt, "writable", true);
|
|
91
|
+
descriptor.setProperty(rt, "value", std::move(metroRequire_));
|
|
92
|
+
|
|
93
|
+
const auto globalObj = rt.global();
|
|
94
|
+
const auto objectCtor = globalObj.getPropertyAsObject(rt, "Object");
|
|
95
|
+
const auto defineProperty = objectCtor.getPropertyAsFunction(rt, "defineProperty");
|
|
96
|
+
defineProperty.call(
|
|
97
|
+
rt,
|
|
98
|
+
facebook::jsi::Value(rt, globalObj),
|
|
99
|
+
facebook::jsi::String::createFromUtf8(rt, kRequireName_),
|
|
100
|
+
std::move(descriptor));
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
void loadWorkletsEntryPoint(facebook::jsi::Runtime &rt) {
|
|
104
|
+
const auto require = rt.global().getProperty(rt, kRequireName_).getObject(rt).getFunction(rt);
|
|
105
|
+
require.call(rt, kWorkletsEntryPointId_);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
ScriptLoader() = default;
|
|
109
|
+
|
|
110
|
+
jsi::Value metroRequire_{};
|
|
111
|
+
|
|
112
|
+
static constexpr auto kRequireName_ = "__r";
|
|
113
|
+
static constexpr auto kWorkletsEntryPointId_ = -2;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
} // namespace worklets
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#include <worklets/Compat/StableApi.h>
|
|
2
|
+
#include <worklets/WorkletRuntime/RuntimeData.h>
|
|
3
|
+
#include <worklets/WorkletRuntime/UIRuntimeDecorator.h>
|
|
4
|
+
|
|
5
|
+
namespace worklets {
|
|
6
|
+
|
|
7
|
+
void UIRuntimeDecorator::decorate(
|
|
8
|
+
facebook::jsi::Runtime &uiRuntime,
|
|
9
|
+
const std::function<void(facebook::jsi::Runtime &rt, const facebook::jsi::Value &callback)>
|
|
10
|
+
&requestAnimationFrame) {
|
|
11
|
+
installRequestAnimationFrame(uiRuntime, requestAnimationFrame);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
} // namespace worklets
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
const std::function<void(facebook::jsi::Runtime &rt, const facebook::jsi::Value &callback)>
|
|
12
|
+
&requestAnimationFrame);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
} // namespace worklets
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
#include <worklets/Tools/ScriptBuffer.h>
|
|
2
|
+
#include <worklets/WorkletRuntime/WorkletHermesRuntime.h>
|
|
3
|
+
|
|
4
|
+
#include <jsi/jsi.h>
|
|
5
|
+
|
|
6
|
+
#include <cstdint>
|
|
7
|
+
#include <memory>
|
|
8
|
+
#include <string>
|
|
9
|
+
#include <utility>
|
|
10
|
+
#include <vector>
|
|
11
|
+
|
|
12
|
+
namespace worklets {
|
|
13
|
+
|
|
14
|
+
WorkletHermesRuntime::WorkletHermesRuntime(std::unique_ptr<facebook::hermes::HermesRuntime> runtime)
|
|
15
|
+
: jsi::WithRuntimeDecorator<WorkletsReentrancyCheck>(*runtime, reentrancyCheck_), runtime_(std::move(runtime)) {
|
|
16
|
+
auto evalBytecode = [](facebook::jsi::Runtime &rt,
|
|
17
|
+
const facebook::jsi::Value &,
|
|
18
|
+
const facebook::jsi::Value *args,
|
|
19
|
+
size_t) -> facebook::jsi::Value {
|
|
20
|
+
const auto buffer = args[0].getObject(rt).getArrayBuffer(rt);
|
|
21
|
+
auto data = std::vector<uint8_t>(buffer.data(rt), buffer.data(rt) + buffer.size(rt));
|
|
22
|
+
return rt.evaluateJavaScript(std::make_shared<BytecodeBuffer>(data), "");
|
|
23
|
+
};
|
|
24
|
+
runtime_->global().setProperty(
|
|
25
|
+
*runtime_,
|
|
26
|
+
"evalBytecode",
|
|
27
|
+
facebook::jsi::Function::createFromHostFunction(
|
|
28
|
+
*runtime_, facebook::jsi::PropNameID::forAscii(*runtime_, "evalBytecode"), 1, evalBytecode));
|
|
29
|
+
|
|
30
|
+
#ifndef NDEBUG
|
|
31
|
+
facebook::hermes::HermesRuntime *wrappedRuntime = runtime_.get();
|
|
32
|
+
jsi::Value evalWithSourceMap = jsi::Function::createFromHostFunction(
|
|
33
|
+
*runtime_,
|
|
34
|
+
jsi::PropNameID::forAscii(*runtime_, "evalWithSourceMap"),
|
|
35
|
+
3,
|
|
36
|
+
[wrappedRuntime](
|
|
37
|
+
jsi::Runtime &rt, const jsi::Value &thisValue, const jsi::Value *args, size_t count) -> jsi::Value {
|
|
38
|
+
auto code = std::make_shared<const jsi::StringBuffer>(args[0].asString(rt).utf8(rt));
|
|
39
|
+
std::string sourceURL;
|
|
40
|
+
if (count > 1 && args[1].isString()) {
|
|
41
|
+
sourceURL = args[1].getString(rt).utf8(rt);
|
|
42
|
+
}
|
|
43
|
+
std::shared_ptr<const jsi::Buffer> sourceMap;
|
|
44
|
+
if (count > 2 && args[2].isString()) {
|
|
45
|
+
auto sourceMapString = args[2].getString(rt).utf8(rt);
|
|
46
|
+
if (!sourceMapString.empty()) {
|
|
47
|
+
sourceMap = std::make_shared<const jsi::StringBuffer>(std::move(sourceMapString));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return wrappedRuntime->evaluateJavaScriptWithSourceMap(code, sourceMap, sourceURL);
|
|
51
|
+
});
|
|
52
|
+
runtime_->global().setProperty(*runtime_, "evalWithSourceMap", evalWithSourceMap);
|
|
53
|
+
#endif // NDEBUG
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
WorkletHermesRuntime::~WorkletHermesRuntime() = default;
|
|
57
|
+
|
|
58
|
+
} // namespace worklets
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <hermes/hermes.h>
|
|
4
|
+
#include <jsi/decorator.h>
|
|
5
|
+
#include <jsi/jsi.h>
|
|
6
|
+
#include <react/debug/react_native_assert.h>
|
|
7
|
+
|
|
8
|
+
#include <atomic>
|
|
9
|
+
#include <memory>
|
|
10
|
+
#include <thread>
|
|
11
|
+
|
|
12
|
+
namespace worklets {
|
|
13
|
+
|
|
14
|
+
using namespace facebook;
|
|
15
|
+
|
|
16
|
+
// ReentrancyCheck is copied from React Native
|
|
17
|
+
// from ReactCommon/hermes/executor/HermesExecutorFactory.cpp
|
|
18
|
+
// https://github.com/facebook/react-native/blob/main/packages/react-native/ReactCommon/hermes/executor/HermesExecutorFactory.cpp
|
|
19
|
+
struct WorkletsReentrancyCheck {
|
|
20
|
+
// This is effectively a very subtle and complex assert, so only
|
|
21
|
+
// include it in builds which would include asserts.
|
|
22
|
+
#ifndef NDEBUG
|
|
23
|
+
WorkletsReentrancyCheck() : tid(std::thread::id()), depth(0) {}
|
|
24
|
+
|
|
25
|
+
void before() {
|
|
26
|
+
std::thread::id this_id = std::this_thread::get_id();
|
|
27
|
+
std::thread::id expected = std::thread::id();
|
|
28
|
+
|
|
29
|
+
// A note on memory ordering: the main purpose of these checks is
|
|
30
|
+
// to observe a before/before race, without an intervening after.
|
|
31
|
+
// This will be detected by the compare_exchange_strong atomicity
|
|
32
|
+
// properties, regardless of memory order.
|
|
33
|
+
//
|
|
34
|
+
// For everything else, it is easiest to think of 'depth' as a
|
|
35
|
+
// proxy for any access made inside the VM. If access to depth
|
|
36
|
+
// are reordered incorrectly, the same could be true of any other
|
|
37
|
+
// operation made by the VM. In fact, using acquire/release
|
|
38
|
+
// memory ordering could create barriers which mask a programmer
|
|
39
|
+
// error. So, we use relaxed memory order, to avoid masking
|
|
40
|
+
// actual ordering errors. Although, in practice, ordering errors
|
|
41
|
+
// of this sort would be surprising, because the decorator would
|
|
42
|
+
// need to call after() without before().
|
|
43
|
+
|
|
44
|
+
if (tid.compare_exchange_strong(expected, this_id, std::memory_order_relaxed)) {
|
|
45
|
+
// Returns true if tid and expected were the same. If they
|
|
46
|
+
// were, then the stored tid referred to no thread, and we
|
|
47
|
+
// atomically saved this thread's tid. Now increment depth.
|
|
48
|
+
react_native_assert(depth == 0 && "[Worklets] No thread id, but depth != 0");
|
|
49
|
+
++depth;
|
|
50
|
+
} else if (expected == this_id) {
|
|
51
|
+
// If the stored tid referred to a thread, expected was set to
|
|
52
|
+
// that value. If that value is this thread's tid, that's ok,
|
|
53
|
+
// just increment depth again.
|
|
54
|
+
react_native_assert(depth != 0 && "[Worklets] Thread id was set, but depth == 0");
|
|
55
|
+
++depth;
|
|
56
|
+
} else {
|
|
57
|
+
// The stored tid was some other thread. This indicates a bad
|
|
58
|
+
// programmer error, where VM methods were called on two
|
|
59
|
+
// different threads unsafely. Fail fast (and hard) so the
|
|
60
|
+
// crash can be analyzed.
|
|
61
|
+
__builtin_trap();
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
void after() {
|
|
66
|
+
react_native_assert(
|
|
67
|
+
tid.load(std::memory_order_relaxed) == std::this_thread::get_id() && "[Worklets] No thread id in after()");
|
|
68
|
+
if (--depth == 0) {
|
|
69
|
+
// If we decremented depth to zero, store no-thread into tid.
|
|
70
|
+
std::thread::id expected = std::this_thread::get_id();
|
|
71
|
+
bool didWrite = tid.compare_exchange_strong(expected, std::thread::id(), std::memory_order_relaxed);
|
|
72
|
+
react_native_assert(didWrite && "[Worklets] Decremented to zero, but no tid write");
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
std::atomic<std::thread::id> tid;
|
|
77
|
+
// This is not atomic, as it is only written or read from the owning
|
|
78
|
+
// thread.
|
|
79
|
+
unsigned int depth;
|
|
80
|
+
#endif // NDEBUG
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
// This is in fact a subclass of jsi::Runtime! WithRuntimeDecorator is a
|
|
84
|
+
// template class that is a subclass of DecoratedRuntime which is also a
|
|
85
|
+
// template class that then inherits its template, which in this case is
|
|
86
|
+
// jsi::Runtime. So the inheritance is: WorkletHermesRuntime ->
|
|
87
|
+
// WithRuntimeDecorator -> DecoratedRuntime -> jsi::Runtime You can find out
|
|
88
|
+
// more about this in ReactCommon/jsi/jsi/Decorator.h or by following this link:
|
|
89
|
+
// https://github.com/facebook/react-native/blob/main/packages/react-native/ReactCommon/jsi/jsi/decorator.h
|
|
90
|
+
class WorkletHermesRuntime : public jsi::WithRuntimeDecorator<WorkletsReentrancyCheck> {
|
|
91
|
+
public:
|
|
92
|
+
explicit WorkletHermesRuntime(std::unique_ptr<facebook::hermes::HermesRuntime> runtime);
|
|
93
|
+
~WorkletHermesRuntime() override;
|
|
94
|
+
|
|
95
|
+
private:
|
|
96
|
+
std::unique_ptr<facebook::hermes::HermesRuntime> runtime_;
|
|
97
|
+
WorkletsReentrancyCheck reentrancyCheck_;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
} // namespace worklets
|
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
#include <jsi/decorator.h>
|
|
2
|
+
#include <jsi/jsi.h>
|
|
3
|
+
#include <worklets/NativeModules/JSIWorkletsModuleProxy.h>
|
|
4
|
+
#include <worklets/Tools/JSLogger.h>
|
|
5
|
+
#include <worklets/Tools/WorkletsJSIUtils.h>
|
|
6
|
+
#include <worklets/WorkletRuntime/RuntimeHolder.h>
|
|
7
|
+
#include <worklets/WorkletRuntime/ScriptLoader.h>
|
|
8
|
+
#include <worklets/WorkletRuntime/WorkletHermesRuntime.h>
|
|
9
|
+
#include <worklets/WorkletRuntime/WorkletRuntime.h>
|
|
10
|
+
#include <worklets/WorkletRuntime/WorkletRuntimeCollector.h>
|
|
11
|
+
#include <worklets/WorkletRuntime/WorkletRuntimeDecorator.h>
|
|
12
|
+
|
|
13
|
+
#include <memory>
|
|
14
|
+
#include <stdexcept>
|
|
15
|
+
#include <string>
|
|
16
|
+
#include <utility>
|
|
17
|
+
#include <vector>
|
|
18
|
+
|
|
19
|
+
namespace worklets {
|
|
20
|
+
|
|
21
|
+
class AroundLock {
|
|
22
|
+
const std::shared_ptr<std::recursive_mutex> mutex_;
|
|
23
|
+
|
|
24
|
+
public:
|
|
25
|
+
explicit AroundLock(const std::shared_ptr<std::recursive_mutex> &mutex) : mutex_(mutex) {}
|
|
26
|
+
|
|
27
|
+
void before() const {
|
|
28
|
+
mutex_->lock();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
void after() const {
|
|
32
|
+
mutex_->unlock();
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
class LockableRuntime : public jsi::WithRuntimeDecorator<AroundLock> {
|
|
37
|
+
AroundLock aroundLock_;
|
|
38
|
+
std::shared_ptr<jsi::Runtime> runtime_;
|
|
39
|
+
|
|
40
|
+
public:
|
|
41
|
+
explicit LockableRuntime(
|
|
42
|
+
std::shared_ptr<jsi::Runtime> &runtime,
|
|
43
|
+
const std::shared_ptr<std::recursive_mutex> &runtimeMutex)
|
|
44
|
+
: jsi::WithRuntimeDecorator<AroundLock>(*runtime, aroundLock_),
|
|
45
|
+
aroundLock_(runtimeMutex),
|
|
46
|
+
runtime_(std::move(runtime)) {}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
static std::shared_ptr<jsi::Runtime> makeRuntime(const std::shared_ptr<std::recursive_mutex> &runtimeMutex) {
|
|
50
|
+
auto hermesRuntime = facebook::hermes::makeHermesRuntime();
|
|
51
|
+
std::shared_ptr<jsi::Runtime> jsiRuntime = std::make_shared<WorkletHermesRuntime>(std::move(hermesRuntime));
|
|
52
|
+
return std::make_shared<LockableRuntime>(jsiRuntime, runtimeMutex);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
WorkletRuntime::WorkletRuntime(
|
|
56
|
+
uint64_t runtimeId,
|
|
57
|
+
const RuntimeData::RuntimeKind runtimeKind,
|
|
58
|
+
const std::string &name,
|
|
59
|
+
const std::shared_ptr<AsyncQueue> &queue,
|
|
60
|
+
bool enableEventLoop)
|
|
61
|
+
: runtimeId_(runtimeId),
|
|
62
|
+
runtimeMutex_(std::make_shared<std::recursive_mutex>()),
|
|
63
|
+
runtime_(makeRuntime(runtimeMutex_)),
|
|
64
|
+
runtimeKind_(runtimeKind),
|
|
65
|
+
name_(name),
|
|
66
|
+
queue_(queue) {
|
|
67
|
+
jsi::Runtime &rt = *runtime_;
|
|
68
|
+
WorkletRuntimeCollector::install(rt);
|
|
69
|
+
if (enableEventLoop) {
|
|
70
|
+
eventLoop_ = std::make_shared<EventLoop>(name_, runtime_, queue_);
|
|
71
|
+
eventLoop_->run();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
void WorkletRuntime::init(const std::shared_ptr<JSIWorkletsModuleProxy> &jsiWorkletsModuleProxy) {
|
|
76
|
+
jsi::Runtime &rt = *runtime_;
|
|
77
|
+
|
|
78
|
+
rt.setRuntimeData(
|
|
79
|
+
RuntimeData::weakRuntimeUUID,
|
|
80
|
+
std::make_shared<WeakRuntimeHolder>(WeakRuntimeHolder{.weakRuntime = weak_from_this()}));
|
|
81
|
+
|
|
82
|
+
const auto jsScheduler = jsiWorkletsModuleProxy->getJSScheduler();
|
|
83
|
+
jsScheduler_ = jsScheduler;
|
|
84
|
+
const auto isDevBundle = jsiWorkletsModuleProxy->isDevBundle();
|
|
85
|
+
const auto memoryManager_ = jsiWorkletsModuleProxy->getMemoryManager();
|
|
86
|
+
const auto script = jsiWorkletsModuleProxy->getScript();
|
|
87
|
+
const auto &sourceUrl = jsiWorkletsModuleProxy->getSourceUrl();
|
|
88
|
+
const auto runtimeBindings = jsiWorkletsModuleProxy->getRuntimeBindings();
|
|
89
|
+
const auto bundleModeEnabled = jsiWorkletsModuleProxy->isBundleModeEnabled();
|
|
90
|
+
const auto unpackerLoader = jsiWorkletsModuleProxy->getUnpackerLoader();
|
|
91
|
+
const auto &nativeLoggingHook = runtimeBindings->nativeLoggingHook;
|
|
92
|
+
|
|
93
|
+
WorkletRuntimeDecorator::decorate(
|
|
94
|
+
rt,
|
|
95
|
+
runtimeKind_,
|
|
96
|
+
name_,
|
|
97
|
+
jsScheduler,
|
|
98
|
+
isDevBundle,
|
|
99
|
+
jsiWorkletsModuleProxy->toOptimizedObject(rt),
|
|
100
|
+
eventLoop_,
|
|
101
|
+
nativeLoggingHook);
|
|
102
|
+
|
|
103
|
+
if (bundleModeEnabled) {
|
|
104
|
+
bundleModeInit(jsScheduler, script, sourceUrl, runtimeBindings);
|
|
105
|
+
} else {
|
|
106
|
+
legacyModeInit(unpackerLoader);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
try {
|
|
110
|
+
memoryManager_->loadAllCustomSerializables(shared_from_this());
|
|
111
|
+
} catch (jsi::JSError &e) {
|
|
112
|
+
throw std::runtime_error(std::string("[Worklets] Failed to load custom serializables. Reason: ") + e.getMessage());
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
void WorkletRuntime::bundleModeInit(
|
|
117
|
+
const std::shared_ptr<JSScheduler> &jsScheduler,
|
|
118
|
+
const std::shared_ptr<const ScriptBuffer> &script,
|
|
119
|
+
const std::string &sourceUrl,
|
|
120
|
+
const std::shared_ptr<RuntimeBindings> &runtimeBindings) {
|
|
121
|
+
jsi::Runtime &rt = *runtime_;
|
|
122
|
+
|
|
123
|
+
if (!script) {
|
|
124
|
+
throw std::runtime_error("[Worklets] Expected to receive the bundle, but got nullptr instead.");
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
ScriptLoader::loadScript(rt, script, sourceUrl);
|
|
128
|
+
|
|
129
|
+
WorkletRuntimeDecorator::postEvaluateScript(rt, runtimeBindings);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
void WorkletRuntime::legacyModeInit(const std::shared_ptr<UnpackerLoader> &unpackerLoader) {
|
|
133
|
+
unpackerLoader->installUnpackers(*runtime_);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/* #region schedule */
|
|
137
|
+
|
|
138
|
+
void WorkletRuntime::schedule(jsi::Function &&function) const {
|
|
139
|
+
react_native_assert(
|
|
140
|
+
queue_ &&
|
|
141
|
+
"[Worklets] Tried to invoke `schedule` on a Worklet Runtime but the "
|
|
142
|
+
"async queue is not set. Recreate the runtime with a valid async queue.");
|
|
143
|
+
queue_->push([function = std::make_shared<jsi::Function>(std::move(function)), weakThis = weak_from_this()]() {
|
|
144
|
+
auto strongThis = weakThis.lock();
|
|
145
|
+
if (!strongThis) {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
strongThis->runSync(*function);
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
void WorkletRuntime::schedule(std::shared_ptr<SerializableWorklet> worklet) const {
|
|
154
|
+
react_native_assert(
|
|
155
|
+
queue_ &&
|
|
156
|
+
"[Worklets] Tried to invoke `schedule` on a Worklet Runtime but the "
|
|
157
|
+
"async queue is not set. Recreate the runtime with a valid async queue.");
|
|
158
|
+
|
|
159
|
+
queue_->push([worklet = std::move(worklet), weakThis = weak_from_this()] {
|
|
160
|
+
auto strongThis = weakThis.lock();
|
|
161
|
+
if (!strongThis) {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
strongThis->runSync(worklet);
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
#ifndef NDEBUG
|
|
170
|
+
void WorkletRuntime::schedule(std::shared_ptr<SerializableWorklet> worklet, std::optional<std::string> scheduleStack)
|
|
171
|
+
const {
|
|
172
|
+
react_native_assert(
|
|
173
|
+
queue_ &&
|
|
174
|
+
"[Worklets] Tried to invoke `schedule` on a Worklet Runtime but the "
|
|
175
|
+
"async queue is not set. Recreate the runtime with a valid async queue.");
|
|
176
|
+
|
|
177
|
+
queue_->push([worklet = std::move(worklet), scheduleStack = std::move(scheduleStack), weakThis = weak_from_this()] {
|
|
178
|
+
auto strongThis = weakThis.lock();
|
|
179
|
+
if (!strongThis) {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
strongThis->runSyncWithStack(worklet, scheduleStack);
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
#endif // NDEBUG
|
|
187
|
+
|
|
188
|
+
void WorkletRuntime::callMicrotasks() const {
|
|
189
|
+
runSync([](jsi::Runtime &rt) {
|
|
190
|
+
auto callMicrotasks = rt.global().getProperty(rt, "__callMicrotasks");
|
|
191
|
+
if (callMicrotasks.isObject()) {
|
|
192
|
+
auto callMicrotasksObject = callMicrotasks.asObject(rt);
|
|
193
|
+
if (callMicrotasksObject.isFunction(rt)) {
|
|
194
|
+
callMicrotasksObject.asFunction(rt).call(rt);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
void WorkletRuntime::schedule(std::function<void()> job) const {
|
|
201
|
+
react_native_assert(
|
|
202
|
+
queue_ &&
|
|
203
|
+
"[Worklets] Tried to invoke `schedule` on a Worklet Runtime but the "
|
|
204
|
+
"async queue is not set. Recreate the runtime with a valid async queue.");
|
|
205
|
+
|
|
206
|
+
queue_->push(std::move(job));
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
void WorkletRuntime::schedule(std::function<void(jsi::Runtime &)> job) const {
|
|
210
|
+
react_native_assert(
|
|
211
|
+
queue_ &&
|
|
212
|
+
"[Worklets] Tried to invoke `schedule` on a Worklet Runtime but the "
|
|
213
|
+
"async queue is not set. Recreate the runtime with a valid async queue.");
|
|
214
|
+
|
|
215
|
+
queue_->push([job = std::move(job), weakThis = weak_from_this()]() {
|
|
216
|
+
auto strongThis = weakThis.lock();
|
|
217
|
+
if (!strongThis) {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
auto lock = std::unique_lock<std::recursive_mutex>(*strongThis->runtimeMutex_);
|
|
222
|
+
jsi::Runtime &runtime = strongThis->getJSIRuntime();
|
|
223
|
+
job(runtime);
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/* #endregion */
|
|
228
|
+
|
|
229
|
+
jsi::Value WorkletRuntime::get(jsi::Runtime &rt, const jsi::PropNameID &propName) {
|
|
230
|
+
auto name = propName.utf8(rt);
|
|
231
|
+
if (name == "toString") {
|
|
232
|
+
return jsi::Function::createFromHostFunction(
|
|
233
|
+
rt,
|
|
234
|
+
propName,
|
|
235
|
+
0,
|
|
236
|
+
[weakThis = weak_from_this()](jsi::Runtime &rt, const jsi::Value &, const jsi::Value *, size_t) -> jsi::Value {
|
|
237
|
+
auto strongThis = weakThis.lock();
|
|
238
|
+
if (!strongThis) {
|
|
239
|
+
return jsi::String::createFromUtf8(rt, "");
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
return jsi::String::createFromUtf8(rt, strongThis->toString());
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
if (name == "name") {
|
|
246
|
+
return jsi::String::createFromUtf8(rt, name_);
|
|
247
|
+
}
|
|
248
|
+
if (name == "runtimeId") {
|
|
249
|
+
return jsi::Value(static_cast<double>(runtimeId_));
|
|
250
|
+
}
|
|
251
|
+
return jsi::Value::undefined();
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
std::vector<jsi::PropNameID> WorkletRuntime::getPropertyNames(jsi::Runtime &rt) {
|
|
255
|
+
std::vector<jsi::PropNameID> result;
|
|
256
|
+
result.push_back(jsi::PropNameID::forUtf8(rt, "toString"));
|
|
257
|
+
result.push_back(jsi::PropNameID::forUtf8(rt, "name"));
|
|
258
|
+
result.push_back(jsi::PropNameID::forUtf8(rt, "runtimeId"));
|
|
259
|
+
return result;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
std::shared_ptr<WorkletRuntime> extractWorkletRuntime(jsi::Runtime &rt, const jsi::Value &value) {
|
|
263
|
+
return value.getObject(rt).getHostObject<WorkletRuntime>(rt);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
void scheduleOnRuntime(
|
|
267
|
+
jsi::Runtime &rt,
|
|
268
|
+
const jsi::Value &workletRuntimeValue,
|
|
269
|
+
const jsi::Value &serializableWorkletValue) {
|
|
270
|
+
auto workletRuntime = extractWorkletRuntime(rt, workletRuntimeValue);
|
|
271
|
+
auto serializableWorklet = extractSerializableOrThrow<SerializableWorklet>(
|
|
272
|
+
rt,
|
|
273
|
+
serializableWorkletValue,
|
|
274
|
+
"[Worklets] Function passed to `_scheduleOnRuntime` is not a serializable worklet.");
|
|
275
|
+
workletRuntime->schedule(serializableWorklet);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
#ifndef NDEBUG
|
|
279
|
+
void scheduleOnRuntime(
|
|
280
|
+
jsi::Runtime &rt,
|
|
281
|
+
const jsi::Value &workletRuntimeValue,
|
|
282
|
+
const jsi::Value &serializableWorkletValue,
|
|
283
|
+
const std::optional<std::string> &scheduleStack) {
|
|
284
|
+
auto workletRuntime = extractWorkletRuntime(rt, workletRuntimeValue);
|
|
285
|
+
auto serializableWorklet = extractSerializableOrThrow<SerializableWorklet>(
|
|
286
|
+
rt,
|
|
287
|
+
serializableWorkletValue,
|
|
288
|
+
"[Worklets] Function passed to `_scheduleOnRuntime` is not a serializable worklet.");
|
|
289
|
+
workletRuntime->schedule(serializableWorklet, scheduleStack);
|
|
290
|
+
}
|
|
291
|
+
#endif // NDEBUG
|
|
292
|
+
|
|
293
|
+
std::weak_ptr<WorkletRuntime> WorkletRuntime::getWeakRuntimeFromJSIRuntime(jsi::Runtime &rt) {
|
|
294
|
+
auto runtimeData = rt.getRuntimeData(RuntimeData::weakRuntimeUUID);
|
|
295
|
+
if (!runtimeData) [[unlikely]] {
|
|
296
|
+
throw std::runtime_error(
|
|
297
|
+
"[Worklets] No weak runtime data found on the provided JSI runtime."
|
|
298
|
+
" Perhaps the JSI Runtime is not a WorkletRuntime?");
|
|
299
|
+
}
|
|
300
|
+
auto weakHolder = std::static_pointer_cast<WeakRuntimeHolder>(runtimeData);
|
|
301
|
+
return weakHolder->weakRuntime;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/* #region deprecated */
|
|
305
|
+
|
|
306
|
+
void WorkletRuntime::runAsyncGuarded(const std::shared_ptr<SerializableWorklet> &worklet) {
|
|
307
|
+
schedule(worklet);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
jsi::Value WorkletRuntime::executeSync(jsi::Runtime &caller, const jsi::Value &worklet) const {
|
|
311
|
+
auto serializableWorklet = extractSerializableOrThrow<SerializableWorklet>(
|
|
312
|
+
caller, worklet, "[Worklets] Only worklets can be executed synchronously on UI runtime.");
|
|
313
|
+
auto result = runSyncSerialized(serializableWorklet);
|
|
314
|
+
return result->toJSValue(caller);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
jsi::Value WorkletRuntime::executeSync(std::function<jsi::Value(jsi::Runtime &)> &&job) const {
|
|
318
|
+
return runSync(job);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
jsi::Value WorkletRuntime::executeSync(const std::function<jsi::Value(jsi::Runtime &)> &job) const {
|
|
322
|
+
return runSync(job);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/* #endregion */
|
|
326
|
+
|
|
327
|
+
} // namespace worklets
|