@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,173 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const TOKEN_PATTERN = /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/;
|
|
4
|
+
const HEADER_VALUE_PATTERN = /^[^\0\r\n]*$/;
|
|
5
|
+
const HTTP_WHITESPACE_PATTERN = /^[\t\n\r ]+|[\t\n\r ]+$/g;
|
|
6
|
+
const ABSOLUTE_URL_SCHEME_PATTERN = /^([A-Za-z][A-Za-z0-9+\-.]*):/;
|
|
7
|
+
const CHARSET_PARAMETER_PATTERN = /;\s*charset\s*=\s*("([^"]*)"|([^;\s]*))/i;
|
|
8
|
+
|
|
9
|
+
const NORMALIZED_METHODS = ['DELETE', 'GET', 'HEAD', 'OPTIONS', 'POST', 'PUT'];
|
|
10
|
+
const FORBIDDEN_METHODS = ['CONNECT', 'TRACE', 'TRACK'];
|
|
11
|
+
const SUPPORTED_SCHEMES = ['http', 'https'];
|
|
12
|
+
|
|
13
|
+
const FORBIDDEN_REQUEST_HEADERS = new Set([
|
|
14
|
+
'accept-charset',
|
|
15
|
+
'accept-encoding',
|
|
16
|
+
'access-control-request-headers',
|
|
17
|
+
'access-control-request-method',
|
|
18
|
+
'connection',
|
|
19
|
+
'content-length',
|
|
20
|
+
'cookie',
|
|
21
|
+
'cookie2',
|
|
22
|
+
'date',
|
|
23
|
+
'dnt',
|
|
24
|
+
'expect',
|
|
25
|
+
'host',
|
|
26
|
+
'keep-alive',
|
|
27
|
+
'origin',
|
|
28
|
+
'referer',
|
|
29
|
+
'set-cookie',
|
|
30
|
+
'te',
|
|
31
|
+
'trailer',
|
|
32
|
+
'transfer-encoding',
|
|
33
|
+
'upgrade',
|
|
34
|
+
'via',
|
|
35
|
+
]);
|
|
36
|
+
const FORBIDDEN_REQUEST_HEADER_PREFIXES = ['proxy-', 'sec-'];
|
|
37
|
+
const METHOD_OVERRIDE_HEADERS = new Set([
|
|
38
|
+
'x-http-method',
|
|
39
|
+
'x-http-method-override',
|
|
40
|
+
'x-method-override',
|
|
41
|
+
]);
|
|
42
|
+
const FORBIDDEN_RESPONSE_HEADERS = new Set(['set-cookie', 'set-cookie2']);
|
|
43
|
+
|
|
44
|
+
export function normalizeMethod(method: string): string {
|
|
45
|
+
const uppercasedMethod = method.toUpperCase();
|
|
46
|
+
return NORMALIZED_METHODS.includes(uppercasedMethod)
|
|
47
|
+
? uppercasedMethod
|
|
48
|
+
: method;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function isToken(value: string): boolean {
|
|
52
|
+
return TOKEN_PATTERN.test(value);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function isForbiddenMethod(method: string): boolean {
|
|
56
|
+
return FORBIDDEN_METHODS.includes(method.toUpperCase());
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function isSupportedRequestUrl(url: string): boolean {
|
|
60
|
+
const scheme = ABSOLUTE_URL_SCHEME_PATTERN.exec(url)?.[1];
|
|
61
|
+
return (
|
|
62
|
+
scheme !== undefined && SUPPORTED_SCHEMES.includes(scheme.toLowerCase())
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function isHeaderName(name: string): boolean {
|
|
67
|
+
return isToken(name);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function isHeaderValue(value: string): boolean {
|
|
71
|
+
return HEADER_VALUE_PATTERN.test(value);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function normalizeHeaderValue(value: string): string {
|
|
75
|
+
return value.replace(HTTP_WHITESPACE_PATTERN, '');
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function isForbiddenRequestHeader(name: string, value: string): boolean {
|
|
79
|
+
const lowerCaseName = name.toLowerCase();
|
|
80
|
+
if (
|
|
81
|
+
FORBIDDEN_REQUEST_HEADERS.has(lowerCaseName) ||
|
|
82
|
+
FORBIDDEN_REQUEST_HEADER_PREFIXES.some((prefix) =>
|
|
83
|
+
lowerCaseName.startsWith(prefix)
|
|
84
|
+
)
|
|
85
|
+
) {
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
return (
|
|
89
|
+
METHOD_OVERRIDE_HEADERS.has(lowerCaseName) &&
|
|
90
|
+
value.split(',').some((method) => isForbiddenMethod(method.trim()))
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function combineHeader(
|
|
95
|
+
headers: Array<[string, string]>,
|
|
96
|
+
name: string,
|
|
97
|
+
value: string
|
|
98
|
+
) {
|
|
99
|
+
const lowerCaseName = name.toLowerCase();
|
|
100
|
+
const existing = headers.find(
|
|
101
|
+
([headerName]) => headerName.toLowerCase() === lowerCaseName
|
|
102
|
+
);
|
|
103
|
+
if (existing === undefined) {
|
|
104
|
+
headers.push([name, value]);
|
|
105
|
+
} else {
|
|
106
|
+
existing[1] = `${existing[1]}, ${value}`;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export function hasHeader(
|
|
111
|
+
headers: Array<[string, string]>,
|
|
112
|
+
name: string
|
|
113
|
+
): boolean {
|
|
114
|
+
const lowerCaseName = name.toLowerCase();
|
|
115
|
+
return headers.some(
|
|
116
|
+
([headerName]) => headerName.toLowerCase() === lowerCaseName
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export function getHeader(
|
|
121
|
+
headers: Array<[string, string]>,
|
|
122
|
+
name: string
|
|
123
|
+
): string | null {
|
|
124
|
+
const lowerCaseName = name.toLowerCase();
|
|
125
|
+
if (FORBIDDEN_RESPONSE_HEADERS.has(lowerCaseName)) {
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
const values = headers
|
|
129
|
+
.filter(([headerName]) => headerName.toLowerCase() === lowerCaseName)
|
|
130
|
+
.map(([, value]) => value);
|
|
131
|
+
return values.length > 0 ? values.join(', ') : null;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export function sortAndCombineHeaders(
|
|
135
|
+
headers: Array<[string, string]>
|
|
136
|
+
): string {
|
|
137
|
+
const combined = new Map<string, string[]>();
|
|
138
|
+
for (const [name, value] of headers) {
|
|
139
|
+
const lowerCaseName = name.toLowerCase();
|
|
140
|
+
if (FORBIDDEN_RESPONSE_HEADERS.has(lowerCaseName)) {
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
const values = combined.get(lowerCaseName);
|
|
144
|
+
if (values === undefined) {
|
|
145
|
+
combined.set(lowerCaseName, [value]);
|
|
146
|
+
} else {
|
|
147
|
+
values.push(value);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return Array.from(combined.keys())
|
|
151
|
+
.sort((left, right) => {
|
|
152
|
+
const uppercasedLeft = left.toUpperCase();
|
|
153
|
+
const uppercasedRight = right.toUpperCase();
|
|
154
|
+
if (uppercasedLeft === uppercasedRight) {
|
|
155
|
+
return 0;
|
|
156
|
+
}
|
|
157
|
+
return uppercasedLeft < uppercasedRight ? -1 : 1;
|
|
158
|
+
})
|
|
159
|
+
.map((name) => `${name}: ${combined.get(name)!.join(', ')}\r\n`)
|
|
160
|
+
.join('');
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export function extractCharset(mimeType: string | null): string | undefined {
|
|
164
|
+
if (mimeType === null) {
|
|
165
|
+
return undefined;
|
|
166
|
+
}
|
|
167
|
+
const match = CHARSET_PARAMETER_PATTERN.exec(mimeType);
|
|
168
|
+
if (match === null) {
|
|
169
|
+
return undefined;
|
|
170
|
+
}
|
|
171
|
+
const charset = match[2] ?? match[3] ?? '';
|
|
172
|
+
return charset !== '' ? charset : undefined;
|
|
173
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
import { AbortController, AbortSignal } from './AbortController';
|
|
4
|
+
import { Blob } from './Blob';
|
|
5
|
+
import { DOMException } from './DOMException';
|
|
6
|
+
import { FileReader } from './FileReader';
|
|
7
|
+
import { FormData } from './FormData';
|
|
8
|
+
import { XMLHttpRequest } from './XMLHttpRequest';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Installs the networking API (`fetch`, `XMLHttpRequest` and their supporting
|
|
12
|
+
* globals) on a Worklet Runtime. The native `__workletsNetworking` binding is
|
|
13
|
+
* installed by C++ only on Worklet Runtimes in Bundle Mode, so this function is
|
|
14
|
+
* a no-op anywhere else.
|
|
15
|
+
*
|
|
16
|
+
* All polyfills must be in place before `whatwg-fetch` is required because it
|
|
17
|
+
* feature-detects them at module scope.
|
|
18
|
+
*/
|
|
19
|
+
let installed = false;
|
|
20
|
+
|
|
21
|
+
export function installNetworking() {
|
|
22
|
+
if (globalThis.__workletsNetworking === undefined || installed) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
installed = true;
|
|
26
|
+
|
|
27
|
+
const global = globalThis as unknown as Record<string, unknown>;
|
|
28
|
+
global.XMLHttpRequest ??= XMLHttpRequest;
|
|
29
|
+
global.Blob ??= Blob;
|
|
30
|
+
global.FileReader ??= FileReader;
|
|
31
|
+
global.FormData ??= FormData;
|
|
32
|
+
global.DOMException ??= DOMException;
|
|
33
|
+
global.AbortController ??= AbortController;
|
|
34
|
+
global.AbortSignal ??= AbortSignal;
|
|
35
|
+
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
37
|
+
require('whatwg-fetch');
|
|
38
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/* eslint-disable no-bitwise */
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
type TextEncoderLike = new () => { encode: (value: string) => Uint8Array };
|
|
5
|
+
|
|
6
|
+
export function utf8Encode(value: string): Uint8Array {
|
|
7
|
+
const TextEncoderConstructor = (
|
|
8
|
+
globalThis as { TextEncoder?: TextEncoderLike }
|
|
9
|
+
).TextEncoder;
|
|
10
|
+
if (TextEncoderConstructor !== undefined) {
|
|
11
|
+
return new TextEncoderConstructor().encode(value);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const bytes: number[] = [];
|
|
15
|
+
for (let i = 0; i < value.length; i++) {
|
|
16
|
+
let codePoint = value.codePointAt(i)!;
|
|
17
|
+
if (codePoint > 0xffff) {
|
|
18
|
+
i++;
|
|
19
|
+
}
|
|
20
|
+
if (codePoint >= 0xd800 && codePoint <= 0xdfff) {
|
|
21
|
+
codePoint = 0xfffd;
|
|
22
|
+
}
|
|
23
|
+
if (codePoint < 0x80) {
|
|
24
|
+
bytes.push(codePoint);
|
|
25
|
+
} else if (codePoint < 0x800) {
|
|
26
|
+
bytes.push(0xc0 | (codePoint >> 6), 0x80 | (codePoint & 0x3f));
|
|
27
|
+
} else if (codePoint < 0x10000) {
|
|
28
|
+
bytes.push(
|
|
29
|
+
0xe0 | (codePoint >> 12),
|
|
30
|
+
0x80 | ((codePoint >> 6) & 0x3f),
|
|
31
|
+
0x80 | (codePoint & 0x3f)
|
|
32
|
+
);
|
|
33
|
+
} else {
|
|
34
|
+
bytes.push(
|
|
35
|
+
0xf0 | (codePoint >> 18),
|
|
36
|
+
0x80 | ((codePoint >> 12) & 0x3f),
|
|
37
|
+
0x80 | ((codePoint >> 6) & 0x3f),
|
|
38
|
+
0x80 | (codePoint & 0x3f)
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return new Uint8Array(bytes);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function utf8Decode(bytes: Uint8Array): string {
|
|
46
|
+
const codePoints: number[] = [];
|
|
47
|
+
let codePoint = 0;
|
|
48
|
+
let bytesNeeded = 0;
|
|
49
|
+
let bytesSeen = 0;
|
|
50
|
+
let lowerBoundary = 0x80;
|
|
51
|
+
let upperBoundary = 0xbf;
|
|
52
|
+
let index = 0;
|
|
53
|
+
while (index < bytes.length) {
|
|
54
|
+
const byte = bytes[index];
|
|
55
|
+
if (bytesNeeded === 0) {
|
|
56
|
+
index++;
|
|
57
|
+
if (byte <= 0x7f) {
|
|
58
|
+
codePoints.push(byte);
|
|
59
|
+
} else if (byte >= 0xc2 && byte <= 0xdf) {
|
|
60
|
+
bytesNeeded = 1;
|
|
61
|
+
codePoint = byte & 0x1f;
|
|
62
|
+
} else if (byte >= 0xe0 && byte <= 0xef) {
|
|
63
|
+
lowerBoundary = byte === 0xe0 ? 0xa0 : 0x80;
|
|
64
|
+
upperBoundary = byte === 0xed ? 0x9f : 0xbf;
|
|
65
|
+
bytesNeeded = 2;
|
|
66
|
+
codePoint = byte & 0x0f;
|
|
67
|
+
} else if (byte >= 0xf0 && byte <= 0xf4) {
|
|
68
|
+
lowerBoundary = byte === 0xf0 ? 0x90 : 0x80;
|
|
69
|
+
upperBoundary = byte === 0xf4 ? 0x8f : 0xbf;
|
|
70
|
+
bytesNeeded = 3;
|
|
71
|
+
codePoint = byte & 0x07;
|
|
72
|
+
} else {
|
|
73
|
+
codePoints.push(0xfffd);
|
|
74
|
+
}
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
if (byte < lowerBoundary || byte > upperBoundary) {
|
|
78
|
+
codePoint = 0;
|
|
79
|
+
bytesNeeded = 0;
|
|
80
|
+
bytesSeen = 0;
|
|
81
|
+
lowerBoundary = 0x80;
|
|
82
|
+
upperBoundary = 0xbf;
|
|
83
|
+
codePoints.push(0xfffd);
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
lowerBoundary = 0x80;
|
|
87
|
+
upperBoundary = 0xbf;
|
|
88
|
+
codePoint = (codePoint << 6) | (byte & 0x3f);
|
|
89
|
+
bytesSeen++;
|
|
90
|
+
index++;
|
|
91
|
+
if (bytesSeen === bytesNeeded) {
|
|
92
|
+
codePoints.push(codePoint);
|
|
93
|
+
codePoint = 0;
|
|
94
|
+
bytesNeeded = 0;
|
|
95
|
+
bytesSeen = 0;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (bytesNeeded !== 0) {
|
|
99
|
+
codePoints.push(0xfffd);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
let result = '';
|
|
103
|
+
const chunkSize = 4096;
|
|
104
|
+
for (let offset = 0; offset < codePoints.length; offset += chunkSize) {
|
|
105
|
+
result += String.fromCodePoint(
|
|
106
|
+
...codePoints.slice(offset, offset + chunkSize)
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
return result;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function stripUtf8Bom(bytes: Uint8Array): Uint8Array {
|
|
113
|
+
if (
|
|
114
|
+
bytes.length >= 3 &&
|
|
115
|
+
bytes[0] === 0xef &&
|
|
116
|
+
bytes[1] === 0xbb &&
|
|
117
|
+
bytes[2] === 0xbf
|
|
118
|
+
) {
|
|
119
|
+
return bytes.subarray(3);
|
|
120
|
+
}
|
|
121
|
+
return bytes;
|
|
122
|
+
}
|
package/src/privateGlobals.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-unsafe-function-type */
|
|
2
1
|
'use strict';
|
|
3
2
|
|
|
4
3
|
// This file works by accident - currently Builder Bob doesn't move `.d.ts` files to output types.
|
|
@@ -57,14 +56,12 @@ declare global {
|
|
|
57
56
|
var _createSerializableArray: (
|
|
58
57
|
value: unknown[]
|
|
59
58
|
) => FlatSerializableRef<unknown[]>;
|
|
60
|
-
var _createSerializableInitializer: (
|
|
61
|
-
value: object
|
|
62
|
-
) => FlatSerializableRef<object>;
|
|
63
59
|
var _createSerializableSynchronizable: (
|
|
64
60
|
value: object
|
|
65
61
|
) => FlatShareableRef<object>;
|
|
66
62
|
var __serializer: typeof makeShareableCloneOnUIRecursive;
|
|
67
|
-
|
|
63
|
+
/** Available on runtimes with the Hermes microtask queue enabled. */
|
|
64
|
+
var __drainMicrotasks: () => void;
|
|
68
65
|
/** Available only on the UI Runtime */
|
|
69
66
|
var __nativeRequestAnimationFrame: (
|
|
70
67
|
callback: (timestamp: number) => void
|
|
@@ -93,12 +90,6 @@ declare global {
|
|
|
93
90
|
runtime: WorkletRuntime,
|
|
94
91
|
worklet: SerializableRef<() => void>
|
|
95
92
|
) => void;
|
|
96
|
-
/**
|
|
97
|
-
* @deprecated Kept for backwards compatibility. Remove it after support for
|
|
98
|
-
* Reanimated 4.3 is dropped. Reanimated uses it to handle event updates
|
|
99
|
-
* synchronously.
|
|
100
|
-
*/
|
|
101
|
-
var _microtaskQueueFinalizers: (() => void)[];
|
|
102
93
|
var _scheduleTimeoutCallback: (delay: number, handlerId: number) => void;
|
|
103
94
|
var __runTimeoutCallback: (handlerId: number) => void;
|
|
104
95
|
var _taskQueue: Queue;
|
|
@@ -112,14 +103,30 @@ declare global {
|
|
|
112
103
|
unknown,
|
|
113
104
|
unknown
|
|
114
105
|
>;
|
|
115
|
-
/** Only in Bundle Mode on Worklet Runtimes. */
|
|
116
|
-
var TurboModules: Map<string, unknown>;
|
|
117
106
|
/**
|
|
118
107
|
* Native logging hook installed by React Native on the RN Runtime and
|
|
119
108
|
* propagated to Worklet Runtimes in Bundle Mode. Level values match RN's
|
|
120
109
|
* `LOG_LEVELS`: 0 = trace, 1 = info, 2 = warn, 3 = error.
|
|
121
110
|
*/
|
|
122
111
|
var nativeLoggingHook: ((message: string, level: number) => void) | undefined;
|
|
112
|
+
/** Only in Bundle Mode on Worklet Runtimes. */
|
|
113
|
+
var __workletsNetworking:
|
|
114
|
+
| {
|
|
115
|
+
sendRequest(
|
|
116
|
+
config: {
|
|
117
|
+
method: string;
|
|
118
|
+
url: string;
|
|
119
|
+
headers: Array<[string, string]>;
|
|
120
|
+
body?: string | ArrayBuffer;
|
|
121
|
+
timeoutMs: number;
|
|
122
|
+
withCredentials: boolean;
|
|
123
|
+
},
|
|
124
|
+
onEvent: (type: string, payload: unknown) => void
|
|
125
|
+
): number;
|
|
126
|
+
abortRequest(requestId: number): void;
|
|
127
|
+
decodeText(buffer: ArrayBuffer, encoding?: string): string;
|
|
128
|
+
}
|
|
129
|
+
| undefined;
|
|
123
130
|
interface NodeRequire {
|
|
124
131
|
resolveWeak(id: string): number;
|
|
125
132
|
getModules(): Map<number, unknown>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// See https://github.com/facebook/hermes/blob/829dcd74f5b774d19a86ab1dc47e3dee9e44d190/lib/VM/JSLib/HermesInternal.cpp#L421-L432.
|
|
4
|
+
type IHermesInternal = typeof HermesInternal & {
|
|
5
|
+
enqueueJob: (job: () => void) => void;
|
|
6
|
+
};
|
|
7
|
+
export function setupQueueMicrotask() {
|
|
8
|
+
'worklet';
|
|
9
|
+
globalThis.queueMicrotask = (
|
|
10
|
+
(globalThis as Record<string, unknown>).HermesInternal as IHermesInternal
|
|
11
|
+
).enqueueJob;
|
|
12
|
+
}
|
|
@@ -21,14 +21,17 @@ export function setupRequestAnimationFrame() {
|
|
|
21
21
|
flushedCallbacksEnd = queuedCallbacksEnd;
|
|
22
22
|
queuedCallbacksBegin = queuedCallbacksEnd;
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
callback
|
|
24
|
+
if (flushedCallbacks.length > 0) {
|
|
25
|
+
for (const callback of flushedCallbacks) {
|
|
26
|
+
callback(timestamp);
|
|
27
|
+
globalThis.__drainMicrotasks();
|
|
28
|
+
}
|
|
29
|
+
} else {
|
|
30
|
+
globalThis.__drainMicrotasks();
|
|
26
31
|
}
|
|
27
32
|
|
|
28
33
|
flushedCallbacksBegin = flushedCallbacksEnd;
|
|
29
34
|
|
|
30
|
-
globalThis.__callMicrotasks();
|
|
31
|
-
|
|
32
35
|
const finalizers = queuedFinalizers;
|
|
33
36
|
queuedFinalizers = [];
|
|
34
37
|
for (const finalizer of finalizers) {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
import { setupQueueMicrotask } from '../common/queueMicrotaskPolyfill';
|
|
3
4
|
import { setupSetImmediate } from '../common/setImmediatePolyfill';
|
|
4
5
|
import { setupSetInterval } from '../common/setIntervalPolyfill';
|
|
5
|
-
import { setupQueueMicrotask } from './queueMicrotask';
|
|
6
6
|
import { setupRequestAnimationFrame } from './requestAnimationFramePolyfill';
|
|
7
7
|
import { setupSetTimeout } from './setTimeout';
|
|
8
8
|
import { setupTaskQueue } from './taskQueue';
|
|
@@ -27,7 +27,7 @@ export function setupRequestAnimationFrame(animationQueuePollingRate: number) {
|
|
|
27
27
|
|
|
28
28
|
for (const callback of flushedCallbacks) {
|
|
29
29
|
callback(timestamp);
|
|
30
|
-
globalThis.
|
|
30
|
+
globalThis.__drainMicrotasks();
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
flushedCallbacksBegin = flushedCallbacksEnd;
|
|
@@ -3,14 +3,12 @@
|
|
|
3
3
|
type Callback = () => void;
|
|
4
4
|
|
|
5
5
|
export type Queue = {
|
|
6
|
-
microtasks: Array<Callback>;
|
|
7
6
|
timeoutCallbacks: Map<number, Callback>;
|
|
8
7
|
};
|
|
9
8
|
|
|
10
9
|
export function setupTaskQueue() {
|
|
11
10
|
'worklet';
|
|
12
11
|
const queue: Queue = {
|
|
13
|
-
microtasks: [],
|
|
14
12
|
timeoutCallbacks: new Map(),
|
|
15
13
|
};
|
|
16
14
|
globalThis._taskQueue = queue;
|
|
@@ -20,19 +18,6 @@ export function setupTaskQueue() {
|
|
|
20
18
|
task?.();
|
|
21
19
|
queue.timeoutCallbacks.delete(handlerId);
|
|
22
20
|
};
|
|
23
|
-
|
|
24
|
-
globalThis.__callMicrotasks = function callMicrotasks() {
|
|
25
|
-
for (let i = 0; i < queue.microtasks.length; i++) {
|
|
26
|
-
queue.microtasks[i]();
|
|
27
|
-
}
|
|
28
|
-
queue.microtasks = [];
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export function pushMicrotask(callback: Callback) {
|
|
33
|
-
'worklet';
|
|
34
|
-
const queue = globalThis._taskQueue;
|
|
35
|
-
queue.microtasks.push(callback);
|
|
36
21
|
}
|
|
37
22
|
|
|
38
23
|
export function pushTask(callback: Callback, handlerId: number, delay: number) {
|
package/src/runtimes.native.ts
CHANGED
|
@@ -82,6 +82,7 @@ export function createWorkletRuntime(
|
|
|
82
82
|
let animationQueuePollingRate: number;
|
|
83
83
|
let enableEventLoop = true;
|
|
84
84
|
let enableLocking = true;
|
|
85
|
+
let enableNetworking = true;
|
|
85
86
|
if (typeof nameOrConfig === 'string') {
|
|
86
87
|
name = nameOrConfig;
|
|
87
88
|
initializerFn = initializer;
|
|
@@ -106,6 +107,13 @@ export function createWorkletRuntime(
|
|
|
106
107
|
enableEventLoop = enableLocking
|
|
107
108
|
? (nameOrConfig?.enableEventLoop ?? true)
|
|
108
109
|
: false;
|
|
110
|
+
/**
|
|
111
|
+
* The networking API depends on the Event Loop - `whatwg-fetch` resolves
|
|
112
|
+
* its responses through `setTimeout`. Without it, requests would hang
|
|
113
|
+
* instead of failing visibly.
|
|
114
|
+
*/
|
|
115
|
+
enableNetworking =
|
|
116
|
+
(nameOrConfig?.enableNetworking ?? true) && enableEventLoop;
|
|
109
117
|
}
|
|
110
118
|
|
|
111
119
|
const useDefaultQueue = queue === 'default';
|
|
@@ -136,7 +144,8 @@ export function createWorkletRuntime(
|
|
|
136
144
|
useDefaultQueue,
|
|
137
145
|
customQueue,
|
|
138
146
|
enableEventLoop,
|
|
139
|
-
enableLocking
|
|
147
|
+
enableLocking,
|
|
148
|
+
enableNetworking
|
|
140
149
|
);
|
|
141
150
|
}
|
|
142
151
|
|
|
@@ -4,6 +4,7 @@ import { type TurboModule, TurboModuleRegistry } from 'react-native';
|
|
|
4
4
|
|
|
5
5
|
export interface Spec extends TurboModule {
|
|
6
6
|
installTurboModule: (bundleModeEnabled: boolean) => boolean;
|
|
7
|
+
prepareBundleMode: () => boolean;
|
|
7
8
|
toggleSlowAnimationsOnUIRuntime: () => boolean;
|
|
8
9
|
start: () => boolean;
|
|
9
10
|
}
|
package/src/threads.native.ts
CHANGED
|
@@ -19,42 +19,36 @@ const SHOULD_CAPTURE_SCHEDULE_STACK =
|
|
|
19
19
|
type UIJob<Args extends unknown[] = unknown[], ReturnValue = unknown> = [
|
|
20
20
|
worklet: WorkletFunction<Args, ReturnValue>,
|
|
21
21
|
args: Args,
|
|
22
|
-
resolve:
|
|
22
|
+
resolve:
|
|
23
|
+
| ((value: ReturnValue | PromiseLike<ReturnValue>) => void)
|
|
24
|
+
| undefined,
|
|
23
25
|
reject: ((reason: unknown) => void) | undefined,
|
|
24
26
|
scheduleStack: string | undefined,
|
|
25
27
|
];
|
|
26
28
|
|
|
27
29
|
let runOnUIQueue: UIJob[] = [];
|
|
28
30
|
|
|
29
|
-
|
|
31
|
+
function runAsyncUIJob<Args extends unknown[], ReturnValue>(
|
|
32
|
+
workletFunction: WorkletFunction<Args, ReturnValue>,
|
|
33
|
+
workletArgs: Args,
|
|
34
|
+
resolve: (value: ReturnValue | PromiseLike<ReturnValue>) => void,
|
|
35
|
+
reject: (reason: unknown) => void
|
|
36
|
+
): void {
|
|
30
37
|
'worklet';
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
if (isExecutingMicrotasksQueue) {
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
try {
|
|
45
|
-
isExecutingMicrotasksQueue = true;
|
|
46
|
-
for (let index = 0; index < microtasksQueue.length; index += 1) {
|
|
47
|
-
// we use classic 'for' loop because the size of the currentTasks array may change while executing some of the callbacks due to queueMicrotask calls
|
|
48
|
-
microtasksQueue[index]();
|
|
49
|
-
}
|
|
50
|
-
microtasksQueue = [];
|
|
51
|
-
globalThis._microtaskQueueFinalizers.forEach((finalizer) => finalizer());
|
|
52
|
-
} finally {
|
|
53
|
-
isExecutingMicrotasksQueue = false;
|
|
54
|
-
}
|
|
55
|
-
};
|
|
38
|
+
try {
|
|
39
|
+
const result = workletFunction(...workletArgs);
|
|
40
|
+
const serializedResult = globalThis.__serializer(
|
|
41
|
+
result
|
|
42
|
+
) as SerializableRef<ReturnValue>;
|
|
43
|
+
globalThis.__workletsModuleProxy.handlePromise(resolve, serializedResult);
|
|
44
|
+
} catch (error) {
|
|
45
|
+
const serializedError = globalThis.__serializer(error);
|
|
46
|
+
globalThis.__workletsModuleProxy.handlePromise(reject, serializedError);
|
|
47
|
+
}
|
|
56
48
|
}
|
|
57
49
|
|
|
50
|
+
let serializableRunAsyncUIJob: SerializableRef | undefined;
|
|
51
|
+
|
|
58
52
|
/**
|
|
59
53
|
* Lets you schedule a function to be executed on the [UI
|
|
60
54
|
* Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/runtimeKinds#ui-runtime).
|
|
@@ -341,7 +335,7 @@ export function runOnUIAsync<Args extends unknown[], ReturnValue>(
|
|
|
341
335
|
function enqueueUI<Args extends unknown[], ReturnValue>(
|
|
342
336
|
worklet: WorkletFunction<Args, ReturnValue>,
|
|
343
337
|
args: Args,
|
|
344
|
-
resolve?: (value: ReturnValue) => void,
|
|
338
|
+
resolve?: (value: ReturnValue | PromiseLike<ReturnValue>) => void,
|
|
345
339
|
reject?: (reason: unknown) => void
|
|
346
340
|
): void {
|
|
347
341
|
const scheduleStack = SHOULD_CAPTURE_SCHEDULE_STACK
|
|
@@ -361,42 +355,43 @@ function flushUIQueue(): void {
|
|
|
361
355
|
queueMicrotask(() => {
|
|
362
356
|
const queue = runOnUIQueue;
|
|
363
357
|
runOnUIQueue = [];
|
|
364
|
-
const jobWorklets =
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
if (reject) {
|
|
379
|
-
const serializedError = globalThis.__serializer(error);
|
|
380
|
-
globalThis.__workletsModuleProxy.handlePromise(
|
|
381
|
-
reject,
|
|
382
|
-
serializedError
|
|
383
|
-
);
|
|
384
|
-
} else {
|
|
385
|
-
throw error;
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
})
|
|
389
|
-
);
|
|
358
|
+
const jobWorklets: SerializableRef[] = [];
|
|
359
|
+
const jobArguments: SerializableRef<unknown[]>[] = [];
|
|
360
|
+
for (const [workletFunction, workletArgs, resolve, reject] of queue) {
|
|
361
|
+
if (resolve === undefined) {
|
|
362
|
+
jobWorklets.push(createSerializable(workletFunction));
|
|
363
|
+
jobArguments.push(createSerializable(workletArgs));
|
|
364
|
+
} else {
|
|
365
|
+
serializableRunAsyncUIJob ??= createSerializable(runAsyncUIJob);
|
|
366
|
+
jobWorklets.push(serializableRunAsyncUIJob);
|
|
367
|
+
jobArguments.push(
|
|
368
|
+
createSerializable([workletFunction, workletArgs, resolve, reject!])
|
|
369
|
+
);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
390
372
|
const scheduleStacks = SHOULD_CAPTURE_SCHEDULE_STACK
|
|
391
373
|
? (queue.map(([, , , , scheduleStack]) => scheduleStack) as string[])
|
|
392
374
|
: undefined;
|
|
393
375
|
WorkletsModule.scheduleOnUI(
|
|
394
376
|
WorkletsModule.createSerializableArray(jobWorklets),
|
|
377
|
+
WorkletsModule.createSerializableArray(jobArguments),
|
|
395
378
|
scheduleStacks
|
|
396
379
|
);
|
|
397
380
|
});
|
|
398
381
|
}
|
|
399
382
|
|
|
383
|
+
/**
|
|
384
|
+
* Returns the id of the thread which currently executes JavaScript on the
|
|
385
|
+
* calling Runtime.
|
|
386
|
+
*
|
|
387
|
+
* @returns The id of the current thread.
|
|
388
|
+
* @see https://docs.swmansion.com/react-native-worklets/docs/utility/getCurrentThreadId
|
|
389
|
+
*/
|
|
390
|
+
export function getCurrentThreadId(): string {
|
|
391
|
+
'worklet';
|
|
392
|
+
return globalThis.__workletsModuleProxy.getCurrentThreadId();
|
|
393
|
+
}
|
|
394
|
+
|
|
400
395
|
if (__DEV__ && !isBundleModeEnabled()) {
|
|
401
396
|
/**
|
|
402
397
|
* QoL guards to give a meaningful error message when the user tries to call
|
package/src/threads.ts
CHANGED
|
@@ -120,3 +120,14 @@ function drainUIQueue(queue: UIJob[]): void {
|
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Returns the id of the thread which currently executes JavaScript on the
|
|
126
|
+
* calling Runtime.
|
|
127
|
+
*
|
|
128
|
+
* @returns The id of the current thread.
|
|
129
|
+
* @see https://docs.swmansion.com/react-native-worklets/docs/utility/getCurrentThreadId
|
|
130
|
+
*/
|
|
131
|
+
export function getCurrentThreadId(): string {
|
|
132
|
+
throw new Error('[Worklets] `getCurrentThreadId` is not supported on web.');
|
|
133
|
+
}
|