@depup/react-native-worklets 0.12.2-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 +5 -5
- 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 +39 -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 +3 -0
- 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 +4 -4
- 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 +1 -29
- 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 +7 -2
- 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 +32 -18
- 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 +1 -44
- package/src/memory/synchronizable.native.ts +38 -4
- package/src/memory/synchronizable.ts +22 -2
- package/src/memory/synchronizableUnpacker.native.ts +23 -4
- 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 -389
- 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 -204
- 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
package/src/types.ts
CHANGED
|
@@ -55,7 +55,7 @@ export type WorkletStackDetails = [
|
|
|
55
55
|
columnOffset: number,
|
|
56
56
|
];
|
|
57
57
|
|
|
58
|
-
type WorkletClosure =
|
|
58
|
+
type WorkletClosure = unknown[];
|
|
59
59
|
|
|
60
60
|
interface WorkletInitData {
|
|
61
61
|
/** Only when bytecode isn't toggled. */
|
|
@@ -69,12 +69,10 @@ interface WorkletInitData {
|
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
interface WorkletProps {
|
|
72
|
-
__closure
|
|
72
|
+
__closure?: WorkletClosure;
|
|
73
73
|
__workletHash: number;
|
|
74
74
|
/** Only in Legacy Eval Mode. */
|
|
75
75
|
__initData?: WorkletInitData;
|
|
76
|
-
/** Only for Handles. */
|
|
77
|
-
__init?: () => unknown;
|
|
78
76
|
/** `__stackDetails` is removed after parsing. */
|
|
79
77
|
__stackDetails?: WorkletStackDetails;
|
|
80
78
|
/** Only in dev builds. */
|
|
@@ -89,7 +87,7 @@ export type WorkletFunction<
|
|
|
89
87
|
export interface WorkletFactory<
|
|
90
88
|
TArgs extends unknown[] = unknown[],
|
|
91
89
|
TReturn = unknown,
|
|
92
|
-
TClosureVariables extends
|
|
90
|
+
TClosureVariables extends unknown[] = unknown[],
|
|
93
91
|
> {
|
|
94
92
|
(closureVariables: TClosureVariables): WorkletFunction<TArgs, TReturn>;
|
|
95
93
|
}
|
|
@@ -121,6 +119,12 @@ type WorkletRuntimeConfigBase = {
|
|
|
121
119
|
* by requestAnimationFrame. If not specified, it defaults to 16 ms.
|
|
122
120
|
*/
|
|
123
121
|
animationQueuePollingRate?: number;
|
|
122
|
+
/**
|
|
123
|
+
* Determines whether the networking API (`fetch`, `XMLHttpRequest` and
|
|
124
|
+
* their supporting globals) is installed on the runtime. Effective only in
|
|
125
|
+
* Bundle Mode. If not specified, it defaults to `true`.
|
|
126
|
+
*/
|
|
127
|
+
enableNetworking?: boolean;
|
|
124
128
|
};
|
|
125
129
|
|
|
126
130
|
/** Configuration object for creating a worklet runtime. */
|
|
@@ -1,389 +0,0 @@
|
|
|
1
|
-
#include <jsi/jsi.h>
|
|
2
|
-
#include <react/debug/react_native_assert.h>
|
|
3
|
-
#include <worklets/SharedItems/Serializable.h>
|
|
4
|
-
#include <worklets/SharedItems/SerializableFactory.h>
|
|
5
|
-
#include <worklets/WorkletRuntime/RuntimeData.h>
|
|
6
|
-
#include <worklets/WorkletRuntime/RuntimeManager.h>
|
|
7
|
-
#include <worklets/WorkletRuntime/WorkletRuntime.h>
|
|
8
|
-
|
|
9
|
-
#include <memory>
|
|
10
|
-
#include <stdexcept>
|
|
11
|
-
#include <string>
|
|
12
|
-
#include <utility>
|
|
13
|
-
|
|
14
|
-
using namespace facebook;
|
|
15
|
-
|
|
16
|
-
namespace worklets {
|
|
17
|
-
|
|
18
|
-
namespace {
|
|
19
|
-
|
|
20
|
-
jsi::Function getValueUnpacker(jsi::Runtime &rt) {
|
|
21
|
-
auto valueUnpacker = rt.global().getProperty(rt, "__valueUnpacker");
|
|
22
|
-
react_native_assert(valueUnpacker.isObject() && "valueUnpacker not found");
|
|
23
|
-
return valueUnpacker.asObject(rt).asFunction(rt);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
void defineOwnDataProperty(jsi::Runtime &rt, const jsi::Object &target, const std::string &key, jsi::Value value) {
|
|
27
|
-
jsi::Object descriptor(rt);
|
|
28
|
-
descriptor.setProperty(rt, "configurable", true);
|
|
29
|
-
descriptor.setProperty(rt, "enumerable", true);
|
|
30
|
-
descriptor.setProperty(rt, "writable", true);
|
|
31
|
-
descriptor.setProperty(rt, "value", std::move(value));
|
|
32
|
-
|
|
33
|
-
const auto objectCtor = rt.global().getPropertyAsObject(rt, "Object");
|
|
34
|
-
const auto defineProperty = objectCtor.getPropertyAsFunction(rt, "defineProperty");
|
|
35
|
-
defineProperty.call(rt, jsi::Value(rt, target), jsi::String::createFromUtf8(rt, key), std::move(descriptor));
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
} // namespace
|
|
39
|
-
|
|
40
|
-
jsi::Value makeSerializableClone(
|
|
41
|
-
jsi::Runtime &rt,
|
|
42
|
-
const jsi::Value &value,
|
|
43
|
-
const jsi::Value &shouldRetainRemote,
|
|
44
|
-
const jsi::Value &nativeStateSource) {
|
|
45
|
-
std::shared_ptr<Serializable> serializable;
|
|
46
|
-
if (value.isObject()) {
|
|
47
|
-
auto object = value.asObject(rt);
|
|
48
|
-
if (!object.getProperty(rt, "__workletHash").isUndefined()) {
|
|
49
|
-
// We pass `false` because this function is invoked only
|
|
50
|
-
// by `makeSerializableCloneOnUIRecursive` which doesn't
|
|
51
|
-
// make Retaining Serializables.
|
|
52
|
-
return makeSerializableWorklet(rt, object, false);
|
|
53
|
-
} else if (!object.getProperty(rt, "__init").isUndefined()) {
|
|
54
|
-
return makeSerializableInitializer(rt, object);
|
|
55
|
-
} else if (object.isFunction(rt)) {
|
|
56
|
-
auto fun = object.asFunction(rt);
|
|
57
|
-
if (fun.isHostFunction(rt)) {
|
|
58
|
-
auto name = fun.getProperty(rt, "name").asString(rt).utf8(rt);
|
|
59
|
-
return makeSerializableHostFunction(
|
|
60
|
-
rt, fun.getHostFunction(rt), name, fun.getProperty(rt, "length").asNumber());
|
|
61
|
-
} else {
|
|
62
|
-
throw std::runtime_error(
|
|
63
|
-
"[Worklets] Cloning remote functions from Worklet Runtimes is only available in Bundle Mode.");
|
|
64
|
-
}
|
|
65
|
-
} else if (object.isArray(rt)) {
|
|
66
|
-
if (shouldRetainRemote.isBool() && shouldRetainRemote.getBool()) {
|
|
67
|
-
serializable = std::make_shared<RetainingSerializable<SerializableArray>>(rt, object.asArray(rt));
|
|
68
|
-
} else {
|
|
69
|
-
serializable = std::make_shared<SerializableArray>(rt, object.asArray(rt));
|
|
70
|
-
}
|
|
71
|
-
} else if (object.isArrayBuffer(rt)) {
|
|
72
|
-
serializable = std::make_shared<SerializableArrayBuffer>(rt, object.getArrayBuffer(rt));
|
|
73
|
-
} else if (object.isHostObject(rt)) {
|
|
74
|
-
if (object.isHostObject<SerializableJSRef>(rt)) {
|
|
75
|
-
return object;
|
|
76
|
-
}
|
|
77
|
-
serializable = std::make_shared<SerializableHostObject>(rt, object.getHostObject(rt));
|
|
78
|
-
} else {
|
|
79
|
-
if (shouldRetainRemote.isBool() && shouldRetainRemote.getBool()) {
|
|
80
|
-
serializable = std::make_shared<RetainingSerializable<SerializableObject>>(rt, object, nativeStateSource);
|
|
81
|
-
} else {
|
|
82
|
-
serializable = std::make_shared<SerializableObject>(rt, object, nativeStateSource);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
} else if (value.isString()) {
|
|
86
|
-
serializable = std::make_shared<SerializableString>(value.asString(rt).utf8(rt));
|
|
87
|
-
} else if (value.isUndefined()) {
|
|
88
|
-
serializable = std::make_shared<SerializableScalar>();
|
|
89
|
-
} else if (value.isNull()) {
|
|
90
|
-
serializable = std::make_shared<SerializableScalar>(nullptr);
|
|
91
|
-
} else if (value.isBool()) {
|
|
92
|
-
serializable = std::make_shared<SerializableScalar>(value.getBool());
|
|
93
|
-
} else if (value.isNumber()) {
|
|
94
|
-
serializable = std::make_shared<SerializableScalar>(value.getNumber());
|
|
95
|
-
} else if (value.isBigInt()) {
|
|
96
|
-
serializable = std::make_shared<SerializableBigInt>(rt, value.getBigInt(rt));
|
|
97
|
-
} else if (value.isSymbol()) {
|
|
98
|
-
// TODO: this is only a placeholder implementation, here we replace symbols
|
|
99
|
-
// with strings in order to make certain objects to be captured. There isn't
|
|
100
|
-
// yet any use-case for using symbols on the UI runtime so it is fine to keep
|
|
101
|
-
// it like this for now.
|
|
102
|
-
serializable = std::make_shared<SerializableString>(value.getSymbol(rt).toString(rt));
|
|
103
|
-
} else {
|
|
104
|
-
throw std::runtime_error("[Worklets] Attempted to convert an unsupported value type.");
|
|
105
|
-
}
|
|
106
|
-
return SerializableJSRef::newNativeStateObject(rt, serializable);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
std::shared_ptr<Serializable> extractSerializableOrThrow(
|
|
110
|
-
jsi::Runtime &rt,
|
|
111
|
-
const jsi::Value &maybeSerializableValue,
|
|
112
|
-
const std::string &errorMessage) {
|
|
113
|
-
if (maybeSerializableValue.isObject()) {
|
|
114
|
-
auto object = maybeSerializableValue.getObject(rt);
|
|
115
|
-
return extractSerializableOrThrow(rt, object, errorMessage);
|
|
116
|
-
} else if (maybeSerializableValue.isUndefined()) {
|
|
117
|
-
return Serializable::undefined();
|
|
118
|
-
}
|
|
119
|
-
throw std::runtime_error(errorMessage);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
std::shared_ptr<Serializable> extractSerializableOrThrow(
|
|
123
|
-
jsi::Runtime &rt,
|
|
124
|
-
const jsi::Object &maybeSerializableValue,
|
|
125
|
-
const std::string &errorMessage) {
|
|
126
|
-
if (maybeSerializableValue.hasNativeState(rt)) {
|
|
127
|
-
auto nativeState = maybeSerializableValue.getNativeState(rt);
|
|
128
|
-
return std::dynamic_pointer_cast<SerializableJSRef>(nativeState)->value();
|
|
129
|
-
}
|
|
130
|
-
throw std::runtime_error(errorMessage);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
Serializable::~Serializable() = default;
|
|
134
|
-
|
|
135
|
-
std::shared_ptr<Serializable> Serializable::undefined() {
|
|
136
|
-
static auto undefined = std::make_shared<SerializableScalar>();
|
|
137
|
-
return undefined;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
SerializableJSRef::~SerializableJSRef() = default;
|
|
141
|
-
|
|
142
|
-
SerializableArray::SerializableArray(jsi::Runtime &rt, const jsi::Array &array) : Serializable(ValueType::ArrayType) {
|
|
143
|
-
auto size = array.size(rt);
|
|
144
|
-
data_.reserve(size);
|
|
145
|
-
for (size_t i = 0; i < size; i++) {
|
|
146
|
-
data_.push_back(extractSerializableOrThrow(rt, array.getValueAtIndex(rt, i)));
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
jsi::Value SerializableArray::toJSValue(jsi::Runtime &rt) {
|
|
151
|
-
auto size = data_.size();
|
|
152
|
-
auto ary = jsi::Array(rt, size);
|
|
153
|
-
for (size_t i = 0; i < size; i++) {
|
|
154
|
-
ary.setValueAtIndex(rt, i, data_[i]->toJSValue(rt));
|
|
155
|
-
}
|
|
156
|
-
return ary;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
jsi::Value SerializableArrayBuffer::toJSValue(jsi::Runtime &rt) {
|
|
160
|
-
auto size = static_cast<int>(data_.size());
|
|
161
|
-
auto arrayBuffer =
|
|
162
|
-
rt.global().getPropertyAsFunction(rt, "ArrayBuffer").callAsConstructor(rt, size).getObject(rt).getArrayBuffer(rt);
|
|
163
|
-
memcpy(arrayBuffer.data(rt), data_.data(), size);
|
|
164
|
-
if (!metadata_.has_value()) {
|
|
165
|
-
return arrayBuffer;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
auto constructor = rt.global().getPropertyAsFunction(rt, metadata_->typeName.c_str());
|
|
169
|
-
return constructor.callAsConstructor(
|
|
170
|
-
rt, arrayBuffer, static_cast<double>(metadata_->byteOffset), static_cast<double>(metadata_->length));
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
SerializableObject::SerializableObject(jsi::Runtime &rt, const jsi::Object &object)
|
|
174
|
-
: Serializable(ValueType::ObjectType) {
|
|
175
|
-
auto propertyNames = object.getPropertyNames(rt);
|
|
176
|
-
auto size = propertyNames.size(rt);
|
|
177
|
-
data_.reserve(size);
|
|
178
|
-
for (size_t i = 0; i < size; i++) {
|
|
179
|
-
auto key = propertyNames.getValueAtIndex(rt, i).asString(rt);
|
|
180
|
-
auto value = extractSerializableOrThrow(rt, object.getProperty(rt, key));
|
|
181
|
-
data_.emplace_back(key.utf8(rt), value);
|
|
182
|
-
}
|
|
183
|
-
if (object.hasNativeState(rt)) {
|
|
184
|
-
nativeState_ = object.getNativeState(rt);
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
SerializableObject::SerializableObject(jsi::Runtime &rt, const jsi::Object &object, const jsi::Value &nativeStateSource)
|
|
189
|
-
: SerializableObject(rt, object) {
|
|
190
|
-
if (nativeStateSource.isObject() && nativeStateSource.asObject(rt).hasNativeState(rt)) {
|
|
191
|
-
nativeState_ = nativeStateSource.asObject(rt).getNativeState(rt);
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
jsi::Value SerializableObject::toJSValue(jsi::Runtime &rt) {
|
|
196
|
-
auto obj = jsi::Object(rt);
|
|
197
|
-
for (const auto &i : data_) {
|
|
198
|
-
if (i.first == "__proto__") {
|
|
199
|
-
defineOwnDataProperty(rt, obj, i.first, i.second->toJSValue(rt));
|
|
200
|
-
} else {
|
|
201
|
-
obj.setProperty(rt, jsi::String::createFromUtf8(rt, i.first), i.second->toJSValue(rt));
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
if (nativeState_ != nullptr) {
|
|
205
|
-
obj.setNativeState(rt, nativeState_);
|
|
206
|
-
}
|
|
207
|
-
return obj;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
SerializableMap::SerializableMap(jsi::Runtime &rt, const jsi::Array &keys, const jsi::Array &values)
|
|
211
|
-
: Serializable(ValueType::MapType) {
|
|
212
|
-
auto size = keys.size(rt);
|
|
213
|
-
react_native_assert(size == values.size(rt) && "Keys and values arrays must have the same size.");
|
|
214
|
-
data_.reserve(size);
|
|
215
|
-
for (size_t i = 0; i < size; i++) {
|
|
216
|
-
auto key = extractSerializableOrThrow(rt, keys.getValueAtIndex(rt, i));
|
|
217
|
-
auto value = extractSerializableOrThrow(rt, values.getValueAtIndex(rt, i));
|
|
218
|
-
data_.emplace_back(key, value);
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
jsi::Value SerializableMap::toJSValue(jsi::Runtime &rt) {
|
|
223
|
-
const auto keyValues = jsi::Array(rt, data_.size());
|
|
224
|
-
for (size_t i = 0, size = data_.size(); i < size; i++) {
|
|
225
|
-
const auto pair = jsi::Array(rt, 2);
|
|
226
|
-
pair.setValueAtIndex(rt, 0, data_[i].first->toJSValue(rt));
|
|
227
|
-
pair.setValueAtIndex(rt, 1, data_[i].second->toJSValue(rt));
|
|
228
|
-
keyValues.setValueAtIndex(rt, i, std::move(pair));
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
const auto &global = rt.global();
|
|
232
|
-
auto map = global.getPropertyAsFunction(rt, "Map").callAsConstructor(rt, std::move(keyValues));
|
|
233
|
-
|
|
234
|
-
return map;
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
SerializableSet::SerializableSet(jsi::Runtime &rt, const jsi::Array &values) : Serializable(ValueType::SetType) {
|
|
238
|
-
auto size = values.size(rt);
|
|
239
|
-
data_.reserve(size);
|
|
240
|
-
for (size_t i = 0; i < size; i++) {
|
|
241
|
-
data_.push_back(extractSerializableOrThrow(rt, values.getValueAtIndex(rt, i)));
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
jsi::Value SerializableSet::toJSValue(jsi::Runtime &rt) {
|
|
246
|
-
const auto values = jsi::Array(rt, data_.size());
|
|
247
|
-
for (size_t i = 0, size = data_.size(); i < size; i++) {
|
|
248
|
-
values.setValueAtIndex(rt, i, data_[i]->toJSValue(rt));
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
const auto &global = rt.global();
|
|
252
|
-
auto set = global.getPropertyAsFunction(rt, "Set").callAsConstructor(rt, std::move(values));
|
|
253
|
-
|
|
254
|
-
return set;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
jsi::Value SerializableRegExp::toJSValue(jsi::Runtime &rt) {
|
|
258
|
-
return rt.global()
|
|
259
|
-
.getPropertyAsFunction(rt, "RegExp")
|
|
260
|
-
.callAsConstructor(rt, jsi::String::createFromUtf8(rt, pattern_), jsi::String::createFromUtf8(rt, flags_));
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
jsi::Value SerializableError::toJSValue(jsi::Runtime &rt) {
|
|
264
|
-
auto error = rt.global()
|
|
265
|
-
.getPropertyAsFunction(rt, "Error")
|
|
266
|
-
.callAsConstructor(rt, jsi::String::createFromUtf8(rt, message_))
|
|
267
|
-
.getObject(rt);
|
|
268
|
-
|
|
269
|
-
error.setProperty(rt, "name", jsi::String::createFromUtf8(rt, name_));
|
|
270
|
-
|
|
271
|
-
if (stack_.has_value()) {
|
|
272
|
-
error.setProperty(rt, "stack", jsi::String::createFromUtf8(rt, stack_.value()));
|
|
273
|
-
} else {
|
|
274
|
-
error.setProperty(rt, "stack", jsi::String::createFromUtf8(rt, ""));
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
return error;
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
jsi::Value SerializableHostObject::toJSValue(jsi::Runtime &rt) {
|
|
281
|
-
return jsi::Object::createFromHostObject(rt, hostObject_);
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
jsi::Value SerializableHostFunction::toJSValue(jsi::Runtime &rt) {
|
|
285
|
-
return jsi::Function::createFromHostFunction(rt, jsi::PropNameID::forUtf8(rt, name_), paramCount_, hostFunction_);
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
jsi::Value SerializableWorklet::toJSValue(jsi::Runtime &rt) {
|
|
289
|
-
react_native_assert(
|
|
290
|
-
std::any_of(data_.cbegin(), data_.cend(), [](const auto &item) { return item.first == "__workletHash"; }) &&
|
|
291
|
-
"SerializableWorklet doesn't have `__workletHash` property");
|
|
292
|
-
jsi::Value obj = SerializableObject::toJSValue(rt);
|
|
293
|
-
return getValueUnpacker(rt).call(rt, obj, jsi::String::createFromAscii(rt, "Worklet"));
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
jsi::Value SerializableImport::toJSValue(jsi::Runtime &rt) {
|
|
297
|
-
/**
|
|
298
|
-
* The only way to obtain a module in runtime is to use the Metro's require
|
|
299
|
-
* method implementation, which is injected into the global object as `__r`.
|
|
300
|
-
*/
|
|
301
|
-
const auto metroRequire = rt.global().getProperty(rt, "__r");
|
|
302
|
-
if (metroRequire.isUndefined()) {
|
|
303
|
-
return jsi::Value::undefined();
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
const auto imported = jsi::String::createFromUtf8(rt, imported_);
|
|
307
|
-
return metroRequire.asObject(rt).asFunction(rt).call(rt, source_).asObject(rt).getProperty(rt, imported);
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
jsi::Value SerializableInitializer::toJSValue(jsi::Runtime &rt) {
|
|
311
|
-
if (remoteValue_ == nullptr) {
|
|
312
|
-
auto initObj = initializer_->toJSValue(rt);
|
|
313
|
-
auto value = std::make_unique<jsi::Value>(
|
|
314
|
-
getValueUnpacker(rt).call(rt, initObj, jsi::String::createFromAscii(rt, "Handle")));
|
|
315
|
-
|
|
316
|
-
// We are locking the initialization here since the thread that is
|
|
317
|
-
// initializing can be preempted on runtime lock. E.g.
|
|
318
|
-
// UI thread can be preempted on initialization of a shared value and then
|
|
319
|
-
// JS thread can try to access the shared value, locking the whole runtime.
|
|
320
|
-
// If we put the lock on `getValueUnpacker` part (basically any part that
|
|
321
|
-
// requires runtime) we would get a deadlock since UI thread would never
|
|
322
|
-
// release it.
|
|
323
|
-
std::unique_lock<std::mutex> lock(initializationMutex_);
|
|
324
|
-
if (remoteValue_ == nullptr) {
|
|
325
|
-
remoteValue_ = std::move(value);
|
|
326
|
-
remoteRuntime_ = &rt;
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
if (&rt == remoteRuntime_) {
|
|
330
|
-
return jsi::Value(rt, *remoteValue_);
|
|
331
|
-
}
|
|
332
|
-
auto initObj = initializer_->toJSValue(rt);
|
|
333
|
-
return getValueUnpacker(rt).call(rt, initObj, jsi::String::createFromAscii(rt, "Handle"));
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
jsi::Value SerializableString::toJSValue(jsi::Runtime &rt) {
|
|
337
|
-
return jsi::String::createFromUtf8(rt, data_);
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
jsi::Value SerializableBigInt::toJSValue(jsi::Runtime &rt) {
|
|
341
|
-
if (fastValue_.has_value()) {
|
|
342
|
-
return jsi::BigInt::fromInt64(rt, fastValue_.value());
|
|
343
|
-
} else {
|
|
344
|
-
return rt.global().getPropertyAsFunction(rt, "BigInt").call(rt, jsi::String::createFromUtf8(rt, slowValue_));
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
jsi::Value SerializableScalar::toJSValue(jsi::Runtime &) {
|
|
349
|
-
switch (valueType_) {
|
|
350
|
-
case Serializable::ValueType::UndefinedType:
|
|
351
|
-
return jsi::Value();
|
|
352
|
-
case Serializable::ValueType::NullType:
|
|
353
|
-
return jsi::Value(nullptr);
|
|
354
|
-
case Serializable::ValueType::BooleanType:
|
|
355
|
-
return jsi::Value(data_.boolean);
|
|
356
|
-
case Serializable::ValueType::NumberType:
|
|
357
|
-
return jsi::Value(data_.number);
|
|
358
|
-
default:
|
|
359
|
-
throw std::runtime_error("[Worklets] Attempted to convert object that's not of a scalar type.");
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
jsi::Value SerializableTurboModuleLike::toJSValue(jsi::Runtime &rt) {
|
|
364
|
-
auto obj = properties_->toJSValue(rt).asObject(rt);
|
|
365
|
-
const auto prototype = proto_->toJSValue(rt);
|
|
366
|
-
rt.global().getPropertyAsObject(rt, "Object").getPropertyAsFunction(rt, "setPrototypeOf").call(rt, obj, prototype);
|
|
367
|
-
|
|
368
|
-
return obj;
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
jsi::Function getCustomSerializableUnpacker(jsi::Runtime &rt) {
|
|
372
|
-
auto customSerializableUnpacker = rt.global().getProperty(rt, "__customSerializableUnpacker");
|
|
373
|
-
react_native_assert(customSerializableUnpacker.isObject() && "customSerializableUnpacker not found");
|
|
374
|
-
return customSerializableUnpacker.asObject(rt).asFunction(rt);
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
jsi::Value CustomSerializable::toJSValue(jsi::Runtime &rt) {
|
|
378
|
-
try {
|
|
379
|
-
auto unpack = getCustomSerializableUnpacker(rt);
|
|
380
|
-
auto data = data_->toJSValue(rt);
|
|
381
|
-
|
|
382
|
-
return unpack.call(rt, data, jsi::Value(typeId_));
|
|
383
|
-
} catch (jsi::JSError &e) {
|
|
384
|
-
throw std::runtime_error(
|
|
385
|
-
std::string("[Worklets] Failed to deserialize CustomSerializable. Reason: ") + e.getMessage());
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
} // namespace worklets
|
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
#include <jsi/jsi.h>
|
|
2
|
-
#include <worklets/SharedItems/SerializableFactory.h>
|
|
3
|
-
#include <worklets/SharedItems/SerializableRemoteFunction.h>
|
|
4
|
-
|
|
5
|
-
#include <memory>
|
|
6
|
-
#include <utility>
|
|
7
|
-
|
|
8
|
-
namespace worklets {
|
|
9
|
-
|
|
10
|
-
jsi::Value makeSerializableString(jsi::Runtime &rt, const jsi::String &string) {
|
|
11
|
-
const auto serializable = std::make_shared<SerializableString>(string.utf8(rt));
|
|
12
|
-
return SerializableJSRef::newNativeStateObject(rt, serializable);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
jsi::Value makeSerializableNumber(jsi::Runtime &rt, double number) {
|
|
16
|
-
const auto serializable = std::make_shared<SerializableScalar>(number);
|
|
17
|
-
return SerializableJSRef::newNativeStateObject(rt, serializable);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
jsi::Value makeSerializableBoolean(jsi::Runtime &rt, bool boolean) {
|
|
21
|
-
const auto serializable = std::make_shared<SerializableScalar>(boolean);
|
|
22
|
-
return SerializableJSRef::newNativeStateObject(rt, serializable);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
jsi::Value makeSerializableBigInt(jsi::Runtime &rt, const jsi::BigInt &bigint) {
|
|
26
|
-
const auto serializable = std::make_shared<SerializableBigInt>(rt, bigint);
|
|
27
|
-
return SerializableJSRef::newNativeStateObject(rt, serializable);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
jsi::Value makeSerializableUndefined(jsi::Runtime &rt) {
|
|
31
|
-
const auto serializable = std::make_shared<SerializableScalar>();
|
|
32
|
-
return SerializableJSRef::newNativeStateObject(rt, serializable);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
jsi::Value makeSerializableNull(jsi::Runtime &rt) {
|
|
36
|
-
const auto serializable = std::make_shared<SerializableScalar>(nullptr);
|
|
37
|
-
return SerializableJSRef::newNativeStateObject(rt, serializable);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
jsi::Value makeSerializableWorklet(jsi::Runtime &rt, const jsi::Object &object, const bool &shouldRetainRemote) {
|
|
41
|
-
std::shared_ptr<Serializable> serializable;
|
|
42
|
-
if (shouldRetainRemote) {
|
|
43
|
-
serializable = std::make_shared<RetainingSerializable<SerializableWorklet>>(rt, object);
|
|
44
|
-
} else {
|
|
45
|
-
serializable = std::make_shared<SerializableWorklet>(rt, object);
|
|
46
|
-
}
|
|
47
|
-
return SerializableJSRef::newNativeStateObject(rt, serializable);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
jsi::Value makeSerializableInitializer(jsi::Runtime &rt, const jsi::Object &initializerObject) {
|
|
51
|
-
const auto serializable = std::make_shared<SerializableInitializer>(rt, initializerObject);
|
|
52
|
-
return SerializableJSRef::newNativeStateObject(rt, serializable);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
jsi::Value makeSerializableHostFunction(
|
|
56
|
-
jsi::Runtime &rt,
|
|
57
|
-
const jsi::HostFunctionType &function,
|
|
58
|
-
const std::string &name,
|
|
59
|
-
unsigned int paramCount) {
|
|
60
|
-
auto serializable = std::make_shared<SerializableHostFunction>(function, name, paramCount);
|
|
61
|
-
return SerializableJSRef::newNativeStateObject(rt, serializable);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
jsi::Value makeRNRuntimeSerializableRemoteFunction(
|
|
65
|
-
jsi::Runtime &rnRuntime,
|
|
66
|
-
const std::string &name,
|
|
67
|
-
const jsi::Function &function,
|
|
68
|
-
const std::shared_ptr<JSScheduler> &jsScheduler,
|
|
69
|
-
const std::shared_ptr<RNRuntimeStatus> &rnRuntimeStatus) {
|
|
70
|
-
auto serializable = std::make_shared<SerializableRemoteFunction>(
|
|
71
|
-
rnRuntime,
|
|
72
|
-
name,
|
|
73
|
-
jsi::Value(rnRuntime, function).getObject(rnRuntime).getFunction(rnRuntime),
|
|
74
|
-
jsScheduler,
|
|
75
|
-
rnRuntimeStatus);
|
|
76
|
-
return SerializableJSRef::newNativeStateObject(rnRuntime, serializable);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
jsi::Value makeWorkletRuntimeSerializableRemoteFunction(
|
|
80
|
-
jsi::Runtime &workletRuntime,
|
|
81
|
-
const std::string &name,
|
|
82
|
-
const jsi::Function &function,
|
|
83
|
-
RuntimeData::RuntimeId hostRuntimeId) {
|
|
84
|
-
auto serializable = std::make_shared<SerializableRemoteFunction>(
|
|
85
|
-
workletRuntime,
|
|
86
|
-
name,
|
|
87
|
-
jsi::Value(workletRuntime, function).getObject(workletRuntime).getFunction(workletRuntime),
|
|
88
|
-
hostRuntimeId);
|
|
89
|
-
return SerializableJSRef::newNativeStateObject(workletRuntime, serializable);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
jsi::Value makeSerializableArray(jsi::Runtime &rt, const jsi::Array &array, const jsi::Value &shouldRetainRemote) {
|
|
93
|
-
std::shared_ptr<Serializable> serializable;
|
|
94
|
-
if (shouldRetainRemote.isBool() && shouldRetainRemote.getBool()) {
|
|
95
|
-
serializable = std::make_shared<RetainingSerializable<SerializableArray>>(rt, array);
|
|
96
|
-
} else {
|
|
97
|
-
serializable = std::make_shared<SerializableArray>(rt, array);
|
|
98
|
-
}
|
|
99
|
-
return SerializableJSRef::newNativeStateObject(rt, serializable);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
jsi::Value makeSerializableArrayBuffer(
|
|
103
|
-
jsi::Runtime &rt,
|
|
104
|
-
const jsi::ArrayBuffer &arrayBuffer,
|
|
105
|
-
std::optional<ArrayBufferMetadata> metadata) {
|
|
106
|
-
auto serializable = std::make_shared<SerializableArrayBuffer>(rt, arrayBuffer, std::move(metadata));
|
|
107
|
-
return SerializableJSRef::newNativeStateObject(rt, serializable);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
jsi::Value makeSerializableMap(jsi::Runtime &rt, const jsi::Array &keys, const jsi::Array &values) {
|
|
111
|
-
auto serializable = std::make_shared<SerializableMap>(rt, keys, values);
|
|
112
|
-
return SerializableJSRef::newNativeStateObject(rt, serializable);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
jsi::Value makeSerializableSet(jsi::Runtime &rt, const jsi::Array &values) {
|
|
116
|
-
auto serializable = std::make_shared<SerializableSet>(rt, values);
|
|
117
|
-
return SerializableJSRef::newNativeStateObject(rt, serializable);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
jsi::Value makeSerializableError(
|
|
121
|
-
jsi::Runtime &rt,
|
|
122
|
-
const std::string &name,
|
|
123
|
-
const std::string &message,
|
|
124
|
-
const std::optional<std::string> &stack) {
|
|
125
|
-
auto serializable = std::make_shared<SerializableError>(name, message, stack);
|
|
126
|
-
return SerializableJSRef::newNativeStateObject(rt, serializable);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
jsi::Value makeSerializableRegExp(jsi::Runtime &rt, const std::string &pattern, const std::string &flags) {
|
|
130
|
-
auto serializable = std::make_shared<SerializableRegExp>(pattern, flags);
|
|
131
|
-
return SerializableJSRef::newNativeStateObject(rt, serializable);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
jsi::Value makeSerializableHostObject(jsi::Runtime &rt, const std::shared_ptr<jsi::HostObject> &value) {
|
|
135
|
-
const auto serializable = std::make_shared<SerializableHostObject>(rt, value);
|
|
136
|
-
return SerializableJSRef::newNativeStateObject(rt, serializable);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
jsi::Value makeSerializableTurboModuleLike(
|
|
140
|
-
jsi::Runtime &rt,
|
|
141
|
-
const jsi::Object &object,
|
|
142
|
-
const std::shared_ptr<jsi::HostObject> &proto) {
|
|
143
|
-
const auto serializable = std::make_shared<SerializableTurboModuleLike>(rt, object, proto);
|
|
144
|
-
return SerializableJSRef::newNativeStateObject(rt, serializable);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
jsi::Value makeSerializableImport(jsi::Runtime &rt, const double source, const jsi::String &imported) {
|
|
148
|
-
auto serializable = std::make_shared<SerializableImport>(rt, source, imported);
|
|
149
|
-
return SerializableJSRef::newNativeStateObject(rt, serializable);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
jsi::Value makeSerializableObject(
|
|
153
|
-
jsi::Runtime &rt,
|
|
154
|
-
jsi::Object object,
|
|
155
|
-
bool shouldRetainRemote,
|
|
156
|
-
const jsi::Value &nativeStateSource) {
|
|
157
|
-
std::shared_ptr<Serializable> serializable;
|
|
158
|
-
if (shouldRetainRemote) {
|
|
159
|
-
serializable = std::make_shared<RetainingSerializable<SerializableObject>>(rt, object, nativeStateSource);
|
|
160
|
-
} else {
|
|
161
|
-
serializable = std::make_shared<SerializableObject>(rt, object, nativeStateSource);
|
|
162
|
-
}
|
|
163
|
-
return SerializableJSRef::newNativeStateObject(rt, serializable);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
jsi::Value makeCustomSerializable(jsi::Runtime &rt, const jsi::Value &data, const int typeId) {
|
|
167
|
-
auto rawData = extractSerializableOrThrow(rt, data, "[Worklets] Data must be a Serializable object.");
|
|
168
|
-
auto customSerializable = std::make_shared<CustomSerializable>(rawData, typeId);
|
|
169
|
-
return SerializableJSRef::newNativeStateObject(rt, customSerializable);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
} // namespace worklets
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include <jsi/jsi.h>
|
|
4
|
-
#include <worklets/SharedItems/Serializable.h>
|
|
5
|
-
|
|
6
|
-
#include <memory>
|
|
7
|
-
#include <optional>
|
|
8
|
-
#include <string>
|
|
9
|
-
|
|
10
|
-
namespace worklets {
|
|
11
|
-
|
|
12
|
-
class RNRuntimeStatus;
|
|
13
|
-
|
|
14
|
-
jsi::Value makeSerializableString(jsi::Runtime &rt, const jsi::String &string);
|
|
15
|
-
|
|
16
|
-
jsi::Value makeSerializableNumber(jsi::Runtime &rt, double number);
|
|
17
|
-
|
|
18
|
-
jsi::Value makeSerializableBoolean(jsi::Runtime &rt, bool boolean);
|
|
19
|
-
|
|
20
|
-
jsi::Value makeSerializableBigInt(jsi::Runtime &rt, const jsi::BigInt &bigint);
|
|
21
|
-
|
|
22
|
-
jsi::Value makeSerializableUndefined(jsi::Runtime &rt);
|
|
23
|
-
|
|
24
|
-
jsi::Value makeSerializableNull(jsi::Runtime &rt);
|
|
25
|
-
|
|
26
|
-
jsi::Value makeSerializableTurboModuleLike(
|
|
27
|
-
jsi::Runtime &rt,
|
|
28
|
-
const jsi::Object &object,
|
|
29
|
-
const std::shared_ptr<jsi::HostObject> &proto);
|
|
30
|
-
|
|
31
|
-
jsi::Value makeSerializableObject(
|
|
32
|
-
jsi::Runtime &rt,
|
|
33
|
-
jsi::Object object,
|
|
34
|
-
bool shouldRetainRemote,
|
|
35
|
-
const jsi::Value &nativeStateSource);
|
|
36
|
-
|
|
37
|
-
jsi::Value makeSerializableImport(jsi::Runtime &rt, double source, const jsi::String &imported);
|
|
38
|
-
|
|
39
|
-
jsi::Value makeSerializableHostObject(jsi::Runtime &rt, const std::shared_ptr<jsi::HostObject> &value);
|
|
40
|
-
|
|
41
|
-
jsi::Value makeSerializableArray(jsi::Runtime &rt, const jsi::Array &array, const jsi::Value &shouldRetainRemote);
|
|
42
|
-
|
|
43
|
-
jsi::Value makeSerializableArrayBuffer(
|
|
44
|
-
jsi::Runtime &rt,
|
|
45
|
-
const jsi::ArrayBuffer &arrayBuffer,
|
|
46
|
-
std::optional<ArrayBufferMetadata> metadata = std::nullopt);
|
|
47
|
-
|
|
48
|
-
jsi::Value makeSerializableMap(jsi::Runtime &rt, const jsi::Array &keys, const jsi::Array &values);
|
|
49
|
-
|
|
50
|
-
jsi::Value makeSerializableSet(jsi::Runtime &rt, const jsi::Array &values);
|
|
51
|
-
|
|
52
|
-
jsi::Value makeSerializableError(
|
|
53
|
-
jsi::Runtime &rt,
|
|
54
|
-
const std::string &name,
|
|
55
|
-
const std::string &message,
|
|
56
|
-
const std::optional<std::string> &stack);
|
|
57
|
-
|
|
58
|
-
jsi::Value makeSerializableRegExp(jsi::Runtime &rt, const std::string &pattern, const std::string &flags);
|
|
59
|
-
|
|
60
|
-
jsi::Value makeSerializableInitializer(jsi::Runtime &rt, const jsi::Object &initializerObject);
|
|
61
|
-
|
|
62
|
-
jsi::Value makeSerializableHostFunction(
|
|
63
|
-
jsi::Runtime &rt,
|
|
64
|
-
const jsi::HostFunctionType &function,
|
|
65
|
-
const std::string &name,
|
|
66
|
-
unsigned int paramCount);
|
|
67
|
-
|
|
68
|
-
jsi::Value makeRNRuntimeSerializableRemoteFunction(
|
|
69
|
-
jsi::Runtime &rnRuntime,
|
|
70
|
-
const std::string &name,
|
|
71
|
-
const jsi::Function &function,
|
|
72
|
-
const std::shared_ptr<JSScheduler> &jsScheduler,
|
|
73
|
-
const std::shared_ptr<RNRuntimeStatus> &rnRuntimeStatus);
|
|
74
|
-
|
|
75
|
-
jsi::Value makeWorkletRuntimeSerializableRemoteFunction(
|
|
76
|
-
jsi::Runtime &workletRuntime,
|
|
77
|
-
const std::string &name,
|
|
78
|
-
const jsi::Function &function,
|
|
79
|
-
RuntimeData::RuntimeId hostRuntimeId);
|
|
80
|
-
|
|
81
|
-
jsi::Value makeSerializableWorklet(jsi::Runtime &rt, const jsi::Object &object, const bool &shouldRetainRemote);
|
|
82
|
-
|
|
83
|
-
jsi::Value makeCustomSerializable(jsi::Runtime &rt, const jsi::Value &data, int typeId);
|
|
84
|
-
|
|
85
|
-
} // namespace worklets
|