@sproutboat/runtime 0.15.0 → 0.17.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/CHANGELOG.md +70 -0
- package/README.md +6 -0
- package/WEB_STREAMS.md +37 -0
- package/WEB_STREAMS_LICENSE +22 -0
- package/package.json +1 -1
- package/src/asset-rules.test.js +125 -0
- package/src/egress.test.ts +248 -5
- package/src/gen-streams.ts +34 -0
- package/src/native-fetch-prelude.js +3058 -70
- package/src/streams-entry.js +19 -0
- package/src/transport-broker.js +12 -0
- package/src/transport-embedded.js +403 -71
- package/test/native-base64.ts +89 -0
- package/test/native-bodies.ts +136 -0
- package/test/native-errors.ts +101 -0
- package/test/native-events.ts +102 -0
- package/test/native-iterators.ts +6 -1
- package/test/native-json.ts +102 -0
- package/test/native-model-resolver.ts +100 -0
- package/test/native-raw-body.ts +118 -0
- package/test/native-request.ts +101 -0
- package/test/native-response-defaults.ts +98 -0
- package/test/native-streaming.ts +117 -0
- package/test/native-streams.ts +107 -0
- package/test/native-timers.ts +89 -0
- package/test/native-url.ts +145 -0
- package/test/native-waituntil.ts +92 -0
- package/test/native-web-apis.ts +110 -0
|
@@ -1,3 +1,2317 @@
|
|
|
1
|
+
// WEB STREAMS: generated by gen-streams.ts, do not edit.
|
|
2
|
+
/* oxlint-disable -- generated third-party implementation */
|
|
3
|
+
// web-streams-polyfill 4.3.0, MIT, copyright Mattias Buelens (see WEB_STREAMS_LICENSE)
|
|
4
|
+
function e() {}
|
|
5
|
+
function t(e) {
|
|
6
|
+
return typeof e == "object" && e !== null || typeof e == "function";
|
|
7
|
+
}
|
|
8
|
+
var r = e;
|
|
9
|
+
function o(e, t) {
|
|
10
|
+
try {
|
|
11
|
+
Object.defineProperty(e, "name", { value: t, configurable: true });
|
|
12
|
+
} catch (e) {}
|
|
13
|
+
}
|
|
14
|
+
var n = Promise;
|
|
15
|
+
var i = Promise.resolve.bind(n);
|
|
16
|
+
var a = Promise.prototype.then;
|
|
17
|
+
var s = Promise.reject.bind(n);
|
|
18
|
+
var l = i;
|
|
19
|
+
function u(e) {
|
|
20
|
+
return new n(e);
|
|
21
|
+
}
|
|
22
|
+
function c(e) {
|
|
23
|
+
return u((t) => t(e));
|
|
24
|
+
}
|
|
25
|
+
function d(e) {
|
|
26
|
+
return s(e);
|
|
27
|
+
}
|
|
28
|
+
function f(e, t, r) {
|
|
29
|
+
return a.call(e, t, r);
|
|
30
|
+
}
|
|
31
|
+
function h(e, t, o) {
|
|
32
|
+
f(f(e, t, o), undefined, r);
|
|
33
|
+
}
|
|
34
|
+
function b(e, t) {
|
|
35
|
+
h(e, t);
|
|
36
|
+
}
|
|
37
|
+
function _(e, t) {
|
|
38
|
+
h(e, undefined, t);
|
|
39
|
+
}
|
|
40
|
+
function m(e, t, r) {
|
|
41
|
+
return f(e, t, r);
|
|
42
|
+
}
|
|
43
|
+
function p(e) {
|
|
44
|
+
f(e, undefined, r);
|
|
45
|
+
}
|
|
46
|
+
var y = (e) => {
|
|
47
|
+
if (typeof queueMicrotask == "function")
|
|
48
|
+
y = queueMicrotask;
|
|
49
|
+
else {
|
|
50
|
+
const e = c(undefined);
|
|
51
|
+
y = (t) => f(e, t);
|
|
52
|
+
}
|
|
53
|
+
return y(e);
|
|
54
|
+
};
|
|
55
|
+
function S(e, t, r) {
|
|
56
|
+
if (typeof e != "function")
|
|
57
|
+
throw new TypeError("Argument is not a function");
|
|
58
|
+
return Function.prototype.apply.call(e, t, r);
|
|
59
|
+
}
|
|
60
|
+
function g(e, t, r) {
|
|
61
|
+
try {
|
|
62
|
+
return c(S(e, t, r));
|
|
63
|
+
} catch (e) {
|
|
64
|
+
return d(e);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
class v {
|
|
69
|
+
constructor() {
|
|
70
|
+
this._cursor = 0, this._size = 0, this._front = { _elements: [], _next: undefined }, this._back = this._front, this._cursor = 0, this._size = 0;
|
|
71
|
+
}
|
|
72
|
+
get length() {
|
|
73
|
+
return this._size;
|
|
74
|
+
}
|
|
75
|
+
push(e) {
|
|
76
|
+
const t = this._back;
|
|
77
|
+
let r = t;
|
|
78
|
+
t._elements.length === 16383 && (r = { _elements: [], _next: undefined }), t._elements.push(e), r !== t && (this._back = r, t._next = r), ++this._size;
|
|
79
|
+
}
|
|
80
|
+
shift() {
|
|
81
|
+
const e = this._front;
|
|
82
|
+
let t = e;
|
|
83
|
+
const r = this._cursor;
|
|
84
|
+
let o = r + 1;
|
|
85
|
+
const n = e._elements, i = n[r];
|
|
86
|
+
return o === 16384 && (t = e._next, o = 0), --this._size, this._cursor = o, e !== t && (this._front = t), n[r] = undefined, i;
|
|
87
|
+
}
|
|
88
|
+
forEach(e) {
|
|
89
|
+
let t = this._cursor, r = this._front, o = r._elements;
|
|
90
|
+
for (;!(t === o.length && r._next === undefined || t === o.length && (r = r._next, o = r._elements, t = 0, o.length === 0)); )
|
|
91
|
+
e(o[t]), ++t;
|
|
92
|
+
}
|
|
93
|
+
peek() {
|
|
94
|
+
const e = this._front, t = this._cursor;
|
|
95
|
+
return e._elements[t];
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
var w = Symbol("[[AbortSteps]]");
|
|
99
|
+
var R = Symbol("[[ErrorSteps]]");
|
|
100
|
+
var T = Symbol("[[CancelSteps]]");
|
|
101
|
+
var P = Symbol("[[PullSteps]]");
|
|
102
|
+
var C = Symbol("[[CanPullSyncSteps]]");
|
|
103
|
+
var q = Symbol("[[ReleaseSteps]]");
|
|
104
|
+
function E(e, t) {
|
|
105
|
+
e._ownerReadableStream = t, t._reader = e, t._state === "readable" ? j(e) : t._state === "closed" ? function(e) {
|
|
106
|
+
j(e), z(e);
|
|
107
|
+
}(e) : k(e, t._storedError);
|
|
108
|
+
}
|
|
109
|
+
function W(e, t) {
|
|
110
|
+
return Mr(e._ownerReadableStream, t);
|
|
111
|
+
}
|
|
112
|
+
function O(e) {
|
|
113
|
+
const t = e._ownerReadableStream;
|
|
114
|
+
t._state === "readable" ? A(e, new TypeError("Reader was released and can no longer be used to monitor the stream's closedness")) : function(e, t) {
|
|
115
|
+
k(e, t);
|
|
116
|
+
}(e, new TypeError("Reader was released and can no longer be used to monitor the stream's closedness")), t._readableStreamController[q](), t._reader = undefined, e._ownerReadableStream = undefined;
|
|
117
|
+
}
|
|
118
|
+
function B(e) {
|
|
119
|
+
return new TypeError("Cannot " + e + " a stream using a released reader");
|
|
120
|
+
}
|
|
121
|
+
function j(e) {
|
|
122
|
+
e._closedPromise = u((t, r) => {
|
|
123
|
+
e._closedPromise_resolve = t, e._closedPromise_reject = r;
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
function k(e, t) {
|
|
127
|
+
j(e), A(e, t);
|
|
128
|
+
}
|
|
129
|
+
function A(e, t) {
|
|
130
|
+
e._closedPromise_reject !== undefined && (p(e._closedPromise), e._closedPromise_reject(t), e._closedPromise_resolve = undefined, e._closedPromise_reject = undefined);
|
|
131
|
+
}
|
|
132
|
+
function z(e) {
|
|
133
|
+
e._closedPromise_resolve !== undefined && (e._closedPromise_resolve(undefined), e._closedPromise_resolve = undefined, e._closedPromise_reject = undefined);
|
|
134
|
+
}
|
|
135
|
+
var D = Number.isFinite || function(e) {
|
|
136
|
+
return typeof e == "number" && isFinite(e);
|
|
137
|
+
};
|
|
138
|
+
var F = Math.trunc || function(e) {
|
|
139
|
+
return e < 0 ? Math.ceil(e) : Math.floor(e);
|
|
140
|
+
};
|
|
141
|
+
function L(e, t) {
|
|
142
|
+
if (e !== undefined && (typeof (r = e) != "object" && typeof r != "function"))
|
|
143
|
+
throw new TypeError(`${t} is not an object.`);
|
|
144
|
+
var r;
|
|
145
|
+
}
|
|
146
|
+
function I(e, t) {
|
|
147
|
+
if (typeof e != "function")
|
|
148
|
+
throw new TypeError(`${t} is not a function.`);
|
|
149
|
+
}
|
|
150
|
+
function $(e, t) {
|
|
151
|
+
if (!function(e) {
|
|
152
|
+
return typeof e == "object" && e !== null || typeof e == "function";
|
|
153
|
+
}(e))
|
|
154
|
+
throw new TypeError(`${t} is not an object.`);
|
|
155
|
+
}
|
|
156
|
+
function M(e, t, r) {
|
|
157
|
+
if (e === undefined)
|
|
158
|
+
throw new TypeError(`Parameter ${t} is required in '${r}'.`);
|
|
159
|
+
}
|
|
160
|
+
function Y(e, t, r) {
|
|
161
|
+
if (e === undefined)
|
|
162
|
+
throw new TypeError(`${t} is required in '${r}'.`);
|
|
163
|
+
}
|
|
164
|
+
function x(e) {
|
|
165
|
+
return Number(e);
|
|
166
|
+
}
|
|
167
|
+
function Q(e) {
|
|
168
|
+
return e === 0 ? 0 : e;
|
|
169
|
+
}
|
|
170
|
+
function N(e, t) {
|
|
171
|
+
const r = Number.MAX_SAFE_INTEGER;
|
|
172
|
+
let o = Number(e);
|
|
173
|
+
if (o = Q(o), !D(o))
|
|
174
|
+
throw new TypeError(`${t} is not a finite number`);
|
|
175
|
+
if (o = function(e) {
|
|
176
|
+
return Q(F(e));
|
|
177
|
+
}(o), o < 0 || o > r)
|
|
178
|
+
throw new TypeError(`${t} is outside the accepted range of 0 to ${r}, inclusive`);
|
|
179
|
+
return D(o) && o !== 0 ? o : 0;
|
|
180
|
+
}
|
|
181
|
+
function H(e, t) {
|
|
182
|
+
if (!Ir(e))
|
|
183
|
+
throw new TypeError(`${t} is not a ReadableStream.`);
|
|
184
|
+
}
|
|
185
|
+
function V(e) {
|
|
186
|
+
return new ReadableStreamDefaultReader(e);
|
|
187
|
+
}
|
|
188
|
+
function U(e, t) {
|
|
189
|
+
e._reader._readRequests.push(t);
|
|
190
|
+
}
|
|
191
|
+
function G(e, t, r) {
|
|
192
|
+
const o = e._reader._readRequests.shift();
|
|
193
|
+
r ? o._closeSteps() : o._chunkSteps(t);
|
|
194
|
+
}
|
|
195
|
+
function X(e) {
|
|
196
|
+
return e._reader._readRequests.length;
|
|
197
|
+
}
|
|
198
|
+
function J(e) {
|
|
199
|
+
const t = e._reader;
|
|
200
|
+
return t !== undefined && !!ee(t);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
class ReadableStreamDefaultReader {
|
|
204
|
+
constructor(e) {
|
|
205
|
+
if (M(e, 1, "ReadableStreamDefaultReader"), H(e, "First parameter"), $r(e))
|
|
206
|
+
throw new TypeError("This stream has already been locked for exclusive reading by another reader");
|
|
207
|
+
E(this, e), this._readRequests = new v;
|
|
208
|
+
}
|
|
209
|
+
get closed() {
|
|
210
|
+
return ee(this) ? this._closedPromise : d(ne("closed"));
|
|
211
|
+
}
|
|
212
|
+
cancel(e = undefined) {
|
|
213
|
+
return ee(this) ? this._ownerReadableStream === undefined ? d(B("cancel")) : W(this, e) : d(ne("cancel"));
|
|
214
|
+
}
|
|
215
|
+
read() {
|
|
216
|
+
if (!ee(this))
|
|
217
|
+
return d(ne("read"));
|
|
218
|
+
if (this._ownerReadableStream === undefined)
|
|
219
|
+
return d(B("read from"));
|
|
220
|
+
const e = re(this) ? new Z : new K;
|
|
221
|
+
return te(this, e), e._promise;
|
|
222
|
+
}
|
|
223
|
+
releaseLock() {
|
|
224
|
+
if (!ee(this))
|
|
225
|
+
throw ne("releaseLock");
|
|
226
|
+
this._ownerReadableStream !== undefined && function(e) {
|
|
227
|
+
O(e);
|
|
228
|
+
const t = new TypeError("Reader was released");
|
|
229
|
+
oe(e, t);
|
|
230
|
+
}(this);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
Object.defineProperties(ReadableStreamDefaultReader.prototype, { cancel: { enumerable: true }, read: { enumerable: true }, releaseLock: { enumerable: true }, closed: { enumerable: true } }), o(ReadableStreamDefaultReader.prototype.cancel, "cancel"), o(ReadableStreamDefaultReader.prototype.read, "read"), o(ReadableStreamDefaultReader.prototype.releaseLock, "releaseLock"), typeof Symbol.toStringTag == "symbol" && Object.defineProperty(ReadableStreamDefaultReader.prototype, Symbol.toStringTag, { value: "ReadableStreamDefaultReader", configurable: true });
|
|
234
|
+
|
|
235
|
+
class K {
|
|
236
|
+
constructor() {
|
|
237
|
+
this._promise = u((e, t) => {
|
|
238
|
+
this._resolvePromise = e, this._rejectPromise = t;
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
_chunkSteps(e) {
|
|
242
|
+
this._resolvePromise({ value: e, done: false });
|
|
243
|
+
}
|
|
244
|
+
_closeSteps() {
|
|
245
|
+
this._resolvePromise({ value: undefined, done: true });
|
|
246
|
+
}
|
|
247
|
+
_errorSteps(e) {
|
|
248
|
+
this._rejectPromise(e);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
class Z {
|
|
253
|
+
constructor() {
|
|
254
|
+
this._promise = undefined;
|
|
255
|
+
}
|
|
256
|
+
_chunkSteps(e) {
|
|
257
|
+
this._promise = l({ value: e, done: false });
|
|
258
|
+
}
|
|
259
|
+
_closeSteps() {
|
|
260
|
+
this._promise = l({ value: undefined, done: true });
|
|
261
|
+
}
|
|
262
|
+
_errorSteps(e) {
|
|
263
|
+
this._promise = d(e);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
function ee(e) {
|
|
267
|
+
return !!t(e) && (!!Object.prototype.hasOwnProperty.call(e, "_readRequests") && e instanceof ReadableStreamDefaultReader);
|
|
268
|
+
}
|
|
269
|
+
function te(e, t) {
|
|
270
|
+
const r = e._ownerReadableStream;
|
|
271
|
+
r._disturbed = true, r._state === "closed" ? t._closeSteps() : r._state === "errored" ? t._errorSteps(r._storedError) : r._readableStreamController[P](t);
|
|
272
|
+
}
|
|
273
|
+
function re(e) {
|
|
274
|
+
const t = e._ownerReadableStream;
|
|
275
|
+
return t._state === "closed" || (t._state === "errored" || t._readableStreamController[C]());
|
|
276
|
+
}
|
|
277
|
+
function oe(e, t) {
|
|
278
|
+
const r = e._readRequests;
|
|
279
|
+
e._readRequests = new v, r.forEach((e) => {
|
|
280
|
+
e._errorSteps(t);
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
function ne(e) {
|
|
284
|
+
return new TypeError(`ReadableStreamDefaultReader.prototype.${e} can only be used on a ReadableStreamDefaultReader`);
|
|
285
|
+
}
|
|
286
|
+
var ie;
|
|
287
|
+
var ae;
|
|
288
|
+
var se;
|
|
289
|
+
function le(e) {
|
|
290
|
+
return e.slice();
|
|
291
|
+
}
|
|
292
|
+
function ue(e, t, r, o, n) {
|
|
293
|
+
new Uint8Array(e).set(new Uint8Array(r, o, n), t);
|
|
294
|
+
}
|
|
295
|
+
var ce = (e) => (ce = typeof e.transfer == "function" ? (e) => e.transfer() : typeof structuredClone == "function" ? (e) => structuredClone(e, { transfer: [e] }) : (e) => e, ce(e));
|
|
296
|
+
var de = (e) => (de = typeof e.detached == "boolean" ? (e) => e.detached : (e) => e.byteLength === 0, de(e));
|
|
297
|
+
function fe(e, t, r) {
|
|
298
|
+
if (e.slice)
|
|
299
|
+
return e.slice(t, r);
|
|
300
|
+
const o = r - t, n = new ArrayBuffer(o);
|
|
301
|
+
return ue(n, 0, e, t, o), n;
|
|
302
|
+
}
|
|
303
|
+
function he(e, t) {
|
|
304
|
+
const r = e[t];
|
|
305
|
+
if (r != null) {
|
|
306
|
+
if (typeof r != "function")
|
|
307
|
+
throw new TypeError(`${String(t)} is not a function`);
|
|
308
|
+
return r;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
function be(e) {
|
|
312
|
+
try {
|
|
313
|
+
const { done: t, value: r } = e;
|
|
314
|
+
return f(l(r), (e) => ({ done: t, value: e }));
|
|
315
|
+
} catch (e) {
|
|
316
|
+
return d(e);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
var _e = (se = (ie = Symbol.asyncIterator) !== null && ie !== undefined ? ie : (ae = Symbol.for) === null || ae === undefined ? undefined : ae.call(Symbol, "Symbol.asyncIterator")) !== null && se !== undefined ? se : "@@asyncIterator";
|
|
320
|
+
function me(e, r = "sync", o) {
|
|
321
|
+
if (o === undefined)
|
|
322
|
+
if (r === "async") {
|
|
323
|
+
if ((o = he(e, _e)) === undefined) {
|
|
324
|
+
return function(e) {
|
|
325
|
+
const r = { next() {
|
|
326
|
+
let t;
|
|
327
|
+
try {
|
|
328
|
+
t = pe(e);
|
|
329
|
+
} catch (e) {
|
|
330
|
+
return d(e);
|
|
331
|
+
}
|
|
332
|
+
return be(t);
|
|
333
|
+
}, return(r) {
|
|
334
|
+
let o;
|
|
335
|
+
try {
|
|
336
|
+
const t = he(e.iterator, "return");
|
|
337
|
+
if (t === undefined)
|
|
338
|
+
return c({ done: true, value: r });
|
|
339
|
+
o = S(t, e.iterator, [r]);
|
|
340
|
+
} catch (e) {
|
|
341
|
+
return d(e);
|
|
342
|
+
}
|
|
343
|
+
return t(o) ? be(o) : d(new TypeError("The iterator.return() method must return an object"));
|
|
344
|
+
} };
|
|
345
|
+
return { iterator: r, nextMethod: r.next, done: false };
|
|
346
|
+
}(me(e, "sync", he(e, Symbol.iterator)));
|
|
347
|
+
}
|
|
348
|
+
} else
|
|
349
|
+
o = he(e, Symbol.iterator);
|
|
350
|
+
if (o === undefined)
|
|
351
|
+
throw new TypeError("The object is not iterable");
|
|
352
|
+
const n = S(o, e, []);
|
|
353
|
+
if (!t(n))
|
|
354
|
+
throw new TypeError("The iterator method must return an object");
|
|
355
|
+
return { iterator: n, nextMethod: n.next, done: false };
|
|
356
|
+
}
|
|
357
|
+
function pe(e) {
|
|
358
|
+
const r = S(e.nextMethod, e.iterator, []);
|
|
359
|
+
if (!t(r))
|
|
360
|
+
throw new TypeError("The iterator.next() method must return an object");
|
|
361
|
+
return r;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
class ye {
|
|
365
|
+
constructor(e, t) {
|
|
366
|
+
this._ongoingPromise = undefined, this._isFinished = false, this._reader = e, this._preventCancel = t;
|
|
367
|
+
}
|
|
368
|
+
next() {
|
|
369
|
+
const e = () => this._nextSteps();
|
|
370
|
+
return this._ongoingPromise = this._ongoingPromise ? m(this._ongoingPromise, e, e) : e(), this._ongoingPromise;
|
|
371
|
+
}
|
|
372
|
+
return(e) {
|
|
373
|
+
const t = () => this._returnSteps(e);
|
|
374
|
+
return this._ongoingPromise = this._ongoingPromise ? m(this._ongoingPromise, t, t) : t(), this._ongoingPromise;
|
|
375
|
+
}
|
|
376
|
+
_nextSteps() {
|
|
377
|
+
if (this._isFinished)
|
|
378
|
+
return Promise.resolve({ value: undefined, done: true });
|
|
379
|
+
const e = this._reader, t = new Se(this);
|
|
380
|
+
return te(e, t), t._promise;
|
|
381
|
+
}
|
|
382
|
+
_returnSteps(e) {
|
|
383
|
+
if (this._isFinished)
|
|
384
|
+
return Promise.resolve({ value: e, done: true });
|
|
385
|
+
this._isFinished = true;
|
|
386
|
+
const t = this._reader;
|
|
387
|
+
if (!this._preventCancel) {
|
|
388
|
+
const r = W(t, e);
|
|
389
|
+
return O(t), m(r, () => ({ value: e, done: true }));
|
|
390
|
+
}
|
|
391
|
+
return O(t), c({ value: e, done: true });
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
class Se {
|
|
396
|
+
constructor(e) {
|
|
397
|
+
this._iterator = e, this._promise = u((e, t) => {
|
|
398
|
+
this._resolvePromise = e, this._rejectPromise = t;
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
_chunkSteps(e) {
|
|
402
|
+
this._iterator._ongoingPromise = undefined, y(() => this._resolvePromise({ value: e, done: false }));
|
|
403
|
+
}
|
|
404
|
+
_closeSteps() {
|
|
405
|
+
const e = this._iterator;
|
|
406
|
+
e._ongoingPromise = undefined, e._isFinished = true, O(e._reader), this._resolvePromise({ value: undefined, done: true });
|
|
407
|
+
}
|
|
408
|
+
_errorSteps(e) {
|
|
409
|
+
const t = this._iterator;
|
|
410
|
+
t._ongoingPromise = undefined, t._isFinished = true, O(t._reader), this._rejectPromise(e);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
var ge = { next() {
|
|
414
|
+
return ve(this) ? this._asyncIteratorImpl.next() : d(we("next"));
|
|
415
|
+
}, return(e) {
|
|
416
|
+
return ve(this) ? this._asyncIteratorImpl.return(e) : d(we("return"));
|
|
417
|
+
}, [_e]() {
|
|
418
|
+
return this;
|
|
419
|
+
} };
|
|
420
|
+
function ve(e) {
|
|
421
|
+
if (!t(e))
|
|
422
|
+
return false;
|
|
423
|
+
if (!Object.prototype.hasOwnProperty.call(e, "_asyncIteratorImpl"))
|
|
424
|
+
return false;
|
|
425
|
+
try {
|
|
426
|
+
return e._asyncIteratorImpl instanceof ye;
|
|
427
|
+
} catch (e) {
|
|
428
|
+
return false;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
function we(e) {
|
|
432
|
+
return new TypeError(`ReadableStreamAsyncIterator.${e} can only be used on a ReadableSteamAsyncIterator`);
|
|
433
|
+
}
|
|
434
|
+
Object.defineProperty(ge, _e, { enumerable: false });
|
|
435
|
+
var Re = Number.isNaN || function(e) {
|
|
436
|
+
return e != e;
|
|
437
|
+
};
|
|
438
|
+
function Te(e) {
|
|
439
|
+
const t = fe(e.buffer, e.byteOffset, e.byteOffset + e.byteLength);
|
|
440
|
+
return new Uint8Array(t);
|
|
441
|
+
}
|
|
442
|
+
function Pe(e) {
|
|
443
|
+
const t = e._queue.shift();
|
|
444
|
+
return e._queueTotalSize -= t.size, e._queueTotalSize < 0 && (e._queueTotalSize = 0), t.value;
|
|
445
|
+
}
|
|
446
|
+
function Ce(e, t, r) {
|
|
447
|
+
if (typeof (o = r) != "number" || Re(o) || o < 0 || r === 1 / 0)
|
|
448
|
+
throw new RangeError("Size must be a finite, non-NaN, non-negative number.");
|
|
449
|
+
var o;
|
|
450
|
+
e._queue.push({ value: t, size: r }), e._queueTotalSize += r;
|
|
451
|
+
}
|
|
452
|
+
function qe(e) {
|
|
453
|
+
e._queue = new v, e._queueTotalSize = 0;
|
|
454
|
+
}
|
|
455
|
+
function Ee(e) {
|
|
456
|
+
return e === DataView;
|
|
457
|
+
}
|
|
458
|
+
function We(e) {
|
|
459
|
+
return Ee(e) ? 1 : e.BYTES_PER_ELEMENT;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
class ReadableStreamBYOBRequest {
|
|
463
|
+
constructor() {
|
|
464
|
+
throw new TypeError("Illegal constructor");
|
|
465
|
+
}
|
|
466
|
+
get view() {
|
|
467
|
+
if (!Be(this))
|
|
468
|
+
throw ot("view");
|
|
469
|
+
return this._view;
|
|
470
|
+
}
|
|
471
|
+
respond(e) {
|
|
472
|
+
if (!Be(this))
|
|
473
|
+
throw ot("respond");
|
|
474
|
+
if (M(e, 1, "respond"), e = N(e, "First parameter"), this._associatedReadableByteStreamController === undefined)
|
|
475
|
+
throw new TypeError("This BYOB request has been invalidated");
|
|
476
|
+
if (de(this._view.buffer))
|
|
477
|
+
throw new TypeError("The BYOB request's buffer has been detached and so cannot be used as a response");
|
|
478
|
+
et(this._associatedReadableByteStreamController, e);
|
|
479
|
+
}
|
|
480
|
+
respondWithNewView(e) {
|
|
481
|
+
if (!Be(this))
|
|
482
|
+
throw ot("respondWithNewView");
|
|
483
|
+
if (M(e, 1, "respondWithNewView"), !ArrayBuffer.isView(e))
|
|
484
|
+
throw new TypeError("You can only respond with array buffer views");
|
|
485
|
+
if (this._associatedReadableByteStreamController === undefined)
|
|
486
|
+
throw new TypeError("This BYOB request has been invalidated");
|
|
487
|
+
if (de(e.buffer))
|
|
488
|
+
throw new TypeError("The given view's buffer has been detached and so cannot be used as a response");
|
|
489
|
+
tt(this._associatedReadableByteStreamController, e);
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
Object.defineProperties(ReadableStreamBYOBRequest.prototype, { respond: { enumerable: true }, respondWithNewView: { enumerable: true }, view: { enumerable: true } }), o(ReadableStreamBYOBRequest.prototype.respond, "respond"), o(ReadableStreamBYOBRequest.prototype.respondWithNewView, "respondWithNewView"), typeof Symbol.toStringTag == "symbol" && Object.defineProperty(ReadableStreamBYOBRequest.prototype, Symbol.toStringTag, { value: "ReadableStreamBYOBRequest", configurable: true });
|
|
493
|
+
|
|
494
|
+
class ReadableByteStreamController {
|
|
495
|
+
constructor() {
|
|
496
|
+
throw new TypeError("Illegal constructor");
|
|
497
|
+
}
|
|
498
|
+
get byobRequest() {
|
|
499
|
+
if (!Oe(this))
|
|
500
|
+
throw nt("byobRequest");
|
|
501
|
+
return Ke(this);
|
|
502
|
+
}
|
|
503
|
+
get desiredSize() {
|
|
504
|
+
if (!Oe(this))
|
|
505
|
+
throw nt("desiredSize");
|
|
506
|
+
return Ze(this);
|
|
507
|
+
}
|
|
508
|
+
close() {
|
|
509
|
+
if (!Oe(this))
|
|
510
|
+
throw nt("close");
|
|
511
|
+
if (this._closeRequested)
|
|
512
|
+
throw new TypeError("The stream has already been closed; do not close it again!");
|
|
513
|
+
const e = this._controlledReadableByteStream._state;
|
|
514
|
+
if (e !== "readable")
|
|
515
|
+
throw new TypeError(`The stream (in ${e} state) is not in the readable state and cannot be closed`);
|
|
516
|
+
Ue(this);
|
|
517
|
+
}
|
|
518
|
+
enqueue(e) {
|
|
519
|
+
if (!Oe(this))
|
|
520
|
+
throw nt("enqueue");
|
|
521
|
+
if (M(e, 1, "enqueue"), !ArrayBuffer.isView(e))
|
|
522
|
+
throw new TypeError("chunk must be an array buffer view");
|
|
523
|
+
if (e.byteLength === 0)
|
|
524
|
+
throw new TypeError("chunk must have non-zero byteLength");
|
|
525
|
+
if (e.buffer.byteLength === 0)
|
|
526
|
+
throw new TypeError("chunk's buffer must have non-zero byteLength");
|
|
527
|
+
if (this._closeRequested)
|
|
528
|
+
throw new TypeError("stream is closed or draining");
|
|
529
|
+
const t = this._controlledReadableByteStream._state;
|
|
530
|
+
if (t !== "readable")
|
|
531
|
+
throw new TypeError(`The stream (in ${t} state) is not in the readable state and cannot be enqueued to`);
|
|
532
|
+
Ge(this, e);
|
|
533
|
+
}
|
|
534
|
+
error(e = undefined) {
|
|
535
|
+
if (!Oe(this))
|
|
536
|
+
throw nt("error");
|
|
537
|
+
Xe(this, e);
|
|
538
|
+
}
|
|
539
|
+
[T](e) {
|
|
540
|
+
ke(this), qe(this);
|
|
541
|
+
const t = this._cancelAlgorithm(e);
|
|
542
|
+
return Ve(this), t;
|
|
543
|
+
}
|
|
544
|
+
[P](e) {
|
|
545
|
+
const t = this._controlledReadableByteStream;
|
|
546
|
+
if (this._queueTotalSize > 0)
|
|
547
|
+
return void Je(this, e);
|
|
548
|
+
const r = this._autoAllocateChunkSize;
|
|
549
|
+
if (r !== undefined) {
|
|
550
|
+
let t;
|
|
551
|
+
try {
|
|
552
|
+
t = new ArrayBuffer(r);
|
|
553
|
+
} catch (t) {
|
|
554
|
+
return void e._errorSteps(t);
|
|
555
|
+
}
|
|
556
|
+
const o = { buffer: t, bufferByteLength: r, byteOffset: 0, byteLength: r, bytesFilled: 0, minimumFill: 1, elementSize: 1, viewConstructor: Uint8Array, readerType: "default" };
|
|
557
|
+
this._pendingPullIntos.push(o);
|
|
558
|
+
}
|
|
559
|
+
U(t, e), je(this);
|
|
560
|
+
}
|
|
561
|
+
[C]() {
|
|
562
|
+
return this._queueTotalSize > 0;
|
|
563
|
+
}
|
|
564
|
+
[q]() {
|
|
565
|
+
if (this._pendingPullIntos.length > 0) {
|
|
566
|
+
const e = this._pendingPullIntos.peek();
|
|
567
|
+
e.readerType = "none", this._pendingPullIntos = new v, this._pendingPullIntos.push(e);
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
function Oe(e) {
|
|
572
|
+
return !!t(e) && (!!Object.prototype.hasOwnProperty.call(e, "_controlledReadableByteStream") && e instanceof ReadableByteStreamController);
|
|
573
|
+
}
|
|
574
|
+
function Be(e) {
|
|
575
|
+
return !!t(e) && (!!Object.prototype.hasOwnProperty.call(e, "_associatedReadableByteStreamController") && e instanceof ReadableStreamBYOBRequest);
|
|
576
|
+
}
|
|
577
|
+
function je(e) {
|
|
578
|
+
const t = function(e) {
|
|
579
|
+
const t = e._controlledReadableByteStream;
|
|
580
|
+
if (t._state !== "readable")
|
|
581
|
+
return false;
|
|
582
|
+
if (e._closeRequested)
|
|
583
|
+
return false;
|
|
584
|
+
if (!e._started)
|
|
585
|
+
return false;
|
|
586
|
+
if (J(t) && X(t) > 0)
|
|
587
|
+
return true;
|
|
588
|
+
if (ut(t) && lt(t) > 0)
|
|
589
|
+
return true;
|
|
590
|
+
const r = Ze(e);
|
|
591
|
+
if (r > 0)
|
|
592
|
+
return true;
|
|
593
|
+
return false;
|
|
594
|
+
}(e);
|
|
595
|
+
if (!t)
|
|
596
|
+
return;
|
|
597
|
+
if (e._pulling)
|
|
598
|
+
return void (e._pullAgain = true);
|
|
599
|
+
e._pulling = true;
|
|
600
|
+
h(e._pullAlgorithm(), () => (e._pulling = false, e._pullAgain && (e._pullAgain = false, je(e)), null), (t) => (Xe(e, t), null));
|
|
601
|
+
}
|
|
602
|
+
function ke(e) {
|
|
603
|
+
xe(e), e._pendingPullIntos = new v;
|
|
604
|
+
}
|
|
605
|
+
function Ae(e, t) {
|
|
606
|
+
let r = false;
|
|
607
|
+
e._state === "closed" && (r = true);
|
|
608
|
+
const o = De(t);
|
|
609
|
+
t.readerType === "default" ? G(e, o, r) : function(e, t, r) {
|
|
610
|
+
const o = e._reader, n = o._readIntoRequests.shift();
|
|
611
|
+
r ? n._closeSteps(t) : n._chunkSteps(t);
|
|
612
|
+
}(e, o, r);
|
|
613
|
+
}
|
|
614
|
+
function ze(e, t) {
|
|
615
|
+
for (let r = 0;r < t.length; ++r)
|
|
616
|
+
Ae(e, t[r]);
|
|
617
|
+
}
|
|
618
|
+
function De(e) {
|
|
619
|
+
const { bytesFilled: t, elementSize: r } = e;
|
|
620
|
+
return new e.viewConstructor(e.buffer, e.byteOffset, t / r);
|
|
621
|
+
}
|
|
622
|
+
function Fe(e, t, r, o) {
|
|
623
|
+
e._queue.push({ buffer: t, byteOffset: r, byteLength: o }), e._queueTotalSize += o;
|
|
624
|
+
}
|
|
625
|
+
function Le(e, t, r, o) {
|
|
626
|
+
let n;
|
|
627
|
+
try {
|
|
628
|
+
n = fe(t, r, r + o);
|
|
629
|
+
} catch (t) {
|
|
630
|
+
throw Xe(e, t), t;
|
|
631
|
+
}
|
|
632
|
+
Fe(e, n, 0, o);
|
|
633
|
+
}
|
|
634
|
+
function Ie(e, t) {
|
|
635
|
+
t.bytesFilled > 0 && Le(e, t.buffer, t.byteOffset, t.bytesFilled), He(e);
|
|
636
|
+
}
|
|
637
|
+
function $e(e, t) {
|
|
638
|
+
const r = Math.min(e._queueTotalSize, t.byteLength - t.bytesFilled), o = t.bytesFilled + r;
|
|
639
|
+
let n = r, i = false;
|
|
640
|
+
const a = o - o % t.elementSize;
|
|
641
|
+
a >= t.minimumFill && (n = a - t.bytesFilled, i = true);
|
|
642
|
+
const s = e._queue;
|
|
643
|
+
for (;n > 0; ) {
|
|
644
|
+
const r = s.peek(), o = Math.min(n, r.byteLength), i = t.byteOffset + t.bytesFilled;
|
|
645
|
+
ue(t.buffer, i, r.buffer, r.byteOffset, o), r.byteLength === o ? s.shift() : (r.byteOffset += o, r.byteLength -= o), e._queueTotalSize -= o, Me(e, o, t), n -= o;
|
|
646
|
+
}
|
|
647
|
+
return i;
|
|
648
|
+
}
|
|
649
|
+
function Me(e, t, r) {
|
|
650
|
+
r.bytesFilled += t;
|
|
651
|
+
}
|
|
652
|
+
function Ye(e) {
|
|
653
|
+
e._queueTotalSize === 0 && e._closeRequested ? (Ve(e), Yr(e._controlledReadableByteStream)) : je(e);
|
|
654
|
+
}
|
|
655
|
+
function xe(e) {
|
|
656
|
+
e._byobRequest !== null && (e._byobRequest._associatedReadableByteStreamController = undefined, e._byobRequest._view = null, e._byobRequest = null);
|
|
657
|
+
}
|
|
658
|
+
function Qe(e) {
|
|
659
|
+
const t = [];
|
|
660
|
+
for (;e._pendingPullIntos.length > 0 && e._queueTotalSize !== 0; ) {
|
|
661
|
+
const r = e._pendingPullIntos.peek();
|
|
662
|
+
$e(e, r) && (He(e), t.push(r));
|
|
663
|
+
}
|
|
664
|
+
return t;
|
|
665
|
+
}
|
|
666
|
+
function Ne(e, t) {
|
|
667
|
+
const r = e._pendingPullIntos.peek();
|
|
668
|
+
xe(e);
|
|
669
|
+
e._controlledReadableByteStream._state === "closed" ? function(e, t) {
|
|
670
|
+
t.readerType === "none" && He(e);
|
|
671
|
+
const r = e._controlledReadableByteStream;
|
|
672
|
+
if (ut(r)) {
|
|
673
|
+
const t = [];
|
|
674
|
+
for (;t.length < lt(r); )
|
|
675
|
+
t.push(He(e));
|
|
676
|
+
ze(r, t);
|
|
677
|
+
}
|
|
678
|
+
}(e, r) : function(e, t, r) {
|
|
679
|
+
if (Me(0, t, r), r.readerType === "none") {
|
|
680
|
+
Ie(e, r);
|
|
681
|
+
const t = Qe(e);
|
|
682
|
+
return void ze(e._controlledReadableByteStream, t);
|
|
683
|
+
}
|
|
684
|
+
if (r.bytesFilled < r.minimumFill)
|
|
685
|
+
return;
|
|
686
|
+
He(e);
|
|
687
|
+
const o = r.bytesFilled % r.elementSize;
|
|
688
|
+
if (o > 0) {
|
|
689
|
+
const t = r.byteOffset + r.bytesFilled;
|
|
690
|
+
Le(e, r.buffer, t - o, o);
|
|
691
|
+
}
|
|
692
|
+
r.bytesFilled -= o;
|
|
693
|
+
const n = Qe(e);
|
|
694
|
+
Ae(e._controlledReadableByteStream, r), ze(e._controlledReadableByteStream, n);
|
|
695
|
+
}(e, t, r), je(e);
|
|
696
|
+
}
|
|
697
|
+
function He(e) {
|
|
698
|
+
return e._pendingPullIntos.shift();
|
|
699
|
+
}
|
|
700
|
+
function Ve(e) {
|
|
701
|
+
e._pullAlgorithm = undefined, e._cancelAlgorithm = undefined;
|
|
702
|
+
}
|
|
703
|
+
function Ue(e) {
|
|
704
|
+
const t = e._controlledReadableByteStream;
|
|
705
|
+
if (!e._closeRequested && t._state === "readable")
|
|
706
|
+
if (e._queueTotalSize > 0)
|
|
707
|
+
e._closeRequested = true;
|
|
708
|
+
else {
|
|
709
|
+
if (e._pendingPullIntos.length > 0) {
|
|
710
|
+
const t = e._pendingPullIntos.peek();
|
|
711
|
+
if (t.bytesFilled % t.elementSize !== 0) {
|
|
712
|
+
const t = new TypeError("Insufficient bytes to fill elements in the given buffer");
|
|
713
|
+
throw Xe(e, t), t;
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
Ve(e), Yr(t);
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
function Ge(e, t) {
|
|
720
|
+
const r = e._controlledReadableByteStream;
|
|
721
|
+
if (e._closeRequested || r._state !== "readable")
|
|
722
|
+
return;
|
|
723
|
+
const { buffer: o, byteOffset: n, byteLength: i } = t;
|
|
724
|
+
if (de(o))
|
|
725
|
+
throw new TypeError("chunk's buffer is detached and so cannot be enqueued");
|
|
726
|
+
const a = ce(o);
|
|
727
|
+
if (e._pendingPullIntos.length > 0) {
|
|
728
|
+
const t = e._pendingPullIntos.peek();
|
|
729
|
+
if (de(t.buffer))
|
|
730
|
+
throw new TypeError("The BYOB request's buffer has been detached and so cannot be filled with an enqueued chunk");
|
|
731
|
+
xe(e), t.buffer = ce(t.buffer), t.readerType === "none" && Ie(e, t);
|
|
732
|
+
}
|
|
733
|
+
if (J(r))
|
|
734
|
+
if (function(e) {
|
|
735
|
+
const t = e._controlledReadableByteStream._reader;
|
|
736
|
+
for (;t._readRequests.length > 0; ) {
|
|
737
|
+
if (e._queueTotalSize === 0)
|
|
738
|
+
return;
|
|
739
|
+
Je(e, t._readRequests.shift());
|
|
740
|
+
}
|
|
741
|
+
}(e), X(r) === 0)
|
|
742
|
+
Fe(e, a, n, i);
|
|
743
|
+
else {
|
|
744
|
+
e._pendingPullIntos.length > 0 && He(e);
|
|
745
|
+
G(r, new Uint8Array(a, n, i), false);
|
|
746
|
+
}
|
|
747
|
+
else if (ut(r)) {
|
|
748
|
+
Fe(e, a, n, i);
|
|
749
|
+
ze(r, Qe(e));
|
|
750
|
+
} else
|
|
751
|
+
Fe(e, a, n, i);
|
|
752
|
+
je(e);
|
|
753
|
+
}
|
|
754
|
+
function Xe(e, t) {
|
|
755
|
+
const r = e._controlledReadableByteStream;
|
|
756
|
+
r._state === "readable" && (ke(e), qe(e), Ve(e), xr(r, t));
|
|
757
|
+
}
|
|
758
|
+
function Je(e, t) {
|
|
759
|
+
const r = e._queue.shift();
|
|
760
|
+
e._queueTotalSize -= r.byteLength, Ye(e);
|
|
761
|
+
const o = new Uint8Array(r.buffer, r.byteOffset, r.byteLength);
|
|
762
|
+
t._chunkSteps(o);
|
|
763
|
+
}
|
|
764
|
+
function Ke(e) {
|
|
765
|
+
if (e._byobRequest === null && e._pendingPullIntos.length > 0) {
|
|
766
|
+
const t = e._pendingPullIntos.peek(), r = new Uint8Array(t.buffer, t.byteOffset + t.bytesFilled, t.byteLength - t.bytesFilled), o = Object.create(ReadableStreamBYOBRequest.prototype);
|
|
767
|
+
(function(e, t, r) {
|
|
768
|
+
e._associatedReadableByteStreamController = t, e._view = r;
|
|
769
|
+
})(o, e, r), e._byobRequest = o;
|
|
770
|
+
}
|
|
771
|
+
return e._byobRequest;
|
|
772
|
+
}
|
|
773
|
+
function Ze(e) {
|
|
774
|
+
const t = e._controlledReadableByteStream._state;
|
|
775
|
+
return t === "errored" ? null : t === "closed" ? 0 : e._strategyHWM - e._queueTotalSize;
|
|
776
|
+
}
|
|
777
|
+
function et(e, t) {
|
|
778
|
+
const r = e._pendingPullIntos.peek();
|
|
779
|
+
if (e._controlledReadableByteStream._state === "closed") {
|
|
780
|
+
if (t !== 0)
|
|
781
|
+
throw new TypeError("bytesWritten must be 0 when calling respond() on a closed stream");
|
|
782
|
+
} else {
|
|
783
|
+
if (t === 0)
|
|
784
|
+
throw new TypeError("bytesWritten must be greater than 0 when calling respond() on a readable stream");
|
|
785
|
+
if (r.bytesFilled + t > r.byteLength)
|
|
786
|
+
throw new RangeError("bytesWritten out of range");
|
|
787
|
+
}
|
|
788
|
+
r.buffer = ce(r.buffer), Ne(e, t);
|
|
789
|
+
}
|
|
790
|
+
function tt(e, t) {
|
|
791
|
+
const r = e._pendingPullIntos.peek();
|
|
792
|
+
if (e._controlledReadableByteStream._state === "closed") {
|
|
793
|
+
if (t.byteLength !== 0)
|
|
794
|
+
throw new TypeError("The view's length must be 0 when calling respondWithNewView() on a closed stream");
|
|
795
|
+
} else if (t.byteLength === 0)
|
|
796
|
+
throw new TypeError("The view's length must be greater than 0 when calling respondWithNewView() on a readable stream");
|
|
797
|
+
if (r.byteOffset + r.bytesFilled !== t.byteOffset)
|
|
798
|
+
throw new RangeError("The region specified by view does not match byobRequest");
|
|
799
|
+
if (r.bufferByteLength !== t.buffer.byteLength)
|
|
800
|
+
throw new RangeError("The buffer of view has different capacity than byobRequest");
|
|
801
|
+
if (r.bytesFilled + t.byteLength > r.byteLength)
|
|
802
|
+
throw new RangeError("The region specified by view is larger than byobRequest");
|
|
803
|
+
const o = t.byteLength;
|
|
804
|
+
r.buffer = ce(t.buffer), Ne(e, o);
|
|
805
|
+
}
|
|
806
|
+
function rt(e, t, r, o, n, i, a) {
|
|
807
|
+
t._controlledReadableByteStream = e, t._pullAgain = false, t._pulling = false, t._byobRequest = null, t._queue = t._queueTotalSize = undefined, qe(t), t._closeRequested = false, t._started = false, t._strategyHWM = i, t._pullAlgorithm = o, t._cancelAlgorithm = n, t._autoAllocateChunkSize = a, t._pendingPullIntos = new v, e._readableStreamController = t;
|
|
808
|
+
h(c(r()), () => (t._started = true, je(t), null), (e) => (Xe(t, e), null));
|
|
809
|
+
}
|
|
810
|
+
function ot(e) {
|
|
811
|
+
return new TypeError(`ReadableStreamBYOBRequest.prototype.${e} can only be used on a ReadableStreamBYOBRequest`);
|
|
812
|
+
}
|
|
813
|
+
function nt(e) {
|
|
814
|
+
return new TypeError(`ReadableByteStreamController.prototype.${e} can only be used on a ReadableByteStreamController`);
|
|
815
|
+
}
|
|
816
|
+
function it(e, t) {
|
|
817
|
+
if ((e = `${e}`) !== "byob")
|
|
818
|
+
throw new TypeError(`${t} '${e}' is not a valid enumeration value for ReadableStreamReaderMode`);
|
|
819
|
+
return e;
|
|
820
|
+
}
|
|
821
|
+
function at(e) {
|
|
822
|
+
return new ReadableStreamBYOBReader(e);
|
|
823
|
+
}
|
|
824
|
+
function st(e, t) {
|
|
825
|
+
e._reader._readIntoRequests.push(t);
|
|
826
|
+
}
|
|
827
|
+
function lt(e) {
|
|
828
|
+
return e._reader._readIntoRequests.length;
|
|
829
|
+
}
|
|
830
|
+
function ut(e) {
|
|
831
|
+
const t = e._reader;
|
|
832
|
+
return t !== undefined && !!ft(t);
|
|
833
|
+
}
|
|
834
|
+
Object.defineProperties(ReadableByteStreamController.prototype, { close: { enumerable: true }, enqueue: { enumerable: true }, error: { enumerable: true }, byobRequest: { enumerable: true }, desiredSize: { enumerable: true } }), o(ReadableByteStreamController.prototype.close, "close"), o(ReadableByteStreamController.prototype.enqueue, "enqueue"), o(ReadableByteStreamController.prototype.error, "error"), typeof Symbol.toStringTag == "symbol" && Object.defineProperty(ReadableByteStreamController.prototype, Symbol.toStringTag, { value: "ReadableByteStreamController", configurable: true });
|
|
835
|
+
|
|
836
|
+
class ReadableStreamBYOBReader {
|
|
837
|
+
constructor(e) {
|
|
838
|
+
if (M(e, 1, "ReadableStreamBYOBReader"), H(e, "First parameter"), $r(e))
|
|
839
|
+
throw new TypeError("This stream has already been locked for exclusive reading by another reader");
|
|
840
|
+
if (!Oe(e._readableStreamController))
|
|
841
|
+
throw new TypeError("Cannot construct a ReadableStreamBYOBReader for a stream not constructed with a byte source");
|
|
842
|
+
E(this, e), this._readIntoRequests = new v;
|
|
843
|
+
}
|
|
844
|
+
get closed() {
|
|
845
|
+
return ft(this) ? this._closedPromise : d(_t("closed"));
|
|
846
|
+
}
|
|
847
|
+
cancel(e = undefined) {
|
|
848
|
+
return ft(this) ? this._ownerReadableStream === undefined ? d(B("cancel")) : W(this, e) : d(_t("cancel"));
|
|
849
|
+
}
|
|
850
|
+
read(e, t = {}) {
|
|
851
|
+
if (!ft(this))
|
|
852
|
+
return d(_t("read"));
|
|
853
|
+
if (!ArrayBuffer.isView(e))
|
|
854
|
+
return d(new TypeError("view must be an array buffer view"));
|
|
855
|
+
if (e.byteLength === 0)
|
|
856
|
+
return d(new TypeError("view must have non-zero byteLength"));
|
|
857
|
+
if (e.buffer.byteLength === 0)
|
|
858
|
+
return d(new TypeError("view's buffer must have non-zero byteLength"));
|
|
859
|
+
if (de(e.buffer))
|
|
860
|
+
return d(new TypeError("view's buffer has been detached"));
|
|
861
|
+
let r;
|
|
862
|
+
try {
|
|
863
|
+
r = function(e, t) {
|
|
864
|
+
var r;
|
|
865
|
+
return L(e, t), { min: N((r = e == null ? undefined : e.min) !== null && r !== undefined ? r : 1, `${t} has member 'min' that`) };
|
|
866
|
+
}(t, "options");
|
|
867
|
+
} catch (e) {
|
|
868
|
+
return d(e);
|
|
869
|
+
}
|
|
870
|
+
const o = r.min;
|
|
871
|
+
if (o === 0)
|
|
872
|
+
return d(new TypeError("options.min must be greater than 0"));
|
|
873
|
+
if (function(e) {
|
|
874
|
+
return Ee(e.constructor);
|
|
875
|
+
}(e)) {
|
|
876
|
+
if (o > e.byteLength)
|
|
877
|
+
return d(new RangeError("options.min must be less than or equal to view's byteLength"));
|
|
878
|
+
} else if (o > e.length)
|
|
879
|
+
return d(new RangeError("options.min must be less than or equal to view's length"));
|
|
880
|
+
if (this._ownerReadableStream === undefined)
|
|
881
|
+
return d(B("read from"));
|
|
882
|
+
const n = function(e, t, r) {
|
|
883
|
+
const o = e._ownerReadableStream;
|
|
884
|
+
return o._state === "errored" || function(e, t, r) {
|
|
885
|
+
const o = e._controlledReadableByteStream, n = We(t.constructor), { byteLength: i } = t, a = r * n;
|
|
886
|
+
return !(e._pendingPullIntos.length > 0) && (o._state === "closed" || e._queueTotalSize >= a);
|
|
887
|
+
}(o._readableStreamController, t, r);
|
|
888
|
+
}(this, e, o) ? new dt : new ct;
|
|
889
|
+
return ht(this, e, o, n), n._promise;
|
|
890
|
+
}
|
|
891
|
+
releaseLock() {
|
|
892
|
+
if (!ft(this))
|
|
893
|
+
throw _t("releaseLock");
|
|
894
|
+
this._ownerReadableStream !== undefined && function(e) {
|
|
895
|
+
O(e);
|
|
896
|
+
const t = new TypeError("Reader was released");
|
|
897
|
+
bt(e, t);
|
|
898
|
+
}(this);
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
Object.defineProperties(ReadableStreamBYOBReader.prototype, { cancel: { enumerable: true }, read: { enumerable: true }, releaseLock: { enumerable: true }, closed: { enumerable: true } }), o(ReadableStreamBYOBReader.prototype.cancel, "cancel"), o(ReadableStreamBYOBReader.prototype.read, "read"), o(ReadableStreamBYOBReader.prototype.releaseLock, "releaseLock"), typeof Symbol.toStringTag == "symbol" && Object.defineProperty(ReadableStreamBYOBReader.prototype, Symbol.toStringTag, { value: "ReadableStreamBYOBReader", configurable: true });
|
|
902
|
+
|
|
903
|
+
class ct {
|
|
904
|
+
constructor() {
|
|
905
|
+
this._promise = u((e, t) => {
|
|
906
|
+
this._resolvePromise = e, this._rejectPromise = t;
|
|
907
|
+
});
|
|
908
|
+
}
|
|
909
|
+
_chunkSteps(e) {
|
|
910
|
+
this._resolvePromise({ value: e, done: false });
|
|
911
|
+
}
|
|
912
|
+
_closeSteps(e) {
|
|
913
|
+
this._resolvePromise({ value: e, done: true });
|
|
914
|
+
}
|
|
915
|
+
_errorSteps(e) {
|
|
916
|
+
this._rejectPromise(e);
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
class dt {
|
|
921
|
+
constructor() {
|
|
922
|
+
this._promise = undefined;
|
|
923
|
+
}
|
|
924
|
+
_chunkSteps(e) {
|
|
925
|
+
this._promise = l({ value: e, done: false });
|
|
926
|
+
}
|
|
927
|
+
_closeSteps(e) {
|
|
928
|
+
this._promise = l({ value: e, done: true });
|
|
929
|
+
}
|
|
930
|
+
_errorSteps(e) {
|
|
931
|
+
this._promise = d(e);
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
function ft(e) {
|
|
935
|
+
return !!t(e) && (!!Object.prototype.hasOwnProperty.call(e, "_readIntoRequests") && e instanceof ReadableStreamBYOBReader);
|
|
936
|
+
}
|
|
937
|
+
function ht(e, t, r, o) {
|
|
938
|
+
const n = e._ownerReadableStream;
|
|
939
|
+
n._disturbed = true, n._state === "errored" ? o._errorSteps(n._storedError) : function(e, t, r, o) {
|
|
940
|
+
const n = e._controlledReadableByteStream, i = t.constructor, a = We(i), { byteOffset: s, byteLength: l } = t, u = r * a;
|
|
941
|
+
let c;
|
|
942
|
+
try {
|
|
943
|
+
c = ce(t.buffer);
|
|
944
|
+
} catch (e) {
|
|
945
|
+
return void o._errorSteps(e);
|
|
946
|
+
}
|
|
947
|
+
const d = { buffer: c, bufferByteLength: c.byteLength, byteOffset: s, byteLength: l, bytesFilled: 0, minimumFill: u, elementSize: a, viewConstructor: i, readerType: "byob" };
|
|
948
|
+
if (e._pendingPullIntos.length > 0)
|
|
949
|
+
return e._pendingPullIntos.push(d), void st(n, o);
|
|
950
|
+
if (n._state === "closed") {
|
|
951
|
+
const e = new i(d.buffer, d.byteOffset, 0);
|
|
952
|
+
return void o._closeSteps(e);
|
|
953
|
+
}
|
|
954
|
+
if (e._queueTotalSize > 0) {
|
|
955
|
+
if ($e(e, d)) {
|
|
956
|
+
const t = De(d);
|
|
957
|
+
return Ye(e), void o._chunkSteps(t);
|
|
958
|
+
}
|
|
959
|
+
if (e._closeRequested) {
|
|
960
|
+
const t = new TypeError("Insufficient bytes to fill elements in the given buffer");
|
|
961
|
+
return Xe(e, t), void o._errorSteps(t);
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
e._pendingPullIntos.push(d), st(n, o), je(e);
|
|
965
|
+
}(n._readableStreamController, t, r, o);
|
|
966
|
+
}
|
|
967
|
+
function bt(e, t) {
|
|
968
|
+
const r = e._readIntoRequests;
|
|
969
|
+
e._readIntoRequests = new v, r.forEach((e) => {
|
|
970
|
+
e._errorSteps(t);
|
|
971
|
+
});
|
|
972
|
+
}
|
|
973
|
+
function _t(e) {
|
|
974
|
+
return new TypeError(`ReadableStreamBYOBReader.prototype.${e} can only be used on a ReadableStreamBYOBReader`);
|
|
975
|
+
}
|
|
976
|
+
function mt(e, t) {
|
|
977
|
+
const { highWaterMark: r } = e;
|
|
978
|
+
if (r === undefined)
|
|
979
|
+
return t;
|
|
980
|
+
if (Re(r) || r < 0)
|
|
981
|
+
throw new RangeError("Invalid highWaterMark");
|
|
982
|
+
return r;
|
|
983
|
+
}
|
|
984
|
+
function pt(e) {
|
|
985
|
+
const { size: t } = e;
|
|
986
|
+
return t || (() => 1);
|
|
987
|
+
}
|
|
988
|
+
function yt(e, t) {
|
|
989
|
+
L(e, t);
|
|
990
|
+
const r = e == null ? undefined : e.highWaterMark, o = e == null ? undefined : e.size;
|
|
991
|
+
return { highWaterMark: r === undefined ? undefined : x(r), size: o === undefined ? undefined : St(o, `${t} has member 'size' that`) };
|
|
992
|
+
}
|
|
993
|
+
function St(e, t) {
|
|
994
|
+
return I(e, t), (t) => x(e(t));
|
|
995
|
+
}
|
|
996
|
+
function gt(e, t, r) {
|
|
997
|
+
return I(e, r), (r) => g(e, t, [r]);
|
|
998
|
+
}
|
|
999
|
+
function vt(e, t, r) {
|
|
1000
|
+
return I(e, r), () => g(e, t, []);
|
|
1001
|
+
}
|
|
1002
|
+
function wt(e, t, r) {
|
|
1003
|
+
return I(e, r), (r) => S(e, t, [r]);
|
|
1004
|
+
}
|
|
1005
|
+
function Rt(e, t, r) {
|
|
1006
|
+
return I(e, r), (r, o) => g(e, t, [r, o]);
|
|
1007
|
+
}
|
|
1008
|
+
function Tt(e, t) {
|
|
1009
|
+
if (!qt(e))
|
|
1010
|
+
throw new TypeError(`${t} is not a WritableStream.`);
|
|
1011
|
+
}
|
|
1012
|
+
|
|
1013
|
+
class WritableStream {
|
|
1014
|
+
constructor(e = {}, t = {}) {
|
|
1015
|
+
e === undefined ? e = null : $(e, "First parameter");
|
|
1016
|
+
const r = yt(t, "Second parameter"), o = function(e, t) {
|
|
1017
|
+
L(e, t);
|
|
1018
|
+
const r = e == null ? undefined : e.abort, o = e == null ? undefined : e.close, n = e == null ? undefined : e.start, i = e == null ? undefined : e.type, a = e == null ? undefined : e.write;
|
|
1019
|
+
return { abort: r === undefined ? undefined : gt(r, e, `${t} has member 'abort' that`), close: o === undefined ? undefined : vt(o, e, `${t} has member 'close' that`), start: n === undefined ? undefined : wt(n, e, `${t} has member 'start' that`), write: a === undefined ? undefined : Rt(a, e, `${t} has member 'write' that`), type: i };
|
|
1020
|
+
}(e, "First parameter");
|
|
1021
|
+
Ct(this);
|
|
1022
|
+
if (o.type !== undefined)
|
|
1023
|
+
throw new RangeError("Invalid type is specified");
|
|
1024
|
+
const n = pt(r);
|
|
1025
|
+
(function(e, t, r, o) {
|
|
1026
|
+
const n = Object.create(WritableStreamDefaultController.prototype);
|
|
1027
|
+
let i, a, s, l;
|
|
1028
|
+
i = t.start !== undefined ? () => t.start(n) : () => {};
|
|
1029
|
+
a = t.write !== undefined ? (e) => t.write(e, n) : () => c(undefined);
|
|
1030
|
+
s = t.close !== undefined ? () => t.close() : () => c(undefined);
|
|
1031
|
+
l = t.abort !== undefined ? (e) => t.abort(e) : () => c(undefined);
|
|
1032
|
+
Nt(e, n, i, a, s, l, r, o);
|
|
1033
|
+
})(this, o, mt(r, 1), n);
|
|
1034
|
+
}
|
|
1035
|
+
get locked() {
|
|
1036
|
+
if (!qt(this))
|
|
1037
|
+
throw Kt("locked");
|
|
1038
|
+
return Et(this);
|
|
1039
|
+
}
|
|
1040
|
+
abort(e = undefined) {
|
|
1041
|
+
return qt(this) ? Et(this) ? d(new TypeError("Cannot abort a stream that already has a writer")) : Wt(this, e) : d(Kt("abort"));
|
|
1042
|
+
}
|
|
1043
|
+
close() {
|
|
1044
|
+
return qt(this) ? Et(this) ? d(new TypeError("Cannot close a stream that already has a writer")) : At(this) ? d(new TypeError("Cannot close an already-closing stream")) : Ot(this) : d(Kt("close"));
|
|
1045
|
+
}
|
|
1046
|
+
getWriter() {
|
|
1047
|
+
if (!qt(this))
|
|
1048
|
+
throw Kt("getWriter");
|
|
1049
|
+
return Pt(this);
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1052
|
+
function Pt(e) {
|
|
1053
|
+
return new WritableStreamDefaultWriter(e);
|
|
1054
|
+
}
|
|
1055
|
+
function Ct(e) {
|
|
1056
|
+
e._state = "writable", e._storedError = undefined, e._writer = undefined, e._writableStreamController = undefined, e._writeRequests = new v, e._inFlightWriteRequest = undefined, e._closeRequest = undefined, e._inFlightCloseRequest = undefined, e._pendingAbortRequest = undefined, e._backpressure = false;
|
|
1057
|
+
}
|
|
1058
|
+
function qt(e) {
|
|
1059
|
+
return !!t(e) && (!!Object.prototype.hasOwnProperty.call(e, "_writableStreamController") && e instanceof WritableStream);
|
|
1060
|
+
}
|
|
1061
|
+
function Et(e) {
|
|
1062
|
+
return e._writer !== undefined;
|
|
1063
|
+
}
|
|
1064
|
+
function Wt(e, t) {
|
|
1065
|
+
var r;
|
|
1066
|
+
if (e._state === "closed" || e._state === "errored")
|
|
1067
|
+
return c(undefined);
|
|
1068
|
+
e._writableStreamController._abortReason = t, (r = e._writableStreamController._abortController) === null || r === undefined || r.abort(t);
|
|
1069
|
+
const o = e._state;
|
|
1070
|
+
if (o === "closed" || o === "errored")
|
|
1071
|
+
return c(undefined);
|
|
1072
|
+
if (e._pendingAbortRequest !== undefined)
|
|
1073
|
+
return e._pendingAbortRequest._promise;
|
|
1074
|
+
let n = false;
|
|
1075
|
+
o === "erroring" && (n = true, t = undefined);
|
|
1076
|
+
const i = u((r, o) => {
|
|
1077
|
+
e._pendingAbortRequest = { _promise: undefined, _resolve: r, _reject: o, _reason: t, _wasAlreadyErroring: n };
|
|
1078
|
+
});
|
|
1079
|
+
return e._pendingAbortRequest._promise = i, n || jt(e, t), i;
|
|
1080
|
+
}
|
|
1081
|
+
function Ot(e) {
|
|
1082
|
+
const t = e._state;
|
|
1083
|
+
if (t === "closed" || t === "errored")
|
|
1084
|
+
return d(new TypeError(`The stream (in ${t} state) is not in the writable state and cannot be closed`));
|
|
1085
|
+
const r = u((t, r) => {
|
|
1086
|
+
const o = { _resolve: t, _reject: r };
|
|
1087
|
+
e._closeRequest = o;
|
|
1088
|
+
}), o = e._writer;
|
|
1089
|
+
var n;
|
|
1090
|
+
return o !== undefined && e._backpressure && t === "writable" && cr(o), Ce(n = e._writableStreamController, xt, 0), Ut(n), r;
|
|
1091
|
+
}
|
|
1092
|
+
function Bt(e, t) {
|
|
1093
|
+
e._state !== "writable" ? kt(e) : jt(e, t);
|
|
1094
|
+
}
|
|
1095
|
+
function jt(e, t) {
|
|
1096
|
+
const r = e._writableStreamController;
|
|
1097
|
+
e._state = "erroring", e._storedError = t;
|
|
1098
|
+
const o = e._writer;
|
|
1099
|
+
o !== undefined && $t(o, t), !function(e) {
|
|
1100
|
+
if (e._inFlightWriteRequest === undefined && e._inFlightCloseRequest === undefined)
|
|
1101
|
+
return false;
|
|
1102
|
+
return true;
|
|
1103
|
+
}(e) && r._started && kt(e);
|
|
1104
|
+
}
|
|
1105
|
+
function kt(e) {
|
|
1106
|
+
e._state = "errored", e._writableStreamController[R]();
|
|
1107
|
+
const t = e._storedError;
|
|
1108
|
+
if (e._writeRequests.forEach((e) => {
|
|
1109
|
+
e._reject(t);
|
|
1110
|
+
}), e._writeRequests = new v, e._pendingAbortRequest === undefined)
|
|
1111
|
+
return void zt(e);
|
|
1112
|
+
const r = e._pendingAbortRequest;
|
|
1113
|
+
if (e._pendingAbortRequest = undefined, r._wasAlreadyErroring)
|
|
1114
|
+
return r._reject(t), void zt(e);
|
|
1115
|
+
h(e._writableStreamController[w](r._reason), () => (r._resolve(), zt(e), null), (t) => (r._reject(t), zt(e), null));
|
|
1116
|
+
}
|
|
1117
|
+
function At(e) {
|
|
1118
|
+
return e._closeRequest !== undefined || e._inFlightCloseRequest !== undefined;
|
|
1119
|
+
}
|
|
1120
|
+
function zt(e) {
|
|
1121
|
+
e._closeRequest !== undefined && (e._closeRequest._reject(e._storedError), e._closeRequest = undefined);
|
|
1122
|
+
const t = e._writer;
|
|
1123
|
+
t !== undefined && nr(t, e._storedError);
|
|
1124
|
+
}
|
|
1125
|
+
function Dt(e, t) {
|
|
1126
|
+
const r = e._writer;
|
|
1127
|
+
r !== undefined && t !== e._backpressure && (t ? function(e) {
|
|
1128
|
+
ar(e);
|
|
1129
|
+
}(r) : cr(r)), e._backpressure = t;
|
|
1130
|
+
}
|
|
1131
|
+
Object.defineProperties(WritableStream.prototype, { abort: { enumerable: true }, close: { enumerable: true }, getWriter: { enumerable: true }, locked: { enumerable: true } }), o(WritableStream.prototype.abort, "abort"), o(WritableStream.prototype.close, "close"), o(WritableStream.prototype.getWriter, "getWriter"), typeof Symbol.toStringTag == "symbol" && Object.defineProperty(WritableStream.prototype, Symbol.toStringTag, { value: "WritableStream", configurable: true });
|
|
1132
|
+
|
|
1133
|
+
class WritableStreamDefaultWriter {
|
|
1134
|
+
constructor(e) {
|
|
1135
|
+
if (M(e, 1, "WritableStreamDefaultWriter"), Tt(e, "First parameter"), Et(e))
|
|
1136
|
+
throw new TypeError("This stream has already been locked for exclusive writing by another writer");
|
|
1137
|
+
this._ownerWritableStream = e, e._writer = this;
|
|
1138
|
+
const t = e._state;
|
|
1139
|
+
if (t === "writable")
|
|
1140
|
+
!At(e) && e._backpressure ? ar(this) : lr(this), rr(this);
|
|
1141
|
+
else if (t === "erroring")
|
|
1142
|
+
sr(this, e._storedError), rr(this);
|
|
1143
|
+
else if (t === "closed")
|
|
1144
|
+
lr(this), rr(r = this), ir(r);
|
|
1145
|
+
else {
|
|
1146
|
+
const t = e._storedError;
|
|
1147
|
+
sr(this, t), or(this, t);
|
|
1148
|
+
}
|
|
1149
|
+
var r;
|
|
1150
|
+
}
|
|
1151
|
+
get closed() {
|
|
1152
|
+
return Ft(this) ? this._closedPromise : d(er("closed"));
|
|
1153
|
+
}
|
|
1154
|
+
get desiredSize() {
|
|
1155
|
+
if (!Ft(this))
|
|
1156
|
+
throw er("desiredSize");
|
|
1157
|
+
if (this._ownerWritableStream === undefined)
|
|
1158
|
+
throw tr("desiredSize");
|
|
1159
|
+
return function(e) {
|
|
1160
|
+
const t = e._ownerWritableStream, r = t._state;
|
|
1161
|
+
if (r === "errored" || r === "erroring")
|
|
1162
|
+
return null;
|
|
1163
|
+
if (r === "closed")
|
|
1164
|
+
return 0;
|
|
1165
|
+
return Vt(t._writableStreamController);
|
|
1166
|
+
}(this);
|
|
1167
|
+
}
|
|
1168
|
+
get ready() {
|
|
1169
|
+
return Ft(this) ? this._readyPromise : d(er("ready"));
|
|
1170
|
+
}
|
|
1171
|
+
abort(e = undefined) {
|
|
1172
|
+
return Ft(this) ? this._ownerWritableStream === undefined ? d(tr("abort")) : function(e, t) {
|
|
1173
|
+
return Wt(e._ownerWritableStream, t);
|
|
1174
|
+
}(this, e) : d(er("abort"));
|
|
1175
|
+
}
|
|
1176
|
+
close() {
|
|
1177
|
+
if (!Ft(this))
|
|
1178
|
+
return d(er("close"));
|
|
1179
|
+
const e = this._ownerWritableStream;
|
|
1180
|
+
return e === undefined ? d(tr("close")) : At(e) ? d(new TypeError("Cannot close an already-closing stream")) : Lt(this);
|
|
1181
|
+
}
|
|
1182
|
+
releaseLock() {
|
|
1183
|
+
if (!Ft(this))
|
|
1184
|
+
throw er("releaseLock");
|
|
1185
|
+
this._ownerWritableStream !== undefined && Mt(this);
|
|
1186
|
+
}
|
|
1187
|
+
write(e = undefined) {
|
|
1188
|
+
return Ft(this) ? this._ownerWritableStream === undefined ? d(tr("write to")) : Yt(this, e) : d(er("write"));
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1191
|
+
function Ft(e) {
|
|
1192
|
+
return !!t(e) && (!!Object.prototype.hasOwnProperty.call(e, "_ownerWritableStream") && e instanceof WritableStreamDefaultWriter);
|
|
1193
|
+
}
|
|
1194
|
+
function Lt(e) {
|
|
1195
|
+
return Ot(e._ownerWritableStream);
|
|
1196
|
+
}
|
|
1197
|
+
function It(e, t) {
|
|
1198
|
+
e._closedPromiseState === "pending" ? nr(e, t) : function(e, t) {
|
|
1199
|
+
or(e, t);
|
|
1200
|
+
}(e, t);
|
|
1201
|
+
}
|
|
1202
|
+
function $t(e, t) {
|
|
1203
|
+
e._readyPromiseState === "pending" ? ur(e, t) : function(e, t) {
|
|
1204
|
+
sr(e, t);
|
|
1205
|
+
}(e, t);
|
|
1206
|
+
}
|
|
1207
|
+
function Mt(e) {
|
|
1208
|
+
const t = e._ownerWritableStream, r = new TypeError("Writer was released and can no longer be used to monitor the stream's closedness");
|
|
1209
|
+
$t(e, r), It(e, r), t._writer = undefined, e._ownerWritableStream = undefined;
|
|
1210
|
+
}
|
|
1211
|
+
function Yt(e, t) {
|
|
1212
|
+
const r = e._ownerWritableStream, o = r._writableStreamController, n = function(e, t) {
|
|
1213
|
+
if (e._strategySizeAlgorithm === undefined)
|
|
1214
|
+
return 1;
|
|
1215
|
+
try {
|
|
1216
|
+
return e._strategySizeAlgorithm(t);
|
|
1217
|
+
} catch (t) {
|
|
1218
|
+
return Gt(e, t), 1;
|
|
1219
|
+
}
|
|
1220
|
+
}(o, t);
|
|
1221
|
+
if (r !== e._ownerWritableStream)
|
|
1222
|
+
return d(tr("write to"));
|
|
1223
|
+
const i = r._state;
|
|
1224
|
+
if (i === "errored")
|
|
1225
|
+
return d(r._storedError);
|
|
1226
|
+
if (At(r) || i === "closed")
|
|
1227
|
+
return d(new TypeError("The stream is closing or closed and cannot be written to"));
|
|
1228
|
+
if (i === "erroring")
|
|
1229
|
+
return d(r._storedError);
|
|
1230
|
+
const a = function(e) {
|
|
1231
|
+
return u((t, r) => {
|
|
1232
|
+
const o = { _resolve: t, _reject: r };
|
|
1233
|
+
e._writeRequests.push(o);
|
|
1234
|
+
});
|
|
1235
|
+
}(r);
|
|
1236
|
+
return function(e, t, r) {
|
|
1237
|
+
try {
|
|
1238
|
+
Ce(e, t, r);
|
|
1239
|
+
} catch (t) {
|
|
1240
|
+
return void Gt(e, t);
|
|
1241
|
+
}
|
|
1242
|
+
const o = e._controlledWritableStream;
|
|
1243
|
+
if (!At(o) && o._state === "writable") {
|
|
1244
|
+
Dt(o, Xt(e));
|
|
1245
|
+
}
|
|
1246
|
+
Ut(e);
|
|
1247
|
+
}(o, t, n), a;
|
|
1248
|
+
}
|
|
1249
|
+
Object.defineProperties(WritableStreamDefaultWriter.prototype, { abort: { enumerable: true }, close: { enumerable: true }, releaseLock: { enumerable: true }, write: { enumerable: true }, closed: { enumerable: true }, desiredSize: { enumerable: true }, ready: { enumerable: true } }), o(WritableStreamDefaultWriter.prototype.abort, "abort"), o(WritableStreamDefaultWriter.prototype.close, "close"), o(WritableStreamDefaultWriter.prototype.releaseLock, "releaseLock"), o(WritableStreamDefaultWriter.prototype.write, "write"), typeof Symbol.toStringTag == "symbol" && Object.defineProperty(WritableStreamDefaultWriter.prototype, Symbol.toStringTag, { value: "WritableStreamDefaultWriter", configurable: true });
|
|
1250
|
+
var xt = {};
|
|
1251
|
+
|
|
1252
|
+
class WritableStreamDefaultController {
|
|
1253
|
+
constructor() {
|
|
1254
|
+
throw new TypeError("Illegal constructor");
|
|
1255
|
+
}
|
|
1256
|
+
get abortReason() {
|
|
1257
|
+
if (!Qt(this))
|
|
1258
|
+
throw Zt("abortReason");
|
|
1259
|
+
return this._abortReason;
|
|
1260
|
+
}
|
|
1261
|
+
get signal() {
|
|
1262
|
+
if (!Qt(this))
|
|
1263
|
+
throw Zt("signal");
|
|
1264
|
+
if (this._abortController === undefined)
|
|
1265
|
+
throw new TypeError("WritableStreamDefaultController.prototype.signal is not supported");
|
|
1266
|
+
return this._abortController.signal;
|
|
1267
|
+
}
|
|
1268
|
+
error(e = undefined) {
|
|
1269
|
+
if (!Qt(this))
|
|
1270
|
+
throw Zt("error");
|
|
1271
|
+
this._controlledWritableStream._state === "writable" && Jt(this, e);
|
|
1272
|
+
}
|
|
1273
|
+
[w](e) {
|
|
1274
|
+
const t = this._abortAlgorithm(e);
|
|
1275
|
+
return Ht(this), t;
|
|
1276
|
+
}
|
|
1277
|
+
[R]() {
|
|
1278
|
+
qe(this);
|
|
1279
|
+
}
|
|
1280
|
+
}
|
|
1281
|
+
function Qt(e) {
|
|
1282
|
+
return !!t(e) && (!!Object.prototype.hasOwnProperty.call(e, "_controlledWritableStream") && e instanceof WritableStreamDefaultController);
|
|
1283
|
+
}
|
|
1284
|
+
function Nt(e, t, r, o, n, i, a, s) {
|
|
1285
|
+
t._controlledWritableStream = e, e._writableStreamController = t, t._queue = undefined, t._queueTotalSize = undefined, qe(t), t._abortReason = undefined, t._abortController = function() {
|
|
1286
|
+
if (typeof AbortController == "function")
|
|
1287
|
+
return new AbortController;
|
|
1288
|
+
}(), t._started = false, t._strategySizeAlgorithm = s, t._strategyHWM = a, t._writeAlgorithm = o, t._closeAlgorithm = n, t._abortAlgorithm = i;
|
|
1289
|
+
const l = Xt(t);
|
|
1290
|
+
Dt(e, l);
|
|
1291
|
+
h(c(r()), () => (t._started = true, Ut(t), null), (r) => (t._started = true, Bt(e, r), null));
|
|
1292
|
+
}
|
|
1293
|
+
function Ht(e) {
|
|
1294
|
+
e._writeAlgorithm = undefined, e._closeAlgorithm = undefined, e._abortAlgorithm = undefined, e._strategySizeAlgorithm = undefined;
|
|
1295
|
+
}
|
|
1296
|
+
function Vt(e) {
|
|
1297
|
+
return e._strategyHWM - e._queueTotalSize;
|
|
1298
|
+
}
|
|
1299
|
+
function Ut(e) {
|
|
1300
|
+
const t = e._controlledWritableStream;
|
|
1301
|
+
if (!e._started)
|
|
1302
|
+
return;
|
|
1303
|
+
if (t._inFlightWriteRequest !== undefined)
|
|
1304
|
+
return;
|
|
1305
|
+
if (t._state === "erroring")
|
|
1306
|
+
return void kt(t);
|
|
1307
|
+
if (e._queue.length === 0)
|
|
1308
|
+
return;
|
|
1309
|
+
const r = e._queue.peek().value;
|
|
1310
|
+
r === xt ? function(e) {
|
|
1311
|
+
const t = e._controlledWritableStream;
|
|
1312
|
+
(function(e) {
|
|
1313
|
+
e._inFlightCloseRequest = e._closeRequest, e._closeRequest = undefined;
|
|
1314
|
+
})(t), Pe(e);
|
|
1315
|
+
const r = e._closeAlgorithm();
|
|
1316
|
+
Ht(e), h(r, () => (function(e) {
|
|
1317
|
+
e._inFlightCloseRequest._resolve(undefined), e._inFlightCloseRequest = undefined, e._state === "erroring" && (e._storedError = undefined, e._pendingAbortRequest !== undefined && (e._pendingAbortRequest._resolve(), e._pendingAbortRequest = undefined)), e._state = "closed";
|
|
1318
|
+
const t = e._writer;
|
|
1319
|
+
t !== undefined && ir(t);
|
|
1320
|
+
}(t), null), (e) => (function(e, t) {
|
|
1321
|
+
e._inFlightCloseRequest._reject(t), e._inFlightCloseRequest = undefined, e._pendingAbortRequest !== undefined && (e._pendingAbortRequest._reject(t), e._pendingAbortRequest = undefined), Bt(e, t);
|
|
1322
|
+
}(t, e), null));
|
|
1323
|
+
}(e) : function(e, t) {
|
|
1324
|
+
const r = e._controlledWritableStream;
|
|
1325
|
+
(function(e) {
|
|
1326
|
+
e._inFlightWriteRequest = e._writeRequests.shift();
|
|
1327
|
+
})(r);
|
|
1328
|
+
const o = e._writeAlgorithm(t);
|
|
1329
|
+
h(o, () => {
|
|
1330
|
+
(function(e) {
|
|
1331
|
+
e._inFlightWriteRequest._resolve(undefined), e._inFlightWriteRequest = undefined;
|
|
1332
|
+
})(r);
|
|
1333
|
+
const t = r._state;
|
|
1334
|
+
if (Pe(e), !At(r) && t === "writable") {
|
|
1335
|
+
const t = Xt(e);
|
|
1336
|
+
Dt(r, t);
|
|
1337
|
+
}
|
|
1338
|
+
return Ut(e), null;
|
|
1339
|
+
}, (t) => (r._state === "writable" && Ht(e), function(e, t) {
|
|
1340
|
+
e._inFlightWriteRequest._reject(t), e._inFlightWriteRequest = undefined, Bt(e, t);
|
|
1341
|
+
}(r, t), null));
|
|
1342
|
+
}(e, r);
|
|
1343
|
+
}
|
|
1344
|
+
function Gt(e, t) {
|
|
1345
|
+
e._controlledWritableStream._state === "writable" && Jt(e, t);
|
|
1346
|
+
}
|
|
1347
|
+
function Xt(e) {
|
|
1348
|
+
return Vt(e) <= 0;
|
|
1349
|
+
}
|
|
1350
|
+
function Jt(e, t) {
|
|
1351
|
+
const r = e._controlledWritableStream;
|
|
1352
|
+
Ht(e), jt(r, t);
|
|
1353
|
+
}
|
|
1354
|
+
function Kt(e) {
|
|
1355
|
+
return new TypeError(`WritableStream.prototype.${e} can only be used on a WritableStream`);
|
|
1356
|
+
}
|
|
1357
|
+
function Zt(e) {
|
|
1358
|
+
return new TypeError(`WritableStreamDefaultController.prototype.${e} can only be used on a WritableStreamDefaultController`);
|
|
1359
|
+
}
|
|
1360
|
+
function er(e) {
|
|
1361
|
+
return new TypeError(`WritableStreamDefaultWriter.prototype.${e} can only be used on a WritableStreamDefaultWriter`);
|
|
1362
|
+
}
|
|
1363
|
+
function tr(e) {
|
|
1364
|
+
return new TypeError("Cannot " + e + " a stream using a released writer");
|
|
1365
|
+
}
|
|
1366
|
+
function rr(e) {
|
|
1367
|
+
e._closedPromise = u((t, r) => {
|
|
1368
|
+
e._closedPromise_resolve = t, e._closedPromise_reject = r, e._closedPromiseState = "pending";
|
|
1369
|
+
});
|
|
1370
|
+
}
|
|
1371
|
+
function or(e, t) {
|
|
1372
|
+
rr(e), nr(e, t);
|
|
1373
|
+
}
|
|
1374
|
+
function nr(e, t) {
|
|
1375
|
+
e._closedPromise_reject !== undefined && (p(e._closedPromise), e._closedPromise_reject(t), e._closedPromise_resolve = undefined, e._closedPromise_reject = undefined, e._closedPromiseState = "rejected");
|
|
1376
|
+
}
|
|
1377
|
+
function ir(e) {
|
|
1378
|
+
e._closedPromise_resolve !== undefined && (e._closedPromise_resolve(undefined), e._closedPromise_resolve = undefined, e._closedPromise_reject = undefined, e._closedPromiseState = "resolved");
|
|
1379
|
+
}
|
|
1380
|
+
function ar(e) {
|
|
1381
|
+
e._readyPromise = u((t, r) => {
|
|
1382
|
+
e._readyPromise_resolve = t, e._readyPromise_reject = r;
|
|
1383
|
+
}), e._readyPromiseState = "pending";
|
|
1384
|
+
}
|
|
1385
|
+
function sr(e, t) {
|
|
1386
|
+
ar(e), ur(e, t);
|
|
1387
|
+
}
|
|
1388
|
+
function lr(e) {
|
|
1389
|
+
ar(e), cr(e);
|
|
1390
|
+
}
|
|
1391
|
+
function ur(e, t) {
|
|
1392
|
+
e._readyPromise_reject !== undefined && (p(e._readyPromise), e._readyPromise_reject(t), e._readyPromise_resolve = undefined, e._readyPromise_reject = undefined, e._readyPromiseState = "rejected");
|
|
1393
|
+
}
|
|
1394
|
+
function cr(e) {
|
|
1395
|
+
e._readyPromise_resolve !== undefined && (e._readyPromise_resolve(undefined), e._readyPromise_resolve = undefined, e._readyPromise_reject = undefined, e._readyPromiseState = "fulfilled");
|
|
1396
|
+
}
|
|
1397
|
+
Object.defineProperties(WritableStreamDefaultController.prototype, { abortReason: { enumerable: true }, signal: { enumerable: true }, error: { enumerable: true } }), typeof Symbol.toStringTag == "symbol" && Object.defineProperty(WritableStreamDefaultController.prototype, Symbol.toStringTag, { value: "WritableStreamDefaultController", configurable: true });
|
|
1398
|
+
var dr = typeof globalThis != "undefined" ? globalThis : typeof self != "undefined" ? self : typeof global != "undefined" ? global : undefined;
|
|
1399
|
+
var fr = function() {
|
|
1400
|
+
const e = dr == null ? undefined : dr.DOMException;
|
|
1401
|
+
return function(e) {
|
|
1402
|
+
if (typeof e != "function" && typeof e != "object")
|
|
1403
|
+
return false;
|
|
1404
|
+
if (e.name !== "DOMException")
|
|
1405
|
+
return false;
|
|
1406
|
+
try {
|
|
1407
|
+
return new e, true;
|
|
1408
|
+
} catch (e) {
|
|
1409
|
+
return false;
|
|
1410
|
+
}
|
|
1411
|
+
}(e) ? e : undefined;
|
|
1412
|
+
}() || function() {
|
|
1413
|
+
const e = function(e, t) {
|
|
1414
|
+
this.message = e || "", this.name = t || "Error", Error.captureStackTrace && Error.captureStackTrace(this, this.constructor);
|
|
1415
|
+
};
|
|
1416
|
+
return o(e, "DOMException"), e.prototype = Object.create(Error.prototype), Object.defineProperty(e.prototype, "constructor", { value: e, writable: true, configurable: true }), e;
|
|
1417
|
+
}();
|
|
1418
|
+
function hr(e, t, r, o, n, i) {
|
|
1419
|
+
const a = V(e), s = Pt(t);
|
|
1420
|
+
e._disturbed = true;
|
|
1421
|
+
const l = new br(s), _ = new mr(l);
|
|
1422
|
+
return u((m, y) => {
|
|
1423
|
+
let S;
|
|
1424
|
+
if (i !== undefined) {
|
|
1425
|
+
if (S = () => {
|
|
1426
|
+
const r = i.reason !== undefined ? i.reason : new fr("Aborted", "AbortError"), a = [];
|
|
1427
|
+
o || a.push(() => t._state === "writable" ? Wt(t, r) : c(undefined)), n || a.push(() => e._state === "readable" ? Mr(e, r) : c(undefined)), T(() => Promise.all(a.map((e) => e())), true, r);
|
|
1428
|
+
}, i.aborted)
|
|
1429
|
+
return void S();
|
|
1430
|
+
i.addEventListener("abort", S);
|
|
1431
|
+
}
|
|
1432
|
+
function g() {
|
|
1433
|
+
for (;!l._shuttingDown && !t._backpressure && t._state === "writable" && !At(t) && e._state === "readable" && re(a); )
|
|
1434
|
+
te(a, _);
|
|
1435
|
+
if (l._shuttingDown)
|
|
1436
|
+
return c(true);
|
|
1437
|
+
if (t._backpressure)
|
|
1438
|
+
return f(s._readyPromise, g);
|
|
1439
|
+
const r = new _r(l);
|
|
1440
|
+
return te(a, r), r._promise;
|
|
1441
|
+
}
|
|
1442
|
+
var v, w, R;
|
|
1443
|
+
if (pr(e, a._closedPromise, (e) => (o ? P(true, e) : T(() => Wt(t, e), true, e), null)), pr(t, s._closedPromise, (t) => (n ? P(true, t) : T(() => Mr(e, t), true, t), null)), v = e, w = a._closedPromise, R = () => (r ? P() : T(() => function(e) {
|
|
1444
|
+
const t = e._ownerWritableStream, r = t._state;
|
|
1445
|
+
return At(t) || r === "closed" ? c(undefined) : r === "errored" ? d(t._storedError) : Lt(e);
|
|
1446
|
+
}(s)), null), v._state === "closed" ? R() : b(w, R), At(t) || t._state === "closed") {
|
|
1447
|
+
const t = new TypeError("the destination writable stream closed before all data could be piped to it");
|
|
1448
|
+
n ? P(true, t) : T(() => Mr(e, t), true, t);
|
|
1449
|
+
}
|
|
1450
|
+
function T(e, r, o) {
|
|
1451
|
+
function n() {
|
|
1452
|
+
return h(e(), () => C(r, o), (e) => C(true, e)), null;
|
|
1453
|
+
}
|
|
1454
|
+
l._shuttingDown || (l._shuttingDown = true, t._state !== "writable" || At(t) ? n() : b(l._waitForWritesToFinish(), n));
|
|
1455
|
+
}
|
|
1456
|
+
function P(e, r) {
|
|
1457
|
+
l._shuttingDown || (l._shuttingDown = true, t._state !== "writable" || At(t) ? C(e, r) : b(l._waitForWritesToFinish(), () => C(e, r)));
|
|
1458
|
+
}
|
|
1459
|
+
function C(e, t) {
|
|
1460
|
+
return Mt(s), O(a), i !== undefined && i.removeEventListener("abort", S), e ? y(t) : m(undefined), null;
|
|
1461
|
+
}
|
|
1462
|
+
p(u((e, t) => {
|
|
1463
|
+
(function r(o) {
|
|
1464
|
+
o ? e() : f(g(), r, t);
|
|
1465
|
+
})(false);
|
|
1466
|
+
}));
|
|
1467
|
+
});
|
|
1468
|
+
}
|
|
1469
|
+
|
|
1470
|
+
class br {
|
|
1471
|
+
constructor(e) {
|
|
1472
|
+
this._writer = e, this._shuttingDown = false, this._currentWrite = c(undefined);
|
|
1473
|
+
}
|
|
1474
|
+
_waitForWritesToFinish() {
|
|
1475
|
+
const e = this._currentWrite;
|
|
1476
|
+
return f(this._currentWrite, () => e !== this._currentWrite ? this._waitForWritesToFinish() : undefined);
|
|
1477
|
+
}
|
|
1478
|
+
}
|
|
1479
|
+
|
|
1480
|
+
class _r {
|
|
1481
|
+
constructor(e) {
|
|
1482
|
+
this._state = e, this._promise = u((e, t) => {
|
|
1483
|
+
this._resolvePromise = e, this._rejectPromise = t;
|
|
1484
|
+
});
|
|
1485
|
+
}
|
|
1486
|
+
_chunkSteps(t) {
|
|
1487
|
+
this._state._currentWrite = f(Yt(this._state._writer, t), undefined, e), this._resolvePromise(false);
|
|
1488
|
+
}
|
|
1489
|
+
_closeSteps() {
|
|
1490
|
+
this._resolvePromise(true);
|
|
1491
|
+
}
|
|
1492
|
+
_errorSteps(e) {
|
|
1493
|
+
this._rejectPromise(e);
|
|
1494
|
+
}
|
|
1495
|
+
}
|
|
1496
|
+
|
|
1497
|
+
class mr {
|
|
1498
|
+
constructor(e) {
|
|
1499
|
+
this._state = e;
|
|
1500
|
+
}
|
|
1501
|
+
_chunkSteps(t) {
|
|
1502
|
+
this._state._currentWrite = f(Yt(this._state._writer, t), undefined, e);
|
|
1503
|
+
}
|
|
1504
|
+
_closeSteps() {}
|
|
1505
|
+
_errorSteps(e) {}
|
|
1506
|
+
}
|
|
1507
|
+
function pr(e, t, r) {
|
|
1508
|
+
e._state === "errored" ? r(e._storedError) : _(t, r);
|
|
1509
|
+
}
|
|
1510
|
+
|
|
1511
|
+
class ReadableStreamDefaultController {
|
|
1512
|
+
constructor() {
|
|
1513
|
+
throw new TypeError("Illegal constructor");
|
|
1514
|
+
}
|
|
1515
|
+
get desiredSize() {
|
|
1516
|
+
if (!yr(this))
|
|
1517
|
+
throw Er("desiredSize");
|
|
1518
|
+
return Pr(this);
|
|
1519
|
+
}
|
|
1520
|
+
close() {
|
|
1521
|
+
if (!yr(this))
|
|
1522
|
+
throw Er("close");
|
|
1523
|
+
if (!Cr(this))
|
|
1524
|
+
throw new TypeError("The stream is not in a state that permits close");
|
|
1525
|
+
wr(this);
|
|
1526
|
+
}
|
|
1527
|
+
enqueue(e = undefined) {
|
|
1528
|
+
if (!yr(this))
|
|
1529
|
+
throw Er("enqueue");
|
|
1530
|
+
if (!Cr(this))
|
|
1531
|
+
throw new TypeError("The stream is not in a state that permits enqueue");
|
|
1532
|
+
return Rr(this, e);
|
|
1533
|
+
}
|
|
1534
|
+
error(e = undefined) {
|
|
1535
|
+
if (!yr(this))
|
|
1536
|
+
throw Er("error");
|
|
1537
|
+
Tr(this, e);
|
|
1538
|
+
}
|
|
1539
|
+
[T](e) {
|
|
1540
|
+
qe(this);
|
|
1541
|
+
const t = this._cancelAlgorithm(e);
|
|
1542
|
+
return vr(this), t;
|
|
1543
|
+
}
|
|
1544
|
+
[P](e) {
|
|
1545
|
+
const t = this._controlledReadableStream;
|
|
1546
|
+
if (this._queue.length > 0) {
|
|
1547
|
+
const r = Pe(this);
|
|
1548
|
+
this._closeRequested && this._queue.length === 0 ? (vr(this), Yr(t)) : Sr(this), e._chunkSteps(r);
|
|
1549
|
+
} else
|
|
1550
|
+
U(t, e), Sr(this);
|
|
1551
|
+
}
|
|
1552
|
+
[C]() {
|
|
1553
|
+
return this._queue.length > 0;
|
|
1554
|
+
}
|
|
1555
|
+
[q]() {}
|
|
1556
|
+
}
|
|
1557
|
+
function yr(e) {
|
|
1558
|
+
return !!t(e) && (!!Object.prototype.hasOwnProperty.call(e, "_controlledReadableStream") && e instanceof ReadableStreamDefaultController);
|
|
1559
|
+
}
|
|
1560
|
+
function Sr(e) {
|
|
1561
|
+
if (!gr(e))
|
|
1562
|
+
return;
|
|
1563
|
+
if (e._pulling)
|
|
1564
|
+
return void (e._pullAgain = true);
|
|
1565
|
+
e._pulling = true;
|
|
1566
|
+
h(e._pullAlgorithm(), () => (e._pulling = false, e._pullAgain && (e._pullAgain = false, Sr(e)), null), (t) => (Tr(e, t), null));
|
|
1567
|
+
}
|
|
1568
|
+
function gr(e) {
|
|
1569
|
+
const t = e._controlledReadableStream;
|
|
1570
|
+
if (!Cr(e))
|
|
1571
|
+
return false;
|
|
1572
|
+
if (!e._started)
|
|
1573
|
+
return false;
|
|
1574
|
+
if ($r(t) && X(t) > 0)
|
|
1575
|
+
return true;
|
|
1576
|
+
return Pr(e) > 0;
|
|
1577
|
+
}
|
|
1578
|
+
function vr(e) {
|
|
1579
|
+
e._pullAlgorithm = undefined, e._cancelAlgorithm = undefined, e._strategySizeAlgorithm = undefined;
|
|
1580
|
+
}
|
|
1581
|
+
function wr(e) {
|
|
1582
|
+
if (!Cr(e))
|
|
1583
|
+
return;
|
|
1584
|
+
const t = e._controlledReadableStream;
|
|
1585
|
+
e._closeRequested = true, e._queue.length === 0 && (vr(e), Yr(t));
|
|
1586
|
+
}
|
|
1587
|
+
function Rr(e, t) {
|
|
1588
|
+
if (!Cr(e))
|
|
1589
|
+
return;
|
|
1590
|
+
const r = e._controlledReadableStream;
|
|
1591
|
+
if ($r(r) && X(r) > 0)
|
|
1592
|
+
G(r, t, false);
|
|
1593
|
+
else {
|
|
1594
|
+
let r;
|
|
1595
|
+
try {
|
|
1596
|
+
r = e._strategySizeAlgorithm(t);
|
|
1597
|
+
} catch (t) {
|
|
1598
|
+
throw Tr(e, t), t;
|
|
1599
|
+
}
|
|
1600
|
+
try {
|
|
1601
|
+
Ce(e, t, r);
|
|
1602
|
+
} catch (t) {
|
|
1603
|
+
throw Tr(e, t), t;
|
|
1604
|
+
}
|
|
1605
|
+
}
|
|
1606
|
+
Sr(e);
|
|
1607
|
+
}
|
|
1608
|
+
function Tr(e, t) {
|
|
1609
|
+
const r = e._controlledReadableStream;
|
|
1610
|
+
r._state === "readable" && (qe(e), vr(e), xr(r, t));
|
|
1611
|
+
}
|
|
1612
|
+
function Pr(e) {
|
|
1613
|
+
const t = e._controlledReadableStream._state;
|
|
1614
|
+
return t === "errored" ? null : t === "closed" ? 0 : e._strategyHWM - e._queueTotalSize;
|
|
1615
|
+
}
|
|
1616
|
+
function Cr(e) {
|
|
1617
|
+
const t = e._controlledReadableStream._state;
|
|
1618
|
+
return !e._closeRequested && t === "readable";
|
|
1619
|
+
}
|
|
1620
|
+
function qr(e, t, r, o, n, i, a) {
|
|
1621
|
+
t._controlledReadableStream = e, t._queue = undefined, t._queueTotalSize = undefined, qe(t), t._started = false, t._closeRequested = false, t._pullAgain = false, t._pulling = false, t._strategySizeAlgorithm = a, t._strategyHWM = i, t._pullAlgorithm = o, t._cancelAlgorithm = n, e._readableStreamController = t;
|
|
1622
|
+
h(c(r()), () => (t._started = true, Sr(t), null), (e) => (Tr(t, e), null));
|
|
1623
|
+
}
|
|
1624
|
+
function Er(e) {
|
|
1625
|
+
return new TypeError(`ReadableStreamDefaultController.prototype.${e} can only be used on a ReadableStreamDefaultController`);
|
|
1626
|
+
}
|
|
1627
|
+
function Wr(e, t) {
|
|
1628
|
+
return Oe(e._readableStreamController) ? function(e) {
|
|
1629
|
+
let t, r, o, n, i, a = V(e), s = false, l = false, d = false, f = false, h = false;
|
|
1630
|
+
const b = u((e) => {
|
|
1631
|
+
i = e;
|
|
1632
|
+
});
|
|
1633
|
+
function m(e) {
|
|
1634
|
+
_(e._closedPromise, (t) => (e !== a || (Xe(o._readableStreamController, t), Xe(n._readableStreamController, t), f && h || i(undefined)), null));
|
|
1635
|
+
}
|
|
1636
|
+
function p() {
|
|
1637
|
+
ft(a) && (O(a), a = V(e), m(a));
|
|
1638
|
+
te(a, { _chunkSteps: (t) => {
|
|
1639
|
+
y(() => {
|
|
1640
|
+
l = false, d = false;
|
|
1641
|
+
const r = t;
|
|
1642
|
+
let a = t;
|
|
1643
|
+
if (!f && !h)
|
|
1644
|
+
try {
|
|
1645
|
+
a = Te(t);
|
|
1646
|
+
} catch (t) {
|
|
1647
|
+
return Xe(o._readableStreamController, t), Xe(n._readableStreamController, t), void i(Mr(e, t));
|
|
1648
|
+
}
|
|
1649
|
+
f || Ge(o._readableStreamController, r), h || Ge(n._readableStreamController, a), s = false, l ? g() : d && v();
|
|
1650
|
+
});
|
|
1651
|
+
}, _closeSteps: () => {
|
|
1652
|
+
s = false, f || Ue(o._readableStreamController), h || Ue(n._readableStreamController), o._readableStreamController._pendingPullIntos.length > 0 && et(o._readableStreamController, 0), n._readableStreamController._pendingPullIntos.length > 0 && et(n._readableStreamController, 0), f && h || i(undefined);
|
|
1653
|
+
}, _errorSteps: () => {
|
|
1654
|
+
s = false;
|
|
1655
|
+
} });
|
|
1656
|
+
}
|
|
1657
|
+
function S(t, r) {
|
|
1658
|
+
ee(a) && (O(a), a = at(e), m(a));
|
|
1659
|
+
const u = r ? n : o, c = r ? o : n;
|
|
1660
|
+
ht(a, t, 1, { _chunkSteps: (t) => {
|
|
1661
|
+
y(() => {
|
|
1662
|
+
l = false, d = false;
|
|
1663
|
+
const o = r ? h : f;
|
|
1664
|
+
if (r ? f : h)
|
|
1665
|
+
o || tt(u._readableStreamController, t);
|
|
1666
|
+
else {
|
|
1667
|
+
let r;
|
|
1668
|
+
try {
|
|
1669
|
+
r = Te(t);
|
|
1670
|
+
} catch (t) {
|
|
1671
|
+
return Xe(u._readableStreamController, t), Xe(c._readableStreamController, t), void i(Mr(e, t));
|
|
1672
|
+
}
|
|
1673
|
+
o || tt(u._readableStreamController, t), Ge(c._readableStreamController, r);
|
|
1674
|
+
}
|
|
1675
|
+
s = false, l ? g() : d && v();
|
|
1676
|
+
});
|
|
1677
|
+
}, _closeSteps: (e) => {
|
|
1678
|
+
s = false;
|
|
1679
|
+
const t = r ? h : f, o = r ? f : h;
|
|
1680
|
+
t || Ue(u._readableStreamController), o || Ue(c._readableStreamController), e !== undefined && (t || tt(u._readableStreamController, e), !o && c._readableStreamController._pendingPullIntos.length > 0 && et(c._readableStreamController, 0)), t && o || i(undefined);
|
|
1681
|
+
}, _errorSteps: () => {
|
|
1682
|
+
s = false;
|
|
1683
|
+
} });
|
|
1684
|
+
}
|
|
1685
|
+
function g() {
|
|
1686
|
+
if (s)
|
|
1687
|
+
return l = true, c(undefined);
|
|
1688
|
+
s = true;
|
|
1689
|
+
const e = Ke(o._readableStreamController);
|
|
1690
|
+
return e === null ? p() : S(e._view, false), c(undefined);
|
|
1691
|
+
}
|
|
1692
|
+
function v() {
|
|
1693
|
+
if (s)
|
|
1694
|
+
return d = true, c(undefined);
|
|
1695
|
+
s = true;
|
|
1696
|
+
const e = Ke(n._readableStreamController);
|
|
1697
|
+
return e === null ? p() : S(e._view, true), c(undefined);
|
|
1698
|
+
}
|
|
1699
|
+
function w(o) {
|
|
1700
|
+
if (f = true, t = o, h) {
|
|
1701
|
+
const o = le([t, r]), n = Mr(e, o);
|
|
1702
|
+
i(n);
|
|
1703
|
+
}
|
|
1704
|
+
return b;
|
|
1705
|
+
}
|
|
1706
|
+
function R(o) {
|
|
1707
|
+
if (h = true, r = o, f) {
|
|
1708
|
+
const o = le([t, r]), n = Mr(e, o);
|
|
1709
|
+
i(n);
|
|
1710
|
+
}
|
|
1711
|
+
return b;
|
|
1712
|
+
}
|
|
1713
|
+
function T() {}
|
|
1714
|
+
return o = Fr(T, g, w), n = Fr(T, v, R), m(a), [o, n];
|
|
1715
|
+
}(e) : function(e) {
|
|
1716
|
+
const t = V(e);
|
|
1717
|
+
let r, o, n, i, a, s = false, l = false, d = false, f = false;
|
|
1718
|
+
const h = u((e) => {
|
|
1719
|
+
a = e;
|
|
1720
|
+
});
|
|
1721
|
+
function b() {
|
|
1722
|
+
if (s)
|
|
1723
|
+
return l = true, c(undefined);
|
|
1724
|
+
s = true;
|
|
1725
|
+
return te(t, { _chunkSteps: (e) => {
|
|
1726
|
+
y(() => {
|
|
1727
|
+
l = false;
|
|
1728
|
+
const t = e, r = e;
|
|
1729
|
+
d || Rr(n._readableStreamController, t), f || Rr(i._readableStreamController, r), s = false, l && b();
|
|
1730
|
+
});
|
|
1731
|
+
}, _closeSteps: () => {
|
|
1732
|
+
s = false, d || wr(n._readableStreamController), f || wr(i._readableStreamController), d && f || a(undefined);
|
|
1733
|
+
}, _errorSteps: () => {
|
|
1734
|
+
s = false;
|
|
1735
|
+
} }), c(undefined);
|
|
1736
|
+
}
|
|
1737
|
+
function m(t) {
|
|
1738
|
+
if (d = true, r = t, f) {
|
|
1739
|
+
const t = le([r, o]), n = Mr(e, t);
|
|
1740
|
+
a(n);
|
|
1741
|
+
}
|
|
1742
|
+
return h;
|
|
1743
|
+
}
|
|
1744
|
+
function p(t) {
|
|
1745
|
+
if (f = true, o = t, d) {
|
|
1746
|
+
const t = le([r, o]), n = Mr(e, t);
|
|
1747
|
+
a(n);
|
|
1748
|
+
}
|
|
1749
|
+
return h;
|
|
1750
|
+
}
|
|
1751
|
+
function S() {}
|
|
1752
|
+
return n = Dr(S, b, m), i = Dr(S, b, p), _(t._closedPromise, (e) => (Tr(n._readableStreamController, e), Tr(i._readableStreamController, e), d && f || a(undefined), null)), [n, i];
|
|
1753
|
+
}(e);
|
|
1754
|
+
}
|
|
1755
|
+
function Or(r) {
|
|
1756
|
+
return t(o = r) && o.getReader !== undefined ? function(r) {
|
|
1757
|
+
let o;
|
|
1758
|
+
function n() {
|
|
1759
|
+
let e;
|
|
1760
|
+
try {
|
|
1761
|
+
e = r.read();
|
|
1762
|
+
} catch (e) {
|
|
1763
|
+
return d(e);
|
|
1764
|
+
}
|
|
1765
|
+
return m(e, (e) => {
|
|
1766
|
+
if (!t(e))
|
|
1767
|
+
throw new TypeError("The promise returned by the reader.read() method must fulfill with an object");
|
|
1768
|
+
if (e.done)
|
|
1769
|
+
wr(o._readableStreamController);
|
|
1770
|
+
else {
|
|
1771
|
+
const t = e.value;
|
|
1772
|
+
Rr(o._readableStreamController, t);
|
|
1773
|
+
}
|
|
1774
|
+
});
|
|
1775
|
+
}
|
|
1776
|
+
function i(e) {
|
|
1777
|
+
try {
|
|
1778
|
+
return c(r.cancel(e));
|
|
1779
|
+
} catch (e) {
|
|
1780
|
+
return d(e);
|
|
1781
|
+
}
|
|
1782
|
+
}
|
|
1783
|
+
return o = Dr(e, n, i, 0), o;
|
|
1784
|
+
}(r.getReader()) : function(r) {
|
|
1785
|
+
let o;
|
|
1786
|
+
const n = me(r, "async");
|
|
1787
|
+
function i() {
|
|
1788
|
+
let e;
|
|
1789
|
+
try {
|
|
1790
|
+
e = pe(n);
|
|
1791
|
+
} catch (e) {
|
|
1792
|
+
return d(e);
|
|
1793
|
+
}
|
|
1794
|
+
return m(c(e), (e) => {
|
|
1795
|
+
if (!t(e))
|
|
1796
|
+
throw new TypeError("The promise returned by the iterator.next() method must fulfill with an object");
|
|
1797
|
+
if (e.done)
|
|
1798
|
+
wr(o._readableStreamController);
|
|
1799
|
+
else {
|
|
1800
|
+
const t = e.value;
|
|
1801
|
+
Rr(o._readableStreamController, t);
|
|
1802
|
+
}
|
|
1803
|
+
});
|
|
1804
|
+
}
|
|
1805
|
+
function a(e) {
|
|
1806
|
+
const r = n.iterator;
|
|
1807
|
+
let o;
|
|
1808
|
+
try {
|
|
1809
|
+
o = he(r, "return");
|
|
1810
|
+
} catch (e) {
|
|
1811
|
+
return d(e);
|
|
1812
|
+
}
|
|
1813
|
+
if (o === undefined)
|
|
1814
|
+
return c(undefined);
|
|
1815
|
+
return m(g(o, r, [e]), (e) => {
|
|
1816
|
+
if (!t(e))
|
|
1817
|
+
throw new TypeError("The promise returned by the iterator.return() method must fulfill with an object");
|
|
1818
|
+
});
|
|
1819
|
+
}
|
|
1820
|
+
return o = Dr(e, i, a, 0), o;
|
|
1821
|
+
}(r);
|
|
1822
|
+
var o;
|
|
1823
|
+
}
|
|
1824
|
+
function Br(e, t, r) {
|
|
1825
|
+
return I(e, r), (r) => g(e, t, [r]);
|
|
1826
|
+
}
|
|
1827
|
+
function jr(e, t, r) {
|
|
1828
|
+
return I(e, r), (r) => g(e, t, [r]);
|
|
1829
|
+
}
|
|
1830
|
+
function kr(e, t, r) {
|
|
1831
|
+
return I(e, r), (r) => S(e, t, [r]);
|
|
1832
|
+
}
|
|
1833
|
+
function Ar(e, t) {
|
|
1834
|
+
if ((e = `${e}`) !== "bytes")
|
|
1835
|
+
throw new TypeError(`${t} '${e}' is not a valid enumeration value for ReadableStreamType`);
|
|
1836
|
+
return e;
|
|
1837
|
+
}
|
|
1838
|
+
function zr(e, t) {
|
|
1839
|
+
L(e, t);
|
|
1840
|
+
const r = e == null ? undefined : e.preventAbort, o = e == null ? undefined : e.preventCancel, n = e == null ? undefined : e.preventClose, i = e == null ? undefined : e.signal;
|
|
1841
|
+
return i !== undefined && function(e, t) {
|
|
1842
|
+
if (!function(e) {
|
|
1843
|
+
if (typeof e != "object" || e === null)
|
|
1844
|
+
return false;
|
|
1845
|
+
try {
|
|
1846
|
+
return typeof e.aborted == "boolean";
|
|
1847
|
+
} catch (e) {
|
|
1848
|
+
return false;
|
|
1849
|
+
}
|
|
1850
|
+
}(e))
|
|
1851
|
+
throw new TypeError(`${t} is not an AbortSignal.`);
|
|
1852
|
+
}(i, `${t} has member 'signal' that`), { preventAbort: Boolean(r), preventCancel: Boolean(o), preventClose: Boolean(n), signal: i };
|
|
1853
|
+
}
|
|
1854
|
+
Object.defineProperties(ReadableStreamDefaultController.prototype, { close: { enumerable: true }, enqueue: { enumerable: true }, error: { enumerable: true }, desiredSize: { enumerable: true } }), o(ReadableStreamDefaultController.prototype.close, "close"), o(ReadableStreamDefaultController.prototype.enqueue, "enqueue"), o(ReadableStreamDefaultController.prototype.error, "error"), typeof Symbol.toStringTag == "symbol" && Object.defineProperty(ReadableStreamDefaultController.prototype, Symbol.toStringTag, { value: "ReadableStreamDefaultController", configurable: true });
|
|
1855
|
+
|
|
1856
|
+
class ReadableStream {
|
|
1857
|
+
constructor(e = {}, t = {}) {
|
|
1858
|
+
e === undefined ? e = null : $(e, "First parameter");
|
|
1859
|
+
const r = yt(t, "Second parameter"), o = function(e, t) {
|
|
1860
|
+
L(e, t);
|
|
1861
|
+
const r = e, o = r == null ? undefined : r.autoAllocateChunkSize, n = r == null ? undefined : r.cancel, i = r == null ? undefined : r.pull, a = r == null ? undefined : r.start, s = r == null ? undefined : r.type;
|
|
1862
|
+
return { autoAllocateChunkSize: o === undefined ? undefined : N(o, `${t} has member 'autoAllocateChunkSize' that`), cancel: n === undefined ? undefined : Br(n, r, `${t} has member 'cancel' that`), pull: i === undefined ? undefined : jr(i, r, `${t} has member 'pull' that`), start: a === undefined ? undefined : kr(a, r, `${t} has member 'start' that`), type: s === undefined ? undefined : Ar(s, `${t} has member 'type' that`) };
|
|
1863
|
+
}(e, "First parameter");
|
|
1864
|
+
if (Lr(this), o.type === "bytes") {
|
|
1865
|
+
if (r.size !== undefined)
|
|
1866
|
+
throw new RangeError("The strategy for a byte stream cannot have a size function");
|
|
1867
|
+
(function(e, t, r) {
|
|
1868
|
+
const o = Object.create(ReadableByteStreamController.prototype);
|
|
1869
|
+
let n, i, a;
|
|
1870
|
+
n = t.start !== undefined ? () => t.start(o) : () => {}, i = t.pull !== undefined ? () => t.pull(o) : () => c(undefined), a = t.cancel !== undefined ? (e) => t.cancel(e) : () => c(undefined);
|
|
1871
|
+
const s = t.autoAllocateChunkSize;
|
|
1872
|
+
if (s === 0)
|
|
1873
|
+
throw new TypeError("autoAllocateChunkSize must be greater than 0");
|
|
1874
|
+
rt(e, o, n, i, a, r, s);
|
|
1875
|
+
})(this, o, mt(r, 0));
|
|
1876
|
+
} else {
|
|
1877
|
+
const e = pt(r);
|
|
1878
|
+
(function(e, t, r, o) {
|
|
1879
|
+
const n = Object.create(ReadableStreamDefaultController.prototype);
|
|
1880
|
+
let i, a, s;
|
|
1881
|
+
i = t.start !== undefined ? () => t.start(n) : () => {}, a = t.pull !== undefined ? () => t.pull(n) : () => c(undefined), s = t.cancel !== undefined ? (e) => t.cancel(e) : () => c(undefined), qr(e, n, i, a, s, r, o);
|
|
1882
|
+
})(this, o, mt(r, 1), e);
|
|
1883
|
+
}
|
|
1884
|
+
}
|
|
1885
|
+
get locked() {
|
|
1886
|
+
if (!Ir(this))
|
|
1887
|
+
throw Qr("locked");
|
|
1888
|
+
return $r(this);
|
|
1889
|
+
}
|
|
1890
|
+
cancel(e = undefined) {
|
|
1891
|
+
return Ir(this) ? $r(this) ? d(new TypeError("Cannot cancel a stream that already has a reader")) : Mr(this, e) : d(Qr("cancel"));
|
|
1892
|
+
}
|
|
1893
|
+
getReader(e = undefined) {
|
|
1894
|
+
if (!Ir(this))
|
|
1895
|
+
throw Qr("getReader");
|
|
1896
|
+
return function(e, t) {
|
|
1897
|
+
L(e, t);
|
|
1898
|
+
const r = e == null ? undefined : e.mode;
|
|
1899
|
+
return { mode: r === undefined ? undefined : it(r, `${t} has member 'mode' that`) };
|
|
1900
|
+
}(e, "First parameter").mode === undefined ? V(this) : at(this);
|
|
1901
|
+
}
|
|
1902
|
+
pipeThrough(e, t = {}) {
|
|
1903
|
+
if (!Ir(this))
|
|
1904
|
+
throw Qr("pipeThrough");
|
|
1905
|
+
M(e, 1, "pipeThrough");
|
|
1906
|
+
const r = function(e, t) {
|
|
1907
|
+
L(e, t);
|
|
1908
|
+
const r = e == null ? undefined : e.readable;
|
|
1909
|
+
Y(r, "readable", "ReadableWritablePair"), H(r, `${t} has member 'readable' that`);
|
|
1910
|
+
const o = e == null ? undefined : e.writable;
|
|
1911
|
+
return Y(o, "writable", "ReadableWritablePair"), Tt(o, `${t} has member 'writable' that`), { readable: r, writable: o };
|
|
1912
|
+
}(e, "First parameter"), o = zr(t, "Second parameter");
|
|
1913
|
+
if ($r(this))
|
|
1914
|
+
throw new TypeError("ReadableStream.prototype.pipeThrough cannot be used on a locked ReadableStream");
|
|
1915
|
+
if (Et(r.writable))
|
|
1916
|
+
throw new TypeError("ReadableStream.prototype.pipeThrough cannot be used on a locked WritableStream");
|
|
1917
|
+
return p(hr(this, r.writable, o.preventClose, o.preventAbort, o.preventCancel, o.signal)), r.readable;
|
|
1918
|
+
}
|
|
1919
|
+
pipeTo(e, t = {}) {
|
|
1920
|
+
if (!Ir(this))
|
|
1921
|
+
return d(Qr("pipeTo"));
|
|
1922
|
+
if (e === undefined)
|
|
1923
|
+
return d("Parameter 1 is required in 'pipeTo'.");
|
|
1924
|
+
if (!qt(e))
|
|
1925
|
+
return d(new TypeError("ReadableStream.prototype.pipeTo's first argument must be a WritableStream"));
|
|
1926
|
+
let r;
|
|
1927
|
+
try {
|
|
1928
|
+
r = zr(t, "Second parameter");
|
|
1929
|
+
} catch (e) {
|
|
1930
|
+
return d(e);
|
|
1931
|
+
}
|
|
1932
|
+
return $r(this) ? d(new TypeError("ReadableStream.prototype.pipeTo cannot be used on a locked ReadableStream")) : Et(e) ? d(new TypeError("ReadableStream.prototype.pipeTo cannot be used on a locked WritableStream")) : hr(this, e, r.preventClose, r.preventAbort, r.preventCancel, r.signal);
|
|
1933
|
+
}
|
|
1934
|
+
tee() {
|
|
1935
|
+
if (!Ir(this))
|
|
1936
|
+
throw Qr("tee");
|
|
1937
|
+
return le(Wr(this));
|
|
1938
|
+
}
|
|
1939
|
+
values(e = undefined) {
|
|
1940
|
+
if (!Ir(this))
|
|
1941
|
+
throw Qr("values");
|
|
1942
|
+
return function(e, t) {
|
|
1943
|
+
const r = V(e), o = new ye(r, t), n = Object.create(ge);
|
|
1944
|
+
return n._asyncIteratorImpl = o, n;
|
|
1945
|
+
}(this, function(e, t) {
|
|
1946
|
+
L(e, t);
|
|
1947
|
+
const r = e == null ? undefined : e.preventCancel;
|
|
1948
|
+
return { preventCancel: Boolean(r) };
|
|
1949
|
+
}(e, "First parameter").preventCancel);
|
|
1950
|
+
}
|
|
1951
|
+
[_e](e) {
|
|
1952
|
+
return this.values(e);
|
|
1953
|
+
}
|
|
1954
|
+
static from(e) {
|
|
1955
|
+
return Or(e);
|
|
1956
|
+
}
|
|
1957
|
+
}
|
|
1958
|
+
function Dr(e, t, r, o = 1, n = () => 1) {
|
|
1959
|
+
const i = Object.create(ReadableStream.prototype);
|
|
1960
|
+
Lr(i);
|
|
1961
|
+
return qr(i, Object.create(ReadableStreamDefaultController.prototype), e, t, r, o, n), i;
|
|
1962
|
+
}
|
|
1963
|
+
function Fr(e, t, r) {
|
|
1964
|
+
const o = Object.create(ReadableStream.prototype);
|
|
1965
|
+
Lr(o);
|
|
1966
|
+
return rt(o, Object.create(ReadableByteStreamController.prototype), e, t, r, 0, undefined), o;
|
|
1967
|
+
}
|
|
1968
|
+
function Lr(e) {
|
|
1969
|
+
e._state = "readable", e._reader = undefined, e._storedError = undefined, e._disturbed = false;
|
|
1970
|
+
}
|
|
1971
|
+
function Ir(e) {
|
|
1972
|
+
return !!t(e) && (!!Object.prototype.hasOwnProperty.call(e, "_readableStreamController") && e instanceof ReadableStream);
|
|
1973
|
+
}
|
|
1974
|
+
function $r(e) {
|
|
1975
|
+
return e._reader !== undefined;
|
|
1976
|
+
}
|
|
1977
|
+
function Mr(t, r) {
|
|
1978
|
+
if (t._disturbed = true, t._state === "closed")
|
|
1979
|
+
return c(undefined);
|
|
1980
|
+
if (t._state === "errored")
|
|
1981
|
+
return d(t._storedError);
|
|
1982
|
+
Yr(t);
|
|
1983
|
+
const o = t._reader;
|
|
1984
|
+
if (o !== undefined && ft(o)) {
|
|
1985
|
+
const e = o._readIntoRequests;
|
|
1986
|
+
o._readIntoRequests = new v, e.forEach((e) => {
|
|
1987
|
+
e._closeSteps(undefined);
|
|
1988
|
+
});
|
|
1989
|
+
}
|
|
1990
|
+
return m(t._readableStreamController[T](r), e);
|
|
1991
|
+
}
|
|
1992
|
+
function Yr(e) {
|
|
1993
|
+
e._state = "closed";
|
|
1994
|
+
const t = e._reader;
|
|
1995
|
+
if (t !== undefined && (z(t), ee(t))) {
|
|
1996
|
+
const e = t._readRequests;
|
|
1997
|
+
t._readRequests = new v, e.forEach((e) => {
|
|
1998
|
+
e._closeSteps();
|
|
1999
|
+
});
|
|
2000
|
+
}
|
|
2001
|
+
}
|
|
2002
|
+
function xr(e, t) {
|
|
2003
|
+
e._state = "errored", e._storedError = t;
|
|
2004
|
+
const r = e._reader;
|
|
2005
|
+
r !== undefined && (A(r, t), ee(r) ? oe(r, t) : bt(r, t));
|
|
2006
|
+
}
|
|
2007
|
+
function Qr(e) {
|
|
2008
|
+
return new TypeError(`ReadableStream.prototype.${e} can only be used on a ReadableStream`);
|
|
2009
|
+
}
|
|
2010
|
+
function Nr(e, t) {
|
|
2011
|
+
L(e, t);
|
|
2012
|
+
const r = e == null ? undefined : e.highWaterMark;
|
|
2013
|
+
return Y(r, "highWaterMark", "QueuingStrategyInit"), { highWaterMark: x(r) };
|
|
2014
|
+
}
|
|
2015
|
+
Object.defineProperties(ReadableStream, { from: { enumerable: true } }), Object.defineProperties(ReadableStream.prototype, { cancel: { enumerable: true }, getReader: { enumerable: true }, pipeThrough: { enumerable: true }, pipeTo: { enumerable: true }, tee: { enumerable: true }, values: { enumerable: true }, locked: { enumerable: true } }), o(ReadableStream.from, "from"), o(ReadableStream.prototype.cancel, "cancel"), o(ReadableStream.prototype.getReader, "getReader"), o(ReadableStream.prototype.pipeThrough, "pipeThrough"), o(ReadableStream.prototype.pipeTo, "pipeTo"), o(ReadableStream.prototype.tee, "tee"), o(ReadableStream.prototype.values, "values"), typeof Symbol.toStringTag == "symbol" && Object.defineProperty(ReadableStream.prototype, Symbol.toStringTag, { value: "ReadableStream", configurable: true }), Object.defineProperty(ReadableStream.prototype, _e, { value: ReadableStream.prototype.values, writable: true, configurable: true });
|
|
2016
|
+
var Hr = (e) => e.byteLength;
|
|
2017
|
+
o(Hr, "size");
|
|
2018
|
+
|
|
2019
|
+
class ByteLengthQueuingStrategy {
|
|
2020
|
+
constructor(e) {
|
|
2021
|
+
M(e, 1, "ByteLengthQueuingStrategy"), e = Nr(e, "First parameter"), this._byteLengthQueuingStrategyHighWaterMark = e.highWaterMark;
|
|
2022
|
+
}
|
|
2023
|
+
get highWaterMark() {
|
|
2024
|
+
if (!Ur(this))
|
|
2025
|
+
throw Vr("highWaterMark");
|
|
2026
|
+
return this._byteLengthQueuingStrategyHighWaterMark;
|
|
2027
|
+
}
|
|
2028
|
+
get size() {
|
|
2029
|
+
if (!Ur(this))
|
|
2030
|
+
throw Vr("size");
|
|
2031
|
+
return Hr;
|
|
2032
|
+
}
|
|
2033
|
+
}
|
|
2034
|
+
function Vr(e) {
|
|
2035
|
+
return new TypeError(`ByteLengthQueuingStrategy.prototype.${e} can only be used on a ByteLengthQueuingStrategy`);
|
|
2036
|
+
}
|
|
2037
|
+
function Ur(e) {
|
|
2038
|
+
return !!t(e) && (!!Object.prototype.hasOwnProperty.call(e, "_byteLengthQueuingStrategyHighWaterMark") && e instanceof ByteLengthQueuingStrategy);
|
|
2039
|
+
}
|
|
2040
|
+
Object.defineProperties(ByteLengthQueuingStrategy.prototype, { highWaterMark: { enumerable: true }, size: { enumerable: true } }), typeof Symbol.toStringTag == "symbol" && Object.defineProperty(ByteLengthQueuingStrategy.prototype, Symbol.toStringTag, { value: "ByteLengthQueuingStrategy", configurable: true });
|
|
2041
|
+
var Gr = () => 1;
|
|
2042
|
+
o(Gr, "size");
|
|
2043
|
+
|
|
2044
|
+
class CountQueuingStrategy {
|
|
2045
|
+
constructor(e) {
|
|
2046
|
+
M(e, 1, "CountQueuingStrategy"), e = Nr(e, "First parameter"), this._countQueuingStrategyHighWaterMark = e.highWaterMark;
|
|
2047
|
+
}
|
|
2048
|
+
get highWaterMark() {
|
|
2049
|
+
if (!Jr(this))
|
|
2050
|
+
throw Xr("highWaterMark");
|
|
2051
|
+
return this._countQueuingStrategyHighWaterMark;
|
|
2052
|
+
}
|
|
2053
|
+
get size() {
|
|
2054
|
+
if (!Jr(this))
|
|
2055
|
+
throw Xr("size");
|
|
2056
|
+
return Gr;
|
|
2057
|
+
}
|
|
2058
|
+
}
|
|
2059
|
+
function Xr(e) {
|
|
2060
|
+
return new TypeError(`CountQueuingStrategy.prototype.${e} can only be used on a CountQueuingStrategy`);
|
|
2061
|
+
}
|
|
2062
|
+
function Jr(e) {
|
|
2063
|
+
return !!t(e) && (!!Object.prototype.hasOwnProperty.call(e, "_countQueuingStrategyHighWaterMark") && e instanceof CountQueuingStrategy);
|
|
2064
|
+
}
|
|
2065
|
+
function Kr(e, t, r) {
|
|
2066
|
+
return I(e, r), (r) => g(e, t, [r]);
|
|
2067
|
+
}
|
|
2068
|
+
function Zr(e, t, r) {
|
|
2069
|
+
return I(e, r), (r) => S(e, t, [r]);
|
|
2070
|
+
}
|
|
2071
|
+
function eo(e, t, r) {
|
|
2072
|
+
return I(e, r), (r, o) => g(e, t, [r, o]);
|
|
2073
|
+
}
|
|
2074
|
+
function to(e, t, r) {
|
|
2075
|
+
return I(e, r), (r) => g(e, t, [r]);
|
|
2076
|
+
}
|
|
2077
|
+
Object.defineProperties(CountQueuingStrategy.prototype, { highWaterMark: { enumerable: true }, size: { enumerable: true } }), typeof Symbol.toStringTag == "symbol" && Object.defineProperty(CountQueuingStrategy.prototype, Symbol.toStringTag, { value: "CountQueuingStrategy", configurable: true });
|
|
2078
|
+
|
|
2079
|
+
class TransformStream {
|
|
2080
|
+
constructor(e = {}, t = {}, r = {}) {
|
|
2081
|
+
e === undefined && (e = null);
|
|
2082
|
+
const o = yt(t, "Second parameter"), n = yt(r, "Third parameter"), i = function(e, t) {
|
|
2083
|
+
L(e, t);
|
|
2084
|
+
const r = e == null ? undefined : e.cancel, o = e == null ? undefined : e.flush, n = e == null ? undefined : e.readableType, i = e == null ? undefined : e.start, a = e == null ? undefined : e.transform, s = e == null ? undefined : e.writableType;
|
|
2085
|
+
return { cancel: r === undefined ? undefined : to(r, e, `${t} has member 'cancel' that`), flush: o === undefined ? undefined : Kr(o, e, `${t} has member 'flush' that`), readableType: n, start: i === undefined ? undefined : Zr(i, e, `${t} has member 'start' that`), transform: a === undefined ? undefined : eo(a, e, `${t} has member 'transform' that`), writableType: s };
|
|
2086
|
+
}(e, "First parameter");
|
|
2087
|
+
if (i.readableType !== undefined)
|
|
2088
|
+
throw new RangeError("Invalid readableType specified");
|
|
2089
|
+
if (i.writableType !== undefined)
|
|
2090
|
+
throw new RangeError("Invalid writableType specified");
|
|
2091
|
+
const a = mt(n, 0), s = pt(n), l = mt(o, 1), f = pt(o);
|
|
2092
|
+
let b;
|
|
2093
|
+
(function(e, t, r, o, n, i) {
|
|
2094
|
+
function a() {
|
|
2095
|
+
return t;
|
|
2096
|
+
}
|
|
2097
|
+
function s(t) {
|
|
2098
|
+
return function(e, t) {
|
|
2099
|
+
const r = e._transformStreamController;
|
|
2100
|
+
if (e._backpressure) {
|
|
2101
|
+
return m(e._backpressureChangePromise, () => {
|
|
2102
|
+
const o = e._writable;
|
|
2103
|
+
if (o._state === "erroring")
|
|
2104
|
+
throw o._storedError;
|
|
2105
|
+
return co(r, t);
|
|
2106
|
+
});
|
|
2107
|
+
}
|
|
2108
|
+
return co(r, t);
|
|
2109
|
+
}(e, t);
|
|
2110
|
+
}
|
|
2111
|
+
function l(t) {
|
|
2112
|
+
return function(e, t) {
|
|
2113
|
+
const r = e._transformStreamController;
|
|
2114
|
+
if (r._finishPromise !== undefined)
|
|
2115
|
+
return r._finishPromise;
|
|
2116
|
+
const o = e._readable;
|
|
2117
|
+
r._finishPromise = u((e, t) => {
|
|
2118
|
+
r._finishPromise_resolve = e, r._finishPromise_reject = t;
|
|
2119
|
+
});
|
|
2120
|
+
const n = r._cancelAlgorithm(t);
|
|
2121
|
+
return lo(r), h(n, () => (o._state === "errored" ? bo(r, o._storedError) : (Tr(o._readableStreamController, t), ho(r)), null), (e) => (Tr(o._readableStreamController, e), bo(r, e), null)), r._finishPromise;
|
|
2122
|
+
}(e, t);
|
|
2123
|
+
}
|
|
2124
|
+
function c() {
|
|
2125
|
+
return function(e) {
|
|
2126
|
+
const t = e._transformStreamController;
|
|
2127
|
+
if (t._finishPromise !== undefined)
|
|
2128
|
+
return t._finishPromise;
|
|
2129
|
+
const r = e._readable;
|
|
2130
|
+
t._finishPromise = u((e, r) => {
|
|
2131
|
+
t._finishPromise_resolve = e, t._finishPromise_reject = r;
|
|
2132
|
+
});
|
|
2133
|
+
const o = t._flushAlgorithm();
|
|
2134
|
+
return lo(t), h(o, () => (r._state === "errored" ? bo(t, r._storedError) : (wr(r._readableStreamController), ho(t)), null), (e) => (Tr(r._readableStreamController, e), bo(t, e), null)), t._finishPromise;
|
|
2135
|
+
}(e);
|
|
2136
|
+
}
|
|
2137
|
+
function d() {
|
|
2138
|
+
return function(e) {
|
|
2139
|
+
return ao(e, false), e._backpressureChangePromise;
|
|
2140
|
+
}(e);
|
|
2141
|
+
}
|
|
2142
|
+
function f(t) {
|
|
2143
|
+
return function(e, t) {
|
|
2144
|
+
const r = e._transformStreamController;
|
|
2145
|
+
if (r._finishPromise !== undefined)
|
|
2146
|
+
return r._finishPromise;
|
|
2147
|
+
const o = e._writable;
|
|
2148
|
+
r._finishPromise = u((e, t) => {
|
|
2149
|
+
r._finishPromise_resolve = e, r._finishPromise_reject = t;
|
|
2150
|
+
});
|
|
2151
|
+
const n = r._cancelAlgorithm(t);
|
|
2152
|
+
return lo(r), h(n, () => (o._state === "errored" ? bo(r, o._storedError) : (Gt(o._writableStreamController, t), io(e), ho(r)), null), (t) => (Gt(o._writableStreamController, t), io(e), bo(r, t), null)), r._finishPromise;
|
|
2153
|
+
}(e, t);
|
|
2154
|
+
}
|
|
2155
|
+
e._writable = function(e, t, r, o, n = 1, i = () => 1) {
|
|
2156
|
+
const a = Object.create(WritableStream.prototype);
|
|
2157
|
+
return Ct(a), Nt(a, Object.create(WritableStreamDefaultController.prototype), e, t, r, o, n, i), a;
|
|
2158
|
+
}(a, s, c, l, r, o), e._readable = Dr(a, d, f, n, i), e._backpressure = undefined, e._backpressureChangePromise = undefined, e._backpressureChangePromise_resolve = undefined, ao(e, true), e._transformStreamController = undefined;
|
|
2159
|
+
})(this, u((e) => {
|
|
2160
|
+
b = e;
|
|
2161
|
+
}), l, f, a, s), function(e, t) {
|
|
2162
|
+
const r = Object.create(TransformStreamDefaultController.prototype);
|
|
2163
|
+
let o, n, i;
|
|
2164
|
+
o = t.transform !== undefined ? (e) => t.transform(e, r) : (e) => {
|
|
2165
|
+
try {
|
|
2166
|
+
return uo(r, e), c(undefined);
|
|
2167
|
+
} catch (e) {
|
|
2168
|
+
return d(e);
|
|
2169
|
+
}
|
|
2170
|
+
};
|
|
2171
|
+
n = t.flush !== undefined ? () => t.flush(r) : () => c(undefined);
|
|
2172
|
+
i = t.cancel !== undefined ? (e) => t.cancel(e) : () => c(undefined);
|
|
2173
|
+
(function(e, t, r, o, n) {
|
|
2174
|
+
t._controlledTransformStream = e, e._transformStreamController = t, t._transformAlgorithm = r, t._flushAlgorithm = o, t._cancelAlgorithm = n, t._finishPromise = undefined, t._finishPromise_resolve = undefined, t._finishPromise_reject = undefined;
|
|
2175
|
+
})(e, r, o, n, i);
|
|
2176
|
+
}(this, i), i.start !== undefined ? b(i.start(this._transformStreamController)) : b(undefined);
|
|
2177
|
+
}
|
|
2178
|
+
get readable() {
|
|
2179
|
+
if (!ro(this))
|
|
2180
|
+
throw _o("readable");
|
|
2181
|
+
return this._readable;
|
|
2182
|
+
}
|
|
2183
|
+
get writable() {
|
|
2184
|
+
if (!ro(this))
|
|
2185
|
+
throw _o("writable");
|
|
2186
|
+
return this._writable;
|
|
2187
|
+
}
|
|
2188
|
+
}
|
|
2189
|
+
function ro(e) {
|
|
2190
|
+
return !!t(e) && (!!Object.prototype.hasOwnProperty.call(e, "_transformStreamController") && e instanceof TransformStream);
|
|
2191
|
+
}
|
|
2192
|
+
function oo(e, t) {
|
|
2193
|
+
Tr(e._readable._readableStreamController, t), no(e, t);
|
|
2194
|
+
}
|
|
2195
|
+
function no(e, t) {
|
|
2196
|
+
lo(e._transformStreamController), Gt(e._writable._writableStreamController, t), io(e);
|
|
2197
|
+
}
|
|
2198
|
+
function io(e) {
|
|
2199
|
+
e._backpressure && ao(e, false);
|
|
2200
|
+
}
|
|
2201
|
+
function ao(e, t) {
|
|
2202
|
+
e._backpressureChangePromise !== undefined && e._backpressureChangePromise_resolve(), e._backpressureChangePromise = u((t) => {
|
|
2203
|
+
e._backpressureChangePromise_resolve = t;
|
|
2204
|
+
}), e._backpressure = t;
|
|
2205
|
+
}
|
|
2206
|
+
Object.defineProperties(TransformStream.prototype, { readable: { enumerable: true }, writable: { enumerable: true } }), typeof Symbol.toStringTag == "symbol" && Object.defineProperty(TransformStream.prototype, Symbol.toStringTag, { value: "TransformStream", configurable: true });
|
|
2207
|
+
|
|
2208
|
+
class TransformStreamDefaultController {
|
|
2209
|
+
constructor() {
|
|
2210
|
+
throw new TypeError("Illegal constructor");
|
|
2211
|
+
}
|
|
2212
|
+
get desiredSize() {
|
|
2213
|
+
if (!so(this))
|
|
2214
|
+
throw fo("desiredSize");
|
|
2215
|
+
return Pr(this._controlledTransformStream._readable._readableStreamController);
|
|
2216
|
+
}
|
|
2217
|
+
enqueue(e = undefined) {
|
|
2218
|
+
if (!so(this))
|
|
2219
|
+
throw fo("enqueue");
|
|
2220
|
+
uo(this, e);
|
|
2221
|
+
}
|
|
2222
|
+
error(e = undefined) {
|
|
2223
|
+
if (!so(this))
|
|
2224
|
+
throw fo("error");
|
|
2225
|
+
var t;
|
|
2226
|
+
t = e, oo(this._controlledTransformStream, t);
|
|
2227
|
+
}
|
|
2228
|
+
terminate() {
|
|
2229
|
+
if (!so(this))
|
|
2230
|
+
throw fo("terminate");
|
|
2231
|
+
(function(e) {
|
|
2232
|
+
const t = e._controlledTransformStream;
|
|
2233
|
+
wr(t._readable._readableStreamController);
|
|
2234
|
+
const r = new TypeError("TransformStream terminated");
|
|
2235
|
+
no(t, r);
|
|
2236
|
+
})(this);
|
|
2237
|
+
}
|
|
2238
|
+
}
|
|
2239
|
+
function so(e) {
|
|
2240
|
+
return !!t(e) && (!!Object.prototype.hasOwnProperty.call(e, "_controlledTransformStream") && e instanceof TransformStreamDefaultController);
|
|
2241
|
+
}
|
|
2242
|
+
function lo(e) {
|
|
2243
|
+
e._transformAlgorithm = undefined, e._flushAlgorithm = undefined, e._cancelAlgorithm = undefined;
|
|
2244
|
+
}
|
|
2245
|
+
function uo(e, t) {
|
|
2246
|
+
const r = e._controlledTransformStream, o = r._readable._readableStreamController;
|
|
2247
|
+
if (!Cr(o))
|
|
2248
|
+
throw new TypeError("Readable side is not in a state that permits enqueue");
|
|
2249
|
+
try {
|
|
2250
|
+
Rr(o, t);
|
|
2251
|
+
} catch (e) {
|
|
2252
|
+
throw no(r, e), r._readable._storedError;
|
|
2253
|
+
}
|
|
2254
|
+
const n = function(e) {
|
|
2255
|
+
return !gr(e);
|
|
2256
|
+
}(o);
|
|
2257
|
+
n !== r._backpressure && ao(r, true);
|
|
2258
|
+
}
|
|
2259
|
+
function co(e, t) {
|
|
2260
|
+
return m(e._transformAlgorithm(t), undefined, (t) => {
|
|
2261
|
+
throw oo(e._controlledTransformStream, t), t;
|
|
2262
|
+
});
|
|
2263
|
+
}
|
|
2264
|
+
function fo(e) {
|
|
2265
|
+
return new TypeError(`TransformStreamDefaultController.prototype.${e} can only be used on a TransformStreamDefaultController`);
|
|
2266
|
+
}
|
|
2267
|
+
function ho(e) {
|
|
2268
|
+
e._finishPromise_resolve !== undefined && (e._finishPromise_resolve(), e._finishPromise_resolve = undefined, e._finishPromise_reject = undefined);
|
|
2269
|
+
}
|
|
2270
|
+
function bo(e, t) {
|
|
2271
|
+
e._finishPromise_reject !== undefined && (p(e._finishPromise), e._finishPromise_reject(t), e._finishPromise_resolve = undefined, e._finishPromise_reject = undefined);
|
|
2272
|
+
}
|
|
2273
|
+
function _o(e) {
|
|
2274
|
+
return new TypeError(`TransformStream.prototype.${e} can only be used on a TransformStream`);
|
|
2275
|
+
}
|
|
2276
|
+
Object.defineProperties(TransformStreamDefaultController.prototype, { enqueue: { enumerable: true }, error: { enumerable: true }, terminate: { enumerable: true }, desiredSize: { enumerable: true } }), o(TransformStreamDefaultController.prototype.enqueue, "enqueue"), o(TransformStreamDefaultController.prototype.error, "error"), o(TransformStreamDefaultController.prototype.terminate, "terminate"), typeof Symbol.toStringTag == "symbol" && Object.defineProperty(TransformStreamDefaultController.prototype, Symbol.toStringTag, { value: "TransformStreamDefaultController", configurable: true });
|
|
2277
|
+
// streams-entry.js
|
|
2278
|
+
if (globalThis.ByteLengthQueuingStrategy == null)
|
|
2279
|
+
globalThis.ByteLengthQueuingStrategy = ByteLengthQueuingStrategy;
|
|
2280
|
+
if (globalThis.CountQueuingStrategy == null)
|
|
2281
|
+
globalThis.CountQueuingStrategy = CountQueuingStrategy;
|
|
2282
|
+
if (globalThis.ReadableByteStreamController == null)
|
|
2283
|
+
globalThis.ReadableByteStreamController = ReadableByteStreamController;
|
|
2284
|
+
if (globalThis.ReadableStream == null)
|
|
2285
|
+
globalThis.ReadableStream = ReadableStream;
|
|
2286
|
+
if (globalThis.ReadableStreamBYOBReader == null)
|
|
2287
|
+
globalThis.ReadableStreamBYOBReader = ReadableStreamBYOBReader;
|
|
2288
|
+
if (globalThis.ReadableStreamBYOBRequest == null)
|
|
2289
|
+
globalThis.ReadableStreamBYOBRequest = ReadableStreamBYOBRequest;
|
|
2290
|
+
if (globalThis.ReadableStreamDefaultController == null)
|
|
2291
|
+
globalThis.ReadableStreamDefaultController = ReadableStreamDefaultController;
|
|
2292
|
+
if (globalThis.ReadableStreamDefaultReader == null)
|
|
2293
|
+
globalThis.ReadableStreamDefaultReader = ReadableStreamDefaultReader;
|
|
2294
|
+
if (globalThis.TransformStream == null)
|
|
2295
|
+
globalThis.TransformStream = TransformStream;
|
|
2296
|
+
if (globalThis.TransformStreamDefaultController == null)
|
|
2297
|
+
globalThis.TransformStreamDefaultController = TransformStreamDefaultController;
|
|
2298
|
+
if (globalThis.WritableStream == null)
|
|
2299
|
+
globalThis.WritableStream = WritableStream;
|
|
2300
|
+
if (globalThis.WritableStreamDefaultController == null)
|
|
2301
|
+
globalThis.WritableStreamDefaultController = WritableStreamDefaultController;
|
|
2302
|
+
if (globalThis.WritableStreamDefaultWriter == null)
|
|
2303
|
+
globalThis.WritableStreamDefaultWriter = WritableStreamDefaultWriter;
|
|
2304
|
+
|
|
2305
|
+
/* oxlint-enable */
|
|
2306
|
+
// END WEB STREAMS
|
|
2307
|
+
|
|
2308
|
+
// Porffor exposes native timers lexically. Libraries also access them through
|
|
2309
|
+
// globalThis, including noble hashes 2.4's host-task yields.
|
|
2310
|
+
if (globalThis.setTimeout == null) globalThis.setTimeout = setTimeout;
|
|
2311
|
+
if (globalThis.clearTimeout == null) globalThis.clearTimeout = clearTimeout;
|
|
2312
|
+
if (globalThis.setInterval == null) globalThis.setInterval = setInterval;
|
|
2313
|
+
if (globalThis.clearInterval == null) globalThis.clearInterval = clearInterval;
|
|
2314
|
+
|
|
1
2315
|
// Prepended to every handler by tools/compile.ts, before Porffor's native-fetch
|
|
2
2316
|
// bundled handler. Porffor's runtime/fetch-globals.js (checked through alpha-10)
|
|
3
2317
|
// gives URL (href/origin/pathname/search only) and Response without static
|
|
@@ -111,8 +2425,38 @@ function __sbCollectionIterator(owner, kind, formData) {
|
|
|
111
2425
|
|
|
112
2426
|
class __SproutboatURLSearchParams {
|
|
113
2427
|
constructor(init) {
|
|
2428
|
+
this._url = null;
|
|
2429
|
+
this._reset(init);
|
|
2430
|
+
}
|
|
2431
|
+
// A URL's searchParams writes back into it (_url), and is re-read when the URL's
|
|
2432
|
+
// search is assigned (_reset).
|
|
2433
|
+
_reset(init) {
|
|
114
2434
|
this._keys = [];
|
|
115
2435
|
this._vals = [];
|
|
2436
|
+
// The URLSearchParams init forms: another URLSearchParams, a sequence of [name, value]
|
|
2437
|
+
// pairs, a record of own string keys, or a query string. Only strings were read, so
|
|
2438
|
+
// new URLSearchParams({ a: "1" }) serialized as "%5Bobject+Object%5D=" (W2).
|
|
2439
|
+
if (init instanceof __SproutboatURLSearchParams) {
|
|
2440
|
+
this._keys = init._keys.slice();
|
|
2441
|
+
this._vals = init._vals.slice();
|
|
2442
|
+
return;
|
|
2443
|
+
}
|
|
2444
|
+
if (init != null && Object(init) === init) {
|
|
2445
|
+
if (__sbIsFn(init[Symbol.iterator])) {
|
|
2446
|
+
for (const pair of init) {
|
|
2447
|
+
const items = Array.from(pair);
|
|
2448
|
+
if (items.length !== 2) throw new TypeError("URLSearchParams: each pair must have exactly two items");
|
|
2449
|
+
this._keys.push(String(items[0]));
|
|
2450
|
+
this._vals.push(String(items[1]));
|
|
2451
|
+
}
|
|
2452
|
+
return;
|
|
2453
|
+
}
|
|
2454
|
+
for (const key of Object.keys(init)) {
|
|
2455
|
+
this._keys.push(key);
|
|
2456
|
+
this._vals.push(String(init[key]));
|
|
2457
|
+
}
|
|
2458
|
+
return;
|
|
2459
|
+
}
|
|
116
2460
|
let raw = init == null ? "" : String(init);
|
|
117
2461
|
if (raw.charCodeAt(0) === 63) raw = raw.slice(1); // strip a leading '?'
|
|
118
2462
|
if (raw.length === 0) return;
|
|
@@ -127,6 +2471,11 @@ class __SproutboatURLSearchParams {
|
|
|
127
2471
|
this._vals.push(decodeURIComponent(v.split("+").join(" ")));
|
|
128
2472
|
}
|
|
129
2473
|
}
|
|
2474
|
+
_update() {
|
|
2475
|
+
if (this._url == null) return;
|
|
2476
|
+
const s = this.toString();
|
|
2477
|
+
this._url._query = s === "" ? null : s;
|
|
2478
|
+
}
|
|
130
2479
|
get(name) {
|
|
131
2480
|
for (let i = 0; i < this._keys.length; i++) if (this._keys[i] === name) return this._vals[i];
|
|
132
2481
|
return null;
|
|
@@ -143,12 +2492,10 @@ class __SproutboatURLSearchParams {
|
|
|
143
2492
|
forEach(cb) {
|
|
144
2493
|
for (let i = 0; i < this._keys.length; i++) cb(this._vals[i], this._keys[i], this);
|
|
145
2494
|
}
|
|
146
|
-
// Mutators: standalone `new URLSearchParams()` building works. They do NOT
|
|
147
|
-
// write back into a URL's `search` (Porffor's URL has no setter) — build the
|
|
148
|
-
// string with toString() and assign it yourself.
|
|
149
2495
|
append(name, value) {
|
|
150
2496
|
this._keys.push(String(name));
|
|
151
2497
|
this._vals.push(String(value));
|
|
2498
|
+
this._update();
|
|
152
2499
|
}
|
|
153
2500
|
set(name, value) {
|
|
154
2501
|
let found = false;
|
|
@@ -163,7 +2510,11 @@ class __SproutboatURLSearchParams {
|
|
|
163
2510
|
found = true;
|
|
164
2511
|
}
|
|
165
2512
|
}
|
|
166
|
-
if (!found)
|
|
2513
|
+
if (!found) {
|
|
2514
|
+
this._keys.push(String(name));
|
|
2515
|
+
this._vals.push(String(value));
|
|
2516
|
+
}
|
|
2517
|
+
this._update();
|
|
167
2518
|
}
|
|
168
2519
|
delete(name) {
|
|
169
2520
|
for (let i = 0; i < this._keys.length; i++)
|
|
@@ -172,13 +2523,15 @@ class __SproutboatURLSearchParams {
|
|
|
172
2523
|
this._vals.splice(i, 1);
|
|
173
2524
|
i--;
|
|
174
2525
|
}
|
|
2526
|
+
this._update();
|
|
175
2527
|
}
|
|
176
2528
|
sort() {
|
|
177
2529
|
const idx = this._keys
|
|
178
2530
|
.map((_, i) => i)
|
|
179
|
-
.sort((a, b) => (this._keys[a] < this._keys[b] ? -1 : this._keys[a] > this._keys[b] ? 1 :
|
|
2531
|
+
.sort((a, b) => (this._keys[a] < this._keys[b] ? -1 : this._keys[a] > this._keys[b] ? 1 : a - b));
|
|
180
2532
|
this._keys = idx.map((i) => this._keys[i]);
|
|
181
2533
|
this._vals = idx.map((i) => this._vals[i]);
|
|
2534
|
+
this._update();
|
|
182
2535
|
}
|
|
183
2536
|
keys() {
|
|
184
2537
|
return __sbCollectionIterator(this, 0, false);
|
|
@@ -193,15 +2546,34 @@ class __SproutboatURLSearchParams {
|
|
|
193
2546
|
get size() {
|
|
194
2547
|
return this._keys.length;
|
|
195
2548
|
}
|
|
2549
|
+
// application/x-www-form-urlencoded: space is "+", and ! ' ( ) ~ are escaped too.
|
|
196
2550
|
toString() {
|
|
197
2551
|
let out = "";
|
|
198
2552
|
for (let i = 0; i < this._keys.length; i++) {
|
|
199
2553
|
if (i > 0) out += "&";
|
|
200
|
-
out +=
|
|
2554
|
+
out += __sbFormEncode(this._keys[i]) + "=" + __sbFormEncode(this._vals[i]);
|
|
201
2555
|
}
|
|
202
2556
|
return out;
|
|
203
2557
|
}
|
|
204
2558
|
}
|
|
2559
|
+
// One pass over encodeURIComponent's output (chained split/join doubled compile time).
|
|
2560
|
+
function __sbFormEncode(s) {
|
|
2561
|
+
const e = encodeURIComponent(s);
|
|
2562
|
+
let out = "";
|
|
2563
|
+
for (let i = 0; i < e.length; i++) {
|
|
2564
|
+
const c = e.charCodeAt(i);
|
|
2565
|
+
if (c === 33) out += "%21";
|
|
2566
|
+
else if (c === 39) out += "%27";
|
|
2567
|
+
else if (c === 40) out += "%28";
|
|
2568
|
+
else if (c === 41) out += "%29";
|
|
2569
|
+
else if (c === 126) out += "%7E";
|
|
2570
|
+
else if (c === 37 && e.charCodeAt(i + 1) === 50 && e.charCodeAt(i + 2) === 48) {
|
|
2571
|
+
out += "+";
|
|
2572
|
+
i += 2;
|
|
2573
|
+
} else out += e[i];
|
|
2574
|
+
}
|
|
2575
|
+
return out;
|
|
2576
|
+
}
|
|
205
2577
|
|
|
206
2578
|
// URL and Response are always defined by Porffor's fetch-globals.js banner.
|
|
207
2579
|
if (globalThis.URLSearchParams == null) globalThis.URLSearchParams = __SproutboatURLSearchParams;
|
|
@@ -218,19 +2590,39 @@ if (!("searchParams" in URL.prototype)) {
|
|
|
218
2590
|
|
|
219
2591
|
if (Response.json == null) {
|
|
220
2592
|
Response.json = function (data, init) {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
2593
|
+
// Typed before construction: a string body would otherwise default to text/plain.
|
|
2594
|
+
const headers = new Headers(init?.headers);
|
|
2595
|
+
if (!headers.has("content-type")) headers.set("content-type", "application/json");
|
|
2596
|
+
return new Response(JSON.stringify(data), { status: init?.status ?? 200, statusText: init?.statusText, headers });
|
|
224
2597
|
};
|
|
225
2598
|
}
|
|
226
2599
|
|
|
2600
|
+
// Error.stack: Porffor keeps no frames, so give V8's first line, "Name: message", rather
|
|
2601
|
+
// than undefined (code logs it or splits it on newlines).
|
|
2602
|
+
for (const E of [Error, TypeError, RangeError, ReferenceError, SyntaxError, EvalError, URIError]) {
|
|
2603
|
+
if (!("stack" in E.prototype)) {
|
|
2604
|
+
Object.defineProperty(E.prototype, "stack", {
|
|
2605
|
+
configurable: true,
|
|
2606
|
+
get() {
|
|
2607
|
+
const message = String(this.message);
|
|
2608
|
+
return message === "" ? String(this.name) : String(this.name) + ": " + message;
|
|
2609
|
+
},
|
|
2610
|
+
});
|
|
2611
|
+
}
|
|
2612
|
+
}
|
|
2613
|
+
|
|
2614
|
+
// Fetch: Headers iterates like entries(), so new Map(headers), [...headers] and
|
|
2615
|
+
// Object.fromEntries(headers) work. Porffor's Headers has entries() but no iterator.
|
|
2616
|
+
if (Headers.prototype[Symbol.iterator] == null) Headers.prototype[Symbol.iterator] = Headers.prototype.entries;
|
|
2617
|
+
|
|
227
2618
|
// Porffor alpha-10 has no static Response.redirect().
|
|
228
2619
|
if (Response.redirect == null) {
|
|
229
2620
|
Response.redirect = function (url, status = 302) {
|
|
230
2621
|
if (status !== 301 && status !== 302 && status !== 303 && status !== 307 && status !== 308) {
|
|
231
2622
|
throw new RangeError("invalid redirect status");
|
|
232
2623
|
}
|
|
233
|
-
|
|
2624
|
+
// Serialized like the URL parser does (a bare origin gains its "/"); invalid URLs throw.
|
|
2625
|
+
return new Response(null, { status, headers: { location: new URL(String(url)).href } });
|
|
234
2626
|
};
|
|
235
2627
|
}
|
|
236
2628
|
|
|
@@ -302,11 +2694,21 @@ if (globalThis.FormData == null) {
|
|
|
302
2694
|
constructor() {
|
|
303
2695
|
this._entries = [];
|
|
304
2696
|
}
|
|
2697
|
+
// A Blob value is stored as a File named by filename ("blob" by default); anything
|
|
2698
|
+
// else as a string, as the FormData spec's entry list does.
|
|
2699
|
+
static _entryValue(value, filename) {
|
|
2700
|
+
if (value instanceof Blob) {
|
|
2701
|
+
if (filename === undefined && value instanceof File) return value;
|
|
2702
|
+
return new File([value], filename === undefined ? "blob" : String(filename), { type: value.type });
|
|
2703
|
+
}
|
|
2704
|
+
return String(value);
|
|
2705
|
+
}
|
|
305
2706
|
append(name, value, filename) {
|
|
306
|
-
this._entries.push([String(name), value, filename]);
|
|
2707
|
+
this._entries.push([String(name), __SproutboatFormData._entryValue(value, filename), filename]);
|
|
307
2708
|
}
|
|
308
2709
|
set(name, value, filename) {
|
|
309
2710
|
name = String(name);
|
|
2711
|
+
value = __SproutboatFormData._entryValue(value, filename);
|
|
310
2712
|
let replaced = false;
|
|
311
2713
|
this._entries = this._entries.filter((e) => {
|
|
312
2714
|
if (e[0] !== name) return true;
|
|
@@ -462,7 +2864,12 @@ if (globalThis.crypto.getRandomValues == null) {
|
|
|
462
2864
|
globalThis.crypto.getRandomValues = function (view) {
|
|
463
2865
|
const n = view.length >>> 0;
|
|
464
2866
|
// WebCrypto caps a single call at 65536 bytes.
|
|
465
|
-
if (n > 65536)
|
|
2867
|
+
if (n > 65536) {
|
|
2868
|
+
// WebCrypto's error for an oversized request (a DOMException named QuotaExceededError).
|
|
2869
|
+
const e = new Error("crypto.getRandomValues: byte length exceeds 65536");
|
|
2870
|
+
e.name = "QuotaExceededError";
|
|
2871
|
+
throw e;
|
|
2872
|
+
}
|
|
466
2873
|
if (n === 0) return view;
|
|
467
2874
|
// One CSPRNG byte per element. Correct for Uint8Array (and randomUUID); a
|
|
468
2875
|
// wider view gets its low byte filled, matching the previous polyfill's shape.
|
|
@@ -472,17 +2879,282 @@ if (globalThis.crypto.getRandomValues == null) {
|
|
|
472
2879
|
return view;
|
|
473
2880
|
};
|
|
474
2881
|
}
|
|
475
|
-
//
|
|
476
|
-
//
|
|
2882
|
+
// queueMicrotask, and atob/btoa input checks as the HTML spec has them: atob drops ASCII
|
|
2883
|
+
// whitespace and rejects anything that is not base64, btoa rejects characters above
|
|
2884
|
+
// U+00FF. Both threw nothing and returned garbage before (W2 conformance).
|
|
2885
|
+
{
|
|
2886
|
+
const invalidCharacter = (message) => {
|
|
2887
|
+
const e = new Error(message);
|
|
2888
|
+
e.name = "InvalidCharacterError";
|
|
2889
|
+
return e;
|
|
2890
|
+
};
|
|
2891
|
+
if (globalThis.queueMicrotask == null) {
|
|
2892
|
+
globalThis.queueMicrotask = function (callback) {
|
|
2893
|
+
if (!__sbIsFn(callback)) throw new TypeError("queueMicrotask needs a function");
|
|
2894
|
+
Promise.resolve().then(() => callback());
|
|
2895
|
+
};
|
|
2896
|
+
}
|
|
2897
|
+
const nativeAtob = globalThis.atob, nativeBtoa = globalThis.btoa;
|
|
2898
|
+
globalThis.atob = function (data) {
|
|
2899
|
+
let text = String(data).replace(/[\t\n\f\r ]/g, "");
|
|
2900
|
+
if (text.length % 4 === 0) text = text.replace(/==?$/, "");
|
|
2901
|
+
if (text.length % 4 === 1 || !/^[A-Za-z0-9+/]*$/.test(text)) throw invalidCharacter("atob: the string is not valid base64");
|
|
2902
|
+
while (text.length % 4 !== 0) text += "=";
|
|
2903
|
+
return nativeAtob(text);
|
|
2904
|
+
};
|
|
2905
|
+
globalThis.btoa = function (data) {
|
|
2906
|
+
const text = String(data);
|
|
2907
|
+
for (let i = 0; i < text.length; i++) if (text.charCodeAt(i) > 0xff) throw invalidCharacter("btoa: the string has characters outside Latin-1");
|
|
2908
|
+
return nativeBtoa(text);
|
|
2909
|
+
};
|
|
2910
|
+
}
|
|
2911
|
+
|
|
2912
|
+
/* oxlint-disable anti-slop/no-runtime-typeof -- these Web API polyfills branch on JavaScript types
|
|
2913
|
+
exactly where their specs do (listener: function or { handleEvent }; structured clone: by value type). */
|
|
2914
|
+
// Event, CustomEvent, EventTarget, AbortSignal and AbortController, as workerd has
|
|
2915
|
+
// them (no DOM tree, so no bubbling or capture phases). Found missing by the W2
|
|
2916
|
+
// conformance suite; libraries use AbortController for fetch timeouts and EventTarget
|
|
2917
|
+
// for their own events.
|
|
2918
|
+
if (typeof globalThis.EventTarget !== "function") {
|
|
2919
|
+
const namedError = (name, message) => {
|
|
2920
|
+
const e = new Error(message);
|
|
2921
|
+
e.name = name;
|
|
2922
|
+
return e;
|
|
2923
|
+
};
|
|
2924
|
+
class Event {
|
|
2925
|
+
constructor(type, init) {
|
|
2926
|
+
if (arguments.length === 0) throw new TypeError("Event requires a type");
|
|
2927
|
+
const options = init || {};
|
|
2928
|
+
this.type = String(type);
|
|
2929
|
+
this.bubbles = !!options.bubbles;
|
|
2930
|
+
this.cancelable = !!options.cancelable;
|
|
2931
|
+
this.composed = !!options.composed;
|
|
2932
|
+
this.defaultPrevented = false;
|
|
2933
|
+
this.target = null;
|
|
2934
|
+
this.currentTarget = null;
|
|
2935
|
+
this.eventPhase = 0;
|
|
2936
|
+
this.isTrusted = false;
|
|
2937
|
+
this.timeStamp = Date.now();
|
|
2938
|
+
this.__sbStopped = false;
|
|
2939
|
+
}
|
|
2940
|
+
preventDefault() { if (this.cancelable) this.defaultPrevented = true; }
|
|
2941
|
+
stopPropagation() {}
|
|
2942
|
+
stopImmediatePropagation() { this.__sbStopped = true; }
|
|
2943
|
+
composedPath() { return this.currentTarget ? [this.currentTarget] : []; }
|
|
2944
|
+
}
|
|
2945
|
+
class CustomEvent extends Event {
|
|
2946
|
+
constructor(type, init) {
|
|
2947
|
+
super(type, init);
|
|
2948
|
+
this.detail = init && init.detail !== undefined ? init.detail : null;
|
|
2949
|
+
}
|
|
2950
|
+
}
|
|
2951
|
+
class EventTarget {
|
|
2952
|
+
constructor() { this.__sbListeners = {}; }
|
|
2953
|
+
addEventListener(type, listener, options) {
|
|
2954
|
+
if (listener == null) return;
|
|
2955
|
+
const capture = typeof options === "boolean" ? options : !!(options && options.capture);
|
|
2956
|
+
const once = !!(options && typeof options === "object" && options.once);
|
|
2957
|
+
const signal = options && typeof options === "object" ? options.signal : undefined;
|
|
2958
|
+
if (signal && signal.aborted) return;
|
|
2959
|
+
const list = this.__sbListeners[type] || (this.__sbListeners[type] = []);
|
|
2960
|
+
for (const entry of list) if (entry.listener === listener && entry.capture === capture) return;
|
|
2961
|
+
const entry = { listener, capture, once, removed: false };
|
|
2962
|
+
list.push(entry);
|
|
2963
|
+
if (signal) signal.addEventListener("abort", () => this.removeEventListener(type, listener, capture));
|
|
2964
|
+
}
|
|
2965
|
+
removeEventListener(type, listener, options) {
|
|
2966
|
+
const capture = typeof options === "boolean" ? options : !!(options && options.capture);
|
|
2967
|
+
const list = this.__sbListeners[type];
|
|
2968
|
+
if (!list) return;
|
|
2969
|
+
for (let i = 0; i < list.length; i++) {
|
|
2970
|
+
if (list[i].listener === listener && list[i].capture === capture) {
|
|
2971
|
+
list[i].removed = true;
|
|
2972
|
+
list.splice(i, 1);
|
|
2973
|
+
return;
|
|
2974
|
+
}
|
|
2975
|
+
}
|
|
2976
|
+
}
|
|
2977
|
+
dispatchEvent(event) {
|
|
2978
|
+
if (!(event instanceof Event)) throw new TypeError("dispatchEvent needs an Event");
|
|
2979
|
+
event.target = this;
|
|
2980
|
+
event.currentTarget = this;
|
|
2981
|
+
event.eventPhase = 2;
|
|
2982
|
+
const list = (this.__sbListeners[event.type] || []).slice();
|
|
2983
|
+
for (const entry of list) {
|
|
2984
|
+
if (entry.removed) continue;
|
|
2985
|
+
if (entry.once) this.removeEventListener(event.type, entry.listener, entry.capture);
|
|
2986
|
+
const fn = entry.listener;
|
|
2987
|
+
if (typeof fn === "function") fn.call(this, event);
|
|
2988
|
+
else if (fn && typeof fn.handleEvent === "function") fn.handleEvent(event);
|
|
2989
|
+
if (event.__sbStopped) break;
|
|
2990
|
+
}
|
|
2991
|
+
event.currentTarget = null;
|
|
2992
|
+
event.eventPhase = 0;
|
|
2993
|
+
return !event.defaultPrevented;
|
|
2994
|
+
}
|
|
2995
|
+
}
|
|
2996
|
+
class AbortSignal extends EventTarget {
|
|
2997
|
+
constructor() {
|
|
2998
|
+
super();
|
|
2999
|
+
this.aborted = false;
|
|
3000
|
+
this.reason = undefined;
|
|
3001
|
+
this.onabort = null;
|
|
3002
|
+
}
|
|
3003
|
+
throwIfAborted() { if (this.aborted) throw this.reason; }
|
|
3004
|
+
__sbAbort(reason) {
|
|
3005
|
+
if (this.aborted) return;
|
|
3006
|
+
this.aborted = true;
|
|
3007
|
+
this.reason = reason === undefined ? namedError("AbortError", "This operation was aborted") : reason;
|
|
3008
|
+
const event = new Event("abort");
|
|
3009
|
+
if (typeof this.onabort === "function") this.onabort.call(this, event);
|
|
3010
|
+
this.dispatchEvent(event);
|
|
3011
|
+
}
|
|
3012
|
+
static abort(reason) {
|
|
3013
|
+
const signal = new AbortSignal();
|
|
3014
|
+
signal.__sbAbort(reason);
|
|
3015
|
+
return signal;
|
|
3016
|
+
}
|
|
3017
|
+
static timeout(ms) {
|
|
3018
|
+
const signal = new AbortSignal();
|
|
3019
|
+
setTimeout(() => signal.__sbAbort(namedError("TimeoutError", "The operation timed out")), ms);
|
|
3020
|
+
return signal;
|
|
3021
|
+
}
|
|
3022
|
+
static any(signals) {
|
|
3023
|
+
const signal = new AbortSignal();
|
|
3024
|
+
for (const s of signals) {
|
|
3025
|
+
if (s.aborted) {
|
|
3026
|
+
signal.__sbAbort(s.reason);
|
|
3027
|
+
return signal;
|
|
3028
|
+
}
|
|
3029
|
+
}
|
|
3030
|
+
for (const s of signals) s.addEventListener("abort", () => signal.__sbAbort(s.reason));
|
|
3031
|
+
return signal;
|
|
3032
|
+
}
|
|
3033
|
+
}
|
|
3034
|
+
class AbortController {
|
|
3035
|
+
constructor() { this.signal = new AbortSignal(); }
|
|
3036
|
+
abort(reason) { this.signal.__sbAbort(reason); }
|
|
3037
|
+
}
|
|
3038
|
+
globalThis.Event = Event;
|
|
3039
|
+
globalThis.CustomEvent = CustomEvent;
|
|
3040
|
+
globalThis.EventTarget = EventTarget;
|
|
3041
|
+
globalThis.AbortSignal = AbortSignal;
|
|
3042
|
+
globalThis.AbortController = AbortController;
|
|
3043
|
+
}
|
|
3044
|
+
|
|
3045
|
+
// TextEncoderStream and TextDecoderStream over the Web Streams ponyfill (W2 conformance).
|
|
3046
|
+
// The encoder holds back a lone high surrogate at the end of a chunk until the next one;
|
|
3047
|
+
// the decoder is TextDecoder in streaming mode, so a character split across chunks decodes.
|
|
3048
|
+
if (globalThis.TextEncoderStream == null) {
|
|
3049
|
+
class TextEncoderStream {
|
|
3050
|
+
constructor() {
|
|
3051
|
+
const encoder = new TextEncoder();
|
|
3052
|
+
let pending = "";
|
|
3053
|
+
const transform = new TransformStream({
|
|
3054
|
+
transform(chunk, controller) {
|
|
3055
|
+
let text = pending + String(chunk);
|
|
3056
|
+
pending = "";
|
|
3057
|
+
const last = text.charCodeAt(text.length - 1);
|
|
3058
|
+
if (last >= 0xd800 && last <= 0xdbff) {
|
|
3059
|
+
pending = text.slice(-1);
|
|
3060
|
+
text = text.slice(0, -1);
|
|
3061
|
+
}
|
|
3062
|
+
if (text.length > 0) controller.enqueue(encoder.encode(text));
|
|
3063
|
+
},
|
|
3064
|
+
flush(controller) {
|
|
3065
|
+
if (pending.length > 0) controller.enqueue(encoder.encode(pending));
|
|
3066
|
+
},
|
|
3067
|
+
});
|
|
3068
|
+
this.readable = transform.readable;
|
|
3069
|
+
this.writable = transform.writable;
|
|
3070
|
+
}
|
|
3071
|
+
get encoding() {
|
|
3072
|
+
return "utf-8";
|
|
3073
|
+
}
|
|
3074
|
+
}
|
|
3075
|
+
class TextDecoderStream {
|
|
3076
|
+
constructor(label = "utf-8", options = undefined) {
|
|
3077
|
+
const decoder = new TextDecoder(label, options);
|
|
3078
|
+
this.encoding = decoder.encoding;
|
|
3079
|
+
this.fatal = decoder.fatal;
|
|
3080
|
+
this.ignoreBOM = decoder.ignoreBOM;
|
|
3081
|
+
const transform = new TransformStream({
|
|
3082
|
+
transform(chunk, controller) {
|
|
3083
|
+
const text = decoder.decode(chunk, { stream: true });
|
|
3084
|
+
if (text.length > 0) controller.enqueue(text);
|
|
3085
|
+
},
|
|
3086
|
+
flush(controller) {
|
|
3087
|
+
const text = decoder.decode();
|
|
3088
|
+
if (text.length > 0) controller.enqueue(text);
|
|
3089
|
+
},
|
|
3090
|
+
});
|
|
3091
|
+
this.readable = transform.readable;
|
|
3092
|
+
this.writable = transform.writable;
|
|
3093
|
+
}
|
|
3094
|
+
}
|
|
3095
|
+
globalThis.TextEncoderStream = TextEncoderStream;
|
|
3096
|
+
globalThis.TextDecoderStream = TextDecoderStream;
|
|
3097
|
+
}
|
|
3098
|
+
|
|
3099
|
+
// structuredClone: the HTML structured-clone algorithm for the types Worker code
|
|
3100
|
+
// passes around. Keeps cycles and shared references (a memo per call), Date, RegExp,
|
|
3101
|
+
// Map, Set, ArrayBuffer, typed arrays, DataView, errors, arrays and plain objects;
|
|
3102
|
+
// functions and symbols throw DataCloneError. It replaced a JSON round-trip that lost
|
|
3103
|
+
// every non-JSON type and crashed on cycles (W2 conformance).
|
|
477
3104
|
if (globalThis.structuredClone == null) {
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
3105
|
+
const dataCloneError = (what) => {
|
|
3106
|
+
const e = new Error(what + " could not be cloned");
|
|
3107
|
+
e.name = "DataCloneError";
|
|
3108
|
+
return e;
|
|
3109
|
+
};
|
|
3110
|
+
const errorTypes = { Error, EvalError, RangeError, ReferenceError, SyntaxError, TypeError, URIError };
|
|
3111
|
+
const clone = (value, memo) => {
|
|
3112
|
+
const type = typeof value;
|
|
3113
|
+
if (type === "function") throw dataCloneError("function");
|
|
3114
|
+
if (type === "symbol") throw dataCloneError("Symbol");
|
|
3115
|
+
if (value === null || type !== "object") return value;
|
|
3116
|
+
if (memo.has(value)) return memo.get(value);
|
|
3117
|
+
let out;
|
|
3118
|
+
if (value instanceof Date) out = new Date(value.getTime());
|
|
3119
|
+
else if (value instanceof RegExp) out = new RegExp(value.source, value.flags);
|
|
3120
|
+
else if (value instanceof ArrayBuffer) out = value.slice(0);
|
|
3121
|
+
else if (ArrayBuffer.isView(value)) {
|
|
3122
|
+
const buffer = clone(value.buffer, memo);
|
|
3123
|
+
out = value instanceof DataView ? new DataView(buffer, value.byteOffset, value.byteLength) : new value.constructor(buffer, value.byteOffset, value.length);
|
|
3124
|
+
} else if (value instanceof Map) {
|
|
3125
|
+
out = new Map();
|
|
3126
|
+
memo.set(value, out);
|
|
3127
|
+
for (const [k, v] of value) out.set(clone(k, memo), clone(v, memo));
|
|
3128
|
+
return out;
|
|
3129
|
+
} else if (value instanceof Set) {
|
|
3130
|
+
out = new Set();
|
|
3131
|
+
memo.set(value, out);
|
|
3132
|
+
for (const v of value) out.add(clone(v, memo));
|
|
3133
|
+
return out;
|
|
3134
|
+
} else if (value instanceof Error) {
|
|
3135
|
+
const Ctor = errorTypes[value.name] || Error;
|
|
3136
|
+
out = new Ctor(value.message);
|
|
3137
|
+
} else if (Array.isArray(value)) {
|
|
3138
|
+
out = new Array(value.length);
|
|
3139
|
+
memo.set(value, out);
|
|
3140
|
+
for (const k of Object.keys(value)) out[k] = clone(value[k], memo);
|
|
3141
|
+
return out;
|
|
3142
|
+
} else {
|
|
3143
|
+
out = {};
|
|
3144
|
+
memo.set(value, out);
|
|
3145
|
+
for (const k of Object.keys(value)) out[k] = clone(value[k], memo);
|
|
3146
|
+
return out;
|
|
3147
|
+
}
|
|
3148
|
+
memo.set(value, out);
|
|
3149
|
+
return out;
|
|
3150
|
+
};
|
|
481
3151
|
globalThis.structuredClone = function (value) {
|
|
482
|
-
return
|
|
3152
|
+
return clone(value, new Map());
|
|
483
3153
|
};
|
|
484
3154
|
}
|
|
485
3155
|
|
|
3156
|
+
/* oxlint-enable anti-slop/no-runtime-typeof */
|
|
3157
|
+
|
|
486
3158
|
if (globalThis.crypto.randomUUID == null) {
|
|
487
3159
|
globalThis.crypto.randomUUID = function () {
|
|
488
3160
|
const b = new Uint8Array(16);
|
|
@@ -503,6 +3175,8 @@ if (globalThis.crypto.randomUUID == null) {
|
|
|
503
3175
|
// dependency, so it works on the broker transport too.
|
|
504
3176
|
function __sbHashBits(algo) {
|
|
505
3177
|
const n = String((algo && algo.name) || algo || "").toUpperCase();
|
|
3178
|
+
if (n === "SHA-1" || n === "SHA1") return "1";
|
|
3179
|
+
if (n === "MD5") return "5";
|
|
506
3180
|
if (n === "SHA-256" || n === "SHA256") return "256";
|
|
507
3181
|
if (n === "SHA-384" || n === "SHA384") return "384";
|
|
508
3182
|
if (n === "SHA-512" || n === "SHA512") return "512";
|
|
@@ -729,42 +3403,77 @@ function __sbHexOrBytes(value) {
|
|
|
729
3403
|
return __sbToBytes(value);
|
|
730
3404
|
}
|
|
731
3405
|
|
|
3406
|
+
// Errors as WebCrypto names them (DOMException names; plain Errors here).
|
|
3407
|
+
function __sbCryptoError(name, message) {
|
|
3408
|
+
const e = new Error(message);
|
|
3409
|
+
e.name = name;
|
|
3410
|
+
return e;
|
|
3411
|
+
}
|
|
3412
|
+
// An HMAC key as importKey and generateKey return it. MD5 is digest-only, as in workerd.
|
|
3413
|
+
function __sbHmacKey(bytes, bits, extractable, usages) {
|
|
3414
|
+
const hash = bits === "1" ? "SHA-1" : "SHA-" + bits;
|
|
3415
|
+
return {
|
|
3416
|
+
type: "secret",
|
|
3417
|
+
extractable: !!extractable,
|
|
3418
|
+
algorithm: { name: "HMAC", hash: { name: hash }, length: bytes.length * 8 },
|
|
3419
|
+
usages: usages || [],
|
|
3420
|
+
__sbKey: bytes,
|
|
3421
|
+
__sbBits: bits,
|
|
3422
|
+
};
|
|
3423
|
+
}
|
|
3424
|
+
function __sbHmacBits(algo) {
|
|
3425
|
+
const bits = __sbHashBits((algo && algo.hash) || "SHA-256");
|
|
3426
|
+
if (!bits || bits === "5") throw __sbCryptoError("NotSupportedError", "HMAC needs SHA-1, SHA-256, SHA-384 or SHA-512");
|
|
3427
|
+
return bits;
|
|
3428
|
+
}
|
|
732
3429
|
if (globalThis.crypto.subtle == null) {
|
|
733
3430
|
globalThis.crypto.subtle = {
|
|
734
3431
|
async digest(algo, data) {
|
|
735
3432
|
const bits = __sbHashBits(algo);
|
|
736
|
-
if (!bits) throw
|
|
3433
|
+
if (!bits) throw __sbCryptoError("NotSupportedError", "crypto.subtle.digest: unsupported algorithm");
|
|
737
3434
|
const out = __sbDigestRaw(bits, __sbToBytes(data));
|
|
738
3435
|
if (!out) throw new Error("crypto.subtle.digest failed");
|
|
739
3436
|
return __sbBufFrom(out);
|
|
740
3437
|
},
|
|
741
3438
|
async importKey(format, keyData, algo, extractable, usages) {
|
|
742
|
-
if (format !== "raw") throw
|
|
3439
|
+
if (format !== "raw") throw __sbCryptoError("NotSupportedError", "crypto.subtle.importKey: only format 'raw' is supported");
|
|
743
3440
|
const name = String((algo && algo.name) || algo || "").toUpperCase();
|
|
744
|
-
if (name !== "HMAC") throw
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
3441
|
+
if (name !== "HMAC") throw __sbCryptoError("NotSupportedError", "crypto.subtle.importKey: only HMAC keys are supported");
|
|
3442
|
+
return __sbHmacKey(__sbToBytes(keyData), __sbHmacBits(algo), extractable, usages);
|
|
3443
|
+
},
|
|
3444
|
+
async exportKey(format, key) {
|
|
3445
|
+
if (!key || key.__sbKey == null) throw new TypeError("crypto.subtle.exportKey: not a key from this runtime");
|
|
3446
|
+
if (format !== "raw") throw __sbCryptoError("NotSupportedError", "crypto.subtle.exportKey: only format 'raw' is supported");
|
|
3447
|
+
if (!key.extractable) throw __sbCryptoError("InvalidAccessError", "crypto.subtle.exportKey: the key is not extractable");
|
|
3448
|
+
return __sbBufFrom(key.__sbKey);
|
|
3449
|
+
},
|
|
3450
|
+
async generateKey(algo, extractable, usages) {
|
|
3451
|
+
const name = String((algo && algo.name) || algo || "").toUpperCase();
|
|
3452
|
+
if (name !== "HMAC") throw __sbCryptoError("NotSupportedError", "crypto.subtle.generateKey: only HMAC keys are supported");
|
|
3453
|
+
const bits = __sbHmacBits(algo);
|
|
3454
|
+
// The default length is the hash's block size: 512 bits, or 1024 for SHA-384/512.
|
|
3455
|
+
const length = (algo && algo.length) || (bits === "384" || bits === "512" ? 1024 : 512);
|
|
3456
|
+
const bytes = __sbRandomBytes(String(Math.ceil(length / 8)));
|
|
3457
|
+
return __sbHmacKey(bytes, bits, extractable, usages);
|
|
755
3458
|
},
|
|
756
3459
|
async sign(algo, key, data) {
|
|
757
|
-
if (!key || key.__sbKey == null) throw
|
|
3460
|
+
if (!key || key.__sbKey == null) throw __sbCryptoError("InvalidAccessError", "crypto.subtle.sign: only HMAC keys are supported");
|
|
758
3461
|
const out = __sbHmacRaw(key.__sbBits, key.__sbKey, __sbToBytes(data));
|
|
759
3462
|
if (!out) throw new Error("crypto.subtle.sign failed");
|
|
760
3463
|
return __sbBufFrom(out);
|
|
761
3464
|
},
|
|
762
3465
|
async verify(algo, key, signature, data) {
|
|
763
|
-
if (!key || key.__sbKey == null) throw
|
|
3466
|
+
if (!key || key.__sbKey == null) throw __sbCryptoError("InvalidAccessError", "crypto.subtle.verify: only HMAC keys are supported");
|
|
764
3467
|
const mac = __sbHmacRaw(key.__sbBits, key.__sbKey, __sbToBytes(data));
|
|
765
3468
|
if (!mac) return false;
|
|
766
3469
|
return __sbEqCt(mac, __sbToBytes(signature));
|
|
767
3470
|
},
|
|
3471
|
+
// workerd's extension: constant-time comparison of two equal-length buffers.
|
|
3472
|
+
timingSafeEqual(a, b) {
|
|
3473
|
+
const x = __sbToBytes(a), y = __sbToBytes(b);
|
|
3474
|
+
if (x.length !== y.length) throw new TypeError("crypto.subtle.timingSafeEqual: the buffers differ in length");
|
|
3475
|
+
return __sbEqCt(x, y);
|
|
3476
|
+
},
|
|
768
3477
|
};
|
|
769
3478
|
}
|
|
770
3479
|
|
|
@@ -967,9 +3676,82 @@ static void sb_sha512_final(sb_sha512_ctx* c, unsigned char* out, int is384) {
|
|
|
967
3676
|
for (int j = 0; j < 8; j++) out[i*8+j] = (unsigned char)(c->h[i] >> (56 - j*8));
|
|
968
3677
|
}
|
|
969
3678
|
|
|
970
|
-
//
|
|
3679
|
+
// SHA-1 and MD5 (W2: workerd's digest has both; HMAC also takes SHA-1). One-shot over a
|
|
3680
|
+
// padded copy: inputs are request-sized, not streams.
|
|
3681
|
+
static uint32_t sb_rol32(uint32_t x, int n) { return (x << n) | (x >> (32 - n)); }
|
|
3682
|
+
static unsigned char* sb_md_pad(const unsigned char* msg, size_t len, size_t* total, int big_endian) {
|
|
3683
|
+
*total = ((len + 8) / 64 + 1) * 64;
|
|
3684
|
+
unsigned char* m = (unsigned char*)calloc(*total, 1);
|
|
3685
|
+
if (!m) return 0;
|
|
3686
|
+
memcpy(m, msg, len); m[len] = 0x80;
|
|
3687
|
+
uint64_t bits = (uint64_t)len * 8;
|
|
3688
|
+
for (int i = 0; i < 8; i++) m[big_endian ? *total - 1 - i : *total - 8 + i] = (unsigned char)(bits >> (8 * i));
|
|
3689
|
+
return m;
|
|
3690
|
+
}
|
|
3691
|
+
static size_t sb_sha1(const unsigned char* msg, size_t len, unsigned char out[20]) {
|
|
3692
|
+
size_t total; unsigned char* m = sb_md_pad(msg, len, &total, 1);
|
|
3693
|
+
if (!m) return 0;
|
|
3694
|
+
uint32_t h[5] = { 0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0 };
|
|
3695
|
+
for (size_t off = 0; off < total; off += 64) {
|
|
3696
|
+
uint32_t w[80];
|
|
3697
|
+
for (int i = 0; i < 16; i++) w[i] = ((uint32_t)m[off + 4*i] << 24) | ((uint32_t)m[off + 4*i + 1] << 16) | ((uint32_t)m[off + 4*i + 2] << 8) | m[off + 4*i + 3];
|
|
3698
|
+
for (int i = 16; i < 80; i++) w[i] = sb_rol32(w[i-3] ^ w[i-8] ^ w[i-14] ^ w[i-16], 1);
|
|
3699
|
+
uint32_t a = h[0], b = h[1], c = h[2], d = h[3], e = h[4];
|
|
3700
|
+
for (int i = 0; i < 80; i++) {
|
|
3701
|
+
uint32_t f, k;
|
|
3702
|
+
if (i < 20) { f = (b & c) | (~b & d); k = 0x5A827999; }
|
|
3703
|
+
else if (i < 40) { f = b ^ c ^ d; k = 0x6ED9EBA1; }
|
|
3704
|
+
else if (i < 60) { f = (b & c) | (b & d) | (c & d); k = 0x8F1BBCDC; }
|
|
3705
|
+
else { f = b ^ c ^ d; k = 0xCA62C1D6; }
|
|
3706
|
+
uint32_t t = sb_rol32(a, 5) + f + e + k + w[i];
|
|
3707
|
+
e = d; d = c; c = sb_rol32(b, 30); b = a; a = t;
|
|
3708
|
+
}
|
|
3709
|
+
h[0] += a; h[1] += b; h[2] += c; h[3] += d; h[4] += e;
|
|
3710
|
+
}
|
|
3711
|
+
free(m);
|
|
3712
|
+
for (int i = 0; i < 5; i++) { out[4*i] = h[i] >> 24; out[4*i+1] = h[i] >> 16; out[4*i+2] = h[i] >> 8; out[4*i+3] = h[i]; }
|
|
3713
|
+
return 20;
|
|
3714
|
+
}
|
|
3715
|
+
static size_t sb_md5(const unsigned char* msg, size_t len, unsigned char out[16]) {
|
|
3716
|
+
static const uint32_t K[64] = {
|
|
3717
|
+
0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee, 0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501,
|
|
3718
|
+
0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be, 0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821,
|
|
3719
|
+
0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa, 0xd62f105d, 0x02441453, 0xd8a1e681, 0xe7d3fbc8,
|
|
3720
|
+
0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed, 0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a,
|
|
3721
|
+
0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c, 0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70,
|
|
3722
|
+
0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x04881d05, 0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665,
|
|
3723
|
+
0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039, 0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1,
|
|
3724
|
+
0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1, 0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391 };
|
|
3725
|
+
static const int S[16] = { 7, 12, 17, 22, 5, 9, 14, 20, 4, 11, 16, 23, 6, 10, 15, 21 };
|
|
3726
|
+
size_t total; unsigned char* m = sb_md_pad(msg, len, &total, 0);
|
|
3727
|
+
if (!m) return 0;
|
|
3728
|
+
uint32_t h[4] = { 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476 };
|
|
3729
|
+
for (size_t off = 0; off < total; off += 64) {
|
|
3730
|
+
uint32_t w[16];
|
|
3731
|
+
for (int i = 0; i < 16; i++) w[i] = (uint32_t)m[off + 4*i] | ((uint32_t)m[off + 4*i + 1] << 8) | ((uint32_t)m[off + 4*i + 2] << 16) | ((uint32_t)m[off + 4*i + 3] << 24);
|
|
3732
|
+
uint32_t a = h[0], b = h[1], c = h[2], d = h[3];
|
|
3733
|
+
for (int i = 0; i < 64; i++) {
|
|
3734
|
+
uint32_t f; int g;
|
|
3735
|
+
if (i < 16) { f = (b & c) | (~b & d); g = i; }
|
|
3736
|
+
else if (i < 32) { f = (d & b) | (~d & c); g = (5*i + 1) % 16; }
|
|
3737
|
+
else if (i < 48) { f = b ^ c ^ d; g = (3*i + 5) % 16; }
|
|
3738
|
+
else { f = c ^ (b | ~d); g = (7*i) % 16; }
|
|
3739
|
+
f = f + a + K[i] + w[g];
|
|
3740
|
+
a = d; d = c; c = b;
|
|
3741
|
+
b = b + sb_rol32(f, S[(i / 16) * 4 + i % 4]);
|
|
3742
|
+
}
|
|
3743
|
+
h[0] += a; h[1] += b; h[2] += c; h[3] += d;
|
|
3744
|
+
}
|
|
3745
|
+
free(m);
|
|
3746
|
+
for (int i = 0; i < 4; i++) { out[4*i] = h[i]; out[4*i+1] = h[i] >> 8; out[4*i+2] = h[i] >> 16; out[4*i+3] = h[i] >> 24; }
|
|
3747
|
+
return 16;
|
|
3748
|
+
}
|
|
3749
|
+
|
|
3750
|
+
// One-shot digest. algo: 1 (SHA-1) | 5 (MD5) | 256 | 384 | 512. out must hold up to 64 bytes.
|
|
971
3751
|
// Returns the digest length, or 0 for an unknown algo.
|
|
972
3752
|
static size_t sb_digest(int algo, const unsigned char* msg, size_t mlen, unsigned char* out) {
|
|
3753
|
+
if (algo == 1) return sb_sha1(msg, mlen, out);
|
|
3754
|
+
if (algo == 5) return sb_md5(msg, mlen, out);
|
|
973
3755
|
if (algo == 256) { sb_sha256_ctx c; sb_sha256_init(&c); sb_sha256_update(&c, msg, mlen); sb_sha256_final(&c, out); return 32; }
|
|
974
3756
|
if (algo == 384) { sb_sha512_ctx c; sb_sha512_init(&c, 1); sb_sha512_update(&c, msg, mlen); sb_sha512_final(&c, out, 1); return 48; }
|
|
975
3757
|
if (algo == 512) { sb_sha512_ctx c; sb_sha512_init(&c, 0); sb_sha512_update(&c, msg, mlen); sb_sha512_final(&c, out, 0); return 64; }
|
|
@@ -979,6 +3761,20 @@ static size_t sb_digest(int algo, const unsigned char* msg, size_t mlen, unsigne
|
|
|
979
3761
|
// HMAC(algo) per RFC 2104. Block size is 64 for SHA-256, 128 for SHA-384/512.
|
|
980
3762
|
static size_t sb_hmac(int algo, const unsigned char* key, size_t klen,
|
|
981
3763
|
const unsigned char* msg, size_t mlen, unsigned char* out) {
|
|
3764
|
+
if (algo == 1) {
|
|
3765
|
+
// HMAC-SHA-1: block 64, over padded copies like the one-shot digest.
|
|
3766
|
+
unsigned char k1[64], inner1[20];
|
|
3767
|
+
memset(k1, 0, sizeof(k1));
|
|
3768
|
+
if (klen > 64) sb_sha1(key, klen, k1); else memcpy(k1, key, klen);
|
|
3769
|
+
unsigned char* buf = (unsigned char*)malloc(64 + (mlen > 20 ? mlen : 20));
|
|
3770
|
+
if (!buf) return 0;
|
|
3771
|
+
for (int i = 0; i < 64; i++) buf[i] = k1[i] ^ 0x36;
|
|
3772
|
+
memcpy(buf + 64, msg, mlen); sb_sha1(buf, 64 + mlen, inner1);
|
|
3773
|
+
for (int i = 0; i < 64; i++) buf[i] = k1[i] ^ 0x5c;
|
|
3774
|
+
memcpy(buf + 64, inner1, 20); sb_sha1(buf, 84, out);
|
|
3775
|
+
free(buf);
|
|
3776
|
+
return 20;
|
|
3777
|
+
}
|
|
982
3778
|
size_t bs = algo == 256 ? 64 : 128;
|
|
983
3779
|
unsigned char k[128], ipad[128], opad[128], inner[64];
|
|
984
3780
|
memset(k, 0, sizeof(k));
|
|
@@ -1388,6 +4184,64 @@ function __sbR2Multipart(bucket, key, uploadId) {
|
|
|
1388
4184
|
};
|
|
1389
4185
|
}
|
|
1390
4186
|
|
|
4187
|
+
// Asset rules use the same parsed manifest in both transports. Matching mirrors
|
|
4188
|
+
// @sproutboat/assets; parity tests cover the portable native implementation.
|
|
4189
|
+
function __sbAssetRedirect(rule, path) {
|
|
4190
|
+
const star = rule.from.indexOf("*");
|
|
4191
|
+
if (star !== -1) {
|
|
4192
|
+
const prefix = rule.from.slice(0, star);
|
|
4193
|
+
if (!path.startsWith(prefix)) return null;
|
|
4194
|
+
return rule.to.split(":splat").join(path.slice(prefix.length));
|
|
4195
|
+
}
|
|
4196
|
+
const from = rule.from.split("/").filter(Boolean);
|
|
4197
|
+
const parts = path.split("/").filter(Boolean);
|
|
4198
|
+
if (from.length !== parts.length) return null;
|
|
4199
|
+
const params = {};
|
|
4200
|
+
for (let i = 0; i < from.length; i++) {
|
|
4201
|
+
if (from[i].startsWith(":")) params[from[i].slice(1)] = parts[i];
|
|
4202
|
+
else if (from[i] !== parts[i]) return null;
|
|
4203
|
+
}
|
|
4204
|
+
let to = rule.to;
|
|
4205
|
+
for (const name in params) to = to.split(":" + name).join(params[name]);
|
|
4206
|
+
return to;
|
|
4207
|
+
}
|
|
4208
|
+
|
|
4209
|
+
function __sbAssetHeaderMatches(pattern, path) {
|
|
4210
|
+
const from = pattern.split("/").filter(Boolean);
|
|
4211
|
+
const parts = path.split("/").filter(Boolean);
|
|
4212
|
+
for (let i = 0; i < from.length; i++) {
|
|
4213
|
+
if (from[i] === "*") return true;
|
|
4214
|
+
if (from[i] !== parts[i]) return false;
|
|
4215
|
+
}
|
|
4216
|
+
return from.length === parts.length;
|
|
4217
|
+
}
|
|
4218
|
+
|
|
4219
|
+
function __sbAssetResponse(path, r) {
|
|
4220
|
+
if (r.location != null) return new Response(null, { status: r.status, headers: { location: r.location } });
|
|
4221
|
+
const rules = r.rules || {};
|
|
4222
|
+
const redirects = rules.redirects || [];
|
|
4223
|
+
for (let i = 0; i < redirects.length; i++) {
|
|
4224
|
+
const to = __sbAssetRedirect(redirects[i], path);
|
|
4225
|
+
if (to !== null) return new Response(null, { status: redirects[i].status, headers: { location: to } });
|
|
4226
|
+
}
|
|
4227
|
+
const headers = new Headers();
|
|
4228
|
+
if (r.type) headers.set("content-type", r.type);
|
|
4229
|
+
if (r.found) headers.set("etag", '"' + r.hash + '"');
|
|
4230
|
+
// A custom 404 page is also an asset; a generated Not Found is not.
|
|
4231
|
+
if (r.type) {
|
|
4232
|
+
const list = rules.headers || [];
|
|
4233
|
+
for (let i = 0; i < list.length; i++) {
|
|
4234
|
+
const rule = list[i];
|
|
4235
|
+
if (!__sbAssetHeaderMatches(rule.pattern, path)) continue;
|
|
4236
|
+
for (let j = 0; j < rule.unset.length; j++) headers.delete(rule.unset[j]);
|
|
4237
|
+
for (let j = 0; j < rule.set.length; j++) headers.set(rule.set[j][0], rule.set[j][1]);
|
|
4238
|
+
}
|
|
4239
|
+
}
|
|
4240
|
+
// Apply the internal byte marker after user rules so they cannot remove it.
|
|
4241
|
+
if (r.body != null) headers.set("x-sb-raw-body", "1");
|
|
4242
|
+
return __sbRawBodyResponse(r.body, { status: r.status || (r.found ? 200 : 404), headers });
|
|
4243
|
+
}
|
|
4244
|
+
|
|
1391
4245
|
// Installed only when the project declares bindings. `env` is the module-scoped
|
|
1392
4246
|
// object from compile.ts (a `const`, but mutable); we add the binding accessors
|
|
1393
4247
|
// to it in place. compile.ts emits `__sbInstallBindings(env, {...})` right after
|
|
@@ -1611,16 +4465,7 @@ globalThis.__sbInstallBindings = function (target, bindings) {
|
|
|
1611
4465
|
} catch {
|
|
1612
4466
|
/* use as-is */
|
|
1613
4467
|
}
|
|
1614
|
-
|
|
1615
|
-
const headers = {};
|
|
1616
|
-
if (r.type) headers["content-type"] = r.type;
|
|
1617
|
-
if (r.found) headers["etag"] = '"' + r.hash + '"';
|
|
1618
|
-
// #176: these bytes came off disk already-finished (UTF-8 text or
|
|
1619
|
-
// binary, doesn't matter which) -- the reserved x-sb-raw-body header
|
|
1620
|
-
// tells the C write path to pass them through untouched instead of
|
|
1621
|
-
// re-encoding as if this were a JS string a handler built.
|
|
1622
|
-
if (r.body != null) headers["x-sb-raw-body"] = "1";
|
|
1623
|
-
return __sbRawBodyResponse(r.body, { status: r.status || (r.found ? 200 : 404), headers });
|
|
4468
|
+
return __sbAssetResponse(path, globalThis.__sbAssetsGet(path));
|
|
1624
4469
|
},
|
|
1625
4470
|
};
|
|
1626
4471
|
}
|
|
@@ -1665,26 +4510,48 @@ globalThis.__sbInstallBindings = function (target, bindings) {
|
|
|
1665
4510
|
// prelude must not replace fetch just by being evaluated.
|
|
1666
4511
|
globalThis.__sbInstallFetch = function () {
|
|
1667
4512
|
globalThis.fetch = function (input, init) {
|
|
1668
|
-
|
|
4513
|
+
// A Request's method, headers and body apply unless init overrides them; a URL
|
|
4514
|
+
// object stands for its href.
|
|
4515
|
+
const req = input != null && !__sbIsStr(input) && input.url != null ? input : null;
|
|
4516
|
+
const url = req ? String(req.url) : input != null && input.href != null ? String(input.href) : String(input);
|
|
1669
4517
|
const opts = init || {};
|
|
4518
|
+
const source = opts.headers != null ? opts.headers : req ? req.headers : null;
|
|
1670
4519
|
const headers = [];
|
|
1671
|
-
if (
|
|
1672
|
-
if (__sbIsFn(
|
|
1673
|
-
else for (const k in
|
|
1674
|
-
}
|
|
1675
|
-
const
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
4520
|
+
if (source) {
|
|
4521
|
+
if (__sbIsFn(source.forEach)) source.forEach((v, k) => headers.push([k, v]));
|
|
4522
|
+
else for (const k in source) headers.push([k, source[k]]);
|
|
4523
|
+
}
|
|
4524
|
+
const body = opts.body !== undefined ? opts.body : req && req.body !== "" ? req.body : null;
|
|
4525
|
+
const method = opts.method || (req && req.method) || "GET";
|
|
4526
|
+
const msg = { url, method, headers, ...__sbRequestBody(body) };
|
|
4527
|
+
const respond = (r) => {
|
|
4528
|
+
const respHeaders = new Headers();
|
|
4529
|
+
for (let j = 0; j < (r.headers || []).length; j++) respHeaders.set(r.headers[j][0], r.headers[j][1]);
|
|
4530
|
+
// #176: bytes from an outbound HTTP response, not a string this handler
|
|
4531
|
+
// built -- must not be re-encoded if the handler proxies it straight
|
|
4532
|
+
// through (see the assets binding for the same reasoning).
|
|
4533
|
+
if (r.body != null) respHeaders.set("x-sb-raw-body", "1");
|
|
4534
|
+
return __sbRawBodyResponse(r.body, { status: r.status || 502, headers: respHeaders });
|
|
4535
|
+
};
|
|
4536
|
+
if (!__sbHttpAsyncEnabled()) return respond(globalThis.__sbFetchUpstream("fetch", msg));
|
|
4537
|
+
// B18: the host runs the request off the event loop. Its reply fires a timer
|
|
4538
|
+
// that never fires on its own; the timer table keeps the callback alive.
|
|
4539
|
+
return new Promise((resolve, reject) => {
|
|
4540
|
+
const id = setTimeout(() => {
|
|
4541
|
+
try {
|
|
4542
|
+
resolve(respond(__sbFetchReply(__sbHttpAsyncResult(id))));
|
|
4543
|
+
} catch (e) {
|
|
4544
|
+
reject(new Error("sproutboat fetch: " + ((e && e.message) || e)));
|
|
4545
|
+
}
|
|
4546
|
+
}, 2147483647);
|
|
4547
|
+
try {
|
|
4548
|
+
msg.asyncId = id;
|
|
4549
|
+
globalThis.__sbFetchUpstream("fetch", msg);
|
|
4550
|
+
} catch (e) {
|
|
4551
|
+
clearTimeout(id);
|
|
4552
|
+
reject(e);
|
|
4553
|
+
}
|
|
1680
4554
|
});
|
|
1681
|
-
const respHeaders = new Headers();
|
|
1682
|
-
for (let j = 0; j < (r.headers || []).length; j++) respHeaders.set(r.headers[j][0], r.headers[j][1]);
|
|
1683
|
-
// #176: bytes from an outbound HTTP response, not a string this handler
|
|
1684
|
-
// built -- must not be re-encoded if the handler proxies it straight
|
|
1685
|
-
// through (see the assets binding for the same reasoning).
|
|
1686
|
-
if (r.body != null) respHeaders.set("x-sb-raw-body", "1");
|
|
1687
|
-
return __sbRawBodyResponse(r.body, { status: r.status || 502, headers: respHeaders });
|
|
1688
4555
|
};
|
|
1689
4556
|
};
|
|
1690
4557
|
|
|
@@ -1743,7 +4610,7 @@ function __sbMakeDONamespace(binding, className) {
|
|
|
1743
4610
|
}
|
|
1744
4611
|
const inst = __sbGetDOInstance(className, idStr);
|
|
1745
4612
|
const res = inst.fetch(req);
|
|
1746
|
-
if (inst.__sbTasks.length || (res && __sbIsFn(res.then))) return __sbFetchWithDrain(res, inst.__sbTasks);
|
|
4613
|
+
if (inst.__sbTasks.length || (res && __sbIsFn(res.then)) || __sbHasStreamBody(res)) return __sbFetchWithDrain(res, inst.__sbTasks);
|
|
1747
4614
|
return res;
|
|
1748
4615
|
},
|
|
1749
4616
|
};
|
|
@@ -2026,14 +4893,17 @@ function __sbTrustedProxyHeader(request, name) {
|
|
|
2026
4893
|
// own.
|
|
2027
4894
|
const __SB_WAITUNTIL_TIMEOUT_MS = 25000;
|
|
2028
4895
|
|
|
2029
|
-
function __sbTimeout(ms) {
|
|
2030
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
2031
|
-
}
|
|
2032
|
-
|
|
2033
4896
|
async function __sbDrainWaitUntil(tasks) {
|
|
2034
4897
|
if (!tasks.length) return;
|
|
2035
4898
|
const pending = tasks.splice(0, tasks.length);
|
|
2036
|
-
|
|
4899
|
+
// Clear the cap's timer once the tasks finish: a pending timer kept the process
|
|
4900
|
+
// busy for the full 25 s (sproutd will not reap a worker with timers left, B22).
|
|
4901
|
+
let timer;
|
|
4902
|
+
const cap = new Promise((resolve) => {
|
|
4903
|
+
timer = setTimeout(resolve, __SB_WAITUNTIL_TIMEOUT_MS);
|
|
4904
|
+
});
|
|
4905
|
+
await Promise.race([__sbDrainAll(pending), cap]);
|
|
4906
|
+
clearTimeout(timer);
|
|
2037
4907
|
}
|
|
2038
4908
|
|
|
2039
4909
|
async function __sbDrainAll(pending) {
|
|
@@ -2049,15 +4919,130 @@ async function __sbDrainAll(pending) {
|
|
|
2049
4919
|
// Tail-called from `__sbEntry`/DO dispatch so the promise this returns is the
|
|
2050
4920
|
// one *this* async function creates, not a `.then()` derived from someone
|
|
2051
4921
|
// else's — see the note below on why that distinction matters here.
|
|
4922
|
+
// B19 (first step): a ReadableStream response body is read to the end and sent buffered;
|
|
4923
|
+
// the native writer had sent "[object ReadableStream]". Chunks must be bytes, as in workerd
|
|
4924
|
+
// (a string chunk is a TypeError), and the whole body is capped like a fetched one.
|
|
4925
|
+
const __SB_STREAM_BODY_MAX = 32 * 1024 * 1024;
|
|
4926
|
+
async function __sbCollectBody(stream) {
|
|
4927
|
+
const reader = stream.getReader();
|
|
4928
|
+
const chunks = [];
|
|
4929
|
+
let size = 0;
|
|
4930
|
+
for (;;) {
|
|
4931
|
+
const { value, done } = await reader.read();
|
|
4932
|
+
if (done) break;
|
|
4933
|
+
let bytes;
|
|
4934
|
+
if (value instanceof Uint8Array) bytes = value;
|
|
4935
|
+
else if (value instanceof ArrayBuffer) bytes = new Uint8Array(value);
|
|
4936
|
+
else if (ArrayBuffer.isView(value)) bytes = new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
|
|
4937
|
+
else throw new TypeError("This ReadableStream did not return bytes.");
|
|
4938
|
+
size += bytes.length;
|
|
4939
|
+
if (size > __SB_STREAM_BODY_MAX) throw new RangeError("Response body stream exceeds 32 MiB");
|
|
4940
|
+
chunks.push(bytes);
|
|
4941
|
+
}
|
|
4942
|
+
const out = new Uint8Array(size);
|
|
4943
|
+
let at = 0;
|
|
4944
|
+
for (const chunk of chunks) {
|
|
4945
|
+
out.set(chunk, at);
|
|
4946
|
+
at += chunk.length;
|
|
4947
|
+
}
|
|
4948
|
+
return out;
|
|
4949
|
+
}
|
|
4950
|
+
function __sbHasStreamBody(res) {
|
|
4951
|
+
return res != null && res.body instanceof ReadableStream;
|
|
4952
|
+
}
|
|
4953
|
+
|
|
4954
|
+
// B19: on a host that streams (a standalone sprout's native server defines sb_stream_*), a
|
|
4955
|
+
// stream body goes out as it is produced: the response is marked with the internal
|
|
4956
|
+
// x-sb-stream header, the native writer sends the status and headers and holds the
|
|
4957
|
+
// connection open, and each chunk is written as it arrives. Hosts that do not stream
|
|
4958
|
+
// (sproutd's workers, for now) link the weak fallbacks, report unsupported and keep buffering.
|
|
4959
|
+
// op: "s" supported, "o" open, "w" write data, "e" end. Returns a short string.
|
|
4960
|
+
// oxlint-disable-next-line no-unused-vars -- read inside the RawC block, not by JS.
|
|
4961
|
+
function __sbStreamOp(op, id, data) {
|
|
4962
|
+
let out = "";
|
|
4963
|
+
// oxlint-disable-next-line no-unused-expressions -- Porffor.c`...` is inline C the compiler consumes, not a JS expression.
|
|
4964
|
+
Porffor.c`
|
|
4965
|
+
extern int sb_stream_supported(void);
|
|
4966
|
+
extern unsigned int sb_stream_open(void);
|
|
4967
|
+
extern int sb_stream_write(unsigned int, const char*, size_t);
|
|
4968
|
+
extern void sb_stream_end(unsigned int);
|
|
4969
|
+
const char* __o; size_t __ol; char* __oo = 0;
|
|
4970
|
+
porf_native_fetch_read_value(op, &__o, &__ol, &__oo);
|
|
4971
|
+
char __op = __ol ? __o[0] : 0;
|
|
4972
|
+
if (__oo) free(__oo);
|
|
4973
|
+
const char* __i; size_t __il; char* __io = 0;
|
|
4974
|
+
porf_native_fetch_read_value(id, &__i, &__il, &__io);
|
|
4975
|
+
char __ib[16]; size_t __ik = __il < 15 ? __il : 15;
|
|
4976
|
+
memcpy(__ib, __i, __ik); __ib[__ik] = 0;
|
|
4977
|
+
if (__io) free(__io);
|
|
4978
|
+
unsigned int __id = (unsigned int)strtoul(__ib, 0, 10);
|
|
4979
|
+
char __r[24]; __r[0] = 0;
|
|
4980
|
+
if (sb_stream_supported()) {
|
|
4981
|
+
if (__op == 's') snprintf(__r, sizeof(__r), "1");
|
|
4982
|
+
else if (__op == 'o') snprintf(__r, sizeof(__r), "%u", sb_stream_open());
|
|
4983
|
+
else if (__op == 'w') {
|
|
4984
|
+
const char* __d = 0; size_t __dl = 0;
|
|
4985
|
+
int __w = -1;
|
|
4986
|
+
if (porf_native_fetch_read_raw_bytes(data, &__d, &__dl) == 0) __w = sb_stream_write(__id, __d, __dl);
|
|
4987
|
+
snprintf(__r, sizeof(__r), "%d", __w);
|
|
4988
|
+
} else if (__op == 'e') { sb_stream_end(__id); snprintf(__r, sizeof(__r), "0"); }
|
|
4989
|
+
}
|
|
4990
|
+
out = porf_box((f64)porf_native_fetch_alloc_bytestring(__r, strlen(__r)), 195);
|
|
4991
|
+
`;
|
|
4992
|
+
return out;
|
|
4993
|
+
}
|
|
4994
|
+
let __sbStreaming = -1;
|
|
4995
|
+
function __sbStreamingSupported() {
|
|
4996
|
+
if (__sbStreaming < 0) __sbStreaming = __sbStreamOp("s", "0", "") === "1" ? 1 : 0;
|
|
4997
|
+
return __sbStreaming === 1;
|
|
4998
|
+
}
|
|
4999
|
+
function __sbStreamResponse(response) {
|
|
5000
|
+
const stream = response.body;
|
|
5001
|
+
const id = __sbStreamOp("o", "0", "");
|
|
5002
|
+
response.headers.set("x-sb-stream", id);
|
|
5003
|
+
response.body = "";
|
|
5004
|
+
(async () => {
|
|
5005
|
+
const reader = stream.getReader();
|
|
5006
|
+
try {
|
|
5007
|
+
for (;;) {
|
|
5008
|
+
const { value, done } = await reader.read();
|
|
5009
|
+
if (done) break;
|
|
5010
|
+
let bytes;
|
|
5011
|
+
if (value instanceof Uint8Array) bytes = value;
|
|
5012
|
+
else if (value instanceof ArrayBuffer) bytes = new Uint8Array(value);
|
|
5013
|
+
else if (ArrayBuffer.isView(value)) bytes = new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
|
|
5014
|
+
else throw new TypeError("This ReadableStream did not return bytes.");
|
|
5015
|
+
if (bytes.length > 0 && __sbStreamOp("w", id, __sbToBytes(bytes)) !== "0") {
|
|
5016
|
+
// The client went away: stop the source.
|
|
5017
|
+
reader.cancel();
|
|
5018
|
+
break;
|
|
5019
|
+
}
|
|
5020
|
+
}
|
|
5021
|
+
} catch (error) {
|
|
5022
|
+
// The status line is already out; log and end what was sent.
|
|
5023
|
+
__sbLogUncaught("fetch", error);
|
|
5024
|
+
}
|
|
5025
|
+
__sbStreamOp("e", id, "");
|
|
5026
|
+
})();
|
|
5027
|
+
return response;
|
|
5028
|
+
}
|
|
5029
|
+
|
|
2052
5030
|
async function __sbFetchWithDrain(res, tasks) {
|
|
2053
5031
|
let r;
|
|
2054
5032
|
try {
|
|
2055
5033
|
r = res && __sbIsFn(res.then) ? await res : res;
|
|
5034
|
+
if (__sbHasStreamBody(r)) {
|
|
5035
|
+
if (__sbStreamingSupported()) __sbStreamResponse(r);
|
|
5036
|
+
else r.body = await __sbCollectBody(r.body);
|
|
5037
|
+
}
|
|
2056
5038
|
} catch (error) {
|
|
2057
5039
|
// #179 — a rejected handler promise must not take the process down with it.
|
|
2058
5040
|
r = __sbErrorResponse(error);
|
|
2059
5041
|
}
|
|
2060
|
-
|
|
5042
|
+
// The response goes out now and ctx.waitUntil work keeps running after it, as in
|
|
5043
|
+
// workerd; it was awaited first, so a 1.5 s background task delayed the response by
|
|
5044
|
+
// 1.5 s. The 25 s cap still bounds it.
|
|
5045
|
+
__sbDrainWaitUntil(tasks);
|
|
2061
5046
|
return r;
|
|
2062
5047
|
}
|
|
2063
5048
|
|
|
@@ -2067,7 +5052,10 @@ async function __sbFetchWithDrain(res, tasks) {
|
|
|
2067
5052
|
// nothing on stderr, which hid #168 entirely.
|
|
2068
5053
|
function __sbErrorResponse(error) {
|
|
2069
5054
|
__sbLogUncaught("fetch", error);
|
|
2070
|
-
|
|
5055
|
+
// Untyped, as workerd sends it: the text/plain default is for handlers' bodies.
|
|
5056
|
+
const response = new Response("Internal Server Error", { status: 500 });
|
|
5057
|
+
response.headers.delete("content-type");
|
|
5058
|
+
return response;
|
|
2071
5059
|
}
|
|
2072
5060
|
|
|
2073
5061
|
function __sbLogUncaught(where, error) {
|
|
@@ -2165,7 +5153,7 @@ globalThis.__sbEntry = function (handlers, request) {
|
|
|
2165
5153
|
}
|
|
2166
5154
|
// Same promise-identity rule as above applies to `__sbFetchWithDrain`'s
|
|
2167
5155
|
// own return, which is why it's tail-called rather than chained on here.
|
|
2168
|
-
if (__sbTasks.length || (__res && __sbIsFn(__res.then))) return __sbFetchWithDrain(__res, __sbTasks);
|
|
5156
|
+
if (__sbTasks.length || (__res && __sbIsFn(__res.then)) || __sbHasStreamBody(__res)) return __sbFetchWithDrain(__res, __sbTasks);
|
|
2169
5157
|
return __sbTagCpu(__res, __t0);
|
|
2170
5158
|
}
|
|
2171
5159
|
if (!__sbTriggerAuthed(request)) return new Response("forbidden", { status: 403 });
|