mphttpx 1.1.0 → 1.2.0-beta.1
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/README.zh-CN.md +982 -0
- package/dist/index.cjs.js +173 -212
- package/dist/index.cjs.min.js +1 -1
- package/dist/index.d.ts +32 -32
- package/dist/index.esm.js +173 -212
- package/dist/index.esm.min.js +1 -1
- package/package.json +2 -1
package/dist/index.cjs.js
CHANGED
|
@@ -9,13 +9,6 @@
|
|
|
9
9
|
/** @internal */
|
|
10
10
|
const polyfill = "MPHTTPX";
|
|
11
11
|
/** @internal */
|
|
12
|
-
function Class_setStringTag(targetFunc, stringTag) {
|
|
13
|
-
Object.defineProperty(targetFunc.prototype, Symbol.toStringTag, {
|
|
14
|
-
configurable: true,
|
|
15
|
-
value: stringTag,
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
/** @internal */
|
|
19
12
|
function checkArgsLength(args, required, className, funcName) {
|
|
20
13
|
if (args.length < required) {
|
|
21
14
|
throw new TypeError(`Failed to ${funcName ? ("execute '" + funcName + "' on") : "construct"} '${className}': ${required} argument${required > 1 ? "s" : ""} required, but only ${args.length} present.`);
|
|
@@ -36,7 +29,7 @@ function isObjectType(name, value) {
|
|
|
36
29
|
return Object.prototype.toString.call(value) === `[object ${name}]`;
|
|
37
30
|
}
|
|
38
31
|
/** @internal */
|
|
39
|
-
function isPolyfillType(name, value) {
|
|
32
|
+
function isPolyfillType(name, value, strict = false) {
|
|
40
33
|
return !!value
|
|
41
34
|
&& typeof value === "object"
|
|
42
35
|
&& "isPolyfill" in value
|
|
@@ -46,7 +39,12 @@ function isPolyfillType(name, value) {
|
|
|
46
39
|
&& value.isPolyfill.symbol === polyfill
|
|
47
40
|
&& "hierarchy" in value.isPolyfill
|
|
48
41
|
&& Array.isArray(value.isPolyfill.hierarchy)
|
|
49
|
-
&& value.isPolyfill.hierarchy.indexOf(name)
|
|
42
|
+
&& ((index) => strict ? index === 0 : index > -1)(value.isPolyfill.hierarchy.indexOf(name));
|
|
43
|
+
}
|
|
44
|
+
/** @internal */
|
|
45
|
+
function isArrayBuffer(value) {
|
|
46
|
+
// Mini Program
|
|
47
|
+
return isObjectType("ArrayBuffer", value) || (!!value && typeof value === "object" && ArrayBuffer.prototype.isPrototypeOf(value));
|
|
50
48
|
}
|
|
51
49
|
|
|
52
50
|
class TextEncoderP {
|
|
@@ -59,16 +57,16 @@ class TextEncoderP {
|
|
|
59
57
|
const [source, destination] = args;
|
|
60
58
|
checkArgsLength(args, 2, "TextEncoder", "encodeInto");
|
|
61
59
|
let _source = "" + source;
|
|
62
|
-
if (!(destination instanceof Uint8Array)) {
|
|
60
|
+
if (!(destination instanceof Uint8Array || isObjectType("Uint8Array", destination))) {
|
|
63
61
|
throw new TypeError("Failed to execute 'encodeInto' on 'TextEncoder': parameter 2 is not of type 'Uint8Array'.");
|
|
64
62
|
}
|
|
65
63
|
let result = encodeText(_source, destination);
|
|
66
64
|
return { read: result.read, written: result.written };
|
|
67
65
|
}
|
|
68
66
|
/** @internal */ toString() { return "[object TextEncoder]"; }
|
|
67
|
+
/** @internal */ get [Symbol.toStringTag]() { return "TextEncoder"; }
|
|
69
68
|
/** @internal */ get isPolyfill() { return { symbol: polyfill, hierarchy: ["TextEncoder"] }; }
|
|
70
69
|
}
|
|
71
|
-
Class_setStringTag(TextEncoderP, "TextEncoder");
|
|
72
70
|
function encodeText(input, destination) {
|
|
73
71
|
const HAS_DESTINATION = typeof destination !== "undefined";
|
|
74
72
|
let pos = 0;
|
|
@@ -185,10 +183,10 @@ class TextDecoderP {
|
|
|
185
183
|
const s = this[state$k];
|
|
186
184
|
let bytes;
|
|
187
185
|
if (input !== undefined) {
|
|
188
|
-
if (input
|
|
186
|
+
if (isArrayBuffer(input)) {
|
|
189
187
|
bytes = new Uint8Array(input);
|
|
190
188
|
}
|
|
191
|
-
else if (input instanceof Uint8Array) {
|
|
189
|
+
else if (input instanceof Uint8Array || isObjectType("Uint8Array", input)) {
|
|
192
190
|
bytes = input;
|
|
193
191
|
}
|
|
194
192
|
else if (ArrayBuffer.isView(input)) {
|
|
@@ -311,9 +309,9 @@ class TextDecoderP {
|
|
|
311
309
|
return res.length > 0x4000 ? buildString(res) : concatString(res);
|
|
312
310
|
}
|
|
313
311
|
/** @internal */ toString() { return "[object TextDecoder]"; }
|
|
312
|
+
/** @internal */ get [Symbol.toStringTag]() { return "TextDecoder"; }
|
|
314
313
|
/** @internal */ get isPolyfill() { return { symbol: polyfill, hierarchy: ["TextDecoder"] }; }
|
|
315
314
|
}
|
|
316
|
-
Class_setStringTag(TextDecoderP, "TextDecoder");
|
|
317
315
|
/** @internal */ const _bomDone = Symbol();
|
|
318
316
|
/** @internal */ const _partial = Symbol();
|
|
319
317
|
/** @internal */
|
|
@@ -359,7 +357,7 @@ class BlobP {
|
|
|
359
357
|
if (isPolyfillType("Blob", chunk)) {
|
|
360
358
|
chunks.push(chunk[state$j][_buffer]);
|
|
361
359
|
}
|
|
362
|
-
else if (chunk
|
|
360
|
+
else if (isArrayBuffer(chunk) || ArrayBuffer.isView(chunk)) {
|
|
363
361
|
chunks.push(BufferSource_toUint8Array(chunk));
|
|
364
362
|
}
|
|
365
363
|
else {
|
|
@@ -391,9 +389,9 @@ class BlobP {
|
|
|
391
389
|
return Promise.resolve(decode$1(this[state$j][_buffer]));
|
|
392
390
|
}
|
|
393
391
|
/** @internal */ toString() { return "[object Blob]"; }
|
|
392
|
+
/** @internal */ get [Symbol.toStringTag]() { return "Blob"; }
|
|
394
393
|
/** @internal */ get isPolyfill() { return { symbol: polyfill, hierarchy: ["Blob"] }; }
|
|
395
394
|
}
|
|
396
|
-
Class_setStringTag(BlobP, "Blob");
|
|
397
395
|
/** @internal */
|
|
398
396
|
const _buffer = Symbol();
|
|
399
397
|
/** @internal */
|
|
@@ -409,7 +407,7 @@ function Blob_toUint8Array(blob) {
|
|
|
409
407
|
return blob[state$j][_buffer];
|
|
410
408
|
}
|
|
411
409
|
function BufferSource_toUint8Array(buf) {
|
|
412
|
-
return buf
|
|
410
|
+
return isArrayBuffer(buf)
|
|
413
411
|
? new Uint8Array(buf)
|
|
414
412
|
: new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
415
413
|
}
|
|
@@ -479,9 +477,9 @@ class FileP extends BlobP {
|
|
|
479
477
|
get name() { return this[state$i].name; }
|
|
480
478
|
get webkitRelativePath() { return ""; }
|
|
481
479
|
/** @internal */ toString() { return "[object File]"; }
|
|
480
|
+
/** @internal */ get [Symbol.toStringTag]() { return "File"; }
|
|
482
481
|
/** @internal */ get isPolyfill() { return { symbol: polyfill, hierarchy: ["File", "Blob"] }; }
|
|
483
482
|
}
|
|
484
|
-
Class_setStringTag(FileP, "File");
|
|
485
483
|
/** @internal */
|
|
486
484
|
class FileState {
|
|
487
485
|
constructor() {
|
|
@@ -494,6 +492,10 @@ const FileE = g["Blob"] ? g["File"] : FileP;
|
|
|
494
492
|
var _a$a, _b$3, _c$1, _d$1, _e$1;
|
|
495
493
|
/** @internal */ const state$h = Symbol( /* "EventState" */);
|
|
496
494
|
class EventP {
|
|
495
|
+
static get NONE() { return 0; }
|
|
496
|
+
static get CAPTURING_PHASE() { return 1; }
|
|
497
|
+
static get AT_TARGET() { return 2; }
|
|
498
|
+
static get BUBBLING_PHASE() { return 3; }
|
|
497
499
|
constructor(...args) {
|
|
498
500
|
const [type, eventInitDict] = args;
|
|
499
501
|
checkArgsLength(args, 1, new.target.name);
|
|
@@ -515,6 +517,10 @@ class EventP {
|
|
|
515
517
|
get target() { return this[state$h].target; }
|
|
516
518
|
get currentTarget() { return this[state$h].currentTarget; }
|
|
517
519
|
get eventPhase() { return this[state$h].eventPhase; }
|
|
520
|
+
get NONE() { return 0; }
|
|
521
|
+
get CAPTURING_PHASE() { return 1; }
|
|
522
|
+
get AT_TARGET() { return 2; }
|
|
523
|
+
get BUBBLING_PHASE() { return 3; }
|
|
518
524
|
get srcElement() { return this[state$h].target; }
|
|
519
525
|
get cancelBubble() { return this[state$h].cancelBubble; }
|
|
520
526
|
set cancelBubble(value) { this[state$h].cancelBubble = !!value; }
|
|
@@ -560,17 +566,9 @@ class EventP {
|
|
|
560
566
|
this.cancelBubble = true;
|
|
561
567
|
}
|
|
562
568
|
/** @internal */ toString() { return "[object Event]"; }
|
|
569
|
+
/** @internal */ get [Symbol.toStringTag]() { return "Event"; }
|
|
563
570
|
/** @internal */ get isPolyfill() { return { symbol: polyfill, hierarchy: ["Event"] }; }
|
|
564
571
|
}
|
|
565
|
-
const properties$2 = {
|
|
566
|
-
NONE: { value: 0, enumerable: true },
|
|
567
|
-
CAPTURING_PHASE: { value: 1, enumerable: true },
|
|
568
|
-
AT_TARGET: { value: 2, enumerable: true },
|
|
569
|
-
BUBBLING_PHASE: { value: 3, enumerable: true },
|
|
570
|
-
};
|
|
571
|
-
Object.defineProperties(EventP, properties$2);
|
|
572
|
-
Object.defineProperties(EventP.prototype, properties$2);
|
|
573
|
-
Class_setStringTag(EventP, "Event");
|
|
574
572
|
/** @internal */ const _timeStamp = (new Date()).getTime();
|
|
575
573
|
/** @internal */ const _isTrusted = Symbol();
|
|
576
574
|
/** @internal */ const _passive = Symbol();
|
|
@@ -586,7 +584,7 @@ class EventState {
|
|
|
586
584
|
this.composed = false;
|
|
587
585
|
this.target = null;
|
|
588
586
|
this.currentTarget = null;
|
|
589
|
-
this.eventPhase =
|
|
587
|
+
this.eventPhase = 0 /* NONE */;
|
|
590
588
|
this.cancelBubble = false;
|
|
591
589
|
this.defaultPrevented = false;
|
|
592
590
|
this.returnValue = true;
|
|
@@ -712,9 +710,9 @@ class EventTargetP {
|
|
|
712
710
|
}
|
|
713
711
|
}
|
|
714
712
|
/** @internal */ toString() { return "[object EventTarget]"; }
|
|
713
|
+
/** @internal */ get [Symbol.toStringTag]() { return "EventTarget"; }
|
|
715
714
|
/** @internal */ get isPolyfill() { return { symbol: polyfill, hierarchy: ["EventTarget"] }; }
|
|
716
715
|
}
|
|
717
|
-
Class_setStringTag(EventTargetP, "EventTarget");
|
|
718
716
|
/** @internal */
|
|
719
717
|
const _executors = Symbol();
|
|
720
718
|
/** @internal */
|
|
@@ -733,7 +731,7 @@ function EventTarget_fire(target, event) {
|
|
|
733
731
|
if (!event.target)
|
|
734
732
|
evs.target = target;
|
|
735
733
|
evs.currentTarget = target;
|
|
736
|
-
evs.eventPhase =
|
|
734
|
+
evs.eventPhase = 2 /* AT_TARGET */;
|
|
737
735
|
Event_setEtField(event, dispatched$2, true);
|
|
738
736
|
let onceIndexes = [];
|
|
739
737
|
for (let i = 0; i < s[_executors].length; ++i) {
|
|
@@ -763,7 +761,7 @@ function EventTarget_fire(target, event) {
|
|
|
763
761
|
}, []);
|
|
764
762
|
}
|
|
765
763
|
evs.currentTarget = null;
|
|
766
|
-
evs.eventPhase =
|
|
764
|
+
evs.eventPhase = 0 /* NONE */;
|
|
767
765
|
Event_setEtField(event, dispatched$2, false);
|
|
768
766
|
return !(event.cancelable && Event_getEtField(event, preventDefaultCalled));
|
|
769
767
|
}
|
|
@@ -843,9 +841,9 @@ class ProgressEventP extends EventP {
|
|
|
843
841
|
get loaded() { return getValue(this[state$f].loaded); }
|
|
844
842
|
get total() { return getValue(this[state$f].total); }
|
|
845
843
|
/** @internal */ toString() { return "[object ProgressEvent]"; }
|
|
844
|
+
/** @internal */ get [Symbol.toStringTag]() { return "ProgressEvent"; }
|
|
846
845
|
/** @internal */ get isPolyfill() { return { symbol: polyfill, hierarchy: ["ProgressEvent", "Event"] }; }
|
|
847
846
|
}
|
|
848
|
-
Class_setStringTag(ProgressEventP, "ProgressEvent");
|
|
849
847
|
/** @internal */
|
|
850
848
|
class ProgressEventState {
|
|
851
849
|
constructor() {
|
|
@@ -881,17 +879,23 @@ var _a$8;
|
|
|
881
879
|
/** @internal */
|
|
882
880
|
const state$e = Symbol( /* "FileReaderState" */);
|
|
883
881
|
class FileReaderP extends EventTargetP {
|
|
882
|
+
static get EMPTY() { return 0; }
|
|
883
|
+
static get LOADING() { return 1; }
|
|
884
|
+
static get DONE() { return 2; }
|
|
884
885
|
constructor() {
|
|
885
886
|
super();
|
|
886
887
|
this[state$e] = new FileReaderState(this);
|
|
887
888
|
}
|
|
888
889
|
get readyState() { return this[state$e].readyState; }
|
|
889
890
|
get result() { return this[state$e].result; }
|
|
891
|
+
get EMPTY() { return 0; }
|
|
892
|
+
get LOADING() { return 1; }
|
|
893
|
+
get DONE() { return 2; }
|
|
890
894
|
get error() { return this[state$e].error; }
|
|
891
895
|
abort() {
|
|
892
|
-
if (this.readyState ===
|
|
896
|
+
if (this.readyState === 1 /* LOADING */) {
|
|
893
897
|
const s = this[state$e];
|
|
894
|
-
s.readyState =
|
|
898
|
+
s.readyState = 2 /* DONE */;
|
|
895
899
|
s.result = null;
|
|
896
900
|
s.error = new MPException("An ongoing operation was aborted, typically with a call to abort().", "AbortError");
|
|
897
901
|
emitProcessEvent(this, "abort");
|
|
@@ -943,22 +947,15 @@ class FileReaderP extends EventTargetP {
|
|
|
943
947
|
get onprogress() { return this[state$e].onprogress; }
|
|
944
948
|
set onprogress(value) { this[state$e].onprogress = value; attach$2(this, "progress"); }
|
|
945
949
|
/** @internal */ toString() { return "[object FileReader]"; }
|
|
950
|
+
/** @internal */ get [Symbol.toStringTag]() { return "FileReader"; }
|
|
946
951
|
/** @internal */ get isPolyfill() { return { symbol: polyfill, hierarchy: ["FileReader", "EventTarget"] }; }
|
|
947
952
|
}
|
|
948
|
-
const properties$1 = {
|
|
949
|
-
EMPTY: { value: 0, enumerable: true },
|
|
950
|
-
LOADING: { value: 1, enumerable: true },
|
|
951
|
-
DONE: { value: 2, enumerable: true },
|
|
952
|
-
};
|
|
953
|
-
Object.defineProperties(FileReaderP, properties$1);
|
|
954
|
-
Object.defineProperties(FileReaderP.prototype, properties$1);
|
|
955
|
-
Class_setStringTag(FileReaderP, "FileReader");
|
|
956
953
|
/** @internal */
|
|
957
954
|
const _handlers$4 = Symbol();
|
|
958
955
|
/** @internal */
|
|
959
956
|
class FileReaderState {
|
|
960
957
|
constructor(target) {
|
|
961
|
-
this.readyState =
|
|
958
|
+
this.readyState = 0 /* EMPTY */;
|
|
962
959
|
this.result = null;
|
|
963
960
|
this.error = null;
|
|
964
961
|
this[_a$8] = getHandlers$4(this);
|
|
@@ -980,11 +977,11 @@ function read$1(reader, kind, args, setResult) {
|
|
|
980
977
|
}
|
|
981
978
|
const s = reader[state$e];
|
|
982
979
|
s.error = null;
|
|
983
|
-
s.readyState =
|
|
980
|
+
s.readyState = 1 /* LOADING */;
|
|
984
981
|
emitProcessEvent(s.target, "loadstart", 0, blob.size);
|
|
985
982
|
setTimeout(() => {
|
|
986
|
-
if (s.readyState ===
|
|
987
|
-
s.readyState =
|
|
983
|
+
if (s.readyState === 1 /* LOADING */) {
|
|
984
|
+
s.readyState = 2 /* DONE */;
|
|
988
985
|
try {
|
|
989
986
|
setResult(blob);
|
|
990
987
|
emitProcessEvent(s.target, "load", blob.size, blob.size);
|
|
@@ -1024,7 +1021,7 @@ class URLSearchParamsP {
|
|
|
1024
1021
|
constructor(init) {
|
|
1025
1022
|
this[state$d] = new URLSearchParamsState();
|
|
1026
1023
|
if (init !== undefined) {
|
|
1027
|
-
if (isObjectType("URLSearchParams", init)) {
|
|
1024
|
+
if (isObjectType("URLSearchParams", init) || isPolyfillType("URLSearchParams", init)) {
|
|
1028
1025
|
init.forEach((value, name) => { this.append(name, value); }, this);
|
|
1029
1026
|
}
|
|
1030
1027
|
else if (init && typeof init === "object") {
|
|
@@ -1205,10 +1202,9 @@ class URLSearchParamsP {
|
|
|
1205
1202
|
}
|
|
1206
1203
|
return result.join("&");
|
|
1207
1204
|
}
|
|
1208
|
-
/** @internal */
|
|
1209
|
-
get isPolyfill() { return { symbol: polyfill, hierarchy: ["URLSearchParams"] }; }
|
|
1205
|
+
/** @internal */ get [Symbol.toStringTag]() { return "URLSearchParams"; }
|
|
1206
|
+
/** @internal */ get isPolyfill() { return { symbol: polyfill, hierarchy: ["URLSearchParams"] }; }
|
|
1210
1207
|
}
|
|
1211
|
-
Class_setStringTag(URLSearchParamsP, "URLSearchParams");
|
|
1212
1208
|
/** @internal */
|
|
1213
1209
|
const _urlspArray = Symbol();
|
|
1214
1210
|
/** @internal */
|
|
@@ -1372,9 +1368,9 @@ class FormDataP {
|
|
|
1372
1368
|
return this.entries();
|
|
1373
1369
|
}
|
|
1374
1370
|
/** @internal */ toString() { return "[object FormData]"; }
|
|
1371
|
+
/** @internal */ get [Symbol.toStringTag]() { return "FormData"; }
|
|
1375
1372
|
/** @internal */ get isPolyfill() { return { symbol: polyfill, hierarchy: ["FormData"] }; }
|
|
1376
1373
|
}
|
|
1377
|
-
Class_setStringTag(FormDataP, "FormData");
|
|
1378
1374
|
/** @internal */
|
|
1379
1375
|
const _formData = Symbol();
|
|
1380
1376
|
/** @internal */
|
|
@@ -1410,7 +1406,7 @@ function normalizeArgs(name, value, filename) {
|
|
|
1410
1406
|
: typeof value.name === "string"
|
|
1411
1407
|
? value.name
|
|
1412
1408
|
: "blob";
|
|
1413
|
-
if (value.name !== filename || isObjectType("Blob", value)) {
|
|
1409
|
+
if (value.name !== filename || isObjectType("Blob", value) || isPolyfillType("Blob", value, true)) {
|
|
1414
1410
|
value = new FileP([value], filename);
|
|
1415
1411
|
}
|
|
1416
1412
|
return ["" + name, value];
|
|
@@ -1487,8 +1483,8 @@ class HeadersP {
|
|
|
1487
1483
|
constructor(init) {
|
|
1488
1484
|
this[state$b] = new HeadersState();
|
|
1489
1485
|
if (init !== undefined) {
|
|
1490
|
-
if (isObjectType("Headers", init)) {
|
|
1491
|
-
init.forEach((value, name) => { this
|
|
1486
|
+
if (isObjectType("Headers", init) || isPolyfillType("Headers", init)) {
|
|
1487
|
+
init.forEach((value, name) => { Headers_append(this, name, value); }, this);
|
|
1492
1488
|
}
|
|
1493
1489
|
else if (Array.isArray(init) || (init && typeof init === "object" && Symbol.iterator in init)) {
|
|
1494
1490
|
let _init = Array.isArray(init) ? init : Array.from(init);
|
|
@@ -1523,51 +1519,20 @@ class HeadersP {
|
|
|
1523
1519
|
checkArgsFn(args, 2, "append");
|
|
1524
1520
|
let _name = normalizeName(name, throwsFn(this[state$b][_initialized] ? "append" : ""));
|
|
1525
1521
|
let _value = normalizeValue(value);
|
|
1526
|
-
|
|
1527
|
-
let array = this[state$b][_headersArray];
|
|
1528
|
-
for (let i = 0; i < array.length; ++i) {
|
|
1529
|
-
let item = array[i];
|
|
1530
|
-
if (item[0] === _name) {
|
|
1531
|
-
item[1] = `${item[1]}, ${_value}`;
|
|
1532
|
-
index = i;
|
|
1533
|
-
break;
|
|
1534
|
-
}
|
|
1535
|
-
}
|
|
1536
|
-
if (index === -1) {
|
|
1537
|
-
array.push([_name, _value]);
|
|
1538
|
-
}
|
|
1522
|
+
Headers_append(this, _name, _value);
|
|
1539
1523
|
}
|
|
1540
1524
|
delete(...args) {
|
|
1541
1525
|
const [name] = args;
|
|
1542
1526
|
checkArgsFn(args, 1, "delete");
|
|
1543
1527
|
let _name = normalizeName(name, throwsFn("delete"));
|
|
1544
|
-
|
|
1545
|
-
let array = this[state$b][_headersArray];
|
|
1546
|
-
let result = [];
|
|
1547
|
-
for (let i = 0; i < array.length; ++i) {
|
|
1548
|
-
let item = array[i];
|
|
1549
|
-
if (item[0] === _name) {
|
|
1550
|
-
index = i;
|
|
1551
|
-
continue;
|
|
1552
|
-
}
|
|
1553
|
-
result.push(item);
|
|
1554
|
-
}
|
|
1555
|
-
if (index > -1) {
|
|
1556
|
-
this[state$b][_headersArray] = result;
|
|
1557
|
-
}
|
|
1528
|
+
delete this[state$b][_headersDict][_name];
|
|
1558
1529
|
}
|
|
1559
1530
|
get(...args) {
|
|
1531
|
+
var _c;
|
|
1560
1532
|
const [name] = args;
|
|
1561
1533
|
checkArgsFn(args, 1, "get");
|
|
1562
1534
|
let _name = normalizeName(name, throwsFn("get"));
|
|
1563
|
-
|
|
1564
|
-
for (let i = 0; i < array.length; ++i) {
|
|
1565
|
-
let item = array[i];
|
|
1566
|
-
if (item[0] === _name) {
|
|
1567
|
-
return item[1];
|
|
1568
|
-
}
|
|
1569
|
-
}
|
|
1570
|
-
return null;
|
|
1535
|
+
return (_c = this[state$b][_headersDict][_name]) !== null && _c !== void 0 ? _c : null;
|
|
1571
1536
|
}
|
|
1572
1537
|
getSetCookie() {
|
|
1573
1538
|
let value = this.get("Set-Cookie");
|
|
@@ -1577,33 +1542,14 @@ class HeadersP {
|
|
|
1577
1542
|
const [name] = args;
|
|
1578
1543
|
checkArgsFn(args, 1, "has");
|
|
1579
1544
|
let _name = normalizeName(name, throwsFn("has"));
|
|
1580
|
-
|
|
1581
|
-
for (let i = 0; i < array.length; ++i) {
|
|
1582
|
-
let item = array[i];
|
|
1583
|
-
if (item[0] === _name) {
|
|
1584
|
-
return true;
|
|
1585
|
-
}
|
|
1586
|
-
}
|
|
1587
|
-
return false;
|
|
1545
|
+
return this[state$b][_headersDict].hasOwnProperty(_name);
|
|
1588
1546
|
}
|
|
1589
1547
|
set(...args) {
|
|
1590
1548
|
const [name, value] = args;
|
|
1591
1549
|
checkArgsFn(args, 2, "set");
|
|
1592
1550
|
let _name = normalizeName(name, throwsFn("set"));
|
|
1593
1551
|
let _value = normalizeValue(value);
|
|
1594
|
-
|
|
1595
|
-
let array = this[state$b][_headersArray];
|
|
1596
|
-
for (let i = 0; i < array.length; ++i) {
|
|
1597
|
-
let item = array[i];
|
|
1598
|
-
if (item[0] === _name) {
|
|
1599
|
-
item[1] = _value;
|
|
1600
|
-
index = i;
|
|
1601
|
-
break;
|
|
1602
|
-
}
|
|
1603
|
-
}
|
|
1604
|
-
if (index === -1) {
|
|
1605
|
-
array.push([_name, _value]);
|
|
1606
|
-
}
|
|
1552
|
+
this[state$b][_headersDict][_name] = _value;
|
|
1607
1553
|
}
|
|
1608
1554
|
forEach(...args) {
|
|
1609
1555
|
const [callbackfn, thisArg] = args;
|
|
@@ -1611,38 +1557,49 @@ class HeadersP {
|
|
|
1611
1557
|
if (typeof callbackfn !== "function") {
|
|
1612
1558
|
throw new TypeError("Failed to execute 'forEach' on 'Headers': parameter 1 is not of type 'Function'.");
|
|
1613
1559
|
}
|
|
1614
|
-
let
|
|
1615
|
-
for (let i = 0; i <
|
|
1616
|
-
let
|
|
1617
|
-
callbackfn.call(thisArg,
|
|
1560
|
+
let names = Object.getOwnPropertyNames(this[state$b][_headersDict]);
|
|
1561
|
+
for (let i = 0; i < names.length; ++i) {
|
|
1562
|
+
let name = names[i];
|
|
1563
|
+
callbackfn.call(thisArg, this[state$b][_headersDict][name], name, this);
|
|
1618
1564
|
}
|
|
1619
1565
|
}
|
|
1620
1566
|
entries() {
|
|
1621
|
-
|
|
1567
|
+
let array = [];
|
|
1568
|
+
this.forEach((value, name) => { array.push([name, value]); });
|
|
1569
|
+
return array.values();
|
|
1622
1570
|
}
|
|
1623
1571
|
keys() {
|
|
1624
|
-
|
|
1572
|
+
let array = [];
|
|
1573
|
+
this.forEach((value, name) => { array.push(name); });
|
|
1574
|
+
return array.values();
|
|
1625
1575
|
}
|
|
1626
1576
|
values() {
|
|
1627
|
-
|
|
1577
|
+
let array = [];
|
|
1578
|
+
this.forEach((value, name) => { array.push(value); });
|
|
1579
|
+
return array.values();
|
|
1628
1580
|
}
|
|
1629
1581
|
[Symbol.iterator]() {
|
|
1630
1582
|
return this.entries();
|
|
1631
1583
|
}
|
|
1632
1584
|
/** @internal */ toString() { return "[object Headers]"; }
|
|
1585
|
+
/** @internal */ get [Symbol.toStringTag]() { return "Headers"; }
|
|
1633
1586
|
/** @internal */ get isPolyfill() { return { symbol: polyfill, hierarchy: ["Headers"] }; }
|
|
1634
1587
|
}
|
|
1635
|
-
Class_setStringTag(HeadersP, "Headers");
|
|
1636
1588
|
/** @internal */ const _initialized = Symbol();
|
|
1637
|
-
/** @internal */ const
|
|
1589
|
+
/** @internal */ const _headersDict = Symbol();
|
|
1638
1590
|
/** @internal */
|
|
1639
1591
|
class HeadersState {
|
|
1640
1592
|
constructor() {
|
|
1641
1593
|
this[_a$5] = false;
|
|
1642
|
-
this[_b$2] =
|
|
1594
|
+
this[_b$2] = {};
|
|
1643
1595
|
}
|
|
1644
1596
|
}
|
|
1645
|
-
_a$5 = _initialized, _b$2 =
|
|
1597
|
+
_a$5 = _initialized, _b$2 = _headersDict;
|
|
1598
|
+
function Headers_append(headers, name, value) {
|
|
1599
|
+
let dict = headers[state$b][_headersDict];
|
|
1600
|
+
let oldValue = dict[name];
|
|
1601
|
+
dict[name] = oldValue !== undefined ? `${oldValue}, ${value}` : value;
|
|
1602
|
+
}
|
|
1646
1603
|
function throwsFn(kind) {
|
|
1647
1604
|
return () => {
|
|
1648
1605
|
throw new TypeError(`Failed to ${kind ? ("execute '" + kind + "' on") : "construct"} 'Headers': Invalid name`);
|
|
@@ -1729,9 +1686,9 @@ class BodyImpl {
|
|
|
1729
1686
|
return consumed(this, kind) || read(this, kind);
|
|
1730
1687
|
}
|
|
1731
1688
|
/** @internal */ toString() { return "[object Body]"; }
|
|
1689
|
+
/** @internal */ get [Symbol.toStringTag]() { return "Body"; }
|
|
1732
1690
|
/** @internal */ get isPolyfill() { return { symbol: polyfill, hierarchy: ["Body"] }; }
|
|
1733
1691
|
}
|
|
1734
|
-
Class_setStringTag(BodyImpl, "Body");
|
|
1735
1692
|
/** @internal */
|
|
1736
1693
|
const _body = Symbol();
|
|
1737
1694
|
/** @internal */
|
|
@@ -1822,13 +1779,13 @@ function convert(body, cloneArrayBuffer = true, setContentType, setContentLength
|
|
|
1822
1779
|
setContentType("text/plain;charset=UTF-8");
|
|
1823
1780
|
}
|
|
1824
1781
|
}
|
|
1825
|
-
else if (isObjectType("URLSearchParams", body)) {
|
|
1782
|
+
else if (isObjectType("URLSearchParams", body) || isPolyfillType("URLSearchParams", body)) {
|
|
1826
1783
|
result = body.toString();
|
|
1827
1784
|
if (setContentType) {
|
|
1828
1785
|
setContentType("application/x-www-form-urlencoded;charset=UTF-8");
|
|
1829
1786
|
}
|
|
1830
1787
|
}
|
|
1831
|
-
else if (body
|
|
1788
|
+
else if (isArrayBuffer(body)) {
|
|
1832
1789
|
result = cloneArrayBuffer ? body.slice(0) : body;
|
|
1833
1790
|
}
|
|
1834
1791
|
else if (ArrayBuffer.isView(body)) {
|
|
@@ -1867,7 +1824,7 @@ function convert(body, cloneArrayBuffer = true, setContentType, setContentLength
|
|
|
1867
1824
|
}
|
|
1868
1825
|
/** @internal */
|
|
1869
1826
|
function convertBack(type, data) {
|
|
1870
|
-
let temp = !!data ? (typeof data !== "string" && !(data
|
|
1827
|
+
let temp = !!data ? (typeof data !== "string" && !isArrayBuffer(data) ? JSON.stringify(data) : data) : "";
|
|
1871
1828
|
if (!type || type === "text") {
|
|
1872
1829
|
return typeof temp === "string" ? temp : decode$1(temp);
|
|
1873
1830
|
}
|
|
@@ -1875,7 +1832,7 @@ function convertBack(type, data) {
|
|
|
1875
1832
|
return JSON.parse(typeof temp === "string" ? temp : decode$1(temp));
|
|
1876
1833
|
}
|
|
1877
1834
|
else if (type === "arraybuffer") {
|
|
1878
|
-
return temp
|
|
1835
|
+
return isArrayBuffer(temp) ? temp.slice(0) : encode$1(temp).buffer;
|
|
1879
1836
|
}
|
|
1880
1837
|
else if (type === "blob") {
|
|
1881
1838
|
return new BlobP([temp]);
|
|
@@ -1959,9 +1916,9 @@ class AbortSignalP extends EventTargetP {
|
|
|
1959
1916
|
attachFn(this, "abort", value, this[state$9][_handlers$3].onabort);
|
|
1960
1917
|
}
|
|
1961
1918
|
/** @internal */ toString() { return "[object AbortSignal]"; }
|
|
1919
|
+
/** @internal */ get [Symbol.toStringTag]() { return "AbortSignal"; }
|
|
1962
1920
|
/** @internal */ get isPolyfill() { return { symbol: polyfill, hierarchy: ["AbortSignal", "EventTarget"] }; }
|
|
1963
1921
|
}
|
|
1964
|
-
Class_setStringTag(AbortSignalP, "AbortSignal");
|
|
1965
1922
|
/** @internal */
|
|
1966
1923
|
const _handlers$3 = Symbol();
|
|
1967
1924
|
/** @internal */
|
|
@@ -2012,9 +1969,9 @@ class AbortControllerP {
|
|
|
2012
1969
|
AbortSignal_abort(this[state$8].signal, reason);
|
|
2013
1970
|
}
|
|
2014
1971
|
/** @internal */ toString() { return "[object AbortController]"; }
|
|
1972
|
+
/** @internal */ get [Symbol.toStringTag]() { return "AbortController"; }
|
|
2015
1973
|
/** @internal */ get isPolyfill() { return { symbol: polyfill, hierarchy: ["AbortController"] }; }
|
|
2016
1974
|
}
|
|
2017
|
-
Class_setStringTag(AbortControllerP, "AbortController");
|
|
2018
1975
|
/** @internal */
|
|
2019
1976
|
class AbortControllerState {
|
|
2020
1977
|
constructor() {
|
|
@@ -2133,9 +2090,9 @@ class RequestP extends BodyImpl {
|
|
|
2133
2090
|
return new RequestP(this, { body: (_a = Body_toPayload(this)) !== null && _a !== void 0 ? _a : null });
|
|
2134
2091
|
}
|
|
2135
2092
|
/** @internal */ toString() { return "[object Request]"; }
|
|
2093
|
+
/** @internal */ get [Symbol.toStringTag]() { return "Request"; }
|
|
2136
2094
|
/** @internal */ get isPolyfill() { return { symbol: polyfill, hierarchy: ["Request"] }; }
|
|
2137
2095
|
}
|
|
2138
|
-
Class_setStringTag(RequestP, "Request");
|
|
2139
2096
|
/** @internal */
|
|
2140
2097
|
class RequestState {
|
|
2141
2098
|
constructor() {
|
|
@@ -2162,8 +2119,7 @@ function normalizeMethod(method) {
|
|
|
2162
2119
|
const RequestE = g["Request"] || RequestP;
|
|
2163
2120
|
|
|
2164
2121
|
// @ts-nocheck
|
|
2165
|
-
|
|
2166
|
-
const mp$3 = (() => {
|
|
2122
|
+
function getPlatform() {
|
|
2167
2123
|
let u = "undefined", r = "request", f = "function";
|
|
2168
2124
|
let mp;
|
|
2169
2125
|
mp =
|
|
@@ -2186,7 +2142,9 @@ const mp$3 = (() => {
|
|
|
2186
2142
|
(typeof Taro !== u && typeof (Taro === null || Taro === void 0 ? void 0 : Taro[r]) === f && Taro) || // Taro
|
|
2187
2143
|
undefined;
|
|
2188
2144
|
return mp;
|
|
2189
|
-
}
|
|
2145
|
+
}
|
|
2146
|
+
/** @internal */
|
|
2147
|
+
const mp$3 = getPlatform();
|
|
2190
2148
|
|
|
2191
2149
|
const request = mp$3 ? mp$3.request : function errorRequest(options) {
|
|
2192
2150
|
const errMsg = "NOT_SUPPORTED_ERR";
|
|
@@ -2241,9 +2199,9 @@ class XMLHttpRequestEventTargetP extends EventTargetP {
|
|
|
2241
2199
|
get ontimeout() { return this[state$6].ontimeout; }
|
|
2242
2200
|
set ontimeout(value) { this[state$6].ontimeout = value; attach$1(this, "timeout"); }
|
|
2243
2201
|
/** @internal */ toString() { return "[object XMLHttpRequestEventTarget]"; }
|
|
2202
|
+
/** @internal */ get [Symbol.toStringTag]() { return "XMLHttpRequestEventTarget"; }
|
|
2244
2203
|
/** @internal */ get isPolyfill() { return { symbol: polyfill, hierarchy: ["XMLHttpRequestEventTarget", "EventTarget"] }; }
|
|
2245
2204
|
}
|
|
2246
|
-
Class_setStringTag(XMLHttpRequestEventTargetP, "XMLHttpRequestEventTarget");
|
|
2247
2205
|
/** @internal */
|
|
2248
2206
|
const _handlers$2 = Symbol();
|
|
2249
2207
|
/** @internal */
|
|
@@ -2282,14 +2240,6 @@ function getHandlers$2(s) {
|
|
|
2282
2240
|
ontimeout: (ev) => { executeFn(s.target, s.ontimeout, ev); },
|
|
2283
2241
|
};
|
|
2284
2242
|
}
|
|
2285
|
-
/** @internal */
|
|
2286
|
-
const XHR_properties = {
|
|
2287
|
-
UNSENT: { value: 0, enumerable: true },
|
|
2288
|
-
OPENED: { value: 1, enumerable: true },
|
|
2289
|
-
HEADERS_RECEIVED: { value: 2, enumerable: true },
|
|
2290
|
-
LOADING: { value: 3, enumerable: true },
|
|
2291
|
-
DONE: { value: 4, enumerable: true },
|
|
2292
|
-
};
|
|
2293
2243
|
const responseTypes = ["", "text", "json", "arraybuffer", "blob", "document"];
|
|
2294
2244
|
/** @internal */
|
|
2295
2245
|
function normalizeResponseType(responseType) {
|
|
@@ -2372,9 +2322,9 @@ class XMLHttpRequestUploadP extends XMLHttpRequestEventTargetP {
|
|
|
2372
2322
|
super();
|
|
2373
2323
|
}
|
|
2374
2324
|
/** @internal */ toString() { return "[object XMLHttpRequestUpload]"; }
|
|
2325
|
+
/** @internal */ get [Symbol.toStringTag]() { return "XMLHttpRequestUpload"; }
|
|
2375
2326
|
/** @internal */ get isPolyfill() { return { symbol: polyfill, hierarchy: ["XMLHttpRequestUpload", "XMLHttpRequestEventTarget", "EventTarget"] }; }
|
|
2376
2327
|
}
|
|
2377
|
-
Class_setStringTag(XMLHttpRequestUploadP, "XMLHttpRequestUpload");
|
|
2378
2328
|
/** @internal */
|
|
2379
2329
|
function createXMLHttpRequestUpload() {
|
|
2380
2330
|
let upload = Object.create(XMLHttpRequestUploadP.prototype);
|
|
@@ -2386,13 +2336,22 @@ function createXMLHttpRequestUpload() {
|
|
|
2386
2336
|
var _a$1, _b$1, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
2387
2337
|
const mp$2 = { request: request };
|
|
2388
2338
|
const setRequest = (request) => { mp$2.request = request; };
|
|
2389
|
-
/** @internal */
|
|
2390
|
-
const state$5 = Symbol( /* "XMLHttpRequestState" */);
|
|
2339
|
+
/** @internal */ const state$5 = Symbol( /* "XMLHttpRequestState" */);
|
|
2391
2340
|
class XMLHttpRequestImpl extends XMLHttpRequestEventTargetP {
|
|
2341
|
+
static get UNSENT() { return 0; }
|
|
2342
|
+
static get OPENED() { return 1; }
|
|
2343
|
+
static get HEADERS_RECEIVED() { return 2; }
|
|
2344
|
+
static get LOADING() { return 3; }
|
|
2345
|
+
static get DONE() { return 4; }
|
|
2392
2346
|
constructor() {
|
|
2393
2347
|
super();
|
|
2394
2348
|
this[state$5] = new XMLHttpRequestState(this);
|
|
2395
2349
|
}
|
|
2350
|
+
get UNSENT() { return 0; }
|
|
2351
|
+
get OPENED() { return 1; }
|
|
2352
|
+
get HEADERS_RECEIVED() { return 2; }
|
|
2353
|
+
get LOADING() { return 3; }
|
|
2354
|
+
get DONE() { return 4; }
|
|
2396
2355
|
get readyState() { return this[state$5].readyState; }
|
|
2397
2356
|
get response() { return this[state$5].response; }
|
|
2398
2357
|
get responseText() { return (!this.responseType || this.responseType === "text") ? this.response : ""; }
|
|
@@ -2402,7 +2361,7 @@ class XMLHttpRequestImpl extends XMLHttpRequestEventTargetP {
|
|
|
2402
2361
|
get responseXML() { return null; }
|
|
2403
2362
|
get status() { return this[state$5].status; }
|
|
2404
2363
|
get statusText() {
|
|
2405
|
-
if (this.readyState ===
|
|
2364
|
+
if (this.readyState === 0 /* UNSENT */ || this.readyState === 1 /* OPENED */)
|
|
2406
2365
|
return "";
|
|
2407
2366
|
return this[state$5].statusText || statusTextMap(this.status);
|
|
2408
2367
|
}
|
|
@@ -2454,7 +2413,7 @@ class XMLHttpRequestImpl extends XMLHttpRequestEventTargetP {
|
|
|
2454
2413
|
}
|
|
2455
2414
|
}
|
|
2456
2415
|
s[_inAfterOpenBeforeSend] = true;
|
|
2457
|
-
setReadyStateAndNotify(this,
|
|
2416
|
+
setReadyStateAndNotify(this, 1 /* OPENED */);
|
|
2458
2417
|
}
|
|
2459
2418
|
overrideMimeType(...args) {
|
|
2460
2419
|
const [mime] = args;
|
|
@@ -2465,7 +2424,7 @@ class XMLHttpRequestImpl extends XMLHttpRequestEventTargetP {
|
|
|
2465
2424
|
}
|
|
2466
2425
|
send(body) {
|
|
2467
2426
|
const s = this[state$5];
|
|
2468
|
-
if (!s[_inAfterOpenBeforeSend] || s.readyState !==
|
|
2427
|
+
if (!s[_inAfterOpenBeforeSend] || s.readyState !== 1 /* OPENED */) {
|
|
2469
2428
|
throw new MPException("Failed to execute 'send' on 'XMLHttpRequest': The object's state must be OPENED.", "InvalidStateError");
|
|
2470
2429
|
}
|
|
2471
2430
|
s[_inAfterOpenBeforeSend] = false;
|
|
@@ -2504,7 +2463,7 @@ class XMLHttpRequestImpl extends XMLHttpRequestEventTargetP {
|
|
|
2504
2463
|
}
|
|
2505
2464
|
setTimeout(() => {
|
|
2506
2465
|
if (s.upload) {
|
|
2507
|
-
const _aborted = s[_inAfterOpenBeforeSend] || s.readyState !==
|
|
2466
|
+
const _aborted = s[_inAfterOpenBeforeSend] || s.readyState !== 1 /* OPENED */;
|
|
2508
2467
|
const _contentLength = _aborted ? 0 : contentLength;
|
|
2509
2468
|
if (_aborted) {
|
|
2510
2469
|
emitProcessEvent(this.upload, "abort");
|
|
@@ -2525,13 +2484,17 @@ class XMLHttpRequestImpl extends XMLHttpRequestEventTargetP {
|
|
|
2525
2484
|
const [name, value] = args;
|
|
2526
2485
|
checkArgsLength(args, 2, "XMLHttpRequest", "setRequestHeader");
|
|
2527
2486
|
const s = this[state$5];
|
|
2528
|
-
if (!s[_inAfterOpenBeforeSend] || s.readyState !==
|
|
2487
|
+
if (!s[_inAfterOpenBeforeSend] || s.readyState !== 1 /* OPENED */) {
|
|
2529
2488
|
throw new MPException("Failed to execute 'setRequestHeader' on 'XMLHttpRequest': The object's state must be OPENED.", "InvalidStateError");
|
|
2530
2489
|
}
|
|
2531
|
-
let _name =
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2490
|
+
let _name = "" + name;
|
|
2491
|
+
let _value = "" + value;
|
|
2492
|
+
try {
|
|
2493
|
+
s[_requestHeaders].append(_name, _value);
|
|
2494
|
+
}
|
|
2495
|
+
catch (e) {
|
|
2496
|
+
throw new SyntaxError(`Failed to execute 'setRequestHeader' on 'XMLHttpRequest': '${_name}' is not a valid HTTP header field name.`);
|
|
2497
|
+
}
|
|
2535
2498
|
}
|
|
2536
2499
|
get onreadystatechange() { return this[state$5].onreadystatechange; }
|
|
2537
2500
|
set onreadystatechange(value) {
|
|
@@ -2539,11 +2502,9 @@ class XMLHttpRequestImpl extends XMLHttpRequestEventTargetP {
|
|
|
2539
2502
|
attachFn(this, "readystatechange", value, this[state$5][_handlers$1].onreadystatechange);
|
|
2540
2503
|
}
|
|
2541
2504
|
/** @internal */ toString() { return "[object XMLHttpRequest]"; }
|
|
2505
|
+
/** @internal */ get [Symbol.toStringTag]() { return "XMLHttpRequest"; }
|
|
2542
2506
|
/** @internal */ get isPolyfill() { return { symbol: polyfill, hierarchy: ["XMLHttpRequest", "XMLHttpRequestEventTarget", "EventTarget"] }; }
|
|
2543
2507
|
}
|
|
2544
|
-
Object.defineProperties(XMLHttpRequestImpl, XHR_properties);
|
|
2545
|
-
Object.defineProperties(XMLHttpRequestImpl.prototype, XHR_properties);
|
|
2546
|
-
Class_setStringTag(XMLHttpRequestImpl, "XMLHttpRequest");
|
|
2547
2508
|
/** @internal */ const _handlers$1 = Symbol();
|
|
2548
2509
|
/** @internal */ const _inAfterOpenBeforeSend = Symbol();
|
|
2549
2510
|
/** @internal */ const _resetPending = Symbol();
|
|
@@ -2557,7 +2518,7 @@ Class_setStringTag(XMLHttpRequestImpl, "XMLHttpRequest");
|
|
|
2557
2518
|
/** @internal */
|
|
2558
2519
|
class XMLHttpRequestState {
|
|
2559
2520
|
constructor(target) {
|
|
2560
|
-
this.readyState =
|
|
2521
|
+
this.readyState = 0 /* UNSENT */;
|
|
2561
2522
|
this.response = "";
|
|
2562
2523
|
this.responseType = "";
|
|
2563
2524
|
this.responseURL = "";
|
|
@@ -2592,12 +2553,12 @@ function requestSuccess(res) {
|
|
|
2592
2553
|
const s = this[state$5];
|
|
2593
2554
|
s.responseURL = s[_requestURL];
|
|
2594
2555
|
s.status = "statusCode" in res ? res.statusCode : "status" in res ? res.status : 200;
|
|
2595
|
-
s[_responseHeaders] = new HeadersP(("header" in res ? res.header : "headers" in res ? res.headers :
|
|
2556
|
+
s[_responseHeaders] = new HeadersP(("header" in res ? res.header : "headers" in res ? res.headers : {}));
|
|
2596
2557
|
let lengthStr = s[_responseHeaders].get("Content-Length");
|
|
2597
2558
|
s[_responseContentLength] = () => { return lengthStr ? parseInt(lengthStr) : 0; };
|
|
2598
|
-
if (s.readyState ===
|
|
2599
|
-
setReadyStateAndNotify(this,
|
|
2600
|
-
setReadyStateAndNotify(this,
|
|
2559
|
+
if (s.readyState === 1 /* OPENED */) {
|
|
2560
|
+
setReadyStateAndNotify(this, 2 /* HEADERS_RECEIVED */);
|
|
2561
|
+
setReadyStateAndNotify(this, 3 /* LOADING */);
|
|
2601
2562
|
setTimeout(() => {
|
|
2602
2563
|
if (!s[_inAfterOpenBeforeSend]) {
|
|
2603
2564
|
let l = s[_responseContentLength];
|
|
@@ -2626,14 +2587,14 @@ function requestFail(err) {
|
|
|
2626
2587
|
requestSuccess.call(this, {
|
|
2627
2588
|
statusCode: "statusCode" in err ? err.statusCode : err.status || 0,
|
|
2628
2589
|
header: "header" in err ? err.header : err.headers || {},
|
|
2629
|
-
data: "data" in err ? err.data : "",
|
|
2590
|
+
data: "data" in err ? err.data || "" : "",
|
|
2630
2591
|
});
|
|
2631
2592
|
return;
|
|
2632
2593
|
}
|
|
2633
2594
|
const s = this[state$5];
|
|
2634
2595
|
s.status = 0;
|
|
2635
2596
|
s.statusText = "errMsg" in err ? err.errMsg : "errorMessage" in err ? err.errorMessage : "";
|
|
2636
|
-
if (!s[_inAfterOpenBeforeSend] && s.readyState !==
|
|
2597
|
+
if (!s[_inAfterOpenBeforeSend] && s.readyState !== 0 /* UNSENT */ && s.readyState !== 4 /* DONE */) {
|
|
2637
2598
|
emitProcessEvent(this, "error");
|
|
2638
2599
|
resetRequestTimeout(this);
|
|
2639
2600
|
}
|
|
@@ -2641,8 +2602,8 @@ function requestFail(err) {
|
|
|
2641
2602
|
function requestComplete() {
|
|
2642
2603
|
const s = this[state$5];
|
|
2643
2604
|
s[_requestTask] = null;
|
|
2644
|
-
if (!s[_inAfterOpenBeforeSend] && (s.readyState ===
|
|
2645
|
-
setReadyStateAndNotify(this,
|
|
2605
|
+
if (!s[_inAfterOpenBeforeSend] && (s.readyState === 1 /* OPENED */ || s.readyState === 3 /* LOADING */)) {
|
|
2606
|
+
setReadyStateAndNotify(this, 4 /* DONE */);
|
|
2646
2607
|
}
|
|
2647
2608
|
setTimeout(() => {
|
|
2648
2609
|
if (!s[_inAfterOpenBeforeSend]) {
|
|
@@ -2661,9 +2622,9 @@ function clearRequest(xhr, delay = true) {
|
|
|
2661
2622
|
const s = xhr[state$5];
|
|
2662
2623
|
const timerFn = delay ? setTimeout : (f) => { f(); };
|
|
2663
2624
|
s[_resetPending] = true;
|
|
2664
|
-
if (s[_requestTask] && s.readyState !==
|
|
2625
|
+
if (s[_requestTask] && s.readyState !== 4 /* DONE */) {
|
|
2665
2626
|
if (delay) {
|
|
2666
|
-
setReadyStateAndNotify(xhr,
|
|
2627
|
+
setReadyStateAndNotify(xhr, 4 /* DONE */);
|
|
2667
2628
|
}
|
|
2668
2629
|
timerFn(() => {
|
|
2669
2630
|
const requestTask = s[_requestTask];
|
|
@@ -2681,7 +2642,7 @@ function clearRequest(xhr, delay = true) {
|
|
|
2681
2642
|
timerFn(() => {
|
|
2682
2643
|
if (s[_resetPending]) {
|
|
2683
2644
|
if (delay) {
|
|
2684
|
-
s.readyState =
|
|
2645
|
+
s.readyState = 0 /* UNSENT */;
|
|
2685
2646
|
}
|
|
2686
2647
|
resetXHR(xhr);
|
|
2687
2648
|
}
|
|
@@ -2691,10 +2652,10 @@ function checkRequestTimeout(xhr) {
|
|
|
2691
2652
|
const s = xhr[state$5];
|
|
2692
2653
|
if (s.timeout) {
|
|
2693
2654
|
s[_timeoutId] = setTimeout(() => {
|
|
2694
|
-
if (!s.status && s.readyState !==
|
|
2655
|
+
if (!s.status && s.readyState !== 4 /* DONE */) {
|
|
2695
2656
|
if (s[_requestTask])
|
|
2696
2657
|
safeAbort(s[_requestTask]);
|
|
2697
|
-
setReadyStateAndNotify(xhr,
|
|
2658
|
+
setReadyStateAndNotify(xhr, 4 /* DONE */);
|
|
2698
2659
|
emitProcessEvent(xhr, "timeout");
|
|
2699
2660
|
}
|
|
2700
2661
|
}, s.timeout);
|
|
@@ -2803,9 +2764,9 @@ class ResponseP extends BodyImpl {
|
|
|
2803
2764
|
return new ResponseP(null, { status, headers: { location: "" + url } });
|
|
2804
2765
|
}
|
|
2805
2766
|
/** @internal */ toString() { return "[object Response]"; }
|
|
2767
|
+
/** @internal */ get [Symbol.toStringTag]() { return "Response"; }
|
|
2806
2768
|
/** @internal */ get isPolyfill() { return { symbol: polyfill, hierarchy: ["Response"] }; }
|
|
2807
2769
|
}
|
|
2808
|
-
Class_setStringTag(ResponseP, "Response");
|
|
2809
2770
|
/** @internal */
|
|
2810
2771
|
class ResponseState {
|
|
2811
2772
|
constructor() {
|
|
@@ -2876,7 +2837,7 @@ function fetchP(...args) {
|
|
|
2876
2837
|
if ("responseType" in xhr) {
|
|
2877
2838
|
xhr.responseType = "arraybuffer";
|
|
2878
2839
|
}
|
|
2879
|
-
if (init && typeof init === "object" && typeof init.headers === "object" && !isObjectType("Headers", init.headers)) {
|
|
2840
|
+
if (init && typeof init === "object" && typeof init.headers === "object" && !(isObjectType("Headers", init.headers) || isPolyfillType("Headers", init.headers))) {
|
|
2880
2841
|
let headers = init.headers;
|
|
2881
2842
|
let names = [];
|
|
2882
2843
|
Object.getOwnPropertyNames(headers).forEach(name => {
|
|
@@ -2898,8 +2859,8 @@ function fetchP(...args) {
|
|
|
2898
2859
|
const abortXHR = () => { xhr.abort(); };
|
|
2899
2860
|
signal.addEventListener("abort", abortXHR);
|
|
2900
2861
|
xhr.onreadystatechange = function () {
|
|
2901
|
-
//
|
|
2902
|
-
if (xhr.readyState === 4) {
|
|
2862
|
+
// success or failure
|
|
2863
|
+
if (xhr.readyState === 4 /* DONE */) {
|
|
2903
2864
|
signal.removeEventListener("abort", abortXHR);
|
|
2904
2865
|
}
|
|
2905
2866
|
};
|
|
@@ -2930,9 +2891,9 @@ class CustomEventP extends EventP {
|
|
|
2930
2891
|
this[state$3].detail = detail !== null && detail !== void 0 ? detail : null;
|
|
2931
2892
|
}
|
|
2932
2893
|
/** @internal */ toString() { return "[object CustomEvent]"; }
|
|
2894
|
+
/** @internal */ get [Symbol.toStringTag]() { return "CustomEvent"; }
|
|
2933
2895
|
/** @internal */ get isPolyfill() { return { symbol: polyfill, hierarchy: ["CustomEvent", "Event"] }; }
|
|
2934
2896
|
}
|
|
2935
|
-
Class_setStringTag(CustomEventP, "CustomEvent");
|
|
2936
2897
|
/** @internal */
|
|
2937
2898
|
class CustomEventState {
|
|
2938
2899
|
}
|
|
@@ -2956,9 +2917,9 @@ class CloseEventP extends EventP {
|
|
|
2956
2917
|
get reason() { return this[state$2].reason; }
|
|
2957
2918
|
get wasClean() { return this[state$2].wasClean; }
|
|
2958
2919
|
/** @internal */ toString() { return "[object CloseEvent]"; }
|
|
2920
|
+
/** @internal */ get [Symbol.toStringTag]() { return "CloseEvent"; }
|
|
2959
2921
|
/** @internal */ get isPolyfill() { return { symbol: polyfill, hierarchy: ["CloseEvent", "Event"] }; }
|
|
2960
2922
|
}
|
|
2961
|
-
Class_setStringTag(CloseEventP, "CloseEvent");
|
|
2962
2923
|
/** @internal */
|
|
2963
2924
|
class CloseEventState {
|
|
2964
2925
|
constructor() {
|
|
@@ -3011,9 +2972,9 @@ class MessageEventP extends EventP {
|
|
|
3011
2972
|
s.ports = ports;
|
|
3012
2973
|
}
|
|
3013
2974
|
/** @internal */ toString() { return "[object MessageEvent]"; }
|
|
2975
|
+
/** @internal */ get [Symbol.toStringTag]() { return "MessageEvent"; }
|
|
3014
2976
|
/** @internal */ get isPolyfill() { return { symbol: polyfill, hierarchy: ["MessageEvent", "Event"] }; }
|
|
3015
2977
|
}
|
|
3016
|
-
Class_setStringTag(MessageEventP, "MessageEvent");
|
|
3017
2978
|
/** @internal */
|
|
3018
2979
|
class MessageEventState {
|
|
3019
2980
|
constructor() {
|
|
@@ -3051,6 +3012,10 @@ const setConnectSocket = (connectSocket) => { mp.connectSocket = connectSocket;
|
|
|
3051
3012
|
/** @internal */
|
|
3052
3013
|
const state = Symbol( /* "WebSocketState" */);
|
|
3053
3014
|
class WebSocketImpl extends EventTargetP {
|
|
3015
|
+
static get CONNECTING() { return 0; }
|
|
3016
|
+
static get OPEN() { return 1; }
|
|
3017
|
+
static get CLOSING() { return 2; }
|
|
3018
|
+
static get CLOSED() { return 3; }
|
|
3054
3019
|
constructor(...args) {
|
|
3055
3020
|
const [url, protocols] = args;
|
|
3056
3021
|
checkArgsLength(args, 1, "WebSocket");
|
|
@@ -3076,6 +3041,10 @@ class WebSocketImpl extends EventTargetP {
|
|
|
3076
3041
|
throw new Error(`connectSocket can't establish a connection to the server at ${"" + url}.`);
|
|
3077
3042
|
}
|
|
3078
3043
|
}
|
|
3044
|
+
get CONNECTING() { return 0; }
|
|
3045
|
+
get OPEN() { return 1; }
|
|
3046
|
+
get CLOSING() { return 2; }
|
|
3047
|
+
get CLOSED() { return 3; }
|
|
3079
3048
|
get binaryType() { return this[state].binaryType; }
|
|
3080
3049
|
set binaryType(value) { if (value === "blob" || value === "arraybuffer") {
|
|
3081
3050
|
this[state].binaryType = value;
|
|
@@ -3086,29 +3055,29 @@ class WebSocketImpl extends EventTargetP {
|
|
|
3086
3055
|
get readyState() { return this[state].readyState; }
|
|
3087
3056
|
get url() { return this[state].url; }
|
|
3088
3057
|
close(code, reason) {
|
|
3089
|
-
if (this.readyState ===
|
|
3058
|
+
if (this.readyState === 2 /* CLOSING */ || this.readyState === 3 /* CLOSED */)
|
|
3090
3059
|
return;
|
|
3091
|
-
this[state].readyState =
|
|
3060
|
+
this[state].readyState = 2 /* CLOSING */;
|
|
3092
3061
|
this[state][_socketTask].close({
|
|
3093
3062
|
code: code,
|
|
3094
3063
|
reason: reason,
|
|
3095
3064
|
fail(err) { console.error(err); },
|
|
3096
3065
|
complete: (function () {
|
|
3097
|
-
this[state].readyState =
|
|
3066
|
+
this[state].readyState = 3 /* CLOSED */;
|
|
3098
3067
|
}).bind(this),
|
|
3099
3068
|
});
|
|
3100
3069
|
}
|
|
3101
3070
|
send(...args) {
|
|
3102
3071
|
const [data] = args;
|
|
3103
3072
|
checkArgsLength(args, 1, "WebSocket", "send");
|
|
3104
|
-
if (this.readyState ===
|
|
3073
|
+
if (this.readyState === 0 /* CONNECTING */) {
|
|
3105
3074
|
throw new MPException("Failed to execute 'send' on 'WebSocket': Still in CONNECTING state.", "InvalidStateError");
|
|
3106
3075
|
}
|
|
3107
|
-
if (this.readyState ===
|
|
3076
|
+
if (this.readyState === 2 /* CLOSING */ || this.readyState === 3 /* CLOSED */) {
|
|
3108
3077
|
return console.error("WebSocket is already in CLOSING or CLOSED state.");
|
|
3109
3078
|
}
|
|
3110
3079
|
let _data;
|
|
3111
|
-
if (data
|
|
3080
|
+
if (isArrayBuffer(data)) {
|
|
3112
3081
|
_data = data;
|
|
3113
3082
|
}
|
|
3114
3083
|
else if (ArrayBuffer.isView(data)) {
|
|
@@ -3134,17 +3103,9 @@ class WebSocketImpl extends EventTargetP {
|
|
|
3134
3103
|
get onopen() { return this[state].onopen; }
|
|
3135
3104
|
set onopen(value) { this[state].onopen = value; attach(this, "open"); }
|
|
3136
3105
|
/** @internal */ toString() { return "[object WebSocket]"; }
|
|
3106
|
+
/** @internal */ get [Symbol.toStringTag]() { return "WebSocket"; }
|
|
3137
3107
|
/** @internal */ get isPolyfill() { return { symbol: polyfill, hierarchy: ["WebSocket", "EventTarget"] }; }
|
|
3138
3108
|
}
|
|
3139
|
-
const properties = {
|
|
3140
|
-
CONNECTING: { value: 0, enumerable: true },
|
|
3141
|
-
OPEN: { value: 1, enumerable: true },
|
|
3142
|
-
CLOSING: { value: 2, enumerable: true },
|
|
3143
|
-
CLOSED: { value: 3, enumerable: true },
|
|
3144
|
-
};
|
|
3145
|
-
Object.defineProperties(WebSocketImpl, properties);
|
|
3146
|
-
Object.defineProperties(WebSocketImpl.prototype, properties);
|
|
3147
|
-
Class_setStringTag(WebSocketImpl, "WebSocket");
|
|
3148
3109
|
/** @internal */ const _socketTask = Symbol();
|
|
3149
3110
|
/** @internal */ const _error = Symbol();
|
|
3150
3111
|
/** @internal */ const _handlers = Symbol();
|
|
@@ -3184,41 +3145,41 @@ function getHandlers(s) {
|
|
|
3184
3145
|
};
|
|
3185
3146
|
}
|
|
3186
3147
|
function onOpen(ws) {
|
|
3187
|
-
let
|
|
3188
|
-
|
|
3148
|
+
let socket = ws;
|
|
3149
|
+
socket[state][_socketTask].onOpen(res => {
|
|
3189
3150
|
if ("header" in res && res.header && typeof res.header === "object") {
|
|
3190
3151
|
let headers = new HeadersP(res.header);
|
|
3191
|
-
|
|
3152
|
+
socket[state].protocol = headers.get("Sec-WebSocket-Protocol") || "";
|
|
3192
3153
|
}
|
|
3193
|
-
|
|
3194
|
-
EventTarget_fire(
|
|
3154
|
+
socket[state].readyState = 1 /* OPEN */;
|
|
3155
|
+
EventTarget_fire(socket, createInnerEvent(socket, "open"));
|
|
3195
3156
|
});
|
|
3196
3157
|
}
|
|
3197
3158
|
function onClose(ws) {
|
|
3198
|
-
let
|
|
3199
|
-
|
|
3200
|
-
|
|
3159
|
+
let socket = ws;
|
|
3160
|
+
socket[state][_socketTask].onClose(res => {
|
|
3161
|
+
socket[state].readyState = 3 /* CLOSED */;
|
|
3201
3162
|
let event = new CloseEventP("close", {
|
|
3202
|
-
wasClean: !
|
|
3163
|
+
wasClean: !socket[state][_error],
|
|
3203
3164
|
code: res.code,
|
|
3204
3165
|
reason: res.reason,
|
|
3205
3166
|
});
|
|
3206
3167
|
Event_setTrusted(event, true);
|
|
3207
|
-
EventTarget_fire(
|
|
3168
|
+
EventTarget_fire(socket, event);
|
|
3208
3169
|
});
|
|
3209
3170
|
}
|
|
3210
3171
|
function onError(ws) {
|
|
3211
|
-
let
|
|
3212
|
-
|
|
3172
|
+
let socket = ws;
|
|
3173
|
+
socket[state][_socketTask].onError(res => {
|
|
3213
3174
|
console.error(res);
|
|
3214
|
-
|
|
3215
|
-
|
|
3216
|
-
EventTarget_fire(
|
|
3175
|
+
socket[state][_error] = res;
|
|
3176
|
+
socket[state].readyState = 3 /* CLOSED */;
|
|
3177
|
+
EventTarget_fire(socket, createInnerEvent(socket, "error"));
|
|
3217
3178
|
});
|
|
3218
3179
|
}
|
|
3219
3180
|
function onMessage(ws) {
|
|
3220
|
-
let
|
|
3221
|
-
|
|
3181
|
+
let socket = ws;
|
|
3182
|
+
socket[state][_socketTask].onMessage(res => {
|
|
3222
3183
|
let data = res.data;
|
|
3223
3184
|
let _data;
|
|
3224
3185
|
// Alipay Mini Program
|
|
@@ -3235,15 +3196,15 @@ function onMessage(ws) {
|
|
|
3235
3196
|
else {
|
|
3236
3197
|
_data = data;
|
|
3237
3198
|
}
|
|
3238
|
-
if (_data
|
|
3199
|
+
if (isArrayBuffer(_data) && socket.binaryType === "blob") {
|
|
3239
3200
|
_data = new BlobP([_data]);
|
|
3240
3201
|
}
|
|
3241
3202
|
let event = new MessageEventP("message", {
|
|
3242
3203
|
data: _data,
|
|
3243
|
-
origin:
|
|
3204
|
+
origin: socket.url,
|
|
3244
3205
|
});
|
|
3245
3206
|
Event_setTrusted(event, true);
|
|
3246
|
-
EventTarget_fire(
|
|
3207
|
+
EventTarget_fire(socket, event);
|
|
3247
3208
|
});
|
|
3248
3209
|
}
|
|
3249
3210
|
|