web-streams-polyfill 3.0.3 → 4.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +33 -2
- package/LICENSE +1 -1
- package/README.md +56 -41
- package/dist/polyfill.es5.js +8 -0
- package/dist/polyfill.js +6 -3999
- package/dist/ponyfill.es5.js +8 -0
- package/dist/ponyfill.es5.mjs +8 -0
- package/dist/ponyfill.js +6 -3971
- package/dist/ponyfill.mjs +6 -3949
- package/package.json +52 -28
- package/types/polyfill.d.ts +62 -0
- package/{dist/types/ts3.6/polyfill.d.ts → types/ponyfill.d.ts} +32 -16
- package/{dist/types → types}/tsdoc-metadata.json +1 -1
- package/dist/polyfill.es2018.js +0 -3868
- package/dist/polyfill.es2018.js.map +0 -1
- package/dist/polyfill.es2018.min.js +0 -2
- package/dist/polyfill.es2018.min.js.map +0 -1
- package/dist/polyfill.es2018.mjs +0 -3846
- package/dist/polyfill.es2018.mjs.map +0 -1
- package/dist/polyfill.es6.js +0 -3879
- package/dist/polyfill.es6.js.map +0 -1
- package/dist/polyfill.es6.min.js +0 -2
- package/dist/polyfill.es6.min.js.map +0 -1
- package/dist/polyfill.es6.mjs +0 -3857
- package/dist/polyfill.es6.mjs.map +0 -1
- package/dist/polyfill.js.map +0 -1
- package/dist/polyfill.min.js +0 -2
- package/dist/polyfill.min.js.map +0 -1
- package/dist/polyfill.mjs +0 -3979
- package/dist/polyfill.mjs.map +0 -1
- package/dist/ponyfill.es2018.js +0 -3840
- package/dist/ponyfill.es2018.js.map +0 -1
- package/dist/ponyfill.es2018.mjs +0 -3818
- package/dist/ponyfill.es2018.mjs.map +0 -1
- package/dist/ponyfill.es6.js +0 -3851
- package/dist/ponyfill.es6.js.map +0 -1
- package/dist/ponyfill.es6.mjs +0 -3829
- package/dist/ponyfill.es6.mjs.map +0 -1
- package/dist/ponyfill.js.map +0 -1
- package/dist/ponyfill.mjs.map +0 -1
- package/dist/types/polyfill.d.ts +0 -751
- package/es2018/package.json +0 -7
- package/es6/package.json +0 -7
- package/ponyfill/es2018/package.json +0 -6
- package/ponyfill/es6/package.json +0 -6
- package/ponyfill/package.json +0 -6
package/dist/ponyfill.js
CHANGED
|
@@ -1,3973 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* @license
|
|
3
|
+
* web-streams-polyfill v4.0.0-beta.1
|
|
4
|
+
* Copyright 2021 Mattias Buelens, Diwank Singh Tomer and other contributors.
|
|
5
|
+
* This code is released under the MIT license.
|
|
6
|
+
* SPDX-License-Identifier: MIT
|
|
3
7
|
*/
|
|
4
|
-
(function (global, factory) {
|
|
5
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
6
|
-
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
7
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.WebStreamsPolyfill = {}));
|
|
8
|
-
}(this, (function (exports) { 'use strict';
|
|
9
|
-
|
|
10
|
-
/// <reference lib="es2015.symbol" />
|
|
11
|
-
var SymbolPolyfill = typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol' ?
|
|
12
|
-
Symbol :
|
|
13
|
-
function (description) { return "Symbol(" + description + ")"; };
|
|
14
|
-
|
|
15
|
-
/// <reference lib="dom" />
|
|
16
|
-
function noop() {
|
|
17
|
-
return undefined;
|
|
18
|
-
}
|
|
19
|
-
function getGlobals() {
|
|
20
|
-
if (typeof self !== 'undefined') {
|
|
21
|
-
return self;
|
|
22
|
-
}
|
|
23
|
-
else if (typeof window !== 'undefined') {
|
|
24
|
-
return window;
|
|
25
|
-
}
|
|
26
|
-
else if (typeof global !== 'undefined') {
|
|
27
|
-
return global;
|
|
28
|
-
}
|
|
29
|
-
return undefined;
|
|
30
|
-
}
|
|
31
|
-
var globals = getGlobals();
|
|
32
|
-
|
|
33
|
-
function typeIsObject(x) {
|
|
34
|
-
return (typeof x === 'object' && x !== null) || typeof x === 'function';
|
|
35
|
-
}
|
|
36
|
-
var rethrowAssertionErrorRejection = noop;
|
|
37
|
-
|
|
38
|
-
var originalPromise = Promise;
|
|
39
|
-
var originalPromiseThen = Promise.prototype.then;
|
|
40
|
-
var originalPromiseResolve = Promise.resolve.bind(originalPromise);
|
|
41
|
-
var originalPromiseReject = Promise.reject.bind(originalPromise);
|
|
42
|
-
function newPromise(executor) {
|
|
43
|
-
return new originalPromise(executor);
|
|
44
|
-
}
|
|
45
|
-
function promiseResolvedWith(value) {
|
|
46
|
-
return originalPromiseResolve(value);
|
|
47
|
-
}
|
|
48
|
-
function promiseRejectedWith(reason) {
|
|
49
|
-
return originalPromiseReject(reason);
|
|
50
|
-
}
|
|
51
|
-
function PerformPromiseThen(promise, onFulfilled, onRejected) {
|
|
52
|
-
// There doesn't appear to be any way to correctly emulate the behaviour from JavaScript, so this is just an
|
|
53
|
-
// approximation.
|
|
54
|
-
return originalPromiseThen.call(promise, onFulfilled, onRejected);
|
|
55
|
-
}
|
|
56
|
-
function uponPromise(promise, onFulfilled, onRejected) {
|
|
57
|
-
PerformPromiseThen(PerformPromiseThen(promise, onFulfilled, onRejected), undefined, rethrowAssertionErrorRejection);
|
|
58
|
-
}
|
|
59
|
-
function uponFulfillment(promise, onFulfilled) {
|
|
60
|
-
uponPromise(promise, onFulfilled);
|
|
61
|
-
}
|
|
62
|
-
function uponRejection(promise, onRejected) {
|
|
63
|
-
uponPromise(promise, undefined, onRejected);
|
|
64
|
-
}
|
|
65
|
-
function transformPromiseWith(promise, fulfillmentHandler, rejectionHandler) {
|
|
66
|
-
return PerformPromiseThen(promise, fulfillmentHandler, rejectionHandler);
|
|
67
|
-
}
|
|
68
|
-
function setPromiseIsHandledToTrue(promise) {
|
|
69
|
-
PerformPromiseThen(promise, undefined, rethrowAssertionErrorRejection);
|
|
70
|
-
}
|
|
71
|
-
var queueMicrotask = (function () {
|
|
72
|
-
var globalQueueMicrotask = globals && globals.queueMicrotask;
|
|
73
|
-
if (typeof globalQueueMicrotask === 'function') {
|
|
74
|
-
return globalQueueMicrotask;
|
|
75
|
-
}
|
|
76
|
-
var resolvedPromise = promiseResolvedWith(undefined);
|
|
77
|
-
return function (fn) { return PerformPromiseThen(resolvedPromise, fn); };
|
|
78
|
-
})();
|
|
79
|
-
function reflectCall(F, V, args) {
|
|
80
|
-
if (typeof F !== 'function') {
|
|
81
|
-
throw new TypeError('Argument is not a function');
|
|
82
|
-
}
|
|
83
|
-
return Function.prototype.apply.call(F, V, args);
|
|
84
|
-
}
|
|
85
|
-
function promiseCall(F, V, args) {
|
|
86
|
-
try {
|
|
87
|
-
return promiseResolvedWith(reflectCall(F, V, args));
|
|
88
|
-
}
|
|
89
|
-
catch (value) {
|
|
90
|
-
return promiseRejectedWith(value);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// Original from Chromium
|
|
95
|
-
// https://chromium.googlesource.com/chromium/src/+/0aee4434a4dba42a42abaea9bfbc0cd196a63bc1/third_party/blink/renderer/core/streams/SimpleQueue.js
|
|
96
|
-
var QUEUE_MAX_ARRAY_SIZE = 16384;
|
|
97
|
-
/**
|
|
98
|
-
* Simple queue structure.
|
|
99
|
-
*
|
|
100
|
-
* Avoids scalability issues with using a packed array directly by using
|
|
101
|
-
* multiple arrays in a linked list and keeping the array size bounded.
|
|
102
|
-
*/
|
|
103
|
-
var SimpleQueue = /** @class */ (function () {
|
|
104
|
-
function SimpleQueue() {
|
|
105
|
-
this._cursor = 0;
|
|
106
|
-
this._size = 0;
|
|
107
|
-
// _front and _back are always defined.
|
|
108
|
-
this._front = {
|
|
109
|
-
_elements: [],
|
|
110
|
-
_next: undefined
|
|
111
|
-
};
|
|
112
|
-
this._back = this._front;
|
|
113
|
-
// The cursor is used to avoid calling Array.shift().
|
|
114
|
-
// It contains the index of the front element of the array inside the
|
|
115
|
-
// front-most node. It is always in the range [0, QUEUE_MAX_ARRAY_SIZE).
|
|
116
|
-
this._cursor = 0;
|
|
117
|
-
// When there is only one node, size === elements.length - cursor.
|
|
118
|
-
this._size = 0;
|
|
119
|
-
}
|
|
120
|
-
Object.defineProperty(SimpleQueue.prototype, "length", {
|
|
121
|
-
get: function () {
|
|
122
|
-
return this._size;
|
|
123
|
-
},
|
|
124
|
-
enumerable: false,
|
|
125
|
-
configurable: true
|
|
126
|
-
});
|
|
127
|
-
// For exception safety, this method is structured in order:
|
|
128
|
-
// 1. Read state
|
|
129
|
-
// 2. Calculate required state mutations
|
|
130
|
-
// 3. Perform state mutations
|
|
131
|
-
SimpleQueue.prototype.push = function (element) {
|
|
132
|
-
var oldBack = this._back;
|
|
133
|
-
var newBack = oldBack;
|
|
134
|
-
if (oldBack._elements.length === QUEUE_MAX_ARRAY_SIZE - 1) {
|
|
135
|
-
newBack = {
|
|
136
|
-
_elements: [],
|
|
137
|
-
_next: undefined
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
// push() is the mutation most likely to throw an exception, so it
|
|
141
|
-
// goes first.
|
|
142
|
-
oldBack._elements.push(element);
|
|
143
|
-
if (newBack !== oldBack) {
|
|
144
|
-
this._back = newBack;
|
|
145
|
-
oldBack._next = newBack;
|
|
146
|
-
}
|
|
147
|
-
++this._size;
|
|
148
|
-
};
|
|
149
|
-
// Like push(), shift() follows the read -> calculate -> mutate pattern for
|
|
150
|
-
// exception safety.
|
|
151
|
-
SimpleQueue.prototype.shift = function () { // must not be called on an empty queue
|
|
152
|
-
var oldFront = this._front;
|
|
153
|
-
var newFront = oldFront;
|
|
154
|
-
var oldCursor = this._cursor;
|
|
155
|
-
var newCursor = oldCursor + 1;
|
|
156
|
-
var elements = oldFront._elements;
|
|
157
|
-
var element = elements[oldCursor];
|
|
158
|
-
if (newCursor === QUEUE_MAX_ARRAY_SIZE) {
|
|
159
|
-
newFront = oldFront._next;
|
|
160
|
-
newCursor = 0;
|
|
161
|
-
}
|
|
162
|
-
// No mutations before this point.
|
|
163
|
-
--this._size;
|
|
164
|
-
this._cursor = newCursor;
|
|
165
|
-
if (oldFront !== newFront) {
|
|
166
|
-
this._front = newFront;
|
|
167
|
-
}
|
|
168
|
-
// Permit shifted element to be garbage collected.
|
|
169
|
-
elements[oldCursor] = undefined;
|
|
170
|
-
return element;
|
|
171
|
-
};
|
|
172
|
-
// The tricky thing about forEach() is that it can be called
|
|
173
|
-
// re-entrantly. The queue may be mutated inside the callback. It is easy to
|
|
174
|
-
// see that push() within the callback has no negative effects since the end
|
|
175
|
-
// of the queue is checked for on every iteration. If shift() is called
|
|
176
|
-
// repeatedly within the callback then the next iteration may return an
|
|
177
|
-
// element that has been removed. In this case the callback will be called
|
|
178
|
-
// with undefined values until we either "catch up" with elements that still
|
|
179
|
-
// exist or reach the back of the queue.
|
|
180
|
-
SimpleQueue.prototype.forEach = function (callback) {
|
|
181
|
-
var i = this._cursor;
|
|
182
|
-
var node = this._front;
|
|
183
|
-
var elements = node._elements;
|
|
184
|
-
while (i !== elements.length || node._next !== undefined) {
|
|
185
|
-
if (i === elements.length) {
|
|
186
|
-
node = node._next;
|
|
187
|
-
elements = node._elements;
|
|
188
|
-
i = 0;
|
|
189
|
-
if (elements.length === 0) {
|
|
190
|
-
break;
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
callback(elements[i]);
|
|
194
|
-
++i;
|
|
195
|
-
}
|
|
196
|
-
};
|
|
197
|
-
// Return the element that would be returned if shift() was called now,
|
|
198
|
-
// without modifying the queue.
|
|
199
|
-
SimpleQueue.prototype.peek = function () { // must not be called on an empty queue
|
|
200
|
-
var front = this._front;
|
|
201
|
-
var cursor = this._cursor;
|
|
202
|
-
return front._elements[cursor];
|
|
203
|
-
};
|
|
204
|
-
return SimpleQueue;
|
|
205
|
-
}());
|
|
206
|
-
|
|
207
|
-
function ReadableStreamReaderGenericInitialize(reader, stream) {
|
|
208
|
-
reader._ownerReadableStream = stream;
|
|
209
|
-
stream._reader = reader;
|
|
210
|
-
if (stream._state === 'readable') {
|
|
211
|
-
defaultReaderClosedPromiseInitialize(reader);
|
|
212
|
-
}
|
|
213
|
-
else if (stream._state === 'closed') {
|
|
214
|
-
defaultReaderClosedPromiseInitializeAsResolved(reader);
|
|
215
|
-
}
|
|
216
|
-
else {
|
|
217
|
-
defaultReaderClosedPromiseInitializeAsRejected(reader, stream._storedError);
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
// A client of ReadableStreamDefaultReader and ReadableStreamBYOBReader may use these functions directly to bypass state
|
|
221
|
-
// check.
|
|
222
|
-
function ReadableStreamReaderGenericCancel(reader, reason) {
|
|
223
|
-
var stream = reader._ownerReadableStream;
|
|
224
|
-
return ReadableStreamCancel(stream, reason);
|
|
225
|
-
}
|
|
226
|
-
function ReadableStreamReaderGenericRelease(reader) {
|
|
227
|
-
if (reader._ownerReadableStream._state === 'readable') {
|
|
228
|
-
defaultReaderClosedPromiseReject(reader, new TypeError("Reader was released and can no longer be used to monitor the stream's closedness"));
|
|
229
|
-
}
|
|
230
|
-
else {
|
|
231
|
-
defaultReaderClosedPromiseResetToRejected(reader, new TypeError("Reader was released and can no longer be used to monitor the stream's closedness"));
|
|
232
|
-
}
|
|
233
|
-
reader._ownerReadableStream._reader = undefined;
|
|
234
|
-
reader._ownerReadableStream = undefined;
|
|
235
|
-
}
|
|
236
|
-
// Helper functions for the readers.
|
|
237
|
-
function readerLockException(name) {
|
|
238
|
-
return new TypeError('Cannot ' + name + ' a stream using a released reader');
|
|
239
|
-
}
|
|
240
|
-
// Helper functions for the ReadableStreamDefaultReader.
|
|
241
|
-
function defaultReaderClosedPromiseInitialize(reader) {
|
|
242
|
-
reader._closedPromise = newPromise(function (resolve, reject) {
|
|
243
|
-
reader._closedPromise_resolve = resolve;
|
|
244
|
-
reader._closedPromise_reject = reject;
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
function defaultReaderClosedPromiseInitializeAsRejected(reader, reason) {
|
|
248
|
-
defaultReaderClosedPromiseInitialize(reader);
|
|
249
|
-
defaultReaderClosedPromiseReject(reader, reason);
|
|
250
|
-
}
|
|
251
|
-
function defaultReaderClosedPromiseInitializeAsResolved(reader) {
|
|
252
|
-
defaultReaderClosedPromiseInitialize(reader);
|
|
253
|
-
defaultReaderClosedPromiseResolve(reader);
|
|
254
|
-
}
|
|
255
|
-
function defaultReaderClosedPromiseReject(reader, reason) {
|
|
256
|
-
if (reader._closedPromise_reject === undefined) {
|
|
257
|
-
return;
|
|
258
|
-
}
|
|
259
|
-
setPromiseIsHandledToTrue(reader._closedPromise);
|
|
260
|
-
reader._closedPromise_reject(reason);
|
|
261
|
-
reader._closedPromise_resolve = undefined;
|
|
262
|
-
reader._closedPromise_reject = undefined;
|
|
263
|
-
}
|
|
264
|
-
function defaultReaderClosedPromiseResetToRejected(reader, reason) {
|
|
265
|
-
defaultReaderClosedPromiseInitializeAsRejected(reader, reason);
|
|
266
|
-
}
|
|
267
|
-
function defaultReaderClosedPromiseResolve(reader) {
|
|
268
|
-
if (reader._closedPromise_resolve === undefined) {
|
|
269
|
-
return;
|
|
270
|
-
}
|
|
271
|
-
reader._closedPromise_resolve(undefined);
|
|
272
|
-
reader._closedPromise_resolve = undefined;
|
|
273
|
-
reader._closedPromise_reject = undefined;
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
var AbortSteps = SymbolPolyfill('[[AbortSteps]]');
|
|
277
|
-
var ErrorSteps = SymbolPolyfill('[[ErrorSteps]]');
|
|
278
|
-
var CancelSteps = SymbolPolyfill('[[CancelSteps]]');
|
|
279
|
-
var PullSteps = SymbolPolyfill('[[PullSteps]]');
|
|
280
|
-
|
|
281
|
-
/// <reference lib="es2015.core" />
|
|
282
|
-
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isFinite#Polyfill
|
|
283
|
-
var NumberIsFinite = Number.isFinite || function (x) {
|
|
284
|
-
return typeof x === 'number' && isFinite(x);
|
|
285
|
-
};
|
|
286
|
-
|
|
287
|
-
/// <reference lib="es2015.core" />
|
|
288
|
-
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/trunc#Polyfill
|
|
289
|
-
var MathTrunc = Math.trunc || function (v) {
|
|
290
|
-
return v < 0 ? Math.ceil(v) : Math.floor(v);
|
|
291
|
-
};
|
|
292
|
-
|
|
293
|
-
// https://heycam.github.io/webidl/#idl-dictionaries
|
|
294
|
-
function isDictionary(x) {
|
|
295
|
-
return typeof x === 'object' || typeof x === 'function';
|
|
296
|
-
}
|
|
297
|
-
function assertDictionary(obj, context) {
|
|
298
|
-
if (obj !== undefined && !isDictionary(obj)) {
|
|
299
|
-
throw new TypeError(context + " is not an object.");
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
// https://heycam.github.io/webidl/#idl-callback-functions
|
|
303
|
-
function assertFunction(x, context) {
|
|
304
|
-
if (typeof x !== 'function') {
|
|
305
|
-
throw new TypeError(context + " is not a function.");
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
// https://heycam.github.io/webidl/#idl-object
|
|
309
|
-
function isObject(x) {
|
|
310
|
-
return (typeof x === 'object' && x !== null) || typeof x === 'function';
|
|
311
|
-
}
|
|
312
|
-
function assertObject(x, context) {
|
|
313
|
-
if (!isObject(x)) {
|
|
314
|
-
throw new TypeError(context + " is not an object.");
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
function assertRequiredArgument(x, position, context) {
|
|
318
|
-
if (x === undefined) {
|
|
319
|
-
throw new TypeError("Parameter " + position + " is required in '" + context + "'.");
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
function assertRequiredField(x, field, context) {
|
|
323
|
-
if (x === undefined) {
|
|
324
|
-
throw new TypeError(field + " is required in '" + context + "'.");
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
// https://heycam.github.io/webidl/#idl-unrestricted-double
|
|
328
|
-
function convertUnrestrictedDouble(value) {
|
|
329
|
-
return Number(value);
|
|
330
|
-
}
|
|
331
|
-
function censorNegativeZero(x) {
|
|
332
|
-
return x === 0 ? 0 : x;
|
|
333
|
-
}
|
|
334
|
-
function integerPart(x) {
|
|
335
|
-
return censorNegativeZero(MathTrunc(x));
|
|
336
|
-
}
|
|
337
|
-
// https://heycam.github.io/webidl/#idl-unsigned-long-long
|
|
338
|
-
function convertUnsignedLongLongWithEnforceRange(value, context) {
|
|
339
|
-
var lowerBound = 0;
|
|
340
|
-
var upperBound = Number.MAX_SAFE_INTEGER;
|
|
341
|
-
var x = Number(value);
|
|
342
|
-
x = censorNegativeZero(x);
|
|
343
|
-
if (!NumberIsFinite(x)) {
|
|
344
|
-
throw new TypeError(context + " is not a finite number");
|
|
345
|
-
}
|
|
346
|
-
x = integerPart(x);
|
|
347
|
-
if (x < lowerBound || x > upperBound) {
|
|
348
|
-
throw new TypeError(context + " is outside the accepted range of " + lowerBound + " to " + upperBound + ", inclusive");
|
|
349
|
-
}
|
|
350
|
-
if (!NumberIsFinite(x) || x === 0) {
|
|
351
|
-
return 0;
|
|
352
|
-
}
|
|
353
|
-
// TODO Use BigInt if supported?
|
|
354
|
-
// let xBigInt = BigInt(integerPart(x));
|
|
355
|
-
// xBigInt = BigInt.asUintN(64, xBigInt);
|
|
356
|
-
// return Number(xBigInt);
|
|
357
|
-
return x;
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
function assertReadableStream(x, context) {
|
|
361
|
-
if (!IsReadableStream(x)) {
|
|
362
|
-
throw new TypeError(context + " is not a ReadableStream.");
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
// Abstract operations for the ReadableStream.
|
|
367
|
-
function AcquireReadableStreamDefaultReader(stream) {
|
|
368
|
-
return new ReadableStreamDefaultReader(stream);
|
|
369
|
-
}
|
|
370
|
-
// ReadableStream API exposed for controllers.
|
|
371
|
-
function ReadableStreamAddReadRequest(stream, readRequest) {
|
|
372
|
-
stream._reader._readRequests.push(readRequest);
|
|
373
|
-
}
|
|
374
|
-
function ReadableStreamFulfillReadRequest(stream, chunk, done) {
|
|
375
|
-
var reader = stream._reader;
|
|
376
|
-
var readRequest = reader._readRequests.shift();
|
|
377
|
-
if (done) {
|
|
378
|
-
readRequest._closeSteps();
|
|
379
|
-
}
|
|
380
|
-
else {
|
|
381
|
-
readRequest._chunkSteps(chunk);
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
function ReadableStreamGetNumReadRequests(stream) {
|
|
385
|
-
return stream._reader._readRequests.length;
|
|
386
|
-
}
|
|
387
|
-
function ReadableStreamHasDefaultReader(stream) {
|
|
388
|
-
var reader = stream._reader;
|
|
389
|
-
if (reader === undefined) {
|
|
390
|
-
return false;
|
|
391
|
-
}
|
|
392
|
-
if (!IsReadableStreamDefaultReader(reader)) {
|
|
393
|
-
return false;
|
|
394
|
-
}
|
|
395
|
-
return true;
|
|
396
|
-
}
|
|
397
|
-
/**
|
|
398
|
-
* A default reader vended by a {@link ReadableStream}.
|
|
399
|
-
*
|
|
400
|
-
* @public
|
|
401
|
-
*/
|
|
402
|
-
var ReadableStreamDefaultReader = /** @class */ (function () {
|
|
403
|
-
function ReadableStreamDefaultReader(stream) {
|
|
404
|
-
assertRequiredArgument(stream, 1, 'ReadableStreamDefaultReader');
|
|
405
|
-
assertReadableStream(stream, 'First parameter');
|
|
406
|
-
if (IsReadableStreamLocked(stream)) {
|
|
407
|
-
throw new TypeError('This stream has already been locked for exclusive reading by another reader');
|
|
408
|
-
}
|
|
409
|
-
ReadableStreamReaderGenericInitialize(this, stream);
|
|
410
|
-
this._readRequests = new SimpleQueue();
|
|
411
|
-
}
|
|
412
|
-
Object.defineProperty(ReadableStreamDefaultReader.prototype, "closed", {
|
|
413
|
-
/**
|
|
414
|
-
* Returns a promise that will be fulfilled when the stream becomes closed,
|
|
415
|
-
* or rejected if the stream ever errors or the reader's lock is released before the stream finishes closing.
|
|
416
|
-
*/
|
|
417
|
-
get: function () {
|
|
418
|
-
if (!IsReadableStreamDefaultReader(this)) {
|
|
419
|
-
return promiseRejectedWith(defaultReaderBrandCheckException('closed'));
|
|
420
|
-
}
|
|
421
|
-
return this._closedPromise;
|
|
422
|
-
},
|
|
423
|
-
enumerable: false,
|
|
424
|
-
configurable: true
|
|
425
|
-
});
|
|
426
|
-
/**
|
|
427
|
-
* If the reader is active, behaves the same as {@link ReadableStream.cancel | stream.cancel(reason)}.
|
|
428
|
-
*/
|
|
429
|
-
ReadableStreamDefaultReader.prototype.cancel = function (reason) {
|
|
430
|
-
if (reason === void 0) { reason = undefined; }
|
|
431
|
-
if (!IsReadableStreamDefaultReader(this)) {
|
|
432
|
-
return promiseRejectedWith(defaultReaderBrandCheckException('cancel'));
|
|
433
|
-
}
|
|
434
|
-
if (this._ownerReadableStream === undefined) {
|
|
435
|
-
return promiseRejectedWith(readerLockException('cancel'));
|
|
436
|
-
}
|
|
437
|
-
return ReadableStreamReaderGenericCancel(this, reason);
|
|
438
|
-
};
|
|
439
|
-
/**
|
|
440
|
-
* Returns a promise that allows access to the next chunk from the stream's internal queue, if available.
|
|
441
|
-
*
|
|
442
|
-
* If reading a chunk causes the queue to become empty, more data will be pulled from the underlying source.
|
|
443
|
-
*/
|
|
444
|
-
ReadableStreamDefaultReader.prototype.read = function () {
|
|
445
|
-
if (!IsReadableStreamDefaultReader(this)) {
|
|
446
|
-
return promiseRejectedWith(defaultReaderBrandCheckException('read'));
|
|
447
|
-
}
|
|
448
|
-
if (this._ownerReadableStream === undefined) {
|
|
449
|
-
return promiseRejectedWith(readerLockException('read from'));
|
|
450
|
-
}
|
|
451
|
-
var resolvePromise;
|
|
452
|
-
var rejectPromise;
|
|
453
|
-
var promise = newPromise(function (resolve, reject) {
|
|
454
|
-
resolvePromise = resolve;
|
|
455
|
-
rejectPromise = reject;
|
|
456
|
-
});
|
|
457
|
-
var readRequest = {
|
|
458
|
-
_chunkSteps: function (chunk) { return resolvePromise({ value: chunk, done: false }); },
|
|
459
|
-
_closeSteps: function () { return resolvePromise({ value: undefined, done: true }); },
|
|
460
|
-
_errorSteps: function (e) { return rejectPromise(e); }
|
|
461
|
-
};
|
|
462
|
-
ReadableStreamDefaultReaderRead(this, readRequest);
|
|
463
|
-
return promise;
|
|
464
|
-
};
|
|
465
|
-
/**
|
|
466
|
-
* Releases the reader's lock on the corresponding stream. After the lock is released, the reader is no longer active.
|
|
467
|
-
* If the associated stream is errored when the lock is released, the reader will appear errored in the same way
|
|
468
|
-
* from now on; otherwise, the reader will appear closed.
|
|
469
|
-
*
|
|
470
|
-
* A reader's lock cannot be released while it still has a pending read request, i.e., if a promise returned by
|
|
471
|
-
* the reader's {@link ReadableStreamDefaultReader.read | read()} method has not yet been settled. Attempting to
|
|
472
|
-
* do so will throw a `TypeError` and leave the reader locked to the stream.
|
|
473
|
-
*/
|
|
474
|
-
ReadableStreamDefaultReader.prototype.releaseLock = function () {
|
|
475
|
-
if (!IsReadableStreamDefaultReader(this)) {
|
|
476
|
-
throw defaultReaderBrandCheckException('releaseLock');
|
|
477
|
-
}
|
|
478
|
-
if (this._ownerReadableStream === undefined) {
|
|
479
|
-
return;
|
|
480
|
-
}
|
|
481
|
-
if (this._readRequests.length > 0) {
|
|
482
|
-
throw new TypeError('Tried to release a reader lock when that reader has pending read() calls un-settled');
|
|
483
|
-
}
|
|
484
|
-
ReadableStreamReaderGenericRelease(this);
|
|
485
|
-
};
|
|
486
|
-
return ReadableStreamDefaultReader;
|
|
487
|
-
}());
|
|
488
|
-
Object.defineProperties(ReadableStreamDefaultReader.prototype, {
|
|
489
|
-
cancel: { enumerable: true },
|
|
490
|
-
read: { enumerable: true },
|
|
491
|
-
releaseLock: { enumerable: true },
|
|
492
|
-
closed: { enumerable: true }
|
|
493
|
-
});
|
|
494
|
-
if (typeof SymbolPolyfill.toStringTag === 'symbol') {
|
|
495
|
-
Object.defineProperty(ReadableStreamDefaultReader.prototype, SymbolPolyfill.toStringTag, {
|
|
496
|
-
value: 'ReadableStreamDefaultReader',
|
|
497
|
-
configurable: true
|
|
498
|
-
});
|
|
499
|
-
}
|
|
500
|
-
// Abstract operations for the readers.
|
|
501
|
-
function IsReadableStreamDefaultReader(x) {
|
|
502
|
-
if (!typeIsObject(x)) {
|
|
503
|
-
return false;
|
|
504
|
-
}
|
|
505
|
-
if (!Object.prototype.hasOwnProperty.call(x, '_readRequests')) {
|
|
506
|
-
return false;
|
|
507
|
-
}
|
|
508
|
-
return true;
|
|
509
|
-
}
|
|
510
|
-
function ReadableStreamDefaultReaderRead(reader, readRequest) {
|
|
511
|
-
var stream = reader._ownerReadableStream;
|
|
512
|
-
stream._disturbed = true;
|
|
513
|
-
if (stream._state === 'closed') {
|
|
514
|
-
readRequest._closeSteps();
|
|
515
|
-
}
|
|
516
|
-
else if (stream._state === 'errored') {
|
|
517
|
-
readRequest._errorSteps(stream._storedError);
|
|
518
|
-
}
|
|
519
|
-
else {
|
|
520
|
-
stream._readableStreamController[PullSteps](readRequest);
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
// Helper functions for the ReadableStreamDefaultReader.
|
|
524
|
-
function defaultReaderBrandCheckException(name) {
|
|
525
|
-
return new TypeError("ReadableStreamDefaultReader.prototype." + name + " can only be used on a ReadableStreamDefaultReader");
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
/// <reference lib="es2018.asynciterable" />
|
|
529
|
-
var _a;
|
|
530
|
-
var AsyncIteratorPrototype;
|
|
531
|
-
if (typeof SymbolPolyfill.asyncIterator === 'symbol') {
|
|
532
|
-
// We're running inside a ES2018+ environment, but we're compiling to an older syntax.
|
|
533
|
-
// We cannot access %AsyncIteratorPrototype% without non-ES2018 syntax, but we can re-create it.
|
|
534
|
-
AsyncIteratorPrototype = (_a = {},
|
|
535
|
-
// 25.1.3.1 %AsyncIteratorPrototype% [ @@asyncIterator ] ( )
|
|
536
|
-
// https://tc39.github.io/ecma262/#sec-asynciteratorprototype-asynciterator
|
|
537
|
-
_a[SymbolPolyfill.asyncIterator] = function () {
|
|
538
|
-
return this;
|
|
539
|
-
},
|
|
540
|
-
_a);
|
|
541
|
-
Object.defineProperty(AsyncIteratorPrototype, SymbolPolyfill.asyncIterator, { enumerable: false });
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
/// <reference lib="es2018.asynciterable" />
|
|
545
|
-
var ReadableStreamAsyncIteratorImpl = /** @class */ (function () {
|
|
546
|
-
function ReadableStreamAsyncIteratorImpl(reader, preventCancel) {
|
|
547
|
-
this._ongoingPromise = undefined;
|
|
548
|
-
this._isFinished = false;
|
|
549
|
-
this._reader = reader;
|
|
550
|
-
this._preventCancel = preventCancel;
|
|
551
|
-
}
|
|
552
|
-
ReadableStreamAsyncIteratorImpl.prototype.next = function () {
|
|
553
|
-
var _this = this;
|
|
554
|
-
var nextSteps = function () { return _this._nextSteps(); };
|
|
555
|
-
this._ongoingPromise = this._ongoingPromise ?
|
|
556
|
-
transformPromiseWith(this._ongoingPromise, nextSteps, nextSteps) :
|
|
557
|
-
nextSteps();
|
|
558
|
-
return this._ongoingPromise;
|
|
559
|
-
};
|
|
560
|
-
ReadableStreamAsyncIteratorImpl.prototype.return = function (value) {
|
|
561
|
-
var _this = this;
|
|
562
|
-
var returnSteps = function () { return _this._returnSteps(value); };
|
|
563
|
-
return this._ongoingPromise ?
|
|
564
|
-
transformPromiseWith(this._ongoingPromise, returnSteps, returnSteps) :
|
|
565
|
-
returnSteps();
|
|
566
|
-
};
|
|
567
|
-
ReadableStreamAsyncIteratorImpl.prototype._nextSteps = function () {
|
|
568
|
-
var _this = this;
|
|
569
|
-
if (this._isFinished) {
|
|
570
|
-
return Promise.resolve({ value: undefined, done: true });
|
|
571
|
-
}
|
|
572
|
-
var reader = this._reader;
|
|
573
|
-
if (reader._ownerReadableStream === undefined) {
|
|
574
|
-
return promiseRejectedWith(readerLockException('iterate'));
|
|
575
|
-
}
|
|
576
|
-
var resolvePromise;
|
|
577
|
-
var rejectPromise;
|
|
578
|
-
var promise = newPromise(function (resolve, reject) {
|
|
579
|
-
resolvePromise = resolve;
|
|
580
|
-
rejectPromise = reject;
|
|
581
|
-
});
|
|
582
|
-
var readRequest = {
|
|
583
|
-
_chunkSteps: function (chunk) {
|
|
584
|
-
_this._ongoingPromise = undefined;
|
|
585
|
-
// This needs to be delayed by one microtask, otherwise we stop pulling too early which breaks a test.
|
|
586
|
-
// FIXME Is this a bug in the specification, or in the test?
|
|
587
|
-
queueMicrotask(function () { return resolvePromise({ value: chunk, done: false }); });
|
|
588
|
-
},
|
|
589
|
-
_closeSteps: function () {
|
|
590
|
-
_this._ongoingPromise = undefined;
|
|
591
|
-
_this._isFinished = true;
|
|
592
|
-
ReadableStreamReaderGenericRelease(reader);
|
|
593
|
-
resolvePromise({ value: undefined, done: true });
|
|
594
|
-
},
|
|
595
|
-
_errorSteps: function (reason) {
|
|
596
|
-
_this._ongoingPromise = undefined;
|
|
597
|
-
_this._isFinished = true;
|
|
598
|
-
ReadableStreamReaderGenericRelease(reader);
|
|
599
|
-
rejectPromise(reason);
|
|
600
|
-
}
|
|
601
|
-
};
|
|
602
|
-
ReadableStreamDefaultReaderRead(reader, readRequest);
|
|
603
|
-
return promise;
|
|
604
|
-
};
|
|
605
|
-
ReadableStreamAsyncIteratorImpl.prototype._returnSteps = function (value) {
|
|
606
|
-
if (this._isFinished) {
|
|
607
|
-
return Promise.resolve({ value: value, done: true });
|
|
608
|
-
}
|
|
609
|
-
this._isFinished = true;
|
|
610
|
-
var reader = this._reader;
|
|
611
|
-
if (reader._ownerReadableStream === undefined) {
|
|
612
|
-
return promiseRejectedWith(readerLockException('finish iterating'));
|
|
613
|
-
}
|
|
614
|
-
if (!this._preventCancel) {
|
|
615
|
-
var result = ReadableStreamReaderGenericCancel(reader, value);
|
|
616
|
-
ReadableStreamReaderGenericRelease(reader);
|
|
617
|
-
return transformPromiseWith(result, function () { return ({ value: value, done: true }); });
|
|
618
|
-
}
|
|
619
|
-
ReadableStreamReaderGenericRelease(reader);
|
|
620
|
-
return promiseResolvedWith({ value: value, done: true });
|
|
621
|
-
};
|
|
622
|
-
return ReadableStreamAsyncIteratorImpl;
|
|
623
|
-
}());
|
|
624
|
-
var ReadableStreamAsyncIteratorPrototype = {
|
|
625
|
-
next: function () {
|
|
626
|
-
if (!IsReadableStreamAsyncIterator(this)) {
|
|
627
|
-
return promiseRejectedWith(streamAsyncIteratorBrandCheckException('next'));
|
|
628
|
-
}
|
|
629
|
-
return this._asyncIteratorImpl.next();
|
|
630
|
-
},
|
|
631
|
-
return: function (value) {
|
|
632
|
-
if (!IsReadableStreamAsyncIterator(this)) {
|
|
633
|
-
return promiseRejectedWith(streamAsyncIteratorBrandCheckException('return'));
|
|
634
|
-
}
|
|
635
|
-
return this._asyncIteratorImpl.return(value);
|
|
636
|
-
}
|
|
637
|
-
};
|
|
638
|
-
if (AsyncIteratorPrototype !== undefined) {
|
|
639
|
-
Object.setPrototypeOf(ReadableStreamAsyncIteratorPrototype, AsyncIteratorPrototype);
|
|
640
|
-
}
|
|
641
|
-
// Abstract operations for the ReadableStream.
|
|
642
|
-
function AcquireReadableStreamAsyncIterator(stream, preventCancel) {
|
|
643
|
-
var reader = AcquireReadableStreamDefaultReader(stream);
|
|
644
|
-
var impl = new ReadableStreamAsyncIteratorImpl(reader, preventCancel);
|
|
645
|
-
var iterator = Object.create(ReadableStreamAsyncIteratorPrototype);
|
|
646
|
-
iterator._asyncIteratorImpl = impl;
|
|
647
|
-
return iterator;
|
|
648
|
-
}
|
|
649
|
-
function IsReadableStreamAsyncIterator(x) {
|
|
650
|
-
if (!typeIsObject(x)) {
|
|
651
|
-
return false;
|
|
652
|
-
}
|
|
653
|
-
if (!Object.prototype.hasOwnProperty.call(x, '_asyncIteratorImpl')) {
|
|
654
|
-
return false;
|
|
655
|
-
}
|
|
656
|
-
return true;
|
|
657
|
-
}
|
|
658
|
-
// Helper functions for the ReadableStream.
|
|
659
|
-
function streamAsyncIteratorBrandCheckException(name) {
|
|
660
|
-
return new TypeError("ReadableStreamAsyncIterator." + name + " can only be used on a ReadableSteamAsyncIterator");
|
|
661
|
-
}
|
|
662
|
-
|
|
663
|
-
/// <reference lib="es2015.core" />
|
|
664
|
-
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isNaN#Polyfill
|
|
665
|
-
var NumberIsNaN = Number.isNaN || function (x) {
|
|
666
|
-
// eslint-disable-next-line no-self-compare
|
|
667
|
-
return x !== x;
|
|
668
|
-
};
|
|
669
|
-
|
|
670
|
-
function IsFiniteNonNegativeNumber(v) {
|
|
671
|
-
if (!IsNonNegativeNumber(v)) {
|
|
672
|
-
return false;
|
|
673
|
-
}
|
|
674
|
-
if (v === Infinity) {
|
|
675
|
-
return false;
|
|
676
|
-
}
|
|
677
|
-
return true;
|
|
678
|
-
}
|
|
679
|
-
function IsNonNegativeNumber(v) {
|
|
680
|
-
if (typeof v !== 'number') {
|
|
681
|
-
return false;
|
|
682
|
-
}
|
|
683
|
-
if (NumberIsNaN(v)) {
|
|
684
|
-
return false;
|
|
685
|
-
}
|
|
686
|
-
if (v < 0) {
|
|
687
|
-
return false;
|
|
688
|
-
}
|
|
689
|
-
return true;
|
|
690
|
-
}
|
|
691
|
-
|
|
692
|
-
function DequeueValue(container) {
|
|
693
|
-
var pair = container._queue.shift();
|
|
694
|
-
container._queueTotalSize -= pair.size;
|
|
695
|
-
if (container._queueTotalSize < 0) {
|
|
696
|
-
container._queueTotalSize = 0;
|
|
697
|
-
}
|
|
698
|
-
return pair.value;
|
|
699
|
-
}
|
|
700
|
-
function EnqueueValueWithSize(container, value, size) {
|
|
701
|
-
size = Number(size);
|
|
702
|
-
if (!IsFiniteNonNegativeNumber(size)) {
|
|
703
|
-
throw new RangeError('Size must be a finite, non-NaN, non-negative number.');
|
|
704
|
-
}
|
|
705
|
-
container._queue.push({ value: value, size: size });
|
|
706
|
-
container._queueTotalSize += size;
|
|
707
|
-
}
|
|
708
|
-
function PeekQueueValue(container) {
|
|
709
|
-
var pair = container._queue.peek();
|
|
710
|
-
return pair.value;
|
|
711
|
-
}
|
|
712
|
-
function ResetQueue(container) {
|
|
713
|
-
container._queue = new SimpleQueue();
|
|
714
|
-
container._queueTotalSize = 0;
|
|
715
|
-
}
|
|
716
|
-
|
|
717
|
-
function CreateArrayFromList(elements) {
|
|
718
|
-
// We use arrays to represent lists, so this is basically a no-op.
|
|
719
|
-
// Do a slice though just in case we happen to depend on the unique-ness.
|
|
720
|
-
return elements.slice();
|
|
721
|
-
}
|
|
722
|
-
function CopyDataBlockBytes(dest, destOffset, src, srcOffset, n) {
|
|
723
|
-
new Uint8Array(dest).set(new Uint8Array(src, srcOffset, n), destOffset);
|
|
724
|
-
}
|
|
725
|
-
// Not implemented correctly
|
|
726
|
-
function TransferArrayBuffer(O) {
|
|
727
|
-
return O;
|
|
728
|
-
}
|
|
729
|
-
// Not implemented correctly
|
|
730
|
-
function IsDetachedBuffer(O) {
|
|
731
|
-
return false;
|
|
732
|
-
}
|
|
733
|
-
|
|
734
|
-
/**
|
|
735
|
-
* A pull-into request in a {@link ReadableByteStreamController}.
|
|
736
|
-
*
|
|
737
|
-
* @public
|
|
738
|
-
*/
|
|
739
|
-
var ReadableStreamBYOBRequest = /** @class */ (function () {
|
|
740
|
-
function ReadableStreamBYOBRequest() {
|
|
741
|
-
throw new TypeError('Illegal constructor');
|
|
742
|
-
}
|
|
743
|
-
Object.defineProperty(ReadableStreamBYOBRequest.prototype, "view", {
|
|
744
|
-
/**
|
|
745
|
-
* Returns the view for writing in to, or `null` if the BYOB request has already been responded to.
|
|
746
|
-
*/
|
|
747
|
-
get: function () {
|
|
748
|
-
if (!IsReadableStreamBYOBRequest(this)) {
|
|
749
|
-
throw byobRequestBrandCheckException('view');
|
|
750
|
-
}
|
|
751
|
-
return this._view;
|
|
752
|
-
},
|
|
753
|
-
enumerable: false,
|
|
754
|
-
configurable: true
|
|
755
|
-
});
|
|
756
|
-
ReadableStreamBYOBRequest.prototype.respond = function (bytesWritten) {
|
|
757
|
-
if (!IsReadableStreamBYOBRequest(this)) {
|
|
758
|
-
throw byobRequestBrandCheckException('respond');
|
|
759
|
-
}
|
|
760
|
-
assertRequiredArgument(bytesWritten, 1, 'respond');
|
|
761
|
-
bytesWritten = convertUnsignedLongLongWithEnforceRange(bytesWritten, 'First parameter');
|
|
762
|
-
if (this._associatedReadableByteStreamController === undefined) {
|
|
763
|
-
throw new TypeError('This BYOB request has been invalidated');
|
|
764
|
-
}
|
|
765
|
-
if (IsDetachedBuffer(this._view.buffer)) ;
|
|
766
|
-
ReadableByteStreamControllerRespond(this._associatedReadableByteStreamController, bytesWritten);
|
|
767
|
-
};
|
|
768
|
-
ReadableStreamBYOBRequest.prototype.respondWithNewView = function (view) {
|
|
769
|
-
if (!IsReadableStreamBYOBRequest(this)) {
|
|
770
|
-
throw byobRequestBrandCheckException('respondWithNewView');
|
|
771
|
-
}
|
|
772
|
-
assertRequiredArgument(view, 1, 'respondWithNewView');
|
|
773
|
-
if (!ArrayBuffer.isView(view)) {
|
|
774
|
-
throw new TypeError('You can only respond with array buffer views');
|
|
775
|
-
}
|
|
776
|
-
if (view.byteLength === 0) {
|
|
777
|
-
throw new TypeError('chunk must have non-zero byteLength');
|
|
778
|
-
}
|
|
779
|
-
if (view.buffer.byteLength === 0) {
|
|
780
|
-
throw new TypeError("chunk's buffer must have non-zero byteLength");
|
|
781
|
-
}
|
|
782
|
-
if (this._associatedReadableByteStreamController === undefined) {
|
|
783
|
-
throw new TypeError('This BYOB request has been invalidated');
|
|
784
|
-
}
|
|
785
|
-
ReadableByteStreamControllerRespondWithNewView(this._associatedReadableByteStreamController, view);
|
|
786
|
-
};
|
|
787
|
-
return ReadableStreamBYOBRequest;
|
|
788
|
-
}());
|
|
789
|
-
Object.defineProperties(ReadableStreamBYOBRequest.prototype, {
|
|
790
|
-
respond: { enumerable: true },
|
|
791
|
-
respondWithNewView: { enumerable: true },
|
|
792
|
-
view: { enumerable: true }
|
|
793
|
-
});
|
|
794
|
-
if (typeof SymbolPolyfill.toStringTag === 'symbol') {
|
|
795
|
-
Object.defineProperty(ReadableStreamBYOBRequest.prototype, SymbolPolyfill.toStringTag, {
|
|
796
|
-
value: 'ReadableStreamBYOBRequest',
|
|
797
|
-
configurable: true
|
|
798
|
-
});
|
|
799
|
-
}
|
|
800
|
-
/**
|
|
801
|
-
* Allows control of a {@link ReadableStream | readable byte stream}'s state and internal queue.
|
|
802
|
-
*
|
|
803
|
-
* @public
|
|
804
|
-
*/
|
|
805
|
-
var ReadableByteStreamController = /** @class */ (function () {
|
|
806
|
-
function ReadableByteStreamController() {
|
|
807
|
-
throw new TypeError('Illegal constructor');
|
|
808
|
-
}
|
|
809
|
-
Object.defineProperty(ReadableByteStreamController.prototype, "byobRequest", {
|
|
810
|
-
/**
|
|
811
|
-
* Returns the current BYOB pull request, or `null` if there isn't one.
|
|
812
|
-
*/
|
|
813
|
-
get: function () {
|
|
814
|
-
if (!IsReadableByteStreamController(this)) {
|
|
815
|
-
throw byteStreamControllerBrandCheckException('byobRequest');
|
|
816
|
-
}
|
|
817
|
-
if (this._byobRequest === null && this._pendingPullIntos.length > 0) {
|
|
818
|
-
var firstDescriptor = this._pendingPullIntos.peek();
|
|
819
|
-
var view = new Uint8Array(firstDescriptor.buffer, firstDescriptor.byteOffset + firstDescriptor.bytesFilled, firstDescriptor.byteLength - firstDescriptor.bytesFilled);
|
|
820
|
-
var byobRequest = Object.create(ReadableStreamBYOBRequest.prototype);
|
|
821
|
-
SetUpReadableStreamBYOBRequest(byobRequest, this, view);
|
|
822
|
-
this._byobRequest = byobRequest;
|
|
823
|
-
}
|
|
824
|
-
return this._byobRequest;
|
|
825
|
-
},
|
|
826
|
-
enumerable: false,
|
|
827
|
-
configurable: true
|
|
828
|
-
});
|
|
829
|
-
Object.defineProperty(ReadableByteStreamController.prototype, "desiredSize", {
|
|
830
|
-
/**
|
|
831
|
-
* Returns the desired size to fill the controlled stream's internal queue. It can be negative, if the queue is
|
|
832
|
-
* over-full. An underlying byte source ought to use this information to determine when and how to apply backpressure.
|
|
833
|
-
*/
|
|
834
|
-
get: function () {
|
|
835
|
-
if (!IsReadableByteStreamController(this)) {
|
|
836
|
-
throw byteStreamControllerBrandCheckException('desiredSize');
|
|
837
|
-
}
|
|
838
|
-
return ReadableByteStreamControllerGetDesiredSize(this);
|
|
839
|
-
},
|
|
840
|
-
enumerable: false,
|
|
841
|
-
configurable: true
|
|
842
|
-
});
|
|
843
|
-
/**
|
|
844
|
-
* Closes the controlled readable stream. Consumers will still be able to read any previously-enqueued chunks from
|
|
845
|
-
* the stream, but once those are read, the stream will become closed.
|
|
846
|
-
*/
|
|
847
|
-
ReadableByteStreamController.prototype.close = function () {
|
|
848
|
-
if (!IsReadableByteStreamController(this)) {
|
|
849
|
-
throw byteStreamControllerBrandCheckException('close');
|
|
850
|
-
}
|
|
851
|
-
if (this._closeRequested) {
|
|
852
|
-
throw new TypeError('The stream has already been closed; do not close it again!');
|
|
853
|
-
}
|
|
854
|
-
var state = this._controlledReadableByteStream._state;
|
|
855
|
-
if (state !== 'readable') {
|
|
856
|
-
throw new TypeError("The stream (in " + state + " state) is not in the readable state and cannot be closed");
|
|
857
|
-
}
|
|
858
|
-
ReadableByteStreamControllerClose(this);
|
|
859
|
-
};
|
|
860
|
-
ReadableByteStreamController.prototype.enqueue = function (chunk) {
|
|
861
|
-
if (!IsReadableByteStreamController(this)) {
|
|
862
|
-
throw byteStreamControllerBrandCheckException('enqueue');
|
|
863
|
-
}
|
|
864
|
-
assertRequiredArgument(chunk, 1, 'enqueue');
|
|
865
|
-
if (!ArrayBuffer.isView(chunk)) {
|
|
866
|
-
throw new TypeError('chunk must be an array buffer view');
|
|
867
|
-
}
|
|
868
|
-
if (chunk.byteLength === 0) {
|
|
869
|
-
throw new TypeError('chunk must have non-zero byteLength');
|
|
870
|
-
}
|
|
871
|
-
if (chunk.buffer.byteLength === 0) {
|
|
872
|
-
throw new TypeError("chunk's buffer must have non-zero byteLength");
|
|
873
|
-
}
|
|
874
|
-
if (this._closeRequested) {
|
|
875
|
-
throw new TypeError('stream is closed or draining');
|
|
876
|
-
}
|
|
877
|
-
var state = this._controlledReadableByteStream._state;
|
|
878
|
-
if (state !== 'readable') {
|
|
879
|
-
throw new TypeError("The stream (in " + state + " state) is not in the readable state and cannot be enqueued to");
|
|
880
|
-
}
|
|
881
|
-
ReadableByteStreamControllerEnqueue(this, chunk);
|
|
882
|
-
};
|
|
883
|
-
/**
|
|
884
|
-
* Errors the controlled readable stream, making all future interactions with it fail with the given error `e`.
|
|
885
|
-
*/
|
|
886
|
-
ReadableByteStreamController.prototype.error = function (e) {
|
|
887
|
-
if (e === void 0) { e = undefined; }
|
|
888
|
-
if (!IsReadableByteStreamController(this)) {
|
|
889
|
-
throw byteStreamControllerBrandCheckException('error');
|
|
890
|
-
}
|
|
891
|
-
ReadableByteStreamControllerError(this, e);
|
|
892
|
-
};
|
|
893
|
-
/** @internal */
|
|
894
|
-
ReadableByteStreamController.prototype[CancelSteps] = function (reason) {
|
|
895
|
-
if (this._pendingPullIntos.length > 0) {
|
|
896
|
-
var firstDescriptor = this._pendingPullIntos.peek();
|
|
897
|
-
firstDescriptor.bytesFilled = 0;
|
|
898
|
-
}
|
|
899
|
-
ResetQueue(this);
|
|
900
|
-
var result = this._cancelAlgorithm(reason);
|
|
901
|
-
ReadableByteStreamControllerClearAlgorithms(this);
|
|
902
|
-
return result;
|
|
903
|
-
};
|
|
904
|
-
/** @internal */
|
|
905
|
-
ReadableByteStreamController.prototype[PullSteps] = function (readRequest) {
|
|
906
|
-
var stream = this._controlledReadableByteStream;
|
|
907
|
-
if (this._queueTotalSize > 0) {
|
|
908
|
-
var entry = this._queue.shift();
|
|
909
|
-
this._queueTotalSize -= entry.byteLength;
|
|
910
|
-
ReadableByteStreamControllerHandleQueueDrain(this);
|
|
911
|
-
var view = new Uint8Array(entry.buffer, entry.byteOffset, entry.byteLength);
|
|
912
|
-
readRequest._chunkSteps(view);
|
|
913
|
-
return;
|
|
914
|
-
}
|
|
915
|
-
var autoAllocateChunkSize = this._autoAllocateChunkSize;
|
|
916
|
-
if (autoAllocateChunkSize !== undefined) {
|
|
917
|
-
var buffer = void 0;
|
|
918
|
-
try {
|
|
919
|
-
buffer = new ArrayBuffer(autoAllocateChunkSize);
|
|
920
|
-
}
|
|
921
|
-
catch (bufferE) {
|
|
922
|
-
readRequest._errorSteps(bufferE);
|
|
923
|
-
return;
|
|
924
|
-
}
|
|
925
|
-
var pullIntoDescriptor = {
|
|
926
|
-
buffer: buffer,
|
|
927
|
-
byteOffset: 0,
|
|
928
|
-
byteLength: autoAllocateChunkSize,
|
|
929
|
-
bytesFilled: 0,
|
|
930
|
-
elementSize: 1,
|
|
931
|
-
viewConstructor: Uint8Array,
|
|
932
|
-
readerType: 'default'
|
|
933
|
-
};
|
|
934
|
-
this._pendingPullIntos.push(pullIntoDescriptor);
|
|
935
|
-
}
|
|
936
|
-
ReadableStreamAddReadRequest(stream, readRequest);
|
|
937
|
-
ReadableByteStreamControllerCallPullIfNeeded(this);
|
|
938
|
-
};
|
|
939
|
-
return ReadableByteStreamController;
|
|
940
|
-
}());
|
|
941
|
-
Object.defineProperties(ReadableByteStreamController.prototype, {
|
|
942
|
-
close: { enumerable: true },
|
|
943
|
-
enqueue: { enumerable: true },
|
|
944
|
-
error: { enumerable: true },
|
|
945
|
-
byobRequest: { enumerable: true },
|
|
946
|
-
desiredSize: { enumerable: true }
|
|
947
|
-
});
|
|
948
|
-
if (typeof SymbolPolyfill.toStringTag === 'symbol') {
|
|
949
|
-
Object.defineProperty(ReadableByteStreamController.prototype, SymbolPolyfill.toStringTag, {
|
|
950
|
-
value: 'ReadableByteStreamController',
|
|
951
|
-
configurable: true
|
|
952
|
-
});
|
|
953
|
-
}
|
|
954
|
-
// Abstract operations for the ReadableByteStreamController.
|
|
955
|
-
function IsReadableByteStreamController(x) {
|
|
956
|
-
if (!typeIsObject(x)) {
|
|
957
|
-
return false;
|
|
958
|
-
}
|
|
959
|
-
if (!Object.prototype.hasOwnProperty.call(x, '_controlledReadableByteStream')) {
|
|
960
|
-
return false;
|
|
961
|
-
}
|
|
962
|
-
return true;
|
|
963
|
-
}
|
|
964
|
-
function IsReadableStreamBYOBRequest(x) {
|
|
965
|
-
if (!typeIsObject(x)) {
|
|
966
|
-
return false;
|
|
967
|
-
}
|
|
968
|
-
if (!Object.prototype.hasOwnProperty.call(x, '_associatedReadableByteStreamController')) {
|
|
969
|
-
return false;
|
|
970
|
-
}
|
|
971
|
-
return true;
|
|
972
|
-
}
|
|
973
|
-
function ReadableByteStreamControllerCallPullIfNeeded(controller) {
|
|
974
|
-
var shouldPull = ReadableByteStreamControllerShouldCallPull(controller);
|
|
975
|
-
if (!shouldPull) {
|
|
976
|
-
return;
|
|
977
|
-
}
|
|
978
|
-
if (controller._pulling) {
|
|
979
|
-
controller._pullAgain = true;
|
|
980
|
-
return;
|
|
981
|
-
}
|
|
982
|
-
controller._pulling = true;
|
|
983
|
-
// TODO: Test controller argument
|
|
984
|
-
var pullPromise = controller._pullAlgorithm();
|
|
985
|
-
uponPromise(pullPromise, function () {
|
|
986
|
-
controller._pulling = false;
|
|
987
|
-
if (controller._pullAgain) {
|
|
988
|
-
controller._pullAgain = false;
|
|
989
|
-
ReadableByteStreamControllerCallPullIfNeeded(controller);
|
|
990
|
-
}
|
|
991
|
-
}, function (e) {
|
|
992
|
-
ReadableByteStreamControllerError(controller, e);
|
|
993
|
-
});
|
|
994
|
-
}
|
|
995
|
-
function ReadableByteStreamControllerClearPendingPullIntos(controller) {
|
|
996
|
-
ReadableByteStreamControllerInvalidateBYOBRequest(controller);
|
|
997
|
-
controller._pendingPullIntos = new SimpleQueue();
|
|
998
|
-
}
|
|
999
|
-
function ReadableByteStreamControllerCommitPullIntoDescriptor(stream, pullIntoDescriptor) {
|
|
1000
|
-
var done = false;
|
|
1001
|
-
if (stream._state === 'closed') {
|
|
1002
|
-
done = true;
|
|
1003
|
-
}
|
|
1004
|
-
var filledView = ReadableByteStreamControllerConvertPullIntoDescriptor(pullIntoDescriptor);
|
|
1005
|
-
if (pullIntoDescriptor.readerType === 'default') {
|
|
1006
|
-
ReadableStreamFulfillReadRequest(stream, filledView, done);
|
|
1007
|
-
}
|
|
1008
|
-
else {
|
|
1009
|
-
ReadableStreamFulfillReadIntoRequest(stream, filledView, done);
|
|
1010
|
-
}
|
|
1011
|
-
}
|
|
1012
|
-
function ReadableByteStreamControllerConvertPullIntoDescriptor(pullIntoDescriptor) {
|
|
1013
|
-
var bytesFilled = pullIntoDescriptor.bytesFilled;
|
|
1014
|
-
var elementSize = pullIntoDescriptor.elementSize;
|
|
1015
|
-
return new pullIntoDescriptor.viewConstructor(pullIntoDescriptor.buffer, pullIntoDescriptor.byteOffset, bytesFilled / elementSize);
|
|
1016
|
-
}
|
|
1017
|
-
function ReadableByteStreamControllerEnqueueChunkToQueue(controller, buffer, byteOffset, byteLength) {
|
|
1018
|
-
controller._queue.push({ buffer: buffer, byteOffset: byteOffset, byteLength: byteLength });
|
|
1019
|
-
controller._queueTotalSize += byteLength;
|
|
1020
|
-
}
|
|
1021
|
-
function ReadableByteStreamControllerFillPullIntoDescriptorFromQueue(controller, pullIntoDescriptor) {
|
|
1022
|
-
var elementSize = pullIntoDescriptor.elementSize;
|
|
1023
|
-
var currentAlignedBytes = pullIntoDescriptor.bytesFilled - pullIntoDescriptor.bytesFilled % elementSize;
|
|
1024
|
-
var maxBytesToCopy = Math.min(controller._queueTotalSize, pullIntoDescriptor.byteLength - pullIntoDescriptor.bytesFilled);
|
|
1025
|
-
var maxBytesFilled = pullIntoDescriptor.bytesFilled + maxBytesToCopy;
|
|
1026
|
-
var maxAlignedBytes = maxBytesFilled - maxBytesFilled % elementSize;
|
|
1027
|
-
var totalBytesToCopyRemaining = maxBytesToCopy;
|
|
1028
|
-
var ready = false;
|
|
1029
|
-
if (maxAlignedBytes > currentAlignedBytes) {
|
|
1030
|
-
totalBytesToCopyRemaining = maxAlignedBytes - pullIntoDescriptor.bytesFilled;
|
|
1031
|
-
ready = true;
|
|
1032
|
-
}
|
|
1033
|
-
var queue = controller._queue;
|
|
1034
|
-
while (totalBytesToCopyRemaining > 0) {
|
|
1035
|
-
var headOfQueue = queue.peek();
|
|
1036
|
-
var bytesToCopy = Math.min(totalBytesToCopyRemaining, headOfQueue.byteLength);
|
|
1037
|
-
var destStart = pullIntoDescriptor.byteOffset + pullIntoDescriptor.bytesFilled;
|
|
1038
|
-
CopyDataBlockBytes(pullIntoDescriptor.buffer, destStart, headOfQueue.buffer, headOfQueue.byteOffset, bytesToCopy);
|
|
1039
|
-
if (headOfQueue.byteLength === bytesToCopy) {
|
|
1040
|
-
queue.shift();
|
|
1041
|
-
}
|
|
1042
|
-
else {
|
|
1043
|
-
headOfQueue.byteOffset += bytesToCopy;
|
|
1044
|
-
headOfQueue.byteLength -= bytesToCopy;
|
|
1045
|
-
}
|
|
1046
|
-
controller._queueTotalSize -= bytesToCopy;
|
|
1047
|
-
ReadableByteStreamControllerFillHeadPullIntoDescriptor(controller, bytesToCopy, pullIntoDescriptor);
|
|
1048
|
-
totalBytesToCopyRemaining -= bytesToCopy;
|
|
1049
|
-
}
|
|
1050
|
-
return ready;
|
|
1051
|
-
}
|
|
1052
|
-
function ReadableByteStreamControllerFillHeadPullIntoDescriptor(controller, size, pullIntoDescriptor) {
|
|
1053
|
-
ReadableByteStreamControllerInvalidateBYOBRequest(controller);
|
|
1054
|
-
pullIntoDescriptor.bytesFilled += size;
|
|
1055
|
-
}
|
|
1056
|
-
function ReadableByteStreamControllerHandleQueueDrain(controller) {
|
|
1057
|
-
if (controller._queueTotalSize === 0 && controller._closeRequested) {
|
|
1058
|
-
ReadableByteStreamControllerClearAlgorithms(controller);
|
|
1059
|
-
ReadableStreamClose(controller._controlledReadableByteStream);
|
|
1060
|
-
}
|
|
1061
|
-
else {
|
|
1062
|
-
ReadableByteStreamControllerCallPullIfNeeded(controller);
|
|
1063
|
-
}
|
|
1064
|
-
}
|
|
1065
|
-
function ReadableByteStreamControllerInvalidateBYOBRequest(controller) {
|
|
1066
|
-
if (controller._byobRequest === null) {
|
|
1067
|
-
return;
|
|
1068
|
-
}
|
|
1069
|
-
controller._byobRequest._associatedReadableByteStreamController = undefined;
|
|
1070
|
-
controller._byobRequest._view = null;
|
|
1071
|
-
controller._byobRequest = null;
|
|
1072
|
-
}
|
|
1073
|
-
function ReadableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(controller) {
|
|
1074
|
-
while (controller._pendingPullIntos.length > 0) {
|
|
1075
|
-
if (controller._queueTotalSize === 0) {
|
|
1076
|
-
return;
|
|
1077
|
-
}
|
|
1078
|
-
var pullIntoDescriptor = controller._pendingPullIntos.peek();
|
|
1079
|
-
if (ReadableByteStreamControllerFillPullIntoDescriptorFromQueue(controller, pullIntoDescriptor)) {
|
|
1080
|
-
ReadableByteStreamControllerShiftPendingPullInto(controller);
|
|
1081
|
-
ReadableByteStreamControllerCommitPullIntoDescriptor(controller._controlledReadableByteStream, pullIntoDescriptor);
|
|
1082
|
-
}
|
|
1083
|
-
}
|
|
1084
|
-
}
|
|
1085
|
-
function ReadableByteStreamControllerPullInto(controller, view, readIntoRequest) {
|
|
1086
|
-
var stream = controller._controlledReadableByteStream;
|
|
1087
|
-
var elementSize = 1;
|
|
1088
|
-
if (view.constructor !== DataView) {
|
|
1089
|
-
elementSize = view.constructor.BYTES_PER_ELEMENT;
|
|
1090
|
-
}
|
|
1091
|
-
var ctor = view.constructor;
|
|
1092
|
-
var buffer = TransferArrayBuffer(view.buffer);
|
|
1093
|
-
var pullIntoDescriptor = {
|
|
1094
|
-
buffer: buffer,
|
|
1095
|
-
byteOffset: view.byteOffset,
|
|
1096
|
-
byteLength: view.byteLength,
|
|
1097
|
-
bytesFilled: 0,
|
|
1098
|
-
elementSize: elementSize,
|
|
1099
|
-
viewConstructor: ctor,
|
|
1100
|
-
readerType: 'byob'
|
|
1101
|
-
};
|
|
1102
|
-
if (controller._pendingPullIntos.length > 0) {
|
|
1103
|
-
controller._pendingPullIntos.push(pullIntoDescriptor);
|
|
1104
|
-
// No ReadableByteStreamControllerCallPullIfNeeded() call since:
|
|
1105
|
-
// - No change happens on desiredSize
|
|
1106
|
-
// - The source has already been notified of that there's at least 1 pending read(view)
|
|
1107
|
-
ReadableStreamAddReadIntoRequest(stream, readIntoRequest);
|
|
1108
|
-
return;
|
|
1109
|
-
}
|
|
1110
|
-
if (stream._state === 'closed') {
|
|
1111
|
-
var emptyView = new ctor(pullIntoDescriptor.buffer, pullIntoDescriptor.byteOffset, 0);
|
|
1112
|
-
readIntoRequest._closeSteps(emptyView);
|
|
1113
|
-
return;
|
|
1114
|
-
}
|
|
1115
|
-
if (controller._queueTotalSize > 0) {
|
|
1116
|
-
if (ReadableByteStreamControllerFillPullIntoDescriptorFromQueue(controller, pullIntoDescriptor)) {
|
|
1117
|
-
var filledView = ReadableByteStreamControllerConvertPullIntoDescriptor(pullIntoDescriptor);
|
|
1118
|
-
ReadableByteStreamControllerHandleQueueDrain(controller);
|
|
1119
|
-
readIntoRequest._chunkSteps(filledView);
|
|
1120
|
-
return;
|
|
1121
|
-
}
|
|
1122
|
-
if (controller._closeRequested) {
|
|
1123
|
-
var e = new TypeError('Insufficient bytes to fill elements in the given buffer');
|
|
1124
|
-
ReadableByteStreamControllerError(controller, e);
|
|
1125
|
-
readIntoRequest._errorSteps(e);
|
|
1126
|
-
return;
|
|
1127
|
-
}
|
|
1128
|
-
}
|
|
1129
|
-
controller._pendingPullIntos.push(pullIntoDescriptor);
|
|
1130
|
-
ReadableStreamAddReadIntoRequest(stream, readIntoRequest);
|
|
1131
|
-
ReadableByteStreamControllerCallPullIfNeeded(controller);
|
|
1132
|
-
}
|
|
1133
|
-
function ReadableByteStreamControllerRespondInClosedState(controller, firstDescriptor) {
|
|
1134
|
-
firstDescriptor.buffer = TransferArrayBuffer(firstDescriptor.buffer);
|
|
1135
|
-
var stream = controller._controlledReadableByteStream;
|
|
1136
|
-
if (ReadableStreamHasBYOBReader(stream)) {
|
|
1137
|
-
while (ReadableStreamGetNumReadIntoRequests(stream) > 0) {
|
|
1138
|
-
var pullIntoDescriptor = ReadableByteStreamControllerShiftPendingPullInto(controller);
|
|
1139
|
-
ReadableByteStreamControllerCommitPullIntoDescriptor(stream, pullIntoDescriptor);
|
|
1140
|
-
}
|
|
1141
|
-
}
|
|
1142
|
-
}
|
|
1143
|
-
function ReadableByteStreamControllerRespondInReadableState(controller, bytesWritten, pullIntoDescriptor) {
|
|
1144
|
-
if (pullIntoDescriptor.bytesFilled + bytesWritten > pullIntoDescriptor.byteLength) {
|
|
1145
|
-
throw new RangeError('bytesWritten out of range');
|
|
1146
|
-
}
|
|
1147
|
-
ReadableByteStreamControllerFillHeadPullIntoDescriptor(controller, bytesWritten, pullIntoDescriptor);
|
|
1148
|
-
if (pullIntoDescriptor.bytesFilled < pullIntoDescriptor.elementSize) {
|
|
1149
|
-
// TODO: Figure out whether we should detach the buffer or not here.
|
|
1150
|
-
return;
|
|
1151
|
-
}
|
|
1152
|
-
ReadableByteStreamControllerShiftPendingPullInto(controller);
|
|
1153
|
-
var remainderSize = pullIntoDescriptor.bytesFilled % pullIntoDescriptor.elementSize;
|
|
1154
|
-
if (remainderSize > 0) {
|
|
1155
|
-
var end = pullIntoDescriptor.byteOffset + pullIntoDescriptor.bytesFilled;
|
|
1156
|
-
var remainder = pullIntoDescriptor.buffer.slice(end - remainderSize, end);
|
|
1157
|
-
ReadableByteStreamControllerEnqueueChunkToQueue(controller, remainder, 0, remainder.byteLength);
|
|
1158
|
-
}
|
|
1159
|
-
pullIntoDescriptor.buffer = TransferArrayBuffer(pullIntoDescriptor.buffer);
|
|
1160
|
-
pullIntoDescriptor.bytesFilled -= remainderSize;
|
|
1161
|
-
ReadableByteStreamControllerCommitPullIntoDescriptor(controller._controlledReadableByteStream, pullIntoDescriptor);
|
|
1162
|
-
ReadableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(controller);
|
|
1163
|
-
}
|
|
1164
|
-
function ReadableByteStreamControllerRespondInternal(controller, bytesWritten) {
|
|
1165
|
-
var firstDescriptor = controller._pendingPullIntos.peek();
|
|
1166
|
-
var state = controller._controlledReadableByteStream._state;
|
|
1167
|
-
if (state === 'closed') {
|
|
1168
|
-
if (bytesWritten !== 0) {
|
|
1169
|
-
throw new TypeError('bytesWritten must be 0 when calling respond() on a closed stream');
|
|
1170
|
-
}
|
|
1171
|
-
ReadableByteStreamControllerRespondInClosedState(controller, firstDescriptor);
|
|
1172
|
-
}
|
|
1173
|
-
else {
|
|
1174
|
-
ReadableByteStreamControllerRespondInReadableState(controller, bytesWritten, firstDescriptor);
|
|
1175
|
-
}
|
|
1176
|
-
ReadableByteStreamControllerCallPullIfNeeded(controller);
|
|
1177
|
-
}
|
|
1178
|
-
function ReadableByteStreamControllerShiftPendingPullInto(controller) {
|
|
1179
|
-
var descriptor = controller._pendingPullIntos.shift();
|
|
1180
|
-
ReadableByteStreamControllerInvalidateBYOBRequest(controller);
|
|
1181
|
-
return descriptor;
|
|
1182
|
-
}
|
|
1183
|
-
function ReadableByteStreamControllerShouldCallPull(controller) {
|
|
1184
|
-
var stream = controller._controlledReadableByteStream;
|
|
1185
|
-
if (stream._state !== 'readable') {
|
|
1186
|
-
return false;
|
|
1187
|
-
}
|
|
1188
|
-
if (controller._closeRequested) {
|
|
1189
|
-
return false;
|
|
1190
|
-
}
|
|
1191
|
-
if (!controller._started) {
|
|
1192
|
-
return false;
|
|
1193
|
-
}
|
|
1194
|
-
if (ReadableStreamHasDefaultReader(stream) && ReadableStreamGetNumReadRequests(stream) > 0) {
|
|
1195
|
-
return true;
|
|
1196
|
-
}
|
|
1197
|
-
if (ReadableStreamHasBYOBReader(stream) && ReadableStreamGetNumReadIntoRequests(stream) > 0) {
|
|
1198
|
-
return true;
|
|
1199
|
-
}
|
|
1200
|
-
var desiredSize = ReadableByteStreamControllerGetDesiredSize(controller);
|
|
1201
|
-
if (desiredSize > 0) {
|
|
1202
|
-
return true;
|
|
1203
|
-
}
|
|
1204
|
-
return false;
|
|
1205
|
-
}
|
|
1206
|
-
function ReadableByteStreamControllerClearAlgorithms(controller) {
|
|
1207
|
-
controller._pullAlgorithm = undefined;
|
|
1208
|
-
controller._cancelAlgorithm = undefined;
|
|
1209
|
-
}
|
|
1210
|
-
// A client of ReadableByteStreamController may use these functions directly to bypass state check.
|
|
1211
|
-
function ReadableByteStreamControllerClose(controller) {
|
|
1212
|
-
var stream = controller._controlledReadableByteStream;
|
|
1213
|
-
if (controller._closeRequested || stream._state !== 'readable') {
|
|
1214
|
-
return;
|
|
1215
|
-
}
|
|
1216
|
-
if (controller._queueTotalSize > 0) {
|
|
1217
|
-
controller._closeRequested = true;
|
|
1218
|
-
return;
|
|
1219
|
-
}
|
|
1220
|
-
if (controller._pendingPullIntos.length > 0) {
|
|
1221
|
-
var firstPendingPullInto = controller._pendingPullIntos.peek();
|
|
1222
|
-
if (firstPendingPullInto.bytesFilled > 0) {
|
|
1223
|
-
var e = new TypeError('Insufficient bytes to fill elements in the given buffer');
|
|
1224
|
-
ReadableByteStreamControllerError(controller, e);
|
|
1225
|
-
throw e;
|
|
1226
|
-
}
|
|
1227
|
-
}
|
|
1228
|
-
ReadableByteStreamControllerClearAlgorithms(controller);
|
|
1229
|
-
ReadableStreamClose(stream);
|
|
1230
|
-
}
|
|
1231
|
-
function ReadableByteStreamControllerEnqueue(controller, chunk) {
|
|
1232
|
-
var stream = controller._controlledReadableByteStream;
|
|
1233
|
-
if (controller._closeRequested || stream._state !== 'readable') {
|
|
1234
|
-
return;
|
|
1235
|
-
}
|
|
1236
|
-
var buffer = chunk.buffer;
|
|
1237
|
-
var byteOffset = chunk.byteOffset;
|
|
1238
|
-
var byteLength = chunk.byteLength;
|
|
1239
|
-
var transferredBuffer = TransferArrayBuffer(buffer);
|
|
1240
|
-
if (ReadableStreamHasDefaultReader(stream)) {
|
|
1241
|
-
if (ReadableStreamGetNumReadRequests(stream) === 0) {
|
|
1242
|
-
ReadableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset, byteLength);
|
|
1243
|
-
}
|
|
1244
|
-
else {
|
|
1245
|
-
var transferredView = new Uint8Array(transferredBuffer, byteOffset, byteLength);
|
|
1246
|
-
ReadableStreamFulfillReadRequest(stream, transferredView, false);
|
|
1247
|
-
}
|
|
1248
|
-
}
|
|
1249
|
-
else if (ReadableStreamHasBYOBReader(stream)) {
|
|
1250
|
-
// TODO: Ideally in this branch detaching should happen only if the buffer is not consumed fully.
|
|
1251
|
-
ReadableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset, byteLength);
|
|
1252
|
-
ReadableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(controller);
|
|
1253
|
-
}
|
|
1254
|
-
else {
|
|
1255
|
-
ReadableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset, byteLength);
|
|
1256
|
-
}
|
|
1257
|
-
ReadableByteStreamControllerCallPullIfNeeded(controller);
|
|
1258
|
-
}
|
|
1259
|
-
function ReadableByteStreamControllerError(controller, e) {
|
|
1260
|
-
var stream = controller._controlledReadableByteStream;
|
|
1261
|
-
if (stream._state !== 'readable') {
|
|
1262
|
-
return;
|
|
1263
|
-
}
|
|
1264
|
-
ReadableByteStreamControllerClearPendingPullIntos(controller);
|
|
1265
|
-
ResetQueue(controller);
|
|
1266
|
-
ReadableByteStreamControllerClearAlgorithms(controller);
|
|
1267
|
-
ReadableStreamError(stream, e);
|
|
1268
|
-
}
|
|
1269
|
-
function ReadableByteStreamControllerGetDesiredSize(controller) {
|
|
1270
|
-
var state = controller._controlledReadableByteStream._state;
|
|
1271
|
-
if (state === 'errored') {
|
|
1272
|
-
return null;
|
|
1273
|
-
}
|
|
1274
|
-
if (state === 'closed') {
|
|
1275
|
-
return 0;
|
|
1276
|
-
}
|
|
1277
|
-
return controller._strategyHWM - controller._queueTotalSize;
|
|
1278
|
-
}
|
|
1279
|
-
function ReadableByteStreamControllerRespond(controller, bytesWritten) {
|
|
1280
|
-
bytesWritten = Number(bytesWritten);
|
|
1281
|
-
if (!IsFiniteNonNegativeNumber(bytesWritten)) {
|
|
1282
|
-
throw new RangeError('bytesWritten must be a finite');
|
|
1283
|
-
}
|
|
1284
|
-
ReadableByteStreamControllerRespondInternal(controller, bytesWritten);
|
|
1285
|
-
}
|
|
1286
|
-
function ReadableByteStreamControllerRespondWithNewView(controller, view) {
|
|
1287
|
-
var firstDescriptor = controller._pendingPullIntos.peek();
|
|
1288
|
-
if (firstDescriptor.byteOffset + firstDescriptor.bytesFilled !== view.byteOffset) {
|
|
1289
|
-
throw new RangeError('The region specified by view does not match byobRequest');
|
|
1290
|
-
}
|
|
1291
|
-
if (firstDescriptor.byteLength !== view.byteLength) {
|
|
1292
|
-
throw new RangeError('The buffer of view has different capacity than byobRequest');
|
|
1293
|
-
}
|
|
1294
|
-
firstDescriptor.buffer = view.buffer;
|
|
1295
|
-
ReadableByteStreamControllerRespondInternal(controller, view.byteLength);
|
|
1296
|
-
}
|
|
1297
|
-
function SetUpReadableByteStreamController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, autoAllocateChunkSize) {
|
|
1298
|
-
controller._controlledReadableByteStream = stream;
|
|
1299
|
-
controller._pullAgain = false;
|
|
1300
|
-
controller._pulling = false;
|
|
1301
|
-
controller._byobRequest = null;
|
|
1302
|
-
// Need to set the slots so that the assert doesn't fire. In the spec the slots already exist implicitly.
|
|
1303
|
-
controller._queue = controller._queueTotalSize = undefined;
|
|
1304
|
-
ResetQueue(controller);
|
|
1305
|
-
controller._closeRequested = false;
|
|
1306
|
-
controller._started = false;
|
|
1307
|
-
controller._strategyHWM = highWaterMark;
|
|
1308
|
-
controller._pullAlgorithm = pullAlgorithm;
|
|
1309
|
-
controller._cancelAlgorithm = cancelAlgorithm;
|
|
1310
|
-
controller._autoAllocateChunkSize = autoAllocateChunkSize;
|
|
1311
|
-
controller._pendingPullIntos = new SimpleQueue();
|
|
1312
|
-
stream._readableStreamController = controller;
|
|
1313
|
-
var startResult = startAlgorithm();
|
|
1314
|
-
uponPromise(promiseResolvedWith(startResult), function () {
|
|
1315
|
-
controller._started = true;
|
|
1316
|
-
ReadableByteStreamControllerCallPullIfNeeded(controller);
|
|
1317
|
-
}, function (r) {
|
|
1318
|
-
ReadableByteStreamControllerError(controller, r);
|
|
1319
|
-
});
|
|
1320
|
-
}
|
|
1321
|
-
function SetUpReadableByteStreamControllerFromUnderlyingSource(stream, underlyingByteSource, highWaterMark) {
|
|
1322
|
-
var controller = Object.create(ReadableByteStreamController.prototype);
|
|
1323
|
-
var startAlgorithm = function () { return undefined; };
|
|
1324
|
-
var pullAlgorithm = function () { return promiseResolvedWith(undefined); };
|
|
1325
|
-
var cancelAlgorithm = function () { return promiseResolvedWith(undefined); };
|
|
1326
|
-
if (underlyingByteSource.start !== undefined) {
|
|
1327
|
-
startAlgorithm = function () { return underlyingByteSource.start(controller); };
|
|
1328
|
-
}
|
|
1329
|
-
if (underlyingByteSource.pull !== undefined) {
|
|
1330
|
-
pullAlgorithm = function () { return underlyingByteSource.pull(controller); };
|
|
1331
|
-
}
|
|
1332
|
-
if (underlyingByteSource.cancel !== undefined) {
|
|
1333
|
-
cancelAlgorithm = function (reason) { return underlyingByteSource.cancel(reason); };
|
|
1334
|
-
}
|
|
1335
|
-
var autoAllocateChunkSize = underlyingByteSource.autoAllocateChunkSize;
|
|
1336
|
-
if (autoAllocateChunkSize === 0) {
|
|
1337
|
-
throw new TypeError('autoAllocateChunkSize must be greater than 0');
|
|
1338
|
-
}
|
|
1339
|
-
SetUpReadableByteStreamController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, autoAllocateChunkSize);
|
|
1340
|
-
}
|
|
1341
|
-
function SetUpReadableStreamBYOBRequest(request, controller, view) {
|
|
1342
|
-
request._associatedReadableByteStreamController = controller;
|
|
1343
|
-
request._view = view;
|
|
1344
|
-
}
|
|
1345
|
-
// Helper functions for the ReadableStreamBYOBRequest.
|
|
1346
|
-
function byobRequestBrandCheckException(name) {
|
|
1347
|
-
return new TypeError("ReadableStreamBYOBRequest.prototype." + name + " can only be used on a ReadableStreamBYOBRequest");
|
|
1348
|
-
}
|
|
1349
|
-
// Helper functions for the ReadableByteStreamController.
|
|
1350
|
-
function byteStreamControllerBrandCheckException(name) {
|
|
1351
|
-
return new TypeError("ReadableByteStreamController.prototype." + name + " can only be used on a ReadableByteStreamController");
|
|
1352
|
-
}
|
|
1353
|
-
|
|
1354
|
-
// Abstract operations for the ReadableStream.
|
|
1355
|
-
function AcquireReadableStreamBYOBReader(stream) {
|
|
1356
|
-
return new ReadableStreamBYOBReader(stream);
|
|
1357
|
-
}
|
|
1358
|
-
// ReadableStream API exposed for controllers.
|
|
1359
|
-
function ReadableStreamAddReadIntoRequest(stream, readIntoRequest) {
|
|
1360
|
-
stream._reader._readIntoRequests.push(readIntoRequest);
|
|
1361
|
-
}
|
|
1362
|
-
function ReadableStreamFulfillReadIntoRequest(stream, chunk, done) {
|
|
1363
|
-
var reader = stream._reader;
|
|
1364
|
-
var readIntoRequest = reader._readIntoRequests.shift();
|
|
1365
|
-
if (done) {
|
|
1366
|
-
readIntoRequest._closeSteps(chunk);
|
|
1367
|
-
}
|
|
1368
|
-
else {
|
|
1369
|
-
readIntoRequest._chunkSteps(chunk);
|
|
1370
|
-
}
|
|
1371
|
-
}
|
|
1372
|
-
function ReadableStreamGetNumReadIntoRequests(stream) {
|
|
1373
|
-
return stream._reader._readIntoRequests.length;
|
|
1374
|
-
}
|
|
1375
|
-
function ReadableStreamHasBYOBReader(stream) {
|
|
1376
|
-
var reader = stream._reader;
|
|
1377
|
-
if (reader === undefined) {
|
|
1378
|
-
return false;
|
|
1379
|
-
}
|
|
1380
|
-
if (!IsReadableStreamBYOBReader(reader)) {
|
|
1381
|
-
return false;
|
|
1382
|
-
}
|
|
1383
|
-
return true;
|
|
1384
|
-
}
|
|
1385
|
-
/**
|
|
1386
|
-
* A BYOB reader vended by a {@link ReadableStream}.
|
|
1387
|
-
*
|
|
1388
|
-
* @public
|
|
1389
|
-
*/
|
|
1390
|
-
var ReadableStreamBYOBReader = /** @class */ (function () {
|
|
1391
|
-
function ReadableStreamBYOBReader(stream) {
|
|
1392
|
-
assertRequiredArgument(stream, 1, 'ReadableStreamBYOBReader');
|
|
1393
|
-
assertReadableStream(stream, 'First parameter');
|
|
1394
|
-
if (IsReadableStreamLocked(stream)) {
|
|
1395
|
-
throw new TypeError('This stream has already been locked for exclusive reading by another reader');
|
|
1396
|
-
}
|
|
1397
|
-
if (!IsReadableByteStreamController(stream._readableStreamController)) {
|
|
1398
|
-
throw new TypeError('Cannot construct a ReadableStreamBYOBReader for a stream not constructed with a byte ' +
|
|
1399
|
-
'source');
|
|
1400
|
-
}
|
|
1401
|
-
ReadableStreamReaderGenericInitialize(this, stream);
|
|
1402
|
-
this._readIntoRequests = new SimpleQueue();
|
|
1403
|
-
}
|
|
1404
|
-
Object.defineProperty(ReadableStreamBYOBReader.prototype, "closed", {
|
|
1405
|
-
/**
|
|
1406
|
-
* Returns a promise that will be fulfilled when the stream becomes closed, or rejected if the stream ever errors or
|
|
1407
|
-
* the reader's lock is released before the stream finishes closing.
|
|
1408
|
-
*/
|
|
1409
|
-
get: function () {
|
|
1410
|
-
if (!IsReadableStreamBYOBReader(this)) {
|
|
1411
|
-
return promiseRejectedWith(byobReaderBrandCheckException('closed'));
|
|
1412
|
-
}
|
|
1413
|
-
return this._closedPromise;
|
|
1414
|
-
},
|
|
1415
|
-
enumerable: false,
|
|
1416
|
-
configurable: true
|
|
1417
|
-
});
|
|
1418
|
-
/**
|
|
1419
|
-
* If the reader is active, behaves the same as {@link ReadableStream.cancel | stream.cancel(reason)}.
|
|
1420
|
-
*/
|
|
1421
|
-
ReadableStreamBYOBReader.prototype.cancel = function (reason) {
|
|
1422
|
-
if (reason === void 0) { reason = undefined; }
|
|
1423
|
-
if (!IsReadableStreamBYOBReader(this)) {
|
|
1424
|
-
return promiseRejectedWith(byobReaderBrandCheckException('cancel'));
|
|
1425
|
-
}
|
|
1426
|
-
if (this._ownerReadableStream === undefined) {
|
|
1427
|
-
return promiseRejectedWith(readerLockException('cancel'));
|
|
1428
|
-
}
|
|
1429
|
-
return ReadableStreamReaderGenericCancel(this, reason);
|
|
1430
|
-
};
|
|
1431
|
-
/**
|
|
1432
|
-
* Attempts to reads bytes into view, and returns a promise resolved with the result.
|
|
1433
|
-
*
|
|
1434
|
-
* If reading a chunk causes the queue to become empty, more data will be pulled from the underlying source.
|
|
1435
|
-
*/
|
|
1436
|
-
ReadableStreamBYOBReader.prototype.read = function (view) {
|
|
1437
|
-
if (!IsReadableStreamBYOBReader(this)) {
|
|
1438
|
-
return promiseRejectedWith(byobReaderBrandCheckException('read'));
|
|
1439
|
-
}
|
|
1440
|
-
if (!ArrayBuffer.isView(view)) {
|
|
1441
|
-
return promiseRejectedWith(new TypeError('view must be an array buffer view'));
|
|
1442
|
-
}
|
|
1443
|
-
if (view.byteLength === 0) {
|
|
1444
|
-
return promiseRejectedWith(new TypeError('view must have non-zero byteLength'));
|
|
1445
|
-
}
|
|
1446
|
-
if (view.buffer.byteLength === 0) {
|
|
1447
|
-
return promiseRejectedWith(new TypeError("view's buffer must have non-zero byteLength"));
|
|
1448
|
-
}
|
|
1449
|
-
if (this._ownerReadableStream === undefined) {
|
|
1450
|
-
return promiseRejectedWith(readerLockException('read from'));
|
|
1451
|
-
}
|
|
1452
|
-
var resolvePromise;
|
|
1453
|
-
var rejectPromise;
|
|
1454
|
-
var promise = newPromise(function (resolve, reject) {
|
|
1455
|
-
resolvePromise = resolve;
|
|
1456
|
-
rejectPromise = reject;
|
|
1457
|
-
});
|
|
1458
|
-
var readIntoRequest = {
|
|
1459
|
-
_chunkSteps: function (chunk) { return resolvePromise({ value: chunk, done: false }); },
|
|
1460
|
-
_closeSteps: function (chunk) { return resolvePromise({ value: chunk, done: true }); },
|
|
1461
|
-
_errorSteps: function (e) { return rejectPromise(e); }
|
|
1462
|
-
};
|
|
1463
|
-
ReadableStreamBYOBReaderRead(this, view, readIntoRequest);
|
|
1464
|
-
return promise;
|
|
1465
|
-
};
|
|
1466
|
-
/**
|
|
1467
|
-
* Releases the reader's lock on the corresponding stream. After the lock is released, the reader is no longer active.
|
|
1468
|
-
* If the associated stream is errored when the lock is released, the reader will appear errored in the same way
|
|
1469
|
-
* from now on; otherwise, the reader will appear closed.
|
|
1470
|
-
*
|
|
1471
|
-
* A reader's lock cannot be released while it still has a pending read request, i.e., if a promise returned by
|
|
1472
|
-
* the reader's {@link ReadableStreamBYOBReader.read | read()} method has not yet been settled. Attempting to
|
|
1473
|
-
* do so will throw a `TypeError` and leave the reader locked to the stream.
|
|
1474
|
-
*/
|
|
1475
|
-
ReadableStreamBYOBReader.prototype.releaseLock = function () {
|
|
1476
|
-
if (!IsReadableStreamBYOBReader(this)) {
|
|
1477
|
-
throw byobReaderBrandCheckException('releaseLock');
|
|
1478
|
-
}
|
|
1479
|
-
if (this._ownerReadableStream === undefined) {
|
|
1480
|
-
return;
|
|
1481
|
-
}
|
|
1482
|
-
if (this._readIntoRequests.length > 0) {
|
|
1483
|
-
throw new TypeError('Tried to release a reader lock when that reader has pending read() calls un-settled');
|
|
1484
|
-
}
|
|
1485
|
-
ReadableStreamReaderGenericRelease(this);
|
|
1486
|
-
};
|
|
1487
|
-
return ReadableStreamBYOBReader;
|
|
1488
|
-
}());
|
|
1489
|
-
Object.defineProperties(ReadableStreamBYOBReader.prototype, {
|
|
1490
|
-
cancel: { enumerable: true },
|
|
1491
|
-
read: { enumerable: true },
|
|
1492
|
-
releaseLock: { enumerable: true },
|
|
1493
|
-
closed: { enumerable: true }
|
|
1494
|
-
});
|
|
1495
|
-
if (typeof SymbolPolyfill.toStringTag === 'symbol') {
|
|
1496
|
-
Object.defineProperty(ReadableStreamBYOBReader.prototype, SymbolPolyfill.toStringTag, {
|
|
1497
|
-
value: 'ReadableStreamBYOBReader',
|
|
1498
|
-
configurable: true
|
|
1499
|
-
});
|
|
1500
|
-
}
|
|
1501
|
-
// Abstract operations for the readers.
|
|
1502
|
-
function IsReadableStreamBYOBReader(x) {
|
|
1503
|
-
if (!typeIsObject(x)) {
|
|
1504
|
-
return false;
|
|
1505
|
-
}
|
|
1506
|
-
if (!Object.prototype.hasOwnProperty.call(x, '_readIntoRequests')) {
|
|
1507
|
-
return false;
|
|
1508
|
-
}
|
|
1509
|
-
return true;
|
|
1510
|
-
}
|
|
1511
|
-
function ReadableStreamBYOBReaderRead(reader, view, readIntoRequest) {
|
|
1512
|
-
var stream = reader._ownerReadableStream;
|
|
1513
|
-
stream._disturbed = true;
|
|
1514
|
-
if (stream._state === 'errored') {
|
|
1515
|
-
readIntoRequest._errorSteps(stream._storedError);
|
|
1516
|
-
}
|
|
1517
|
-
else {
|
|
1518
|
-
ReadableByteStreamControllerPullInto(stream._readableStreamController, view, readIntoRequest);
|
|
1519
|
-
}
|
|
1520
|
-
}
|
|
1521
|
-
// Helper functions for the ReadableStreamBYOBReader.
|
|
1522
|
-
function byobReaderBrandCheckException(name) {
|
|
1523
|
-
return new TypeError("ReadableStreamBYOBReader.prototype." + name + " can only be used on a ReadableStreamBYOBReader");
|
|
1524
|
-
}
|
|
1525
|
-
|
|
1526
|
-
function ExtractHighWaterMark(strategy, defaultHWM) {
|
|
1527
|
-
var highWaterMark = strategy.highWaterMark;
|
|
1528
|
-
if (highWaterMark === undefined) {
|
|
1529
|
-
return defaultHWM;
|
|
1530
|
-
}
|
|
1531
|
-
if (NumberIsNaN(highWaterMark) || highWaterMark < 0) {
|
|
1532
|
-
throw new RangeError('Invalid highWaterMark');
|
|
1533
|
-
}
|
|
1534
|
-
return highWaterMark;
|
|
1535
|
-
}
|
|
1536
|
-
function ExtractSizeAlgorithm(strategy) {
|
|
1537
|
-
var size = strategy.size;
|
|
1538
|
-
if (!size) {
|
|
1539
|
-
return function () { return 1; };
|
|
1540
|
-
}
|
|
1541
|
-
return size;
|
|
1542
|
-
}
|
|
1543
|
-
|
|
1544
|
-
function convertQueuingStrategy(init, context) {
|
|
1545
|
-
assertDictionary(init, context);
|
|
1546
|
-
var highWaterMark = init === null || init === void 0 ? void 0 : init.highWaterMark;
|
|
1547
|
-
var size = init === null || init === void 0 ? void 0 : init.size;
|
|
1548
|
-
return {
|
|
1549
|
-
highWaterMark: highWaterMark === undefined ? undefined : convertUnrestrictedDouble(highWaterMark),
|
|
1550
|
-
size: size === undefined ? undefined : convertQueuingStrategySize(size, context + " has member 'size' that")
|
|
1551
|
-
};
|
|
1552
|
-
}
|
|
1553
|
-
function convertQueuingStrategySize(fn, context) {
|
|
1554
|
-
assertFunction(fn, context);
|
|
1555
|
-
return function (chunk) { return convertUnrestrictedDouble(fn(chunk)); };
|
|
1556
|
-
}
|
|
1557
|
-
|
|
1558
|
-
function convertUnderlyingSink(original, context) {
|
|
1559
|
-
assertDictionary(original, context);
|
|
1560
|
-
var abort = original === null || original === void 0 ? void 0 : original.abort;
|
|
1561
|
-
var close = original === null || original === void 0 ? void 0 : original.close;
|
|
1562
|
-
var start = original === null || original === void 0 ? void 0 : original.start;
|
|
1563
|
-
var type = original === null || original === void 0 ? void 0 : original.type;
|
|
1564
|
-
var write = original === null || original === void 0 ? void 0 : original.write;
|
|
1565
|
-
return {
|
|
1566
|
-
abort: abort === undefined ?
|
|
1567
|
-
undefined :
|
|
1568
|
-
convertUnderlyingSinkAbortCallback(abort, original, context + " has member 'abort' that"),
|
|
1569
|
-
close: close === undefined ?
|
|
1570
|
-
undefined :
|
|
1571
|
-
convertUnderlyingSinkCloseCallback(close, original, context + " has member 'close' that"),
|
|
1572
|
-
start: start === undefined ?
|
|
1573
|
-
undefined :
|
|
1574
|
-
convertUnderlyingSinkStartCallback(start, original, context + " has member 'start' that"),
|
|
1575
|
-
write: write === undefined ?
|
|
1576
|
-
undefined :
|
|
1577
|
-
convertUnderlyingSinkWriteCallback(write, original, context + " has member 'write' that"),
|
|
1578
|
-
type: type
|
|
1579
|
-
};
|
|
1580
|
-
}
|
|
1581
|
-
function convertUnderlyingSinkAbortCallback(fn, original, context) {
|
|
1582
|
-
assertFunction(fn, context);
|
|
1583
|
-
return function (reason) { return promiseCall(fn, original, [reason]); };
|
|
1584
|
-
}
|
|
1585
|
-
function convertUnderlyingSinkCloseCallback(fn, original, context) {
|
|
1586
|
-
assertFunction(fn, context);
|
|
1587
|
-
return function () { return promiseCall(fn, original, []); };
|
|
1588
|
-
}
|
|
1589
|
-
function convertUnderlyingSinkStartCallback(fn, original, context) {
|
|
1590
|
-
assertFunction(fn, context);
|
|
1591
|
-
return function (controller) { return reflectCall(fn, original, [controller]); };
|
|
1592
|
-
}
|
|
1593
|
-
function convertUnderlyingSinkWriteCallback(fn, original, context) {
|
|
1594
|
-
assertFunction(fn, context);
|
|
1595
|
-
return function (chunk, controller) { return promiseCall(fn, original, [chunk, controller]); };
|
|
1596
|
-
}
|
|
1597
|
-
|
|
1598
|
-
function assertWritableStream(x, context) {
|
|
1599
|
-
if (!IsWritableStream(x)) {
|
|
1600
|
-
throw new TypeError(context + " is not a WritableStream.");
|
|
1601
|
-
}
|
|
1602
|
-
}
|
|
1603
|
-
|
|
1604
|
-
/**
|
|
1605
|
-
* A writable stream represents a destination for data, into which you can write.
|
|
1606
|
-
*
|
|
1607
|
-
* @public
|
|
1608
|
-
*/
|
|
1609
|
-
var WritableStream = /** @class */ (function () {
|
|
1610
|
-
function WritableStream(rawUnderlyingSink, rawStrategy) {
|
|
1611
|
-
if (rawUnderlyingSink === void 0) { rawUnderlyingSink = {}; }
|
|
1612
|
-
if (rawStrategy === void 0) { rawStrategy = {}; }
|
|
1613
|
-
if (rawUnderlyingSink === undefined) {
|
|
1614
|
-
rawUnderlyingSink = null;
|
|
1615
|
-
}
|
|
1616
|
-
else {
|
|
1617
|
-
assertObject(rawUnderlyingSink, 'First parameter');
|
|
1618
|
-
}
|
|
1619
|
-
var strategy = convertQueuingStrategy(rawStrategy, 'Second parameter');
|
|
1620
|
-
var underlyingSink = convertUnderlyingSink(rawUnderlyingSink, 'First parameter');
|
|
1621
|
-
InitializeWritableStream(this);
|
|
1622
|
-
var type = underlyingSink.type;
|
|
1623
|
-
if (type !== undefined) {
|
|
1624
|
-
throw new RangeError('Invalid type is specified');
|
|
1625
|
-
}
|
|
1626
|
-
var sizeAlgorithm = ExtractSizeAlgorithm(strategy);
|
|
1627
|
-
var highWaterMark = ExtractHighWaterMark(strategy, 1);
|
|
1628
|
-
SetUpWritableStreamDefaultControllerFromUnderlyingSink(this, underlyingSink, highWaterMark, sizeAlgorithm);
|
|
1629
|
-
}
|
|
1630
|
-
Object.defineProperty(WritableStream.prototype, "locked", {
|
|
1631
|
-
/**
|
|
1632
|
-
* Returns whether or not the writable stream is locked to a writer.
|
|
1633
|
-
*/
|
|
1634
|
-
get: function () {
|
|
1635
|
-
if (!IsWritableStream(this)) {
|
|
1636
|
-
throw streamBrandCheckException$2('locked');
|
|
1637
|
-
}
|
|
1638
|
-
return IsWritableStreamLocked(this);
|
|
1639
|
-
},
|
|
1640
|
-
enumerable: false,
|
|
1641
|
-
configurable: true
|
|
1642
|
-
});
|
|
1643
|
-
/**
|
|
1644
|
-
* Aborts the stream, signaling that the producer can no longer successfully write to the stream and it is to be
|
|
1645
|
-
* immediately moved to an errored state, with any queued-up writes discarded. This will also execute any abort
|
|
1646
|
-
* mechanism of the underlying sink.
|
|
1647
|
-
*
|
|
1648
|
-
* The returned promise will fulfill if the stream shuts down successfully, or reject if the underlying sink signaled
|
|
1649
|
-
* that there was an error doing so. Additionally, it will reject with a `TypeError` (without attempting to cancel
|
|
1650
|
-
* the stream) if the stream is currently locked.
|
|
1651
|
-
*/
|
|
1652
|
-
WritableStream.prototype.abort = function (reason) {
|
|
1653
|
-
if (reason === void 0) { reason = undefined; }
|
|
1654
|
-
if (!IsWritableStream(this)) {
|
|
1655
|
-
return promiseRejectedWith(streamBrandCheckException$2('abort'));
|
|
1656
|
-
}
|
|
1657
|
-
if (IsWritableStreamLocked(this)) {
|
|
1658
|
-
return promiseRejectedWith(new TypeError('Cannot abort a stream that already has a writer'));
|
|
1659
|
-
}
|
|
1660
|
-
return WritableStreamAbort(this, reason);
|
|
1661
|
-
};
|
|
1662
|
-
/**
|
|
1663
|
-
* Closes the stream. The underlying sink will finish processing any previously-written chunks, before invoking its
|
|
1664
|
-
* close behavior. During this time any further attempts to write will fail (without erroring the stream).
|
|
1665
|
-
*
|
|
1666
|
-
* The method returns a promise that will fulfill if all remaining chunks are successfully written and the stream
|
|
1667
|
-
* successfully closes, or rejects if an error is encountered during this process. Additionally, it will reject with
|
|
1668
|
-
* a `TypeError` (without attempting to cancel the stream) if the stream is currently locked.
|
|
1669
|
-
*/
|
|
1670
|
-
WritableStream.prototype.close = function () {
|
|
1671
|
-
if (!IsWritableStream(this)) {
|
|
1672
|
-
return promiseRejectedWith(streamBrandCheckException$2('close'));
|
|
1673
|
-
}
|
|
1674
|
-
if (IsWritableStreamLocked(this)) {
|
|
1675
|
-
return promiseRejectedWith(new TypeError('Cannot close a stream that already has a writer'));
|
|
1676
|
-
}
|
|
1677
|
-
if (WritableStreamCloseQueuedOrInFlight(this)) {
|
|
1678
|
-
return promiseRejectedWith(new TypeError('Cannot close an already-closing stream'));
|
|
1679
|
-
}
|
|
1680
|
-
return WritableStreamClose(this);
|
|
1681
|
-
};
|
|
1682
|
-
/**
|
|
1683
|
-
* Creates a {@link WritableStreamDefaultWriter | writer} and locks the stream to the new writer. While the stream
|
|
1684
|
-
* is locked, no other writer can be acquired until this one is released.
|
|
1685
|
-
*
|
|
1686
|
-
* This functionality is especially useful for creating abstractions that desire the ability to write to a stream
|
|
1687
|
-
* without interruption or interleaving. By getting a writer for the stream, you can ensure nobody else can write at
|
|
1688
|
-
* the same time, which would cause the resulting written data to be unpredictable and probably useless.
|
|
1689
|
-
*/
|
|
1690
|
-
WritableStream.prototype.getWriter = function () {
|
|
1691
|
-
if (!IsWritableStream(this)) {
|
|
1692
|
-
throw streamBrandCheckException$2('getWriter');
|
|
1693
|
-
}
|
|
1694
|
-
return AcquireWritableStreamDefaultWriter(this);
|
|
1695
|
-
};
|
|
1696
|
-
return WritableStream;
|
|
1697
|
-
}());
|
|
1698
|
-
Object.defineProperties(WritableStream.prototype, {
|
|
1699
|
-
abort: { enumerable: true },
|
|
1700
|
-
close: { enumerable: true },
|
|
1701
|
-
getWriter: { enumerable: true },
|
|
1702
|
-
locked: { enumerable: true }
|
|
1703
|
-
});
|
|
1704
|
-
if (typeof SymbolPolyfill.toStringTag === 'symbol') {
|
|
1705
|
-
Object.defineProperty(WritableStream.prototype, SymbolPolyfill.toStringTag, {
|
|
1706
|
-
value: 'WritableStream',
|
|
1707
|
-
configurable: true
|
|
1708
|
-
});
|
|
1709
|
-
}
|
|
1710
|
-
// Abstract operations for the WritableStream.
|
|
1711
|
-
function AcquireWritableStreamDefaultWriter(stream) {
|
|
1712
|
-
return new WritableStreamDefaultWriter(stream);
|
|
1713
|
-
}
|
|
1714
|
-
// Throws if and only if startAlgorithm throws.
|
|
1715
|
-
function CreateWritableStream(startAlgorithm, writeAlgorithm, closeAlgorithm, abortAlgorithm, highWaterMark, sizeAlgorithm) {
|
|
1716
|
-
if (highWaterMark === void 0) { highWaterMark = 1; }
|
|
1717
|
-
if (sizeAlgorithm === void 0) { sizeAlgorithm = function () { return 1; }; }
|
|
1718
|
-
var stream = Object.create(WritableStream.prototype);
|
|
1719
|
-
InitializeWritableStream(stream);
|
|
1720
|
-
var controller = Object.create(WritableStreamDefaultController.prototype);
|
|
1721
|
-
SetUpWritableStreamDefaultController(stream, controller, startAlgorithm, writeAlgorithm, closeAlgorithm, abortAlgorithm, highWaterMark, sizeAlgorithm);
|
|
1722
|
-
return stream;
|
|
1723
|
-
}
|
|
1724
|
-
function InitializeWritableStream(stream) {
|
|
1725
|
-
stream._state = 'writable';
|
|
1726
|
-
// The error that will be reported by new method calls once the state becomes errored. Only set when [[state]] is
|
|
1727
|
-
// 'erroring' or 'errored'. May be set to an undefined value.
|
|
1728
|
-
stream._storedError = undefined;
|
|
1729
|
-
stream._writer = undefined;
|
|
1730
|
-
// Initialize to undefined first because the constructor of the controller checks this
|
|
1731
|
-
// variable to validate the caller.
|
|
1732
|
-
stream._writableStreamController = undefined;
|
|
1733
|
-
// This queue is placed here instead of the writer class in order to allow for passing a writer to the next data
|
|
1734
|
-
// producer without waiting for the queued writes to finish.
|
|
1735
|
-
stream._writeRequests = new SimpleQueue();
|
|
1736
|
-
// Write requests are removed from _writeRequests when write() is called on the underlying sink. This prevents
|
|
1737
|
-
// them from being erroneously rejected on error. If a write() call is in-flight, the request is stored here.
|
|
1738
|
-
stream._inFlightWriteRequest = undefined;
|
|
1739
|
-
// The promise that was returned from writer.close(). Stored here because it may be fulfilled after the writer
|
|
1740
|
-
// has been detached.
|
|
1741
|
-
stream._closeRequest = undefined;
|
|
1742
|
-
// Close request is removed from _closeRequest when close() is called on the underlying sink. This prevents it
|
|
1743
|
-
// from being erroneously rejected on error. If a close() call is in-flight, the request is stored here.
|
|
1744
|
-
stream._inFlightCloseRequest = undefined;
|
|
1745
|
-
// The promise that was returned from writer.abort(). This may also be fulfilled after the writer has detached.
|
|
1746
|
-
stream._pendingAbortRequest = undefined;
|
|
1747
|
-
// The backpressure signal set by the controller.
|
|
1748
|
-
stream._backpressure = false;
|
|
1749
|
-
}
|
|
1750
|
-
function IsWritableStream(x) {
|
|
1751
|
-
if (!typeIsObject(x)) {
|
|
1752
|
-
return false;
|
|
1753
|
-
}
|
|
1754
|
-
if (!Object.prototype.hasOwnProperty.call(x, '_writableStreamController')) {
|
|
1755
|
-
return false;
|
|
1756
|
-
}
|
|
1757
|
-
return true;
|
|
1758
|
-
}
|
|
1759
|
-
function IsWritableStreamLocked(stream) {
|
|
1760
|
-
if (stream._writer === undefined) {
|
|
1761
|
-
return false;
|
|
1762
|
-
}
|
|
1763
|
-
return true;
|
|
1764
|
-
}
|
|
1765
|
-
function WritableStreamAbort(stream, reason) {
|
|
1766
|
-
var state = stream._state;
|
|
1767
|
-
if (state === 'closed' || state === 'errored') {
|
|
1768
|
-
return promiseResolvedWith(undefined);
|
|
1769
|
-
}
|
|
1770
|
-
if (stream._pendingAbortRequest !== undefined) {
|
|
1771
|
-
return stream._pendingAbortRequest._promise;
|
|
1772
|
-
}
|
|
1773
|
-
var wasAlreadyErroring = false;
|
|
1774
|
-
if (state === 'erroring') {
|
|
1775
|
-
wasAlreadyErroring = true;
|
|
1776
|
-
// reason will not be used, so don't keep a reference to it.
|
|
1777
|
-
reason = undefined;
|
|
1778
|
-
}
|
|
1779
|
-
var promise = newPromise(function (resolve, reject) {
|
|
1780
|
-
stream._pendingAbortRequest = {
|
|
1781
|
-
_promise: undefined,
|
|
1782
|
-
_resolve: resolve,
|
|
1783
|
-
_reject: reject,
|
|
1784
|
-
_reason: reason,
|
|
1785
|
-
_wasAlreadyErroring: wasAlreadyErroring
|
|
1786
|
-
};
|
|
1787
|
-
});
|
|
1788
|
-
stream._pendingAbortRequest._promise = promise;
|
|
1789
|
-
if (!wasAlreadyErroring) {
|
|
1790
|
-
WritableStreamStartErroring(stream, reason);
|
|
1791
|
-
}
|
|
1792
|
-
return promise;
|
|
1793
|
-
}
|
|
1794
|
-
function WritableStreamClose(stream) {
|
|
1795
|
-
var state = stream._state;
|
|
1796
|
-
if (state === 'closed' || state === 'errored') {
|
|
1797
|
-
return promiseRejectedWith(new TypeError("The stream (in " + state + " state) is not in the writable state and cannot be closed"));
|
|
1798
|
-
}
|
|
1799
|
-
var promise = newPromise(function (resolve, reject) {
|
|
1800
|
-
var closeRequest = {
|
|
1801
|
-
_resolve: resolve,
|
|
1802
|
-
_reject: reject
|
|
1803
|
-
};
|
|
1804
|
-
stream._closeRequest = closeRequest;
|
|
1805
|
-
});
|
|
1806
|
-
var writer = stream._writer;
|
|
1807
|
-
if (writer !== undefined && stream._backpressure && state === 'writable') {
|
|
1808
|
-
defaultWriterReadyPromiseResolve(writer);
|
|
1809
|
-
}
|
|
1810
|
-
WritableStreamDefaultControllerClose(stream._writableStreamController);
|
|
1811
|
-
return promise;
|
|
1812
|
-
}
|
|
1813
|
-
// WritableStream API exposed for controllers.
|
|
1814
|
-
function WritableStreamAddWriteRequest(stream) {
|
|
1815
|
-
var promise = newPromise(function (resolve, reject) {
|
|
1816
|
-
var writeRequest = {
|
|
1817
|
-
_resolve: resolve,
|
|
1818
|
-
_reject: reject
|
|
1819
|
-
};
|
|
1820
|
-
stream._writeRequests.push(writeRequest);
|
|
1821
|
-
});
|
|
1822
|
-
return promise;
|
|
1823
|
-
}
|
|
1824
|
-
function WritableStreamDealWithRejection(stream, error) {
|
|
1825
|
-
var state = stream._state;
|
|
1826
|
-
if (state === 'writable') {
|
|
1827
|
-
WritableStreamStartErroring(stream, error);
|
|
1828
|
-
return;
|
|
1829
|
-
}
|
|
1830
|
-
WritableStreamFinishErroring(stream);
|
|
1831
|
-
}
|
|
1832
|
-
function WritableStreamStartErroring(stream, reason) {
|
|
1833
|
-
var controller = stream._writableStreamController;
|
|
1834
|
-
stream._state = 'erroring';
|
|
1835
|
-
stream._storedError = reason;
|
|
1836
|
-
var writer = stream._writer;
|
|
1837
|
-
if (writer !== undefined) {
|
|
1838
|
-
WritableStreamDefaultWriterEnsureReadyPromiseRejected(writer, reason);
|
|
1839
|
-
}
|
|
1840
|
-
if (!WritableStreamHasOperationMarkedInFlight(stream) && controller._started) {
|
|
1841
|
-
WritableStreamFinishErroring(stream);
|
|
1842
|
-
}
|
|
1843
|
-
}
|
|
1844
|
-
function WritableStreamFinishErroring(stream) {
|
|
1845
|
-
stream._state = 'errored';
|
|
1846
|
-
stream._writableStreamController[ErrorSteps]();
|
|
1847
|
-
var storedError = stream._storedError;
|
|
1848
|
-
stream._writeRequests.forEach(function (writeRequest) {
|
|
1849
|
-
writeRequest._reject(storedError);
|
|
1850
|
-
});
|
|
1851
|
-
stream._writeRequests = new SimpleQueue();
|
|
1852
|
-
if (stream._pendingAbortRequest === undefined) {
|
|
1853
|
-
WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream);
|
|
1854
|
-
return;
|
|
1855
|
-
}
|
|
1856
|
-
var abortRequest = stream._pendingAbortRequest;
|
|
1857
|
-
stream._pendingAbortRequest = undefined;
|
|
1858
|
-
if (abortRequest._wasAlreadyErroring) {
|
|
1859
|
-
abortRequest._reject(storedError);
|
|
1860
|
-
WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream);
|
|
1861
|
-
return;
|
|
1862
|
-
}
|
|
1863
|
-
var promise = stream._writableStreamController[AbortSteps](abortRequest._reason);
|
|
1864
|
-
uponPromise(promise, function () {
|
|
1865
|
-
abortRequest._resolve();
|
|
1866
|
-
WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream);
|
|
1867
|
-
}, function (reason) {
|
|
1868
|
-
abortRequest._reject(reason);
|
|
1869
|
-
WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream);
|
|
1870
|
-
});
|
|
1871
|
-
}
|
|
1872
|
-
function WritableStreamFinishInFlightWrite(stream) {
|
|
1873
|
-
stream._inFlightWriteRequest._resolve(undefined);
|
|
1874
|
-
stream._inFlightWriteRequest = undefined;
|
|
1875
|
-
}
|
|
1876
|
-
function WritableStreamFinishInFlightWriteWithError(stream, error) {
|
|
1877
|
-
stream._inFlightWriteRequest._reject(error);
|
|
1878
|
-
stream._inFlightWriteRequest = undefined;
|
|
1879
|
-
WritableStreamDealWithRejection(stream, error);
|
|
1880
|
-
}
|
|
1881
|
-
function WritableStreamFinishInFlightClose(stream) {
|
|
1882
|
-
stream._inFlightCloseRequest._resolve(undefined);
|
|
1883
|
-
stream._inFlightCloseRequest = undefined;
|
|
1884
|
-
var state = stream._state;
|
|
1885
|
-
if (state === 'erroring') {
|
|
1886
|
-
// The error was too late to do anything, so it is ignored.
|
|
1887
|
-
stream._storedError = undefined;
|
|
1888
|
-
if (stream._pendingAbortRequest !== undefined) {
|
|
1889
|
-
stream._pendingAbortRequest._resolve();
|
|
1890
|
-
stream._pendingAbortRequest = undefined;
|
|
1891
|
-
}
|
|
1892
|
-
}
|
|
1893
|
-
stream._state = 'closed';
|
|
1894
|
-
var writer = stream._writer;
|
|
1895
|
-
if (writer !== undefined) {
|
|
1896
|
-
defaultWriterClosedPromiseResolve(writer);
|
|
1897
|
-
}
|
|
1898
|
-
}
|
|
1899
|
-
function WritableStreamFinishInFlightCloseWithError(stream, error) {
|
|
1900
|
-
stream._inFlightCloseRequest._reject(error);
|
|
1901
|
-
stream._inFlightCloseRequest = undefined;
|
|
1902
|
-
// Never execute sink abort() after sink close().
|
|
1903
|
-
if (stream._pendingAbortRequest !== undefined) {
|
|
1904
|
-
stream._pendingAbortRequest._reject(error);
|
|
1905
|
-
stream._pendingAbortRequest = undefined;
|
|
1906
|
-
}
|
|
1907
|
-
WritableStreamDealWithRejection(stream, error);
|
|
1908
|
-
}
|
|
1909
|
-
// TODO(ricea): Fix alphabetical order.
|
|
1910
|
-
function WritableStreamCloseQueuedOrInFlight(stream) {
|
|
1911
|
-
if (stream._closeRequest === undefined && stream._inFlightCloseRequest === undefined) {
|
|
1912
|
-
return false;
|
|
1913
|
-
}
|
|
1914
|
-
return true;
|
|
1915
|
-
}
|
|
1916
|
-
function WritableStreamHasOperationMarkedInFlight(stream) {
|
|
1917
|
-
if (stream._inFlightWriteRequest === undefined && stream._inFlightCloseRequest === undefined) {
|
|
1918
|
-
return false;
|
|
1919
|
-
}
|
|
1920
|
-
return true;
|
|
1921
|
-
}
|
|
1922
|
-
function WritableStreamMarkCloseRequestInFlight(stream) {
|
|
1923
|
-
stream._inFlightCloseRequest = stream._closeRequest;
|
|
1924
|
-
stream._closeRequest = undefined;
|
|
1925
|
-
}
|
|
1926
|
-
function WritableStreamMarkFirstWriteRequestInFlight(stream) {
|
|
1927
|
-
stream._inFlightWriteRequest = stream._writeRequests.shift();
|
|
1928
|
-
}
|
|
1929
|
-
function WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream) {
|
|
1930
|
-
if (stream._closeRequest !== undefined) {
|
|
1931
|
-
stream._closeRequest._reject(stream._storedError);
|
|
1932
|
-
stream._closeRequest = undefined;
|
|
1933
|
-
}
|
|
1934
|
-
var writer = stream._writer;
|
|
1935
|
-
if (writer !== undefined) {
|
|
1936
|
-
defaultWriterClosedPromiseReject(writer, stream._storedError);
|
|
1937
|
-
}
|
|
1938
|
-
}
|
|
1939
|
-
function WritableStreamUpdateBackpressure(stream, backpressure) {
|
|
1940
|
-
var writer = stream._writer;
|
|
1941
|
-
if (writer !== undefined && backpressure !== stream._backpressure) {
|
|
1942
|
-
if (backpressure) {
|
|
1943
|
-
defaultWriterReadyPromiseReset(writer);
|
|
1944
|
-
}
|
|
1945
|
-
else {
|
|
1946
|
-
defaultWriterReadyPromiseResolve(writer);
|
|
1947
|
-
}
|
|
1948
|
-
}
|
|
1949
|
-
stream._backpressure = backpressure;
|
|
1950
|
-
}
|
|
1951
|
-
/**
|
|
1952
|
-
* A default writer vended by a {@link WritableStream}.
|
|
1953
|
-
*
|
|
1954
|
-
* @public
|
|
1955
|
-
*/
|
|
1956
|
-
var WritableStreamDefaultWriter = /** @class */ (function () {
|
|
1957
|
-
function WritableStreamDefaultWriter(stream) {
|
|
1958
|
-
assertRequiredArgument(stream, 1, 'WritableStreamDefaultWriter');
|
|
1959
|
-
assertWritableStream(stream, 'First parameter');
|
|
1960
|
-
if (IsWritableStreamLocked(stream)) {
|
|
1961
|
-
throw new TypeError('This stream has already been locked for exclusive writing by another writer');
|
|
1962
|
-
}
|
|
1963
|
-
this._ownerWritableStream = stream;
|
|
1964
|
-
stream._writer = this;
|
|
1965
|
-
var state = stream._state;
|
|
1966
|
-
if (state === 'writable') {
|
|
1967
|
-
if (!WritableStreamCloseQueuedOrInFlight(stream) && stream._backpressure) {
|
|
1968
|
-
defaultWriterReadyPromiseInitialize(this);
|
|
1969
|
-
}
|
|
1970
|
-
else {
|
|
1971
|
-
defaultWriterReadyPromiseInitializeAsResolved(this);
|
|
1972
|
-
}
|
|
1973
|
-
defaultWriterClosedPromiseInitialize(this);
|
|
1974
|
-
}
|
|
1975
|
-
else if (state === 'erroring') {
|
|
1976
|
-
defaultWriterReadyPromiseInitializeAsRejected(this, stream._storedError);
|
|
1977
|
-
defaultWriterClosedPromiseInitialize(this);
|
|
1978
|
-
}
|
|
1979
|
-
else if (state === 'closed') {
|
|
1980
|
-
defaultWriterReadyPromiseInitializeAsResolved(this);
|
|
1981
|
-
defaultWriterClosedPromiseInitializeAsResolved(this);
|
|
1982
|
-
}
|
|
1983
|
-
else {
|
|
1984
|
-
var storedError = stream._storedError;
|
|
1985
|
-
defaultWriterReadyPromiseInitializeAsRejected(this, storedError);
|
|
1986
|
-
defaultWriterClosedPromiseInitializeAsRejected(this, storedError);
|
|
1987
|
-
}
|
|
1988
|
-
}
|
|
1989
|
-
Object.defineProperty(WritableStreamDefaultWriter.prototype, "closed", {
|
|
1990
|
-
/**
|
|
1991
|
-
* Returns a promise that will be fulfilled when the stream becomes closed, or rejected if the stream ever errors or
|
|
1992
|
-
* the writer’s lock is released before the stream finishes closing.
|
|
1993
|
-
*/
|
|
1994
|
-
get: function () {
|
|
1995
|
-
if (!IsWritableStreamDefaultWriter(this)) {
|
|
1996
|
-
return promiseRejectedWith(defaultWriterBrandCheckException('closed'));
|
|
1997
|
-
}
|
|
1998
|
-
return this._closedPromise;
|
|
1999
|
-
},
|
|
2000
|
-
enumerable: false,
|
|
2001
|
-
configurable: true
|
|
2002
|
-
});
|
|
2003
|
-
Object.defineProperty(WritableStreamDefaultWriter.prototype, "desiredSize", {
|
|
2004
|
-
/**
|
|
2005
|
-
* Returns the desired size to fill the stream’s internal queue. It can be negative, if the queue is over-full.
|
|
2006
|
-
* A producer can use this information to determine the right amount of data to write.
|
|
2007
|
-
*
|
|
2008
|
-
* It will be `null` if the stream cannot be successfully written to (due to either being errored, or having an abort
|
|
2009
|
-
* queued up). It will return zero if the stream is closed. And the getter will throw an exception if invoked when
|
|
2010
|
-
* the writer’s lock is released.
|
|
2011
|
-
*/
|
|
2012
|
-
get: function () {
|
|
2013
|
-
if (!IsWritableStreamDefaultWriter(this)) {
|
|
2014
|
-
throw defaultWriterBrandCheckException('desiredSize');
|
|
2015
|
-
}
|
|
2016
|
-
if (this._ownerWritableStream === undefined) {
|
|
2017
|
-
throw defaultWriterLockException('desiredSize');
|
|
2018
|
-
}
|
|
2019
|
-
return WritableStreamDefaultWriterGetDesiredSize(this);
|
|
2020
|
-
},
|
|
2021
|
-
enumerable: false,
|
|
2022
|
-
configurable: true
|
|
2023
|
-
});
|
|
2024
|
-
Object.defineProperty(WritableStreamDefaultWriter.prototype, "ready", {
|
|
2025
|
-
/**
|
|
2026
|
-
* Returns a promise that will be fulfilled when the desired size to fill the stream’s internal queue transitions
|
|
2027
|
-
* from non-positive to positive, signaling that it is no longer applying backpressure. Once the desired size dips
|
|
2028
|
-
* back to zero or below, the getter will return a new promise that stays pending until the next transition.
|
|
2029
|
-
*
|
|
2030
|
-
* If the stream becomes errored or aborted, or the writer’s lock is released, the returned promise will become
|
|
2031
|
-
* rejected.
|
|
2032
|
-
*/
|
|
2033
|
-
get: function () {
|
|
2034
|
-
if (!IsWritableStreamDefaultWriter(this)) {
|
|
2035
|
-
return promiseRejectedWith(defaultWriterBrandCheckException('ready'));
|
|
2036
|
-
}
|
|
2037
|
-
return this._readyPromise;
|
|
2038
|
-
},
|
|
2039
|
-
enumerable: false,
|
|
2040
|
-
configurable: true
|
|
2041
|
-
});
|
|
2042
|
-
/**
|
|
2043
|
-
* If the reader is active, behaves the same as {@link WritableStream.abort | stream.abort(reason)}.
|
|
2044
|
-
*/
|
|
2045
|
-
WritableStreamDefaultWriter.prototype.abort = function (reason) {
|
|
2046
|
-
if (reason === void 0) { reason = undefined; }
|
|
2047
|
-
if (!IsWritableStreamDefaultWriter(this)) {
|
|
2048
|
-
return promiseRejectedWith(defaultWriterBrandCheckException('abort'));
|
|
2049
|
-
}
|
|
2050
|
-
if (this._ownerWritableStream === undefined) {
|
|
2051
|
-
return promiseRejectedWith(defaultWriterLockException('abort'));
|
|
2052
|
-
}
|
|
2053
|
-
return WritableStreamDefaultWriterAbort(this, reason);
|
|
2054
|
-
};
|
|
2055
|
-
/**
|
|
2056
|
-
* If the reader is active, behaves the same as {@link WritableStream.close | stream.close()}.
|
|
2057
|
-
*/
|
|
2058
|
-
WritableStreamDefaultWriter.prototype.close = function () {
|
|
2059
|
-
if (!IsWritableStreamDefaultWriter(this)) {
|
|
2060
|
-
return promiseRejectedWith(defaultWriterBrandCheckException('close'));
|
|
2061
|
-
}
|
|
2062
|
-
var stream = this._ownerWritableStream;
|
|
2063
|
-
if (stream === undefined) {
|
|
2064
|
-
return promiseRejectedWith(defaultWriterLockException('close'));
|
|
2065
|
-
}
|
|
2066
|
-
if (WritableStreamCloseQueuedOrInFlight(stream)) {
|
|
2067
|
-
return promiseRejectedWith(new TypeError('Cannot close an already-closing stream'));
|
|
2068
|
-
}
|
|
2069
|
-
return WritableStreamDefaultWriterClose(this);
|
|
2070
|
-
};
|
|
2071
|
-
/**
|
|
2072
|
-
* Releases the writer’s lock on the corresponding stream. After the lock is released, the writer is no longer active.
|
|
2073
|
-
* If the associated stream is errored when the lock is released, the writer will appear errored in the same way from
|
|
2074
|
-
* now on; otherwise, the writer will appear closed.
|
|
2075
|
-
*
|
|
2076
|
-
* Note that the lock can still be released even if some ongoing writes have not yet finished (i.e. even if the
|
|
2077
|
-
* promises returned from previous calls to {@link WritableStreamDefaultWriter.write | write()} have not yet settled).
|
|
2078
|
-
* It’s not necessary to hold the lock on the writer for the duration of the write; the lock instead simply prevents
|
|
2079
|
-
* other producers from writing in an interleaved manner.
|
|
2080
|
-
*/
|
|
2081
|
-
WritableStreamDefaultWriter.prototype.releaseLock = function () {
|
|
2082
|
-
if (!IsWritableStreamDefaultWriter(this)) {
|
|
2083
|
-
throw defaultWriterBrandCheckException('releaseLock');
|
|
2084
|
-
}
|
|
2085
|
-
var stream = this._ownerWritableStream;
|
|
2086
|
-
if (stream === undefined) {
|
|
2087
|
-
return;
|
|
2088
|
-
}
|
|
2089
|
-
WritableStreamDefaultWriterRelease(this);
|
|
2090
|
-
};
|
|
2091
|
-
WritableStreamDefaultWriter.prototype.write = function (chunk) {
|
|
2092
|
-
if (chunk === void 0) { chunk = undefined; }
|
|
2093
|
-
if (!IsWritableStreamDefaultWriter(this)) {
|
|
2094
|
-
return promiseRejectedWith(defaultWriterBrandCheckException('write'));
|
|
2095
|
-
}
|
|
2096
|
-
if (this._ownerWritableStream === undefined) {
|
|
2097
|
-
return promiseRejectedWith(defaultWriterLockException('write to'));
|
|
2098
|
-
}
|
|
2099
|
-
return WritableStreamDefaultWriterWrite(this, chunk);
|
|
2100
|
-
};
|
|
2101
|
-
return WritableStreamDefaultWriter;
|
|
2102
|
-
}());
|
|
2103
|
-
Object.defineProperties(WritableStreamDefaultWriter.prototype, {
|
|
2104
|
-
abort: { enumerable: true },
|
|
2105
|
-
close: { enumerable: true },
|
|
2106
|
-
releaseLock: { enumerable: true },
|
|
2107
|
-
write: { enumerable: true },
|
|
2108
|
-
closed: { enumerable: true },
|
|
2109
|
-
desiredSize: { enumerable: true },
|
|
2110
|
-
ready: { enumerable: true }
|
|
2111
|
-
});
|
|
2112
|
-
if (typeof SymbolPolyfill.toStringTag === 'symbol') {
|
|
2113
|
-
Object.defineProperty(WritableStreamDefaultWriter.prototype, SymbolPolyfill.toStringTag, {
|
|
2114
|
-
value: 'WritableStreamDefaultWriter',
|
|
2115
|
-
configurable: true
|
|
2116
|
-
});
|
|
2117
|
-
}
|
|
2118
|
-
// Abstract operations for the WritableStreamDefaultWriter.
|
|
2119
|
-
function IsWritableStreamDefaultWriter(x) {
|
|
2120
|
-
if (!typeIsObject(x)) {
|
|
2121
|
-
return false;
|
|
2122
|
-
}
|
|
2123
|
-
if (!Object.prototype.hasOwnProperty.call(x, '_ownerWritableStream')) {
|
|
2124
|
-
return false;
|
|
2125
|
-
}
|
|
2126
|
-
return true;
|
|
2127
|
-
}
|
|
2128
|
-
// A client of WritableStreamDefaultWriter may use these functions directly to bypass state check.
|
|
2129
|
-
function WritableStreamDefaultWriterAbort(writer, reason) {
|
|
2130
|
-
var stream = writer._ownerWritableStream;
|
|
2131
|
-
return WritableStreamAbort(stream, reason);
|
|
2132
|
-
}
|
|
2133
|
-
function WritableStreamDefaultWriterClose(writer) {
|
|
2134
|
-
var stream = writer._ownerWritableStream;
|
|
2135
|
-
return WritableStreamClose(stream);
|
|
2136
|
-
}
|
|
2137
|
-
function WritableStreamDefaultWriterCloseWithErrorPropagation(writer) {
|
|
2138
|
-
var stream = writer._ownerWritableStream;
|
|
2139
|
-
var state = stream._state;
|
|
2140
|
-
if (WritableStreamCloseQueuedOrInFlight(stream) || state === 'closed') {
|
|
2141
|
-
return promiseResolvedWith(undefined);
|
|
2142
|
-
}
|
|
2143
|
-
if (state === 'errored') {
|
|
2144
|
-
return promiseRejectedWith(stream._storedError);
|
|
2145
|
-
}
|
|
2146
|
-
return WritableStreamDefaultWriterClose(writer);
|
|
2147
|
-
}
|
|
2148
|
-
function WritableStreamDefaultWriterEnsureClosedPromiseRejected(writer, error) {
|
|
2149
|
-
if (writer._closedPromiseState === 'pending') {
|
|
2150
|
-
defaultWriterClosedPromiseReject(writer, error);
|
|
2151
|
-
}
|
|
2152
|
-
else {
|
|
2153
|
-
defaultWriterClosedPromiseResetToRejected(writer, error);
|
|
2154
|
-
}
|
|
2155
|
-
}
|
|
2156
|
-
function WritableStreamDefaultWriterEnsureReadyPromiseRejected(writer, error) {
|
|
2157
|
-
if (writer._readyPromiseState === 'pending') {
|
|
2158
|
-
defaultWriterReadyPromiseReject(writer, error);
|
|
2159
|
-
}
|
|
2160
|
-
else {
|
|
2161
|
-
defaultWriterReadyPromiseResetToRejected(writer, error);
|
|
2162
|
-
}
|
|
2163
|
-
}
|
|
2164
|
-
function WritableStreamDefaultWriterGetDesiredSize(writer) {
|
|
2165
|
-
var stream = writer._ownerWritableStream;
|
|
2166
|
-
var state = stream._state;
|
|
2167
|
-
if (state === 'errored' || state === 'erroring') {
|
|
2168
|
-
return null;
|
|
2169
|
-
}
|
|
2170
|
-
if (state === 'closed') {
|
|
2171
|
-
return 0;
|
|
2172
|
-
}
|
|
2173
|
-
return WritableStreamDefaultControllerGetDesiredSize(stream._writableStreamController);
|
|
2174
|
-
}
|
|
2175
|
-
function WritableStreamDefaultWriterRelease(writer) {
|
|
2176
|
-
var stream = writer._ownerWritableStream;
|
|
2177
|
-
var releasedError = new TypeError("Writer was released and can no longer be used to monitor the stream's closedness");
|
|
2178
|
-
WritableStreamDefaultWriterEnsureReadyPromiseRejected(writer, releasedError);
|
|
2179
|
-
// The state transitions to "errored" before the sink abort() method runs, but the writer.closed promise is not
|
|
2180
|
-
// rejected until afterwards. This means that simply testing state will not work.
|
|
2181
|
-
WritableStreamDefaultWriterEnsureClosedPromiseRejected(writer, releasedError);
|
|
2182
|
-
stream._writer = undefined;
|
|
2183
|
-
writer._ownerWritableStream = undefined;
|
|
2184
|
-
}
|
|
2185
|
-
function WritableStreamDefaultWriterWrite(writer, chunk) {
|
|
2186
|
-
var stream = writer._ownerWritableStream;
|
|
2187
|
-
var controller = stream._writableStreamController;
|
|
2188
|
-
var chunkSize = WritableStreamDefaultControllerGetChunkSize(controller, chunk);
|
|
2189
|
-
if (stream !== writer._ownerWritableStream) {
|
|
2190
|
-
return promiseRejectedWith(defaultWriterLockException('write to'));
|
|
2191
|
-
}
|
|
2192
|
-
var state = stream._state;
|
|
2193
|
-
if (state === 'errored') {
|
|
2194
|
-
return promiseRejectedWith(stream._storedError);
|
|
2195
|
-
}
|
|
2196
|
-
if (WritableStreamCloseQueuedOrInFlight(stream) || state === 'closed') {
|
|
2197
|
-
return promiseRejectedWith(new TypeError('The stream is closing or closed and cannot be written to'));
|
|
2198
|
-
}
|
|
2199
|
-
if (state === 'erroring') {
|
|
2200
|
-
return promiseRejectedWith(stream._storedError);
|
|
2201
|
-
}
|
|
2202
|
-
var promise = WritableStreamAddWriteRequest(stream);
|
|
2203
|
-
WritableStreamDefaultControllerWrite(controller, chunk, chunkSize);
|
|
2204
|
-
return promise;
|
|
2205
|
-
}
|
|
2206
|
-
var closeSentinel = {};
|
|
2207
|
-
/**
|
|
2208
|
-
* Allows control of a {@link WritableStream | writable stream}'s state and internal queue.
|
|
2209
|
-
*
|
|
2210
|
-
* @public
|
|
2211
|
-
*/
|
|
2212
|
-
var WritableStreamDefaultController = /** @class */ (function () {
|
|
2213
|
-
function WritableStreamDefaultController() {
|
|
2214
|
-
throw new TypeError('Illegal constructor');
|
|
2215
|
-
}
|
|
2216
|
-
/**
|
|
2217
|
-
* Closes the controlled writable stream, making all future interactions with it fail with the given error `e`.
|
|
2218
|
-
*
|
|
2219
|
-
* This method is rarely used, since usually it suffices to return a rejected promise from one of the underlying
|
|
2220
|
-
* sink's methods. However, it can be useful for suddenly shutting down a stream in response to an event outside the
|
|
2221
|
-
* normal lifecycle of interactions with the underlying sink.
|
|
2222
|
-
*/
|
|
2223
|
-
WritableStreamDefaultController.prototype.error = function (e) {
|
|
2224
|
-
if (e === void 0) { e = undefined; }
|
|
2225
|
-
if (!IsWritableStreamDefaultController(this)) {
|
|
2226
|
-
throw new TypeError('WritableStreamDefaultController.prototype.error can only be used on a WritableStreamDefaultController');
|
|
2227
|
-
}
|
|
2228
|
-
var state = this._controlledWritableStream._state;
|
|
2229
|
-
if (state !== 'writable') {
|
|
2230
|
-
// The stream is closed, errored or will be soon. The sink can't do anything useful if it gets an error here, so
|
|
2231
|
-
// just treat it as a no-op.
|
|
2232
|
-
return;
|
|
2233
|
-
}
|
|
2234
|
-
WritableStreamDefaultControllerError(this, e);
|
|
2235
|
-
};
|
|
2236
|
-
/** @internal */
|
|
2237
|
-
WritableStreamDefaultController.prototype[AbortSteps] = function (reason) {
|
|
2238
|
-
var result = this._abortAlgorithm(reason);
|
|
2239
|
-
WritableStreamDefaultControllerClearAlgorithms(this);
|
|
2240
|
-
return result;
|
|
2241
|
-
};
|
|
2242
|
-
/** @internal */
|
|
2243
|
-
WritableStreamDefaultController.prototype[ErrorSteps] = function () {
|
|
2244
|
-
ResetQueue(this);
|
|
2245
|
-
};
|
|
2246
|
-
return WritableStreamDefaultController;
|
|
2247
|
-
}());
|
|
2248
|
-
Object.defineProperties(WritableStreamDefaultController.prototype, {
|
|
2249
|
-
error: { enumerable: true }
|
|
2250
|
-
});
|
|
2251
|
-
if (typeof SymbolPolyfill.toStringTag === 'symbol') {
|
|
2252
|
-
Object.defineProperty(WritableStreamDefaultController.prototype, SymbolPolyfill.toStringTag, {
|
|
2253
|
-
value: 'WritableStreamDefaultController',
|
|
2254
|
-
configurable: true
|
|
2255
|
-
});
|
|
2256
|
-
}
|
|
2257
|
-
// Abstract operations implementing interface required by the WritableStream.
|
|
2258
|
-
function IsWritableStreamDefaultController(x) {
|
|
2259
|
-
if (!typeIsObject(x)) {
|
|
2260
|
-
return false;
|
|
2261
|
-
}
|
|
2262
|
-
if (!Object.prototype.hasOwnProperty.call(x, '_controlledWritableStream')) {
|
|
2263
|
-
return false;
|
|
2264
|
-
}
|
|
2265
|
-
return true;
|
|
2266
|
-
}
|
|
2267
|
-
function SetUpWritableStreamDefaultController(stream, controller, startAlgorithm, writeAlgorithm, closeAlgorithm, abortAlgorithm, highWaterMark, sizeAlgorithm) {
|
|
2268
|
-
controller._controlledWritableStream = stream;
|
|
2269
|
-
stream._writableStreamController = controller;
|
|
2270
|
-
// Need to set the slots so that the assert doesn't fire. In the spec the slots already exist implicitly.
|
|
2271
|
-
controller._queue = undefined;
|
|
2272
|
-
controller._queueTotalSize = undefined;
|
|
2273
|
-
ResetQueue(controller);
|
|
2274
|
-
controller._started = false;
|
|
2275
|
-
controller._strategySizeAlgorithm = sizeAlgorithm;
|
|
2276
|
-
controller._strategyHWM = highWaterMark;
|
|
2277
|
-
controller._writeAlgorithm = writeAlgorithm;
|
|
2278
|
-
controller._closeAlgorithm = closeAlgorithm;
|
|
2279
|
-
controller._abortAlgorithm = abortAlgorithm;
|
|
2280
|
-
var backpressure = WritableStreamDefaultControllerGetBackpressure(controller);
|
|
2281
|
-
WritableStreamUpdateBackpressure(stream, backpressure);
|
|
2282
|
-
var startResult = startAlgorithm();
|
|
2283
|
-
var startPromise = promiseResolvedWith(startResult);
|
|
2284
|
-
uponPromise(startPromise, function () {
|
|
2285
|
-
controller._started = true;
|
|
2286
|
-
WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller);
|
|
2287
|
-
}, function (r) {
|
|
2288
|
-
controller._started = true;
|
|
2289
|
-
WritableStreamDealWithRejection(stream, r);
|
|
2290
|
-
});
|
|
2291
|
-
}
|
|
2292
|
-
function SetUpWritableStreamDefaultControllerFromUnderlyingSink(stream, underlyingSink, highWaterMark, sizeAlgorithm) {
|
|
2293
|
-
var controller = Object.create(WritableStreamDefaultController.prototype);
|
|
2294
|
-
var startAlgorithm = function () { return undefined; };
|
|
2295
|
-
var writeAlgorithm = function () { return promiseResolvedWith(undefined); };
|
|
2296
|
-
var closeAlgorithm = function () { return promiseResolvedWith(undefined); };
|
|
2297
|
-
var abortAlgorithm = function () { return promiseResolvedWith(undefined); };
|
|
2298
|
-
if (underlyingSink.start !== undefined) {
|
|
2299
|
-
startAlgorithm = function () { return underlyingSink.start(controller); };
|
|
2300
|
-
}
|
|
2301
|
-
if (underlyingSink.write !== undefined) {
|
|
2302
|
-
writeAlgorithm = function (chunk) { return underlyingSink.write(chunk, controller); };
|
|
2303
|
-
}
|
|
2304
|
-
if (underlyingSink.close !== undefined) {
|
|
2305
|
-
closeAlgorithm = function () { return underlyingSink.close(); };
|
|
2306
|
-
}
|
|
2307
|
-
if (underlyingSink.abort !== undefined) {
|
|
2308
|
-
abortAlgorithm = function (reason) { return underlyingSink.abort(reason); };
|
|
2309
|
-
}
|
|
2310
|
-
SetUpWritableStreamDefaultController(stream, controller, startAlgorithm, writeAlgorithm, closeAlgorithm, abortAlgorithm, highWaterMark, sizeAlgorithm);
|
|
2311
|
-
}
|
|
2312
|
-
// ClearAlgorithms may be called twice. Erroring the same stream in multiple ways will often result in redundant calls.
|
|
2313
|
-
function WritableStreamDefaultControllerClearAlgorithms(controller) {
|
|
2314
|
-
controller._writeAlgorithm = undefined;
|
|
2315
|
-
controller._closeAlgorithm = undefined;
|
|
2316
|
-
controller._abortAlgorithm = undefined;
|
|
2317
|
-
controller._strategySizeAlgorithm = undefined;
|
|
2318
|
-
}
|
|
2319
|
-
function WritableStreamDefaultControllerClose(controller) {
|
|
2320
|
-
EnqueueValueWithSize(controller, closeSentinel, 0);
|
|
2321
|
-
WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller);
|
|
2322
|
-
}
|
|
2323
|
-
function WritableStreamDefaultControllerGetChunkSize(controller, chunk) {
|
|
2324
|
-
try {
|
|
2325
|
-
return controller._strategySizeAlgorithm(chunk);
|
|
2326
|
-
}
|
|
2327
|
-
catch (chunkSizeE) {
|
|
2328
|
-
WritableStreamDefaultControllerErrorIfNeeded(controller, chunkSizeE);
|
|
2329
|
-
return 1;
|
|
2330
|
-
}
|
|
2331
|
-
}
|
|
2332
|
-
function WritableStreamDefaultControllerGetDesiredSize(controller) {
|
|
2333
|
-
return controller._strategyHWM - controller._queueTotalSize;
|
|
2334
|
-
}
|
|
2335
|
-
function WritableStreamDefaultControllerWrite(controller, chunk, chunkSize) {
|
|
2336
|
-
try {
|
|
2337
|
-
EnqueueValueWithSize(controller, chunk, chunkSize);
|
|
2338
|
-
}
|
|
2339
|
-
catch (enqueueE) {
|
|
2340
|
-
WritableStreamDefaultControllerErrorIfNeeded(controller, enqueueE);
|
|
2341
|
-
return;
|
|
2342
|
-
}
|
|
2343
|
-
var stream = controller._controlledWritableStream;
|
|
2344
|
-
if (!WritableStreamCloseQueuedOrInFlight(stream) && stream._state === 'writable') {
|
|
2345
|
-
var backpressure = WritableStreamDefaultControllerGetBackpressure(controller);
|
|
2346
|
-
WritableStreamUpdateBackpressure(stream, backpressure);
|
|
2347
|
-
}
|
|
2348
|
-
WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller);
|
|
2349
|
-
}
|
|
2350
|
-
// Abstract operations for the WritableStreamDefaultController.
|
|
2351
|
-
function WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller) {
|
|
2352
|
-
var stream = controller._controlledWritableStream;
|
|
2353
|
-
if (!controller._started) {
|
|
2354
|
-
return;
|
|
2355
|
-
}
|
|
2356
|
-
if (stream._inFlightWriteRequest !== undefined) {
|
|
2357
|
-
return;
|
|
2358
|
-
}
|
|
2359
|
-
var state = stream._state;
|
|
2360
|
-
if (state === 'erroring') {
|
|
2361
|
-
WritableStreamFinishErroring(stream);
|
|
2362
|
-
return;
|
|
2363
|
-
}
|
|
2364
|
-
if (controller._queue.length === 0) {
|
|
2365
|
-
return;
|
|
2366
|
-
}
|
|
2367
|
-
var value = PeekQueueValue(controller);
|
|
2368
|
-
if (value === closeSentinel) {
|
|
2369
|
-
WritableStreamDefaultControllerProcessClose(controller);
|
|
2370
|
-
}
|
|
2371
|
-
else {
|
|
2372
|
-
WritableStreamDefaultControllerProcessWrite(controller, value);
|
|
2373
|
-
}
|
|
2374
|
-
}
|
|
2375
|
-
function WritableStreamDefaultControllerErrorIfNeeded(controller, error) {
|
|
2376
|
-
if (controller._controlledWritableStream._state === 'writable') {
|
|
2377
|
-
WritableStreamDefaultControllerError(controller, error);
|
|
2378
|
-
}
|
|
2379
|
-
}
|
|
2380
|
-
function WritableStreamDefaultControllerProcessClose(controller) {
|
|
2381
|
-
var stream = controller._controlledWritableStream;
|
|
2382
|
-
WritableStreamMarkCloseRequestInFlight(stream);
|
|
2383
|
-
DequeueValue(controller);
|
|
2384
|
-
var sinkClosePromise = controller._closeAlgorithm();
|
|
2385
|
-
WritableStreamDefaultControllerClearAlgorithms(controller);
|
|
2386
|
-
uponPromise(sinkClosePromise, function () {
|
|
2387
|
-
WritableStreamFinishInFlightClose(stream);
|
|
2388
|
-
}, function (reason) {
|
|
2389
|
-
WritableStreamFinishInFlightCloseWithError(stream, reason);
|
|
2390
|
-
});
|
|
2391
|
-
}
|
|
2392
|
-
function WritableStreamDefaultControllerProcessWrite(controller, chunk) {
|
|
2393
|
-
var stream = controller._controlledWritableStream;
|
|
2394
|
-
WritableStreamMarkFirstWriteRequestInFlight(stream);
|
|
2395
|
-
var sinkWritePromise = controller._writeAlgorithm(chunk);
|
|
2396
|
-
uponPromise(sinkWritePromise, function () {
|
|
2397
|
-
WritableStreamFinishInFlightWrite(stream);
|
|
2398
|
-
var state = stream._state;
|
|
2399
|
-
DequeueValue(controller);
|
|
2400
|
-
if (!WritableStreamCloseQueuedOrInFlight(stream) && state === 'writable') {
|
|
2401
|
-
var backpressure = WritableStreamDefaultControllerGetBackpressure(controller);
|
|
2402
|
-
WritableStreamUpdateBackpressure(stream, backpressure);
|
|
2403
|
-
}
|
|
2404
|
-
WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller);
|
|
2405
|
-
}, function (reason) {
|
|
2406
|
-
if (stream._state === 'writable') {
|
|
2407
|
-
WritableStreamDefaultControllerClearAlgorithms(controller);
|
|
2408
|
-
}
|
|
2409
|
-
WritableStreamFinishInFlightWriteWithError(stream, reason);
|
|
2410
|
-
});
|
|
2411
|
-
}
|
|
2412
|
-
function WritableStreamDefaultControllerGetBackpressure(controller) {
|
|
2413
|
-
var desiredSize = WritableStreamDefaultControllerGetDesiredSize(controller);
|
|
2414
|
-
return desiredSize <= 0;
|
|
2415
|
-
}
|
|
2416
|
-
// A client of WritableStreamDefaultController may use these functions directly to bypass state check.
|
|
2417
|
-
function WritableStreamDefaultControllerError(controller, error) {
|
|
2418
|
-
var stream = controller._controlledWritableStream;
|
|
2419
|
-
WritableStreamDefaultControllerClearAlgorithms(controller);
|
|
2420
|
-
WritableStreamStartErroring(stream, error);
|
|
2421
|
-
}
|
|
2422
|
-
// Helper functions for the WritableStream.
|
|
2423
|
-
function streamBrandCheckException$2(name) {
|
|
2424
|
-
return new TypeError("WritableStream.prototype." + name + " can only be used on a WritableStream");
|
|
2425
|
-
}
|
|
2426
|
-
// Helper functions for the WritableStreamDefaultWriter.
|
|
2427
|
-
function defaultWriterBrandCheckException(name) {
|
|
2428
|
-
return new TypeError("WritableStreamDefaultWriter.prototype." + name + " can only be used on a WritableStreamDefaultWriter");
|
|
2429
|
-
}
|
|
2430
|
-
function defaultWriterLockException(name) {
|
|
2431
|
-
return new TypeError('Cannot ' + name + ' a stream using a released writer');
|
|
2432
|
-
}
|
|
2433
|
-
function defaultWriterClosedPromiseInitialize(writer) {
|
|
2434
|
-
writer._closedPromise = newPromise(function (resolve, reject) {
|
|
2435
|
-
writer._closedPromise_resolve = resolve;
|
|
2436
|
-
writer._closedPromise_reject = reject;
|
|
2437
|
-
writer._closedPromiseState = 'pending';
|
|
2438
|
-
});
|
|
2439
|
-
}
|
|
2440
|
-
function defaultWriterClosedPromiseInitializeAsRejected(writer, reason) {
|
|
2441
|
-
defaultWriterClosedPromiseInitialize(writer);
|
|
2442
|
-
defaultWriterClosedPromiseReject(writer, reason);
|
|
2443
|
-
}
|
|
2444
|
-
function defaultWriterClosedPromiseInitializeAsResolved(writer) {
|
|
2445
|
-
defaultWriterClosedPromiseInitialize(writer);
|
|
2446
|
-
defaultWriterClosedPromiseResolve(writer);
|
|
2447
|
-
}
|
|
2448
|
-
function defaultWriterClosedPromiseReject(writer, reason) {
|
|
2449
|
-
if (writer._closedPromise_reject === undefined) {
|
|
2450
|
-
return;
|
|
2451
|
-
}
|
|
2452
|
-
setPromiseIsHandledToTrue(writer._closedPromise);
|
|
2453
|
-
writer._closedPromise_reject(reason);
|
|
2454
|
-
writer._closedPromise_resolve = undefined;
|
|
2455
|
-
writer._closedPromise_reject = undefined;
|
|
2456
|
-
writer._closedPromiseState = 'rejected';
|
|
2457
|
-
}
|
|
2458
|
-
function defaultWriterClosedPromiseResetToRejected(writer, reason) {
|
|
2459
|
-
defaultWriterClosedPromiseInitializeAsRejected(writer, reason);
|
|
2460
|
-
}
|
|
2461
|
-
function defaultWriterClosedPromiseResolve(writer) {
|
|
2462
|
-
if (writer._closedPromise_resolve === undefined) {
|
|
2463
|
-
return;
|
|
2464
|
-
}
|
|
2465
|
-
writer._closedPromise_resolve(undefined);
|
|
2466
|
-
writer._closedPromise_resolve = undefined;
|
|
2467
|
-
writer._closedPromise_reject = undefined;
|
|
2468
|
-
writer._closedPromiseState = 'resolved';
|
|
2469
|
-
}
|
|
2470
|
-
function defaultWriterReadyPromiseInitialize(writer) {
|
|
2471
|
-
writer._readyPromise = newPromise(function (resolve, reject) {
|
|
2472
|
-
writer._readyPromise_resolve = resolve;
|
|
2473
|
-
writer._readyPromise_reject = reject;
|
|
2474
|
-
});
|
|
2475
|
-
writer._readyPromiseState = 'pending';
|
|
2476
|
-
}
|
|
2477
|
-
function defaultWriterReadyPromiseInitializeAsRejected(writer, reason) {
|
|
2478
|
-
defaultWriterReadyPromiseInitialize(writer);
|
|
2479
|
-
defaultWriterReadyPromiseReject(writer, reason);
|
|
2480
|
-
}
|
|
2481
|
-
function defaultWriterReadyPromiseInitializeAsResolved(writer) {
|
|
2482
|
-
defaultWriterReadyPromiseInitialize(writer);
|
|
2483
|
-
defaultWriterReadyPromiseResolve(writer);
|
|
2484
|
-
}
|
|
2485
|
-
function defaultWriterReadyPromiseReject(writer, reason) {
|
|
2486
|
-
if (writer._readyPromise_reject === undefined) {
|
|
2487
|
-
return;
|
|
2488
|
-
}
|
|
2489
|
-
setPromiseIsHandledToTrue(writer._readyPromise);
|
|
2490
|
-
writer._readyPromise_reject(reason);
|
|
2491
|
-
writer._readyPromise_resolve = undefined;
|
|
2492
|
-
writer._readyPromise_reject = undefined;
|
|
2493
|
-
writer._readyPromiseState = 'rejected';
|
|
2494
|
-
}
|
|
2495
|
-
function defaultWriterReadyPromiseReset(writer) {
|
|
2496
|
-
defaultWriterReadyPromiseInitialize(writer);
|
|
2497
|
-
}
|
|
2498
|
-
function defaultWriterReadyPromiseResetToRejected(writer, reason) {
|
|
2499
|
-
defaultWriterReadyPromiseInitializeAsRejected(writer, reason);
|
|
2500
|
-
}
|
|
2501
|
-
function defaultWriterReadyPromiseResolve(writer) {
|
|
2502
|
-
if (writer._readyPromise_resolve === undefined) {
|
|
2503
|
-
return;
|
|
2504
|
-
}
|
|
2505
|
-
writer._readyPromise_resolve(undefined);
|
|
2506
|
-
writer._readyPromise_resolve = undefined;
|
|
2507
|
-
writer._readyPromise_reject = undefined;
|
|
2508
|
-
writer._readyPromiseState = 'fulfilled';
|
|
2509
|
-
}
|
|
2510
|
-
|
|
2511
|
-
function isAbortSignal(value) {
|
|
2512
|
-
if (typeof value !== 'object' || value === null) {
|
|
2513
|
-
return false;
|
|
2514
|
-
}
|
|
2515
|
-
try {
|
|
2516
|
-
return typeof value.aborted === 'boolean';
|
|
2517
|
-
}
|
|
2518
|
-
catch (_a) {
|
|
2519
|
-
// AbortSignal.prototype.aborted throws if its brand check fails
|
|
2520
|
-
return false;
|
|
2521
|
-
}
|
|
2522
|
-
}
|
|
2523
|
-
|
|
2524
|
-
/// <reference lib="dom" />
|
|
2525
|
-
var NativeDOMException = typeof DOMException !== 'undefined' ? DOMException : undefined;
|
|
2526
|
-
|
|
2527
|
-
/// <reference types="node" />
|
|
2528
|
-
function isDOMExceptionConstructor(ctor) {
|
|
2529
|
-
if (!(typeof ctor === 'function' || typeof ctor === 'object')) {
|
|
2530
|
-
return false;
|
|
2531
|
-
}
|
|
2532
|
-
try {
|
|
2533
|
-
new ctor();
|
|
2534
|
-
return true;
|
|
2535
|
-
}
|
|
2536
|
-
catch (_a) {
|
|
2537
|
-
return false;
|
|
2538
|
-
}
|
|
2539
|
-
}
|
|
2540
|
-
function createDOMExceptionPolyfill() {
|
|
2541
|
-
// eslint-disable-next-line no-shadow
|
|
2542
|
-
var ctor = function DOMException(message, name) {
|
|
2543
|
-
this.message = message || '';
|
|
2544
|
-
this.name = name || 'Error';
|
|
2545
|
-
if (Error.captureStackTrace) {
|
|
2546
|
-
Error.captureStackTrace(this, this.constructor);
|
|
2547
|
-
}
|
|
2548
|
-
};
|
|
2549
|
-
ctor.prototype = Object.create(Error.prototype);
|
|
2550
|
-
Object.defineProperty(ctor.prototype, 'constructor', { value: ctor, writable: true, configurable: true });
|
|
2551
|
-
return ctor;
|
|
2552
|
-
}
|
|
2553
|
-
// eslint-disable-next-line no-redeclare
|
|
2554
|
-
var DOMException$1 = isDOMExceptionConstructor(NativeDOMException) ? NativeDOMException : createDOMExceptionPolyfill();
|
|
2555
|
-
|
|
2556
|
-
function ReadableStreamPipeTo(source, dest, preventClose, preventAbort, preventCancel, signal) {
|
|
2557
|
-
var reader = AcquireReadableStreamDefaultReader(source);
|
|
2558
|
-
var writer = AcquireWritableStreamDefaultWriter(dest);
|
|
2559
|
-
source._disturbed = true;
|
|
2560
|
-
var shuttingDown = false;
|
|
2561
|
-
// This is used to keep track of the spec's requirement that we wait for ongoing writes during shutdown.
|
|
2562
|
-
var currentWrite = promiseResolvedWith(undefined);
|
|
2563
|
-
return newPromise(function (resolve, reject) {
|
|
2564
|
-
var abortAlgorithm;
|
|
2565
|
-
if (signal !== undefined) {
|
|
2566
|
-
abortAlgorithm = function () {
|
|
2567
|
-
var error = new DOMException$1('Aborted', 'AbortError');
|
|
2568
|
-
var actions = [];
|
|
2569
|
-
if (!preventAbort) {
|
|
2570
|
-
actions.push(function () {
|
|
2571
|
-
if (dest._state === 'writable') {
|
|
2572
|
-
return WritableStreamAbort(dest, error);
|
|
2573
|
-
}
|
|
2574
|
-
return promiseResolvedWith(undefined);
|
|
2575
|
-
});
|
|
2576
|
-
}
|
|
2577
|
-
if (!preventCancel) {
|
|
2578
|
-
actions.push(function () {
|
|
2579
|
-
if (source._state === 'readable') {
|
|
2580
|
-
return ReadableStreamCancel(source, error);
|
|
2581
|
-
}
|
|
2582
|
-
return promiseResolvedWith(undefined);
|
|
2583
|
-
});
|
|
2584
|
-
}
|
|
2585
|
-
shutdownWithAction(function () { return Promise.all(actions.map(function (action) { return action(); })); }, true, error);
|
|
2586
|
-
};
|
|
2587
|
-
if (signal.aborted) {
|
|
2588
|
-
abortAlgorithm();
|
|
2589
|
-
return;
|
|
2590
|
-
}
|
|
2591
|
-
signal.addEventListener('abort', abortAlgorithm);
|
|
2592
|
-
}
|
|
2593
|
-
// Using reader and writer, read all chunks from this and write them to dest
|
|
2594
|
-
// - Backpressure must be enforced
|
|
2595
|
-
// - Shutdown must stop all activity
|
|
2596
|
-
function pipeLoop() {
|
|
2597
|
-
return newPromise(function (resolveLoop, rejectLoop) {
|
|
2598
|
-
function next(done) {
|
|
2599
|
-
if (done) {
|
|
2600
|
-
resolveLoop();
|
|
2601
|
-
}
|
|
2602
|
-
else {
|
|
2603
|
-
// Use `PerformPromiseThen` instead of `uponPromise` to avoid
|
|
2604
|
-
// adding unnecessary `.catch(rethrowAssertionErrorRejection)` handlers
|
|
2605
|
-
PerformPromiseThen(pipeStep(), next, rejectLoop);
|
|
2606
|
-
}
|
|
2607
|
-
}
|
|
2608
|
-
next(false);
|
|
2609
|
-
});
|
|
2610
|
-
}
|
|
2611
|
-
function pipeStep() {
|
|
2612
|
-
if (shuttingDown) {
|
|
2613
|
-
return promiseResolvedWith(true);
|
|
2614
|
-
}
|
|
2615
|
-
return PerformPromiseThen(writer._readyPromise, function () {
|
|
2616
|
-
return newPromise(function (resolveRead, rejectRead) {
|
|
2617
|
-
ReadableStreamDefaultReaderRead(reader, {
|
|
2618
|
-
_chunkSteps: function (chunk) {
|
|
2619
|
-
currentWrite = PerformPromiseThen(WritableStreamDefaultWriterWrite(writer, chunk), undefined, noop);
|
|
2620
|
-
resolveRead(false);
|
|
2621
|
-
},
|
|
2622
|
-
_closeSteps: function () { return resolveRead(true); },
|
|
2623
|
-
_errorSteps: rejectRead
|
|
2624
|
-
});
|
|
2625
|
-
});
|
|
2626
|
-
});
|
|
2627
|
-
}
|
|
2628
|
-
// Errors must be propagated forward
|
|
2629
|
-
isOrBecomesErrored(source, reader._closedPromise, function (storedError) {
|
|
2630
|
-
if (!preventAbort) {
|
|
2631
|
-
shutdownWithAction(function () { return WritableStreamAbort(dest, storedError); }, true, storedError);
|
|
2632
|
-
}
|
|
2633
|
-
else {
|
|
2634
|
-
shutdown(true, storedError);
|
|
2635
|
-
}
|
|
2636
|
-
});
|
|
2637
|
-
// Errors must be propagated backward
|
|
2638
|
-
isOrBecomesErrored(dest, writer._closedPromise, function (storedError) {
|
|
2639
|
-
if (!preventCancel) {
|
|
2640
|
-
shutdownWithAction(function () { return ReadableStreamCancel(source, storedError); }, true, storedError);
|
|
2641
|
-
}
|
|
2642
|
-
else {
|
|
2643
|
-
shutdown(true, storedError);
|
|
2644
|
-
}
|
|
2645
|
-
});
|
|
2646
|
-
// Closing must be propagated forward
|
|
2647
|
-
isOrBecomesClosed(source, reader._closedPromise, function () {
|
|
2648
|
-
if (!preventClose) {
|
|
2649
|
-
shutdownWithAction(function () { return WritableStreamDefaultWriterCloseWithErrorPropagation(writer); });
|
|
2650
|
-
}
|
|
2651
|
-
else {
|
|
2652
|
-
shutdown();
|
|
2653
|
-
}
|
|
2654
|
-
});
|
|
2655
|
-
// Closing must be propagated backward
|
|
2656
|
-
if (WritableStreamCloseQueuedOrInFlight(dest) || dest._state === 'closed') {
|
|
2657
|
-
var destClosed_1 = new TypeError('the destination writable stream closed before all data could be piped to it');
|
|
2658
|
-
if (!preventCancel) {
|
|
2659
|
-
shutdownWithAction(function () { return ReadableStreamCancel(source, destClosed_1); }, true, destClosed_1);
|
|
2660
|
-
}
|
|
2661
|
-
else {
|
|
2662
|
-
shutdown(true, destClosed_1);
|
|
2663
|
-
}
|
|
2664
|
-
}
|
|
2665
|
-
setPromiseIsHandledToTrue(pipeLoop());
|
|
2666
|
-
function waitForWritesToFinish() {
|
|
2667
|
-
// Another write may have started while we were waiting on this currentWrite, so we have to be sure to wait
|
|
2668
|
-
// for that too.
|
|
2669
|
-
var oldCurrentWrite = currentWrite;
|
|
2670
|
-
return PerformPromiseThen(currentWrite, function () { return oldCurrentWrite !== currentWrite ? waitForWritesToFinish() : undefined; });
|
|
2671
|
-
}
|
|
2672
|
-
function isOrBecomesErrored(stream, promise, action) {
|
|
2673
|
-
if (stream._state === 'errored') {
|
|
2674
|
-
action(stream._storedError);
|
|
2675
|
-
}
|
|
2676
|
-
else {
|
|
2677
|
-
uponRejection(promise, action);
|
|
2678
|
-
}
|
|
2679
|
-
}
|
|
2680
|
-
function isOrBecomesClosed(stream, promise, action) {
|
|
2681
|
-
if (stream._state === 'closed') {
|
|
2682
|
-
action();
|
|
2683
|
-
}
|
|
2684
|
-
else {
|
|
2685
|
-
uponFulfillment(promise, action);
|
|
2686
|
-
}
|
|
2687
|
-
}
|
|
2688
|
-
function shutdownWithAction(action, originalIsError, originalError) {
|
|
2689
|
-
if (shuttingDown) {
|
|
2690
|
-
return;
|
|
2691
|
-
}
|
|
2692
|
-
shuttingDown = true;
|
|
2693
|
-
if (dest._state === 'writable' && !WritableStreamCloseQueuedOrInFlight(dest)) {
|
|
2694
|
-
uponFulfillment(waitForWritesToFinish(), doTheRest);
|
|
2695
|
-
}
|
|
2696
|
-
else {
|
|
2697
|
-
doTheRest();
|
|
2698
|
-
}
|
|
2699
|
-
function doTheRest() {
|
|
2700
|
-
uponPromise(action(), function () { return finalize(originalIsError, originalError); }, function (newError) { return finalize(true, newError); });
|
|
2701
|
-
}
|
|
2702
|
-
}
|
|
2703
|
-
function shutdown(isError, error) {
|
|
2704
|
-
if (shuttingDown) {
|
|
2705
|
-
return;
|
|
2706
|
-
}
|
|
2707
|
-
shuttingDown = true;
|
|
2708
|
-
if (dest._state === 'writable' && !WritableStreamCloseQueuedOrInFlight(dest)) {
|
|
2709
|
-
uponFulfillment(waitForWritesToFinish(), function () { return finalize(isError, error); });
|
|
2710
|
-
}
|
|
2711
|
-
else {
|
|
2712
|
-
finalize(isError, error);
|
|
2713
|
-
}
|
|
2714
|
-
}
|
|
2715
|
-
function finalize(isError, error) {
|
|
2716
|
-
WritableStreamDefaultWriterRelease(writer);
|
|
2717
|
-
ReadableStreamReaderGenericRelease(reader);
|
|
2718
|
-
if (signal !== undefined) {
|
|
2719
|
-
signal.removeEventListener('abort', abortAlgorithm);
|
|
2720
|
-
}
|
|
2721
|
-
if (isError) {
|
|
2722
|
-
reject(error);
|
|
2723
|
-
}
|
|
2724
|
-
else {
|
|
2725
|
-
resolve(undefined);
|
|
2726
|
-
}
|
|
2727
|
-
}
|
|
2728
|
-
});
|
|
2729
|
-
}
|
|
2730
|
-
|
|
2731
|
-
/**
|
|
2732
|
-
* Allows control of a {@link ReadableStream | readable stream}'s state and internal queue.
|
|
2733
|
-
*
|
|
2734
|
-
* @public
|
|
2735
|
-
*/
|
|
2736
|
-
var ReadableStreamDefaultController = /** @class */ (function () {
|
|
2737
|
-
function ReadableStreamDefaultController() {
|
|
2738
|
-
throw new TypeError('Illegal constructor');
|
|
2739
|
-
}
|
|
2740
|
-
Object.defineProperty(ReadableStreamDefaultController.prototype, "desiredSize", {
|
|
2741
|
-
/**
|
|
2742
|
-
* Returns the desired size to fill the controlled stream's internal queue. It can be negative, if the queue is
|
|
2743
|
-
* over-full. An underlying source ought to use this information to determine when and how to apply backpressure.
|
|
2744
|
-
*/
|
|
2745
|
-
get: function () {
|
|
2746
|
-
if (!IsReadableStreamDefaultController(this)) {
|
|
2747
|
-
throw defaultControllerBrandCheckException$1('desiredSize');
|
|
2748
|
-
}
|
|
2749
|
-
return ReadableStreamDefaultControllerGetDesiredSize(this);
|
|
2750
|
-
},
|
|
2751
|
-
enumerable: false,
|
|
2752
|
-
configurable: true
|
|
2753
|
-
});
|
|
2754
|
-
/**
|
|
2755
|
-
* Closes the controlled readable stream. Consumers will still be able to read any previously-enqueued chunks from
|
|
2756
|
-
* the stream, but once those are read, the stream will become closed.
|
|
2757
|
-
*/
|
|
2758
|
-
ReadableStreamDefaultController.prototype.close = function () {
|
|
2759
|
-
if (!IsReadableStreamDefaultController(this)) {
|
|
2760
|
-
throw defaultControllerBrandCheckException$1('close');
|
|
2761
|
-
}
|
|
2762
|
-
if (!ReadableStreamDefaultControllerCanCloseOrEnqueue(this)) {
|
|
2763
|
-
throw new TypeError('The stream is not in a state that permits close');
|
|
2764
|
-
}
|
|
2765
|
-
ReadableStreamDefaultControllerClose(this);
|
|
2766
|
-
};
|
|
2767
|
-
ReadableStreamDefaultController.prototype.enqueue = function (chunk) {
|
|
2768
|
-
if (chunk === void 0) { chunk = undefined; }
|
|
2769
|
-
if (!IsReadableStreamDefaultController(this)) {
|
|
2770
|
-
throw defaultControllerBrandCheckException$1('enqueue');
|
|
2771
|
-
}
|
|
2772
|
-
if (!ReadableStreamDefaultControllerCanCloseOrEnqueue(this)) {
|
|
2773
|
-
throw new TypeError('The stream is not in a state that permits enqueue');
|
|
2774
|
-
}
|
|
2775
|
-
return ReadableStreamDefaultControllerEnqueue(this, chunk);
|
|
2776
|
-
};
|
|
2777
|
-
/**
|
|
2778
|
-
* Errors the controlled readable stream, making all future interactions with it fail with the given error `e`.
|
|
2779
|
-
*/
|
|
2780
|
-
ReadableStreamDefaultController.prototype.error = function (e) {
|
|
2781
|
-
if (e === void 0) { e = undefined; }
|
|
2782
|
-
if (!IsReadableStreamDefaultController(this)) {
|
|
2783
|
-
throw defaultControllerBrandCheckException$1('error');
|
|
2784
|
-
}
|
|
2785
|
-
ReadableStreamDefaultControllerError(this, e);
|
|
2786
|
-
};
|
|
2787
|
-
/** @internal */
|
|
2788
|
-
ReadableStreamDefaultController.prototype[CancelSteps] = function (reason) {
|
|
2789
|
-
ResetQueue(this);
|
|
2790
|
-
var result = this._cancelAlgorithm(reason);
|
|
2791
|
-
ReadableStreamDefaultControllerClearAlgorithms(this);
|
|
2792
|
-
return result;
|
|
2793
|
-
};
|
|
2794
|
-
/** @internal */
|
|
2795
|
-
ReadableStreamDefaultController.prototype[PullSteps] = function (readRequest) {
|
|
2796
|
-
var stream = this._controlledReadableStream;
|
|
2797
|
-
if (this._queue.length > 0) {
|
|
2798
|
-
var chunk = DequeueValue(this);
|
|
2799
|
-
if (this._closeRequested && this._queue.length === 0) {
|
|
2800
|
-
ReadableStreamDefaultControllerClearAlgorithms(this);
|
|
2801
|
-
ReadableStreamClose(stream);
|
|
2802
|
-
}
|
|
2803
|
-
else {
|
|
2804
|
-
ReadableStreamDefaultControllerCallPullIfNeeded(this);
|
|
2805
|
-
}
|
|
2806
|
-
readRequest._chunkSteps(chunk);
|
|
2807
|
-
}
|
|
2808
|
-
else {
|
|
2809
|
-
ReadableStreamAddReadRequest(stream, readRequest);
|
|
2810
|
-
ReadableStreamDefaultControllerCallPullIfNeeded(this);
|
|
2811
|
-
}
|
|
2812
|
-
};
|
|
2813
|
-
return ReadableStreamDefaultController;
|
|
2814
|
-
}());
|
|
2815
|
-
Object.defineProperties(ReadableStreamDefaultController.prototype, {
|
|
2816
|
-
close: { enumerable: true },
|
|
2817
|
-
enqueue: { enumerable: true },
|
|
2818
|
-
error: { enumerable: true },
|
|
2819
|
-
desiredSize: { enumerable: true }
|
|
2820
|
-
});
|
|
2821
|
-
if (typeof SymbolPolyfill.toStringTag === 'symbol') {
|
|
2822
|
-
Object.defineProperty(ReadableStreamDefaultController.prototype, SymbolPolyfill.toStringTag, {
|
|
2823
|
-
value: 'ReadableStreamDefaultController',
|
|
2824
|
-
configurable: true
|
|
2825
|
-
});
|
|
2826
|
-
}
|
|
2827
|
-
// Abstract operations for the ReadableStreamDefaultController.
|
|
2828
|
-
function IsReadableStreamDefaultController(x) {
|
|
2829
|
-
if (!typeIsObject(x)) {
|
|
2830
|
-
return false;
|
|
2831
|
-
}
|
|
2832
|
-
if (!Object.prototype.hasOwnProperty.call(x, '_controlledReadableStream')) {
|
|
2833
|
-
return false;
|
|
2834
|
-
}
|
|
2835
|
-
return true;
|
|
2836
|
-
}
|
|
2837
|
-
function ReadableStreamDefaultControllerCallPullIfNeeded(controller) {
|
|
2838
|
-
var shouldPull = ReadableStreamDefaultControllerShouldCallPull(controller);
|
|
2839
|
-
if (!shouldPull) {
|
|
2840
|
-
return;
|
|
2841
|
-
}
|
|
2842
|
-
if (controller._pulling) {
|
|
2843
|
-
controller._pullAgain = true;
|
|
2844
|
-
return;
|
|
2845
|
-
}
|
|
2846
|
-
controller._pulling = true;
|
|
2847
|
-
var pullPromise = controller._pullAlgorithm();
|
|
2848
|
-
uponPromise(pullPromise, function () {
|
|
2849
|
-
controller._pulling = false;
|
|
2850
|
-
if (controller._pullAgain) {
|
|
2851
|
-
controller._pullAgain = false;
|
|
2852
|
-
ReadableStreamDefaultControllerCallPullIfNeeded(controller);
|
|
2853
|
-
}
|
|
2854
|
-
}, function (e) {
|
|
2855
|
-
ReadableStreamDefaultControllerError(controller, e);
|
|
2856
|
-
});
|
|
2857
|
-
}
|
|
2858
|
-
function ReadableStreamDefaultControllerShouldCallPull(controller) {
|
|
2859
|
-
var stream = controller._controlledReadableStream;
|
|
2860
|
-
if (!ReadableStreamDefaultControllerCanCloseOrEnqueue(controller)) {
|
|
2861
|
-
return false;
|
|
2862
|
-
}
|
|
2863
|
-
if (!controller._started) {
|
|
2864
|
-
return false;
|
|
2865
|
-
}
|
|
2866
|
-
if (IsReadableStreamLocked(stream) && ReadableStreamGetNumReadRequests(stream) > 0) {
|
|
2867
|
-
return true;
|
|
2868
|
-
}
|
|
2869
|
-
var desiredSize = ReadableStreamDefaultControllerGetDesiredSize(controller);
|
|
2870
|
-
if (desiredSize > 0) {
|
|
2871
|
-
return true;
|
|
2872
|
-
}
|
|
2873
|
-
return false;
|
|
2874
|
-
}
|
|
2875
|
-
function ReadableStreamDefaultControllerClearAlgorithms(controller) {
|
|
2876
|
-
controller._pullAlgorithm = undefined;
|
|
2877
|
-
controller._cancelAlgorithm = undefined;
|
|
2878
|
-
controller._strategySizeAlgorithm = undefined;
|
|
2879
|
-
}
|
|
2880
|
-
// A client of ReadableStreamDefaultController may use these functions directly to bypass state check.
|
|
2881
|
-
function ReadableStreamDefaultControllerClose(controller) {
|
|
2882
|
-
if (!ReadableStreamDefaultControllerCanCloseOrEnqueue(controller)) {
|
|
2883
|
-
return;
|
|
2884
|
-
}
|
|
2885
|
-
var stream = controller._controlledReadableStream;
|
|
2886
|
-
controller._closeRequested = true;
|
|
2887
|
-
if (controller._queue.length === 0) {
|
|
2888
|
-
ReadableStreamDefaultControllerClearAlgorithms(controller);
|
|
2889
|
-
ReadableStreamClose(stream);
|
|
2890
|
-
}
|
|
2891
|
-
}
|
|
2892
|
-
function ReadableStreamDefaultControllerEnqueue(controller, chunk) {
|
|
2893
|
-
if (!ReadableStreamDefaultControllerCanCloseOrEnqueue(controller)) {
|
|
2894
|
-
return;
|
|
2895
|
-
}
|
|
2896
|
-
var stream = controller._controlledReadableStream;
|
|
2897
|
-
if (IsReadableStreamLocked(stream) && ReadableStreamGetNumReadRequests(stream) > 0) {
|
|
2898
|
-
ReadableStreamFulfillReadRequest(stream, chunk, false);
|
|
2899
|
-
}
|
|
2900
|
-
else {
|
|
2901
|
-
var chunkSize = void 0;
|
|
2902
|
-
try {
|
|
2903
|
-
chunkSize = controller._strategySizeAlgorithm(chunk);
|
|
2904
|
-
}
|
|
2905
|
-
catch (chunkSizeE) {
|
|
2906
|
-
ReadableStreamDefaultControllerError(controller, chunkSizeE);
|
|
2907
|
-
throw chunkSizeE;
|
|
2908
|
-
}
|
|
2909
|
-
try {
|
|
2910
|
-
EnqueueValueWithSize(controller, chunk, chunkSize);
|
|
2911
|
-
}
|
|
2912
|
-
catch (enqueueE) {
|
|
2913
|
-
ReadableStreamDefaultControllerError(controller, enqueueE);
|
|
2914
|
-
throw enqueueE;
|
|
2915
|
-
}
|
|
2916
|
-
}
|
|
2917
|
-
ReadableStreamDefaultControllerCallPullIfNeeded(controller);
|
|
2918
|
-
}
|
|
2919
|
-
function ReadableStreamDefaultControllerError(controller, e) {
|
|
2920
|
-
var stream = controller._controlledReadableStream;
|
|
2921
|
-
if (stream._state !== 'readable') {
|
|
2922
|
-
return;
|
|
2923
|
-
}
|
|
2924
|
-
ResetQueue(controller);
|
|
2925
|
-
ReadableStreamDefaultControllerClearAlgorithms(controller);
|
|
2926
|
-
ReadableStreamError(stream, e);
|
|
2927
|
-
}
|
|
2928
|
-
function ReadableStreamDefaultControllerGetDesiredSize(controller) {
|
|
2929
|
-
var state = controller._controlledReadableStream._state;
|
|
2930
|
-
if (state === 'errored') {
|
|
2931
|
-
return null;
|
|
2932
|
-
}
|
|
2933
|
-
if (state === 'closed') {
|
|
2934
|
-
return 0;
|
|
2935
|
-
}
|
|
2936
|
-
return controller._strategyHWM - controller._queueTotalSize;
|
|
2937
|
-
}
|
|
2938
|
-
// This is used in the implementation of TransformStream.
|
|
2939
|
-
function ReadableStreamDefaultControllerHasBackpressure(controller) {
|
|
2940
|
-
if (ReadableStreamDefaultControllerShouldCallPull(controller)) {
|
|
2941
|
-
return false;
|
|
2942
|
-
}
|
|
2943
|
-
return true;
|
|
2944
|
-
}
|
|
2945
|
-
function ReadableStreamDefaultControllerCanCloseOrEnqueue(controller) {
|
|
2946
|
-
var state = controller._controlledReadableStream._state;
|
|
2947
|
-
if (!controller._closeRequested && state === 'readable') {
|
|
2948
|
-
return true;
|
|
2949
|
-
}
|
|
2950
|
-
return false;
|
|
2951
|
-
}
|
|
2952
|
-
function SetUpReadableStreamDefaultController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, sizeAlgorithm) {
|
|
2953
|
-
controller._controlledReadableStream = stream;
|
|
2954
|
-
controller._queue = undefined;
|
|
2955
|
-
controller._queueTotalSize = undefined;
|
|
2956
|
-
ResetQueue(controller);
|
|
2957
|
-
controller._started = false;
|
|
2958
|
-
controller._closeRequested = false;
|
|
2959
|
-
controller._pullAgain = false;
|
|
2960
|
-
controller._pulling = false;
|
|
2961
|
-
controller._strategySizeAlgorithm = sizeAlgorithm;
|
|
2962
|
-
controller._strategyHWM = highWaterMark;
|
|
2963
|
-
controller._pullAlgorithm = pullAlgorithm;
|
|
2964
|
-
controller._cancelAlgorithm = cancelAlgorithm;
|
|
2965
|
-
stream._readableStreamController = controller;
|
|
2966
|
-
var startResult = startAlgorithm();
|
|
2967
|
-
uponPromise(promiseResolvedWith(startResult), function () {
|
|
2968
|
-
controller._started = true;
|
|
2969
|
-
ReadableStreamDefaultControllerCallPullIfNeeded(controller);
|
|
2970
|
-
}, function (r) {
|
|
2971
|
-
ReadableStreamDefaultControllerError(controller, r);
|
|
2972
|
-
});
|
|
2973
|
-
}
|
|
2974
|
-
function SetUpReadableStreamDefaultControllerFromUnderlyingSource(stream, underlyingSource, highWaterMark, sizeAlgorithm) {
|
|
2975
|
-
var controller = Object.create(ReadableStreamDefaultController.prototype);
|
|
2976
|
-
var startAlgorithm = function () { return undefined; };
|
|
2977
|
-
var pullAlgorithm = function () { return promiseResolvedWith(undefined); };
|
|
2978
|
-
var cancelAlgorithm = function () { return promiseResolvedWith(undefined); };
|
|
2979
|
-
if (underlyingSource.start !== undefined) {
|
|
2980
|
-
startAlgorithm = function () { return underlyingSource.start(controller); };
|
|
2981
|
-
}
|
|
2982
|
-
if (underlyingSource.pull !== undefined) {
|
|
2983
|
-
pullAlgorithm = function () { return underlyingSource.pull(controller); };
|
|
2984
|
-
}
|
|
2985
|
-
if (underlyingSource.cancel !== undefined) {
|
|
2986
|
-
cancelAlgorithm = function (reason) { return underlyingSource.cancel(reason); };
|
|
2987
|
-
}
|
|
2988
|
-
SetUpReadableStreamDefaultController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, sizeAlgorithm);
|
|
2989
|
-
}
|
|
2990
|
-
// Helper functions for the ReadableStreamDefaultController.
|
|
2991
|
-
function defaultControllerBrandCheckException$1(name) {
|
|
2992
|
-
return new TypeError("ReadableStreamDefaultController.prototype." + name + " can only be used on a ReadableStreamDefaultController");
|
|
2993
|
-
}
|
|
2994
|
-
|
|
2995
|
-
function ReadableStreamTee(stream, cloneForBranch2) {
|
|
2996
|
-
var reader = AcquireReadableStreamDefaultReader(stream);
|
|
2997
|
-
var reading = false;
|
|
2998
|
-
var canceled1 = false;
|
|
2999
|
-
var canceled2 = false;
|
|
3000
|
-
var reason1;
|
|
3001
|
-
var reason2;
|
|
3002
|
-
var branch1;
|
|
3003
|
-
var branch2;
|
|
3004
|
-
var resolveCancelPromise;
|
|
3005
|
-
var cancelPromise = newPromise(function (resolve) {
|
|
3006
|
-
resolveCancelPromise = resolve;
|
|
3007
|
-
});
|
|
3008
|
-
function pullAlgorithm() {
|
|
3009
|
-
if (reading) {
|
|
3010
|
-
return promiseResolvedWith(undefined);
|
|
3011
|
-
}
|
|
3012
|
-
reading = true;
|
|
3013
|
-
var readRequest = {
|
|
3014
|
-
_chunkSteps: function (value) {
|
|
3015
|
-
// This needs to be delayed a microtask because it takes at least a microtask to detect errors (using
|
|
3016
|
-
// reader._closedPromise below), and we want errors in stream to error both branches immediately. We cannot let
|
|
3017
|
-
// successful synchronously-available reads get ahead of asynchronously-available errors.
|
|
3018
|
-
queueMicrotask(function () {
|
|
3019
|
-
reading = false;
|
|
3020
|
-
var value1 = value;
|
|
3021
|
-
var value2 = value;
|
|
3022
|
-
// There is no way to access the cloning code right now in the reference implementation.
|
|
3023
|
-
// If we add one then we'll need an implementation for serializable objects.
|
|
3024
|
-
// if (!canceled2 && cloneForBranch2) {
|
|
3025
|
-
// value2 = StructuredDeserialize(StructuredSerialize(value2));
|
|
3026
|
-
// }
|
|
3027
|
-
if (!canceled1) {
|
|
3028
|
-
ReadableStreamDefaultControllerEnqueue(branch1._readableStreamController, value1);
|
|
3029
|
-
}
|
|
3030
|
-
if (!canceled2) {
|
|
3031
|
-
ReadableStreamDefaultControllerEnqueue(branch2._readableStreamController, value2);
|
|
3032
|
-
}
|
|
3033
|
-
});
|
|
3034
|
-
},
|
|
3035
|
-
_closeSteps: function () {
|
|
3036
|
-
reading = false;
|
|
3037
|
-
if (!canceled1) {
|
|
3038
|
-
ReadableStreamDefaultControllerClose(branch1._readableStreamController);
|
|
3039
|
-
}
|
|
3040
|
-
if (!canceled2) {
|
|
3041
|
-
ReadableStreamDefaultControllerClose(branch2._readableStreamController);
|
|
3042
|
-
}
|
|
3043
|
-
if (!canceled1 || !canceled2) {
|
|
3044
|
-
resolveCancelPromise(undefined);
|
|
3045
|
-
}
|
|
3046
|
-
},
|
|
3047
|
-
_errorSteps: function () {
|
|
3048
|
-
reading = false;
|
|
3049
|
-
}
|
|
3050
|
-
};
|
|
3051
|
-
ReadableStreamDefaultReaderRead(reader, readRequest);
|
|
3052
|
-
return promiseResolvedWith(undefined);
|
|
3053
|
-
}
|
|
3054
|
-
function cancel1Algorithm(reason) {
|
|
3055
|
-
canceled1 = true;
|
|
3056
|
-
reason1 = reason;
|
|
3057
|
-
if (canceled2) {
|
|
3058
|
-
var compositeReason = CreateArrayFromList([reason1, reason2]);
|
|
3059
|
-
var cancelResult = ReadableStreamCancel(stream, compositeReason);
|
|
3060
|
-
resolveCancelPromise(cancelResult);
|
|
3061
|
-
}
|
|
3062
|
-
return cancelPromise;
|
|
3063
|
-
}
|
|
3064
|
-
function cancel2Algorithm(reason) {
|
|
3065
|
-
canceled2 = true;
|
|
3066
|
-
reason2 = reason;
|
|
3067
|
-
if (canceled1) {
|
|
3068
|
-
var compositeReason = CreateArrayFromList([reason1, reason2]);
|
|
3069
|
-
var cancelResult = ReadableStreamCancel(stream, compositeReason);
|
|
3070
|
-
resolveCancelPromise(cancelResult);
|
|
3071
|
-
}
|
|
3072
|
-
return cancelPromise;
|
|
3073
|
-
}
|
|
3074
|
-
function startAlgorithm() {
|
|
3075
|
-
// do nothing
|
|
3076
|
-
}
|
|
3077
|
-
branch1 = CreateReadableStream(startAlgorithm, pullAlgorithm, cancel1Algorithm);
|
|
3078
|
-
branch2 = CreateReadableStream(startAlgorithm, pullAlgorithm, cancel2Algorithm);
|
|
3079
|
-
uponRejection(reader._closedPromise, function (r) {
|
|
3080
|
-
ReadableStreamDefaultControllerError(branch1._readableStreamController, r);
|
|
3081
|
-
ReadableStreamDefaultControllerError(branch2._readableStreamController, r);
|
|
3082
|
-
if (!canceled1 || !canceled2) {
|
|
3083
|
-
resolveCancelPromise(undefined);
|
|
3084
|
-
}
|
|
3085
|
-
});
|
|
3086
|
-
return [branch1, branch2];
|
|
3087
|
-
}
|
|
3088
|
-
|
|
3089
|
-
function convertUnderlyingDefaultOrByteSource(source, context) {
|
|
3090
|
-
assertDictionary(source, context);
|
|
3091
|
-
var original = source;
|
|
3092
|
-
var autoAllocateChunkSize = original === null || original === void 0 ? void 0 : original.autoAllocateChunkSize;
|
|
3093
|
-
var cancel = original === null || original === void 0 ? void 0 : original.cancel;
|
|
3094
|
-
var pull = original === null || original === void 0 ? void 0 : original.pull;
|
|
3095
|
-
var start = original === null || original === void 0 ? void 0 : original.start;
|
|
3096
|
-
var type = original === null || original === void 0 ? void 0 : original.type;
|
|
3097
|
-
return {
|
|
3098
|
-
autoAllocateChunkSize: autoAllocateChunkSize === undefined ?
|
|
3099
|
-
undefined :
|
|
3100
|
-
convertUnsignedLongLongWithEnforceRange(autoAllocateChunkSize, context + " has member 'autoAllocateChunkSize' that"),
|
|
3101
|
-
cancel: cancel === undefined ?
|
|
3102
|
-
undefined :
|
|
3103
|
-
convertUnderlyingSourceCancelCallback(cancel, original, context + " has member 'cancel' that"),
|
|
3104
|
-
pull: pull === undefined ?
|
|
3105
|
-
undefined :
|
|
3106
|
-
convertUnderlyingSourcePullCallback(pull, original, context + " has member 'pull' that"),
|
|
3107
|
-
start: start === undefined ?
|
|
3108
|
-
undefined :
|
|
3109
|
-
convertUnderlyingSourceStartCallback(start, original, context + " has member 'start' that"),
|
|
3110
|
-
type: type === undefined ? undefined : convertReadableStreamType(type, context + " has member 'type' that")
|
|
3111
|
-
};
|
|
3112
|
-
}
|
|
3113
|
-
function convertUnderlyingSourceCancelCallback(fn, original, context) {
|
|
3114
|
-
assertFunction(fn, context);
|
|
3115
|
-
return function (reason) { return promiseCall(fn, original, [reason]); };
|
|
3116
|
-
}
|
|
3117
|
-
function convertUnderlyingSourcePullCallback(fn, original, context) {
|
|
3118
|
-
assertFunction(fn, context);
|
|
3119
|
-
return function (controller) { return promiseCall(fn, original, [controller]); };
|
|
3120
|
-
}
|
|
3121
|
-
function convertUnderlyingSourceStartCallback(fn, original, context) {
|
|
3122
|
-
assertFunction(fn, context);
|
|
3123
|
-
return function (controller) { return reflectCall(fn, original, [controller]); };
|
|
3124
|
-
}
|
|
3125
|
-
function convertReadableStreamType(type, context) {
|
|
3126
|
-
type = "" + type;
|
|
3127
|
-
if (type !== 'bytes') {
|
|
3128
|
-
throw new TypeError(context + " '" + type + "' is not a valid enumeration value for ReadableStreamType");
|
|
3129
|
-
}
|
|
3130
|
-
return type;
|
|
3131
|
-
}
|
|
3132
|
-
|
|
3133
|
-
function convertReaderOptions(options, context) {
|
|
3134
|
-
assertDictionary(options, context);
|
|
3135
|
-
var mode = options === null || options === void 0 ? void 0 : options.mode;
|
|
3136
|
-
return {
|
|
3137
|
-
mode: mode === undefined ? undefined : convertReadableStreamReaderMode(mode, context + " has member 'mode' that")
|
|
3138
|
-
};
|
|
3139
|
-
}
|
|
3140
|
-
function convertReadableStreamReaderMode(mode, context) {
|
|
3141
|
-
mode = "" + mode;
|
|
3142
|
-
if (mode !== 'byob') {
|
|
3143
|
-
throw new TypeError(context + " '" + mode + "' is not a valid enumeration value for ReadableStreamReaderMode");
|
|
3144
|
-
}
|
|
3145
|
-
return mode;
|
|
3146
|
-
}
|
|
3147
|
-
|
|
3148
|
-
function convertIteratorOptions(options, context) {
|
|
3149
|
-
assertDictionary(options, context);
|
|
3150
|
-
var preventCancel = options === null || options === void 0 ? void 0 : options.preventCancel;
|
|
3151
|
-
return { preventCancel: Boolean(preventCancel) };
|
|
3152
|
-
}
|
|
3153
|
-
|
|
3154
|
-
function convertPipeOptions(options, context) {
|
|
3155
|
-
assertDictionary(options, context);
|
|
3156
|
-
var preventAbort = options === null || options === void 0 ? void 0 : options.preventAbort;
|
|
3157
|
-
var preventCancel = options === null || options === void 0 ? void 0 : options.preventCancel;
|
|
3158
|
-
var preventClose = options === null || options === void 0 ? void 0 : options.preventClose;
|
|
3159
|
-
var signal = options === null || options === void 0 ? void 0 : options.signal;
|
|
3160
|
-
if (signal !== undefined) {
|
|
3161
|
-
assertAbortSignal(signal, context + " has member 'signal' that");
|
|
3162
|
-
}
|
|
3163
|
-
return {
|
|
3164
|
-
preventAbort: Boolean(preventAbort),
|
|
3165
|
-
preventCancel: Boolean(preventCancel),
|
|
3166
|
-
preventClose: Boolean(preventClose),
|
|
3167
|
-
signal: signal
|
|
3168
|
-
};
|
|
3169
|
-
}
|
|
3170
|
-
function assertAbortSignal(signal, context) {
|
|
3171
|
-
if (!isAbortSignal(signal)) {
|
|
3172
|
-
throw new TypeError(context + " is not an AbortSignal.");
|
|
3173
|
-
}
|
|
3174
|
-
}
|
|
3175
|
-
|
|
3176
|
-
function convertReadableWritablePair(pair, context) {
|
|
3177
|
-
assertDictionary(pair, context);
|
|
3178
|
-
var readable = pair === null || pair === void 0 ? void 0 : pair.readable;
|
|
3179
|
-
assertRequiredField(readable, 'readable', 'ReadableWritablePair');
|
|
3180
|
-
assertReadableStream(readable, context + " has member 'readable' that");
|
|
3181
|
-
var writable = pair === null || pair === void 0 ? void 0 : pair.writable;
|
|
3182
|
-
assertRequiredField(writable, 'writable', 'ReadableWritablePair');
|
|
3183
|
-
assertWritableStream(writable, context + " has member 'writable' that");
|
|
3184
|
-
return { readable: readable, writable: writable };
|
|
3185
|
-
}
|
|
3186
|
-
|
|
3187
|
-
/**
|
|
3188
|
-
* A readable stream represents a source of data, from which you can read.
|
|
3189
|
-
*
|
|
3190
|
-
* @public
|
|
3191
|
-
*/
|
|
3192
|
-
var ReadableStream = /** @class */ (function () {
|
|
3193
|
-
function ReadableStream(rawUnderlyingSource, rawStrategy) {
|
|
3194
|
-
if (rawUnderlyingSource === void 0) { rawUnderlyingSource = {}; }
|
|
3195
|
-
if (rawStrategy === void 0) { rawStrategy = {}; }
|
|
3196
|
-
if (rawUnderlyingSource === undefined) {
|
|
3197
|
-
rawUnderlyingSource = null;
|
|
3198
|
-
}
|
|
3199
|
-
else {
|
|
3200
|
-
assertObject(rawUnderlyingSource, 'First parameter');
|
|
3201
|
-
}
|
|
3202
|
-
var strategy = convertQueuingStrategy(rawStrategy, 'Second parameter');
|
|
3203
|
-
var underlyingSource = convertUnderlyingDefaultOrByteSource(rawUnderlyingSource, 'First parameter');
|
|
3204
|
-
InitializeReadableStream(this);
|
|
3205
|
-
if (underlyingSource.type === 'bytes') {
|
|
3206
|
-
if (strategy.size !== undefined) {
|
|
3207
|
-
throw new RangeError('The strategy for a byte stream cannot have a size function');
|
|
3208
|
-
}
|
|
3209
|
-
var highWaterMark = ExtractHighWaterMark(strategy, 0);
|
|
3210
|
-
SetUpReadableByteStreamControllerFromUnderlyingSource(this, underlyingSource, highWaterMark);
|
|
3211
|
-
}
|
|
3212
|
-
else {
|
|
3213
|
-
var sizeAlgorithm = ExtractSizeAlgorithm(strategy);
|
|
3214
|
-
var highWaterMark = ExtractHighWaterMark(strategy, 1);
|
|
3215
|
-
SetUpReadableStreamDefaultControllerFromUnderlyingSource(this, underlyingSource, highWaterMark, sizeAlgorithm);
|
|
3216
|
-
}
|
|
3217
|
-
}
|
|
3218
|
-
Object.defineProperty(ReadableStream.prototype, "locked", {
|
|
3219
|
-
/**
|
|
3220
|
-
* Whether or not the readable stream is locked to a {@link ReadableStreamDefaultReader | reader}.
|
|
3221
|
-
*/
|
|
3222
|
-
get: function () {
|
|
3223
|
-
if (!IsReadableStream(this)) {
|
|
3224
|
-
throw streamBrandCheckException$1('locked');
|
|
3225
|
-
}
|
|
3226
|
-
return IsReadableStreamLocked(this);
|
|
3227
|
-
},
|
|
3228
|
-
enumerable: false,
|
|
3229
|
-
configurable: true
|
|
3230
|
-
});
|
|
3231
|
-
/**
|
|
3232
|
-
* Cancels the stream, signaling a loss of interest in the stream by a consumer.
|
|
3233
|
-
*
|
|
3234
|
-
* The supplied `reason` argument will be given to the underlying source's {@link UnderlyingSource.cancel | cancel()}
|
|
3235
|
-
* method, which might or might not use it.
|
|
3236
|
-
*/
|
|
3237
|
-
ReadableStream.prototype.cancel = function (reason) {
|
|
3238
|
-
if (reason === void 0) { reason = undefined; }
|
|
3239
|
-
if (!IsReadableStream(this)) {
|
|
3240
|
-
return promiseRejectedWith(streamBrandCheckException$1('cancel'));
|
|
3241
|
-
}
|
|
3242
|
-
if (IsReadableStreamLocked(this)) {
|
|
3243
|
-
return promiseRejectedWith(new TypeError('Cannot cancel a stream that already has a reader'));
|
|
3244
|
-
}
|
|
3245
|
-
return ReadableStreamCancel(this, reason);
|
|
3246
|
-
};
|
|
3247
|
-
ReadableStream.prototype.getReader = function (rawOptions) {
|
|
3248
|
-
if (rawOptions === void 0) { rawOptions = undefined; }
|
|
3249
|
-
if (!IsReadableStream(this)) {
|
|
3250
|
-
throw streamBrandCheckException$1('getReader');
|
|
3251
|
-
}
|
|
3252
|
-
var options = convertReaderOptions(rawOptions, 'First parameter');
|
|
3253
|
-
if (options.mode === undefined) {
|
|
3254
|
-
return AcquireReadableStreamDefaultReader(this);
|
|
3255
|
-
}
|
|
3256
|
-
return AcquireReadableStreamBYOBReader(this);
|
|
3257
|
-
};
|
|
3258
|
-
ReadableStream.prototype.pipeThrough = function (rawTransform, rawOptions) {
|
|
3259
|
-
if (rawOptions === void 0) { rawOptions = {}; }
|
|
3260
|
-
if (!IsReadableStream(this)) {
|
|
3261
|
-
throw streamBrandCheckException$1('pipeThrough');
|
|
3262
|
-
}
|
|
3263
|
-
assertRequiredArgument(rawTransform, 1, 'pipeThrough');
|
|
3264
|
-
var transform = convertReadableWritablePair(rawTransform, 'First parameter');
|
|
3265
|
-
var options = convertPipeOptions(rawOptions, 'Second parameter');
|
|
3266
|
-
if (IsReadableStreamLocked(this)) {
|
|
3267
|
-
throw new TypeError('ReadableStream.prototype.pipeThrough cannot be used on a locked ReadableStream');
|
|
3268
|
-
}
|
|
3269
|
-
if (IsWritableStreamLocked(transform.writable)) {
|
|
3270
|
-
throw new TypeError('ReadableStream.prototype.pipeThrough cannot be used on a locked WritableStream');
|
|
3271
|
-
}
|
|
3272
|
-
var promise = ReadableStreamPipeTo(this, transform.writable, options.preventClose, options.preventAbort, options.preventCancel, options.signal);
|
|
3273
|
-
setPromiseIsHandledToTrue(promise);
|
|
3274
|
-
return transform.readable;
|
|
3275
|
-
};
|
|
3276
|
-
ReadableStream.prototype.pipeTo = function (destination, rawOptions) {
|
|
3277
|
-
if (rawOptions === void 0) { rawOptions = {}; }
|
|
3278
|
-
if (!IsReadableStream(this)) {
|
|
3279
|
-
return promiseRejectedWith(streamBrandCheckException$1('pipeTo'));
|
|
3280
|
-
}
|
|
3281
|
-
if (destination === undefined) {
|
|
3282
|
-
return promiseRejectedWith("Parameter 1 is required in 'pipeTo'.");
|
|
3283
|
-
}
|
|
3284
|
-
if (!IsWritableStream(destination)) {
|
|
3285
|
-
return promiseRejectedWith(new TypeError("ReadableStream.prototype.pipeTo's first argument must be a WritableStream"));
|
|
3286
|
-
}
|
|
3287
|
-
var options;
|
|
3288
|
-
try {
|
|
3289
|
-
options = convertPipeOptions(rawOptions, 'Second parameter');
|
|
3290
|
-
}
|
|
3291
|
-
catch (e) {
|
|
3292
|
-
return promiseRejectedWith(e);
|
|
3293
|
-
}
|
|
3294
|
-
if (IsReadableStreamLocked(this)) {
|
|
3295
|
-
return promiseRejectedWith(new TypeError('ReadableStream.prototype.pipeTo cannot be used on a locked ReadableStream'));
|
|
3296
|
-
}
|
|
3297
|
-
if (IsWritableStreamLocked(destination)) {
|
|
3298
|
-
return promiseRejectedWith(new TypeError('ReadableStream.prototype.pipeTo cannot be used on a locked WritableStream'));
|
|
3299
|
-
}
|
|
3300
|
-
return ReadableStreamPipeTo(this, destination, options.preventClose, options.preventAbort, options.preventCancel, options.signal);
|
|
3301
|
-
};
|
|
3302
|
-
/**
|
|
3303
|
-
* Tees this readable stream, returning a two-element array containing the two resulting branches as
|
|
3304
|
-
* new {@link ReadableStream} instances.
|
|
3305
|
-
*
|
|
3306
|
-
* Teeing a stream will lock it, preventing any other consumer from acquiring a reader.
|
|
3307
|
-
* To cancel the stream, cancel both of the resulting branches; a composite cancellation reason will then be
|
|
3308
|
-
* propagated to the stream's underlying source.
|
|
3309
|
-
*
|
|
3310
|
-
* Note that the chunks seen in each branch will be the same object. If the chunks are not immutable,
|
|
3311
|
-
* this could allow interference between the two branches.
|
|
3312
|
-
*/
|
|
3313
|
-
ReadableStream.prototype.tee = function () {
|
|
3314
|
-
if (!IsReadableStream(this)) {
|
|
3315
|
-
throw streamBrandCheckException$1('tee');
|
|
3316
|
-
}
|
|
3317
|
-
var branches = ReadableStreamTee(this);
|
|
3318
|
-
return CreateArrayFromList(branches);
|
|
3319
|
-
};
|
|
3320
|
-
ReadableStream.prototype.values = function (rawOptions) {
|
|
3321
|
-
if (rawOptions === void 0) { rawOptions = undefined; }
|
|
3322
|
-
if (!IsReadableStream(this)) {
|
|
3323
|
-
throw streamBrandCheckException$1('values');
|
|
3324
|
-
}
|
|
3325
|
-
var options = convertIteratorOptions(rawOptions, 'First parameter');
|
|
3326
|
-
return AcquireReadableStreamAsyncIterator(this, options.preventCancel);
|
|
3327
|
-
};
|
|
3328
|
-
return ReadableStream;
|
|
3329
|
-
}());
|
|
3330
|
-
Object.defineProperties(ReadableStream.prototype, {
|
|
3331
|
-
cancel: { enumerable: true },
|
|
3332
|
-
getReader: { enumerable: true },
|
|
3333
|
-
pipeThrough: { enumerable: true },
|
|
3334
|
-
pipeTo: { enumerable: true },
|
|
3335
|
-
tee: { enumerable: true },
|
|
3336
|
-
values: { enumerable: true },
|
|
3337
|
-
locked: { enumerable: true }
|
|
3338
|
-
});
|
|
3339
|
-
if (typeof SymbolPolyfill.toStringTag === 'symbol') {
|
|
3340
|
-
Object.defineProperty(ReadableStream.prototype, SymbolPolyfill.toStringTag, {
|
|
3341
|
-
value: 'ReadableStream',
|
|
3342
|
-
configurable: true
|
|
3343
|
-
});
|
|
3344
|
-
}
|
|
3345
|
-
if (typeof SymbolPolyfill.asyncIterator === 'symbol') {
|
|
3346
|
-
Object.defineProperty(ReadableStream.prototype, SymbolPolyfill.asyncIterator, {
|
|
3347
|
-
value: ReadableStream.prototype.values,
|
|
3348
|
-
writable: true,
|
|
3349
|
-
configurable: true
|
|
3350
|
-
});
|
|
3351
|
-
}
|
|
3352
|
-
// Abstract operations for the ReadableStream.
|
|
3353
|
-
// Throws if and only if startAlgorithm throws.
|
|
3354
|
-
function CreateReadableStream(startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, sizeAlgorithm) {
|
|
3355
|
-
if (highWaterMark === void 0) { highWaterMark = 1; }
|
|
3356
|
-
if (sizeAlgorithm === void 0) { sizeAlgorithm = function () { return 1; }; }
|
|
3357
|
-
var stream = Object.create(ReadableStream.prototype);
|
|
3358
|
-
InitializeReadableStream(stream);
|
|
3359
|
-
var controller = Object.create(ReadableStreamDefaultController.prototype);
|
|
3360
|
-
SetUpReadableStreamDefaultController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, sizeAlgorithm);
|
|
3361
|
-
return stream;
|
|
3362
|
-
}
|
|
3363
|
-
function InitializeReadableStream(stream) {
|
|
3364
|
-
stream._state = 'readable';
|
|
3365
|
-
stream._reader = undefined;
|
|
3366
|
-
stream._storedError = undefined;
|
|
3367
|
-
stream._disturbed = false;
|
|
3368
|
-
}
|
|
3369
|
-
function IsReadableStream(x) {
|
|
3370
|
-
if (!typeIsObject(x)) {
|
|
3371
|
-
return false;
|
|
3372
|
-
}
|
|
3373
|
-
if (!Object.prototype.hasOwnProperty.call(x, '_readableStreamController')) {
|
|
3374
|
-
return false;
|
|
3375
|
-
}
|
|
3376
|
-
return true;
|
|
3377
|
-
}
|
|
3378
|
-
function IsReadableStreamLocked(stream) {
|
|
3379
|
-
if (stream._reader === undefined) {
|
|
3380
|
-
return false;
|
|
3381
|
-
}
|
|
3382
|
-
return true;
|
|
3383
|
-
}
|
|
3384
|
-
// ReadableStream API exposed for controllers.
|
|
3385
|
-
function ReadableStreamCancel(stream, reason) {
|
|
3386
|
-
stream._disturbed = true;
|
|
3387
|
-
if (stream._state === 'closed') {
|
|
3388
|
-
return promiseResolvedWith(undefined);
|
|
3389
|
-
}
|
|
3390
|
-
if (stream._state === 'errored') {
|
|
3391
|
-
return promiseRejectedWith(stream._storedError);
|
|
3392
|
-
}
|
|
3393
|
-
ReadableStreamClose(stream);
|
|
3394
|
-
var sourceCancelPromise = stream._readableStreamController[CancelSteps](reason);
|
|
3395
|
-
return transformPromiseWith(sourceCancelPromise, noop);
|
|
3396
|
-
}
|
|
3397
|
-
function ReadableStreamClose(stream) {
|
|
3398
|
-
stream._state = 'closed';
|
|
3399
|
-
var reader = stream._reader;
|
|
3400
|
-
if (reader === undefined) {
|
|
3401
|
-
return;
|
|
3402
|
-
}
|
|
3403
|
-
defaultReaderClosedPromiseResolve(reader);
|
|
3404
|
-
if (IsReadableStreamDefaultReader(reader)) {
|
|
3405
|
-
reader._readRequests.forEach(function (readRequest) {
|
|
3406
|
-
readRequest._closeSteps();
|
|
3407
|
-
});
|
|
3408
|
-
reader._readRequests = new SimpleQueue();
|
|
3409
|
-
}
|
|
3410
|
-
}
|
|
3411
|
-
function ReadableStreamError(stream, e) {
|
|
3412
|
-
stream._state = 'errored';
|
|
3413
|
-
stream._storedError = e;
|
|
3414
|
-
var reader = stream._reader;
|
|
3415
|
-
if (reader === undefined) {
|
|
3416
|
-
return;
|
|
3417
|
-
}
|
|
3418
|
-
defaultReaderClosedPromiseReject(reader, e);
|
|
3419
|
-
if (IsReadableStreamDefaultReader(reader)) {
|
|
3420
|
-
reader._readRequests.forEach(function (readRequest) {
|
|
3421
|
-
readRequest._errorSteps(e);
|
|
3422
|
-
});
|
|
3423
|
-
reader._readRequests = new SimpleQueue();
|
|
3424
|
-
}
|
|
3425
|
-
else {
|
|
3426
|
-
reader._readIntoRequests.forEach(function (readIntoRequest) {
|
|
3427
|
-
readIntoRequest._errorSteps(e);
|
|
3428
|
-
});
|
|
3429
|
-
reader._readIntoRequests = new SimpleQueue();
|
|
3430
|
-
}
|
|
3431
|
-
}
|
|
3432
|
-
// Helper functions for the ReadableStream.
|
|
3433
|
-
function streamBrandCheckException$1(name) {
|
|
3434
|
-
return new TypeError("ReadableStream.prototype." + name + " can only be used on a ReadableStream");
|
|
3435
|
-
}
|
|
3436
|
-
|
|
3437
|
-
function convertQueuingStrategyInit(init, context) {
|
|
3438
|
-
assertDictionary(init, context);
|
|
3439
|
-
var highWaterMark = init === null || init === void 0 ? void 0 : init.highWaterMark;
|
|
3440
|
-
assertRequiredField(highWaterMark, 'highWaterMark', 'QueuingStrategyInit');
|
|
3441
|
-
return {
|
|
3442
|
-
highWaterMark: convertUnrestrictedDouble(highWaterMark)
|
|
3443
|
-
};
|
|
3444
|
-
}
|
|
3445
|
-
|
|
3446
|
-
var byteLengthSizeFunction = function size(chunk) {
|
|
3447
|
-
return chunk.byteLength;
|
|
3448
|
-
};
|
|
3449
|
-
/**
|
|
3450
|
-
* A queuing strategy that counts the number of bytes in each chunk.
|
|
3451
|
-
*
|
|
3452
|
-
* @public
|
|
3453
|
-
*/
|
|
3454
|
-
var ByteLengthQueuingStrategy = /** @class */ (function () {
|
|
3455
|
-
function ByteLengthQueuingStrategy(options) {
|
|
3456
|
-
assertRequiredArgument(options, 1, 'ByteLengthQueuingStrategy');
|
|
3457
|
-
options = convertQueuingStrategyInit(options, 'First parameter');
|
|
3458
|
-
this._byteLengthQueuingStrategyHighWaterMark = options.highWaterMark;
|
|
3459
|
-
}
|
|
3460
|
-
Object.defineProperty(ByteLengthQueuingStrategy.prototype, "highWaterMark", {
|
|
3461
|
-
/**
|
|
3462
|
-
* Returns the high water mark provided to the constructor.
|
|
3463
|
-
*/
|
|
3464
|
-
get: function () {
|
|
3465
|
-
if (!IsByteLengthQueuingStrategy(this)) {
|
|
3466
|
-
throw byteLengthBrandCheckException('highWaterMark');
|
|
3467
|
-
}
|
|
3468
|
-
return this._byteLengthQueuingStrategyHighWaterMark;
|
|
3469
|
-
},
|
|
3470
|
-
enumerable: false,
|
|
3471
|
-
configurable: true
|
|
3472
|
-
});
|
|
3473
|
-
Object.defineProperty(ByteLengthQueuingStrategy.prototype, "size", {
|
|
3474
|
-
/**
|
|
3475
|
-
* Measures the size of `chunk` by returning the value of its `byteLength` property.
|
|
3476
|
-
*/
|
|
3477
|
-
get: function () {
|
|
3478
|
-
if (!IsByteLengthQueuingStrategy(this)) {
|
|
3479
|
-
throw byteLengthBrandCheckException('size');
|
|
3480
|
-
}
|
|
3481
|
-
return byteLengthSizeFunction;
|
|
3482
|
-
},
|
|
3483
|
-
enumerable: false,
|
|
3484
|
-
configurable: true
|
|
3485
|
-
});
|
|
3486
|
-
return ByteLengthQueuingStrategy;
|
|
3487
|
-
}());
|
|
3488
|
-
Object.defineProperties(ByteLengthQueuingStrategy.prototype, {
|
|
3489
|
-
highWaterMark: { enumerable: true },
|
|
3490
|
-
size: { enumerable: true }
|
|
3491
|
-
});
|
|
3492
|
-
if (typeof SymbolPolyfill.toStringTag === 'symbol') {
|
|
3493
|
-
Object.defineProperty(ByteLengthQueuingStrategy.prototype, SymbolPolyfill.toStringTag, {
|
|
3494
|
-
value: 'ByteLengthQueuingStrategy',
|
|
3495
|
-
configurable: true
|
|
3496
|
-
});
|
|
3497
|
-
}
|
|
3498
|
-
// Helper functions for the ByteLengthQueuingStrategy.
|
|
3499
|
-
function byteLengthBrandCheckException(name) {
|
|
3500
|
-
return new TypeError("ByteLengthQueuingStrategy.prototype." + name + " can only be used on a ByteLengthQueuingStrategy");
|
|
3501
|
-
}
|
|
3502
|
-
function IsByteLengthQueuingStrategy(x) {
|
|
3503
|
-
if (!typeIsObject(x)) {
|
|
3504
|
-
return false;
|
|
3505
|
-
}
|
|
3506
|
-
if (!Object.prototype.hasOwnProperty.call(x, '_byteLengthQueuingStrategyHighWaterMark')) {
|
|
3507
|
-
return false;
|
|
3508
|
-
}
|
|
3509
|
-
return true;
|
|
3510
|
-
}
|
|
3511
|
-
|
|
3512
|
-
var countSizeFunction = function size() {
|
|
3513
|
-
return 1;
|
|
3514
|
-
};
|
|
3515
|
-
/**
|
|
3516
|
-
* A queuing strategy that counts the number of chunks.
|
|
3517
|
-
*
|
|
3518
|
-
* @public
|
|
3519
|
-
*/
|
|
3520
|
-
var CountQueuingStrategy = /** @class */ (function () {
|
|
3521
|
-
function CountQueuingStrategy(options) {
|
|
3522
|
-
assertRequiredArgument(options, 1, 'CountQueuingStrategy');
|
|
3523
|
-
options = convertQueuingStrategyInit(options, 'First parameter');
|
|
3524
|
-
this._countQueuingStrategyHighWaterMark = options.highWaterMark;
|
|
3525
|
-
}
|
|
3526
|
-
Object.defineProperty(CountQueuingStrategy.prototype, "highWaterMark", {
|
|
3527
|
-
/**
|
|
3528
|
-
* Returns the high water mark provided to the constructor.
|
|
3529
|
-
*/
|
|
3530
|
-
get: function () {
|
|
3531
|
-
if (!IsCountQueuingStrategy(this)) {
|
|
3532
|
-
throw countBrandCheckException('highWaterMark');
|
|
3533
|
-
}
|
|
3534
|
-
return this._countQueuingStrategyHighWaterMark;
|
|
3535
|
-
},
|
|
3536
|
-
enumerable: false,
|
|
3537
|
-
configurable: true
|
|
3538
|
-
});
|
|
3539
|
-
Object.defineProperty(CountQueuingStrategy.prototype, "size", {
|
|
3540
|
-
/**
|
|
3541
|
-
* Measures the size of `chunk` by always returning 1.
|
|
3542
|
-
* This ensures that the total queue size is a count of the number of chunks in the queue.
|
|
3543
|
-
*/
|
|
3544
|
-
get: function () {
|
|
3545
|
-
if (!IsCountQueuingStrategy(this)) {
|
|
3546
|
-
throw countBrandCheckException('size');
|
|
3547
|
-
}
|
|
3548
|
-
return countSizeFunction;
|
|
3549
|
-
},
|
|
3550
|
-
enumerable: false,
|
|
3551
|
-
configurable: true
|
|
3552
|
-
});
|
|
3553
|
-
return CountQueuingStrategy;
|
|
3554
|
-
}());
|
|
3555
|
-
Object.defineProperties(CountQueuingStrategy.prototype, {
|
|
3556
|
-
highWaterMark: { enumerable: true },
|
|
3557
|
-
size: { enumerable: true }
|
|
3558
|
-
});
|
|
3559
|
-
if (typeof SymbolPolyfill.toStringTag === 'symbol') {
|
|
3560
|
-
Object.defineProperty(CountQueuingStrategy.prototype, SymbolPolyfill.toStringTag, {
|
|
3561
|
-
value: 'CountQueuingStrategy',
|
|
3562
|
-
configurable: true
|
|
3563
|
-
});
|
|
3564
|
-
}
|
|
3565
|
-
// Helper functions for the CountQueuingStrategy.
|
|
3566
|
-
function countBrandCheckException(name) {
|
|
3567
|
-
return new TypeError("CountQueuingStrategy.prototype." + name + " can only be used on a CountQueuingStrategy");
|
|
3568
|
-
}
|
|
3569
|
-
function IsCountQueuingStrategy(x) {
|
|
3570
|
-
if (!typeIsObject(x)) {
|
|
3571
|
-
return false;
|
|
3572
|
-
}
|
|
3573
|
-
if (!Object.prototype.hasOwnProperty.call(x, '_countQueuingStrategyHighWaterMark')) {
|
|
3574
|
-
return false;
|
|
3575
|
-
}
|
|
3576
|
-
return true;
|
|
3577
|
-
}
|
|
3578
|
-
|
|
3579
|
-
function convertTransformer(original, context) {
|
|
3580
|
-
assertDictionary(original, context);
|
|
3581
|
-
var flush = original === null || original === void 0 ? void 0 : original.flush;
|
|
3582
|
-
var readableType = original === null || original === void 0 ? void 0 : original.readableType;
|
|
3583
|
-
var start = original === null || original === void 0 ? void 0 : original.start;
|
|
3584
|
-
var transform = original === null || original === void 0 ? void 0 : original.transform;
|
|
3585
|
-
var writableType = original === null || original === void 0 ? void 0 : original.writableType;
|
|
3586
|
-
return {
|
|
3587
|
-
flush: flush === undefined ?
|
|
3588
|
-
undefined :
|
|
3589
|
-
convertTransformerFlushCallback(flush, original, context + " has member 'flush' that"),
|
|
3590
|
-
readableType: readableType,
|
|
3591
|
-
start: start === undefined ?
|
|
3592
|
-
undefined :
|
|
3593
|
-
convertTransformerStartCallback(start, original, context + " has member 'start' that"),
|
|
3594
|
-
transform: transform === undefined ?
|
|
3595
|
-
undefined :
|
|
3596
|
-
convertTransformerTransformCallback(transform, original, context + " has member 'transform' that"),
|
|
3597
|
-
writableType: writableType
|
|
3598
|
-
};
|
|
3599
|
-
}
|
|
3600
|
-
function convertTransformerFlushCallback(fn, original, context) {
|
|
3601
|
-
assertFunction(fn, context);
|
|
3602
|
-
return function (controller) { return promiseCall(fn, original, [controller]); };
|
|
3603
|
-
}
|
|
3604
|
-
function convertTransformerStartCallback(fn, original, context) {
|
|
3605
|
-
assertFunction(fn, context);
|
|
3606
|
-
return function (controller) { return reflectCall(fn, original, [controller]); };
|
|
3607
|
-
}
|
|
3608
|
-
function convertTransformerTransformCallback(fn, original, context) {
|
|
3609
|
-
assertFunction(fn, context);
|
|
3610
|
-
return function (chunk, controller) { return promiseCall(fn, original, [chunk, controller]); };
|
|
3611
|
-
}
|
|
3612
|
-
|
|
3613
|
-
// Class TransformStream
|
|
3614
|
-
/**
|
|
3615
|
-
* A transform stream consists of a pair of streams: a {@link WritableStream | writable stream},
|
|
3616
|
-
* known as its writable side, and a {@link ReadableStream | readable stream}, known as its readable side.
|
|
3617
|
-
* In a manner specific to the transform stream in question, writes to the writable side result in new data being
|
|
3618
|
-
* made available for reading from the readable side.
|
|
3619
|
-
*
|
|
3620
|
-
* @public
|
|
3621
|
-
*/
|
|
3622
|
-
var TransformStream = /** @class */ (function () {
|
|
3623
|
-
function TransformStream(rawTransformer, rawWritableStrategy, rawReadableStrategy) {
|
|
3624
|
-
if (rawTransformer === void 0) { rawTransformer = {}; }
|
|
3625
|
-
if (rawWritableStrategy === void 0) { rawWritableStrategy = {}; }
|
|
3626
|
-
if (rawReadableStrategy === void 0) { rawReadableStrategy = {}; }
|
|
3627
|
-
if (rawTransformer === undefined) {
|
|
3628
|
-
rawTransformer = null;
|
|
3629
|
-
}
|
|
3630
|
-
var writableStrategy = convertQueuingStrategy(rawWritableStrategy, 'Second parameter');
|
|
3631
|
-
var readableStrategy = convertQueuingStrategy(rawReadableStrategy, 'Third parameter');
|
|
3632
|
-
var transformer = convertTransformer(rawTransformer, 'First parameter');
|
|
3633
|
-
if (transformer.readableType !== undefined) {
|
|
3634
|
-
throw new RangeError('Invalid readableType specified');
|
|
3635
|
-
}
|
|
3636
|
-
if (transformer.writableType !== undefined) {
|
|
3637
|
-
throw new RangeError('Invalid writableType specified');
|
|
3638
|
-
}
|
|
3639
|
-
var readableHighWaterMark = ExtractHighWaterMark(readableStrategy, 0);
|
|
3640
|
-
var readableSizeAlgorithm = ExtractSizeAlgorithm(readableStrategy);
|
|
3641
|
-
var writableHighWaterMark = ExtractHighWaterMark(writableStrategy, 1);
|
|
3642
|
-
var writableSizeAlgorithm = ExtractSizeAlgorithm(writableStrategy);
|
|
3643
|
-
var startPromise_resolve;
|
|
3644
|
-
var startPromise = newPromise(function (resolve) {
|
|
3645
|
-
startPromise_resolve = resolve;
|
|
3646
|
-
});
|
|
3647
|
-
InitializeTransformStream(this, startPromise, writableHighWaterMark, writableSizeAlgorithm, readableHighWaterMark, readableSizeAlgorithm);
|
|
3648
|
-
SetUpTransformStreamDefaultControllerFromTransformer(this, transformer);
|
|
3649
|
-
if (transformer.start !== undefined) {
|
|
3650
|
-
startPromise_resolve(transformer.start(this._transformStreamController));
|
|
3651
|
-
}
|
|
3652
|
-
else {
|
|
3653
|
-
startPromise_resolve(undefined);
|
|
3654
|
-
}
|
|
3655
|
-
}
|
|
3656
|
-
Object.defineProperty(TransformStream.prototype, "readable", {
|
|
3657
|
-
/**
|
|
3658
|
-
* The readable side of the transform stream.
|
|
3659
|
-
*/
|
|
3660
|
-
get: function () {
|
|
3661
|
-
if (!IsTransformStream(this)) {
|
|
3662
|
-
throw streamBrandCheckException('readable');
|
|
3663
|
-
}
|
|
3664
|
-
return this._readable;
|
|
3665
|
-
},
|
|
3666
|
-
enumerable: false,
|
|
3667
|
-
configurable: true
|
|
3668
|
-
});
|
|
3669
|
-
Object.defineProperty(TransformStream.prototype, "writable", {
|
|
3670
|
-
/**
|
|
3671
|
-
* The writable side of the transform stream.
|
|
3672
|
-
*/
|
|
3673
|
-
get: function () {
|
|
3674
|
-
if (!IsTransformStream(this)) {
|
|
3675
|
-
throw streamBrandCheckException('writable');
|
|
3676
|
-
}
|
|
3677
|
-
return this._writable;
|
|
3678
|
-
},
|
|
3679
|
-
enumerable: false,
|
|
3680
|
-
configurable: true
|
|
3681
|
-
});
|
|
3682
|
-
return TransformStream;
|
|
3683
|
-
}());
|
|
3684
|
-
Object.defineProperties(TransformStream.prototype, {
|
|
3685
|
-
readable: { enumerable: true },
|
|
3686
|
-
writable: { enumerable: true }
|
|
3687
|
-
});
|
|
3688
|
-
if (typeof SymbolPolyfill.toStringTag === 'symbol') {
|
|
3689
|
-
Object.defineProperty(TransformStream.prototype, SymbolPolyfill.toStringTag, {
|
|
3690
|
-
value: 'TransformStream',
|
|
3691
|
-
configurable: true
|
|
3692
|
-
});
|
|
3693
|
-
}
|
|
3694
|
-
function InitializeTransformStream(stream, startPromise, writableHighWaterMark, writableSizeAlgorithm, readableHighWaterMark, readableSizeAlgorithm) {
|
|
3695
|
-
function startAlgorithm() {
|
|
3696
|
-
return startPromise;
|
|
3697
|
-
}
|
|
3698
|
-
function writeAlgorithm(chunk) {
|
|
3699
|
-
return TransformStreamDefaultSinkWriteAlgorithm(stream, chunk);
|
|
3700
|
-
}
|
|
3701
|
-
function abortAlgorithm(reason) {
|
|
3702
|
-
return TransformStreamDefaultSinkAbortAlgorithm(stream, reason);
|
|
3703
|
-
}
|
|
3704
|
-
function closeAlgorithm() {
|
|
3705
|
-
return TransformStreamDefaultSinkCloseAlgorithm(stream);
|
|
3706
|
-
}
|
|
3707
|
-
stream._writable = CreateWritableStream(startAlgorithm, writeAlgorithm, closeAlgorithm, abortAlgorithm, writableHighWaterMark, writableSizeAlgorithm);
|
|
3708
|
-
function pullAlgorithm() {
|
|
3709
|
-
return TransformStreamDefaultSourcePullAlgorithm(stream);
|
|
3710
|
-
}
|
|
3711
|
-
function cancelAlgorithm(reason) {
|
|
3712
|
-
TransformStreamErrorWritableAndUnblockWrite(stream, reason);
|
|
3713
|
-
return promiseResolvedWith(undefined);
|
|
3714
|
-
}
|
|
3715
|
-
stream._readable = CreateReadableStream(startAlgorithm, pullAlgorithm, cancelAlgorithm, readableHighWaterMark, readableSizeAlgorithm);
|
|
3716
|
-
// The [[backpressure]] slot is set to undefined so that it can be initialised by TransformStreamSetBackpressure.
|
|
3717
|
-
stream._backpressure = undefined;
|
|
3718
|
-
stream._backpressureChangePromise = undefined;
|
|
3719
|
-
stream._backpressureChangePromise_resolve = undefined;
|
|
3720
|
-
TransformStreamSetBackpressure(stream, true);
|
|
3721
|
-
stream._transformStreamController = undefined;
|
|
3722
|
-
}
|
|
3723
|
-
function IsTransformStream(x) {
|
|
3724
|
-
if (!typeIsObject(x)) {
|
|
3725
|
-
return false;
|
|
3726
|
-
}
|
|
3727
|
-
if (!Object.prototype.hasOwnProperty.call(x, '_transformStreamController')) {
|
|
3728
|
-
return false;
|
|
3729
|
-
}
|
|
3730
|
-
return true;
|
|
3731
|
-
}
|
|
3732
|
-
// This is a no-op if both sides are already errored.
|
|
3733
|
-
function TransformStreamError(stream, e) {
|
|
3734
|
-
ReadableStreamDefaultControllerError(stream._readable._readableStreamController, e);
|
|
3735
|
-
TransformStreamErrorWritableAndUnblockWrite(stream, e);
|
|
3736
|
-
}
|
|
3737
|
-
function TransformStreamErrorWritableAndUnblockWrite(stream, e) {
|
|
3738
|
-
TransformStreamDefaultControllerClearAlgorithms(stream._transformStreamController);
|
|
3739
|
-
WritableStreamDefaultControllerErrorIfNeeded(stream._writable._writableStreamController, e);
|
|
3740
|
-
if (stream._backpressure) {
|
|
3741
|
-
// Pretend that pull() was called to permit any pending write() calls to complete. TransformStreamSetBackpressure()
|
|
3742
|
-
// cannot be called from enqueue() or pull() once the ReadableStream is errored, so this will will be the final time
|
|
3743
|
-
// _backpressure is set.
|
|
3744
|
-
TransformStreamSetBackpressure(stream, false);
|
|
3745
|
-
}
|
|
3746
|
-
}
|
|
3747
|
-
function TransformStreamSetBackpressure(stream, backpressure) {
|
|
3748
|
-
// Passes also when called during construction.
|
|
3749
|
-
if (stream._backpressureChangePromise !== undefined) {
|
|
3750
|
-
stream._backpressureChangePromise_resolve();
|
|
3751
|
-
}
|
|
3752
|
-
stream._backpressureChangePromise = newPromise(function (resolve) {
|
|
3753
|
-
stream._backpressureChangePromise_resolve = resolve;
|
|
3754
|
-
});
|
|
3755
|
-
stream._backpressure = backpressure;
|
|
3756
|
-
}
|
|
3757
|
-
// Class TransformStreamDefaultController
|
|
3758
|
-
/**
|
|
3759
|
-
* Allows control of the {@link ReadableStream} and {@link WritableStream} of the associated {@link TransformStream}.
|
|
3760
|
-
*
|
|
3761
|
-
* @public
|
|
3762
|
-
*/
|
|
3763
|
-
var TransformStreamDefaultController = /** @class */ (function () {
|
|
3764
|
-
function TransformStreamDefaultController() {
|
|
3765
|
-
throw new TypeError('Illegal constructor');
|
|
3766
|
-
}
|
|
3767
|
-
Object.defineProperty(TransformStreamDefaultController.prototype, "desiredSize", {
|
|
3768
|
-
/**
|
|
3769
|
-
* Returns the desired size to fill the readable side’s internal queue. It can be negative, if the queue is over-full.
|
|
3770
|
-
*/
|
|
3771
|
-
get: function () {
|
|
3772
|
-
if (!IsTransformStreamDefaultController(this)) {
|
|
3773
|
-
throw defaultControllerBrandCheckException('desiredSize');
|
|
3774
|
-
}
|
|
3775
|
-
var readableController = this._controlledTransformStream._readable._readableStreamController;
|
|
3776
|
-
return ReadableStreamDefaultControllerGetDesiredSize(readableController);
|
|
3777
|
-
},
|
|
3778
|
-
enumerable: false,
|
|
3779
|
-
configurable: true
|
|
3780
|
-
});
|
|
3781
|
-
TransformStreamDefaultController.prototype.enqueue = function (chunk) {
|
|
3782
|
-
if (chunk === void 0) { chunk = undefined; }
|
|
3783
|
-
if (!IsTransformStreamDefaultController(this)) {
|
|
3784
|
-
throw defaultControllerBrandCheckException('enqueue');
|
|
3785
|
-
}
|
|
3786
|
-
TransformStreamDefaultControllerEnqueue(this, chunk);
|
|
3787
|
-
};
|
|
3788
|
-
/**
|
|
3789
|
-
* Errors both the readable side and the writable side of the controlled transform stream, making all future
|
|
3790
|
-
* interactions with it fail with the given error `e`. Any chunks queued for transformation will be discarded.
|
|
3791
|
-
*/
|
|
3792
|
-
TransformStreamDefaultController.prototype.error = function (reason) {
|
|
3793
|
-
if (reason === void 0) { reason = undefined; }
|
|
3794
|
-
if (!IsTransformStreamDefaultController(this)) {
|
|
3795
|
-
throw defaultControllerBrandCheckException('error');
|
|
3796
|
-
}
|
|
3797
|
-
TransformStreamDefaultControllerError(this, reason);
|
|
3798
|
-
};
|
|
3799
|
-
/**
|
|
3800
|
-
* Closes the readable side and errors the writable side of the controlled transform stream. This is useful when the
|
|
3801
|
-
* transformer only needs to consume a portion of the chunks written to the writable side.
|
|
3802
|
-
*/
|
|
3803
|
-
TransformStreamDefaultController.prototype.terminate = function () {
|
|
3804
|
-
if (!IsTransformStreamDefaultController(this)) {
|
|
3805
|
-
throw defaultControllerBrandCheckException('terminate');
|
|
3806
|
-
}
|
|
3807
|
-
TransformStreamDefaultControllerTerminate(this);
|
|
3808
|
-
};
|
|
3809
|
-
return TransformStreamDefaultController;
|
|
3810
|
-
}());
|
|
3811
|
-
Object.defineProperties(TransformStreamDefaultController.prototype, {
|
|
3812
|
-
enqueue: { enumerable: true },
|
|
3813
|
-
error: { enumerable: true },
|
|
3814
|
-
terminate: { enumerable: true },
|
|
3815
|
-
desiredSize: { enumerable: true }
|
|
3816
|
-
});
|
|
3817
|
-
if (typeof SymbolPolyfill.toStringTag === 'symbol') {
|
|
3818
|
-
Object.defineProperty(TransformStreamDefaultController.prototype, SymbolPolyfill.toStringTag, {
|
|
3819
|
-
value: 'TransformStreamDefaultController',
|
|
3820
|
-
configurable: true
|
|
3821
|
-
});
|
|
3822
|
-
}
|
|
3823
|
-
// Transform Stream Default Controller Abstract Operations
|
|
3824
|
-
function IsTransformStreamDefaultController(x) {
|
|
3825
|
-
if (!typeIsObject(x)) {
|
|
3826
|
-
return false;
|
|
3827
|
-
}
|
|
3828
|
-
if (!Object.prototype.hasOwnProperty.call(x, '_controlledTransformStream')) {
|
|
3829
|
-
return false;
|
|
3830
|
-
}
|
|
3831
|
-
return true;
|
|
3832
|
-
}
|
|
3833
|
-
function SetUpTransformStreamDefaultController(stream, controller, transformAlgorithm, flushAlgorithm) {
|
|
3834
|
-
controller._controlledTransformStream = stream;
|
|
3835
|
-
stream._transformStreamController = controller;
|
|
3836
|
-
controller._transformAlgorithm = transformAlgorithm;
|
|
3837
|
-
controller._flushAlgorithm = flushAlgorithm;
|
|
3838
|
-
}
|
|
3839
|
-
function SetUpTransformStreamDefaultControllerFromTransformer(stream, transformer) {
|
|
3840
|
-
var controller = Object.create(TransformStreamDefaultController.prototype);
|
|
3841
|
-
var transformAlgorithm = function (chunk) {
|
|
3842
|
-
try {
|
|
3843
|
-
TransformStreamDefaultControllerEnqueue(controller, chunk);
|
|
3844
|
-
return promiseResolvedWith(undefined);
|
|
3845
|
-
}
|
|
3846
|
-
catch (transformResultE) {
|
|
3847
|
-
return promiseRejectedWith(transformResultE);
|
|
3848
|
-
}
|
|
3849
|
-
};
|
|
3850
|
-
var flushAlgorithm = function () { return promiseResolvedWith(undefined); };
|
|
3851
|
-
if (transformer.transform !== undefined) {
|
|
3852
|
-
transformAlgorithm = function (chunk) { return transformer.transform(chunk, controller); };
|
|
3853
|
-
}
|
|
3854
|
-
if (transformer.flush !== undefined) {
|
|
3855
|
-
flushAlgorithm = function () { return transformer.flush(controller); };
|
|
3856
|
-
}
|
|
3857
|
-
SetUpTransformStreamDefaultController(stream, controller, transformAlgorithm, flushAlgorithm);
|
|
3858
|
-
}
|
|
3859
|
-
function TransformStreamDefaultControllerClearAlgorithms(controller) {
|
|
3860
|
-
controller._transformAlgorithm = undefined;
|
|
3861
|
-
controller._flushAlgorithm = undefined;
|
|
3862
|
-
}
|
|
3863
|
-
function TransformStreamDefaultControllerEnqueue(controller, chunk) {
|
|
3864
|
-
var stream = controller._controlledTransformStream;
|
|
3865
|
-
var readableController = stream._readable._readableStreamController;
|
|
3866
|
-
if (!ReadableStreamDefaultControllerCanCloseOrEnqueue(readableController)) {
|
|
3867
|
-
throw new TypeError('Readable side is not in a state that permits enqueue');
|
|
3868
|
-
}
|
|
3869
|
-
// We throttle transform invocations based on the backpressure of the ReadableStream, but we still
|
|
3870
|
-
// accept TransformStreamDefaultControllerEnqueue() calls.
|
|
3871
|
-
try {
|
|
3872
|
-
ReadableStreamDefaultControllerEnqueue(readableController, chunk);
|
|
3873
|
-
}
|
|
3874
|
-
catch (e) {
|
|
3875
|
-
// This happens when readableStrategy.size() throws.
|
|
3876
|
-
TransformStreamErrorWritableAndUnblockWrite(stream, e);
|
|
3877
|
-
throw stream._readable._storedError;
|
|
3878
|
-
}
|
|
3879
|
-
var backpressure = ReadableStreamDefaultControllerHasBackpressure(readableController);
|
|
3880
|
-
if (backpressure !== stream._backpressure) {
|
|
3881
|
-
TransformStreamSetBackpressure(stream, true);
|
|
3882
|
-
}
|
|
3883
|
-
}
|
|
3884
|
-
function TransformStreamDefaultControllerError(controller, e) {
|
|
3885
|
-
TransformStreamError(controller._controlledTransformStream, e);
|
|
3886
|
-
}
|
|
3887
|
-
function TransformStreamDefaultControllerPerformTransform(controller, chunk) {
|
|
3888
|
-
var transformPromise = controller._transformAlgorithm(chunk);
|
|
3889
|
-
return transformPromiseWith(transformPromise, undefined, function (r) {
|
|
3890
|
-
TransformStreamError(controller._controlledTransformStream, r);
|
|
3891
|
-
throw r;
|
|
3892
|
-
});
|
|
3893
|
-
}
|
|
3894
|
-
function TransformStreamDefaultControllerTerminate(controller) {
|
|
3895
|
-
var stream = controller._controlledTransformStream;
|
|
3896
|
-
var readableController = stream._readable._readableStreamController;
|
|
3897
|
-
ReadableStreamDefaultControllerClose(readableController);
|
|
3898
|
-
var error = new TypeError('TransformStream terminated');
|
|
3899
|
-
TransformStreamErrorWritableAndUnblockWrite(stream, error);
|
|
3900
|
-
}
|
|
3901
|
-
// TransformStreamDefaultSink Algorithms
|
|
3902
|
-
function TransformStreamDefaultSinkWriteAlgorithm(stream, chunk) {
|
|
3903
|
-
var controller = stream._transformStreamController;
|
|
3904
|
-
if (stream._backpressure) {
|
|
3905
|
-
var backpressureChangePromise = stream._backpressureChangePromise;
|
|
3906
|
-
return transformPromiseWith(backpressureChangePromise, function () {
|
|
3907
|
-
var writable = stream._writable;
|
|
3908
|
-
var state = writable._state;
|
|
3909
|
-
if (state === 'erroring') {
|
|
3910
|
-
throw writable._storedError;
|
|
3911
|
-
}
|
|
3912
|
-
return TransformStreamDefaultControllerPerformTransform(controller, chunk);
|
|
3913
|
-
});
|
|
3914
|
-
}
|
|
3915
|
-
return TransformStreamDefaultControllerPerformTransform(controller, chunk);
|
|
3916
|
-
}
|
|
3917
|
-
function TransformStreamDefaultSinkAbortAlgorithm(stream, reason) {
|
|
3918
|
-
// abort() is not called synchronously, so it is possible for abort() to be called when the stream is already
|
|
3919
|
-
// errored.
|
|
3920
|
-
TransformStreamError(stream, reason);
|
|
3921
|
-
return promiseResolvedWith(undefined);
|
|
3922
|
-
}
|
|
3923
|
-
function TransformStreamDefaultSinkCloseAlgorithm(stream) {
|
|
3924
|
-
// stream._readable cannot change after construction, so caching it across a call to user code is safe.
|
|
3925
|
-
var readable = stream._readable;
|
|
3926
|
-
var controller = stream._transformStreamController;
|
|
3927
|
-
var flushPromise = controller._flushAlgorithm();
|
|
3928
|
-
TransformStreamDefaultControllerClearAlgorithms(controller);
|
|
3929
|
-
// Return a promise that is fulfilled with undefined on success.
|
|
3930
|
-
return transformPromiseWith(flushPromise, function () {
|
|
3931
|
-
if (readable._state === 'errored') {
|
|
3932
|
-
throw readable._storedError;
|
|
3933
|
-
}
|
|
3934
|
-
ReadableStreamDefaultControllerClose(readable._readableStreamController);
|
|
3935
|
-
}, function (r) {
|
|
3936
|
-
TransformStreamError(stream, r);
|
|
3937
|
-
throw readable._storedError;
|
|
3938
|
-
});
|
|
3939
|
-
}
|
|
3940
|
-
// TransformStreamDefaultSource Algorithms
|
|
3941
|
-
function TransformStreamDefaultSourcePullAlgorithm(stream) {
|
|
3942
|
-
// Invariant. Enforced by the promises returned by start() and pull().
|
|
3943
|
-
TransformStreamSetBackpressure(stream, false);
|
|
3944
|
-
// Prevent the next pull() call until there is backpressure.
|
|
3945
|
-
return stream._backpressureChangePromise;
|
|
3946
|
-
}
|
|
3947
|
-
// Helper functions for the TransformStreamDefaultController.
|
|
3948
|
-
function defaultControllerBrandCheckException(name) {
|
|
3949
|
-
return new TypeError("TransformStreamDefaultController.prototype." + name + " can only be used on a TransformStreamDefaultController");
|
|
3950
|
-
}
|
|
3951
|
-
// Helper functions for the TransformStream.
|
|
3952
|
-
function streamBrandCheckException(name) {
|
|
3953
|
-
return new TypeError("TransformStream.prototype." + name + " can only be used on a TransformStream");
|
|
3954
|
-
}
|
|
3955
|
-
|
|
3956
|
-
exports.ByteLengthQueuingStrategy = ByteLengthQueuingStrategy;
|
|
3957
|
-
exports.CountQueuingStrategy = CountQueuingStrategy;
|
|
3958
|
-
exports.ReadableByteStreamController = ReadableByteStreamController;
|
|
3959
|
-
exports.ReadableStream = ReadableStream;
|
|
3960
|
-
exports.ReadableStreamBYOBReader = ReadableStreamBYOBReader;
|
|
3961
|
-
exports.ReadableStreamBYOBRequest = ReadableStreamBYOBRequest;
|
|
3962
|
-
exports.ReadableStreamDefaultController = ReadableStreamDefaultController;
|
|
3963
|
-
exports.ReadableStreamDefaultReader = ReadableStreamDefaultReader;
|
|
3964
|
-
exports.TransformStream = TransformStream;
|
|
3965
|
-
exports.TransformStreamDefaultController = TransformStreamDefaultController;
|
|
3966
|
-
exports.WritableStream = WritableStream;
|
|
3967
|
-
exports.WritableStreamDefaultController = WritableStreamDefaultController;
|
|
3968
|
-
exports.WritableStreamDefaultWriter = WritableStreamDefaultWriter;
|
|
3969
|
-
|
|
3970
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3971
|
-
|
|
3972
|
-
})));
|
|
3973
|
-
//# sourceMappingURL=ponyfill.js.map
|
|
8
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).WebStreamsPolyfill={})}(this,(function(e){"use strict";const t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?Symbol:e=>`Symbol(${e})`;function r(){}function o(e){return"object"==typeof e&&null!==e||"function"==typeof e}const n=r,a=Promise,i=Promise.prototype.then,l=Promise.resolve.bind(a),s=Promise.reject.bind(a);function u(e){return new a(e)}function c(e){return l(e)}function d(e){return s(e)}function f(e,t,r){return i.call(e,t,r)}function b(e,t,r){f(f(e,t,r),void 0,n)}function _(e,t){b(e,t)}function h(e,t){b(e,void 0,t)}function m(e,t,r){return f(e,t,r)}function p(e){f(e,void 0,n)}let y=e=>{if("function"==typeof queueMicrotask)y=queueMicrotask;else{const e=c(void 0);y=t=>f(e,t)}return y(e)};function g(e,t,r){if("function"!=typeof e)throw new TypeError("Argument is not a function");return Function.prototype.apply.call(e,t,r)}function S(e,t,r){try{return c(g(e,t,r))}catch(e){return d(e)}}class v{constructor(){this._cursor=0,this._size=0,this._front={_elements:[],_next:void 0},this._back=this._front,this._cursor=0,this._size=0}get length(){return this._size}push(e){const t=this._back;let r=t;16383===t._elements.length&&(r={_elements:[],_next:void 0}),t._elements.push(e),r!==t&&(this._back=r,t._next=r),++this._size}shift(){const e=this._front;let t=e;const r=this._cursor;let o=r+1;const n=e._elements,a=n[r];return 16384===o&&(t=e._next,o=0),--this._size,this._cursor=o,e!==t&&(this._front=t),n[r]=void 0,a}forEach(e){let t=this._cursor,r=this._front,o=r._elements;for(;!(t===o.length&&void 0===r._next||t===o.length&&(r=r._next,o=r._elements,t=0,0===o.length));)e(o[t]),++t}peek(){const e=this._front,t=this._cursor;return e._elements[t]}}function w(e,t){e._ownerReadableStream=t,t._reader=e,"readable"===t._state?q(e):"closed"===t._state?function(e){q(e),W(e)}(e):P(e,t._storedError)}function R(e,t){return dr(e._ownerReadableStream,t)}function T(e){"readable"===e._ownerReadableStream._state?E(e,new TypeError("Reader was released and can no longer be used to monitor the stream's closedness")):function(e,t){P(e,t)}(e,new TypeError("Reader was released and can no longer be used to monitor the stream's closedness")),e._ownerReadableStream._reader=void 0,e._ownerReadableStream=void 0}function C(e){return new TypeError("Cannot "+e+" a stream using a released reader")}function q(e){e._closedPromise=u(((t,r)=>{e._closedPromise_resolve=t,e._closedPromise_reject=r}))}function P(e,t){q(e),E(e,t)}function E(e,t){void 0!==e._closedPromise_reject&&(p(e._closedPromise),e._closedPromise_reject(t),e._closedPromise_resolve=void 0,e._closedPromise_reject=void 0)}function W(e){void 0!==e._closedPromise_resolve&&(e._closedPromise_resolve(void 0),e._closedPromise_resolve=void 0,e._closedPromise_reject=void 0)}const O=t("[[AbortSteps]]"),B=t("[[ErrorSteps]]"),k=t("[[CancelSteps]]"),j=t("[[PullSteps]]"),A=Number.isFinite||function(e){return"number"==typeof e&&isFinite(e)},z=Math.trunc||function(e){return e<0?Math.ceil(e):Math.floor(e)};function F(e,t){if(void 0!==e&&("object"!=typeof(r=e)&&"function"!=typeof r))throw new TypeError(`${t} is not an object.`);var r}function I(e,t){if("function"!=typeof e)throw new TypeError(`${t} is not a function.`)}function L(e,t){if(!function(e){return"object"==typeof e&&null!==e||"function"==typeof e}(e))throw new TypeError(`${t} is not an object.`)}function D(e,t,r){if(void 0===e)throw new TypeError(`Parameter ${t} is required in '${r}'.`)}function $(e,t,r){if(void 0===e)throw new TypeError(`${t} is required in '${r}'.`)}function M(e){return Number(e)}function Q(e){return 0===e?0:e}function Y(e,t){const r=Number.MAX_SAFE_INTEGER;let o=Number(e);if(o=Q(o),!A(o))throw new TypeError(`${t} is not a finite number`);if(o=function(e){return Q(z(e))}(o),o<0||o>r)throw new TypeError(`${t} is outside the accepted range of 0 to ${r}, inclusive`);return A(o)&&0!==o?o:0}function x(e,t){if(!ur(e))throw new TypeError(`${t} is not a ReadableStream.`)}function N(e){return new ReadableStreamDefaultReader(e)}function H(e,t){e._reader._readRequests.push(t)}function V(e,t,r){const o=e._reader._readRequests.shift();r?o._closeSteps():o._chunkSteps(t)}function U(e){return e._reader._readRequests.length}function G(e){const t=e._reader;return void 0!==t&&!!X(t)}class ReadableStreamDefaultReader{constructor(e){if(D(e,1,"ReadableStreamDefaultReader"),x(e,"First parameter"),cr(e))throw new TypeError("This stream has already been locked for exclusive reading by another reader");w(this,e),this._readRequests=new v}get closed(){return X(this)?this._closedPromise:d(K("closed"))}cancel(e){return X(this)?void 0===this._ownerReadableStream?d(C("cancel")):R(this,e):d(K("cancel"))}read(){if(!X(this))return d(K("read"));if(void 0===this._ownerReadableStream)return d(C("read from"));let e,t;const r=u(((r,o)=>{e=r,t=o}));return J(this,{_chunkSteps:t=>e({value:t,done:!1}),_closeSteps:()=>e({value:void 0,done:!0}),_errorSteps:e=>t(e)}),r}releaseLock(){if(!X(this))throw K("releaseLock");if(void 0!==this._ownerReadableStream){if(this._readRequests.length>0)throw new TypeError("Tried to release a reader lock when that reader has pending read() calls un-settled");T(this)}}}function X(e){return!!o(e)&&(!!Object.prototype.hasOwnProperty.call(e,"_readRequests")&&e instanceof ReadableStreamDefaultReader)}function J(e,t){const r=e._ownerReadableStream;r._disturbed=!0,"closed"===r._state?t._closeSteps():"errored"===r._state?t._errorSteps(r._storedError):r._readableStreamController[j](t)}function K(e){return new TypeError(`ReadableStreamDefaultReader.prototype.${e} can only be used on a ReadableStreamDefaultReader`)}Object.defineProperties(ReadableStreamDefaultReader.prototype,{cancel:{enumerable:!0},read:{enumerable:!0},releaseLock:{enumerable:!0},closed:{enumerable:!0}}),"symbol"==typeof t.toStringTag&&Object.defineProperty(ReadableStreamDefaultReader.prototype,t.toStringTag,{value:"ReadableStreamDefaultReader",configurable:!0});class Z{constructor(e,t){this._ongoingPromise=void 0,this._isFinished=!1,this._reader=e,this._preventCancel=t}next(){const e=()=>this._nextSteps();return this._ongoingPromise=this._ongoingPromise?m(this._ongoingPromise,e,e):e(),this._ongoingPromise}return(e){const t=()=>this._returnSteps(e);return this._ongoingPromise?m(this._ongoingPromise,t,t):t()}_nextSteps(){if(this._isFinished)return Promise.resolve({value:void 0,done:!0});const e=this._reader;if(void 0===e._ownerReadableStream)return d(C("iterate"));let t,r;const o=u(((e,o)=>{t=e,r=o}));return J(e,{_chunkSteps:e=>{this._ongoingPromise=void 0,y((()=>t({value:e,done:!1})))},_closeSteps:()=>{this._ongoingPromise=void 0,this._isFinished=!0,T(e),t({value:void 0,done:!0})},_errorSteps:t=>{this._ongoingPromise=void 0,this._isFinished=!0,T(e),r(t)}}),o}_returnSteps(e){if(this._isFinished)return Promise.resolve({value:e,done:!0});this._isFinished=!0;const t=this._reader;if(void 0===t._ownerReadableStream)return d(C("finish iterating"));if(!this._preventCancel){const r=R(t,e);return T(t),m(r,(()=>({value:e,done:!0})))}return T(t),c({value:e,done:!0})}}const ee={next(){return te(this)?this._asyncIteratorImpl.next():d(re("next"))},return(e){return te(this)?this._asyncIteratorImpl.return(e):d(re("return"))}};function te(e){if(!o(e))return!1;if(!Object.prototype.hasOwnProperty.call(e,"_asyncIteratorImpl"))return!1;try{return e._asyncIteratorImpl instanceof Z}catch(e){return!1}}function re(e){return new TypeError(`ReadableStreamAsyncIterator.${e} can only be used on a ReadableSteamAsyncIterator`)}"symbol"==typeof t.asyncIterator&&Object.defineProperty(ee,t.asyncIterator,{value(){return this},writable:!0,configurable:!0});const oe=Number.isNaN||function(e){return e!=e};function ne(e){return e.slice()}function ae(e,t,r,o,n){new Uint8Array(e).set(new Uint8Array(r,o,n),t)}function ie(e,t,r){if(e.slice)return e.slice(t,r);const o=r-t,n=new ArrayBuffer(o);return ae(n,0,e,t,o),n}function le(e){const t=ie(e.buffer,e.byteOffset,e.byteOffset+e.byteLength);return new Uint8Array(t)}function se(e){const t=e._queue.shift();return e._queueTotalSize-=t.size,e._queueTotalSize<0&&(e._queueTotalSize=0),t.value}function ue(e,t,r){if("number"!=typeof(o=r)||oe(o)||o<0||r===1/0)throw new RangeError("Size must be a finite, non-NaN, non-negative number.");var o;e._queue.push({value:t,size:r}),e._queueTotalSize+=r}function ce(e){e._queue=new v,e._queueTotalSize=0}class ReadableStreamBYOBRequest{constructor(){throw new TypeError("Illegal constructor")}get view(){if(!fe(this))throw Ae("view");return this._view}respond(e){if(!fe(this))throw Ae("respond");if(D(e,1,"respond"),e=Y(e,"First parameter"),void 0===this._associatedReadableByteStreamController)throw new TypeError("This BYOB request has been invalidated");this._view.buffer,Be(this._associatedReadableByteStreamController,e)}respondWithNewView(e){if(!fe(this))throw Ae("respondWithNewView");if(D(e,1,"respondWithNewView"),!ArrayBuffer.isView(e))throw new TypeError("You can only respond with array buffer views");if(void 0===this._associatedReadableByteStreamController)throw new TypeError("This BYOB request has been invalidated");e.buffer,ke(this._associatedReadableByteStreamController,e)}}Object.defineProperties(ReadableStreamBYOBRequest.prototype,{respond:{enumerable:!0},respondWithNewView:{enumerable:!0},view:{enumerable:!0}}),"symbol"==typeof t.toStringTag&&Object.defineProperty(ReadableStreamBYOBRequest.prototype,t.toStringTag,{value:"ReadableStreamBYOBRequest",configurable:!0});class ReadableByteStreamController{constructor(){throw new TypeError("Illegal constructor")}get byobRequest(){if(!de(this))throw ze("byobRequest");return We(this)}get desiredSize(){if(!de(this))throw ze("desiredSize");return Oe(this)}close(){if(!de(this))throw ze("close");if(this._closeRequested)throw new TypeError("The stream has already been closed; do not close it again!");const e=this._controlledReadableByteStream._state;if("readable"!==e)throw new TypeError(`The stream (in ${e} state) is not in the readable state and cannot be closed`);qe(this)}enqueue(e){if(!de(this))throw ze("enqueue");if(D(e,1,"enqueue"),!ArrayBuffer.isView(e))throw new TypeError("chunk must be an array buffer view");if(0===e.byteLength)throw new TypeError("chunk must have non-zero byteLength");if(0===e.buffer.byteLength)throw new TypeError("chunk's buffer must have non-zero byteLength");if(this._closeRequested)throw new TypeError("stream is closed or draining");const t=this._controlledReadableByteStream._state;if("readable"!==t)throw new TypeError(`The stream (in ${t} state) is not in the readable state and cannot be enqueued to`);Pe(this,e)}error(e){if(!de(this))throw ze("error");Ee(this,e)}[k](e){_e(this),ce(this);const t=this._cancelAlgorithm(e);return Ce(this),t}[j](e){const t=this._controlledReadableByteStream;if(this._queueTotalSize>0){const t=this._queue.shift();this._queueTotalSize-=t.byteLength,Se(this);const r=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);return void e._chunkSteps(r)}const r=this._autoAllocateChunkSize;if(void 0!==r){let t;try{t=new ArrayBuffer(r)}catch(t){return void e._errorSteps(t)}const o={buffer:t,bufferByteLength:r,byteOffset:0,byteLength:r,bytesFilled:0,elementSize:1,viewConstructor:Uint8Array,readerType:"default"};this._pendingPullIntos.push(o)}H(t,e),be(this)}}function de(e){return!!o(e)&&(!!Object.prototype.hasOwnProperty.call(e,"_controlledReadableByteStream")&&e instanceof ReadableByteStreamController)}function fe(e){return!!o(e)&&(!!Object.prototype.hasOwnProperty.call(e,"_associatedReadableByteStreamController")&&e instanceof ReadableStreamBYOBRequest)}function be(e){if(!function(e){const t=e._controlledReadableByteStream;if("readable"!==t._state)return!1;if(e._closeRequested)return!1;if(!e._started)return!1;if(G(t)&&U(t)>0)return!0;if(De(t)&&Le(t)>0)return!0;if(Oe(e)>0)return!0;return!1}(e))return;if(e._pulling)return void(e._pullAgain=!0);e._pulling=!0;b(e._pullAlgorithm(),(()=>{e._pulling=!1,e._pullAgain&&(e._pullAgain=!1,be(e))}),(t=>{Ee(e,t)}))}function _e(e){ve(e),e._pendingPullIntos=new v}function he(e,t){let r=!1;"closed"===e._state&&(r=!0);const o=me(t);"default"===t.readerType?V(e,o,r):function(e,t,r){const o=e._reader._readIntoRequests.shift();r?o._closeSteps(t):o._chunkSteps(t)}(e,o,r)}function me(e){const t=e.bytesFilled,r=e.elementSize;return new e.viewConstructor(e.buffer,e.byteOffset,t/r)}function pe(e,t,r,o){e._queue.push({buffer:t,byteOffset:r,byteLength:o}),e._queueTotalSize+=o}function ye(e,t){const r=t.elementSize,o=t.bytesFilled-t.bytesFilled%r,n=Math.min(e._queueTotalSize,t.byteLength-t.bytesFilled),a=t.bytesFilled+n,i=a-a%r;let l=n,s=!1;i>o&&(l=i-t.bytesFilled,s=!0);const u=e._queue;for(;l>0;){const r=u.peek(),o=Math.min(l,r.byteLength),n=t.byteOffset+t.bytesFilled;ae(t.buffer,n,r.buffer,r.byteOffset,o),r.byteLength===o?u.shift():(r.byteOffset+=o,r.byteLength-=o),e._queueTotalSize-=o,ge(e,o,t),l-=o}return s}function ge(e,t,r){r.bytesFilled+=t}function Se(e){0===e._queueTotalSize&&e._closeRequested?(Ce(e),fr(e._controlledReadableByteStream)):be(e)}function ve(e){null!==e._byobRequest&&(e._byobRequest._associatedReadableByteStreamController=void 0,e._byobRequest._view=null,e._byobRequest=null)}function we(e){for(;e._pendingPullIntos.length>0;){if(0===e._queueTotalSize)return;const t=e._pendingPullIntos.peek();ye(e,t)&&(Te(e),he(e._controlledReadableByteStream,t))}}function Re(e,t){const r=e._pendingPullIntos.peek();ve(e);"closed"===e._controlledReadableByteStream._state?function(e,t){const r=e._controlledReadableByteStream;if(De(r))for(;Le(r)>0;)he(r,Te(e))}(e):function(e,t,r){if(ge(0,t,r),r.bytesFilled<r.elementSize)return;Te(e);const o=r.bytesFilled%r.elementSize;if(o>0){const t=r.byteOffset+r.bytesFilled,n=ie(r.buffer,t-o,t);pe(e,n,0,n.byteLength)}r.bytesFilled-=o,he(e._controlledReadableByteStream,r),we(e)}(e,t,r),be(e)}function Te(e){return e._pendingPullIntos.shift()}function Ce(e){e._pullAlgorithm=void 0,e._cancelAlgorithm=void 0}function qe(e){const t=e._controlledReadableByteStream;if(!e._closeRequested&&"readable"===t._state)if(e._queueTotalSize>0)e._closeRequested=!0;else{if(e._pendingPullIntos.length>0){if(e._pendingPullIntos.peek().bytesFilled>0){const t=new TypeError("Insufficient bytes to fill elements in the given buffer");throw Ee(e,t),t}}Ce(e),fr(t)}}function Pe(e,t){const r=e._controlledReadableByteStream;if(e._closeRequested||"readable"!==r._state)return;const o=t.buffer,n=t.byteOffset,a=t.byteLength,i=o;if(e._pendingPullIntos.length>0){const t=e._pendingPullIntos.peek();t.buffer,0,t.buffer=t.buffer}if(ve(e),G(r))if(0===U(r))pe(e,i,n,a);else{V(r,new Uint8Array(i,n,a),!1)}else De(r)?(pe(e,i,n,a),we(e)):pe(e,i,n,a);be(e)}function Ee(e,t){const r=e._controlledReadableByteStream;"readable"===r._state&&(_e(e),ce(e),Ce(e),br(r,t))}function We(e){if(null===e._byobRequest&&e._pendingPullIntos.length>0){const t=e._pendingPullIntos.peek(),r=new Uint8Array(t.buffer,t.byteOffset+t.bytesFilled,t.byteLength-t.bytesFilled),o=Object.create(ReadableStreamBYOBRequest.prototype);!function(e,t,r){e._associatedReadableByteStreamController=t,e._view=r}(o,e,r),e._byobRequest=o}return e._byobRequest}function Oe(e){const t=e._controlledReadableByteStream._state;return"errored"===t?null:"closed"===t?0:e._strategyHWM-e._queueTotalSize}function Be(e,t){const r=e._pendingPullIntos.peek();if("closed"===e._controlledReadableByteStream._state){if(0!==t)throw new TypeError("bytesWritten must be 0 when calling respond() on a closed stream")}else{if(0===t)throw new TypeError("bytesWritten must be greater than 0 when calling respond() on a readable stream");if(r.bytesFilled+t>r.byteLength)throw new RangeError("bytesWritten out of range")}r.buffer=r.buffer,Re(e,t)}function ke(e,t){const r=e._pendingPullIntos.peek();if("closed"===e._controlledReadableByteStream._state){if(0!==t.byteLength)throw new TypeError("The view's length must be 0 when calling respondWithNewView() on a closed stream")}else if(0===t.byteLength)throw new TypeError("The view's length must be greater than 0 when calling respondWithNewView() on a readable stream");if(r.byteOffset+r.bytesFilled!==t.byteOffset)throw new RangeError("The region specified by view does not match byobRequest");if(r.bufferByteLength!==t.buffer.byteLength)throw new RangeError("The buffer of view has different capacity than byobRequest");if(r.bytesFilled+t.byteLength>r.byteLength)throw new RangeError("The region specified by view is larger than byobRequest");r.buffer=t.buffer,Re(e,t.byteLength)}function je(e,t,r,o,n,a,i){t._controlledReadableByteStream=e,t._pullAgain=!1,t._pulling=!1,t._byobRequest=null,t._queue=t._queueTotalSize=void 0,ce(t),t._closeRequested=!1,t._started=!1,t._strategyHWM=a,t._pullAlgorithm=o,t._cancelAlgorithm=n,t._autoAllocateChunkSize=i,t._pendingPullIntos=new v,e._readableStreamController=t;b(c(r()),(()=>{t._started=!0,be(t)}),(e=>{Ee(t,e)}))}function Ae(e){return new TypeError(`ReadableStreamBYOBRequest.prototype.${e} can only be used on a ReadableStreamBYOBRequest`)}function ze(e){return new TypeError(`ReadableByteStreamController.prototype.${e} can only be used on a ReadableByteStreamController`)}function Fe(e){return new ReadableStreamBYOBReader(e)}function Ie(e,t){e._reader._readIntoRequests.push(t)}function Le(e){return e._reader._readIntoRequests.length}function De(e){const t=e._reader;return void 0!==t&&!!$e(t)}Object.defineProperties(ReadableByteStreamController.prototype,{close:{enumerable:!0},enqueue:{enumerable:!0},error:{enumerable:!0},byobRequest:{enumerable:!0},desiredSize:{enumerable:!0}}),"symbol"==typeof t.toStringTag&&Object.defineProperty(ReadableByteStreamController.prototype,t.toStringTag,{value:"ReadableByteStreamController",configurable:!0});class ReadableStreamBYOBReader{constructor(e){if(D(e,1,"ReadableStreamBYOBReader"),x(e,"First parameter"),cr(e))throw new TypeError("This stream has already been locked for exclusive reading by another reader");if(!de(e._readableStreamController))throw new TypeError("Cannot construct a ReadableStreamBYOBReader for a stream not constructed with a byte source");w(this,e),this._readIntoRequests=new v}get closed(){return $e(this)?this._closedPromise:d(Qe("closed"))}cancel(e){return $e(this)?void 0===this._ownerReadableStream?d(C("cancel")):R(this,e):d(Qe("cancel"))}read(e){if(!$e(this))return d(Qe("read"));if(!ArrayBuffer.isView(e))return d(new TypeError("view must be an array buffer view"));if(0===e.byteLength)return d(new TypeError("view must have non-zero byteLength"));if(0===e.buffer.byteLength)return d(new TypeError("view's buffer must have non-zero byteLength"));if(e.buffer,void 0===this._ownerReadableStream)return d(C("read from"));let t,r;const o=u(((e,o)=>{t=e,r=o}));return Me(this,e,{_chunkSteps:e=>t({value:e,done:!1}),_closeSteps:e=>t({value:e,done:!0}),_errorSteps:e=>r(e)}),o}releaseLock(){if(!$e(this))throw Qe("releaseLock");if(void 0!==this._ownerReadableStream){if(this._readIntoRequests.length>0)throw new TypeError("Tried to release a reader lock when that reader has pending read() calls un-settled");T(this)}}}function $e(e){return!!o(e)&&(!!Object.prototype.hasOwnProperty.call(e,"_readIntoRequests")&&e instanceof ReadableStreamBYOBReader)}function Me(e,t,r){const o=e._ownerReadableStream;o._disturbed=!0,"errored"===o._state?r._errorSteps(o._storedError):function(e,t,r){const o=e._controlledReadableByteStream;let n=1;t.constructor!==DataView&&(n=t.constructor.BYTES_PER_ELEMENT);const a=t.constructor,i=t.buffer,l={buffer:i,bufferByteLength:i.byteLength,byteOffset:t.byteOffset,byteLength:t.byteLength,bytesFilled:0,elementSize:n,viewConstructor:a,readerType:"byob"};if(e._pendingPullIntos.length>0)return e._pendingPullIntos.push(l),void Ie(o,r);if("closed"!==o._state){if(e._queueTotalSize>0){if(ye(e,l)){const t=me(l);return Se(e),void r._chunkSteps(t)}if(e._closeRequested){const t=new TypeError("Insufficient bytes to fill elements in the given buffer");return Ee(e,t),void r._errorSteps(t)}}e._pendingPullIntos.push(l),Ie(o,r),be(e)}else{const e=new a(l.buffer,l.byteOffset,0);r._closeSteps(e)}}(o._readableStreamController,t,r)}function Qe(e){return new TypeError(`ReadableStreamBYOBReader.prototype.${e} can only be used on a ReadableStreamBYOBReader`)}function Ye(e,t){const{highWaterMark:r}=e;if(void 0===r)return t;if(oe(r)||r<0)throw new RangeError("Invalid highWaterMark");return r}function xe(e){const{size:t}=e;return t||(()=>1)}function Ne(e,t){F(e,t);const r=null==e?void 0:e.highWaterMark,o=null==e?void 0:e.size;return{highWaterMark:void 0===r?void 0:M(r),size:void 0===o?void 0:He(o,`${t} has member 'size' that`)}}function He(e,t){return I(e,t),t=>M(e(t))}function Ve(e,t,r){return I(e,r),r=>S(e,t,[r])}function Ue(e,t,r){return I(e,r),()=>S(e,t,[])}function Ge(e,t,r){return I(e,r),r=>g(e,t,[r])}function Xe(e,t,r){return I(e,r),(r,o)=>S(e,t,[r,o])}function Je(e,t){if(!tt(e))throw new TypeError(`${t} is not a WritableStream.`)}Object.defineProperties(ReadableStreamBYOBReader.prototype,{cancel:{enumerable:!0},read:{enumerable:!0},releaseLock:{enumerable:!0},closed:{enumerable:!0}}),"symbol"==typeof t.toStringTag&&Object.defineProperty(ReadableStreamBYOBReader.prototype,t.toStringTag,{value:"ReadableStreamBYOBReader",configurable:!0});const Ke="function"==typeof AbortController;class WritableStream{constructor(e={},t={}){void 0===e?e=null:L(e,"First parameter");const r=Ne(t,"Second parameter"),o=function(e,t){F(e,t);const r=null==e?void 0:e.abort,o=null==e?void 0:e.close,n=null==e?void 0:e.start,a=null==e?void 0:e.type,i=null==e?void 0:e.write;return{abort:void 0===r?void 0:Ve(r,e,`${t} has member 'abort' that`),close:void 0===o?void 0:Ue(o,e,`${t} has member 'close' that`),start:void 0===n?void 0:Ge(n,e,`${t} has member 'start' that`),write:void 0===i?void 0:Xe(i,e,`${t} has member 'write' that`),type:a}}(e,"First parameter");et(this);if(void 0!==o.type)throw new RangeError("Invalid type is specified");const n=xe(r);!function(e,t,r,o){const n=Object.create(WritableStreamDefaultController.prototype);let a=()=>{},i=()=>c(void 0),l=()=>c(void 0),s=()=>c(void 0);void 0!==t.start&&(a=()=>t.start(n));void 0!==t.write&&(i=e=>t.write(e,n));void 0!==t.close&&(l=()=>t.close());void 0!==t.abort&&(s=e=>t.abort(e));gt(e,n,a,i,l,s,r,o)}(this,o,Ye(r,1),n)}get locked(){if(!tt(this))throw qt("locked");return rt(this)}abort(e){return tt(this)?rt(this)?d(new TypeError("Cannot abort a stream that already has a writer")):ot(this,e):d(qt("abort"))}close(){return tt(this)?rt(this)?d(new TypeError("Cannot close a stream that already has a writer")):st(this)?d(new TypeError("Cannot close an already-closing stream")):nt(this):d(qt("close"))}getWriter(){if(!tt(this))throw qt("getWriter");return Ze(this)}}function Ze(e){return new WritableStreamDefaultWriter(e)}function et(e){e._state="writable",e._storedError=void 0,e._writer=void 0,e._writableStreamController=void 0,e._writeRequests=new v,e._inFlightWriteRequest=void 0,e._closeRequest=void 0,e._inFlightCloseRequest=void 0,e._pendingAbortRequest=void 0,e._backpressure=!1}function tt(e){return!!o(e)&&(!!Object.prototype.hasOwnProperty.call(e,"_writableStreamController")&&e instanceof WritableStream)}function rt(e){return void 0!==e._writer}function ot(e,t){var r;if("closed"===e._state||"errored"===e._state)return c(void 0);e._writableStreamController._abortReason=t,null===(r=e._writableStreamController._abortController)||void 0===r||r.abort();const o=e._state;if("closed"===o||"errored"===o)return c(void 0);if(void 0!==e._pendingAbortRequest)return e._pendingAbortRequest._promise;let n=!1;"erroring"===o&&(n=!0,t=void 0);const a=u(((r,o)=>{e._pendingAbortRequest={_promise:void 0,_resolve:r,_reject:o,_reason:t,_wasAlreadyErroring:n}}));return e._pendingAbortRequest._promise=a,n||it(e,t),a}function nt(e){const t=e._state;if("closed"===t||"errored"===t)return d(new TypeError(`The stream (in ${t} state) is not in the writable state and cannot be closed`));const r=u(((t,r)=>{const o={_resolve:t,_reject:r};e._closeRequest=o})),o=e._writer;var n;return void 0!==o&&e._backpressure&&"writable"===t&&Lt(o),ue(n=e._writableStreamController,pt,0),wt(n),r}function at(e,t){"writable"!==e._state?lt(e):it(e,t)}function it(e,t){const r=e._writableStreamController;e._state="erroring",e._storedError=t;const o=e._writer;void 0!==o&&_t(o,t),!function(e){if(void 0===e._inFlightWriteRequest&&void 0===e._inFlightCloseRequest)return!1;return!0}(e)&&r._started&<(e)}function lt(e){e._state="errored",e._writableStreamController[B]();const t=e._storedError;if(e._writeRequests.forEach((e=>{e._reject(t)})),e._writeRequests=new v,void 0===e._pendingAbortRequest)return void ut(e);const r=e._pendingAbortRequest;if(e._pendingAbortRequest=void 0,r._wasAlreadyErroring)return r._reject(t),void ut(e);b(e._writableStreamController[O](r._reason),(()=>{r._resolve(),ut(e)}),(t=>{r._reject(t),ut(e)}))}function st(e){return void 0!==e._closeRequest||void 0!==e._inFlightCloseRequest}function ut(e){void 0!==e._closeRequest&&(e._closeRequest._reject(e._storedError),e._closeRequest=void 0);const t=e._writer;void 0!==t&&kt(t,e._storedError)}function ct(e,t){const r=e._writer;void 0!==r&&t!==e._backpressure&&(t?function(e){At(e)}(r):Lt(r)),e._backpressure=t}Object.defineProperties(WritableStream.prototype,{abort:{enumerable:!0},close:{enumerable:!0},getWriter:{enumerable:!0},locked:{enumerable:!0}}),"symbol"==typeof t.toStringTag&&Object.defineProperty(WritableStream.prototype,t.toStringTag,{value:"WritableStream",configurable:!0});class WritableStreamDefaultWriter{constructor(e){if(D(e,1,"WritableStreamDefaultWriter"),Je(e,"First parameter"),rt(e))throw new TypeError("This stream has already been locked for exclusive writing by another writer");this._ownerWritableStream=e,e._writer=this;const t=e._state;if("writable"===t)!st(e)&&e._backpressure?At(this):Ft(this),Ot(this);else if("erroring"===t)zt(this,e._storedError),Ot(this);else if("closed"===t)Ft(this),Ot(r=this),jt(r);else{const t=e._storedError;zt(this,t),Bt(this,t)}var r}get closed(){return dt(this)?this._closedPromise:d(Et("closed"))}get desiredSize(){if(!dt(this))throw Et("desiredSize");if(void 0===this._ownerWritableStream)throw Wt("desiredSize");return function(e){const t=e._ownerWritableStream,r=t._state;if("errored"===r||"erroring"===r)return null;if("closed"===r)return 0;return vt(t._writableStreamController)}(this)}get ready(){return dt(this)?this._readyPromise:d(Et("ready"))}abort(e){return dt(this)?void 0===this._ownerWritableStream?d(Wt("abort")):function(e,t){return ot(e._ownerWritableStream,t)}(this,e):d(Et("abort"))}close(){if(!dt(this))return d(Et("close"));const e=this._ownerWritableStream;return void 0===e?d(Wt("close")):st(e)?d(new TypeError("Cannot close an already-closing stream")):ft(this)}releaseLock(){if(!dt(this))throw Et("releaseLock");void 0!==this._ownerWritableStream&&ht(this)}write(e){return dt(this)?void 0===this._ownerWritableStream?d(Wt("write to")):mt(this,e):d(Et("write"))}}function dt(e){return!!o(e)&&(!!Object.prototype.hasOwnProperty.call(e,"_ownerWritableStream")&&e instanceof WritableStreamDefaultWriter)}function ft(e){return nt(e._ownerWritableStream)}function bt(e,t){"pending"===e._closedPromiseState?kt(e,t):function(e,t){Bt(e,t)}(e,t)}function _t(e,t){"pending"===e._readyPromiseState?It(e,t):function(e,t){zt(e,t)}(e,t)}function ht(e){const t=e._ownerWritableStream,r=new TypeError("Writer was released and can no longer be used to monitor the stream's closedness");_t(e,r),bt(e,r),t._writer=void 0,e._ownerWritableStream=void 0}function mt(e,t){const r=e._ownerWritableStream,o=r._writableStreamController,n=function(e,t){try{return e._strategySizeAlgorithm(t)}catch(t){return Rt(e,t),1}}(o,t);if(r!==e._ownerWritableStream)return d(Wt("write to"));const a=r._state;if("errored"===a)return d(r._storedError);if(st(r)||"closed"===a)return d(new TypeError("The stream is closing or closed and cannot be written to"));if("erroring"===a)return d(r._storedError);const i=function(e){return u(((t,r)=>{const o={_resolve:t,_reject:r};e._writeRequests.push(o)}))}(r);return function(e,t,r){try{ue(e,t,r)}catch(t){return void Rt(e,t)}const o=e._controlledWritableStream;if(!st(o)&&"writable"===o._state){ct(o,Tt(e))}wt(e)}(o,t,n),i}Object.defineProperties(WritableStreamDefaultWriter.prototype,{abort:{enumerable:!0},close:{enumerable:!0},releaseLock:{enumerable:!0},write:{enumerable:!0},closed:{enumerable:!0},desiredSize:{enumerable:!0},ready:{enumerable:!0}}),"symbol"==typeof t.toStringTag&&Object.defineProperty(WritableStreamDefaultWriter.prototype,t.toStringTag,{value:"WritableStreamDefaultWriter",configurable:!0});const pt={};class WritableStreamDefaultController{constructor(){throw new TypeError("Illegal constructor")}get abortReason(){if(!yt(this))throw Pt("abortReason");return this._abortReason}get signal(){if(!yt(this))throw Pt("signal");if(void 0===this._abortController)throw new TypeError("WritableStreamDefaultController.prototype.signal is not supported");return this._abortController.signal}error(e){if(!yt(this))throw Pt("error");"writable"===this._controlledWritableStream._state&&Ct(this,e)}[O](e){const t=this._abortAlgorithm(e);return St(this),t}[B](){ce(this)}}function yt(e){return!!o(e)&&(!!Object.prototype.hasOwnProperty.call(e,"_controlledWritableStream")&&e instanceof WritableStreamDefaultController)}function gt(e,t,r,o,n,a,i,l){t._controlledWritableStream=e,e._writableStreamController=t,t._queue=void 0,t._queueTotalSize=void 0,ce(t),t._abortReason=void 0,t._abortController=function(){if(Ke)return new AbortController}(),t._started=!1,t._strategySizeAlgorithm=l,t._strategyHWM=i,t._writeAlgorithm=o,t._closeAlgorithm=n,t._abortAlgorithm=a;const s=Tt(t);ct(e,s);b(c(r()),(()=>{t._started=!0,wt(t)}),(r=>{t._started=!0,at(e,r)}))}function St(e){e._writeAlgorithm=void 0,e._closeAlgorithm=void 0,e._abortAlgorithm=void 0,e._strategySizeAlgorithm=void 0}function vt(e){return e._strategyHWM-e._queueTotalSize}function wt(e){const t=e._controlledWritableStream;if(!e._started)return;if(void 0!==t._inFlightWriteRequest)return;if("erroring"===t._state)return void lt(t);if(0===e._queue.length)return;const r=e._queue.peek().value;r===pt?function(e){const t=e._controlledWritableStream;(function(e){e._inFlightCloseRequest=e._closeRequest,e._closeRequest=void 0})(t),se(e);const r=e._closeAlgorithm();St(e),b(r,(()=>{!function(e){e._inFlightCloseRequest._resolve(void 0),e._inFlightCloseRequest=void 0,"erroring"===e._state&&(e._storedError=void 0,void 0!==e._pendingAbortRequest&&(e._pendingAbortRequest._resolve(),e._pendingAbortRequest=void 0)),e._state="closed";const t=e._writer;void 0!==t&&jt(t)}(t)}),(e=>{!function(e,t){e._inFlightCloseRequest._reject(t),e._inFlightCloseRequest=void 0,void 0!==e._pendingAbortRequest&&(e._pendingAbortRequest._reject(t),e._pendingAbortRequest=void 0),at(e,t)}(t,e)}))}(e):function(e,t){const r=e._controlledWritableStream;!function(e){e._inFlightWriteRequest=e._writeRequests.shift()}(r);b(e._writeAlgorithm(t),(()=>{!function(e){e._inFlightWriteRequest._resolve(void 0),e._inFlightWriteRequest=void 0}(r);const t=r._state;if(se(e),!st(r)&&"writable"===t){const t=Tt(e);ct(r,t)}wt(e)}),(t=>{"writable"===r._state&&St(e),function(e,t){e._inFlightWriteRequest._reject(t),e._inFlightWriteRequest=void 0,at(e,t)}(r,t)}))}(e,r)}function Rt(e,t){"writable"===e._controlledWritableStream._state&&Ct(e,t)}function Tt(e){return vt(e)<=0}function Ct(e,t){const r=e._controlledWritableStream;St(e),it(r,t)}function qt(e){return new TypeError(`WritableStream.prototype.${e} can only be used on a WritableStream`)}function Pt(e){return new TypeError(`WritableStreamDefaultController.prototype.${e} can only be used on a WritableStreamDefaultController`)}function Et(e){return new TypeError(`WritableStreamDefaultWriter.prototype.${e} can only be used on a WritableStreamDefaultWriter`)}function Wt(e){return new TypeError("Cannot "+e+" a stream using a released writer")}function Ot(e){e._closedPromise=u(((t,r)=>{e._closedPromise_resolve=t,e._closedPromise_reject=r,e._closedPromiseState="pending"}))}function Bt(e,t){Ot(e),kt(e,t)}function kt(e,t){void 0!==e._closedPromise_reject&&(p(e._closedPromise),e._closedPromise_reject(t),e._closedPromise_resolve=void 0,e._closedPromise_reject=void 0,e._closedPromiseState="rejected")}function jt(e){void 0!==e._closedPromise_resolve&&(e._closedPromise_resolve(void 0),e._closedPromise_resolve=void 0,e._closedPromise_reject=void 0,e._closedPromiseState="resolved")}function At(e){e._readyPromise=u(((t,r)=>{e._readyPromise_resolve=t,e._readyPromise_reject=r})),e._readyPromiseState="pending"}function zt(e,t){At(e),It(e,t)}function Ft(e){At(e),Lt(e)}function It(e,t){void 0!==e._readyPromise_reject&&(p(e._readyPromise),e._readyPromise_reject(t),e._readyPromise_resolve=void 0,e._readyPromise_reject=void 0,e._readyPromiseState="rejected")}function Lt(e){void 0!==e._readyPromise_resolve&&(e._readyPromise_resolve(void 0),e._readyPromise_resolve=void 0,e._readyPromise_reject=void 0,e._readyPromiseState="fulfilled")}Object.defineProperties(WritableStreamDefaultController.prototype,{error:{enumerable:!0}}),"symbol"==typeof t.toStringTag&&Object.defineProperty(WritableStreamDefaultController.prototype,t.toStringTag,{value:"WritableStreamDefaultController",configurable:!0});const Dt="undefined"!=typeof DOMException?DOMException:void 0;const $t=function(e){if("function"!=typeof e&&"object"!=typeof e)return!1;try{return new e,!0}catch(e){return!1}}(Dt)?Dt:function(){const e=function(e,t){this.message=e||"",this.name=t||"Error",Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)};return e.prototype=Object.create(Error.prototype),Object.defineProperty(e.prototype,"constructor",{value:e,writable:!0,configurable:!0}),e}();function Mt(e,t,o,n,a,i){const l=N(e),s=Ze(t);e._disturbed=!0;let m=!1,y=c(void 0);return u(((g,S)=>{let v;if(void 0!==i){if(v=()=>{const r=new $t("Aborted","AbortError"),o=[];n||o.push((()=>"writable"===t._state?ot(t,r):c(void 0))),a||o.push((()=>"readable"===e._state?dr(e,r):c(void 0))),E((()=>Promise.all(o.map((e=>e())))),!0,r)},i.aborted)return void v();i.addEventListener("abort",v)}var w,R,C;if(P(e,l._closedPromise,(e=>{n?W(!0,e):E((()=>ot(t,e)),!0,e)})),P(t,s._closedPromise,(t=>{a?W(!0,t):E((()=>dr(e,t)),!0,t)})),w=e,R=l._closedPromise,C=()=>{o?W():E((()=>function(e){const t=e._ownerWritableStream,r=t._state;return st(t)||"closed"===r?c(void 0):"errored"===r?d(t._storedError):ft(e)}(s)))},"closed"===w._state?C():_(R,C),st(t)||"closed"===t._state){const t=new TypeError("the destination writable stream closed before all data could be piped to it");a?W(!0,t):E((()=>dr(e,t)),!0,t)}function q(){const e=y;return f(y,(()=>e!==y?q():void 0))}function P(e,t,r){"errored"===e._state?r(e._storedError):h(t,r)}function E(e,r,o){function n(){b(e(),(()=>O(r,o)),(e=>O(!0,e)))}m||(m=!0,"writable"!==t._state||st(t)?n():_(q(),n))}function W(e,r){m||(m=!0,"writable"!==t._state||st(t)?O(e,r):_(q(),(()=>O(e,r))))}function O(e,t){ht(s),T(l),void 0!==i&&i.removeEventListener("abort",v),e?S(t):g(void 0)}p(u(((e,t)=>{!function o(n){n?e():f(m?c(!0):f(s._readyPromise,(()=>u(((e,t)=>{J(l,{_chunkSteps:t=>{y=f(mt(s,t),void 0,r),e(!1)},_closeSteps:()=>e(!0),_errorSteps:t})})))),o,t)}(!1)})))}))}class ReadableStreamDefaultController{constructor(){throw new TypeError("Illegal constructor")}get desiredSize(){if(!Qt(this))throw Kt("desiredSize");return Gt(this)}close(){if(!Qt(this))throw Kt("close");if(!Xt(this))throw new TypeError("The stream is not in a state that permits close");Ht(this)}enqueue(e){if(!Qt(this))throw Kt("enqueue");if(!Xt(this))throw new TypeError("The stream is not in a state that permits enqueue");return Vt(this,e)}error(e){if(!Qt(this))throw Kt("error");Ut(this,e)}[k](e){ce(this);const t=this._cancelAlgorithm(e);return Nt(this),t}[j](e){const t=this._controlledReadableStream;if(this._queue.length>0){const r=se(this);this._closeRequested&&0===this._queue.length?(Nt(this),fr(t)):Yt(this),e._chunkSteps(r)}else H(t,e),Yt(this)}}function Qt(e){return!!o(e)&&(!!Object.prototype.hasOwnProperty.call(e,"_controlledReadableStream")&&e instanceof ReadableStreamDefaultController)}function Yt(e){if(!xt(e))return;if(e._pulling)return void(e._pullAgain=!0);e._pulling=!0;b(e._pullAlgorithm(),(()=>{e._pulling=!1,e._pullAgain&&(e._pullAgain=!1,Yt(e))}),(t=>{Ut(e,t)}))}function xt(e){const t=e._controlledReadableStream;if(!Xt(e))return!1;if(!e._started)return!1;if(cr(t)&&U(t)>0)return!0;return Gt(e)>0}function Nt(e){e._pullAlgorithm=void 0,e._cancelAlgorithm=void 0,e._strategySizeAlgorithm=void 0}function Ht(e){if(!Xt(e))return;const t=e._controlledReadableStream;e._closeRequested=!0,0===e._queue.length&&(Nt(e),fr(t))}function Vt(e,t){if(!Xt(e))return;const r=e._controlledReadableStream;if(cr(r)&&U(r)>0)V(r,t,!1);else{let r;try{r=e._strategySizeAlgorithm(t)}catch(t){throw Ut(e,t),t}try{ue(e,t,r)}catch(t){throw Ut(e,t),t}}Yt(e)}function Ut(e,t){const r=e._controlledReadableStream;"readable"===r._state&&(ce(e),Nt(e),br(r,t))}function Gt(e){const t=e._controlledReadableStream._state;return"errored"===t?null:"closed"===t?0:e._strategyHWM-e._queueTotalSize}function Xt(e){const t=e._controlledReadableStream._state;return!e._closeRequested&&"readable"===t}function Jt(e,t,r,o,n,a,i){t._controlledReadableStream=e,t._queue=void 0,t._queueTotalSize=void 0,ce(t),t._started=!1,t._closeRequested=!1,t._pullAgain=!1,t._pulling=!1,t._strategySizeAlgorithm=i,t._strategyHWM=a,t._pullAlgorithm=o,t._cancelAlgorithm=n,e._readableStreamController=t;b(c(r()),(()=>{t._started=!0,Yt(t)}),(e=>{Ut(t,e)}))}function Kt(e){return new TypeError(`ReadableStreamDefaultController.prototype.${e} can only be used on a ReadableStreamDefaultController`)}function Zt(e,t){return de(e._readableStreamController)?function(e){let t,r,o,n,a,i=N(e),l=!1,s=!1,d=!1;const f=u((e=>{a=e}));function b(e){h(e._closedPromise,(t=>{e===i&&(Ee(o._readableStreamController,t),Ee(n._readableStreamController,t),s&&d||a(void 0))}))}function _(){$e(i)&&(T(i),i=N(e),b(i));J(i,{_chunkSteps:t=>{y((()=>{l=!1;const r=t;let i=t;if(!s&&!d)try{i=le(t)}catch(t){return Ee(o._readableStreamController,t),Ee(n._readableStreamController,t),void a(dr(e,t))}s||Pe(o._readableStreamController,r),d||Pe(n._readableStreamController,i)}))},_closeSteps:()=>{l=!1,s||qe(o._readableStreamController),d||qe(n._readableStreamController),o._readableStreamController._pendingPullIntos.length>0&&Be(o._readableStreamController,0),n._readableStreamController._pendingPullIntos.length>0&&Be(n._readableStreamController,0),s&&d||a(void 0)},_errorSteps:()=>{l=!1}})}function m(t,r){X(i)&&(T(i),i=Fe(e),b(i));const u=r?n:o,c=r?o:n;Me(i,t,{_chunkSteps:t=>{y((()=>{l=!1;const o=r?d:s;if(r?s:d)o||ke(u._readableStreamController,t);else{let r;try{r=le(t)}catch(t){return Ee(u._readableStreamController,t),Ee(c._readableStreamController,t),void a(dr(e,t))}o||ke(u._readableStreamController,t),Pe(c._readableStreamController,r)}}))},_closeSteps:e=>{l=!1;const t=r?d:s,o=r?s:d;t||qe(u._readableStreamController),o||qe(c._readableStreamController),void 0!==e&&(t||ke(u._readableStreamController,e),!o&&c._readableStreamController._pendingPullIntos.length>0&&Be(c._readableStreamController,0)),t&&o||a(void 0)},_errorSteps:()=>{l=!1}})}function p(){if(l)return c(void 0);l=!0;const e=We(o._readableStreamController);return null===e?_():m(e._view,!1),c(void 0)}function g(){if(l)return c(void 0);l=!0;const e=We(n._readableStreamController);return null===e?_():m(e._view,!0),c(void 0)}function S(o){if(s=!0,t=o,d){const o=ne([t,r]),n=dr(e,o);a(n)}return f}function v(o){if(d=!0,r=o,s){const o=ne([t,r]),n=dr(e,o);a(n)}return f}function w(){}return o=lr(w,p,S),n=lr(w,g,v),b(i),[o,n]}(e):function(e,t){const r=N(e);let o,n,a,i,l,s=!1,d=!1,f=!1;const b=u((e=>{l=e}));function _(){if(s)return c(void 0);s=!0;return J(r,{_chunkSteps:e=>{y((()=>{s=!1;const t=e,r=e;d||Vt(a._readableStreamController,t),f||Vt(i._readableStreamController,r)}))},_closeSteps:()=>{s=!1,d||Ht(a._readableStreamController),f||Ht(i._readableStreamController),d&&f||l(void 0)},_errorSteps:()=>{s=!1}}),c(void 0)}function m(t){if(d=!0,o=t,f){const t=ne([o,n]),r=dr(e,t);l(r)}return b}function p(t){if(f=!0,n=t,d){const t=ne([o,n]),r=dr(e,t);l(r)}return b}function g(){}return a=ir(g,_,m),i=ir(g,_,p),h(r._closedPromise,(e=>{Ut(a._readableStreamController,e),Ut(i._readableStreamController,e),d&&f||l(void 0)})),[a,i]}(e)}function er(e,t,r){return I(e,r),r=>S(e,t,[r])}function tr(e,t,r){return I(e,r),r=>S(e,t,[r])}function rr(e,t,r){return I(e,r),r=>g(e,t,[r])}function or(e,t){if("bytes"!==(e=`${e}`))throw new TypeError(`${t} '${e}' is not a valid enumeration value for ReadableStreamType`);return e}function nr(e,t){if("byob"!==(e=`${e}`))throw new TypeError(`${t} '${e}' is not a valid enumeration value for ReadableStreamReaderMode`);return e}function ar(e,t){F(e,t);const r=null==e?void 0:e.preventAbort,o=null==e?void 0:e.preventCancel,n=null==e?void 0:e.preventClose,a=null==e?void 0:e.signal;return void 0!==a&&function(e,t){if(!function(e){if("object"!=typeof e||null===e)return!1;try{return"boolean"==typeof e.aborted}catch(e){return!1}}(e))throw new TypeError(`${t} is not an AbortSignal.`)}(a,`${t} has member 'signal' that`),{preventAbort:Boolean(r),preventCancel:Boolean(o),preventClose:Boolean(n),signal:a}}Object.defineProperties(ReadableStreamDefaultController.prototype,{close:{enumerable:!0},enqueue:{enumerable:!0},error:{enumerable:!0},desiredSize:{enumerable:!0}}),"symbol"==typeof t.toStringTag&&Object.defineProperty(ReadableStreamDefaultController.prototype,t.toStringTag,{value:"ReadableStreamDefaultController",configurable:!0});class ReadableStream{constructor(e={},t={}){void 0===e?e=null:L(e,"First parameter");const r=Ne(t,"Second parameter"),o=function(e,t){F(e,t);const r=e,o=null==r?void 0:r.autoAllocateChunkSize,n=null==r?void 0:r.cancel,a=null==r?void 0:r.pull,i=null==r?void 0:r.start,l=null==r?void 0:r.type;return{autoAllocateChunkSize:void 0===o?void 0:Y(o,`${t} has member 'autoAllocateChunkSize' that`),cancel:void 0===n?void 0:er(n,r,`${t} has member 'cancel' that`),pull:void 0===a?void 0:tr(a,r,`${t} has member 'pull' that`),start:void 0===i?void 0:rr(i,r,`${t} has member 'start' that`),type:void 0===l?void 0:or(l,`${t} has member 'type' that`)}}(e,"First parameter");if(sr(this),"bytes"===o.type){if(void 0!==r.size)throw new RangeError("The strategy for a byte stream cannot have a size function");!function(e,t,r){const o=Object.create(ReadableByteStreamController.prototype);let n=()=>{},a=()=>c(void 0),i=()=>c(void 0);void 0!==t.start&&(n=()=>t.start(o)),void 0!==t.pull&&(a=()=>t.pull(o)),void 0!==t.cancel&&(i=e=>t.cancel(e));const l=t.autoAllocateChunkSize;if(0===l)throw new TypeError("autoAllocateChunkSize must be greater than 0");je(e,o,n,a,i,r,l)}(this,o,Ye(r,0))}else{const e=xe(r);!function(e,t,r,o){const n=Object.create(ReadableStreamDefaultController.prototype);let a=()=>{},i=()=>c(void 0),l=()=>c(void 0);void 0!==t.start&&(a=()=>t.start(n)),void 0!==t.pull&&(i=()=>t.pull(n)),void 0!==t.cancel&&(l=e=>t.cancel(e)),Jt(e,n,a,i,l,r,o)}(this,o,Ye(r,1),e)}}get locked(){if(!ur(this))throw _r("locked");return cr(this)}cancel(e){return ur(this)?cr(this)?d(new TypeError("Cannot cancel a stream that already has a reader")):dr(this,e):d(_r("cancel"))}getReader(e){if(!ur(this))throw _r("getReader");return void 0===function(e,t){F(e,t);const r=null==e?void 0:e.mode;return{mode:void 0===r?void 0:nr(r,`${t} has member 'mode' that`)}}(e,"First parameter").mode?N(this):Fe(this)}pipeThrough(e,t={}){if(!ur(this))throw _r("pipeThrough");D(e,1,"pipeThrough");const r=function(e,t){F(e,t);const r=null==e?void 0:e.readable;$(r,"readable","ReadableWritablePair"),x(r,`${t} has member 'readable' that`);const o=null==e?void 0:e.writable;return $(o,"writable","ReadableWritablePair"),Je(o,`${t} has member 'writable' that`),{readable:r,writable:o}}(e,"First parameter"),o=ar(t,"Second parameter");if(cr(this))throw new TypeError("ReadableStream.prototype.pipeThrough cannot be used on a locked ReadableStream");if(rt(r.writable))throw new TypeError("ReadableStream.prototype.pipeThrough cannot be used on a locked WritableStream");return p(Mt(this,r.writable,o.preventClose,o.preventAbort,o.preventCancel,o.signal)),r.readable}pipeTo(e,t={}){if(!ur(this))return d(_r("pipeTo"));if(void 0===e)return d("Parameter 1 is required in 'pipeTo'.");if(!tt(e))return d(new TypeError("ReadableStream.prototype.pipeTo's first argument must be a WritableStream"));let r;try{r=ar(t,"Second parameter")}catch(e){return d(e)}return cr(this)?d(new TypeError("ReadableStream.prototype.pipeTo cannot be used on a locked ReadableStream")):rt(e)?d(new TypeError("ReadableStream.prototype.pipeTo cannot be used on a locked WritableStream")):Mt(this,e,r.preventClose,r.preventAbort,r.preventCancel,r.signal)}tee(){if(!ur(this))throw _r("tee");return ne(Zt(this))}values(e){if(!ur(this))throw _r("values");return function(e,t){const r=N(e),o=new Z(r,t),n=Object.create(ee);return n._asyncIteratorImpl=o,n}(this,function(e,t){F(e,t);const r=null==e?void 0:e.preventCancel;return{preventCancel:Boolean(r)}}(e,"First parameter").preventCancel)}}function ir(e,t,r,o=1,n=(()=>1)){const a=Object.create(ReadableStream.prototype);sr(a);return Jt(a,Object.create(ReadableStreamDefaultController.prototype),e,t,r,o,n),a}function lr(e,t,r){const o=Object.create(ReadableStream.prototype);sr(o);return je(o,Object.create(ReadableByteStreamController.prototype),e,t,r,0,void 0),o}function sr(e){e._state="readable",e._reader=void 0,e._storedError=void 0,e._disturbed=!1}function ur(e){return!!o(e)&&(!!Object.prototype.hasOwnProperty.call(e,"_readableStreamController")&&e instanceof ReadableStream)}function cr(e){return void 0!==e._reader}function dr(e,t){if(e._disturbed=!0,"closed"===e._state)return c(void 0);if("errored"===e._state)return d(e._storedError);fr(e);const o=e._reader;void 0!==o&&$e(o)&&(o._readIntoRequests.forEach((e=>{e._closeSteps(void 0)})),o._readIntoRequests=new v);return m(e._readableStreamController[k](t),r)}function fr(e){e._state="closed";const t=e._reader;void 0!==t&&(W(t),X(t)&&(t._readRequests.forEach((e=>{e._closeSteps()})),t._readRequests=new v))}function br(e,t){e._state="errored",e._storedError=t;const r=e._reader;void 0!==r&&(E(r,t),X(r)?(r._readRequests.forEach((e=>{e._errorSteps(t)})),r._readRequests=new v):(r._readIntoRequests.forEach((e=>{e._errorSteps(t)})),r._readIntoRequests=new v))}function _r(e){return new TypeError(`ReadableStream.prototype.${e} can only be used on a ReadableStream`)}function hr(e,t){F(e,t);const r=null==e?void 0:e.highWaterMark;return $(r,"highWaterMark","QueuingStrategyInit"),{highWaterMark:M(r)}}Object.defineProperties(ReadableStream.prototype,{cancel:{enumerable:!0},getReader:{enumerable:!0},pipeThrough:{enumerable:!0},pipeTo:{enumerable:!0},tee:{enumerable:!0},values:{enumerable:!0},locked:{enumerable:!0}}),"symbol"==typeof t.toStringTag&&Object.defineProperty(ReadableStream.prototype,t.toStringTag,{value:"ReadableStream",configurable:!0}),"symbol"==typeof t.asyncIterator&&Object.defineProperty(ReadableStream.prototype,t.asyncIterator,{value:ReadableStream.prototype.values,writable:!0,configurable:!0});const mr=e=>e.byteLength;Object.defineProperty(mr,"name",{value:"size",configurable:!0});class ByteLengthQueuingStrategy{constructor(e){D(e,1,"ByteLengthQueuingStrategy"),e=hr(e,"First parameter"),this._byteLengthQueuingStrategyHighWaterMark=e.highWaterMark}get highWaterMark(){if(!yr(this))throw pr("highWaterMark");return this._byteLengthQueuingStrategyHighWaterMark}get size(){if(!yr(this))throw pr("size");return mr}}function pr(e){return new TypeError(`ByteLengthQueuingStrategy.prototype.${e} can only be used on a ByteLengthQueuingStrategy`)}function yr(e){return!!o(e)&&(!!Object.prototype.hasOwnProperty.call(e,"_byteLengthQueuingStrategyHighWaterMark")&&e instanceof ByteLengthQueuingStrategy)}Object.defineProperties(ByteLengthQueuingStrategy.prototype,{highWaterMark:{enumerable:!0},size:{enumerable:!0}}),"symbol"==typeof t.toStringTag&&Object.defineProperty(ByteLengthQueuingStrategy.prototype,t.toStringTag,{value:"ByteLengthQueuingStrategy",configurable:!0});const gr=()=>1;Object.defineProperty(gr,"name",{value:"size",configurable:!0});class CountQueuingStrategy{constructor(e){D(e,1,"CountQueuingStrategy"),e=hr(e,"First parameter"),this._countQueuingStrategyHighWaterMark=e.highWaterMark}get highWaterMark(){if(!vr(this))throw Sr("highWaterMark");return this._countQueuingStrategyHighWaterMark}get size(){if(!vr(this))throw Sr("size");return gr}}function Sr(e){return new TypeError(`CountQueuingStrategy.prototype.${e} can only be used on a CountQueuingStrategy`)}function vr(e){return!!o(e)&&(!!Object.prototype.hasOwnProperty.call(e,"_countQueuingStrategyHighWaterMark")&&e instanceof CountQueuingStrategy)}function wr(e,t,r){return I(e,r),r=>S(e,t,[r])}function Rr(e,t,r){return I(e,r),r=>g(e,t,[r])}function Tr(e,t,r){return I(e,r),(r,o)=>S(e,t,[r,o])}Object.defineProperties(CountQueuingStrategy.prototype,{highWaterMark:{enumerable:!0},size:{enumerable:!0}}),"symbol"==typeof t.toStringTag&&Object.defineProperty(CountQueuingStrategy.prototype,t.toStringTag,{value:"CountQueuingStrategy",configurable:!0});class TransformStream{constructor(e={},t={},r={}){void 0===e&&(e=null);const o=Ne(t,"Second parameter"),n=Ne(r,"Third parameter"),a=function(e,t){F(e,t);const r=null==e?void 0:e.flush,o=null==e?void 0:e.readableType,n=null==e?void 0:e.start,a=null==e?void 0:e.transform,i=null==e?void 0:e.writableType;return{flush:void 0===r?void 0:wr(r,e,`${t} has member 'flush' that`),readableType:o,start:void 0===n?void 0:Rr(n,e,`${t} has member 'start' that`),transform:void 0===a?void 0:Tr(a,e,`${t} has member 'transform' that`),writableType:i}}(e,"First parameter");if(void 0!==a.readableType)throw new RangeError("Invalid readableType specified");if(void 0!==a.writableType)throw new RangeError("Invalid writableType specified");const i=Ye(n,0),l=xe(n),s=Ye(o,1),f=xe(o);let b;!function(e,t,r,o,n,a){function i(){return t}function l(t){return function(e,t){const r=e._transformStreamController;if(e._backpressure){return m(e._backpressureChangePromise,(()=>{const o=e._writable;if("erroring"===o._state)throw o._storedError;return kr(r,t)}))}return kr(r,t)}(e,t)}function s(t){return function(e,t){return qr(e,t),c(void 0)}(e,t)}function u(){return function(e){const t=e._readable,r=e._transformStreamController,o=r._flushAlgorithm();return Or(r),m(o,(()=>{if("errored"===t._state)throw t._storedError;Ht(t._readableStreamController)}),(r=>{throw qr(e,r),t._storedError}))}(e)}function d(){return function(e){return Er(e,!1),e._backpressureChangePromise}(e)}function f(t){return Pr(e,t),c(void 0)}e._writable=function(e,t,r,o,n=1,a=(()=>1)){const i=Object.create(WritableStream.prototype);return et(i),gt(i,Object.create(WritableStreamDefaultController.prototype),e,t,r,o,n,a),i}(i,l,u,s,r,o),e._readable=ir(i,d,f,n,a),e._backpressure=void 0,e._backpressureChangePromise=void 0,e._backpressureChangePromise_resolve=void 0,Er(e,!0),e._transformStreamController=void 0}(this,u((e=>{b=e})),s,f,i,l),function(e,t){const r=Object.create(TransformStreamDefaultController.prototype);let o=e=>{try{return Br(r,e),c(void 0)}catch(e){return d(e)}},n=()=>c(void 0);void 0!==t.transform&&(o=e=>t.transform(e,r));void 0!==t.flush&&(n=()=>t.flush(r));!function(e,t,r,o){t._controlledTransformStream=e,e._transformStreamController=t,t._transformAlgorithm=r,t._flushAlgorithm=o}(e,r,o,n)}(this,a),void 0!==a.start?b(a.start(this._transformStreamController)):b(void 0)}get readable(){if(!Cr(this))throw Ar("readable");return this._readable}get writable(){if(!Cr(this))throw Ar("writable");return this._writable}}function Cr(e){return!!o(e)&&(!!Object.prototype.hasOwnProperty.call(e,"_transformStreamController")&&e instanceof TransformStream)}function qr(e,t){Ut(e._readable._readableStreamController,t),Pr(e,t)}function Pr(e,t){Or(e._transformStreamController),Rt(e._writable._writableStreamController,t),e._backpressure&&Er(e,!1)}function Er(e,t){void 0!==e._backpressureChangePromise&&e._backpressureChangePromise_resolve(),e._backpressureChangePromise=u((t=>{e._backpressureChangePromise_resolve=t})),e._backpressure=t}Object.defineProperties(TransformStream.prototype,{readable:{enumerable:!0},writable:{enumerable:!0}}),"symbol"==typeof t.toStringTag&&Object.defineProperty(TransformStream.prototype,t.toStringTag,{value:"TransformStream",configurable:!0});class TransformStreamDefaultController{constructor(){throw new TypeError("Illegal constructor")}get desiredSize(){if(!Wr(this))throw jr("desiredSize");return Gt(this._controlledTransformStream._readable._readableStreamController)}enqueue(e){if(!Wr(this))throw jr("enqueue");Br(this,e)}error(e){if(!Wr(this))throw jr("error");var t;t=e,qr(this._controlledTransformStream,t)}terminate(){if(!Wr(this))throw jr("terminate");!function(e){const t=e._controlledTransformStream;Ht(t._readable._readableStreamController);const r=new TypeError("TransformStream terminated");Pr(t,r)}(this)}}function Wr(e){return!!o(e)&&(!!Object.prototype.hasOwnProperty.call(e,"_controlledTransformStream")&&e instanceof TransformStreamDefaultController)}function Or(e){e._transformAlgorithm=void 0,e._flushAlgorithm=void 0}function Br(e,t){const r=e._controlledTransformStream,o=r._readable._readableStreamController;if(!Xt(o))throw new TypeError("Readable side is not in a state that permits enqueue");try{Vt(o,t)}catch(e){throw Pr(r,e),r._readable._storedError}(function(e){return!xt(e)})(o)!==r._backpressure&&Er(r,!0)}function kr(e,t){return m(e._transformAlgorithm(t),void 0,(t=>{throw qr(e._controlledTransformStream,t),t}))}function jr(e){return new TypeError(`TransformStreamDefaultController.prototype.${e} can only be used on a TransformStreamDefaultController`)}function Ar(e){return new TypeError(`TransformStream.prototype.${e} can only be used on a TransformStream`)}Object.defineProperties(TransformStreamDefaultController.prototype,{enqueue:{enumerable:!0},error:{enumerable:!0},terminate:{enumerable:!0},desiredSize:{enumerable:!0}}),"symbol"==typeof t.toStringTag&&Object.defineProperty(TransformStreamDefaultController.prototype,t.toStringTag,{value:"TransformStreamDefaultController",configurable:!0}),e.ByteLengthQueuingStrategy=ByteLengthQueuingStrategy,e.CountQueuingStrategy=CountQueuingStrategy,e.ReadableByteStreamController=ReadableByteStreamController,e.ReadableStream=ReadableStream,e.ReadableStreamBYOBReader=ReadableStreamBYOBReader,e.ReadableStreamBYOBRequest=ReadableStreamBYOBRequest,e.ReadableStreamDefaultController=ReadableStreamDefaultController,e.ReadableStreamDefaultReader=ReadableStreamDefaultReader,e.TransformStream=TransformStream,e.TransformStreamDefaultController=TransformStreamDefaultController,e.WritableStream=WritableStream,e.WritableStreamDefaultController=WritableStreamDefaultController,e.WritableStreamDefaultWriter=WritableStreamDefaultWriter,Object.defineProperty(e,"__esModule",{value:!0})}));
|