@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
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
#include <worklets/Networking/NetworkingInstaller.h>
|
|
2
|
+
#include <worklets/Networking/TextDecoding.h>
|
|
3
|
+
#include <worklets/Tools/WorkletsJSIUtils.h>
|
|
4
|
+
|
|
5
|
+
#include <cmath>
|
|
6
|
+
#include <cstdint>
|
|
7
|
+
#include <memory>
|
|
8
|
+
#include <string>
|
|
9
|
+
|
|
10
|
+
namespace worklets {
|
|
11
|
+
|
|
12
|
+
namespace {
|
|
13
|
+
|
|
14
|
+
class NetworkingRuntimeGuard : public jsi::HostObject {
|
|
15
|
+
public:
|
|
16
|
+
NetworkingRuntimeGuard(std::weak_ptr<Networking> weakNetworking, const RuntimeData::RuntimeId runtimeId)
|
|
17
|
+
: weakNetworking_(std::move(weakNetworking)), runtimeId_(runtimeId) {}
|
|
18
|
+
|
|
19
|
+
~NetworkingRuntimeGuard() override {
|
|
20
|
+
if (const auto networking = weakNetworking_.lock()) {
|
|
21
|
+
networking->abortAllForRuntime(runtimeId_);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
private:
|
|
26
|
+
const std::weak_ptr<Networking> weakNetworking_;
|
|
27
|
+
const RuntimeData::RuntimeId runtimeId_;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
// https://encoding.spec.whatwg.org/#decode - a BOM overrides the declared
|
|
31
|
+
// encoding, so it is sniffed before the label is consulted.
|
|
32
|
+
std::string decodeWithLabel(
|
|
33
|
+
const std::shared_ptr<Networking> &networking,
|
|
34
|
+
const uint8_t *data,
|
|
35
|
+
size_t size,
|
|
36
|
+
const std::string &label) {
|
|
37
|
+
if (size >= 2 && data[0] == 0xFE && data[1] == 0xFF) {
|
|
38
|
+
return text::decodeUtf16(data + 2, size - 2, /*littleEndian*/ false);
|
|
39
|
+
}
|
|
40
|
+
if (size >= 2 && data[0] == 0xFF && data[1] == 0xFE) {
|
|
41
|
+
return text::decodeUtf16(data + 2, size - 2, /*littleEndian*/ true);
|
|
42
|
+
}
|
|
43
|
+
if (size >= 3 && data[0] == 0xEF && data[1] == 0xBB && data[2] == 0xBF) {
|
|
44
|
+
data += 3;
|
|
45
|
+
size -= 3;
|
|
46
|
+
return text::decodeUtf8(data, size);
|
|
47
|
+
}
|
|
48
|
+
if (text::isUtf8Label(label)) {
|
|
49
|
+
return text::decodeUtf8(data, size);
|
|
50
|
+
}
|
|
51
|
+
if (text::isWindows1252Label(label)) {
|
|
52
|
+
return text::decodeWindows1252(data, size);
|
|
53
|
+
}
|
|
54
|
+
if (auto decoded = networking->decodeTextWithPlatform(data, size, label)) {
|
|
55
|
+
return text::toValidUtf8(*decoded);
|
|
56
|
+
}
|
|
57
|
+
return text::decodeUtf8(data, size);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
jsi::Value decodeText(
|
|
61
|
+
jsi::Runtime &rt,
|
|
62
|
+
const std::shared_ptr<Networking> &networking,
|
|
63
|
+
const jsi::Value &bufferValue,
|
|
64
|
+
const jsi::Value &encodingValue) {
|
|
65
|
+
auto arrayBuffer = bufferValue.asObject(rt).getArrayBuffer(rt);
|
|
66
|
+
const auto label = text::normalizeEncodingLabel(encodingValue.isString() ? encodingValue.asString(rt).utf8(rt) : "");
|
|
67
|
+
return jsi::String::createFromUtf8(
|
|
68
|
+
rt, decodeWithLabel(networking, arrayBuffer.data(rt), arrayBuffer.size(rt), label));
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
} // namespace
|
|
72
|
+
|
|
73
|
+
void NetworkingInstaller::install(
|
|
74
|
+
jsi::Runtime &rt,
|
|
75
|
+
const std::shared_ptr<Networking> &networking,
|
|
76
|
+
const RuntimeData::RuntimeId runtimeId) {
|
|
77
|
+
const auto weakNetworking = std::weak_ptr<Networking>(networking);
|
|
78
|
+
|
|
79
|
+
auto networkingObject = jsi::Object(rt);
|
|
80
|
+
|
|
81
|
+
jsi_utils::addMethod<2>(
|
|
82
|
+
rt,
|
|
83
|
+
networkingObject,
|
|
84
|
+
"sendRequest",
|
|
85
|
+
[weakNetworking](jsi::Runtime &rt, const jsi::Value &, const jsi::Value(&args)[2]) -> jsi::Value {
|
|
86
|
+
const auto networking = weakNetworking.lock();
|
|
87
|
+
if (!networking) {
|
|
88
|
+
throw jsi::JSError(rt, "[Worklets] The networking module is no longer available.");
|
|
89
|
+
}
|
|
90
|
+
const auto requestId = networking->sendRequest(rt, args[0].asObject(rt), args[1].asObject(rt).asFunction(rt));
|
|
91
|
+
return {static_cast<double>(requestId)};
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
jsi_utils::addMethod<1>(
|
|
95
|
+
rt,
|
|
96
|
+
networkingObject,
|
|
97
|
+
"abortRequest",
|
|
98
|
+
[weakNetworking](jsi::Runtime &rt, const jsi::Value &, const jsi::Value(&args)[1]) {
|
|
99
|
+
const auto requestId = args[0].asNumber();
|
|
100
|
+
if (!std::isfinite(requestId) || requestId < 1 || requestId >= 18446744073709551616.0 ||
|
|
101
|
+
std::trunc(requestId) != requestId) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
if (const auto networking = weakNetworking.lock()) {
|
|
105
|
+
networking->abortRequest(rt, static_cast<uint64_t>(requestId));
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
jsi_utils::addMethod<2>(
|
|
110
|
+
rt,
|
|
111
|
+
networkingObject,
|
|
112
|
+
"decodeText",
|
|
113
|
+
[weakNetworking](jsi::Runtime &rt, const jsi::Value &, const jsi::Value(&args)[2]) -> jsi::Value {
|
|
114
|
+
const auto networking = weakNetworking.lock();
|
|
115
|
+
if (!networking) {
|
|
116
|
+
throw jsi::JSError(rt, "[Worklets] The networking module is no longer available.");
|
|
117
|
+
}
|
|
118
|
+
return decodeText(rt, networking, args[0], args[1]);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
rt.global().setProperty(rt, "__workletsNetworking", networkingObject);
|
|
122
|
+
|
|
123
|
+
const auto guard = std::make_shared<NetworkingRuntimeGuard>(weakNetworking, runtimeId);
|
|
124
|
+
rt.global().setProperty(rt, "__workletsNetworkingGuard", jsi::Object::createFromHostObject(rt, guard));
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
} // namespace worklets
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <jsi/jsi.h>
|
|
4
|
+
#include <worklets/Networking/Networking.h>
|
|
5
|
+
#include <worklets/WorkletRuntime/RuntimeData.h>
|
|
6
|
+
|
|
7
|
+
#include <memory>
|
|
8
|
+
|
|
9
|
+
using namespace facebook;
|
|
10
|
+
|
|
11
|
+
namespace worklets {
|
|
12
|
+
|
|
13
|
+
class NetworkingInstaller {
|
|
14
|
+
public:
|
|
15
|
+
static void
|
|
16
|
+
install(jsi::Runtime &rt, const std::shared_ptr<Networking> &networking, RuntimeData::RuntimeId runtimeId);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
} // namespace worklets
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <cstdint>
|
|
4
|
+
#include <optional>
|
|
5
|
+
#include <string>
|
|
6
|
+
#include <utility>
|
|
7
|
+
#include <vector>
|
|
8
|
+
|
|
9
|
+
namespace worklets {
|
|
10
|
+
|
|
11
|
+
enum class RequestError : uint8_t {
|
|
12
|
+
Network = 0,
|
|
13
|
+
Timeout = 1,
|
|
14
|
+
Aborted = 2,
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
struct RequestConfig {
|
|
18
|
+
std::string method;
|
|
19
|
+
std::string url;
|
|
20
|
+
std::vector<std::pair<std::string, std::string>> headers;
|
|
21
|
+
std::optional<std::vector<uint8_t>> body;
|
|
22
|
+
double timeoutMs;
|
|
23
|
+
bool withCredentials;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
struct ResponseInfo {
|
|
27
|
+
int status;
|
|
28
|
+
std::string statusText;
|
|
29
|
+
std::vector<std::pair<std::string, std::string>> headers;
|
|
30
|
+
std::string url;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
} // namespace worklets
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
#include <worklets/Networking/TextDecoding.h>
|
|
2
|
+
|
|
3
|
+
#include <algorithm>
|
|
4
|
+
#include <cctype>
|
|
5
|
+
|
|
6
|
+
namespace worklets::text {
|
|
7
|
+
|
|
8
|
+
namespace {
|
|
9
|
+
|
|
10
|
+
constexpr uint32_t kReplacementCodePoint = 0xFFFD;
|
|
11
|
+
|
|
12
|
+
// Code points for bytes 0x80-0x9F, where windows-1252 differs from Latin-1.
|
|
13
|
+
constexpr uint16_t kWindows1252CodePoints[32] = {0x20AC, 0x0081, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
|
|
14
|
+
0x02C6, 0x2030, 0x0160, 0x2039, 0x0152, 0x008D, 0x017D, 0x008F,
|
|
15
|
+
0x0090, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
|
|
16
|
+
0x02DC, 0x2122, 0x0161, 0x203A, 0x0153, 0x009D, 0x017E, 0x0178};
|
|
17
|
+
|
|
18
|
+
void appendUtf8(std::string &result, const uint32_t codePoint) {
|
|
19
|
+
if (codePoint < 0x80) {
|
|
20
|
+
result.push_back(static_cast<char>(codePoint));
|
|
21
|
+
} else if (codePoint < 0x800) {
|
|
22
|
+
result.push_back(static_cast<char>(0xC0 | (codePoint >> 6)));
|
|
23
|
+
result.push_back(static_cast<char>(0x80 | (codePoint & 0x3F)));
|
|
24
|
+
} else if (codePoint < 0x10000) {
|
|
25
|
+
result.push_back(static_cast<char>(0xE0 | (codePoint >> 12)));
|
|
26
|
+
result.push_back(static_cast<char>(0x80 | ((codePoint >> 6) & 0x3F)));
|
|
27
|
+
result.push_back(static_cast<char>(0x80 | (codePoint & 0x3F)));
|
|
28
|
+
} else {
|
|
29
|
+
result.push_back(static_cast<char>(0xF0 | (codePoint >> 18)));
|
|
30
|
+
result.push_back(static_cast<char>(0x80 | ((codePoint >> 12) & 0x3F)));
|
|
31
|
+
result.push_back(static_cast<char>(0x80 | ((codePoint >> 6) & 0x3F)));
|
|
32
|
+
result.push_back(static_cast<char>(0x80 | (codePoint & 0x3F)));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
std::string decodeWindows1252Impl(const uint8_t *data, const size_t size) {
|
|
37
|
+
std::string result;
|
|
38
|
+
result.reserve(size);
|
|
39
|
+
for (size_t i = 0; i < size; i++) {
|
|
40
|
+
const auto byte = data[i];
|
|
41
|
+
if (byte >= 0x80 && byte < 0xA0) {
|
|
42
|
+
appendUtf8(result, kWindows1252CodePoints[byte - 0x80]);
|
|
43
|
+
} else {
|
|
44
|
+
appendUtf8(result, byte);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return result;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// The WHATWG Encoding Standard UTF-8 decoder, emitting U+FFFD for malformed
|
|
51
|
+
// sequences. `jsi::String::createFromUtf8` has undefined behavior for invalid
|
|
52
|
+
// UTF-8, so every byte sequence must pass through here first.
|
|
53
|
+
std::string decodeUtf8Impl(const uint8_t *data, const size_t size) {
|
|
54
|
+
std::string result;
|
|
55
|
+
result.reserve(size);
|
|
56
|
+
uint32_t codePoint = 0;
|
|
57
|
+
int bytesNeeded = 0;
|
|
58
|
+
int bytesSeen = 0;
|
|
59
|
+
uint8_t lowerBoundary = 0x80;
|
|
60
|
+
uint8_t upperBoundary = 0xBF;
|
|
61
|
+
size_t index = 0;
|
|
62
|
+
while (index < size) {
|
|
63
|
+
const auto byte = data[index];
|
|
64
|
+
if (bytesNeeded == 0) {
|
|
65
|
+
index++;
|
|
66
|
+
if (byte <= 0x7F) {
|
|
67
|
+
result.push_back(static_cast<char>(byte));
|
|
68
|
+
} else if (byte >= 0xC2 && byte <= 0xDF) {
|
|
69
|
+
bytesNeeded = 1;
|
|
70
|
+
codePoint = byte & 0x1FU;
|
|
71
|
+
} else if (byte >= 0xE0 && byte <= 0xEF) {
|
|
72
|
+
lowerBoundary = byte == 0xE0 ? 0xA0 : 0x80;
|
|
73
|
+
upperBoundary = byte == 0xED ? 0x9F : 0xBF;
|
|
74
|
+
bytesNeeded = 2;
|
|
75
|
+
codePoint = byte & 0x0FU;
|
|
76
|
+
} else if (byte >= 0xF0 && byte <= 0xF4) {
|
|
77
|
+
lowerBoundary = byte == 0xF0 ? 0x90 : 0x80;
|
|
78
|
+
upperBoundary = byte == 0xF4 ? 0x8F : 0xBF;
|
|
79
|
+
bytesNeeded = 3;
|
|
80
|
+
codePoint = byte & 0x07U;
|
|
81
|
+
} else {
|
|
82
|
+
appendUtf8(result, kReplacementCodePoint);
|
|
83
|
+
}
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
if (byte < lowerBoundary || byte > upperBoundary) {
|
|
87
|
+
codePoint = 0;
|
|
88
|
+
bytesNeeded = 0;
|
|
89
|
+
bytesSeen = 0;
|
|
90
|
+
lowerBoundary = 0x80;
|
|
91
|
+
upperBoundary = 0xBF;
|
|
92
|
+
appendUtf8(result, kReplacementCodePoint);
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
lowerBoundary = 0x80;
|
|
96
|
+
upperBoundary = 0xBF;
|
|
97
|
+
codePoint = (codePoint << 6U) | (byte & 0x3FU);
|
|
98
|
+
bytesSeen++;
|
|
99
|
+
index++;
|
|
100
|
+
if (bytesSeen == bytesNeeded) {
|
|
101
|
+
appendUtf8(result, codePoint);
|
|
102
|
+
codePoint = 0;
|
|
103
|
+
bytesNeeded = 0;
|
|
104
|
+
bytesSeen = 0;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (bytesNeeded != 0) {
|
|
108
|
+
appendUtf8(result, kReplacementCodePoint);
|
|
109
|
+
}
|
|
110
|
+
return result;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
} // namespace
|
|
114
|
+
|
|
115
|
+
std::string normalizeEncodingLabel(std::string label) {
|
|
116
|
+
constexpr auto isAsciiWhitespace = [](const unsigned char character) {
|
|
117
|
+
return character == 0x09 || character == 0x0A || character == 0x0C || character == 0x0D || character == 0x20;
|
|
118
|
+
};
|
|
119
|
+
const auto begin = std::find_if_not(label.begin(), label.end(), isAsciiWhitespace);
|
|
120
|
+
const auto end = std::find_if_not(label.rbegin(), label.rend(), isAsciiWhitespace).base();
|
|
121
|
+
label = begin < end ? std::string(begin, end) : std::string{};
|
|
122
|
+
std::transform(label.begin(), label.end(), label.begin(), [](const unsigned char character) {
|
|
123
|
+
return static_cast<char>(std::tolower(character));
|
|
124
|
+
});
|
|
125
|
+
return label;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// https://encoding.spec.whatwg.org/#names-and-labels
|
|
129
|
+
bool isUtf8Label(const std::string &label) {
|
|
130
|
+
return label.empty() || label == "utf-8" || label == "utf8" || label == "unicode-1-1-utf-8" ||
|
|
131
|
+
label == "unicode11utf8" || label == "unicode20utf8" || label == "x-unicode20utf8";
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// https://encoding.spec.whatwg.org/#names-and-labels
|
|
135
|
+
bool isWindows1252Label(const std::string &label) {
|
|
136
|
+
return label == "ansi_x3.4-1968" || label == "ascii" || label == "cp1252" || label == "cp819" ||
|
|
137
|
+
label == "csisolatin1" || label == "ibm819" || label == "iso-8859-1" || label == "iso-ir-100" ||
|
|
138
|
+
label == "iso8859-1" || label == "iso88591" || label == "iso_8859-1" || label == "iso_8859-1:1987" ||
|
|
139
|
+
label == "l1" || label == "latin1" || label == "us-ascii" || label == "windows-1252" || label == "x-cp1252";
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
std::string decodeUtf8(const uint8_t *data, const size_t size) {
|
|
143
|
+
return decodeUtf8Impl(data, size);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
std::string decodeWindows1252(const uint8_t *data, const size_t size) {
|
|
147
|
+
return decodeWindows1252Impl(data, size);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// https://encoding.spec.whatwg.org/#shared-utf-16-decoder
|
|
151
|
+
std::string decodeUtf16(const uint8_t *data, const size_t size, const bool littleEndian) {
|
|
152
|
+
std::string result;
|
|
153
|
+
result.reserve(size);
|
|
154
|
+
uint32_t leadSurrogate = 0;
|
|
155
|
+
bool hasLeadSurrogate = false;
|
|
156
|
+
size_t index = 0;
|
|
157
|
+
while (index + 1 < size) {
|
|
158
|
+
const uint32_t unit = littleEndian
|
|
159
|
+
? static_cast<uint32_t>(data[index]) | (static_cast<uint32_t>(data[index + 1]) << 8U)
|
|
160
|
+
: (static_cast<uint32_t>(data[index]) << 8U) | static_cast<uint32_t>(data[index + 1]);
|
|
161
|
+
index += 2;
|
|
162
|
+
if (hasLeadSurrogate) {
|
|
163
|
+
hasLeadSurrogate = false;
|
|
164
|
+
if (unit >= 0xDC00 && unit <= 0xDFFF) {
|
|
165
|
+
appendUtf8(result, 0x10000 + ((leadSurrogate - 0xD800) << 10U) + (unit - 0xDC00));
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
appendUtf8(result, kReplacementCodePoint);
|
|
169
|
+
}
|
|
170
|
+
if (unit >= 0xD800 && unit <= 0xDBFF) {
|
|
171
|
+
leadSurrogate = unit;
|
|
172
|
+
hasLeadSurrogate = true;
|
|
173
|
+
} else if (unit >= 0xDC00 && unit <= 0xDFFF) {
|
|
174
|
+
appendUtf8(result, kReplacementCodePoint);
|
|
175
|
+
} else {
|
|
176
|
+
appendUtf8(result, unit);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
if (hasLeadSurrogate || index != size) {
|
|
180
|
+
appendUtf8(result, kReplacementCodePoint);
|
|
181
|
+
}
|
|
182
|
+
return result;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
std::string toValidUtf8(const std::string &value) {
|
|
186
|
+
return decodeUtf8Impl(reinterpret_cast<const uint8_t *>(value.data()), value.size());
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
} // namespace worklets::text
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <cstddef>
|
|
4
|
+
#include <cstdint>
|
|
5
|
+
#include <string>
|
|
6
|
+
|
|
7
|
+
namespace worklets::text {
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Decoders for the WHATWG Encoding Standard subset the networking module
|
|
11
|
+
* handles in C++. Every function returns well-formed UTF-8, so the result is
|
|
12
|
+
* always safe to hand to `jsi::String::createFromUtf8`, whose behavior is
|
|
13
|
+
* undefined for invalid UTF-8.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/** Normalizes an encoding label: trims ASCII whitespace and lowercases. */
|
|
17
|
+
std::string normalizeEncodingLabel(std::string label);
|
|
18
|
+
|
|
19
|
+
bool isUtf8Label(const std::string &label);
|
|
20
|
+
bool isWindows1252Label(const std::string &label);
|
|
21
|
+
|
|
22
|
+
std::string decodeUtf8(const uint8_t *data, size_t size);
|
|
23
|
+
std::string decodeUtf16(const uint8_t *data, size_t size, bool littleEndian);
|
|
24
|
+
std::string decodeWindows1252(const uint8_t *data, size_t size);
|
|
25
|
+
|
|
26
|
+
/** Replaces malformed sequences in an already-UTF-8-ish string with U+FFFD. */
|
|
27
|
+
std::string toValidUtf8(const std::string &value);
|
|
28
|
+
|
|
29
|
+
} // namespace worklets::text
|
|
@@ -2,13 +2,41 @@
|
|
|
2
2
|
|
|
3
3
|
#include <jsi/jsi.h>
|
|
4
4
|
|
|
5
|
+
#include <cstdint>
|
|
6
|
+
#include <utility>
|
|
7
|
+
|
|
5
8
|
namespace worklets {
|
|
6
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Identifies the owner of a job, so that a queue shared between several owners
|
|
12
|
+
* can cancel the jobs of one of them without touching the jobs of the others.
|
|
13
|
+
*
|
|
14
|
+
* Worklet Runtimes send their RuntimeId as a token.
|
|
15
|
+
*/
|
|
16
|
+
using AbortToken = uint64_t;
|
|
17
|
+
|
|
18
|
+
inline constexpr AbortToken defaultToken{0};
|
|
19
|
+
|
|
7
20
|
class AsyncQueue : public facebook::jsi::NativeState {
|
|
8
21
|
public:
|
|
9
22
|
~AsyncQueue() override = default;
|
|
10
23
|
|
|
11
24
|
virtual void push(std::function<void()> &&job) = 0;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Pushes a job on behalf of the owner the token belongs to. The default
|
|
28
|
+
* implementation discards the token.
|
|
29
|
+
*/
|
|
30
|
+
virtual void push(std::function<void()> &&job, AbortToken /* abortToken */) {
|
|
31
|
+
push(std::move(job));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Drops the jobs that are still pending, destroying them on the calling
|
|
36
|
+
* thread. A queue shared between several owners drops only the jobs pushed
|
|
37
|
+
* with this token. The default implementation keeps every job.
|
|
38
|
+
*/
|
|
39
|
+
virtual void abortPending(AbortToken /* abortToken */) {}
|
|
12
40
|
};
|
|
13
41
|
|
|
14
42
|
} // namespace worklets
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
#endif // ANDROID
|
|
6
6
|
|
|
7
7
|
#include <memory>
|
|
8
|
+
#include <queue>
|
|
8
9
|
#include <string>
|
|
9
10
|
#include <thread>
|
|
10
11
|
#include <utility>
|
|
@@ -92,6 +93,14 @@ void AsyncQueueImpl::push(std::function<void()> &&job) {
|
|
|
92
93
|
state_->cv.notify_one();
|
|
93
94
|
}
|
|
94
95
|
|
|
96
|
+
void AsyncQueueImpl::abortPending(AbortToken /* abortToken */) {
|
|
97
|
+
std::queue<std::function<void()>> pendingJobs;
|
|
98
|
+
{
|
|
99
|
+
std::unique_lock<std::mutex> lock(state_->mutex);
|
|
100
|
+
std::swap(pendingJobs, state_->queue);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
95
104
|
AsyncQueueUI::AsyncQueueUI(const std::shared_ptr<UIScheduler> &uiScheduler) : uiScheduler_(uiScheduler) {}
|
|
96
105
|
|
|
97
106
|
void AsyncQueueUI::push(std::function<void()> &&job) {
|
|
@@ -25,8 +25,12 @@ class AsyncQueueImpl : public AsyncQueue {
|
|
|
25
25
|
|
|
26
26
|
~AsyncQueueImpl() override;
|
|
27
27
|
|
|
28
|
+
using AsyncQueue::push;
|
|
29
|
+
|
|
28
30
|
void push(std::function<void()> &&job) override;
|
|
29
31
|
|
|
32
|
+
void abortPending(AbortToken abortToken) override;
|
|
33
|
+
|
|
30
34
|
private:
|
|
31
35
|
static void runLoop(const std::shared_ptr<AsyncQueueState> &state);
|
|
32
36
|
|
|
@@ -39,6 +43,8 @@ class AsyncQueueUI : public AsyncQueue {
|
|
|
39
43
|
|
|
40
44
|
~AsyncQueueUI() override = default;
|
|
41
45
|
|
|
46
|
+
using AsyncQueue::push;
|
|
47
|
+
|
|
42
48
|
void push(std::function<void()> &&job) override;
|
|
43
49
|
|
|
44
50
|
private:
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
#include <worklets/RunLoop/EventLoop.h>
|
|
2
|
-
#include <worklets/Tools/WorkletsJSIUtils.h>
|
|
3
2
|
|
|
4
3
|
#include <memory>
|
|
5
4
|
#include <string>
|
|
@@ -11,10 +10,12 @@ namespace worklets {
|
|
|
11
10
|
|
|
12
11
|
EventLoop::EventLoop(
|
|
13
12
|
const std::string &name,
|
|
13
|
+
const AbortToken abortToken,
|
|
14
14
|
const std::shared_ptr<jsi::Runtime> &runtime,
|
|
15
15
|
const std::shared_ptr<AsyncQueue> &queue,
|
|
16
16
|
const std::shared_ptr<std::recursive_mutex> &runtimeMutex)
|
|
17
|
-
:
|
|
17
|
+
: abortToken_(abortToken),
|
|
18
|
+
runtime_(runtime),
|
|
18
19
|
queue_(queue),
|
|
19
20
|
runtimeMutex_(runtimeMutex),
|
|
20
21
|
timeoutsQueueState_(std::make_shared<TimeoutsQueueState>()),
|
|
@@ -87,14 +88,28 @@ void EventLoop::pushTask(std::function<void(jsi::Runtime &rt)> &&job) {
|
|
|
87
88
|
if (auto runtime = weakRuntime.lock()) {
|
|
88
89
|
std::unique_lock lock(*runtimeMutex);
|
|
89
90
|
job(*runtime);
|
|
90
|
-
|
|
91
|
+
runtime->drainMicrotasks();
|
|
91
92
|
}
|
|
92
|
-
}
|
|
93
|
+
},
|
|
94
|
+
abortToken_);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
void EventLoop::abortPending() {
|
|
98
|
+
std::vector<Timeout> pendingTimeouts;
|
|
99
|
+
{
|
|
100
|
+
std::unique_lock<std::mutex> lock(timeoutsQueueState_->mutex);
|
|
101
|
+
timeoutsQueueState_->running = false;
|
|
102
|
+
std::swap(pendingTimeouts, timeoutsQueueState_->queue);
|
|
103
|
+
}
|
|
104
|
+
timeoutsQueueState_->cv.notify_all();
|
|
93
105
|
}
|
|
94
106
|
|
|
95
107
|
void EventLoop::pushTimeout(std::function<void(jsi::Runtime &rt)> &&job, int64_t delay) {
|
|
96
108
|
{
|
|
97
109
|
std::unique_lock<std::mutex> lock(timeoutsQueueState_->mutex);
|
|
110
|
+
if (!timeoutsQueueState_->running) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
98
113
|
const auto targetTime = getCurrentTimeInMs() + delay;
|
|
99
114
|
const auto timeout = Timeout{std::move(job), targetTime};
|
|
100
115
|
auto &queue = timeoutsQueueState_->queue;
|
|
@@ -33,6 +33,7 @@ class EventLoop : public std::enable_shared_from_this<EventLoop> {
|
|
|
33
33
|
public:
|
|
34
34
|
EventLoop(
|
|
35
35
|
const std::string &name,
|
|
36
|
+
AbortToken abortToken,
|
|
36
37
|
const std::shared_ptr<jsi::Runtime> &runtime,
|
|
37
38
|
const std::shared_ptr<AsyncQueue> &queue,
|
|
38
39
|
const std::shared_ptr<std::recursive_mutex> &runtimeMutex);
|
|
@@ -40,8 +41,10 @@ class EventLoop : public std::enable_shared_from_this<EventLoop> {
|
|
|
40
41
|
void run();
|
|
41
42
|
void pushTask(std::function<void(jsi::Runtime &rt)> &&job);
|
|
42
43
|
void pushTimeout(std::function<void(jsi::Runtime &rt)> &&job, int64_t delay);
|
|
44
|
+
void abortPending();
|
|
43
45
|
|
|
44
46
|
private:
|
|
47
|
+
const AbortToken abortToken_;
|
|
45
48
|
const std::shared_ptr<jsi::Runtime> runtime_;
|
|
46
49
|
const std::shared_ptr<AsyncQueue> queue_;
|
|
47
50
|
const std::shared_ptr<std::recursive_mutex> runtimeMutex_;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#include <jsi/jsi.h>
|
|
2
2
|
#include <react/debug/react_native_assert.h>
|
|
3
3
|
#include <worklets/SharedItems/MemoryManager.h>
|
|
4
|
-
#include <worklets/SharedItems/Serializable.h>
|
|
4
|
+
#include <worklets/SharedItems/Serializable/Serializable.h>
|
|
5
5
|
#include <worklets/WorkletRuntime/WorkletRuntime.h>
|
|
6
6
|
|
|
7
7
|
namespace worklets {
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
#include <jsi/jsi.h>
|
|
4
4
|
#include <react/debug/react_native_assert.h>
|
|
5
|
-
#include <worklets/SharedItems/Serializable.h>
|
|
5
|
+
#include <worklets/SharedItems/Serializable/CustomSerializable.h>
|
|
6
|
+
#include <worklets/SharedItems/Serializable/Serializable.h>
|
|
6
7
|
#include <worklets/WorkletRuntime/WorkletRuntime.h>
|
|
7
8
|
|
|
8
9
|
#include <memory>
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
#include <jsi/jsi.h>
|
|
2
|
+
#include <react/debug/react_native_assert.h>
|
|
3
|
+
#include <worklets/SharedItems/Serializable/CustomSerializable.h>
|
|
4
|
+
|
|
5
|
+
#include <memory>
|
|
6
|
+
#include <stdexcept>
|
|
7
|
+
#include <string>
|
|
8
|
+
|
|
9
|
+
using namespace facebook;
|
|
10
|
+
|
|
11
|
+
namespace worklets {
|
|
12
|
+
|
|
13
|
+
jsi::Function getCustomSerializableUnpacker(jsi::Runtime &rt) {
|
|
14
|
+
auto customSerializableUnpacker = rt.global().getProperty(rt, "__customSerializableUnpacker");
|
|
15
|
+
react_native_assert(customSerializableUnpacker.isObject() && "customSerializableUnpacker not found");
|
|
16
|
+
return customSerializableUnpacker.asObject(rt).asFunction(rt);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
jsi::Value CustomSerializable::toJSValue(jsi::Runtime &rt) {
|
|
20
|
+
try {
|
|
21
|
+
auto unpack = getCustomSerializableUnpacker(rt);
|
|
22
|
+
auto data = data_->toJSValue(rt);
|
|
23
|
+
|
|
24
|
+
return unpack.call(rt, data, jsi::Value(typeId_));
|
|
25
|
+
} catch (jsi::JSError &e) {
|
|
26
|
+
throw std::runtime_error(
|
|
27
|
+
std::string("[Worklets] Failed to deserialize CustomSerializable. Reason: ") + e.getMessage());
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
jsi::Value makeCustomSerializable(jsi::Runtime &rt, const jsi::Value &data, const int typeId) {
|
|
32
|
+
auto rawData = extractSerializableOrThrow(rt, data, "[Worklets] Data must be a Serializable object.");
|
|
33
|
+
auto customSerializable = std::make_shared<CustomSerializable>(rawData, typeId);
|
|
34
|
+
return SerializableJSRef::newNativeStateObject(rt, customSerializable);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
} // namespace worklets
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <jsi/jsi.h>
|
|
4
|
+
#include <worklets/SharedItems/Serializable/SerializableWorklet.h>
|
|
5
|
+
|
|
6
|
+
#include <memory>
|
|
7
|
+
|
|
8
|
+
namespace worklets {
|
|
9
|
+
|
|
10
|
+
facebook::jsi::Function getCustomSerializableUnpacker(facebook::jsi::Runtime &rt);
|
|
11
|
+
|
|
12
|
+
class CustomSerializable : public Serializable {
|
|
13
|
+
public:
|
|
14
|
+
CustomSerializable(std::shared_ptr<Serializable> data, const int typeId)
|
|
15
|
+
: Serializable(ValueType::CustomType), data_(std::move(data)), typeId_(typeId) {}
|
|
16
|
+
|
|
17
|
+
facebook::jsi::Value toJSValue(facebook::jsi::Runtime &rt) override;
|
|
18
|
+
|
|
19
|
+
private:
|
|
20
|
+
const std::shared_ptr<Serializable> data_;
|
|
21
|
+
const int typeId_;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
struct SerializationData {
|
|
25
|
+
std::shared_ptr<SerializableWorklet> determine;
|
|
26
|
+
std::shared_ptr<SerializableWorklet> pack;
|
|
27
|
+
std::shared_ptr<SerializableWorklet> unpack;
|
|
28
|
+
int typeId;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
facebook::jsi::Value makeCustomSerializable(facebook::jsi::Runtime &rt, const facebook::jsi::Value &data, int typeId);
|
|
32
|
+
|
|
33
|
+
} // namespace worklets
|