@depup/react-native-worklets 0.12.1-depup.0 → 0.13.0-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/Common/cpp/worklets/AnimationFrameQueue/AnimationFrameBatchinator.cpp +1 -2
- package/Common/cpp/worklets/AnimationFrameQueue/AnimationFrameBatchinator.h +1 -1
- package/Common/cpp/worklets/Compat/StableApi.cpp +24 -8
- package/Common/cpp/worklets/Compat/StableApi.h +1 -1
- package/Common/cpp/worklets/NativeModules/JSIWorkletsModuleProxy.cpp +113 -50
- package/Common/cpp/worklets/NativeModules/JSIWorkletsModuleProxy.h +10 -1
- package/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.cpp +95 -37
- package/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.h +57 -7
- package/Common/cpp/worklets/NativeModules/WorkletsModuleProxyInitializer.cpp +94 -0
- package/Common/cpp/worklets/NativeModules/WorkletsModuleProxyInitializer.h +58 -0
- package/Common/cpp/worklets/Networking/Networking.cpp +283 -0
- package/Common/cpp/worklets/Networking/Networking.h +51 -0
- package/Common/cpp/worklets/Networking/NetworkingBackend.h +47 -0
- package/Common/cpp/worklets/Networking/NetworkingInstaller.cpp +127 -0
- package/Common/cpp/worklets/Networking/NetworkingInstaller.h +19 -0
- package/Common/cpp/worklets/Networking/NetworkingTypes.h +33 -0
- package/Common/cpp/worklets/Networking/TextDecoding.cpp +189 -0
- package/Common/cpp/worklets/Networking/TextDecoding.h +29 -0
- package/Common/cpp/worklets/RunLoop/AsyncQueue.h +28 -0
- package/Common/cpp/worklets/RunLoop/AsyncQueueImpl.cpp +9 -0
- package/Common/cpp/worklets/RunLoop/AsyncQueueImpl.h +6 -0
- package/Common/cpp/worklets/RunLoop/EventLoop.cpp +19 -4
- package/Common/cpp/worklets/RunLoop/EventLoop.h +3 -0
- package/Common/cpp/worklets/SharedItems/MemoryManager.cpp +1 -1
- package/Common/cpp/worklets/SharedItems/MemoryManager.h +2 -1
- package/Common/cpp/worklets/SharedItems/Serializable/CustomSerializable.cpp +37 -0
- package/Common/cpp/worklets/SharedItems/Serializable/CustomSerializable.h +33 -0
- package/Common/cpp/worklets/SharedItems/Serializable/RetainingSerializable.h +112 -0
- package/Common/cpp/worklets/SharedItems/Serializable/Serializable.cpp +129 -0
- package/Common/cpp/worklets/SharedItems/Serializable/Serializable.h +121 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableArray.cpp +38 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableArray.h +39 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableArrayBuffer.cpp +35 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableArrayBuffer.h +43 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableBigInt.cpp +23 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableBigInt.h +35 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableError.cpp +38 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableError.h +30 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableHostFunction.cpp +24 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableHostFunction.h +32 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableHostObject.cpp +19 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableHostObject.h +25 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableImport.cpp +29 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableImport.h +25 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableMap.cpp +44 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableMap.h +25 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableObject.cpp +80 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableObject.h +35 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableRegExp.cpp +22 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableRegExp.h +25 -0
- package/Common/cpp/worklets/SharedItems/{SerializableRemoteFunction.cpp → Serializable/SerializableRemoteFunction.cpp} +30 -2
- package/Common/cpp/worklets/SharedItems/{SerializableRemoteFunction.h → Serializable/SerializableRemoteFunction.h} +24 -10
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableScalar.cpp +46 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableScalar.h +41 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableSet.cpp +36 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableSet.h +23 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableString.cpp +19 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableString.h +22 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableTurboModuleLike.cpp +26 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableTurboModuleLike.h +33 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableWorklet.cpp +31 -0
- package/Common/cpp/worklets/SharedItems/Serializable/SerializableWorklet.h +23 -0
- package/Common/cpp/worklets/SharedItems/Serializable.h +21 -409
- package/Common/cpp/worklets/SharedItems/Shareable.cpp +1 -1
- package/Common/cpp/worklets/SharedItems/Shareable.h +1 -1
- package/Common/cpp/worklets/SharedItems/Synchronizable.h +43 -20
- package/Common/cpp/worklets/SharedItems/SynchronizableAccess.cpp +24 -26
- package/Common/cpp/worklets/SharedItems/SynchronizableAccess.h +5 -7
- package/Common/cpp/worklets/SharedItems/SynchronizableDynamic.cpp +36 -0
- package/Common/cpp/worklets/SharedItems/SynchronizableDynamic.h +27 -0
- package/Common/cpp/worklets/SharedItems/SynchronizableFixed.cpp +76 -0
- package/Common/cpp/worklets/SharedItems/SynchronizableFixed.h +48 -0
- package/Common/cpp/worklets/Tools/ScriptBuffer.h +0 -5
- package/Common/cpp/worklets/Tools/WorkletsJSIUtils.h +16 -30
- package/Common/cpp/worklets/WorkletRuntime/RuntimeBindings.h +27 -30
- package/Common/cpp/worklets/WorkletRuntime/RuntimeManager.cpp +4 -3
- package/Common/cpp/worklets/WorkletRuntime/RuntimeManager.h +2 -1
- package/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.cpp +79 -29
- package/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.h +34 -19
- package/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.cpp +13 -86
- package/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.h +1 -7
- package/Package.swift +147 -0
- package/README.md +7 -7
- package/RNWorklets.podspec +1 -2
- package/android/CMakeLists.txt +7 -26
- package/android/build.gradle.kts +5 -31
- package/android/src/main/cpp/worklets/android/WorkletsModule.cpp +46 -129
- package/android/src/main/cpp/worklets/android/WorkletsModule.h +21 -11
- package/android/src/main/cpp/worklets/android/WorkletsOnLoad.cpp +2 -4
- package/android/src/main/cpp/worklets/android/networking/AndroidNetworkingBackend.cpp +82 -0
- package/android/src/main/cpp/worklets/android/networking/AndroidNetworkingBackend.h +32 -0
- package/android/src/main/cpp/worklets/android/networking/JNetworkRequestListener.cpp +73 -0
- package/android/src/main/cpp/worklets/android/networking/JNetworkRequestListener.h +38 -0
- package/android/src/{no-networking → main/java}/com/swmansion/worklets/WorkletsModule.kt +40 -28
- package/android/src/main/java/com/swmansion/worklets/networking/NetworkRequestListener.kt +37 -0
- package/android/src/main/java/com/swmansion/worklets/networking/Networking.kt +244 -0
- package/android/src/main/java/com/swmansion/worklets/runloop/AnimationFrameQueue.kt +40 -5
- package/apple/worklets/apple/AnimationFrameQueue.mm +9 -1
- package/apple/worklets/apple/AssertJavaScriptQueue.h +3 -2
- package/apple/worklets/apple/AssertTurboModuleManagerQueue.h +4 -0
- package/apple/worklets/apple/IOSUIScheduler.mm +3 -0
- package/apple/worklets/apple/Networking/AppleNetworkingBackend.h +29 -0
- package/apple/worklets/apple/Networking/AppleNetworkingBackend.mm +93 -0
- package/apple/worklets/apple/Networking/WorkletsURLSessionDelegate.h +37 -0
- package/apple/worklets/apple/Networking/WorkletsURLSessionDelegate.mm +447 -0
- package/apple/worklets/apple/WorkletsModule.h +3 -2
- package/apple/worklets/apple/WorkletsModule.mm +82 -74
- package/bundleMode/index.js +10 -47
- package/bundleMode/polyfills/prepareBundleMode.js +16 -0
- package/changes.json +6 -6
- package/compatibility.json +4 -1
- package/lib/module/WorkletsModule/NativeWorklets.native.js +12 -9
- package/lib/module/WorkletsModule/NativeWorklets.native.js.map +1 -1
- package/lib/module/debug/jsVersion.js +1 -1
- package/lib/module/featureFlags/staticFlags.json +0 -1
- package/lib/module/featureFlags/types.js +0 -1
- package/lib/module/featureFlags/types.js.map +1 -1
- package/lib/module/index.js +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/initializers/initializers.native.js +5 -12
- package/lib/module/initializers/initializers.native.js.map +1 -1
- package/lib/module/memory/bundleUnpacker.native.js +2 -10
- package/lib/module/memory/bundleUnpacker.native.js.map +1 -1
- package/lib/module/memory/serializable.native.js +3 -31
- package/lib/module/memory/serializable.native.js.map +1 -1
- package/lib/module/memory/synchronizable.js +1 -1
- package/lib/module/memory/synchronizable.js.map +1 -1
- package/lib/module/memory/synchronizable.native.js +7 -3
- package/lib/module/memory/synchronizable.native.js.map +1 -1
- package/lib/module/memory/synchronizableUnpacker.native.js +22 -9
- package/lib/module/memory/synchronizableUnpacker.native.js.map +1 -1
- package/lib/module/memory/valueUnpacker.native.js +0 -8
- package/lib/module/memory/valueUnpacker.native.js.map +1 -1
- package/lib/module/mock.js +22 -1
- package/lib/module/mock.js.map +1 -1
- package/lib/module/networking/AbortController.js +43 -0
- package/lib/module/networking/AbortController.js.map +1 -0
- package/lib/module/networking/Blob.js +60 -0
- package/lib/module/networking/Blob.js.map +1 -0
- package/lib/module/networking/DOMException.js +35 -0
- package/lib/module/networking/DOMException.js.map +1 -0
- package/lib/module/networking/FileReader.js +83 -0
- package/lib/module/networking/FileReader.js.map +1 -0
- package/lib/module/networking/FormData.js +105 -0
- package/lib/module/networking/FormData.js.map +1 -0
- package/lib/module/networking/XMLHttpRequest.js +450 -0
- package/lib/module/networking/XMLHttpRequest.js.map +1 -0
- package/lib/module/networking/bytes.js +6 -0
- package/lib/module/networking/bytes.js.map +1 -0
- package/lib/module/networking/events.js +44 -0
- package/lib/module/networking/events.js.map +1 -0
- package/lib/module/networking/http.js +100 -0
- package/lib/module/networking/http.js.map +1 -0
- package/lib/module/networking/install.js +37 -0
- package/lib/module/networking/install.js.map +1 -0
- package/lib/module/networking/utf8.js +99 -0
- package/lib/module/networking/utf8.js.map +1 -0
- package/lib/module/privateGlobals.d.js +0 -1
- package/lib/module/privateGlobals.d.js.map +1 -1
- package/lib/module/runLoop/common/queueMicrotaskPolyfill.js +9 -0
- package/lib/module/runLoop/common/queueMicrotaskPolyfill.js.map +1 -0
- package/lib/module/runLoop/uiRuntime/requestAnimationFrame.js +7 -3
- package/lib/module/runLoop/uiRuntime/requestAnimationFrame.js.map +1 -1
- package/lib/module/runLoop/workletRuntime/index.js +1 -1
- package/lib/module/runLoop/workletRuntime/index.js.map +1 -1
- package/lib/module/runLoop/workletRuntime/requestAnimationFramePolyfill.js +1 -1
- package/lib/module/runLoop/workletRuntime/requestAnimationFramePolyfill.js.map +1 -1
- package/lib/module/runLoop/workletRuntime/taskQueue.js +0 -13
- package/lib/module/runLoop/workletRuntime/taskQueue.js.map +1 -1
- package/lib/module/runtimes.native.js +8 -1
- package/lib/module/runtimes.native.js.map +1 -1
- package/lib/module/specs/NativeWorkletsModule.js.map +1 -1
- package/lib/module/threads.js +11 -0
- package/lib/module/threads.js.map +1 -1
- package/lib/module/threads.native.js +35 -42
- package/lib/module/threads.native.js.map +1 -1
- package/lib/typescript/WorkletsModule/NativeWorklets.native.d.ts.map +1 -1
- package/lib/typescript/WorkletsModule/workletsModuleProxy.d.ts +6 -5
- package/lib/typescript/WorkletsModule/workletsModuleProxy.d.ts.map +1 -1
- package/lib/typescript/debug/jsVersion.d.ts +1 -1
- package/lib/typescript/featureFlags/types.d.ts +0 -1
- package/lib/typescript/featureFlags/types.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +2 -2
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/memory/bundleUnpacker.native.d.ts.map +1 -1
- package/lib/typescript/memory/serializable.native.d.ts.map +1 -1
- package/lib/typescript/memory/synchronizable.d.ts +6 -2
- package/lib/typescript/memory/synchronizable.d.ts.map +1 -1
- package/lib/typescript/memory/synchronizable.native.d.ts +6 -2
- package/lib/typescript/memory/synchronizable.native.d.ts.map +1 -1
- package/lib/typescript/memory/synchronizableUnpacker.native.d.ts +1 -1
- package/lib/typescript/memory/synchronizableUnpacker.native.d.ts.map +1 -1
- package/lib/typescript/memory/types.d.ts +6 -0
- package/lib/typescript/memory/types.d.ts.map +1 -1
- package/lib/typescript/memory/valueUnpacker.native.d.ts.map +1 -1
- package/lib/typescript/networking/AbortController.d.ts +16 -0
- package/lib/typescript/networking/AbortController.d.ts.map +1 -0
- package/lib/typescript/networking/Blob.d.ts +16 -0
- package/lib/typescript/networking/Blob.d.ts.map +1 -0
- package/lib/typescript/networking/DOMException.d.ts +5 -0
- package/lib/typescript/networking/DOMException.d.ts.map +1 -0
- package/lib/typescript/networking/FileReader.d.ts +19 -0
- package/lib/typescript/networking/FileReader.d.ts.map +1 -0
- package/lib/typescript/networking/FormData.d.ts +30 -0
- package/lib/typescript/networking/FormData.d.ts.map +1 -0
- package/lib/typescript/networking/XMLHttpRequest.d.ts +77 -0
- package/lib/typescript/networking/XMLHttpRequest.d.ts.map +1 -0
- package/lib/typescript/networking/bytes.d.ts +2 -0
- package/lib/typescript/networking/bytes.d.ts.map +1 -0
- package/lib/typescript/networking/events.d.ts +18 -0
- package/lib/typescript/networking/events.d.ts.map +1 -0
- package/lib/typescript/networking/http.d.ts +14 -0
- package/lib/typescript/networking/http.d.ts.map +1 -0
- package/lib/typescript/networking/install.d.ts +2 -0
- package/lib/typescript/networking/install.d.ts.map +1 -0
- package/lib/typescript/networking/utf8.d.ts +4 -0
- package/lib/typescript/networking/utf8.d.ts.map +1 -0
- package/lib/typescript/runLoop/{workletRuntime/queueMicrotask.d.ts → common/queueMicrotaskPolyfill.d.ts} +1 -1
- package/lib/typescript/runLoop/common/queueMicrotaskPolyfill.d.ts.map +1 -0
- package/lib/typescript/runLoop/uiRuntime/requestAnimationFrame.d.ts.map +1 -1
- package/lib/typescript/runLoop/workletRuntime/taskQueue.d.ts +0 -2
- package/lib/typescript/runLoop/workletRuntime/taskQueue.d.ts.map +1 -1
- package/lib/typescript/runtimes.native.d.ts.map +1 -1
- package/lib/typescript/specs/NativeWorkletsModule.d.ts +1 -0
- package/lib/typescript/specs/NativeWorkletsModule.d.ts.map +1 -1
- package/lib/typescript/threads.d.ts +8 -0
- package/lib/typescript/threads.d.ts.map +1 -1
- package/lib/typescript/threads.native.d.ts +8 -1
- package/lib/typescript/threads.native.d.ts.map +1 -1
- package/lib/typescript/types.d.ts +9 -5
- package/lib/typescript/types.d.ts.map +1 -1
- package/package.json +36 -22
- package/plugin/index.js +63 -93
- package/plugin-oxc/babel.d.ts +7 -0
- package/plugin-oxc/babel.js +200 -0
- package/plugin-oxc/index.d.ts +33 -0
- package/plugin-oxc/index.js +36 -0
- package/plugin-oxc/worklets-oxc-plugin.darwin-arm64.node +0 -0
- package/plugin-oxc/worklets-oxc-plugin.darwin-x64.node +0 -0
- package/plugin-oxc/worklets-oxc-plugin.linux-arm64.node +0 -0
- package/plugin-oxc/worklets-oxc-plugin.linux-x64.node +0 -0
- package/plugin-oxc/worklets-oxc-plugin.win32-arm64.node +0 -0
- package/plugin-oxc/worklets-oxc-plugin.win32-x64.node +0 -0
- package/react-native.config.js +5 -0
- package/scripts/worklets_utils.rb +0 -10
- package/src/WorkletsModule/NativeWorklets.native.ts +26 -9
- package/src/WorkletsModule/workletsModuleProxy.ts +15 -5
- package/src/debug/jsVersion.ts +1 -1
- package/src/featureFlags/staticFlags.json +0 -1
- package/src/featureFlags/types.ts +0 -1
- package/src/index.ts +3 -0
- package/src/initializers/initializers.native.ts +5 -13
- package/src/memory/bundleUnpacker.native.ts +6 -13
- package/src/memory/serializable.native.ts +6 -46
- package/src/memory/synchronizable.native.ts +38 -4
- package/src/memory/synchronizable.ts +22 -2
- package/src/memory/synchronizableUnpacker.native.ts +38 -13
- package/src/memory/types.ts +9 -0
- package/src/memory/valueUnpacker.native.ts +0 -8
- package/src/mock.ts +28 -1
- package/src/networking/AbortController.ts +57 -0
- package/src/networking/Blob.ts +74 -0
- package/src/networking/DOMException.ts +37 -0
- package/src/networking/FileReader.ts +99 -0
- package/src/networking/FormData.ts +135 -0
- package/src/networking/XMLHttpRequest.ts +557 -0
- package/src/networking/bytes.ts +8 -0
- package/src/networking/events.ts +61 -0
- package/src/networking/http.ts +173 -0
- package/src/networking/install.ts +38 -0
- package/src/networking/utf8.ts +122 -0
- package/src/privateGlobals.d.ts +20 -13
- package/src/runLoop/common/queueMicrotaskPolyfill.ts +12 -0
- package/src/runLoop/uiRuntime/requestAnimationFrame.ts +7 -4
- package/src/runLoop/workletRuntime/index.ts +1 -1
- package/src/runLoop/workletRuntime/requestAnimationFramePolyfill.ts +1 -1
- package/src/runLoop/workletRuntime/taskQueue.ts +0 -15
- package/src/runtimes.native.ts +10 -1
- package/src/specs/NativeWorkletsModule.ts +1 -0
- package/src/threads.native.ts +49 -54
- package/src/threads.ts +11 -0
- package/src/types.ts +9 -5
- package/Common/cpp/worklets/SharedItems/Serializable.cpp +0 -373
- package/Common/cpp/worklets/SharedItems/SerializableFactory.cpp +0 -172
- package/Common/cpp/worklets/SharedItems/SerializableFactory.h +0 -85
- package/Common/cpp/worklets/SharedItems/Synchronizable.cpp +0 -59
- package/android/src/main/cpp/worklets/android/JWorkletRuntimeWrapper.cpp +0 -51
- package/android/src/main/cpp/worklets/android/JWorkletRuntimeWrapper.h +0 -43
- package/android/src/networking/com/swmansion/worklets/WorkletRuntimeWrapper.kt +0 -27
- package/android/src/networking/com/swmansion/worklets/WorkletsHeaderUtil.kt +0 -30
- package/android/src/networking/com/swmansion/worklets/WorkletsModule.kt +0 -203
- package/android/src/networking/com/swmansion/worklets/WorkletsNetworkEventUtil.kt +0 -272
- package/android/src/networking/com/swmansion/worklets/WorkletsNetworking.kt +0 -1124
- package/android/src/networking/com/swmansion/worklets/WorkletsOkHttpCallUtil.kt +0 -40
- package/android/src/networking/com/swmansion/worklets/WorkletsProgressListener.kt +0 -13
- package/android/src/networking/com/swmansion/worklets/WorkletsProgressRequestBody.kt +0 -98
- package/android/src/networking/com/swmansion/worklets/WorkletsProgressResponseBody.kt +0 -60
- package/android/src/networking/com/swmansion/worklets/WorkletsProgressiveStringDecoder.kt +0 -87
- package/android/src/networking/com/swmansion/worklets/WorkletsRequestBodyUtil.kt +0 -181
- package/apple/worklets/apple/Networking/WorkletsNetworking.h +0 -25
- package/apple/worklets/apple/Networking/WorkletsNetworking.mm +0 -707
- package/bundleMode/shims/turboModuleRegistryShim.js +0 -47
- package/lib/module/bundleMode/network.native.js +0 -44
- package/lib/module/bundleMode/network.native.js.map +0 -1
- package/lib/module/runLoop/workletRuntime/queueMicrotask.js +0 -11
- package/lib/module/runLoop/workletRuntime/queueMicrotask.js.map +0 -1
- package/lib/typescript/bundleMode/network.native.d.ts +0 -7
- package/lib/typescript/bundleMode/network.native.d.ts.map +0 -1
- package/lib/typescript/runLoop/workletRuntime/queueMicrotask.d.ts.map +0 -1
- package/src/bundleMode/network.native.ts +0 -63
- package/src/runLoop/workletRuntime/queueMicrotask.ts +0 -13
|
@@ -47,9 +47,8 @@ void AnimationFrameBatchinator::flush() {
|
|
|
47
47
|
auto &uiWorkletRuntime = strongThis->uiWorkletRuntime_;
|
|
48
48
|
uiWorkletRuntime->runSync([&](jsi::Runtime &rt) {
|
|
49
49
|
for (const auto &callback : callbacks) {
|
|
50
|
-
uiWorkletRuntime->
|
|
50
|
+
uiWorkletRuntime->runSyncAndDiscard(*callback, timestampMs);
|
|
51
51
|
}
|
|
52
|
-
jsi_utils::triggerWeakRefCleanup(uiWorkletRuntime->getJSIRuntime());
|
|
53
52
|
});
|
|
54
53
|
});
|
|
55
54
|
}
|
|
@@ -1,8 +1,24 @@
|
|
|
1
1
|
#include <jsi/jsi.h>
|
|
2
2
|
#include <worklets/Compat/Holders.h>
|
|
3
3
|
#include <worklets/Compat/StableApi.h>
|
|
4
|
-
#include <worklets/SharedItems/Serializable.h>
|
|
5
|
-
#include <worklets/SharedItems/
|
|
4
|
+
#include <worklets/SharedItems/Serializable/CustomSerializable.h>
|
|
5
|
+
#include <worklets/SharedItems/Serializable/Serializable.h>
|
|
6
|
+
#include <worklets/SharedItems/Serializable/SerializableArray.h>
|
|
7
|
+
#include <worklets/SharedItems/Serializable/SerializableArrayBuffer.h>
|
|
8
|
+
#include <worklets/SharedItems/Serializable/SerializableBigInt.h>
|
|
9
|
+
#include <worklets/SharedItems/Serializable/SerializableError.h>
|
|
10
|
+
#include <worklets/SharedItems/Serializable/SerializableHostFunction.h>
|
|
11
|
+
#include <worklets/SharedItems/Serializable/SerializableHostObject.h>
|
|
12
|
+
#include <worklets/SharedItems/Serializable/SerializableImport.h>
|
|
13
|
+
#include <worklets/SharedItems/Serializable/SerializableMap.h>
|
|
14
|
+
#include <worklets/SharedItems/Serializable/SerializableObject.h>
|
|
15
|
+
#include <worklets/SharedItems/Serializable/SerializableRegExp.h>
|
|
16
|
+
#include <worklets/SharedItems/Serializable/SerializableRemoteFunction.h>
|
|
17
|
+
#include <worklets/SharedItems/Serializable/SerializableScalar.h>
|
|
18
|
+
#include <worklets/SharedItems/Serializable/SerializableSet.h>
|
|
19
|
+
#include <worklets/SharedItems/Serializable/SerializableString.h>
|
|
20
|
+
#include <worklets/SharedItems/Serializable/SerializableTurboModuleLike.h>
|
|
21
|
+
#include <worklets/SharedItems/Serializable/SerializableWorklet.h>
|
|
6
22
|
#include <worklets/SharedItems/Shareable.h>
|
|
7
23
|
#include <worklets/SharedItems/Synchronizable.h>
|
|
8
24
|
#include <worklets/Tools/JSISerializer.h>
|
|
@@ -70,7 +86,7 @@ std::shared_ptr<Serializable> extractSerializable(
|
|
|
70
86
|
case Serializable::ValueType::RemoteFunctionType:
|
|
71
87
|
return extractSerializableOrThrow<SerializableRemoteFunction>(rt, value, errorMessage);
|
|
72
88
|
case Serializable::ValueType::HandleType:
|
|
73
|
-
|
|
89
|
+
throw std::runtime_error("[Worklets] Not implemented.");
|
|
74
90
|
case Serializable::ValueType::HostObjectType:
|
|
75
91
|
return extractSerializableOrThrow<SerializableHostObject>(rt, value, errorMessage);
|
|
76
92
|
case Serializable::ValueType::HostFunctionType:
|
|
@@ -101,14 +117,14 @@ std::shared_ptr<Serializable> extractSerializable(
|
|
|
101
117
|
void runSyncOnRuntime(
|
|
102
118
|
const std::shared_ptr<WorkletRuntime> &workletRuntime,
|
|
103
119
|
const std::shared_ptr<Serializable> &worklet) {
|
|
104
|
-
workletRuntime->
|
|
120
|
+
workletRuntime->runSyncAndDiscard(std::static_pointer_cast<SerializableWorklet>(worklet));
|
|
105
121
|
}
|
|
106
122
|
|
|
107
123
|
void runSyncOnRuntime(
|
|
108
124
|
const std::shared_ptr<WorkletRuntime> &workletRuntime,
|
|
109
125
|
const std::shared_ptr<Serializable> &worklet,
|
|
110
126
|
const facebook::jsi::Value &arg0) {
|
|
111
|
-
workletRuntime->
|
|
127
|
+
workletRuntime->runSyncAndDiscard(std::static_pointer_cast<SerializableWorklet>(worklet), arg0);
|
|
112
128
|
}
|
|
113
129
|
|
|
114
130
|
void runSyncOnRuntime(
|
|
@@ -116,18 +132,18 @@ void runSyncOnRuntime(
|
|
|
116
132
|
const std::shared_ptr<Serializable> &worklet,
|
|
117
133
|
const facebook::jsi::Value &arg0,
|
|
118
134
|
const facebook::jsi::Value &arg1) {
|
|
119
|
-
workletRuntime->
|
|
135
|
+
workletRuntime->runSyncAndDiscard(std::static_pointer_cast<SerializableWorklet>(worklet), arg0, arg1);
|
|
120
136
|
}
|
|
121
137
|
|
|
122
138
|
void runSyncOnRuntime(const std::shared_ptr<WorkletRuntime> &workletRuntime, const facebook::jsi::Function &function) {
|
|
123
|
-
workletRuntime->
|
|
139
|
+
workletRuntime->runSyncAndDiscard(function);
|
|
124
140
|
}
|
|
125
141
|
|
|
126
142
|
void runSyncOnRuntime(
|
|
127
143
|
const std::shared_ptr<WorkletRuntime> &workletRuntime,
|
|
128
144
|
const facebook::jsi::Function &function,
|
|
129
145
|
const facebook::jsi::Value &arg0) {
|
|
130
|
-
workletRuntime->
|
|
146
|
+
workletRuntime->runSyncAndDiscard(function, arg0);
|
|
131
147
|
}
|
|
132
148
|
|
|
133
149
|
std::shared_ptr<WorkletRuntime> getWorkletRuntimeFromHolder(
|
|
@@ -3,25 +3,43 @@
|
|
|
3
3
|
#include <worklets/Compat/Holders.h>
|
|
4
4
|
#include <worklets/Compat/StableApi.h>
|
|
5
5
|
#include <worklets/NativeModules/JSIWorkletsModuleProxy.h>
|
|
6
|
-
#include <worklets/SharedItems/Serializable.h>
|
|
7
|
-
#include <worklets/SharedItems/
|
|
8
|
-
#include <worklets/SharedItems/
|
|
6
|
+
#include <worklets/SharedItems/Serializable/CustomSerializable.h>
|
|
7
|
+
#include <worklets/SharedItems/Serializable/Serializable.h>
|
|
8
|
+
#include <worklets/SharedItems/Serializable/SerializableArray.h>
|
|
9
|
+
#include <worklets/SharedItems/Serializable/SerializableArrayBuffer.h>
|
|
10
|
+
#include <worklets/SharedItems/Serializable/SerializableBigInt.h>
|
|
11
|
+
#include <worklets/SharedItems/Serializable/SerializableError.h>
|
|
12
|
+
#include <worklets/SharedItems/Serializable/SerializableHostFunction.h>
|
|
13
|
+
#include <worklets/SharedItems/Serializable/SerializableHostObject.h>
|
|
14
|
+
#include <worklets/SharedItems/Serializable/SerializableImport.h>
|
|
15
|
+
#include <worklets/SharedItems/Serializable/SerializableMap.h>
|
|
16
|
+
#include <worklets/SharedItems/Serializable/SerializableObject.h>
|
|
17
|
+
#include <worklets/SharedItems/Serializable/SerializableRegExp.h>
|
|
18
|
+
#include <worklets/SharedItems/Serializable/SerializableRemoteFunction.h>
|
|
19
|
+
#include <worklets/SharedItems/Serializable/SerializableScalar.h>
|
|
20
|
+
#include <worklets/SharedItems/Serializable/SerializableSet.h>
|
|
21
|
+
#include <worklets/SharedItems/Serializable/SerializableString.h>
|
|
22
|
+
#include <worklets/SharedItems/Serializable/SerializableTurboModuleLike.h>
|
|
23
|
+
#include <worklets/SharedItems/Serializable/SerializableWorklet.h>
|
|
9
24
|
#include <worklets/SharedItems/Shareable.h>
|
|
10
25
|
#include <worklets/SharedItems/Synchronizable.h>
|
|
26
|
+
#include <worklets/SharedItems/SynchronizableDynamic.h>
|
|
27
|
+
#include <worklets/SharedItems/SynchronizableFixed.h>
|
|
11
28
|
#include <worklets/Tools/FeatureFlags.h>
|
|
12
29
|
#include <worklets/Tools/JSLogger.h>
|
|
13
30
|
#include <worklets/Tools/WorkletsJSIUtils.h>
|
|
14
31
|
#include <worklets/WorkletRuntime/BundleModeConfig.h>
|
|
15
32
|
#include <worklets/WorkletRuntime/RuntimeData.h>
|
|
16
33
|
|
|
17
|
-
#ifndef NDEBUG
|
|
18
|
-
#include <algorithm>
|
|
19
|
-
#endif // NDEBUG
|
|
20
34
|
#include <memory>
|
|
21
35
|
#include <optional>
|
|
36
|
+
#include <sstream>
|
|
22
37
|
#include <stdexcept>
|
|
23
38
|
#include <string>
|
|
39
|
+
#include <thread>
|
|
40
|
+
#include <type_traits>
|
|
24
41
|
#include <utility>
|
|
42
|
+
#include <variant>
|
|
25
43
|
#include <vector>
|
|
26
44
|
|
|
27
45
|
using namespace facebook;
|
|
@@ -33,31 +51,26 @@ namespace {
|
|
|
33
51
|
inline void scheduleOnUI(
|
|
34
52
|
const std::weak_ptr<WorkletRuntime> &weakUIWorkletRuntime,
|
|
35
53
|
jsi::Runtime &rt,
|
|
36
|
-
const jsi::Value &serializableArrayOfWorkletsValue
|
|
54
|
+
const jsi::Value &serializableArrayOfWorkletsValue,
|
|
55
|
+
const jsi::Value &serializableArrayOfArgumentsValue
|
|
37
56
|
#ifndef NDEBUG
|
|
38
57
|
,
|
|
39
58
|
const jsi::Value &scheduleStacksValue
|
|
40
59
|
#endif // NDEBUG
|
|
41
60
|
) {
|
|
42
|
-
auto
|
|
61
|
+
auto serializableArrayOfWorklets = extractSerializableOrThrow<SerializableArray>(
|
|
43
62
|
rt, serializableArrayOfWorkletsValue, "[Worklets] scheduleOnUI expects a serializable array of worklets.");
|
|
44
|
-
auto
|
|
45
|
-
|
|
46
|
-
const auto &workletsList = serializableArrayOfWorklets->getList();
|
|
47
|
-
std::vector<std::shared_ptr<SerializableWorklet>> worklets;
|
|
48
|
-
worklets.reserve(workletsList.size());
|
|
49
|
-
for (const auto &item : workletsList) {
|
|
50
|
-
worklets.push_back(std::static_pointer_cast<SerializableWorklet>(item));
|
|
51
|
-
}
|
|
63
|
+
auto serializableArrayOfArguments = extractSerializableOrThrow<SerializableArray>(
|
|
64
|
+
rt, serializableArrayOfArgumentsValue, "[Worklets] scheduleOnUI expects a serializable array of arguments.");
|
|
52
65
|
|
|
53
66
|
#ifndef NDEBUG
|
|
54
|
-
std::vector<std::optional<std::string>> scheduleStacks
|
|
67
|
+
std::vector<std::optional<std::string>> scheduleStacks;
|
|
55
68
|
if (scheduleStacksValue.isObject()) {
|
|
56
69
|
auto stacksObject = scheduleStacksValue.asObject(rt);
|
|
57
70
|
if (stacksObject.isArray(rt)) {
|
|
58
71
|
auto stacksArray = stacksObject.asArray(rt);
|
|
59
|
-
|
|
60
|
-
for (size_t i = 0; i <
|
|
72
|
+
scheduleStacks.resize(stacksArray.size(rt));
|
|
73
|
+
for (size_t i = 0; i < scheduleStacks.size(); i++) {
|
|
61
74
|
auto stackValue = stacksArray.getValueAtIndex(rt, i);
|
|
62
75
|
if (stackValue.isString()) {
|
|
63
76
|
scheduleStacks[i] = stackValue.asString(rt).utf8(rt);
|
|
@@ -72,9 +85,10 @@ inline void scheduleOnUI(
|
|
|
72
85
|
return;
|
|
73
86
|
}
|
|
74
87
|
#ifndef NDEBUG
|
|
75
|
-
uiWorkletRuntime->scheduleWithStack(
|
|
88
|
+
uiWorkletRuntime->scheduleWithStack(
|
|
89
|
+
std::move(serializableArrayOfWorklets), std::move(serializableArrayOfArguments), std::move(scheduleStacks));
|
|
76
90
|
#else
|
|
77
|
-
uiWorkletRuntime->schedule(std::move(
|
|
91
|
+
uiWorkletRuntime->schedule(std::move(serializableArrayOfWorklets), std::move(serializableArrayOfArguments));
|
|
78
92
|
#endif // NDEBUG
|
|
79
93
|
}
|
|
80
94
|
|
|
@@ -137,9 +151,10 @@ inline jsi::Value createWorkletRuntime(
|
|
|
137
151
|
std::shared_ptr<SerializableWorklet> &initializer,
|
|
138
152
|
const std::shared_ptr<AsyncQueue> &queue,
|
|
139
153
|
bool enableEventLoop,
|
|
140
|
-
bool enableLocking
|
|
141
|
-
|
|
142
|
-
|
|
154
|
+
bool enableLocking,
|
|
155
|
+
bool enableNetworking) {
|
|
156
|
+
const auto workletRuntime = runtimeManager->createWorkletRuntime(
|
|
157
|
+
sourceProxy, name, initializer, queue, enableEventLoop, enableLocking, enableNetworking);
|
|
143
158
|
return jsi::Object::createFromHostObject(originRuntime, workletRuntime);
|
|
144
159
|
}
|
|
145
160
|
|
|
@@ -168,6 +183,29 @@ inline std::shared_ptr<AsyncQueue> extractAsyncQueue(jsi::Runtime &rt, const jsi
|
|
|
168
183
|
return asyncQueue;
|
|
169
184
|
}
|
|
170
185
|
|
|
186
|
+
inline jsi::Value synchronizableValueToJSValue(jsi::Runtime &rt, const SynchronizableValue &value) {
|
|
187
|
+
return std::visit(
|
|
188
|
+
[&rt](const auto &alternative) -> jsi::Value {
|
|
189
|
+
using TAlternative = std::decay_t<decltype(alternative)>;
|
|
190
|
+
if constexpr (std::is_same_v<TAlternative, std::shared_ptr<Serializable>>) {
|
|
191
|
+
return alternative->toJSValue(rt);
|
|
192
|
+
} else {
|
|
193
|
+
return jsi::Value(alternative);
|
|
194
|
+
}
|
|
195
|
+
},
|
|
196
|
+
value);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
inline SynchronizableFixedValue jsValueToSynchronizableFixedValue(const jsi::Value &value) {
|
|
200
|
+
if (value.isBool()) {
|
|
201
|
+
return value.getBool();
|
|
202
|
+
}
|
|
203
|
+
if (value.isNumber()) {
|
|
204
|
+
return value.getNumber();
|
|
205
|
+
}
|
|
206
|
+
throw std::runtime_error("[Worklets] Expected a number or boolean for a fixed-type Synchronizable.");
|
|
207
|
+
}
|
|
208
|
+
|
|
171
209
|
inline void registerCustomSerializable(
|
|
172
210
|
const std::shared_ptr<RuntimeManager> &runtimeManager,
|
|
173
211
|
const std::shared_ptr<MemoryManager> &memoryManager,
|
|
@@ -267,11 +305,6 @@ jsi::Object JSIWorkletsModuleProxy::toOptimizedObject(jsi::Runtime &rt) const {
|
|
|
267
305
|
return makeSerializableHostObject(rt, at<0>(args).asObject(rt).asHostObject(rt));
|
|
268
306
|
});
|
|
269
307
|
|
|
270
|
-
jsi_utils::addMethod<1>(
|
|
271
|
-
rt, obj, "createSerializableInitializer", [](jsi::Runtime &rt, const jsi::Value &, const jsi::Value(&args)[1]) {
|
|
272
|
-
return makeSerializableInitializer(rt, at<0>(args).asObject(rt));
|
|
273
|
-
});
|
|
274
|
-
|
|
275
308
|
jsi_utils::addMethod<2>(
|
|
276
309
|
rt, obj, "createSerializableArray", [](jsi::Runtime &rt, const jsi::Value &, const jsi::Value(&args)[2]) {
|
|
277
310
|
return makeSerializableArray(rt, at<0>(args).asObject(rt).asArray(rt), at<1>(args));
|
|
@@ -426,15 +459,15 @@ jsi::Object JSIWorkletsModuleProxy::toOptimizedObject(jsi::Runtime &rt) const {
|
|
|
426
459
|
}
|
|
427
460
|
});
|
|
428
461
|
|
|
429
|
-
jsi_utils::addMethod<
|
|
462
|
+
jsi_utils::addMethod<3>(
|
|
430
463
|
rt,
|
|
431
464
|
obj,
|
|
432
465
|
"scheduleOnUI",
|
|
433
|
-
[uiWorkletRuntime = uiWorkletRuntime_](jsi::Runtime &rt, const jsi::Value &, const jsi::Value(&args)[
|
|
466
|
+
[uiWorkletRuntime = uiWorkletRuntime_](jsi::Runtime &rt, const jsi::Value &, const jsi::Value(&args)[3]) {
|
|
434
467
|
#ifndef NDEBUG
|
|
435
|
-
scheduleOnUI(uiWorkletRuntime, rt, at<0>(args), at<1>(args));
|
|
468
|
+
scheduleOnUI(uiWorkletRuntime, rt, at<0>(args), at<1>(args), at<2>(args));
|
|
436
469
|
#else
|
|
437
|
-
scheduleOnUI(uiWorkletRuntime, rt, at<0>(args));
|
|
470
|
+
scheduleOnUI(uiWorkletRuntime, rt, at<0>(args), at<1>(args));
|
|
438
471
|
#endif // NDEBUG
|
|
439
472
|
});
|
|
440
473
|
|
|
@@ -493,11 +526,11 @@ jsi::Object JSIWorkletsModuleProxy::toOptimizedObject(jsi::Runtime &rt) const {
|
|
|
493
526
|
return serializedResult->toJSValue(rt);
|
|
494
527
|
});
|
|
495
528
|
|
|
496
|
-
jsi_utils::addMethod<
|
|
529
|
+
jsi_utils::addMethod<7>(
|
|
497
530
|
rt,
|
|
498
531
|
obj,
|
|
499
532
|
"createWorkletRuntime",
|
|
500
|
-
[sourceProxy = shared_from_this()](jsi::Runtime &rt, const jsi::Value &, const jsi::Value(&args)[
|
|
533
|
+
[sourceProxy = shared_from_this()](jsi::Runtime &rt, const jsi::Value &, const jsi::Value(&args)[7]) {
|
|
501
534
|
const auto name = at<0>(args).getString(rt).utf8(rt);
|
|
502
535
|
auto serializableInitializer = extractSerializableOrThrow<SerializableWorklet>(
|
|
503
536
|
rt, at<1>(args), "[Worklets] Initializer must be a worklet.");
|
|
@@ -512,10 +545,19 @@ jsi::Object JSIWorkletsModuleProxy::toOptimizedObject(jsi::Runtime &rt) const {
|
|
|
512
545
|
|
|
513
546
|
const auto enableEventLoop = at<4>(args).getBool();
|
|
514
547
|
const auto enableLocking = at<5>(args).getBool();
|
|
548
|
+
const auto enableNetworking = at<6>(args).getBool();
|
|
515
549
|
const auto runtimeManager = sourceProxy->getRuntimeManager();
|
|
516
550
|
|
|
517
551
|
return createWorkletRuntime(
|
|
518
|
-
rt,
|
|
552
|
+
rt,
|
|
553
|
+
runtimeManager,
|
|
554
|
+
sourceProxy,
|
|
555
|
+
name,
|
|
556
|
+
serializableInitializer,
|
|
557
|
+
asyncQueue,
|
|
558
|
+
enableEventLoop,
|
|
559
|
+
enableLocking,
|
|
560
|
+
enableNetworking);
|
|
519
561
|
});
|
|
520
562
|
|
|
521
563
|
jsi_utils::addMethod<3>(
|
|
@@ -596,41 +638,62 @@ jsi::Object JSIWorkletsModuleProxy::toOptimizedObject(jsi::Runtime &rt) const {
|
|
|
596
638
|
/* value */ at<1>(args).asBool());
|
|
597
639
|
});
|
|
598
640
|
|
|
599
|
-
jsi_utils::addMethod<
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
641
|
+
jsi_utils::addMethod<0>(rt, obj, "getCurrentThreadId", [](jsi::Runtime &rt, const jsi::Value &) {
|
|
642
|
+
std::ostringstream stream;
|
|
643
|
+
stream << std::this_thread::get_id();
|
|
644
|
+
return jsi::String::createFromUtf8(rt, stream.str());
|
|
645
|
+
});
|
|
646
|
+
|
|
647
|
+
jsi_utils::addMethod<2>(
|
|
648
|
+
rt, obj, "createSynchronizable", [](jsi::Runtime &rt, const jsi::Value &, const jsi::Value(&args)[2]) {
|
|
649
|
+
if (at<1>(args).getBool()) {
|
|
650
|
+
return SerializableJSRef::newNativeStateObject(
|
|
651
|
+
rt, SynchronizableFixed::make(jsValueToSynchronizableFixedValue(at<0>(args))));
|
|
652
|
+
} else {
|
|
653
|
+
auto initial = extractSerializableOrThrow(rt, at<0>(args), "[Worklets] Value must be a Serializable.");
|
|
654
|
+
return SerializableJSRef::newNativeStateObject(rt, std::make_shared<SynchronizableDynamic>(initial));
|
|
655
|
+
}
|
|
604
656
|
});
|
|
605
657
|
|
|
606
658
|
jsi_utils::addMethod<1>(
|
|
607
659
|
rt, obj, "synchronizableGetDirty", [](jsi::Runtime &rt, const jsi::Value &, const jsi::Value(&args)[1]) {
|
|
608
|
-
|
|
609
|
-
|
|
660
|
+
return synchronizableValueToJSValue(
|
|
661
|
+
rt, Synchronizable::extractSynchronizableOrThrow(rt, at<0>(args))->getDirty());
|
|
610
662
|
});
|
|
611
663
|
|
|
612
664
|
jsi_utils::addMethod<1>(
|
|
613
665
|
rt, obj, "synchronizableGetBlocking", [](jsi::Runtime &rt, const jsi::Value &, const jsi::Value(&args)[1]) {
|
|
614
|
-
|
|
615
|
-
|
|
666
|
+
return synchronizableValueToJSValue(
|
|
667
|
+
rt, Synchronizable::extractSynchronizableOrThrow(rt, at<0>(args))->getBlocking());
|
|
616
668
|
});
|
|
617
669
|
|
|
618
670
|
jsi_utils::addMethod<2>(
|
|
619
671
|
rt, obj, "synchronizableSetBlocking", [](jsi::Runtime &rt, const jsi::Value &, const jsi::Value(&args)[2]) {
|
|
620
|
-
auto synchronizable = extractSynchronizableOrThrow(rt, at<0>(args));
|
|
621
|
-
auto newValue =
|
|
622
|
-
synchronizable->
|
|
672
|
+
auto synchronizable = Synchronizable::extractSynchronizableOrThrow(rt, at<0>(args));
|
|
673
|
+
const auto &newValue = at<1>(args);
|
|
674
|
+
if (synchronizable->isFixed()) {
|
|
675
|
+
synchronizable->setBlocking(jsValueToSynchronizableFixedValue(newValue));
|
|
676
|
+
} else {
|
|
677
|
+
synchronizable->setBlocking(
|
|
678
|
+
extractSerializableOrThrow(rt, newValue, "[Worklets] Value must be a Serializable."));
|
|
679
|
+
}
|
|
680
|
+
});
|
|
681
|
+
|
|
682
|
+
jsi_utils::addMethod<2>(
|
|
683
|
+
rt, obj, "synchronizableSetDirty", [](jsi::Runtime &rt, const jsi::Value &, const jsi::Value(&args)[2]) {
|
|
684
|
+
Synchronizable::extractSynchronizableOrThrow(rt, at<0>(args))
|
|
685
|
+
->setDirty(jsValueToSynchronizableFixedValue(at<1>(args)));
|
|
623
686
|
});
|
|
624
687
|
|
|
625
688
|
jsi_utils::addMethod<1>(
|
|
626
689
|
rt, obj, "synchronizableLock", [](jsi::Runtime &rt, const jsi::Value &, const jsi::Value(&args)[1]) {
|
|
627
|
-
auto synchronizable = extractSynchronizableOrThrow(rt, at<0>(args));
|
|
690
|
+
auto synchronizable = Synchronizable::extractSynchronizableOrThrow(rt, at<0>(args));
|
|
628
691
|
synchronizable->lock();
|
|
629
692
|
});
|
|
630
693
|
|
|
631
694
|
jsi_utils::addMethod<1>(
|
|
632
695
|
rt, obj, "synchronizableUnlock", [](jsi::Runtime &rt, const jsi::Value &, const jsi::Value(&args)[1]) {
|
|
633
|
-
auto synchronizable = extractSynchronizableOrThrow(rt, at<0>(args));
|
|
696
|
+
auto synchronizable = Synchronizable::extractSynchronizableOrThrow(rt, at<0>(args));
|
|
634
697
|
synchronizable->unlock();
|
|
635
698
|
});
|
|
636
699
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
#include <jsi/jsi.h>
|
|
4
4
|
#include <worklets/SharedItems/MemoryManager.h>
|
|
5
|
-
#include <worklets/SharedItems/Serializable.h>
|
|
5
|
+
#include <worklets/SharedItems/Serializable/Serializable.h>
|
|
6
6
|
#include <worklets/SharedItems/UnpackerLoader.h>
|
|
7
7
|
#include <worklets/Tools/RNRuntimeStatus.h>
|
|
8
8
|
#include <worklets/Tools/ScriptBuffer.h>
|
|
@@ -18,6 +18,7 @@ using namespace facebook;
|
|
|
18
18
|
|
|
19
19
|
namespace worklets {
|
|
20
20
|
|
|
21
|
+
class Networking;
|
|
21
22
|
class WorkletRuntime;
|
|
22
23
|
|
|
23
24
|
class JSIWorkletsModuleProxy : public std::enable_shared_from_this<JSIWorkletsModuleProxy> {
|
|
@@ -30,6 +31,7 @@ class JSIWorkletsModuleProxy : public std::enable_shared_from_this<JSIWorkletsMo
|
|
|
30
31
|
const std::shared_ptr<RuntimeManager> &runtimeManager,
|
|
31
32
|
const std::weak_ptr<WorkletRuntime> &uiWorkletRuntime,
|
|
32
33
|
const std::shared_ptr<RuntimeBindings> &runtimeBindings,
|
|
34
|
+
const std::shared_ptr<Networking> &networking,
|
|
33
35
|
const BundleModeConfig &bundleModeConfig,
|
|
34
36
|
const std::shared_ptr<UnpackerLoader> &unpackerLoader,
|
|
35
37
|
const std::shared_ptr<RNRuntimeStatus> &rnRuntimeStatus,
|
|
@@ -42,6 +44,7 @@ class JSIWorkletsModuleProxy : public std::enable_shared_from_this<JSIWorkletsMo
|
|
|
42
44
|
runtimeManager_(runtimeManager),
|
|
43
45
|
uiWorkletRuntime_(uiWorkletRuntime),
|
|
44
46
|
runtimeBindings_(runtimeBindings),
|
|
47
|
+
networking_(networking),
|
|
45
48
|
unpackerLoader_(unpackerLoader),
|
|
46
49
|
rnRuntimeStatus_(rnRuntimeStatus),
|
|
47
50
|
hostRuntimeId_(hostRuntimeId) {}
|
|
@@ -57,6 +60,7 @@ class JSIWorkletsModuleProxy : public std::enable_shared_from_this<JSIWorkletsMo
|
|
|
57
60
|
sourceProxy->runtimeManager_,
|
|
58
61
|
sourceProxy->uiWorkletRuntime_,
|
|
59
62
|
sourceProxy->runtimeBindings_,
|
|
63
|
+
sourceProxy->networking_,
|
|
60
64
|
sourceProxy->bundleModeConfig_,
|
|
61
65
|
sourceProxy->unpackerLoader_,
|
|
62
66
|
sourceProxy->rnRuntimeStatus_,
|
|
@@ -105,6 +109,10 @@ class JSIWorkletsModuleProxy : public std::enable_shared_from_this<JSIWorkletsMo
|
|
|
105
109
|
return runtimeBindings_;
|
|
106
110
|
}
|
|
107
111
|
|
|
112
|
+
[[nodiscard]] std::shared_ptr<Networking> getNetworking() const {
|
|
113
|
+
return networking_;
|
|
114
|
+
}
|
|
115
|
+
|
|
108
116
|
[[nodiscard]] std::shared_ptr<UnpackerLoader> getUnpackerLoader() const {
|
|
109
117
|
return unpackerLoader_;
|
|
110
118
|
}
|
|
@@ -118,6 +126,7 @@ class JSIWorkletsModuleProxy : public std::enable_shared_from_this<JSIWorkletsMo
|
|
|
118
126
|
const std::shared_ptr<RuntimeManager> runtimeManager_;
|
|
119
127
|
const std::weak_ptr<WorkletRuntime> uiWorkletRuntime_;
|
|
120
128
|
const std::shared_ptr<RuntimeBindings> runtimeBindings_;
|
|
129
|
+
const std::shared_ptr<Networking> networking_;
|
|
121
130
|
const std::shared_ptr<UnpackerLoader> unpackerLoader_;
|
|
122
131
|
const std::shared_ptr<RNRuntimeStatus> rnRuntimeStatus_;
|
|
123
132
|
const RuntimeData::RuntimeId hostRuntimeId_;
|
|
@@ -6,8 +6,10 @@
|
|
|
6
6
|
#include <worklets/WorkletRuntime/RuntimeData.h>
|
|
7
7
|
#include <worklets/WorkletRuntime/UIRuntimeDecorator.h>
|
|
8
8
|
|
|
9
|
+
#include <react/debug/react_native_assert.h>
|
|
10
|
+
|
|
9
11
|
#include <memory>
|
|
10
|
-
#include <
|
|
12
|
+
#include <stdexcept>
|
|
11
13
|
|
|
12
14
|
using namespace facebook;
|
|
13
15
|
|
|
@@ -18,64 +20,120 @@ bool isDevBundleFromRNRuntime(jsi::Runtime &rnRuntime) {
|
|
|
18
20
|
return rtDev.isBool() && rtDev.asBool();
|
|
19
21
|
}
|
|
20
22
|
|
|
21
|
-
/**
|
|
22
|
-
* This method is required outside of Bundle Mode to make sure we start creating
|
|
23
|
-
* Worklet Runtimes only after unpackers code was loaded from the RN Runtime.
|
|
24
|
-
*
|
|
25
|
-
* In Bundle Mode unpackers are installed during bundle evaluation instead.
|
|
26
|
-
*/
|
|
27
23
|
void WorkletsModuleProxy::start() {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
24
|
+
react_native_assert(jsScheduler_->canInvokeSyncOnJS() && "start must be called on the JS thread");
|
|
25
|
+
if (!rnRuntimeProxy_) [[unlikely]] {
|
|
26
|
+
throw std::runtime_error("[Worklets] WorkletsModuleProxy must be attached to the RN runtime before start.");
|
|
27
|
+
}
|
|
28
|
+
if (uiRuntimeStarted_) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
34
31
|
|
|
35
|
-
|
|
36
|
-
std::make_shared<AnimationFrameBatchinator>(uiWorkletRuntime_, runtimeBindings_->requestAnimationFrame);
|
|
37
|
-
|
|
38
|
-
UIRuntimeDecorator::decorate(
|
|
39
|
-
uiWorkletRuntime_->getJSIRuntime(), animationFrameBatchinator_->getJsiRequestAnimationFrame());
|
|
32
|
+
startUIRuntime(JSIWorkletsModuleProxy::createForNewRuntime(rnRuntimeProxy_, RuntimeData::uiRuntimeId));
|
|
40
33
|
}
|
|
41
34
|
|
|
42
35
|
WorkletsModuleProxy::WorkletsModuleProxy(
|
|
43
|
-
|
|
44
|
-
const std::shared_ptr<CallInvoker> &jsCallInvoker,
|
|
36
|
+
const std::shared_ptr<JSScheduler> &jsScheduler,
|
|
45
37
|
const std::shared_ptr<UIScheduler> &uiScheduler,
|
|
46
|
-
std::function<bool()> &&isJavaScriptThread,
|
|
47
38
|
const std::shared_ptr<RuntimeBindings> &runtimeBindings,
|
|
48
|
-
const BundleModeConfig &bundleModeConfig,
|
|
49
39
|
const std::shared_ptr<RNRuntimeStatus> &rnRuntimeStatus)
|
|
50
|
-
: isDevBundle_(
|
|
51
|
-
jsScheduler_(
|
|
40
|
+
: isDevBundle_(false),
|
|
41
|
+
jsScheduler_(jsScheduler),
|
|
52
42
|
uiScheduler_(uiScheduler),
|
|
53
43
|
jsLogger_(std::make_shared<JSLogger>(jsScheduler_)),
|
|
54
44
|
runtimeBindings_(runtimeBindings),
|
|
55
|
-
bundleModeConfig_
|
|
45
|
+
bundleModeConfig_{.enabled = false},
|
|
56
46
|
memoryManager_(std::make_shared<MemoryManager>()),
|
|
57
47
|
runtimeManager_(std::make_shared<RuntimeManager>()),
|
|
58
48
|
unpackerLoader_(std::make_shared<UnpackerLoader>()),
|
|
59
49
|
rnRuntimeStatus_(rnRuntimeStatus),
|
|
50
|
+
networking_(
|
|
51
|
+
runtimeBindings->networkingBackend ? std::make_shared<Networking>(runtimeBindings->networkingBackend)
|
|
52
|
+
: nullptr),
|
|
60
53
|
uiWorkletRuntime_(runtimeManager_->createUninitializedUIRuntime(std::make_shared<AsyncQueueUI>(uiScheduler_))),
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
54
|
+
uiRuntimeStarted_(false) {}
|
|
55
|
+
|
|
56
|
+
void WorkletsModuleProxy::startUIRuntimeInBundleModeAOT(const BundleModeConfig &bundleModeConfig) {
|
|
57
|
+
if (!bundleModeConfig.enabled) [[unlikely]] {
|
|
58
|
+
throw std::runtime_error("[Worklets] startUIRuntimeInBundleModeAOT requires Bundle Mode.");
|
|
59
|
+
}
|
|
60
|
+
if (rnRuntimeProxy_) [[unlikely]] {
|
|
61
|
+
throw std::runtime_error("[Worklets] startUIRuntimeInBundleModeAOT must be called before attachToRNRuntime.");
|
|
62
|
+
}
|
|
63
|
+
if (uiRuntimeStarted_) [[unlikely]] {
|
|
64
|
+
throw std::runtime_error("[Worklets] The UI Worklet Runtime was already started.");
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
bundleModeConfig_ = bundleModeConfig;
|
|
68
|
+
startUIRuntime(std::make_shared<JSIWorkletsModuleProxy>(
|
|
69
|
+
false, /* isDevBundle_ */
|
|
70
|
+
jsScheduler_,
|
|
71
|
+
uiScheduler_,
|
|
72
|
+
memoryManager_,
|
|
73
|
+
runtimeManager_,
|
|
74
|
+
uiWorkletRuntime_,
|
|
75
|
+
runtimeBindings_,
|
|
76
|
+
networking_,
|
|
77
|
+
bundleModeConfig_,
|
|
78
|
+
unpackerLoader_,
|
|
79
|
+
rnRuntimeStatus_,
|
|
80
|
+
RuntimeData::uiRuntimeId));
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
void WorkletsModuleProxy::attachToRNRuntime(
|
|
84
|
+
jsi::Runtime &rnRuntime,
|
|
85
|
+
const std::optional<BundleModeConfig> &bundleModeConfig) {
|
|
86
|
+
react_native_assert(jsScheduler_->canInvokeSyncOnJS() && "attachToRNRuntime must be called on the JS thread");
|
|
87
|
+
if (rnRuntimeProxy_) [[unlikely]] {
|
|
88
|
+
throw std::runtime_error("[Worklets] WorkletsModuleProxy is already attached to the RN runtime.");
|
|
89
|
+
}
|
|
90
|
+
if (uiRuntimeStarted_ && bundleModeConfig.has_value()) [[unlikely]] {
|
|
91
|
+
throw std::runtime_error("[Worklets] The Bundle Mode config was already set by startUIRuntimeInBundleModeAOT.");
|
|
92
|
+
}
|
|
93
|
+
if (!uiRuntimeStarted_ && !bundleModeConfig.has_value()) [[unlikely]] {
|
|
94
|
+
throw std::runtime_error(
|
|
95
|
+
"[Worklets] attachToRNRuntime requires a Bundle Mode config unless startUIRuntimeInBundleModeAOT was called.");
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
isDevBundle_ = isDevBundleFromRNRuntime(rnRuntime);
|
|
99
|
+
if (bundleModeConfig.has_value()) {
|
|
100
|
+
bundleModeConfig_ = *bundleModeConfig;
|
|
101
|
+
}
|
|
102
|
+
rnRuntimeProxy_ = std::make_shared<JSIWorkletsModuleProxy>(
|
|
103
|
+
isDevBundle_,
|
|
104
|
+
jsScheduler_,
|
|
105
|
+
uiScheduler_,
|
|
106
|
+
memoryManager_,
|
|
107
|
+
runtimeManager_,
|
|
108
|
+
uiWorkletRuntime_,
|
|
109
|
+
runtimeBindings_,
|
|
110
|
+
networking_,
|
|
111
|
+
bundleModeConfig_,
|
|
112
|
+
unpackerLoader_,
|
|
113
|
+
rnRuntimeStatus_,
|
|
114
|
+
RuntimeData::rnRuntimeId);
|
|
115
|
+
|
|
73
116
|
RNRuntimeWorkletDecorator::decorate(rnRuntime, rnRuntimeProxy_->toOptimizedObject(rnRuntime), jsLogger_);
|
|
74
117
|
}
|
|
75
118
|
|
|
76
119
|
WorkletsModuleProxy::~WorkletsModuleProxy() {
|
|
120
|
+
if (networking_) {
|
|
121
|
+
networking_->abortAll();
|
|
122
|
+
}
|
|
77
123
|
animationFrameBatchinator_.reset();
|
|
78
124
|
uiWorkletRuntime_.reset();
|
|
79
125
|
}
|
|
80
126
|
|
|
127
|
+
void WorkletsModuleProxy::startUIRuntime(const std::shared_ptr<JSIWorkletsModuleProxy> &uiRuntimeProxy) {
|
|
128
|
+
uiWorkletRuntime_->init(uiRuntimeProxy);
|
|
129
|
+
|
|
130
|
+
animationFrameBatchinator_ =
|
|
131
|
+
std::make_shared<AnimationFrameBatchinator>(uiWorkletRuntime_, runtimeBindings_->requestAnimationFrame);
|
|
132
|
+
|
|
133
|
+
UIRuntimeDecorator::decorate(
|
|
134
|
+
uiWorkletRuntime_->getJSIRuntime(), animationFrameBatchinator_->getJsiRequestAnimationFrame());
|
|
135
|
+
|
|
136
|
+
uiRuntimeStarted_ = true;
|
|
137
|
+
}
|
|
138
|
+
|
|
81
139
|
} // namespace worklets
|