@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,83 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
import { toArrayBuffer } from "./bytes.js";
|
|
4
|
+
import { utf8Decode } from "./utf8.js";
|
|
5
|
+
const EMPTY = 0;
|
|
6
|
+
const LOADING = 1;
|
|
7
|
+
const DONE = 2;
|
|
8
|
+
const CHARSET_PARAMETER_PATTERN = /;\s*charset\s*=\s*("([^"]*)"|([^;\s]*))/i;
|
|
9
|
+
export class FileReader {
|
|
10
|
+
static EMPTY = EMPTY;
|
|
11
|
+
static LOADING = LOADING;
|
|
12
|
+
static DONE = DONE;
|
|
13
|
+
EMPTY = EMPTY;
|
|
14
|
+
LOADING = LOADING;
|
|
15
|
+
DONE = DONE;
|
|
16
|
+
readyState = EMPTY;
|
|
17
|
+
result = null;
|
|
18
|
+
error = null;
|
|
19
|
+
onload = null;
|
|
20
|
+
onerror = null;
|
|
21
|
+
onloadend = null;
|
|
22
|
+
readAsArrayBuffer(blob) {
|
|
23
|
+
this.read(() => toArrayBuffer(readBytes(blob)));
|
|
24
|
+
}
|
|
25
|
+
readAsText(blob, encoding) {
|
|
26
|
+
this.read(() => {
|
|
27
|
+
const bytes = readBytes(blob);
|
|
28
|
+
const resolvedEncoding = encoding ?? extractCharset(blob.type);
|
|
29
|
+
const networking = globalThis.__workletsNetworking;
|
|
30
|
+
if (networking !== undefined) {
|
|
31
|
+
return networking.decodeText(toArrayBuffer(bytes), resolvedEncoding);
|
|
32
|
+
}
|
|
33
|
+
return utf8Decode(bytes);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
read(produceResult) {
|
|
37
|
+
if (this.readyState === LOADING) {
|
|
38
|
+
throw new Error("[Worklets] Failed to execute 'read' on 'FileReader': the object is already loading.");
|
|
39
|
+
}
|
|
40
|
+
this.result = null;
|
|
41
|
+
this.error = null;
|
|
42
|
+
this.readyState = LOADING;
|
|
43
|
+
/**
|
|
44
|
+
* The File API fires read events from a task, not from a microtask, so
|
|
45
|
+
* `setTimeout` is used here rather than `queueMicrotask`. Reads are started
|
|
46
|
+
* from Promise continuations, which makes the distinction observable.
|
|
47
|
+
*/
|
|
48
|
+
setTimeout(() => {
|
|
49
|
+
let failed = false;
|
|
50
|
+
try {
|
|
51
|
+
this.result = produceResult();
|
|
52
|
+
} catch (error) {
|
|
53
|
+
this.error = error;
|
|
54
|
+
failed = true;
|
|
55
|
+
}
|
|
56
|
+
this.readyState = DONE;
|
|
57
|
+
invoke(failed ? this.onerror : this.onload);
|
|
58
|
+
invoke(this.onloadend);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function invoke(handler) {
|
|
63
|
+
try {
|
|
64
|
+
handler?.();
|
|
65
|
+
} catch (error) {
|
|
66
|
+
console.error(error);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function readBytes(blob) {
|
|
70
|
+
if (typeof blob?.__getBytes !== 'function') {
|
|
71
|
+
throw new Error('[Worklets] FileReader can only read a Blob created by the Worklets networking module.');
|
|
72
|
+
}
|
|
73
|
+
return blob.__getBytes();
|
|
74
|
+
}
|
|
75
|
+
function extractCharset(mimeType) {
|
|
76
|
+
const match = CHARSET_PARAMETER_PATTERN.exec(mimeType);
|
|
77
|
+
if (match === null) {
|
|
78
|
+
return undefined;
|
|
79
|
+
}
|
|
80
|
+
const charset = match[2] ?? match[3] ?? '';
|
|
81
|
+
return charset !== '' ? charset : undefined;
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=FileReader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["toArrayBuffer","utf8Decode","EMPTY","LOADING","DONE","CHARSET_PARAMETER_PATTERN","FileReader","readyState","result","error","onload","onerror","onloadend","readAsArrayBuffer","blob","read","readBytes","readAsText","encoding","bytes","resolvedEncoding","extractCharset","type","networking","globalThis","__workletsNetworking","undefined","decodeText","produceResult","Error","setTimeout","failed","invoke","handler","console","__getBytes","mimeType","match","exec","charset"],"sourceRoot":"../../../src","sources":["networking/FileReader.ts"],"mappings":"AAAA,YAAY;;AAGZ,SAASA,aAAa,QAAQ,YAAS;AACvC,SAASC,UAAU,QAAQ,WAAQ;AAEnC,MAAMC,KAAK,GAAG,CAAC;AACf,MAAMC,OAAO,GAAG,CAAC;AACjB,MAAMC,IAAI,GAAG,CAAC;AAEd,MAAMC,yBAAyB,GAAG,0CAA0C;AAE5E,OAAO,MAAMC,UAAU,CAAC;EACtB,OAAgBJ,KAAK,GAAGA,KAAK;EA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QACF,IAAI,CAACvB,MAAM,GAAGoB,aAAa,CAAC,CAAC;MAC/B,CAAC,CAAC,OAAOnB,KAAK,EAAE;QACd,IAAI,CAACA,KAAK,GAAGA,KAAK;QAClBsB,MAAM,GAAG,IAAI;MACf;MACA,IAAI,CAACxB,UAAU,GAAGH,IAAI;MACtB4B,MAAM,CAACD,MAAM,GAAG,IAAI,CAACpB,OAAO,GAAG,IAAI,CAACD,MAAM,CAAC;MAC3CsB,MAAM,CAAC,IAAI,CAACpB,SAAS,CAAC;IACxB,CAAC,CAAC;EACJ;AACF;AAEA,SAASoB,MAAMA,CAACC,OAA4B,EAAE;EAC5C,IAAI;IACFA,OAAO,GAAG,CAAC;EACb,CAAC,CAAC,OAAOxB,KAAK,EAAE;IACdyB,OAAO,CAACzB,KAAK,CAACA,KAAK,CAAC;EACtB;AACF;AAEA,SAASO,SAASA,CAACF,IAAU,EAAc;EACzC,IAAI,OAAOA,IAAI,EAAEqB,UAAU,KAAK,UAAU,EAAE;IAC1C,MAAM,IAAIN,KAAK,CACb,uFACF,CAAC;EACH;EACA,OAAOf,IAAI,CAACqB,UAAU,CAAC,CAAC;AAC1B;AAEA,SAASd,cAAcA,CAACe,QAAgB,EAAsB;EAC5D,MAAMC,KAAK,GAAGhC,yBAAyB,CAACiC,IAAI,CAACF,QAAQ,CAAC;EACtD,IAAIC,KAAK,KAAK,IAAI,EAAE;IAClB,OAAOX,SAAS;EAClB;EACA,MAAMa,OAAO,GAAGF,KAAK,CAAC,CAAC,CAAC,IAAIA,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE;EAC1C,OAAOE,OAAO,KAAK,EAAE,GAAGA,OAAO,GAAGb,SAAS;AAC7C","ignoreList":[]}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
import { toArrayBuffer } from "./bytes.js";
|
|
4
|
+
import { utf8Encode } from "./utf8.js";
|
|
5
|
+
export class FormData {
|
|
6
|
+
formEntries = [];
|
|
7
|
+
get [Symbol.toStringTag]() {
|
|
8
|
+
return 'FormData';
|
|
9
|
+
}
|
|
10
|
+
append(name, value) {
|
|
11
|
+
if (value !== null && typeof value === 'object') {
|
|
12
|
+
throw new TypeError("[Worklets] Failed to execute 'append' on 'FormData': only string values are supported.");
|
|
13
|
+
}
|
|
14
|
+
this.formEntries.push([String(name), String(value)]);
|
|
15
|
+
}
|
|
16
|
+
set(name, value) {
|
|
17
|
+
this.delete(name);
|
|
18
|
+
this.append(name, value);
|
|
19
|
+
}
|
|
20
|
+
get(name) {
|
|
21
|
+
const entry = this.formEntries.find(([entryName]) => entryName === String(name));
|
|
22
|
+
return entry !== undefined ? entry[1] : null;
|
|
23
|
+
}
|
|
24
|
+
getAll(name) {
|
|
25
|
+
return this.formEntries.filter(([entryName]) => entryName === String(name)).map(([, value]) => value);
|
|
26
|
+
}
|
|
27
|
+
has(name) {
|
|
28
|
+
return this.formEntries.some(([entryName]) => entryName === String(name));
|
|
29
|
+
}
|
|
30
|
+
delete(name) {
|
|
31
|
+
this.formEntries = this.formEntries.filter(([entryName]) => entryName !== String(name));
|
|
32
|
+
}
|
|
33
|
+
forEach(callback) {
|
|
34
|
+
for (const [name, value] of this.formEntries) {
|
|
35
|
+
callback(value, name, this);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
*entries() {
|
|
39
|
+
for (const [name, value] of this.formEntries) {
|
|
40
|
+
yield [name, value];
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
*keys() {
|
|
44
|
+
for (const [name] of this.formEntries) {
|
|
45
|
+
yield name;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
*values() {
|
|
49
|
+
for (const [, value] of this.formEntries) {
|
|
50
|
+
yield value;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
[Symbol.iterator]() {
|
|
54
|
+
return this.entries();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Mirrors React Native's non-standard `FormData.getParts`. Its presence makes
|
|
59
|
+
* libraries like Axios treat this object as a React Native `FormData` and
|
|
60
|
+
* leave the multipart encoding to `XMLHttpRequest`.
|
|
61
|
+
*/
|
|
62
|
+
getParts() {
|
|
63
|
+
return this.formEntries.map(([name, value]) => ({
|
|
64
|
+
string: value,
|
|
65
|
+
fieldName: name,
|
|
66
|
+
headers: {
|
|
67
|
+
'content-disposition': `form-data; name="${escapeName(name)}"`
|
|
68
|
+
}
|
|
69
|
+
}));
|
|
70
|
+
}
|
|
71
|
+
__encodeMultipart() {
|
|
72
|
+
const parts = this.formEntries.map(([name, value]) => `content-disposition: form-data; name="${escapeName(name)}"\r\n\r\n${value}`);
|
|
73
|
+
const boundary = pickBoundary(parts);
|
|
74
|
+
let encoded = '';
|
|
75
|
+
for (const part of parts) {
|
|
76
|
+
encoded += `--${boundary}\r\n${part}\r\n`;
|
|
77
|
+
}
|
|
78
|
+
encoded += `--${boundary}--\r\n`;
|
|
79
|
+
return {
|
|
80
|
+
body: toArrayBuffer(utf8Encode(encoded)),
|
|
81
|
+
contentType: `multipart/form-data; boundary=${boundary}`
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Picks a boundary that appears in none of the parts. Entry values are written
|
|
88
|
+
* verbatim, so a value that contained the boundary could otherwise inject
|
|
89
|
+
* arbitrary parts into the request.
|
|
90
|
+
*/
|
|
91
|
+
function pickBoundary(parts) {
|
|
92
|
+
for (;;) {
|
|
93
|
+
const boundary = `----WorkletsFormDataBoundary${randomToken()}${randomToken()}`;
|
|
94
|
+
if (!parts.some(part => part.includes(boundary))) {
|
|
95
|
+
return boundary;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
function randomToken() {
|
|
100
|
+
return Math.random().toString(36).slice(2).padEnd(11, '0');
|
|
101
|
+
}
|
|
102
|
+
function escapeName(name) {
|
|
103
|
+
return name.replace(/\r/g, '%0D').replace(/\n/g, '%0A').replace(/"/g, '%22');
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=FormData.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["toArrayBuffer","utf8Encode","FormData","formEntries","Symbol","toStringTag","append","name","value","TypeError","push","String","set","delete","get","entry","find","entryName","undefined","getAll","filter","map","has","some","forEach","callback","entries","keys","values","iterator","getParts","string","fieldName","headers","escapeName","__encodeMultipart","parts","boundary","pickBoundary","encoded","part","body","contentType","randomToken","includes","Math","random","toString","slice","padEnd","replace"],"sourceRoot":"../../../src","sources":["networking/FormData.ts"],"mappings":"AAAA,YAAY;;AAEZ,SAASA,aAAa,QAAQ,YAAS;AACvC,SAASC,UAAU,QAAQ,WAAQ;AAEnC,OAAO,MAAMC,QAAQ,CAAC;EACZC,WAAW,GAA4B,EAAE;EAEjD,KAAKC,MAAM,CAACC,WAAW,IAAI;IACzB,OAAO,UAAU;EACnB;EAEAC,MAAMA,CAACC,IAAY,EAAEC,KAAc,EAAE;IACnC,IAAIA,KAAK,KAAK,IAAI,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE;MAC/C,MAAM,IAAIC,SAAS,CACjB,wFACF,CAAC;IACH;IACA,IAAI,CAACN,WAAW,CAACO,IAAI,CAAC,CAACC,MAAM,CAACJ,IAAI,CAAC,EAAEI,MAAM,CAACH,KAAK,CAAC,CAAC,CAAC;EACtD;EAEAI,GAAGA,CAACL,IAAY,EAAEC,KAAc,EAAE;IAChC,IAAI,CAACK,MAAM,CAACN,IAAI,CAAC;IACjB,IAAI,CAACD,MAAM,CAACC,IAAI,EAAEC,KAAK,CAAC;EAC1B;EAEAM,GAAGA,CAACP,IAAY,EAAiB;IAC/B,MAAMQ,KAAK,GAAG,IAAI,CAACZ,WAAW,CAACa,IAAI,CACjC,CAAC,CAACC,SAAS,CAAC,KAAKA,SAAS,KAAKN,MAAM,CAACJ,IAAI,CAC5C,CAAC;IACD,OAAOQ,KAAK,KAAKG,SAAS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ACP,QAAQ,CAAC,CAAC,EAAE;MAClD,OAAOA,QAAQ;IACjB;EACF;AACF;AAEA,SAASM,WAAWA,CAAA,EAAW;EAC7B,OAAOE,IAAI,CAACC,MAAM,CAAC,CAAC,CAACC,QAAQ,CAAC,EAAE,CAAC,CAACC,KAAK,CAAC,CAAC,CAAC,CAACC,MAAM,CAAC,EAAE,EAAE,GAAG,CAAC;AAC5D;AAEA,SAASf,UAAUA,CAAC3B,IAAY,EAAU;EACxC,OAAOA,IAAI,CAAC2C,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAACA,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAACA,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC;AAC9E","ignoreList":[]}
|
|
@@ -0,0 +1,450 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
import { Blob } from "./Blob.js";
|
|
4
|
+
import { toArrayBuffer } from "./bytes.js";
|
|
5
|
+
import { DOMException } from "./DOMException.js";
|
|
6
|
+
import { EventTargetLite } from "./events.js";
|
|
7
|
+
import { FormData } from "./FormData.js";
|
|
8
|
+
import { combineHeader, extractCharset, getHeader, hasHeader, isForbiddenMethod, isForbiddenRequestHeader, isHeaderName, isHeaderValue, isSupportedRequestUrl, isToken, normalizeHeaderValue, normalizeMethod, sortAndCombineHeaders } from "./http.js";
|
|
9
|
+
import { stripUtf8Bom, utf8Decode, utf8Encode } from "./utf8.js";
|
|
10
|
+
const UNSENT = 0;
|
|
11
|
+
const OPENED = 1;
|
|
12
|
+
const HEADERS_RECEIVED = 2;
|
|
13
|
+
const LOADING = 3;
|
|
14
|
+
const DONE = 4;
|
|
15
|
+
const RESPONSE_TYPES = ['', 'text', 'arraybuffer', 'blob', 'json'];
|
|
16
|
+
class XMLHttpRequestUpload extends EventTargetLite {}
|
|
17
|
+
export class XMLHttpRequest extends EventTargetLite {
|
|
18
|
+
static UNSENT = UNSENT;
|
|
19
|
+
static OPENED = OPENED;
|
|
20
|
+
static HEADERS_RECEIVED = HEADERS_RECEIVED;
|
|
21
|
+
static LOADING = LOADING;
|
|
22
|
+
static DONE = DONE;
|
|
23
|
+
UNSENT = UNSENT;
|
|
24
|
+
OPENED = OPENED;
|
|
25
|
+
HEADERS_RECEIVED = HEADERS_RECEIVED;
|
|
26
|
+
LOADING = LOADING;
|
|
27
|
+
DONE = DONE;
|
|
28
|
+
readyState = UNSENT;
|
|
29
|
+
status = 0;
|
|
30
|
+
statusText = '';
|
|
31
|
+
responseURL = '';
|
|
32
|
+
timeout = 0;
|
|
33
|
+
/**
|
|
34
|
+
* The specification defaults this to `false`. React Native's own
|
|
35
|
+
* `XMLHttpRequest` defaults it to `true`, and Worklet Runtimes share the
|
|
36
|
+
* app's cookie storage, so the parity is deliberate.
|
|
37
|
+
*/
|
|
38
|
+
withCredentials = true;
|
|
39
|
+
upload = new XMLHttpRequestUpload();
|
|
40
|
+
onreadystatechange = null;
|
|
41
|
+
onloadstart = null;
|
|
42
|
+
onprogress = null;
|
|
43
|
+
onload = null;
|
|
44
|
+
onloadend = null;
|
|
45
|
+
onerror = null;
|
|
46
|
+
ontimeout = null;
|
|
47
|
+
onabort = null;
|
|
48
|
+
requestId = null;
|
|
49
|
+
requestToken = 0;
|
|
50
|
+
method = 'GET';
|
|
51
|
+
url = '';
|
|
52
|
+
sent = false;
|
|
53
|
+
hasRequestBody = false;
|
|
54
|
+
requestBodyLength = 0;
|
|
55
|
+
uploadSettled = false;
|
|
56
|
+
downloadedBytes = 0;
|
|
57
|
+
mimeTypeOverride = null;
|
|
58
|
+
requestHeaders = [];
|
|
59
|
+
responseHeaders = [];
|
|
60
|
+
responseTypeValue = '';
|
|
61
|
+
responseBytes = null;
|
|
62
|
+
responseBlobValue = null;
|
|
63
|
+
responseTextValue = null;
|
|
64
|
+
responseJsonValue = undefined;
|
|
65
|
+
get responseType() {
|
|
66
|
+
return this.responseTypeValue;
|
|
67
|
+
}
|
|
68
|
+
set responseType(value) {
|
|
69
|
+
if (this.readyState >= LOADING) {
|
|
70
|
+
throw new DOMException("[Worklets] Failed to set 'responseType' on 'XMLHttpRequest': the response type cannot be changed once loading has started.", 'InvalidStateError');
|
|
71
|
+
}
|
|
72
|
+
if (!RESPONSE_TYPES.includes(value)) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
this.responseTypeValue = value;
|
|
76
|
+
}
|
|
77
|
+
get response() {
|
|
78
|
+
switch (this.responseTypeValue) {
|
|
79
|
+
case '':
|
|
80
|
+
case 'text':
|
|
81
|
+
return this.readyState >= LOADING ? this.getResponseText() : '';
|
|
82
|
+
case 'arraybuffer':
|
|
83
|
+
return this.readyState === DONE ? this.responseBytes : null;
|
|
84
|
+
case 'blob':
|
|
85
|
+
if (this.readyState !== DONE || this.responseBytes === null) {
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
if (this.responseBlobValue === null) {
|
|
89
|
+
this.responseBlobValue = new Blob([this.responseBytes], {
|
|
90
|
+
type: this.mimeTypeOverride ?? this.getResponseHeader('content-type') ?? ''
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
return this.responseBlobValue;
|
|
94
|
+
case 'json':
|
|
95
|
+
if (this.readyState !== DONE) {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
if (this.responseJsonValue === undefined) {
|
|
99
|
+
try {
|
|
100
|
+
this.responseJsonValue = JSON.parse(this.responseBytes === null ? '' : utf8Decode(stripUtf8Bom(new Uint8Array(this.responseBytes))));
|
|
101
|
+
} catch {
|
|
102
|
+
this.responseJsonValue = null;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return this.responseJsonValue;
|
|
106
|
+
default:
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
get responseText() {
|
|
111
|
+
if (this.responseTypeValue !== '' && this.responseTypeValue !== 'text') {
|
|
112
|
+
throw new DOMException("[Worklets] Failed to read 'responseText' on 'XMLHttpRequest': the value is only accessible if the object's 'responseType' is '' or 'text'.", 'InvalidStateError');
|
|
113
|
+
}
|
|
114
|
+
return this.readyState >= LOADING ? this.getResponseText() : '';
|
|
115
|
+
}
|
|
116
|
+
open(method, url, async = true) {
|
|
117
|
+
const methodValue = String(method);
|
|
118
|
+
const urlValue = String(url);
|
|
119
|
+
if (!isToken(methodValue)) {
|
|
120
|
+
throw new DOMException(`[Worklets] Failed to execute 'open' on 'XMLHttpRequest': '${methodValue}' is not a valid HTTP method.`, 'SyntaxError');
|
|
121
|
+
}
|
|
122
|
+
if (isForbiddenMethod(methodValue)) {
|
|
123
|
+
throw new DOMException(`[Worklets] Failed to execute 'open' on 'XMLHttpRequest': '${methodValue}' HTTP method is unsupported.`, 'SecurityError');
|
|
124
|
+
}
|
|
125
|
+
if (urlValue === '') {
|
|
126
|
+
throw new DOMException("[Worklets] Failed to execute 'open' on 'XMLHttpRequest': the URL cannot be empty.", 'SyntaxError');
|
|
127
|
+
}
|
|
128
|
+
if (!async) {
|
|
129
|
+
throw new DOMException('[Worklets] Synchronous XMLHttpRequest is not supported.', 'InvalidAccessError');
|
|
130
|
+
}
|
|
131
|
+
this.terminate();
|
|
132
|
+
this.method = normalizeMethod(methodValue);
|
|
133
|
+
this.url = urlValue;
|
|
134
|
+
this.sent = false;
|
|
135
|
+
this.hasRequestBody = false;
|
|
136
|
+
this.requestBodyLength = 0;
|
|
137
|
+
this.uploadSettled = false;
|
|
138
|
+
this.mimeTypeOverride = null;
|
|
139
|
+
this.requestHeaders = [];
|
|
140
|
+
this.resetResponse();
|
|
141
|
+
if (this.readyState !== OPENED) {
|
|
142
|
+
this.setReadyState(OPENED);
|
|
143
|
+
} else {
|
|
144
|
+
this.readyState = OPENED;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
setRequestHeader(name, value) {
|
|
148
|
+
if (this.readyState !== OPENED || this.sent) {
|
|
149
|
+
throw new DOMException("[Worklets] Failed to execute 'setRequestHeader' on 'XMLHttpRequest': the object's state must be OPENED.", 'InvalidStateError');
|
|
150
|
+
}
|
|
151
|
+
const nameValue = String(name);
|
|
152
|
+
const headerValue = normalizeHeaderValue(String(value));
|
|
153
|
+
if (!isHeaderName(nameValue) || !isHeaderValue(headerValue)) {
|
|
154
|
+
throw new DOMException(`[Worklets] Failed to execute 'setRequestHeader' on 'XMLHttpRequest': '${nameValue}: ${headerValue}' is not a valid header.`, 'SyntaxError');
|
|
155
|
+
}
|
|
156
|
+
if (isForbiddenRequestHeader(nameValue, headerValue)) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
combineHeader(this.requestHeaders, nameValue, headerValue);
|
|
160
|
+
}
|
|
161
|
+
getAllResponseHeaders() {
|
|
162
|
+
return sortAndCombineHeaders(this.responseHeaders);
|
|
163
|
+
}
|
|
164
|
+
getResponseHeader(name) {
|
|
165
|
+
return getHeader(this.responseHeaders, String(name));
|
|
166
|
+
}
|
|
167
|
+
overrideMimeType(mimeType) {
|
|
168
|
+
if (this.readyState >= LOADING) {
|
|
169
|
+
throw new DOMException("[Worklets] Failed to execute 'overrideMimeType' on 'XMLHttpRequest': the MIME type cannot be overridden once loading has started.", 'InvalidStateError');
|
|
170
|
+
}
|
|
171
|
+
this.mimeTypeOverride = String(mimeType);
|
|
172
|
+
this.responseTextValue = null;
|
|
173
|
+
}
|
|
174
|
+
send(body) {
|
|
175
|
+
const networking = globalThis.__workletsNetworking;
|
|
176
|
+
if (networking === undefined) {
|
|
177
|
+
throw new DOMException('[Worklets] XMLHttpRequest is not available on this runtime.', 'InvalidStateError');
|
|
178
|
+
}
|
|
179
|
+
if (this.readyState !== OPENED || this.sent) {
|
|
180
|
+
throw new DOMException("[Worklets] Failed to execute 'send' on 'XMLHttpRequest': the object's state must be OPENED.", 'InvalidStateError');
|
|
181
|
+
}
|
|
182
|
+
this.sent = true;
|
|
183
|
+
if (!isSupportedRequestUrl(this.url)) {
|
|
184
|
+
this.__dispatch('loadstart');
|
|
185
|
+
setTimeout(() => this.handleRequestError('network', `Only http and https URLs are supported, got '${this.url}'.`));
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
const {
|
|
189
|
+
data,
|
|
190
|
+
contentType
|
|
191
|
+
} = this.method === 'GET' || this.method === 'HEAD' ? {
|
|
192
|
+
data: undefined,
|
|
193
|
+
contentType: undefined
|
|
194
|
+
} : normalizeBody(body);
|
|
195
|
+
const headers = [...this.requestHeaders];
|
|
196
|
+
if (contentType !== undefined && !hasHeader(headers, 'content-type')) {
|
|
197
|
+
headers.push(['Content-Type', contentType]);
|
|
198
|
+
}
|
|
199
|
+
this.hasRequestBody = data !== undefined;
|
|
200
|
+
this.requestBodyLength = typeof data === 'string' ? utf8Encode(data).length : data?.byteLength ?? 0;
|
|
201
|
+
const token = ++this.requestToken;
|
|
202
|
+
this.requestId = networking.sendRequest({
|
|
203
|
+
method: this.method,
|
|
204
|
+
url: this.url,
|
|
205
|
+
headers,
|
|
206
|
+
body: data,
|
|
207
|
+
timeoutMs: this.timeout,
|
|
208
|
+
withCredentials: this.withCredentials
|
|
209
|
+
}, (type, payload) => {
|
|
210
|
+
if (token === this.requestToken && this.requestId !== null) {
|
|
211
|
+
this.handleNetworkingEvent(type, payload);
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
this.__dispatch('loadstart');
|
|
215
|
+
if (this.hasRequestBody) {
|
|
216
|
+
this.upload.__dispatch('loadstart', {
|
|
217
|
+
loaded: 0,
|
|
218
|
+
total: this.requestBodyLength,
|
|
219
|
+
lengthComputable: this.requestBodyLength > 0
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
abort() {
|
|
224
|
+
const wasInFlight = this.terminate();
|
|
225
|
+
if (this.readyState === OPENED && !this.sent) {
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
if (!wasInFlight || this.readyState === UNSENT) {
|
|
229
|
+
this.readyState = UNSENT;
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
if (this.readyState === DONE) {
|
|
233
|
+
this.resetResponse();
|
|
234
|
+
this.readyState = UNSENT;
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
this.resetResponse();
|
|
238
|
+
this.setReadyState(DONE);
|
|
239
|
+
this.settleUploadWithError('abort');
|
|
240
|
+
this.__dispatch('abort');
|
|
241
|
+
this.__dispatch('loadend');
|
|
242
|
+
if (this.readyState === DONE) {
|
|
243
|
+
this.readyState = UNSENT;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
handleNetworkingEvent(type, payload) {
|
|
247
|
+
switch (type) {
|
|
248
|
+
case 'response':
|
|
249
|
+
{
|
|
250
|
+
const {
|
|
251
|
+
status,
|
|
252
|
+
statusText,
|
|
253
|
+
headers,
|
|
254
|
+
url
|
|
255
|
+
} = payload;
|
|
256
|
+
this.status = status;
|
|
257
|
+
this.statusText = statusText;
|
|
258
|
+
this.responseHeaders = headers;
|
|
259
|
+
this.responseURL = url;
|
|
260
|
+
this.settleUploadWithSuccess();
|
|
261
|
+
this.setReadyState(HEADERS_RECEIVED);
|
|
262
|
+
break;
|
|
263
|
+
}
|
|
264
|
+
case 'downloadProgress':
|
|
265
|
+
{
|
|
266
|
+
const {
|
|
267
|
+
loaded,
|
|
268
|
+
total
|
|
269
|
+
} = payload;
|
|
270
|
+
this.downloadedBytes = loaded;
|
|
271
|
+
if (this.readyState === HEADERS_RECEIVED) {
|
|
272
|
+
this.setReadyState(LOADING);
|
|
273
|
+
} else {
|
|
274
|
+
this.__dispatch('readystatechange');
|
|
275
|
+
}
|
|
276
|
+
this.__dispatch('progress', {
|
|
277
|
+
loaded,
|
|
278
|
+
total: total > 0 ? total : 0,
|
|
279
|
+
lengthComputable: total > 0
|
|
280
|
+
});
|
|
281
|
+
break;
|
|
282
|
+
}
|
|
283
|
+
case 'uploadProgress':
|
|
284
|
+
{
|
|
285
|
+
const {
|
|
286
|
+
loaded,
|
|
287
|
+
total
|
|
288
|
+
} = payload;
|
|
289
|
+
this.upload.__dispatch('progress', {
|
|
290
|
+
loaded,
|
|
291
|
+
total: total > 0 ? total : 0,
|
|
292
|
+
lengthComputable: total > 0
|
|
293
|
+
});
|
|
294
|
+
break;
|
|
295
|
+
}
|
|
296
|
+
case 'done':
|
|
297
|
+
{
|
|
298
|
+
this.requestId = null;
|
|
299
|
+
const {
|
|
300
|
+
body,
|
|
301
|
+
error,
|
|
302
|
+
message
|
|
303
|
+
} = payload;
|
|
304
|
+
if (error !== undefined) {
|
|
305
|
+
this.handleRequestError(error, message);
|
|
306
|
+
} else if (this.status === 0) {
|
|
307
|
+
this.handleRequestError('network', 'The request completed without a response.');
|
|
308
|
+
} else {
|
|
309
|
+
this.handleResponseEndOfBody(body);
|
|
310
|
+
}
|
|
311
|
+
break;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
handleRequestError(error, message) {
|
|
316
|
+
const terminalEvent = error === 'timeout' ? 'timeout' : error === 'aborted' ? 'abort' : 'error';
|
|
317
|
+
this.resetResponse();
|
|
318
|
+
this.setReadyState(DONE);
|
|
319
|
+
this.settleUploadWithError(terminalEvent);
|
|
320
|
+
this.__dispatch(terminalEvent, {
|
|
321
|
+
message
|
|
322
|
+
});
|
|
323
|
+
this.__dispatch('loadend');
|
|
324
|
+
}
|
|
325
|
+
handleResponseEndOfBody(body) {
|
|
326
|
+
this.responseBytes = body ?? new ArrayBuffer(0);
|
|
327
|
+
this.responseTextValue = null;
|
|
328
|
+
this.responseBlobValue = null;
|
|
329
|
+
this.responseJsonValue = undefined;
|
|
330
|
+
const transmitted = Math.max(this.responseBytes.byteLength, this.downloadedBytes);
|
|
331
|
+
const rawContentLength = this.getResponseHeader('content-length');
|
|
332
|
+
const contentLength = rawContentLength === null ? Number.NaN : Number(rawContentLength);
|
|
333
|
+
const total = Number.isInteger(contentLength) && contentLength > 0 ? contentLength : 0;
|
|
334
|
+
const progress = {
|
|
335
|
+
loaded: transmitted,
|
|
336
|
+
total,
|
|
337
|
+
lengthComputable: total > 0
|
|
338
|
+
};
|
|
339
|
+
this.settleUploadWithSuccess();
|
|
340
|
+
this.__dispatch('progress', progress);
|
|
341
|
+
this.setReadyState(DONE);
|
|
342
|
+
this.__dispatch('load', progress);
|
|
343
|
+
this.__dispatch('loadend', progress);
|
|
344
|
+
}
|
|
345
|
+
settleUploadWithSuccess() {
|
|
346
|
+
if (!this.hasRequestBody || this.uploadSettled) {
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
this.uploadSettled = true;
|
|
350
|
+
const progress = {
|
|
351
|
+
loaded: this.requestBodyLength,
|
|
352
|
+
total: this.requestBodyLength,
|
|
353
|
+
lengthComputable: this.requestBodyLength > 0
|
|
354
|
+
};
|
|
355
|
+
this.upload.__dispatch('progress', progress);
|
|
356
|
+
this.upload.__dispatch('load', progress);
|
|
357
|
+
this.upload.__dispatch('loadend', progress);
|
|
358
|
+
}
|
|
359
|
+
settleUploadWithError(type) {
|
|
360
|
+
if (!this.hasRequestBody || this.uploadSettled) {
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
this.uploadSettled = true;
|
|
364
|
+
this.upload.__dispatch(type);
|
|
365
|
+
this.upload.__dispatch('loadend');
|
|
366
|
+
}
|
|
367
|
+
getResponseText() {
|
|
368
|
+
if (this.responseTextValue === null) {
|
|
369
|
+
this.responseTextValue = decodeResponseText(this.responseBytes, extractCharset(this.mimeTypeOverride) ?? extractCharset(this.getResponseHeader('content-type')));
|
|
370
|
+
}
|
|
371
|
+
return this.responseTextValue;
|
|
372
|
+
}
|
|
373
|
+
resetResponse() {
|
|
374
|
+
this.status = 0;
|
|
375
|
+
this.statusText = '';
|
|
376
|
+
this.responseURL = '';
|
|
377
|
+
this.downloadedBytes = 0;
|
|
378
|
+
this.responseHeaders = [];
|
|
379
|
+
this.responseBytes = null;
|
|
380
|
+
this.responseTextValue = null;
|
|
381
|
+
this.responseBlobValue = null;
|
|
382
|
+
this.responseJsonValue = undefined;
|
|
383
|
+
}
|
|
384
|
+
terminate() {
|
|
385
|
+
if (this.requestId === null) {
|
|
386
|
+
return this.sent;
|
|
387
|
+
}
|
|
388
|
+
globalThis.__workletsNetworking?.abortRequest(this.requestId);
|
|
389
|
+
this.requestId = null;
|
|
390
|
+
return true;
|
|
391
|
+
}
|
|
392
|
+
setReadyState(readyState) {
|
|
393
|
+
this.readyState = readyState;
|
|
394
|
+
this.__dispatch('readystatechange');
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
function decodeResponseText(bytes, charset) {
|
|
398
|
+
if (bytes === null || bytes.byteLength === 0) {
|
|
399
|
+
return '';
|
|
400
|
+
}
|
|
401
|
+
const networking = globalThis.__workletsNetworking;
|
|
402
|
+
if (networking !== undefined) {
|
|
403
|
+
return networking.decodeText(bytes, charset);
|
|
404
|
+
}
|
|
405
|
+
return utf8Decode(new Uint8Array(bytes));
|
|
406
|
+
}
|
|
407
|
+
function isBlobLike(body) {
|
|
408
|
+
return typeof body?.__getBytes === 'function';
|
|
409
|
+
}
|
|
410
|
+
function normalizeBody(body) {
|
|
411
|
+
if (body === null || body === undefined) {
|
|
412
|
+
return {};
|
|
413
|
+
}
|
|
414
|
+
if (typeof body === 'string') {
|
|
415
|
+
return {
|
|
416
|
+
data: body,
|
|
417
|
+
contentType: 'text/plain;charset=UTF-8'
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
if (body instanceof ArrayBuffer) {
|
|
421
|
+
return {
|
|
422
|
+
data: body
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
if (isBlobLike(body)) {
|
|
426
|
+
return {
|
|
427
|
+
data: toArrayBuffer(body.__getBytes()),
|
|
428
|
+
contentType: body.type !== '' ? body.type : undefined
|
|
429
|
+
};
|
|
430
|
+
}
|
|
431
|
+
if (body instanceof FormData) {
|
|
432
|
+
const {
|
|
433
|
+
body: data,
|
|
434
|
+
contentType
|
|
435
|
+
} = body.__encodeMultipart();
|
|
436
|
+
return {
|
|
437
|
+
data,
|
|
438
|
+
contentType
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
if (ArrayBuffer.isView(body)) {
|
|
442
|
+
return {
|
|
443
|
+
data: toArrayBuffer(new Uint8Array(body.buffer, body.byteOffset, body.byteLength))
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
return {
|
|
447
|
+
data: String(body)
|
|
448
|
+
};
|
|
449
|
+
}
|
|
450
|
+
//# sourceMappingURL=XMLHttpRequest.js.map
|