fetch-xhr-shim 1.0.2 → 1.0.4
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/dist/cjs/dev.js +1 -0
- package/dist/cjs/event-system/AbortSignalP.js +2 -2
- package/dist/cjs/event-system/EventP.js +6 -2
- package/dist/cjs/fetch-api/BodyImpl.js +1 -1
- package/dist/cjs/fetch-api/HeadersP.js +3 -3
- package/dist/cjs/fetch-api/fetchP.js +3 -3
- package/dist/cjs/fixes.js +3 -3
- package/dist/cjs/network/FormDataP.js +24 -4
- package/dist/cjs/network/URLSearchParamsP.js +3 -3
- package/dist/cjs/utils.js +17 -2
- package/dist/dev.d.ts +2 -1
- package/dist/esm/dev.js +1 -1
- package/dist/esm/event-system/AbortSignalP.js +2 -2
- package/dist/esm/event-system/EventP.js +6 -2
- package/dist/esm/fetch-api/BodyImpl.js +1 -1
- package/dist/esm/fetch-api/HeadersP.js +4 -4
- package/dist/esm/fetch-api/fetchP.js +3 -3
- package/dist/esm/fixes.js +3 -3
- package/dist/esm/network/FormDataP.js +25 -5
- package/dist/esm/network/URLSearchParamsP.js +4 -4
- package/dist/esm/utils.js +17 -3
- package/dist/fetch-xhr-shim.cjs.js +3496 -2449
- package/dist/fetch-xhr-shim.cjs.min.js +1 -1
- package/dist/fetch-xhr-shim.esm.js +3496 -2449
- package/dist/fetch-xhr-shim.esm.min.js +1 -1
- package/dist/fetch-xhr-shim.polyfill.iife.js +3794 -2759
- package/dist/fetch-xhr-shim.polyfill.iife.min.js +1 -1
- package/package.json +4 -1
- package/polyfill.js +3794 -2759
package/dist/cjs/dev.js
CHANGED
|
@@ -44,10 +44,10 @@ class AbortSignalP extends EventTargetP.EventTargetP {
|
|
|
44
44
|
}
|
|
45
45
|
/** @internal */
|
|
46
46
|
constructor() {
|
|
47
|
-
|
|
47
|
+
super();
|
|
48
|
+
if (this.constructor === AbortSignalP) {
|
|
48
49
|
throw new TypeError("Failed to construct 'AbortSignal': Illegal constructor");
|
|
49
50
|
}
|
|
50
|
-
super();
|
|
51
51
|
utils.setState(this, "__AbortSignal__", new AbortSignalState(this));
|
|
52
52
|
}
|
|
53
53
|
get aborted() { return state(this).aborted; }
|
|
@@ -101,8 +101,12 @@ function state(target) {
|
|
|
101
101
|
return target.__Event__;
|
|
102
102
|
}
|
|
103
103
|
const timeStamp = (new Date()).getTime();
|
|
104
|
+
function getFuncName(func) {
|
|
105
|
+
// ES5
|
|
106
|
+
return "name" in func ? func.name : "unknown";
|
|
107
|
+
}
|
|
104
108
|
function createTrustedPropertyDescriptor() {
|
|
105
|
-
let name = createTrustedPropertyDescriptor
|
|
109
|
+
let name = getFuncName(createTrustedPropertyDescriptor);
|
|
106
110
|
let idx = name.length;
|
|
107
111
|
let isTrusted = "NO";
|
|
108
112
|
return {
|
|
@@ -116,7 +120,7 @@ function createTrustedPropertyDescriptor() {
|
|
|
116
120
|
}
|
|
117
121
|
function Event_setTrusted(event, isTrusted) {
|
|
118
122
|
let s = state(event) || {};
|
|
119
|
-
s.isTrusted = `${createTrustedPropertyDescriptor
|
|
123
|
+
s.isTrusted = `${getFuncName(createTrustedPropertyDescriptor)}:${isTrusted ? "YES" : "NO"}`;
|
|
120
124
|
}
|
|
121
125
|
const EventE = (typeof Event !== "undefined" && Event) || EventP;
|
|
122
126
|
|
|
@@ -69,7 +69,7 @@ class Payload {
|
|
|
69
69
|
class BodyImpl {
|
|
70
70
|
/** @internal */
|
|
71
71
|
constructor() {
|
|
72
|
-
if (
|
|
72
|
+
if (this.constructor === BodyImpl) {
|
|
73
73
|
throw new TypeError("Failed to construct 'Body': Illegal constructor");
|
|
74
74
|
}
|
|
75
75
|
utils.setState(this, "__Body__", new BodyState());
|
|
@@ -77,17 +77,17 @@ class HeadersP {
|
|
|
77
77
|
entries() {
|
|
78
78
|
let array = [];
|
|
79
79
|
this.forEach(function (value, name) { array.push([name, value]); });
|
|
80
|
-
return
|
|
80
|
+
return utils.makeIterator(array);
|
|
81
81
|
}
|
|
82
82
|
keys() {
|
|
83
83
|
let array = [];
|
|
84
84
|
this.forEach(function (value, name) { array.push([name, value]); });
|
|
85
|
-
return array.map(function (x) { return x[0]; })
|
|
85
|
+
return utils.makeIterator(array.map(function (x) { return x[0]; }));
|
|
86
86
|
}
|
|
87
87
|
values() {
|
|
88
88
|
let array = [];
|
|
89
89
|
this.forEach(function (value, name) { array.push([name, value]); });
|
|
90
|
-
return array.map(function (x) { return x[1]; })
|
|
90
|
+
return utils.makeIterator(array.map(function (x) { return x[1]; }));
|
|
91
91
|
}
|
|
92
92
|
// @ts-ignore
|
|
93
93
|
/** @internal */ [utils._Symbol.iterator]() {
|
|
@@ -9,8 +9,8 @@ var HeadersP = require('./HeadersP.js');
|
|
|
9
9
|
const mp = { XMLHttpRequest: (typeof XMLHttpRequest !== "undefined" && XMLHttpRequest) || undefined };
|
|
10
10
|
function setXMLHttpRequestClass(XHRClass) { mp.XMLHttpRequest = XHRClass; }
|
|
11
11
|
function fetchP(input, init) {
|
|
12
|
-
utils.checkArgsLength(arguments.length, 1, "Window", "fetch");
|
|
13
|
-
if (
|
|
12
|
+
utils.checkArgsLength(arguments.length, 1, "Window", "fetch"); // @ts-expect-error
|
|
13
|
+
if (this instanceof fetchP) {
|
|
14
14
|
throw new TypeError("fetch is not a constructor");
|
|
15
15
|
}
|
|
16
16
|
return new Promise(function (resolve, reject) {
|
|
@@ -107,8 +107,8 @@ function fetchP(input, init) {
|
|
|
107
107
|
reject(createAbortException());
|
|
108
108
|
})
|
|
109
109
|
.catch(function (e) {
|
|
110
|
-
console.error(e);
|
|
111
110
|
reject(new TypeError("Failed to fetch"));
|
|
111
|
+
console.error(e);
|
|
112
112
|
});
|
|
113
113
|
});
|
|
114
114
|
}
|
package/dist/cjs/fixes.js
CHANGED
|
@@ -145,8 +145,8 @@ function fixFetch(fetchFunc) {
|
|
|
145
145
|
}).bind(this))
|
|
146
146
|
.catch(function (e) {
|
|
147
147
|
reject(new TypeError("Failed to fetch"));
|
|
148
|
-
console.error(e);
|
|
149
148
|
processing = false;
|
|
149
|
+
console.error(e);
|
|
150
150
|
})
|
|
151
151
|
.then(function () { if (removeFn) {
|
|
152
152
|
removeFn();
|
|
@@ -202,8 +202,8 @@ function fixXMLHttpRequest(XHRClass) {
|
|
|
202
202
|
payload.promise.then((function (r) {
|
|
203
203
|
if (!state(this).aborted) {
|
|
204
204
|
if (withCredentials !== this.withCredentials) {
|
|
205
|
-
console.warn("Illegal to set the 'withCredentials' property on 'XMLHttpRequest': The value may only be set if the object's state is UNSENT or OPENED.");
|
|
206
205
|
this.withCredentials = withCredentials;
|
|
206
|
+
console.warn("Illegal to set the 'withCredentials' property on 'XMLHttpRequest': The value may only be set if the object's state is UNSENT or OPENED.");
|
|
207
207
|
}
|
|
208
208
|
_send.call(this, r !== "" ? r : undefined);
|
|
209
209
|
}
|
|
@@ -211,9 +211,9 @@ function fixXMLHttpRequest(XHRClass) {
|
|
|
211
211
|
state(this).processing = false;
|
|
212
212
|
}).bind(this))
|
|
213
213
|
.catch((function (e) {
|
|
214
|
-
console.error(e);
|
|
215
214
|
state(this).aborted = false;
|
|
216
215
|
state(this).processing = false;
|
|
216
|
+
console.error(e);
|
|
217
217
|
}).bind(this));
|
|
218
218
|
}
|
|
219
219
|
else {
|
|
@@ -12,7 +12,7 @@ class FormDataP {
|
|
|
12
12
|
let elements = form.elements;
|
|
13
13
|
for (let i = 0; i < elements.length; ++i) {
|
|
14
14
|
let elm = elements[i];
|
|
15
|
-
if (!elm.name || elm.disabled || elm.type === "submit" || elm.type === "button" ||
|
|
15
|
+
if (!elm.name || elm.disabled || elm.type === "submit" || elm.type === "button" || matches(elm, "form fieldset[disabled] *"))
|
|
16
16
|
return;
|
|
17
17
|
if (elm.type === "file") {
|
|
18
18
|
let files = elm.files && elm.files.length
|
|
@@ -140,13 +140,13 @@ class FormDataP {
|
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
142
|
entries() {
|
|
143
|
-
return state(this).array.map(function (x) { return [x[0], x[1]]; })
|
|
143
|
+
return utils.makeIterator(state(this).array.map(function (x) { return [x[0], x[1]]; }));
|
|
144
144
|
}
|
|
145
145
|
keys() {
|
|
146
|
-
return state(this).array.map(function (x) { return x[0]; })
|
|
146
|
+
return utils.makeIterator(state(this).array.map(function (x) { return x[0]; }));
|
|
147
147
|
}
|
|
148
148
|
values() {
|
|
149
|
-
return state(this).array.map(function (x) { return x[1]; })
|
|
149
|
+
return utils.makeIterator(state(this).array.map(function (x) { return x[1]; }));
|
|
150
150
|
}
|
|
151
151
|
// @ts-ignore
|
|
152
152
|
/** @internal */ [utils._Symbol.iterator]() {
|
|
@@ -183,6 +183,26 @@ function normalizeArgs(name, value, filename) {
|
|
|
183
183
|
}
|
|
184
184
|
return ["" + name, "" + value];
|
|
185
185
|
}
|
|
186
|
+
// Polyfill for Element.prototype.matches,
|
|
187
|
+
// tries native, then vendor prefixes, then querySelectorAll fallback.
|
|
188
|
+
function matches(elm, selectors) {
|
|
189
|
+
let proto = (typeof Element !== "undefined" && Element && Element.prototype);
|
|
190
|
+
if (proto && !proto.matches) {
|
|
191
|
+
proto.matches = // @ts-ignore
|
|
192
|
+
proto.matchesSelector || // @ts-ignore
|
|
193
|
+
proto.mozMatchesSelector || // @ts-ignore
|
|
194
|
+
proto.msMatchesSelector || // @ts-ignore
|
|
195
|
+
proto.oMatchesSelector || // @ts-ignore
|
|
196
|
+
proto.webkitMatchesSelector || // @ts-ignore
|
|
197
|
+
function (s) {
|
|
198
|
+
let matches = (this.ownerDocument || this.document).querySelectorAll(s);
|
|
199
|
+
let i = matches.length;
|
|
200
|
+
while (--i >= 0 && matches.item(i) !== this) { }
|
|
201
|
+
return i > -1;
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
return proto ? proto.matches.call(elm, selectors) : false;
|
|
205
|
+
}
|
|
186
206
|
function isFormData(value) {
|
|
187
207
|
return utils.isPolyfillType("FormData", value) || isExternalFormData(value);
|
|
188
208
|
}
|
|
@@ -160,13 +160,13 @@ class URLSearchParamsP {
|
|
|
160
160
|
}
|
|
161
161
|
}
|
|
162
162
|
entries() {
|
|
163
|
-
return state(this).array.map(function (x) { return [x[0], x[1]]; })
|
|
163
|
+
return utils.makeIterator(state(this).array.map(function (x) { return [x[0], x[1]]; }));
|
|
164
164
|
}
|
|
165
165
|
keys() {
|
|
166
|
-
return state(this).array.map(function (x) { return x[0]; })
|
|
166
|
+
return utils.makeIterator(state(this).array.map(function (x) { return x[0]; }));
|
|
167
167
|
}
|
|
168
168
|
values() {
|
|
169
|
-
return state(this).array.map(function (x) { return x[1]; })
|
|
169
|
+
return utils.makeIterator(state(this).array.map(function (x) { return x[1]; }));
|
|
170
170
|
}
|
|
171
171
|
// @ts-ignore
|
|
172
172
|
/** @internal */ [utils._Symbol.iterator]() {
|
package/dist/cjs/utils.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
// Safe fallback for Symbol.iterator and Symbol.toStringTag — uses native Symbol when available, string keys otherwise.
|
|
3
4
|
const _Symbol = {
|
|
4
|
-
iterator: ((typeof Symbol === "function"
|
|
5
|
-
toStringTag: ((typeof Symbol === "function"
|
|
5
|
+
iterator: ((typeof Symbol === "function" && Symbol.iterator) || "Symbol(Symbol.iterator)"),
|
|
6
|
+
toStringTag: ((typeof Symbol === "function" && Symbol.toStringTag) || "Symbol(Symbol.toStringTag)"),
|
|
6
7
|
};
|
|
7
8
|
class DOMExceptionP extends Error {
|
|
8
9
|
constructor(message, name) {
|
|
@@ -53,6 +54,19 @@ function isSequence(value) {
|
|
|
53
54
|
&& Symbol.iterator in value
|
|
54
55
|
&& typeof value[Symbol.iterator] === "function");
|
|
55
56
|
}
|
|
57
|
+
function makeIterator(array) {
|
|
58
|
+
let index = 0;
|
|
59
|
+
let iterator = {
|
|
60
|
+
next: function () {
|
|
61
|
+
if (index < array.length) {
|
|
62
|
+
return { value: array[index++], done: false };
|
|
63
|
+
}
|
|
64
|
+
return { value: undefined, done: true };
|
|
65
|
+
},
|
|
66
|
+
[_Symbol.iterator]: function () { return iterator; },
|
|
67
|
+
};
|
|
68
|
+
return iterator;
|
|
69
|
+
}
|
|
56
70
|
function checkArgsLength(actual, expect, className, funcName) {
|
|
57
71
|
if (actual < expect) {
|
|
58
72
|
throw new TypeError(`Failed to ${funcName ? ("execute '" + funcName + "' on") : "construct"} '${className}': ${expect} argument${expect > 1 ? "s" : ""} required, but only ${actual} present.`);
|
|
@@ -67,4 +81,5 @@ exports.className = className;
|
|
|
67
81
|
exports.isObjectType = isObjectType;
|
|
68
82
|
exports.isPolyfillType = isPolyfillType;
|
|
69
83
|
exports.isSequence = isSequence;
|
|
84
|
+
exports.makeIterator = makeIterator;
|
|
70
85
|
exports.setState = setState;
|
package/dist/dev.d.ts
CHANGED
|
@@ -141,6 +141,7 @@ declare function setState<T extends object, K extends keyof T>(target: T, name:
|
|
|
141
141
|
declare function isObjectType<T>(name: string, value: unknown): value is T;
|
|
142
142
|
declare function isPolyfillType<T>(name: string, value: unknown, strict?: boolean): value is T;
|
|
143
143
|
declare function isSequence(value: unknown): value is any[];
|
|
144
|
+
declare function makeIterator<T>(array: T[]): IterableIterator<T>;
|
|
144
145
|
declare function checkArgsLength(actual: number, expect: number, className: string, funcName?: string): void;
|
|
145
146
|
|
|
146
|
-
export { AbortSignal_abort, BodyImpl, DOMExceptionE as DOMException, DOMExceptionP, EventTarget_dispatchEvent, Event_setTrusted, FormData_toBlob, Payload, ProgressEventP, Uint8Array_toBase64, _Symbol, attachFn, checkArgsLength, className, createAbortSignal, createFormDataFromBinaryText, createHeaders, createPhonyPayload, decode, emitProgressEvent, encode, executeFn, extractBoundary, initBody, isArrayBuffer, isBlob, isEventTarget, isFormData, isHeaders, isObjectType, isPolyfillType, isSequence, isURLSearchParams, normalizeMethod, normalizeName, normalizeValue, parseHeaders, setState };
|
|
147
|
+
export { AbortSignal_abort, BodyImpl, DOMExceptionE as DOMException, DOMExceptionP, EventTarget_dispatchEvent, Event_setTrusted, FormData_toBlob, Payload, ProgressEventP, Uint8Array_toBase64, _Symbol, attachFn, checkArgsLength, className, createAbortSignal, createFormDataFromBinaryText, createHeaders, createPhonyPayload, decode, emitProgressEvent, encode, executeFn, extractBoundary, initBody, isArrayBuffer, isBlob, isEventTarget, isFormData, isHeaders, isObjectType, isPolyfillType, isSequence, isURLSearchParams, makeIterator, normalizeMethod, normalizeName, normalizeValue, parseHeaders, setState };
|
package/dist/esm/dev.js
CHANGED
|
@@ -10,4 +10,4 @@ export { FormData_toBlob, createFormDataFromBinaryText, extractBoundary, isFormD
|
|
|
10
10
|
export { createHeaders, isHeaders, normalizeName, normalizeValue, parseHeaders } from './fetch-api/HeadersP.js';
|
|
11
11
|
export { BodyImpl, Payload, initBody } from './fetch-api/BodyImpl.js';
|
|
12
12
|
export { createPhonyPayload, normalizeMethod } from './fetch-api/RequestP.js';
|
|
13
|
-
export { DOMException, DOMExceptionP, _Symbol, checkArgsLength, className, isObjectType, isPolyfillType, isSequence, setState } from './utils.js';
|
|
13
|
+
export { DOMException, DOMExceptionP, _Symbol, checkArgsLength, className, isObjectType, isPolyfillType, isSequence, makeIterator, setState } from './utils.js';
|
|
@@ -42,10 +42,10 @@ class AbortSignalP extends EventTargetP {
|
|
|
42
42
|
}
|
|
43
43
|
/** @internal */
|
|
44
44
|
constructor() {
|
|
45
|
-
|
|
45
|
+
super();
|
|
46
|
+
if (this.constructor === AbortSignalP) {
|
|
46
47
|
throw new TypeError("Failed to construct 'AbortSignal': Illegal constructor");
|
|
47
48
|
}
|
|
48
|
-
super();
|
|
49
49
|
setState(this, "__AbortSignal__", new AbortSignalState(this));
|
|
50
50
|
}
|
|
51
51
|
get aborted() { return state(this).aborted; }
|
|
@@ -99,8 +99,12 @@ function state(target) {
|
|
|
99
99
|
return target.__Event__;
|
|
100
100
|
}
|
|
101
101
|
const timeStamp = (new Date()).getTime();
|
|
102
|
+
function getFuncName(func) {
|
|
103
|
+
// ES5
|
|
104
|
+
return "name" in func ? func.name : "unknown";
|
|
105
|
+
}
|
|
102
106
|
function createTrustedPropertyDescriptor() {
|
|
103
|
-
let name = createTrustedPropertyDescriptor
|
|
107
|
+
let name = getFuncName(createTrustedPropertyDescriptor);
|
|
104
108
|
let idx = name.length;
|
|
105
109
|
let isTrusted = "NO";
|
|
106
110
|
return {
|
|
@@ -114,7 +118,7 @@ function createTrustedPropertyDescriptor() {
|
|
|
114
118
|
}
|
|
115
119
|
function Event_setTrusted(event, isTrusted) {
|
|
116
120
|
let s = state(event) || {};
|
|
117
|
-
s.isTrusted = `${createTrustedPropertyDescriptor
|
|
121
|
+
s.isTrusted = `${getFuncName(createTrustedPropertyDescriptor)}:${isTrusted ? "YES" : "NO"}`;
|
|
118
122
|
}
|
|
119
123
|
const EventE = (typeof Event !== "undefined" && Event) || EventP;
|
|
120
124
|
|
|
@@ -67,7 +67,7 @@ class Payload {
|
|
|
67
67
|
class BodyImpl {
|
|
68
68
|
/** @internal */
|
|
69
69
|
constructor() {
|
|
70
|
-
if (
|
|
70
|
+
if (this.constructor === BodyImpl) {
|
|
71
71
|
throw new TypeError("Failed to construct 'Body': Illegal constructor");
|
|
72
72
|
}
|
|
73
73
|
setState(this, "__Body__", new BodyState());
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { setState, isSequence, _Symbol, isPolyfillType, checkArgsLength } from '../utils.js';
|
|
1
|
+
import { setState, isSequence, makeIterator, _Symbol, isPolyfillType, checkArgsLength } from '../utils.js';
|
|
2
2
|
|
|
3
3
|
class HeadersP {
|
|
4
4
|
constructor(init) {
|
|
@@ -75,17 +75,17 @@ class HeadersP {
|
|
|
75
75
|
entries() {
|
|
76
76
|
let array = [];
|
|
77
77
|
this.forEach(function (value, name) { array.push([name, value]); });
|
|
78
|
-
return array
|
|
78
|
+
return makeIterator(array);
|
|
79
79
|
}
|
|
80
80
|
keys() {
|
|
81
81
|
let array = [];
|
|
82
82
|
this.forEach(function (value, name) { array.push([name, value]); });
|
|
83
|
-
return array.map(function (x) { return x[0]; })
|
|
83
|
+
return makeIterator(array.map(function (x) { return x[0]; }));
|
|
84
84
|
}
|
|
85
85
|
values() {
|
|
86
86
|
let array = [];
|
|
87
87
|
this.forEach(function (value, name) { array.push([name, value]); });
|
|
88
|
-
return array.map(function (x) { return x[1]; })
|
|
88
|
+
return makeIterator(array.map(function (x) { return x[1]; }));
|
|
89
89
|
}
|
|
90
90
|
// @ts-ignore
|
|
91
91
|
/** @internal */ [_Symbol.iterator]() {
|
|
@@ -7,8 +7,8 @@ import { parseHeaders, isHeaders, normalizeName, normalizeValue } from './Header
|
|
|
7
7
|
const mp = { XMLHttpRequest: (typeof XMLHttpRequest !== "undefined" && XMLHttpRequest) || undefined };
|
|
8
8
|
function setXMLHttpRequestClass(XHRClass) { mp.XMLHttpRequest = XHRClass; }
|
|
9
9
|
function fetchP(input, init) {
|
|
10
|
-
checkArgsLength(arguments.length, 1, "Window", "fetch");
|
|
11
|
-
if (
|
|
10
|
+
checkArgsLength(arguments.length, 1, "Window", "fetch"); // @ts-expect-error
|
|
11
|
+
if (this instanceof fetchP) {
|
|
12
12
|
throw new TypeError("fetch is not a constructor");
|
|
13
13
|
}
|
|
14
14
|
return new Promise(function (resolve, reject) {
|
|
@@ -105,8 +105,8 @@ function fetchP(input, init) {
|
|
|
105
105
|
reject(createAbortException());
|
|
106
106
|
})
|
|
107
107
|
.catch(function (e) {
|
|
108
|
-
console.error(e);
|
|
109
108
|
reject(new TypeError("Failed to fetch"));
|
|
109
|
+
console.error(e);
|
|
110
110
|
});
|
|
111
111
|
});
|
|
112
112
|
}
|
package/dist/esm/fixes.js
CHANGED
|
@@ -143,8 +143,8 @@ function fixFetch(fetchFunc) {
|
|
|
143
143
|
}).bind(this))
|
|
144
144
|
.catch(function (e) {
|
|
145
145
|
reject(new TypeError("Failed to fetch"));
|
|
146
|
-
console.error(e);
|
|
147
146
|
processing = false;
|
|
147
|
+
console.error(e);
|
|
148
148
|
})
|
|
149
149
|
.then(function () { if (removeFn) {
|
|
150
150
|
removeFn();
|
|
@@ -200,8 +200,8 @@ function fixXMLHttpRequest(XHRClass) {
|
|
|
200
200
|
payload.promise.then((function (r) {
|
|
201
201
|
if (!state(this).aborted) {
|
|
202
202
|
if (withCredentials !== this.withCredentials) {
|
|
203
|
-
console.warn("Illegal to set the 'withCredentials' property on 'XMLHttpRequest': The value may only be set if the object's state is UNSENT or OPENED.");
|
|
204
203
|
this.withCredentials = withCredentials;
|
|
204
|
+
console.warn("Illegal to set the 'withCredentials' property on 'XMLHttpRequest': The value may only be set if the object's state is UNSENT or OPENED.");
|
|
205
205
|
}
|
|
206
206
|
_send.call(this, r !== "" ? r : undefined);
|
|
207
207
|
}
|
|
@@ -209,9 +209,9 @@ function fixXMLHttpRequest(XHRClass) {
|
|
|
209
209
|
state(this).processing = false;
|
|
210
210
|
}).bind(this))
|
|
211
211
|
.catch((function (e) {
|
|
212
|
-
console.error(e);
|
|
213
212
|
state(this).aborted = false;
|
|
214
213
|
state(this).processing = false;
|
|
214
|
+
console.error(e);
|
|
215
215
|
}).bind(this));
|
|
216
216
|
}
|
|
217
217
|
else {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { File as FileE, FileP as FilePolyfill } from '../file-system/FileP.js';
|
|
2
2
|
import { Blob as BlobE, BlobP, isBlob } from '../file-system/BlobP.js';
|
|
3
|
-
import { setState, _Symbol, isPolyfillType, checkArgsLength } from '../utils.js';
|
|
3
|
+
import { setState, makeIterator, _Symbol, isPolyfillType, checkArgsLength } from '../utils.js';
|
|
4
4
|
|
|
5
5
|
class FormDataP {
|
|
6
6
|
constructor(form, submitter) {
|
|
@@ -10,7 +10,7 @@ class FormDataP {
|
|
|
10
10
|
let elements = form.elements;
|
|
11
11
|
for (let i = 0; i < elements.length; ++i) {
|
|
12
12
|
let elm = elements[i];
|
|
13
|
-
if (!elm.name || elm.disabled || elm.type === "submit" || elm.type === "button" ||
|
|
13
|
+
if (!elm.name || elm.disabled || elm.type === "submit" || elm.type === "button" || matches(elm, "form fieldset[disabled] *"))
|
|
14
14
|
return;
|
|
15
15
|
if (elm.type === "file") {
|
|
16
16
|
let files = elm.files && elm.files.length
|
|
@@ -138,13 +138,13 @@ class FormDataP {
|
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
140
|
entries() {
|
|
141
|
-
return state(this).array.map(function (x) { return [x[0], x[1]]; })
|
|
141
|
+
return makeIterator(state(this).array.map(function (x) { return [x[0], x[1]]; }));
|
|
142
142
|
}
|
|
143
143
|
keys() {
|
|
144
|
-
return state(this).array.map(function (x) { return x[0]; })
|
|
144
|
+
return makeIterator(state(this).array.map(function (x) { return x[0]; }));
|
|
145
145
|
}
|
|
146
146
|
values() {
|
|
147
|
-
return state(this).array.map(function (x) { return x[1]; })
|
|
147
|
+
return makeIterator(state(this).array.map(function (x) { return x[1]; }));
|
|
148
148
|
}
|
|
149
149
|
// @ts-ignore
|
|
150
150
|
/** @internal */ [_Symbol.iterator]() {
|
|
@@ -181,6 +181,26 @@ function normalizeArgs(name, value, filename) {
|
|
|
181
181
|
}
|
|
182
182
|
return ["" + name, "" + value];
|
|
183
183
|
}
|
|
184
|
+
// Polyfill for Element.prototype.matches,
|
|
185
|
+
// tries native, then vendor prefixes, then querySelectorAll fallback.
|
|
186
|
+
function matches(elm, selectors) {
|
|
187
|
+
let proto = (typeof Element !== "undefined" && Element && Element.prototype);
|
|
188
|
+
if (proto && !proto.matches) {
|
|
189
|
+
proto.matches = // @ts-ignore
|
|
190
|
+
proto.matchesSelector || // @ts-ignore
|
|
191
|
+
proto.mozMatchesSelector || // @ts-ignore
|
|
192
|
+
proto.msMatchesSelector || // @ts-ignore
|
|
193
|
+
proto.oMatchesSelector || // @ts-ignore
|
|
194
|
+
proto.webkitMatchesSelector || // @ts-ignore
|
|
195
|
+
function (s) {
|
|
196
|
+
let matches = (this.ownerDocument || this.document).querySelectorAll(s);
|
|
197
|
+
let i = matches.length;
|
|
198
|
+
while (--i >= 0 && matches.item(i) !== this) { }
|
|
199
|
+
return i > -1;
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
return proto ? proto.matches.call(elm, selectors) : false;
|
|
203
|
+
}
|
|
184
204
|
function isFormData(value) {
|
|
185
205
|
return isPolyfillType("FormData", value) || isExternalFormData(value);
|
|
186
206
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { setState, isSequence, _Symbol, isPolyfillType, checkArgsLength, isObjectType } from '../utils.js';
|
|
1
|
+
import { setState, isSequence, makeIterator, _Symbol, isPolyfillType, checkArgsLength, isObjectType } from '../utils.js';
|
|
2
2
|
|
|
3
3
|
class URLSearchParamsP {
|
|
4
4
|
constructor(init) {
|
|
@@ -158,13 +158,13 @@ class URLSearchParamsP {
|
|
|
158
158
|
}
|
|
159
159
|
}
|
|
160
160
|
entries() {
|
|
161
|
-
return state(this).array.map(function (x) { return [x[0], x[1]]; })
|
|
161
|
+
return makeIterator(state(this).array.map(function (x) { return [x[0], x[1]]; }));
|
|
162
162
|
}
|
|
163
163
|
keys() {
|
|
164
|
-
return state(this).array.map(function (x) { return x[0]; })
|
|
164
|
+
return makeIterator(state(this).array.map(function (x) { return x[0]; }));
|
|
165
165
|
}
|
|
166
166
|
values() {
|
|
167
|
-
return state(this).array.map(function (x) { return x[1]; })
|
|
167
|
+
return makeIterator(state(this).array.map(function (x) { return x[1]; }));
|
|
168
168
|
}
|
|
169
169
|
// @ts-ignore
|
|
170
170
|
/** @internal */ [_Symbol.iterator]() {
|
package/dist/esm/utils.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
// Safe fallback for Symbol.iterator and Symbol.toStringTag — uses native Symbol when available, string keys otherwise.
|
|
1
2
|
const _Symbol = {
|
|
2
|
-
iterator: ((typeof Symbol === "function"
|
|
3
|
-
toStringTag: ((typeof Symbol === "function"
|
|
3
|
+
iterator: ((typeof Symbol === "function" && Symbol.iterator) || "Symbol(Symbol.iterator)"),
|
|
4
|
+
toStringTag: ((typeof Symbol === "function" && Symbol.toStringTag) || "Symbol(Symbol.toStringTag)"),
|
|
4
5
|
};
|
|
5
6
|
class DOMExceptionP extends Error {
|
|
6
7
|
constructor(message, name) {
|
|
@@ -51,10 +52,23 @@ function isSequence(value) {
|
|
|
51
52
|
&& Symbol.iterator in value
|
|
52
53
|
&& typeof value[Symbol.iterator] === "function");
|
|
53
54
|
}
|
|
55
|
+
function makeIterator(array) {
|
|
56
|
+
let index = 0;
|
|
57
|
+
let iterator = {
|
|
58
|
+
next: function () {
|
|
59
|
+
if (index < array.length) {
|
|
60
|
+
return { value: array[index++], done: false };
|
|
61
|
+
}
|
|
62
|
+
return { value: undefined, done: true };
|
|
63
|
+
},
|
|
64
|
+
[_Symbol.iterator]: function () { return iterator; },
|
|
65
|
+
};
|
|
66
|
+
return iterator;
|
|
67
|
+
}
|
|
54
68
|
function checkArgsLength(actual, expect, className, funcName) {
|
|
55
69
|
if (actual < expect) {
|
|
56
70
|
throw new TypeError(`Failed to ${funcName ? ("execute '" + funcName + "' on") : "construct"} '${className}': ${expect} argument${expect > 1 ? "s" : ""} required, but only ${actual} present.`);
|
|
57
71
|
}
|
|
58
72
|
}
|
|
59
73
|
|
|
60
|
-
export { DOMExceptionE as DOMException, DOMExceptionP, _Symbol, checkArgsLength, className, isObjectType, isPolyfillType, isSequence, setState };
|
|
74
|
+
export { DOMExceptionE as DOMException, DOMExceptionP, _Symbol, checkArgsLength, className, isObjectType, isPolyfillType, isSequence, makeIterator, setState };
|