web-streams-polyfill 3.2.0 → 3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +11 -14
- package/dist/polyfill.es2018.js +723 -185
- package/dist/polyfill.es2018.js.map +1 -1
- package/dist/polyfill.es2018.min.js +8 -1
- package/dist/polyfill.es2018.min.js.map +1 -1
- package/dist/polyfill.es2018.mjs +721 -181
- package/dist/polyfill.es2018.mjs.map +1 -1
- package/dist/polyfill.es6.js +789 -185
- package/dist/polyfill.es6.js.map +1 -1
- package/dist/polyfill.es6.min.js +8 -1
- package/dist/polyfill.es6.min.js.map +1 -1
- package/dist/polyfill.es6.mjs +787 -181
- package/dist/polyfill.es6.mjs.map +1 -1
- package/dist/polyfill.js +873 -231
- package/dist/polyfill.js.map +1 -1
- package/dist/polyfill.min.js +8 -1
- package/dist/polyfill.min.js.map +1 -1
- package/dist/polyfill.mjs +871 -227
- package/dist/polyfill.mjs.map +1 -1
- package/dist/ponyfill.es2018.js +723 -185
- package/dist/ponyfill.es2018.js.map +1 -1
- package/dist/ponyfill.es2018.mjs +721 -181
- package/dist/ponyfill.es2018.mjs.map +1 -1
- package/dist/ponyfill.es6.js +789 -185
- package/dist/ponyfill.es6.js.map +1 -1
- package/dist/ponyfill.es6.mjs +787 -181
- package/dist/ponyfill.es6.mjs.map +1 -1
- package/dist/ponyfill.js +873 -231
- package/dist/ponyfill.js.map +1 -1
- package/dist/ponyfill.mjs +871 -227
- package/dist/ponyfill.mjs.map +1 -1
- package/es2018/package.json +1 -1
- package/es6/package.json +1 -1
- package/package.json +30 -32
- package/ponyfill/es2018/package.json +1 -1
- package/ponyfill/es6/package.json +1 -1
- package/ponyfill/package.json +1 -1
- package/types/polyfill.d.ts +29 -0
- package/{dist/types/ts3.6/polyfill.d.ts → types/ponyfill.d.ts} +57 -7
- package/{dist/types → types}/tsdoc-metadata.json +1 -1
- package/CHANGELOG.md +0 -134
- package/dist/types/polyfill.d.ts +0 -771
package/dist/ponyfill.mjs
CHANGED
|
@@ -1,44 +1,140 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* @license
|
|
3
|
+
* web-streams-polyfill v3.3.0
|
|
4
|
+
* Copyright 2024 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
8
|
/// <reference lib="es2015.symbol" />
|
|
5
9
|
var SymbolPolyfill = typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol' ?
|
|
6
10
|
Symbol :
|
|
7
|
-
function (description) { return "Symbol("
|
|
11
|
+
function (description) { return "Symbol(".concat(description, ")"); };
|
|
12
|
+
|
|
13
|
+
/******************************************************************************
|
|
14
|
+
Copyright (c) Microsoft Corporation.
|
|
15
|
+
|
|
16
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
17
|
+
purpose with or without fee is hereby granted.
|
|
18
|
+
|
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
20
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
21
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
22
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
23
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
24
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
25
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
26
|
+
***************************************************************************** */
|
|
27
|
+
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
function __generator(thisArg, body) {
|
|
31
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
32
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
33
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
34
|
+
function step(op) {
|
|
35
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
36
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
37
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
38
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
39
|
+
switch (op[0]) {
|
|
40
|
+
case 0: case 1: t = op; break;
|
|
41
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
42
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
43
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
44
|
+
default:
|
|
45
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
46
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
47
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
48
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
49
|
+
if (t[2]) _.ops.pop();
|
|
50
|
+
_.trys.pop(); continue;
|
|
51
|
+
}
|
|
52
|
+
op = body.call(thisArg, _);
|
|
53
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
54
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function __values(o) {
|
|
59
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
60
|
+
if (m) return m.call(o);
|
|
61
|
+
if (o && typeof o.length === "number") return {
|
|
62
|
+
next: function () {
|
|
63
|
+
if (o && i >= o.length) o = void 0;
|
|
64
|
+
return { value: o && o[i++], done: !o };
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function __await(v) {
|
|
71
|
+
return this instanceof __await ? (this.v = v, this) : new __await(v);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function __asyncGenerator(thisArg, _arguments, generator) {
|
|
75
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
76
|
+
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
77
|
+
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
78
|
+
function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
|
|
79
|
+
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
80
|
+
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
81
|
+
function fulfill(value) { resume("next", value); }
|
|
82
|
+
function reject(value) { resume("throw", value); }
|
|
83
|
+
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function __asyncDelegator(o) {
|
|
87
|
+
var i, p;
|
|
88
|
+
return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
|
|
89
|
+
function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: false } : f ? f(v) : v; } : f; }
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function __asyncValues(o) {
|
|
93
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
94
|
+
var m = o[Symbol.asyncIterator], i;
|
|
95
|
+
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
96
|
+
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
97
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
101
|
+
var e = new Error(message);
|
|
102
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
103
|
+
};
|
|
8
104
|
|
|
9
|
-
/// <reference lib="dom" />
|
|
10
105
|
function noop() {
|
|
11
106
|
return undefined;
|
|
12
107
|
}
|
|
13
|
-
function getGlobals() {
|
|
14
|
-
if (typeof self !== 'undefined') {
|
|
15
|
-
return self;
|
|
16
|
-
}
|
|
17
|
-
else if (typeof window !== 'undefined') {
|
|
18
|
-
return window;
|
|
19
|
-
}
|
|
20
|
-
else if (typeof global !== 'undefined') {
|
|
21
|
-
return global;
|
|
22
|
-
}
|
|
23
|
-
return undefined;
|
|
24
|
-
}
|
|
25
|
-
var globals = getGlobals();
|
|
26
108
|
|
|
27
109
|
function typeIsObject(x) {
|
|
28
110
|
return (typeof x === 'object' && x !== null) || typeof x === 'function';
|
|
29
111
|
}
|
|
30
112
|
var rethrowAssertionErrorRejection = noop;
|
|
113
|
+
function setFunctionName(fn, name) {
|
|
114
|
+
try {
|
|
115
|
+
Object.defineProperty(fn, 'name', {
|
|
116
|
+
value: name,
|
|
117
|
+
configurable: true
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
catch (_a) {
|
|
121
|
+
// This property is non-configurable in older browsers, so ignore if this throws.
|
|
122
|
+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name#browser_compatibility
|
|
123
|
+
}
|
|
124
|
+
}
|
|
31
125
|
|
|
32
126
|
var originalPromise = Promise;
|
|
33
127
|
var originalPromiseThen = Promise.prototype.then;
|
|
34
|
-
var originalPromiseResolve = Promise.resolve.bind(originalPromise);
|
|
35
128
|
var originalPromiseReject = Promise.reject.bind(originalPromise);
|
|
129
|
+
// https://webidl.spec.whatwg.org/#a-new-promise
|
|
36
130
|
function newPromise(executor) {
|
|
37
131
|
return new originalPromise(executor);
|
|
38
132
|
}
|
|
133
|
+
// https://webidl.spec.whatwg.org/#a-promise-resolved-with
|
|
39
134
|
function promiseResolvedWith(value) {
|
|
40
|
-
return
|
|
135
|
+
return newPromise(function (resolve) { return resolve(value); });
|
|
41
136
|
}
|
|
137
|
+
// https://webidl.spec.whatwg.org/#a-promise-rejected-with
|
|
42
138
|
function promiseRejectedWith(reason) {
|
|
43
139
|
return originalPromiseReject(reason);
|
|
44
140
|
}
|
|
@@ -47,6 +143,9 @@ function PerformPromiseThen(promise, onFulfilled, onRejected) {
|
|
|
47
143
|
// approximation.
|
|
48
144
|
return originalPromiseThen.call(promise, onFulfilled, onRejected);
|
|
49
145
|
}
|
|
146
|
+
// Bluebird logs a warning when a promise is created within a fulfillment handler, but then isn't returned
|
|
147
|
+
// from that handler. To prevent this, return null instead of void from all handlers.
|
|
148
|
+
// http://bluebirdjs.com/docs/warning-explanations.html#warning-a-promise-was-created-in-a-handler-but-was-not-returned-from-it
|
|
50
149
|
function uponPromise(promise, onFulfilled, onRejected) {
|
|
51
150
|
PerformPromiseThen(PerformPromiseThen(promise, onFulfilled, onRejected), undefined, rethrowAssertionErrorRejection);
|
|
52
151
|
}
|
|
@@ -62,14 +161,16 @@ function transformPromiseWith(promise, fulfillmentHandler, rejectionHandler) {
|
|
|
62
161
|
function setPromiseIsHandledToTrue(promise) {
|
|
63
162
|
PerformPromiseThen(promise, undefined, rethrowAssertionErrorRejection);
|
|
64
163
|
}
|
|
65
|
-
var
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
164
|
+
var _queueMicrotask = function (callback) {
|
|
165
|
+
if (typeof queueMicrotask === 'function') {
|
|
166
|
+
_queueMicrotask = queueMicrotask;
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
var resolvedPromise_1 = promiseResolvedWith(undefined);
|
|
170
|
+
_queueMicrotask = function (cb) { return PerformPromiseThen(resolvedPromise_1, cb); };
|
|
69
171
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
})();
|
|
172
|
+
return _queueMicrotask(callback);
|
|
173
|
+
};
|
|
73
174
|
function reflectCall(F, V, args) {
|
|
74
175
|
if (typeof F !== 'function') {
|
|
75
176
|
throw new TypeError('Argument is not a function');
|
|
@@ -198,6 +299,12 @@ var SimpleQueue = /** @class */ (function () {
|
|
|
198
299
|
return SimpleQueue;
|
|
199
300
|
}());
|
|
200
301
|
|
|
302
|
+
var AbortSteps = SymbolPolyfill('[[AbortSteps]]');
|
|
303
|
+
var ErrorSteps = SymbolPolyfill('[[ErrorSteps]]');
|
|
304
|
+
var CancelSteps = SymbolPolyfill('[[CancelSteps]]');
|
|
305
|
+
var PullSteps = SymbolPolyfill('[[PullSteps]]');
|
|
306
|
+
var ReleaseSteps = SymbolPolyfill('[[ReleaseSteps]]');
|
|
307
|
+
|
|
201
308
|
function ReadableStreamReaderGenericInitialize(reader, stream) {
|
|
202
309
|
reader._ownerReadableStream = stream;
|
|
203
310
|
stream._reader = reader;
|
|
@@ -218,13 +325,15 @@ function ReadableStreamReaderGenericCancel(reader, reason) {
|
|
|
218
325
|
return ReadableStreamCancel(stream, reason);
|
|
219
326
|
}
|
|
220
327
|
function ReadableStreamReaderGenericRelease(reader) {
|
|
221
|
-
|
|
328
|
+
var stream = reader._ownerReadableStream;
|
|
329
|
+
if (stream._state === 'readable') {
|
|
222
330
|
defaultReaderClosedPromiseReject(reader, new TypeError("Reader was released and can no longer be used to monitor the stream's closedness"));
|
|
223
331
|
}
|
|
224
332
|
else {
|
|
225
333
|
defaultReaderClosedPromiseResetToRejected(reader, new TypeError("Reader was released and can no longer be used to monitor the stream's closedness"));
|
|
226
334
|
}
|
|
227
|
-
|
|
335
|
+
stream._readableStreamController[ReleaseSteps]();
|
|
336
|
+
stream._reader = undefined;
|
|
228
337
|
reader._ownerReadableStream = undefined;
|
|
229
338
|
}
|
|
230
339
|
// Helper functions for the readers.
|
|
@@ -267,11 +376,6 @@ function defaultReaderClosedPromiseResolve(reader) {
|
|
|
267
376
|
reader._closedPromise_reject = undefined;
|
|
268
377
|
}
|
|
269
378
|
|
|
270
|
-
var AbortSteps = SymbolPolyfill('[[AbortSteps]]');
|
|
271
|
-
var ErrorSteps = SymbolPolyfill('[[ErrorSteps]]');
|
|
272
|
-
var CancelSteps = SymbolPolyfill('[[CancelSteps]]');
|
|
273
|
-
var PullSteps = SymbolPolyfill('[[PullSteps]]');
|
|
274
|
-
|
|
275
379
|
/// <reference lib="es2015.core" />
|
|
276
380
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isFinite#Polyfill
|
|
277
381
|
var NumberIsFinite = Number.isFinite || function (x) {
|
|
@@ -290,13 +394,13 @@ function isDictionary(x) {
|
|
|
290
394
|
}
|
|
291
395
|
function assertDictionary(obj, context) {
|
|
292
396
|
if (obj !== undefined && !isDictionary(obj)) {
|
|
293
|
-
throw new TypeError(context
|
|
397
|
+
throw new TypeError("".concat(context, " is not an object."));
|
|
294
398
|
}
|
|
295
399
|
}
|
|
296
400
|
// https://heycam.github.io/webidl/#idl-callback-functions
|
|
297
401
|
function assertFunction(x, context) {
|
|
298
402
|
if (typeof x !== 'function') {
|
|
299
|
-
throw new TypeError(context
|
|
403
|
+
throw new TypeError("".concat(context, " is not a function."));
|
|
300
404
|
}
|
|
301
405
|
}
|
|
302
406
|
// https://heycam.github.io/webidl/#idl-object
|
|
@@ -305,17 +409,17 @@ function isObject(x) {
|
|
|
305
409
|
}
|
|
306
410
|
function assertObject(x, context) {
|
|
307
411
|
if (!isObject(x)) {
|
|
308
|
-
throw new TypeError(context
|
|
412
|
+
throw new TypeError("".concat(context, " is not an object."));
|
|
309
413
|
}
|
|
310
414
|
}
|
|
311
415
|
function assertRequiredArgument(x, position, context) {
|
|
312
416
|
if (x === undefined) {
|
|
313
|
-
throw new TypeError("Parameter "
|
|
417
|
+
throw new TypeError("Parameter ".concat(position, " is required in '").concat(context, "'."));
|
|
314
418
|
}
|
|
315
419
|
}
|
|
316
420
|
function assertRequiredField(x, field, context) {
|
|
317
421
|
if (x === undefined) {
|
|
318
|
-
throw new TypeError(field
|
|
422
|
+
throw new TypeError("".concat(field, " is required in '").concat(context, "'."));
|
|
319
423
|
}
|
|
320
424
|
}
|
|
321
425
|
// https://heycam.github.io/webidl/#idl-unrestricted-double
|
|
@@ -335,11 +439,11 @@ function convertUnsignedLongLongWithEnforceRange(value, context) {
|
|
|
335
439
|
var x = Number(value);
|
|
336
440
|
x = censorNegativeZero(x);
|
|
337
441
|
if (!NumberIsFinite(x)) {
|
|
338
|
-
throw new TypeError(context
|
|
442
|
+
throw new TypeError("".concat(context, " is not a finite number"));
|
|
339
443
|
}
|
|
340
444
|
x = integerPart(x);
|
|
341
445
|
if (x < lowerBound || x > upperBound) {
|
|
342
|
-
throw new TypeError(context
|
|
446
|
+
throw new TypeError("".concat(context, " is outside the accepted range of ").concat(lowerBound, " to ").concat(upperBound, ", inclusive"));
|
|
343
447
|
}
|
|
344
448
|
if (!NumberIsFinite(x) || x === 0) {
|
|
345
449
|
return 0;
|
|
@@ -353,7 +457,7 @@ function convertUnsignedLongLongWithEnforceRange(value, context) {
|
|
|
353
457
|
|
|
354
458
|
function assertReadableStream(x, context) {
|
|
355
459
|
if (!IsReadableStream(x)) {
|
|
356
|
-
throw new TypeError(context
|
|
460
|
+
throw new TypeError("".concat(context, " is not a ReadableStream."));
|
|
357
461
|
}
|
|
358
462
|
}
|
|
359
463
|
|
|
@@ -472,10 +576,7 @@ var ReadableStreamDefaultReader = /** @class */ (function () {
|
|
|
472
576
|
if (this._ownerReadableStream === undefined) {
|
|
473
577
|
return;
|
|
474
578
|
}
|
|
475
|
-
|
|
476
|
-
throw new TypeError('Tried to release a reader lock when that reader has pending read() calls un-settled');
|
|
477
|
-
}
|
|
478
|
-
ReadableStreamReaderGenericRelease(this);
|
|
579
|
+
ReadableStreamDefaultReaderRelease(this);
|
|
479
580
|
};
|
|
480
581
|
return ReadableStreamDefaultReader;
|
|
481
582
|
}());
|
|
@@ -485,6 +586,9 @@ Object.defineProperties(ReadableStreamDefaultReader.prototype, {
|
|
|
485
586
|
releaseLock: { enumerable: true },
|
|
486
587
|
closed: { enumerable: true }
|
|
487
588
|
});
|
|
589
|
+
setFunctionName(ReadableStreamDefaultReader.prototype.cancel, 'cancel');
|
|
590
|
+
setFunctionName(ReadableStreamDefaultReader.prototype.read, 'read');
|
|
591
|
+
setFunctionName(ReadableStreamDefaultReader.prototype.releaseLock, 'releaseLock');
|
|
488
592
|
if (typeof SymbolPolyfill.toStringTag === 'symbol') {
|
|
489
593
|
Object.defineProperty(ReadableStreamDefaultReader.prototype, SymbolPolyfill.toStringTag, {
|
|
490
594
|
value: 'ReadableStreamDefaultReader',
|
|
@@ -514,9 +618,21 @@ function ReadableStreamDefaultReaderRead(reader, readRequest) {
|
|
|
514
618
|
stream._readableStreamController[PullSteps](readRequest);
|
|
515
619
|
}
|
|
516
620
|
}
|
|
621
|
+
function ReadableStreamDefaultReaderRelease(reader) {
|
|
622
|
+
ReadableStreamReaderGenericRelease(reader);
|
|
623
|
+
var e = new TypeError('Reader was released');
|
|
624
|
+
ReadableStreamDefaultReaderErrorReadRequests(reader, e);
|
|
625
|
+
}
|
|
626
|
+
function ReadableStreamDefaultReaderErrorReadRequests(reader, e) {
|
|
627
|
+
var readRequests = reader._readRequests;
|
|
628
|
+
reader._readRequests = new SimpleQueue();
|
|
629
|
+
readRequests.forEach(function (readRequest) {
|
|
630
|
+
readRequest._errorSteps(e);
|
|
631
|
+
});
|
|
632
|
+
}
|
|
517
633
|
// Helper functions for the ReadableStreamDefaultReader.
|
|
518
634
|
function defaultReaderBrandCheckException(name) {
|
|
519
|
-
return new TypeError("ReadableStreamDefaultReader.prototype."
|
|
635
|
+
return new TypeError("ReadableStreamDefaultReader.prototype.".concat(name, " can only be used on a ReadableStreamDefaultReader"));
|
|
520
636
|
}
|
|
521
637
|
|
|
522
638
|
/// <reference lib="es2018.asynciterable" />
|
|
@@ -564,9 +680,6 @@ var ReadableStreamAsyncIteratorImpl = /** @class */ (function () {
|
|
|
564
680
|
return Promise.resolve({ value: undefined, done: true });
|
|
565
681
|
}
|
|
566
682
|
var reader = this._reader;
|
|
567
|
-
if (reader._ownerReadableStream === undefined) {
|
|
568
|
-
return promiseRejectedWith(readerLockException('iterate'));
|
|
569
|
-
}
|
|
570
683
|
var resolvePromise;
|
|
571
684
|
var rejectPromise;
|
|
572
685
|
var promise = newPromise(function (resolve, reject) {
|
|
@@ -578,7 +691,7 @@ var ReadableStreamAsyncIteratorImpl = /** @class */ (function () {
|
|
|
578
691
|
_this._ongoingPromise = undefined;
|
|
579
692
|
// This needs to be delayed by one microtask, otherwise we stop pulling too early which breaks a test.
|
|
580
693
|
// FIXME Is this a bug in the specification, or in the test?
|
|
581
|
-
|
|
694
|
+
_queueMicrotask(function () { return resolvePromise({ value: chunk, done: false }); });
|
|
582
695
|
},
|
|
583
696
|
_closeSteps: function () {
|
|
584
697
|
_this._ongoingPromise = undefined;
|
|
@@ -602,9 +715,6 @@ var ReadableStreamAsyncIteratorImpl = /** @class */ (function () {
|
|
|
602
715
|
}
|
|
603
716
|
this._isFinished = true;
|
|
604
717
|
var reader = this._reader;
|
|
605
|
-
if (reader._ownerReadableStream === undefined) {
|
|
606
|
-
return promiseRejectedWith(readerLockException('finish iterating'));
|
|
607
|
-
}
|
|
608
718
|
if (!this._preventCancel) {
|
|
609
719
|
var result = ReadableStreamReaderGenericCancel(reader, value);
|
|
610
720
|
ReadableStreamReaderGenericRelease(reader);
|
|
@@ -658,7 +768,7 @@ function IsReadableStreamAsyncIterator(x) {
|
|
|
658
768
|
}
|
|
659
769
|
// Helper functions for the ReadableStream.
|
|
660
770
|
function streamAsyncIteratorBrandCheckException(name) {
|
|
661
|
-
return new TypeError("ReadableStreamAsyncIterator."
|
|
771
|
+
return new TypeError("ReadableStreamAsyncIterator.".concat(name, " can only be used on a ReadableSteamAsyncIterator"));
|
|
662
772
|
}
|
|
663
773
|
|
|
664
774
|
/// <reference lib="es2015.core" />
|
|
@@ -676,15 +786,29 @@ function CreateArrayFromList(elements) {
|
|
|
676
786
|
function CopyDataBlockBytes(dest, destOffset, src, srcOffset, n) {
|
|
677
787
|
new Uint8Array(dest).set(new Uint8Array(src, srcOffset, n), destOffset);
|
|
678
788
|
}
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
}
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
789
|
+
var TransferArrayBuffer = function (O) {
|
|
790
|
+
if (typeof O.transfer === 'function') {
|
|
791
|
+
TransferArrayBuffer = function (buffer) { return buffer.transfer(); };
|
|
792
|
+
}
|
|
793
|
+
else if (typeof structuredClone === 'function') {
|
|
794
|
+
TransferArrayBuffer = function (buffer) { return structuredClone(buffer, { transfer: [buffer] }); };
|
|
795
|
+
}
|
|
796
|
+
else {
|
|
797
|
+
// Not implemented correctly
|
|
798
|
+
TransferArrayBuffer = function (buffer) { return buffer; };
|
|
799
|
+
}
|
|
800
|
+
return TransferArrayBuffer(O);
|
|
801
|
+
};
|
|
802
|
+
var IsDetachedBuffer = function (O) {
|
|
803
|
+
if (typeof O.detached === 'boolean') {
|
|
804
|
+
IsDetachedBuffer = function (buffer) { return buffer.detached; };
|
|
805
|
+
}
|
|
806
|
+
else {
|
|
807
|
+
// Not implemented correctly
|
|
808
|
+
IsDetachedBuffer = function (buffer) { return buffer.byteLength === 0; };
|
|
809
|
+
}
|
|
810
|
+
return IsDetachedBuffer(O);
|
|
811
|
+
};
|
|
688
812
|
function ArrayBufferSlice(buffer, begin, end) {
|
|
689
813
|
// ArrayBuffer.prototype.slice is not available on IE10
|
|
690
814
|
// https://www.caniuse.com/mdn-javascript_builtins_arraybuffer_slice
|
|
@@ -696,6 +820,79 @@ function ArrayBufferSlice(buffer, begin, end) {
|
|
|
696
820
|
CopyDataBlockBytes(slice, 0, buffer, begin, length);
|
|
697
821
|
return slice;
|
|
698
822
|
}
|
|
823
|
+
function GetMethod(receiver, prop) {
|
|
824
|
+
var func = receiver[prop];
|
|
825
|
+
if (func === undefined || func === null) {
|
|
826
|
+
return undefined;
|
|
827
|
+
}
|
|
828
|
+
if (typeof func !== 'function') {
|
|
829
|
+
throw new TypeError("".concat(String(prop), " is not a function"));
|
|
830
|
+
}
|
|
831
|
+
return func;
|
|
832
|
+
}
|
|
833
|
+
function CreateAsyncFromSyncIterator(syncIteratorRecord) {
|
|
834
|
+
// Instead of re-implementing CreateAsyncFromSyncIterator and %AsyncFromSyncIteratorPrototype%,
|
|
835
|
+
// we use yield* inside an async generator function to achieve the same result.
|
|
836
|
+
var _a;
|
|
837
|
+
// Wrap the sync iterator inside a sync iterable, so we can use it with yield*.
|
|
838
|
+
var syncIterable = (_a = {},
|
|
839
|
+
_a[SymbolPolyfill.iterator] = function () { return syncIteratorRecord.iterator; },
|
|
840
|
+
_a);
|
|
841
|
+
// Create an async generator function and immediately invoke it.
|
|
842
|
+
var asyncIterator = (function () {
|
|
843
|
+
return __asyncGenerator(this, arguments, function () {
|
|
844
|
+
return __generator(this, function (_a) {
|
|
845
|
+
switch (_a.label) {
|
|
846
|
+
case 0: return [5 /*yield**/, __values(__asyncDelegator(__asyncValues(syncIterable)))];
|
|
847
|
+
case 1: return [4 /*yield*/, __await.apply(void 0, [_a.sent()])];
|
|
848
|
+
case 2: return [4 /*yield*/, __await.apply(void 0, [_a.sent()])];
|
|
849
|
+
case 3: return [2 /*return*/, _a.sent()];
|
|
850
|
+
}
|
|
851
|
+
});
|
|
852
|
+
});
|
|
853
|
+
}());
|
|
854
|
+
// Return as an async iterator record.
|
|
855
|
+
var nextMethod = asyncIterator.next;
|
|
856
|
+
return { iterator: asyncIterator, nextMethod: nextMethod, done: false };
|
|
857
|
+
}
|
|
858
|
+
function GetIterator(obj, hint, method) {
|
|
859
|
+
if (hint === void 0) { hint = 'sync'; }
|
|
860
|
+
if (method === undefined) {
|
|
861
|
+
if (hint === 'async') {
|
|
862
|
+
method = GetMethod(obj, SymbolPolyfill.asyncIterator);
|
|
863
|
+
if (method === undefined) {
|
|
864
|
+
var syncMethod = GetMethod(obj, SymbolPolyfill.iterator);
|
|
865
|
+
var syncIteratorRecord = GetIterator(obj, 'sync', syncMethod);
|
|
866
|
+
return CreateAsyncFromSyncIterator(syncIteratorRecord);
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
else {
|
|
870
|
+
method = GetMethod(obj, SymbolPolyfill.iterator);
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
if (method === undefined) {
|
|
874
|
+
throw new TypeError('The object is not iterable');
|
|
875
|
+
}
|
|
876
|
+
var iterator = reflectCall(method, obj, []);
|
|
877
|
+
if (!typeIsObject(iterator)) {
|
|
878
|
+
throw new TypeError('The iterator method must return an object');
|
|
879
|
+
}
|
|
880
|
+
var nextMethod = iterator.next;
|
|
881
|
+
return { iterator: iterator, nextMethod: nextMethod, done: false };
|
|
882
|
+
}
|
|
883
|
+
function IteratorNext(iteratorRecord) {
|
|
884
|
+
var result = reflectCall(iteratorRecord.nextMethod, iteratorRecord.iterator, []);
|
|
885
|
+
if (!typeIsObject(result)) {
|
|
886
|
+
throw new TypeError('The iterator.next() method must return an object');
|
|
887
|
+
}
|
|
888
|
+
return result;
|
|
889
|
+
}
|
|
890
|
+
function IteratorComplete(iterResult) {
|
|
891
|
+
return Boolean(iterResult.done);
|
|
892
|
+
}
|
|
893
|
+
function IteratorValue(iterResult) {
|
|
894
|
+
return iterResult.value;
|
|
895
|
+
}
|
|
699
896
|
|
|
700
897
|
function IsNonNegativeNumber(v) {
|
|
701
898
|
if (typeof v !== 'number') {
|
|
@@ -738,6 +935,19 @@ function ResetQueue(container) {
|
|
|
738
935
|
container._queueTotalSize = 0;
|
|
739
936
|
}
|
|
740
937
|
|
|
938
|
+
function isDataViewConstructor(ctor) {
|
|
939
|
+
return ctor === DataView;
|
|
940
|
+
}
|
|
941
|
+
function isDataView(view) {
|
|
942
|
+
return isDataViewConstructor(view.constructor);
|
|
943
|
+
}
|
|
944
|
+
function arrayBufferViewElementSize(ctor) {
|
|
945
|
+
if (isDataViewConstructor(ctor)) {
|
|
946
|
+
return 1;
|
|
947
|
+
}
|
|
948
|
+
return ctor.BYTES_PER_ELEMENT;
|
|
949
|
+
}
|
|
950
|
+
|
|
741
951
|
/**
|
|
742
952
|
* A pull-into request in a {@link ReadableByteStreamController}.
|
|
743
953
|
*
|
|
@@ -769,7 +979,9 @@ var ReadableStreamBYOBRequest = /** @class */ (function () {
|
|
|
769
979
|
if (this._associatedReadableByteStreamController === undefined) {
|
|
770
980
|
throw new TypeError('This BYOB request has been invalidated');
|
|
771
981
|
}
|
|
772
|
-
if (IsDetachedBuffer(this._view.buffer))
|
|
982
|
+
if (IsDetachedBuffer(this._view.buffer)) {
|
|
983
|
+
throw new TypeError("The BYOB request's buffer has been detached and so cannot be used as a response");
|
|
984
|
+
}
|
|
773
985
|
ReadableByteStreamControllerRespond(this._associatedReadableByteStreamController, bytesWritten);
|
|
774
986
|
};
|
|
775
987
|
ReadableStreamBYOBRequest.prototype.respondWithNewView = function (view) {
|
|
@@ -783,7 +995,9 @@ var ReadableStreamBYOBRequest = /** @class */ (function () {
|
|
|
783
995
|
if (this._associatedReadableByteStreamController === undefined) {
|
|
784
996
|
throw new TypeError('This BYOB request has been invalidated');
|
|
785
997
|
}
|
|
786
|
-
if (IsDetachedBuffer(view.buffer))
|
|
998
|
+
if (IsDetachedBuffer(view.buffer)) {
|
|
999
|
+
throw new TypeError('The given view\'s buffer has been detached and so cannot be used as a response');
|
|
1000
|
+
}
|
|
787
1001
|
ReadableByteStreamControllerRespondWithNewView(this._associatedReadableByteStreamController, view);
|
|
788
1002
|
};
|
|
789
1003
|
return ReadableStreamBYOBRequest;
|
|
@@ -793,6 +1007,8 @@ Object.defineProperties(ReadableStreamBYOBRequest.prototype, {
|
|
|
793
1007
|
respondWithNewView: { enumerable: true },
|
|
794
1008
|
view: { enumerable: true }
|
|
795
1009
|
});
|
|
1010
|
+
setFunctionName(ReadableStreamBYOBRequest.prototype.respond, 'respond');
|
|
1011
|
+
setFunctionName(ReadableStreamBYOBRequest.prototype.respondWithNewView, 'respondWithNewView');
|
|
796
1012
|
if (typeof SymbolPolyfill.toStringTag === 'symbol') {
|
|
797
1013
|
Object.defineProperty(ReadableStreamBYOBRequest.prototype, SymbolPolyfill.toStringTag, {
|
|
798
1014
|
value: 'ReadableStreamBYOBRequest',
|
|
@@ -848,7 +1064,7 @@ var ReadableByteStreamController = /** @class */ (function () {
|
|
|
848
1064
|
}
|
|
849
1065
|
var state = this._controlledReadableByteStream._state;
|
|
850
1066
|
if (state !== 'readable') {
|
|
851
|
-
throw new TypeError("The stream (in "
|
|
1067
|
+
throw new TypeError("The stream (in ".concat(state, " state) is not in the readable state and cannot be closed"));
|
|
852
1068
|
}
|
|
853
1069
|
ReadableByteStreamControllerClose(this);
|
|
854
1070
|
};
|
|
@@ -871,7 +1087,7 @@ var ReadableByteStreamController = /** @class */ (function () {
|
|
|
871
1087
|
}
|
|
872
1088
|
var state = this._controlledReadableByteStream._state;
|
|
873
1089
|
if (state !== 'readable') {
|
|
874
|
-
throw new TypeError("The stream (in "
|
|
1090
|
+
throw new TypeError("The stream (in ".concat(state, " state) is not in the readable state and cannot be enqueued to"));
|
|
875
1091
|
}
|
|
876
1092
|
ReadableByteStreamControllerEnqueue(this, chunk);
|
|
877
1093
|
};
|
|
@@ -897,11 +1113,7 @@ var ReadableByteStreamController = /** @class */ (function () {
|
|
|
897
1113
|
ReadableByteStreamController.prototype[PullSteps] = function (readRequest) {
|
|
898
1114
|
var stream = this._controlledReadableByteStream;
|
|
899
1115
|
if (this._queueTotalSize > 0) {
|
|
900
|
-
|
|
901
|
-
this._queueTotalSize -= entry.byteLength;
|
|
902
|
-
ReadableByteStreamControllerHandleQueueDrain(this);
|
|
903
|
-
var view = new Uint8Array(entry.buffer, entry.byteOffset, entry.byteLength);
|
|
904
|
-
readRequest._chunkSteps(view);
|
|
1116
|
+
ReadableByteStreamControllerFillReadRequestFromQueue(this, readRequest);
|
|
905
1117
|
return;
|
|
906
1118
|
}
|
|
907
1119
|
var autoAllocateChunkSize = this._autoAllocateChunkSize;
|
|
@@ -920,6 +1132,7 @@ var ReadableByteStreamController = /** @class */ (function () {
|
|
|
920
1132
|
byteOffset: 0,
|
|
921
1133
|
byteLength: autoAllocateChunkSize,
|
|
922
1134
|
bytesFilled: 0,
|
|
1135
|
+
minimumFill: 1,
|
|
923
1136
|
elementSize: 1,
|
|
924
1137
|
viewConstructor: Uint8Array,
|
|
925
1138
|
readerType: 'default'
|
|
@@ -929,6 +1142,15 @@ var ReadableByteStreamController = /** @class */ (function () {
|
|
|
929
1142
|
ReadableStreamAddReadRequest(stream, readRequest);
|
|
930
1143
|
ReadableByteStreamControllerCallPullIfNeeded(this);
|
|
931
1144
|
};
|
|
1145
|
+
/** @internal */
|
|
1146
|
+
ReadableByteStreamController.prototype[ReleaseSteps] = function () {
|
|
1147
|
+
if (this._pendingPullIntos.length > 0) {
|
|
1148
|
+
var firstPullInto = this._pendingPullIntos.peek();
|
|
1149
|
+
firstPullInto.readerType = 'none';
|
|
1150
|
+
this._pendingPullIntos = new SimpleQueue();
|
|
1151
|
+
this._pendingPullIntos.push(firstPullInto);
|
|
1152
|
+
}
|
|
1153
|
+
};
|
|
932
1154
|
return ReadableByteStreamController;
|
|
933
1155
|
}());
|
|
934
1156
|
Object.defineProperties(ReadableByteStreamController.prototype, {
|
|
@@ -938,6 +1160,9 @@ Object.defineProperties(ReadableByteStreamController.prototype, {
|
|
|
938
1160
|
byobRequest: { enumerable: true },
|
|
939
1161
|
desiredSize: { enumerable: true }
|
|
940
1162
|
});
|
|
1163
|
+
setFunctionName(ReadableByteStreamController.prototype.close, 'close');
|
|
1164
|
+
setFunctionName(ReadableByteStreamController.prototype.enqueue, 'enqueue');
|
|
1165
|
+
setFunctionName(ReadableByteStreamController.prototype.error, 'error');
|
|
941
1166
|
if (typeof SymbolPolyfill.toStringTag === 'symbol') {
|
|
942
1167
|
Object.defineProperty(ReadableByteStreamController.prototype, SymbolPolyfill.toStringTag, {
|
|
943
1168
|
value: 'ReadableByteStreamController',
|
|
@@ -981,8 +1206,10 @@ function ReadableByteStreamControllerCallPullIfNeeded(controller) {
|
|
|
981
1206
|
controller._pullAgain = false;
|
|
982
1207
|
ReadableByteStreamControllerCallPullIfNeeded(controller);
|
|
983
1208
|
}
|
|
1209
|
+
return null;
|
|
984
1210
|
}, function (e) {
|
|
985
1211
|
ReadableByteStreamControllerError(controller, e);
|
|
1212
|
+
return null;
|
|
986
1213
|
});
|
|
987
1214
|
}
|
|
988
1215
|
function ReadableByteStreamControllerClearPendingPullIntos(controller) {
|
|
@@ -1011,15 +1238,33 @@ function ReadableByteStreamControllerEnqueueChunkToQueue(controller, buffer, byt
|
|
|
1011
1238
|
controller._queue.push({ buffer: buffer, byteOffset: byteOffset, byteLength: byteLength });
|
|
1012
1239
|
controller._queueTotalSize += byteLength;
|
|
1013
1240
|
}
|
|
1241
|
+
function ReadableByteStreamControllerEnqueueClonedChunkToQueue(controller, buffer, byteOffset, byteLength) {
|
|
1242
|
+
var clonedChunk;
|
|
1243
|
+
try {
|
|
1244
|
+
clonedChunk = ArrayBufferSlice(buffer, byteOffset, byteOffset + byteLength);
|
|
1245
|
+
}
|
|
1246
|
+
catch (cloneE) {
|
|
1247
|
+
ReadableByteStreamControllerError(controller, cloneE);
|
|
1248
|
+
throw cloneE;
|
|
1249
|
+
}
|
|
1250
|
+
ReadableByteStreamControllerEnqueueChunkToQueue(controller, clonedChunk, 0, byteLength);
|
|
1251
|
+
}
|
|
1252
|
+
function ReadableByteStreamControllerEnqueueDetachedPullIntoToQueue(controller, firstDescriptor) {
|
|
1253
|
+
if (firstDescriptor.bytesFilled > 0) {
|
|
1254
|
+
ReadableByteStreamControllerEnqueueClonedChunkToQueue(controller, firstDescriptor.buffer, firstDescriptor.byteOffset, firstDescriptor.bytesFilled);
|
|
1255
|
+
}
|
|
1256
|
+
ReadableByteStreamControllerShiftPendingPullInto(controller);
|
|
1257
|
+
}
|
|
1014
1258
|
function ReadableByteStreamControllerFillPullIntoDescriptorFromQueue(controller, pullIntoDescriptor) {
|
|
1015
|
-
var elementSize = pullIntoDescriptor.elementSize;
|
|
1016
|
-
var currentAlignedBytes = pullIntoDescriptor.bytesFilled - pullIntoDescriptor.bytesFilled % elementSize;
|
|
1017
1259
|
var maxBytesToCopy = Math.min(controller._queueTotalSize, pullIntoDescriptor.byteLength - pullIntoDescriptor.bytesFilled);
|
|
1018
1260
|
var maxBytesFilled = pullIntoDescriptor.bytesFilled + maxBytesToCopy;
|
|
1019
|
-
var maxAlignedBytes = maxBytesFilled - maxBytesFilled % elementSize;
|
|
1020
1261
|
var totalBytesToCopyRemaining = maxBytesToCopy;
|
|
1021
1262
|
var ready = false;
|
|
1022
|
-
|
|
1263
|
+
var remainderBytes = maxBytesFilled % pullIntoDescriptor.elementSize;
|
|
1264
|
+
var maxAlignedBytes = maxBytesFilled - remainderBytes;
|
|
1265
|
+
// A descriptor for a read() request that is not yet filled up to its minimum length will stay at the head
|
|
1266
|
+
// of the queue, so the underlying source can keep filling it.
|
|
1267
|
+
if (maxAlignedBytes >= pullIntoDescriptor.minimumFill) {
|
|
1023
1268
|
totalBytesToCopyRemaining = maxAlignedBytes - pullIntoDescriptor.bytesFilled;
|
|
1024
1269
|
ready = true;
|
|
1025
1270
|
}
|
|
@@ -1074,25 +1319,37 @@ function ReadableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(contro
|
|
|
1074
1319
|
}
|
|
1075
1320
|
}
|
|
1076
1321
|
}
|
|
1077
|
-
function
|
|
1078
|
-
var
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1322
|
+
function ReadableByteStreamControllerProcessReadRequestsUsingQueue(controller) {
|
|
1323
|
+
var reader = controller._controlledReadableByteStream._reader;
|
|
1324
|
+
while (reader._readRequests.length > 0) {
|
|
1325
|
+
if (controller._queueTotalSize === 0) {
|
|
1326
|
+
return;
|
|
1327
|
+
}
|
|
1328
|
+
var readRequest = reader._readRequests.shift();
|
|
1329
|
+
ReadableByteStreamControllerFillReadRequestFromQueue(controller, readRequest);
|
|
1082
1330
|
}
|
|
1331
|
+
}
|
|
1332
|
+
function ReadableByteStreamControllerPullInto(controller, view, min, readIntoRequest) {
|
|
1333
|
+
var stream = controller._controlledReadableByteStream;
|
|
1083
1334
|
var ctor = view.constructor;
|
|
1084
|
-
|
|
1085
|
-
var
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1335
|
+
var elementSize = arrayBufferViewElementSize(ctor);
|
|
1336
|
+
var byteOffset = view.byteOffset, byteLength = view.byteLength;
|
|
1337
|
+
var minimumFill = min * elementSize;
|
|
1338
|
+
var buffer;
|
|
1339
|
+
try {
|
|
1340
|
+
buffer = TransferArrayBuffer(view.buffer);
|
|
1341
|
+
}
|
|
1342
|
+
catch (e) {
|
|
1343
|
+
readIntoRequest._errorSteps(e);
|
|
1344
|
+
return;
|
|
1345
|
+
}
|
|
1090
1346
|
var pullIntoDescriptor = {
|
|
1091
1347
|
buffer: buffer,
|
|
1092
1348
|
bufferByteLength: buffer.byteLength,
|
|
1093
|
-
byteOffset:
|
|
1094
|
-
byteLength:
|
|
1349
|
+
byteOffset: byteOffset,
|
|
1350
|
+
byteLength: byteLength,
|
|
1095
1351
|
bytesFilled: 0,
|
|
1352
|
+
minimumFill: minimumFill,
|
|
1096
1353
|
elementSize: elementSize,
|
|
1097
1354
|
viewConstructor: ctor,
|
|
1098
1355
|
readerType: 'byob'
|
|
@@ -1129,6 +1386,9 @@ function ReadableByteStreamControllerPullInto(controller, view, readIntoRequest)
|
|
|
1129
1386
|
ReadableByteStreamControllerCallPullIfNeeded(controller);
|
|
1130
1387
|
}
|
|
1131
1388
|
function ReadableByteStreamControllerRespondInClosedState(controller, firstDescriptor) {
|
|
1389
|
+
if (firstDescriptor.readerType === 'none') {
|
|
1390
|
+
ReadableByteStreamControllerShiftPendingPullInto(controller);
|
|
1391
|
+
}
|
|
1132
1392
|
var stream = controller._controlledReadableByteStream;
|
|
1133
1393
|
if (ReadableStreamHasBYOBReader(stream)) {
|
|
1134
1394
|
while (ReadableStreamGetNumReadIntoRequests(stream) > 0) {
|
|
@@ -1139,15 +1399,21 @@ function ReadableByteStreamControllerRespondInClosedState(controller, firstDescr
|
|
|
1139
1399
|
}
|
|
1140
1400
|
function ReadableByteStreamControllerRespondInReadableState(controller, bytesWritten, pullIntoDescriptor) {
|
|
1141
1401
|
ReadableByteStreamControllerFillHeadPullIntoDescriptor(controller, bytesWritten, pullIntoDescriptor);
|
|
1142
|
-
if (pullIntoDescriptor.
|
|
1402
|
+
if (pullIntoDescriptor.readerType === 'none') {
|
|
1403
|
+
ReadableByteStreamControllerEnqueueDetachedPullIntoToQueue(controller, pullIntoDescriptor);
|
|
1404
|
+
ReadableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(controller);
|
|
1405
|
+
return;
|
|
1406
|
+
}
|
|
1407
|
+
if (pullIntoDescriptor.bytesFilled < pullIntoDescriptor.minimumFill) {
|
|
1408
|
+
// A descriptor for a read() request that is not yet filled up to its minimum length will stay at the head
|
|
1409
|
+
// of the queue, so the underlying source can keep filling it.
|
|
1143
1410
|
return;
|
|
1144
1411
|
}
|
|
1145
1412
|
ReadableByteStreamControllerShiftPendingPullInto(controller);
|
|
1146
1413
|
var remainderSize = pullIntoDescriptor.bytesFilled % pullIntoDescriptor.elementSize;
|
|
1147
1414
|
if (remainderSize > 0) {
|
|
1148
1415
|
var end = pullIntoDescriptor.byteOffset + pullIntoDescriptor.bytesFilled;
|
|
1149
|
-
|
|
1150
|
-
ReadableByteStreamControllerEnqueueChunkToQueue(controller, remainder, 0, remainder.byteLength);
|
|
1416
|
+
ReadableByteStreamControllerEnqueueClonedChunkToQueue(controller, pullIntoDescriptor.buffer, end - remainderSize, remainderSize);
|
|
1151
1417
|
}
|
|
1152
1418
|
pullIntoDescriptor.bytesFilled -= remainderSize;
|
|
1153
1419
|
ReadableByteStreamControllerCommitPullIntoDescriptor(controller._controlledReadableByteStream, pullIntoDescriptor);
|
|
@@ -1158,7 +1424,7 @@ function ReadableByteStreamControllerRespondInternal(controller, bytesWritten) {
|
|
|
1158
1424
|
ReadableByteStreamControllerInvalidateBYOBRequest(controller);
|
|
1159
1425
|
var state = controller._controlledReadableByteStream._state;
|
|
1160
1426
|
if (state === 'closed') {
|
|
1161
|
-
ReadableByteStreamControllerRespondInClosedState(controller);
|
|
1427
|
+
ReadableByteStreamControllerRespondInClosedState(controller, firstDescriptor);
|
|
1162
1428
|
}
|
|
1163
1429
|
else {
|
|
1164
1430
|
ReadableByteStreamControllerRespondInReadableState(controller, bytesWritten, firstDescriptor);
|
|
@@ -1208,7 +1474,7 @@ function ReadableByteStreamControllerClose(controller) {
|
|
|
1208
1474
|
}
|
|
1209
1475
|
if (controller._pendingPullIntos.length > 0) {
|
|
1210
1476
|
var firstPendingPullInto = controller._pendingPullIntos.peek();
|
|
1211
|
-
if (firstPendingPullInto.bytesFilled
|
|
1477
|
+
if (firstPendingPullInto.bytesFilled % firstPendingPullInto.elementSize !== 0) {
|
|
1212
1478
|
var e = new TypeError('Insufficient bytes to fill elements in the given buffer');
|
|
1213
1479
|
ReadableByteStreamControllerError(controller, e);
|
|
1214
1480
|
throw e;
|
|
@@ -1222,17 +1488,24 @@ function ReadableByteStreamControllerEnqueue(controller, chunk) {
|
|
|
1222
1488
|
if (controller._closeRequested || stream._state !== 'readable') {
|
|
1223
1489
|
return;
|
|
1224
1490
|
}
|
|
1225
|
-
var buffer = chunk.buffer;
|
|
1226
|
-
|
|
1227
|
-
|
|
1491
|
+
var buffer = chunk.buffer, byteOffset = chunk.byteOffset, byteLength = chunk.byteLength;
|
|
1492
|
+
if (IsDetachedBuffer(buffer)) {
|
|
1493
|
+
throw new TypeError('chunk\'s buffer is detached and so cannot be enqueued');
|
|
1494
|
+
}
|
|
1228
1495
|
var transferredBuffer = TransferArrayBuffer(buffer);
|
|
1229
1496
|
if (controller._pendingPullIntos.length > 0) {
|
|
1230
1497
|
var firstPendingPullInto = controller._pendingPullIntos.peek();
|
|
1231
|
-
if (IsDetachedBuffer(firstPendingPullInto.buffer))
|
|
1498
|
+
if (IsDetachedBuffer(firstPendingPullInto.buffer)) {
|
|
1499
|
+
throw new TypeError('The BYOB request\'s buffer has been detached and so cannot be filled with an enqueued chunk');
|
|
1500
|
+
}
|
|
1501
|
+
ReadableByteStreamControllerInvalidateBYOBRequest(controller);
|
|
1232
1502
|
firstPendingPullInto.buffer = TransferArrayBuffer(firstPendingPullInto.buffer);
|
|
1503
|
+
if (firstPendingPullInto.readerType === 'none') {
|
|
1504
|
+
ReadableByteStreamControllerEnqueueDetachedPullIntoToQueue(controller, firstPendingPullInto);
|
|
1505
|
+
}
|
|
1233
1506
|
}
|
|
1234
|
-
ReadableByteStreamControllerInvalidateBYOBRequest(controller);
|
|
1235
1507
|
if (ReadableStreamHasDefaultReader(stream)) {
|
|
1508
|
+
ReadableByteStreamControllerProcessReadRequestsUsingQueue(controller);
|
|
1236
1509
|
if (ReadableStreamGetNumReadRequests(stream) === 0) {
|
|
1237
1510
|
ReadableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset, byteLength);
|
|
1238
1511
|
}
|
|
@@ -1264,6 +1537,13 @@ function ReadableByteStreamControllerError(controller, e) {
|
|
|
1264
1537
|
ReadableByteStreamControllerClearAlgorithms(controller);
|
|
1265
1538
|
ReadableStreamError(stream, e);
|
|
1266
1539
|
}
|
|
1540
|
+
function ReadableByteStreamControllerFillReadRequestFromQueue(controller, readRequest) {
|
|
1541
|
+
var entry = controller._queue.shift();
|
|
1542
|
+
controller._queueTotalSize -= entry.byteLength;
|
|
1543
|
+
ReadableByteStreamControllerHandleQueueDrain(controller);
|
|
1544
|
+
var view = new Uint8Array(entry.buffer, entry.byteOffset, entry.byteLength);
|
|
1545
|
+
readRequest._chunkSteps(view);
|
|
1546
|
+
}
|
|
1267
1547
|
function ReadableByteStreamControllerGetBYOBRequest(controller) {
|
|
1268
1548
|
if (controller._byobRequest === null && controller._pendingPullIntos.length > 0) {
|
|
1269
1549
|
var firstDescriptor = controller._pendingPullIntos.peek();
|
|
@@ -1349,24 +1629,35 @@ function SetUpReadableByteStreamController(stream, controller, startAlgorithm, p
|
|
|
1349
1629
|
uponPromise(promiseResolvedWith(startResult), function () {
|
|
1350
1630
|
controller._started = true;
|
|
1351
1631
|
ReadableByteStreamControllerCallPullIfNeeded(controller);
|
|
1632
|
+
return null;
|
|
1352
1633
|
}, function (r) {
|
|
1353
1634
|
ReadableByteStreamControllerError(controller, r);
|
|
1635
|
+
return null;
|
|
1354
1636
|
});
|
|
1355
1637
|
}
|
|
1356
1638
|
function SetUpReadableByteStreamControllerFromUnderlyingSource(stream, underlyingByteSource, highWaterMark) {
|
|
1357
1639
|
var controller = Object.create(ReadableByteStreamController.prototype);
|
|
1358
|
-
var startAlgorithm
|
|
1359
|
-
var pullAlgorithm
|
|
1360
|
-
var cancelAlgorithm
|
|
1640
|
+
var startAlgorithm;
|
|
1641
|
+
var pullAlgorithm;
|
|
1642
|
+
var cancelAlgorithm;
|
|
1361
1643
|
if (underlyingByteSource.start !== undefined) {
|
|
1362
1644
|
startAlgorithm = function () { return underlyingByteSource.start(controller); };
|
|
1363
1645
|
}
|
|
1646
|
+
else {
|
|
1647
|
+
startAlgorithm = function () { return undefined; };
|
|
1648
|
+
}
|
|
1364
1649
|
if (underlyingByteSource.pull !== undefined) {
|
|
1365
1650
|
pullAlgorithm = function () { return underlyingByteSource.pull(controller); };
|
|
1366
1651
|
}
|
|
1652
|
+
else {
|
|
1653
|
+
pullAlgorithm = function () { return promiseResolvedWith(undefined); };
|
|
1654
|
+
}
|
|
1367
1655
|
if (underlyingByteSource.cancel !== undefined) {
|
|
1368
1656
|
cancelAlgorithm = function (reason) { return underlyingByteSource.cancel(reason); };
|
|
1369
1657
|
}
|
|
1658
|
+
else {
|
|
1659
|
+
cancelAlgorithm = function () { return promiseResolvedWith(undefined); };
|
|
1660
|
+
}
|
|
1370
1661
|
var autoAllocateChunkSize = underlyingByteSource.autoAllocateChunkSize;
|
|
1371
1662
|
if (autoAllocateChunkSize === 0) {
|
|
1372
1663
|
throw new TypeError('autoAllocateChunkSize must be greater than 0');
|
|
@@ -1379,11 +1670,34 @@ function SetUpReadableStreamBYOBRequest(request, controller, view) {
|
|
|
1379
1670
|
}
|
|
1380
1671
|
// Helper functions for the ReadableStreamBYOBRequest.
|
|
1381
1672
|
function byobRequestBrandCheckException(name) {
|
|
1382
|
-
return new TypeError("ReadableStreamBYOBRequest.prototype."
|
|
1673
|
+
return new TypeError("ReadableStreamBYOBRequest.prototype.".concat(name, " can only be used on a ReadableStreamBYOBRequest"));
|
|
1383
1674
|
}
|
|
1384
1675
|
// Helper functions for the ReadableByteStreamController.
|
|
1385
1676
|
function byteStreamControllerBrandCheckException(name) {
|
|
1386
|
-
return new TypeError("ReadableByteStreamController.prototype."
|
|
1677
|
+
return new TypeError("ReadableByteStreamController.prototype.".concat(name, " can only be used on a ReadableByteStreamController"));
|
|
1678
|
+
}
|
|
1679
|
+
|
|
1680
|
+
function convertReaderOptions(options, context) {
|
|
1681
|
+
assertDictionary(options, context);
|
|
1682
|
+
var mode = options === null || options === void 0 ? void 0 : options.mode;
|
|
1683
|
+
return {
|
|
1684
|
+
mode: mode === undefined ? undefined : convertReadableStreamReaderMode(mode, "".concat(context, " has member 'mode' that"))
|
|
1685
|
+
};
|
|
1686
|
+
}
|
|
1687
|
+
function convertReadableStreamReaderMode(mode, context) {
|
|
1688
|
+
mode = "".concat(mode);
|
|
1689
|
+
if (mode !== 'byob') {
|
|
1690
|
+
throw new TypeError("".concat(context, " '").concat(mode, "' is not a valid enumeration value for ReadableStreamReaderMode"));
|
|
1691
|
+
}
|
|
1692
|
+
return mode;
|
|
1693
|
+
}
|
|
1694
|
+
function convertByobReadOptions(options, context) {
|
|
1695
|
+
var _a;
|
|
1696
|
+
assertDictionary(options, context);
|
|
1697
|
+
var min = (_a = options === null || options === void 0 ? void 0 : options.min) !== null && _a !== void 0 ? _a : 1;
|
|
1698
|
+
return {
|
|
1699
|
+
min: convertUnsignedLongLongWithEnforceRange(min, "".concat(context, " has member 'min' that"))
|
|
1700
|
+
};
|
|
1387
1701
|
}
|
|
1388
1702
|
|
|
1389
1703
|
// Abstract operations for the ReadableStream.
|
|
@@ -1463,12 +1777,8 @@ var ReadableStreamBYOBReader = /** @class */ (function () {
|
|
|
1463
1777
|
}
|
|
1464
1778
|
return ReadableStreamReaderGenericCancel(this, reason);
|
|
1465
1779
|
};
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
*
|
|
1469
|
-
* If reading a chunk causes the queue to become empty, more data will be pulled from the underlying source.
|
|
1470
|
-
*/
|
|
1471
|
-
ReadableStreamBYOBReader.prototype.read = function (view) {
|
|
1780
|
+
ReadableStreamBYOBReader.prototype.read = function (view, rawOptions) {
|
|
1781
|
+
if (rawOptions === void 0) { rawOptions = {}; }
|
|
1472
1782
|
if (!IsReadableStreamBYOBReader(this)) {
|
|
1473
1783
|
return promiseRejectedWith(byobReaderBrandCheckException('read'));
|
|
1474
1784
|
}
|
|
@@ -1481,7 +1791,28 @@ var ReadableStreamBYOBReader = /** @class */ (function () {
|
|
|
1481
1791
|
if (view.buffer.byteLength === 0) {
|
|
1482
1792
|
return promiseRejectedWith(new TypeError("view's buffer must have non-zero byteLength"));
|
|
1483
1793
|
}
|
|
1484
|
-
if (IsDetachedBuffer(view.buffer))
|
|
1794
|
+
if (IsDetachedBuffer(view.buffer)) {
|
|
1795
|
+
return promiseRejectedWith(new TypeError('view\'s buffer has been detached'));
|
|
1796
|
+
}
|
|
1797
|
+
var options;
|
|
1798
|
+
try {
|
|
1799
|
+
options = convertByobReadOptions(rawOptions, 'options');
|
|
1800
|
+
}
|
|
1801
|
+
catch (e) {
|
|
1802
|
+
return promiseRejectedWith(e);
|
|
1803
|
+
}
|
|
1804
|
+
var min = options.min;
|
|
1805
|
+
if (min === 0) {
|
|
1806
|
+
return promiseRejectedWith(new TypeError('options.min must be greater than 0'));
|
|
1807
|
+
}
|
|
1808
|
+
if (!isDataView(view)) {
|
|
1809
|
+
if (min > view.length) {
|
|
1810
|
+
return promiseRejectedWith(new RangeError('options.min must be less than or equal to view\'s length'));
|
|
1811
|
+
}
|
|
1812
|
+
}
|
|
1813
|
+
else if (min > view.byteLength) {
|
|
1814
|
+
return promiseRejectedWith(new RangeError('options.min must be less than or equal to view\'s byteLength'));
|
|
1815
|
+
}
|
|
1485
1816
|
if (this._ownerReadableStream === undefined) {
|
|
1486
1817
|
return promiseRejectedWith(readerLockException('read from'));
|
|
1487
1818
|
}
|
|
@@ -1496,7 +1827,7 @@ var ReadableStreamBYOBReader = /** @class */ (function () {
|
|
|
1496
1827
|
_closeSteps: function (chunk) { return resolvePromise({ value: chunk, done: true }); },
|
|
1497
1828
|
_errorSteps: function (e) { return rejectPromise(e); }
|
|
1498
1829
|
};
|
|
1499
|
-
ReadableStreamBYOBReaderRead(this, view, readIntoRequest);
|
|
1830
|
+
ReadableStreamBYOBReaderRead(this, view, min, readIntoRequest);
|
|
1500
1831
|
return promise;
|
|
1501
1832
|
};
|
|
1502
1833
|
/**
|
|
@@ -1515,10 +1846,7 @@ var ReadableStreamBYOBReader = /** @class */ (function () {
|
|
|
1515
1846
|
if (this._ownerReadableStream === undefined) {
|
|
1516
1847
|
return;
|
|
1517
1848
|
}
|
|
1518
|
-
|
|
1519
|
-
throw new TypeError('Tried to release a reader lock when that reader has pending read() calls un-settled');
|
|
1520
|
-
}
|
|
1521
|
-
ReadableStreamReaderGenericRelease(this);
|
|
1849
|
+
ReadableStreamBYOBReaderRelease(this);
|
|
1522
1850
|
};
|
|
1523
1851
|
return ReadableStreamBYOBReader;
|
|
1524
1852
|
}());
|
|
@@ -1528,6 +1856,9 @@ Object.defineProperties(ReadableStreamBYOBReader.prototype, {
|
|
|
1528
1856
|
releaseLock: { enumerable: true },
|
|
1529
1857
|
closed: { enumerable: true }
|
|
1530
1858
|
});
|
|
1859
|
+
setFunctionName(ReadableStreamBYOBReader.prototype.cancel, 'cancel');
|
|
1860
|
+
setFunctionName(ReadableStreamBYOBReader.prototype.read, 'read');
|
|
1861
|
+
setFunctionName(ReadableStreamBYOBReader.prototype.releaseLock, 'releaseLock');
|
|
1531
1862
|
if (typeof SymbolPolyfill.toStringTag === 'symbol') {
|
|
1532
1863
|
Object.defineProperty(ReadableStreamBYOBReader.prototype, SymbolPolyfill.toStringTag, {
|
|
1533
1864
|
value: 'ReadableStreamBYOBReader',
|
|
@@ -1544,19 +1875,31 @@ function IsReadableStreamBYOBReader(x) {
|
|
|
1544
1875
|
}
|
|
1545
1876
|
return x instanceof ReadableStreamBYOBReader;
|
|
1546
1877
|
}
|
|
1547
|
-
function ReadableStreamBYOBReaderRead(reader, view, readIntoRequest) {
|
|
1878
|
+
function ReadableStreamBYOBReaderRead(reader, view, min, readIntoRequest) {
|
|
1548
1879
|
var stream = reader._ownerReadableStream;
|
|
1549
1880
|
stream._disturbed = true;
|
|
1550
1881
|
if (stream._state === 'errored') {
|
|
1551
1882
|
readIntoRequest._errorSteps(stream._storedError);
|
|
1552
1883
|
}
|
|
1553
1884
|
else {
|
|
1554
|
-
ReadableByteStreamControllerPullInto(stream._readableStreamController, view, readIntoRequest);
|
|
1885
|
+
ReadableByteStreamControllerPullInto(stream._readableStreamController, view, min, readIntoRequest);
|
|
1555
1886
|
}
|
|
1556
1887
|
}
|
|
1888
|
+
function ReadableStreamBYOBReaderRelease(reader) {
|
|
1889
|
+
ReadableStreamReaderGenericRelease(reader);
|
|
1890
|
+
var e = new TypeError('Reader was released');
|
|
1891
|
+
ReadableStreamBYOBReaderErrorReadIntoRequests(reader, e);
|
|
1892
|
+
}
|
|
1893
|
+
function ReadableStreamBYOBReaderErrorReadIntoRequests(reader, e) {
|
|
1894
|
+
var readIntoRequests = reader._readIntoRequests;
|
|
1895
|
+
reader._readIntoRequests = new SimpleQueue();
|
|
1896
|
+
readIntoRequests.forEach(function (readIntoRequest) {
|
|
1897
|
+
readIntoRequest._errorSteps(e);
|
|
1898
|
+
});
|
|
1899
|
+
}
|
|
1557
1900
|
// Helper functions for the ReadableStreamBYOBReader.
|
|
1558
1901
|
function byobReaderBrandCheckException(name) {
|
|
1559
|
-
return new TypeError("ReadableStreamBYOBReader.prototype."
|
|
1902
|
+
return new TypeError("ReadableStreamBYOBReader.prototype.".concat(name, " can only be used on a ReadableStreamBYOBReader"));
|
|
1560
1903
|
}
|
|
1561
1904
|
|
|
1562
1905
|
function ExtractHighWaterMark(strategy, defaultHWM) {
|
|
@@ -1583,7 +1926,7 @@ function convertQueuingStrategy(init, context) {
|
|
|
1583
1926
|
var size = init === null || init === void 0 ? void 0 : init.size;
|
|
1584
1927
|
return {
|
|
1585
1928
|
highWaterMark: highWaterMark === undefined ? undefined : convertUnrestrictedDouble(highWaterMark),
|
|
1586
|
-
size: size === undefined ? undefined : convertQueuingStrategySize(size, context
|
|
1929
|
+
size: size === undefined ? undefined : convertQueuingStrategySize(size, "".concat(context, " has member 'size' that"))
|
|
1587
1930
|
};
|
|
1588
1931
|
}
|
|
1589
1932
|
function convertQueuingStrategySize(fn, context) {
|
|
@@ -1601,16 +1944,16 @@ function convertUnderlyingSink(original, context) {
|
|
|
1601
1944
|
return {
|
|
1602
1945
|
abort: abort === undefined ?
|
|
1603
1946
|
undefined :
|
|
1604
|
-
convertUnderlyingSinkAbortCallback(abort, original, context
|
|
1947
|
+
convertUnderlyingSinkAbortCallback(abort, original, "".concat(context, " has member 'abort' that")),
|
|
1605
1948
|
close: close === undefined ?
|
|
1606
1949
|
undefined :
|
|
1607
|
-
convertUnderlyingSinkCloseCallback(close, original, context
|
|
1950
|
+
convertUnderlyingSinkCloseCallback(close, original, "".concat(context, " has member 'close' that")),
|
|
1608
1951
|
start: start === undefined ?
|
|
1609
1952
|
undefined :
|
|
1610
|
-
convertUnderlyingSinkStartCallback(start, original, context
|
|
1953
|
+
convertUnderlyingSinkStartCallback(start, original, "".concat(context, " has member 'start' that")),
|
|
1611
1954
|
write: write === undefined ?
|
|
1612
1955
|
undefined :
|
|
1613
|
-
convertUnderlyingSinkWriteCallback(write, original, context
|
|
1956
|
+
convertUnderlyingSinkWriteCallback(write, original, "".concat(context, " has member 'write' that")),
|
|
1614
1957
|
type: type
|
|
1615
1958
|
};
|
|
1616
1959
|
}
|
|
@@ -1633,7 +1976,7 @@ function convertUnderlyingSinkWriteCallback(fn, original, context) {
|
|
|
1633
1976
|
|
|
1634
1977
|
function assertWritableStream(x, context) {
|
|
1635
1978
|
if (!IsWritableStream(x)) {
|
|
1636
|
-
throw new TypeError(context
|
|
1979
|
+
throw new TypeError("".concat(context, " is not a WritableStream."));
|
|
1637
1980
|
}
|
|
1638
1981
|
}
|
|
1639
1982
|
|
|
@@ -1762,6 +2105,9 @@ Object.defineProperties(WritableStream.prototype, {
|
|
|
1762
2105
|
getWriter: { enumerable: true },
|
|
1763
2106
|
locked: { enumerable: true }
|
|
1764
2107
|
});
|
|
2108
|
+
setFunctionName(WritableStream.prototype.abort, 'abort');
|
|
2109
|
+
setFunctionName(WritableStream.prototype.close, 'close');
|
|
2110
|
+
setFunctionName(WritableStream.prototype.getWriter, 'getWriter');
|
|
1765
2111
|
if (typeof SymbolPolyfill.toStringTag === 'symbol') {
|
|
1766
2112
|
Object.defineProperty(WritableStream.prototype, SymbolPolyfill.toStringTag, {
|
|
1767
2113
|
value: 'WritableStream',
|
|
@@ -1829,7 +2175,7 @@ function WritableStreamAbort(stream, reason) {
|
|
|
1829
2175
|
return promiseResolvedWith(undefined);
|
|
1830
2176
|
}
|
|
1831
2177
|
stream._writableStreamController._abortReason = reason;
|
|
1832
|
-
(_a = stream._writableStreamController._abortController) === null || _a === void 0 ? void 0 : _a.abort();
|
|
2178
|
+
(_a = stream._writableStreamController._abortController) === null || _a === void 0 ? void 0 : _a.abort(reason);
|
|
1833
2179
|
// TypeScript narrows the type of `stream._state` down to 'writable' | 'erroring',
|
|
1834
2180
|
// but it doesn't know that signaling abort runs author code that might have changed the state.
|
|
1835
2181
|
// Widen the type again by casting to WritableStreamState.
|
|
@@ -1864,7 +2210,7 @@ function WritableStreamAbort(stream, reason) {
|
|
|
1864
2210
|
function WritableStreamClose(stream) {
|
|
1865
2211
|
var state = stream._state;
|
|
1866
2212
|
if (state === 'closed' || state === 'errored') {
|
|
1867
|
-
return promiseRejectedWith(new TypeError("The stream (in "
|
|
2213
|
+
return promiseRejectedWith(new TypeError("The stream (in ".concat(state, " state) is not in the writable state and cannot be closed")));
|
|
1868
2214
|
}
|
|
1869
2215
|
var promise = newPromise(function (resolve, reject) {
|
|
1870
2216
|
var closeRequest = {
|
|
@@ -1934,9 +2280,11 @@ function WritableStreamFinishErroring(stream) {
|
|
|
1934
2280
|
uponPromise(promise, function () {
|
|
1935
2281
|
abortRequest._resolve();
|
|
1936
2282
|
WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream);
|
|
2283
|
+
return null;
|
|
1937
2284
|
}, function (reason) {
|
|
1938
2285
|
abortRequest._reject(reason);
|
|
1939
2286
|
WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream);
|
|
2287
|
+
return null;
|
|
1940
2288
|
});
|
|
1941
2289
|
}
|
|
1942
2290
|
function WritableStreamFinishInFlightWrite(stream) {
|
|
@@ -2179,6 +2527,10 @@ Object.defineProperties(WritableStreamDefaultWriter.prototype, {
|
|
|
2179
2527
|
desiredSize: { enumerable: true },
|
|
2180
2528
|
ready: { enumerable: true }
|
|
2181
2529
|
});
|
|
2530
|
+
setFunctionName(WritableStreamDefaultWriter.prototype.abort, 'abort');
|
|
2531
|
+
setFunctionName(WritableStreamDefaultWriter.prototype.close, 'close');
|
|
2532
|
+
setFunctionName(WritableStreamDefaultWriter.prototype.releaseLock, 'releaseLock');
|
|
2533
|
+
setFunctionName(WritableStreamDefaultWriter.prototype.write, 'write');
|
|
2182
2534
|
if (typeof SymbolPolyfill.toStringTag === 'symbol') {
|
|
2183
2535
|
Object.defineProperty(WritableStreamDefaultWriter.prototype, SymbolPolyfill.toStringTag, {
|
|
2184
2536
|
value: 'WritableStreamDefaultWriter',
|
|
@@ -2394,29 +2746,43 @@ function SetUpWritableStreamDefaultController(stream, controller, startAlgorithm
|
|
|
2394
2746
|
uponPromise(startPromise, function () {
|
|
2395
2747
|
controller._started = true;
|
|
2396
2748
|
WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller);
|
|
2749
|
+
return null;
|
|
2397
2750
|
}, function (r) {
|
|
2398
2751
|
controller._started = true;
|
|
2399
2752
|
WritableStreamDealWithRejection(stream, r);
|
|
2753
|
+
return null;
|
|
2400
2754
|
});
|
|
2401
2755
|
}
|
|
2402
2756
|
function SetUpWritableStreamDefaultControllerFromUnderlyingSink(stream, underlyingSink, highWaterMark, sizeAlgorithm) {
|
|
2403
2757
|
var controller = Object.create(WritableStreamDefaultController.prototype);
|
|
2404
|
-
var startAlgorithm
|
|
2405
|
-
var writeAlgorithm
|
|
2406
|
-
var closeAlgorithm
|
|
2407
|
-
var abortAlgorithm
|
|
2758
|
+
var startAlgorithm;
|
|
2759
|
+
var writeAlgorithm;
|
|
2760
|
+
var closeAlgorithm;
|
|
2761
|
+
var abortAlgorithm;
|
|
2408
2762
|
if (underlyingSink.start !== undefined) {
|
|
2409
2763
|
startAlgorithm = function () { return underlyingSink.start(controller); };
|
|
2410
2764
|
}
|
|
2765
|
+
else {
|
|
2766
|
+
startAlgorithm = function () { return undefined; };
|
|
2767
|
+
}
|
|
2411
2768
|
if (underlyingSink.write !== undefined) {
|
|
2412
2769
|
writeAlgorithm = function (chunk) { return underlyingSink.write(chunk, controller); };
|
|
2413
2770
|
}
|
|
2771
|
+
else {
|
|
2772
|
+
writeAlgorithm = function () { return promiseResolvedWith(undefined); };
|
|
2773
|
+
}
|
|
2414
2774
|
if (underlyingSink.close !== undefined) {
|
|
2415
2775
|
closeAlgorithm = function () { return underlyingSink.close(); };
|
|
2416
2776
|
}
|
|
2777
|
+
else {
|
|
2778
|
+
closeAlgorithm = function () { return promiseResolvedWith(undefined); };
|
|
2779
|
+
}
|
|
2417
2780
|
if (underlyingSink.abort !== undefined) {
|
|
2418
2781
|
abortAlgorithm = function (reason) { return underlyingSink.abort(reason); };
|
|
2419
2782
|
}
|
|
2783
|
+
else {
|
|
2784
|
+
abortAlgorithm = function () { return promiseResolvedWith(undefined); };
|
|
2785
|
+
}
|
|
2420
2786
|
SetUpWritableStreamDefaultController(stream, controller, startAlgorithm, writeAlgorithm, closeAlgorithm, abortAlgorithm, highWaterMark, sizeAlgorithm);
|
|
2421
2787
|
}
|
|
2422
2788
|
// ClearAlgorithms may be called twice. Erroring the same stream in multiple ways will often result in redundant calls.
|
|
@@ -2495,8 +2861,10 @@ function WritableStreamDefaultControllerProcessClose(controller) {
|
|
|
2495
2861
|
WritableStreamDefaultControllerClearAlgorithms(controller);
|
|
2496
2862
|
uponPromise(sinkClosePromise, function () {
|
|
2497
2863
|
WritableStreamFinishInFlightClose(stream);
|
|
2864
|
+
return null;
|
|
2498
2865
|
}, function (reason) {
|
|
2499
2866
|
WritableStreamFinishInFlightCloseWithError(stream, reason);
|
|
2867
|
+
return null;
|
|
2500
2868
|
});
|
|
2501
2869
|
}
|
|
2502
2870
|
function WritableStreamDefaultControllerProcessWrite(controller, chunk) {
|
|
@@ -2512,11 +2880,13 @@ function WritableStreamDefaultControllerProcessWrite(controller, chunk) {
|
|
|
2512
2880
|
WritableStreamUpdateBackpressure(stream, backpressure);
|
|
2513
2881
|
}
|
|
2514
2882
|
WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller);
|
|
2883
|
+
return null;
|
|
2515
2884
|
}, function (reason) {
|
|
2516
2885
|
if (stream._state === 'writable') {
|
|
2517
2886
|
WritableStreamDefaultControllerClearAlgorithms(controller);
|
|
2518
2887
|
}
|
|
2519
2888
|
WritableStreamFinishInFlightWriteWithError(stream, reason);
|
|
2889
|
+
return null;
|
|
2520
2890
|
});
|
|
2521
2891
|
}
|
|
2522
2892
|
function WritableStreamDefaultControllerGetBackpressure(controller) {
|
|
@@ -2531,15 +2901,15 @@ function WritableStreamDefaultControllerError(controller, error) {
|
|
|
2531
2901
|
}
|
|
2532
2902
|
// Helper functions for the WritableStream.
|
|
2533
2903
|
function streamBrandCheckException$2(name) {
|
|
2534
|
-
return new TypeError("WritableStream.prototype."
|
|
2904
|
+
return new TypeError("WritableStream.prototype.".concat(name, " can only be used on a WritableStream"));
|
|
2535
2905
|
}
|
|
2536
2906
|
// Helper functions for the WritableStreamDefaultController.
|
|
2537
2907
|
function defaultControllerBrandCheckException$2(name) {
|
|
2538
|
-
return new TypeError("WritableStreamDefaultController.prototype."
|
|
2908
|
+
return new TypeError("WritableStreamDefaultController.prototype.".concat(name, " can only be used on a WritableStreamDefaultController"));
|
|
2539
2909
|
}
|
|
2540
2910
|
// Helper functions for the WritableStreamDefaultWriter.
|
|
2541
2911
|
function defaultWriterBrandCheckException(name) {
|
|
2542
|
-
return new TypeError("WritableStreamDefaultWriter.prototype."
|
|
2912
|
+
return new TypeError("WritableStreamDefaultWriter.prototype.".concat(name, " can only be used on a WritableStreamDefaultWriter"));
|
|
2543
2913
|
}
|
|
2544
2914
|
function defaultWriterLockException(name) {
|
|
2545
2915
|
return new TypeError('Cannot ' + name + ' a stream using a released writer');
|
|
@@ -2623,13 +2993,28 @@ function defaultWriterReadyPromiseResolve(writer) {
|
|
|
2623
2993
|
}
|
|
2624
2994
|
|
|
2625
2995
|
/// <reference lib="dom" />
|
|
2626
|
-
|
|
2996
|
+
function getGlobals() {
|
|
2997
|
+
if (typeof globalThis !== 'undefined') {
|
|
2998
|
+
return globalThis;
|
|
2999
|
+
}
|
|
3000
|
+
else if (typeof self !== 'undefined') {
|
|
3001
|
+
return self;
|
|
3002
|
+
}
|
|
3003
|
+
else if (typeof global !== 'undefined') {
|
|
3004
|
+
return global;
|
|
3005
|
+
}
|
|
3006
|
+
return undefined;
|
|
3007
|
+
}
|
|
3008
|
+
var globals = getGlobals();
|
|
2627
3009
|
|
|
2628
3010
|
/// <reference types="node" />
|
|
2629
3011
|
function isDOMExceptionConstructor(ctor) {
|
|
2630
3012
|
if (!(typeof ctor === 'function' || typeof ctor === 'object')) {
|
|
2631
3013
|
return false;
|
|
2632
3014
|
}
|
|
3015
|
+
if (ctor.name !== 'DOMException') {
|
|
3016
|
+
return false;
|
|
3017
|
+
}
|
|
2633
3018
|
try {
|
|
2634
3019
|
new ctor();
|
|
2635
3020
|
return true;
|
|
@@ -2638,8 +3023,21 @@ function isDOMExceptionConstructor(ctor) {
|
|
|
2638
3023
|
return false;
|
|
2639
3024
|
}
|
|
2640
3025
|
}
|
|
2641
|
-
|
|
2642
|
-
|
|
3026
|
+
/**
|
|
3027
|
+
* Support:
|
|
3028
|
+
* - Web browsers
|
|
3029
|
+
* - Node 18 and higher (https://github.com/nodejs/node/commit/e4b1fb5e6422c1ff151234bb9de792d45dd88d87)
|
|
3030
|
+
*/
|
|
3031
|
+
function getFromGlobal() {
|
|
3032
|
+
var ctor = globals === null || globals === void 0 ? void 0 : globals.DOMException;
|
|
3033
|
+
return isDOMExceptionConstructor(ctor) ? ctor : undefined;
|
|
3034
|
+
}
|
|
3035
|
+
/**
|
|
3036
|
+
* Support:
|
|
3037
|
+
* - All platforms
|
|
3038
|
+
*/
|
|
3039
|
+
function createPolyfill() {
|
|
3040
|
+
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
2643
3041
|
var ctor = function DOMException(message, name) {
|
|
2644
3042
|
this.message = message || '';
|
|
2645
3043
|
this.name = name || 'Error';
|
|
@@ -2647,12 +3045,13 @@ function createDOMExceptionPolyfill() {
|
|
|
2647
3045
|
Error.captureStackTrace(this, this.constructor);
|
|
2648
3046
|
}
|
|
2649
3047
|
};
|
|
3048
|
+
setFunctionName(ctor, 'DOMException');
|
|
2650
3049
|
ctor.prototype = Object.create(Error.prototype);
|
|
2651
3050
|
Object.defineProperty(ctor.prototype, 'constructor', { value: ctor, writable: true, configurable: true });
|
|
2652
3051
|
return ctor;
|
|
2653
3052
|
}
|
|
2654
|
-
// eslint-disable-next-line no-redeclare
|
|
2655
|
-
var DOMException
|
|
3053
|
+
// eslint-disable-next-line @typescript-eslint/no-redeclare
|
|
3054
|
+
var DOMException = getFromGlobal() || createPolyfill();
|
|
2656
3055
|
|
|
2657
3056
|
function ReadableStreamPipeTo(source, dest, preventClose, preventAbort, preventCancel, signal) {
|
|
2658
3057
|
var reader = AcquireReadableStreamDefaultReader(source);
|
|
@@ -2665,7 +3064,7 @@ function ReadableStreamPipeTo(source, dest, preventClose, preventAbort, preventC
|
|
|
2665
3064
|
var abortAlgorithm;
|
|
2666
3065
|
if (signal !== undefined) {
|
|
2667
3066
|
abortAlgorithm = function () {
|
|
2668
|
-
var error = new DOMException
|
|
3067
|
+
var error = signal.reason !== undefined ? signal.reason : new DOMException('Aborted', 'AbortError');
|
|
2669
3068
|
var actions = [];
|
|
2670
3069
|
if (!preventAbort) {
|
|
2671
3070
|
actions.push(function () {
|
|
@@ -2734,6 +3133,7 @@ function ReadableStreamPipeTo(source, dest, preventClose, preventAbort, preventC
|
|
|
2734
3133
|
else {
|
|
2735
3134
|
shutdown(true, storedError);
|
|
2736
3135
|
}
|
|
3136
|
+
return null;
|
|
2737
3137
|
});
|
|
2738
3138
|
// Errors must be propagated backward
|
|
2739
3139
|
isOrBecomesErrored(dest, writer._closedPromise, function (storedError) {
|
|
@@ -2743,6 +3143,7 @@ function ReadableStreamPipeTo(source, dest, preventClose, preventAbort, preventC
|
|
|
2743
3143
|
else {
|
|
2744
3144
|
shutdown(true, storedError);
|
|
2745
3145
|
}
|
|
3146
|
+
return null;
|
|
2746
3147
|
});
|
|
2747
3148
|
// Closing must be propagated forward
|
|
2748
3149
|
isOrBecomesClosed(source, reader._closedPromise, function () {
|
|
@@ -2752,6 +3153,7 @@ function ReadableStreamPipeTo(source, dest, preventClose, preventAbort, preventC
|
|
|
2752
3153
|
else {
|
|
2753
3154
|
shutdown();
|
|
2754
3155
|
}
|
|
3156
|
+
return null;
|
|
2755
3157
|
});
|
|
2756
3158
|
// Closing must be propagated backward
|
|
2757
3159
|
if (WritableStreamCloseQueuedOrInFlight(dest) || dest._state === 'closed') {
|
|
@@ -2799,6 +3201,7 @@ function ReadableStreamPipeTo(source, dest, preventClose, preventAbort, preventC
|
|
|
2799
3201
|
}
|
|
2800
3202
|
function doTheRest() {
|
|
2801
3203
|
uponPromise(action(), function () { return finalize(originalIsError, originalError); }, function (newError) { return finalize(true, newError); });
|
|
3204
|
+
return null;
|
|
2802
3205
|
}
|
|
2803
3206
|
}
|
|
2804
3207
|
function shutdown(isError, error) {
|
|
@@ -2825,6 +3228,7 @@ function ReadableStreamPipeTo(source, dest, preventClose, preventAbort, preventC
|
|
|
2825
3228
|
else {
|
|
2826
3229
|
resolve(undefined);
|
|
2827
3230
|
}
|
|
3231
|
+
return null;
|
|
2828
3232
|
}
|
|
2829
3233
|
});
|
|
2830
3234
|
}
|
|
@@ -2911,6 +3315,10 @@ var ReadableStreamDefaultController = /** @class */ (function () {
|
|
|
2911
3315
|
ReadableStreamDefaultControllerCallPullIfNeeded(this);
|
|
2912
3316
|
}
|
|
2913
3317
|
};
|
|
3318
|
+
/** @internal */
|
|
3319
|
+
ReadableStreamDefaultController.prototype[ReleaseSteps] = function () {
|
|
3320
|
+
// Do nothing.
|
|
3321
|
+
};
|
|
2914
3322
|
return ReadableStreamDefaultController;
|
|
2915
3323
|
}());
|
|
2916
3324
|
Object.defineProperties(ReadableStreamDefaultController.prototype, {
|
|
@@ -2919,6 +3327,9 @@ Object.defineProperties(ReadableStreamDefaultController.prototype, {
|
|
|
2919
3327
|
error: { enumerable: true },
|
|
2920
3328
|
desiredSize: { enumerable: true }
|
|
2921
3329
|
});
|
|
3330
|
+
setFunctionName(ReadableStreamDefaultController.prototype.close, 'close');
|
|
3331
|
+
setFunctionName(ReadableStreamDefaultController.prototype.enqueue, 'enqueue');
|
|
3332
|
+
setFunctionName(ReadableStreamDefaultController.prototype.error, 'error');
|
|
2922
3333
|
if (typeof SymbolPolyfill.toStringTag === 'symbol') {
|
|
2923
3334
|
Object.defineProperty(ReadableStreamDefaultController.prototype, SymbolPolyfill.toStringTag, {
|
|
2924
3335
|
value: 'ReadableStreamDefaultController',
|
|
@@ -2952,8 +3363,10 @@ function ReadableStreamDefaultControllerCallPullIfNeeded(controller) {
|
|
|
2952
3363
|
controller._pullAgain = false;
|
|
2953
3364
|
ReadableStreamDefaultControllerCallPullIfNeeded(controller);
|
|
2954
3365
|
}
|
|
3366
|
+
return null;
|
|
2955
3367
|
}, function (e) {
|
|
2956
3368
|
ReadableStreamDefaultControllerError(controller, e);
|
|
3369
|
+
return null;
|
|
2957
3370
|
});
|
|
2958
3371
|
}
|
|
2959
3372
|
function ReadableStreamDefaultControllerShouldCallPull(controller) {
|
|
@@ -3068,29 +3481,40 @@ function SetUpReadableStreamDefaultController(stream, controller, startAlgorithm
|
|
|
3068
3481
|
uponPromise(promiseResolvedWith(startResult), function () {
|
|
3069
3482
|
controller._started = true;
|
|
3070
3483
|
ReadableStreamDefaultControllerCallPullIfNeeded(controller);
|
|
3484
|
+
return null;
|
|
3071
3485
|
}, function (r) {
|
|
3072
3486
|
ReadableStreamDefaultControllerError(controller, r);
|
|
3487
|
+
return null;
|
|
3073
3488
|
});
|
|
3074
3489
|
}
|
|
3075
3490
|
function SetUpReadableStreamDefaultControllerFromUnderlyingSource(stream, underlyingSource, highWaterMark, sizeAlgorithm) {
|
|
3076
3491
|
var controller = Object.create(ReadableStreamDefaultController.prototype);
|
|
3077
|
-
var startAlgorithm
|
|
3078
|
-
var pullAlgorithm
|
|
3079
|
-
var cancelAlgorithm
|
|
3492
|
+
var startAlgorithm;
|
|
3493
|
+
var pullAlgorithm;
|
|
3494
|
+
var cancelAlgorithm;
|
|
3080
3495
|
if (underlyingSource.start !== undefined) {
|
|
3081
3496
|
startAlgorithm = function () { return underlyingSource.start(controller); };
|
|
3082
3497
|
}
|
|
3498
|
+
else {
|
|
3499
|
+
startAlgorithm = function () { return undefined; };
|
|
3500
|
+
}
|
|
3083
3501
|
if (underlyingSource.pull !== undefined) {
|
|
3084
3502
|
pullAlgorithm = function () { return underlyingSource.pull(controller); };
|
|
3085
3503
|
}
|
|
3504
|
+
else {
|
|
3505
|
+
pullAlgorithm = function () { return promiseResolvedWith(undefined); };
|
|
3506
|
+
}
|
|
3086
3507
|
if (underlyingSource.cancel !== undefined) {
|
|
3087
3508
|
cancelAlgorithm = function (reason) { return underlyingSource.cancel(reason); };
|
|
3088
3509
|
}
|
|
3510
|
+
else {
|
|
3511
|
+
cancelAlgorithm = function () { return promiseResolvedWith(undefined); };
|
|
3512
|
+
}
|
|
3089
3513
|
SetUpReadableStreamDefaultController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, sizeAlgorithm);
|
|
3090
3514
|
}
|
|
3091
3515
|
// Helper functions for the ReadableStreamDefaultController.
|
|
3092
3516
|
function defaultControllerBrandCheckException$1(name) {
|
|
3093
|
-
return new TypeError("ReadableStreamDefaultController.prototype."
|
|
3517
|
+
return new TypeError("ReadableStreamDefaultController.prototype.".concat(name, " can only be used on a ReadableStreamDefaultController"));
|
|
3094
3518
|
}
|
|
3095
3519
|
|
|
3096
3520
|
function ReadableStreamTee(stream, cloneForBranch2) {
|
|
@@ -3124,7 +3548,7 @@ function ReadableStreamDefaultTee(stream, cloneForBranch2) {
|
|
|
3124
3548
|
// This needs to be delayed a microtask because it takes at least a microtask to detect errors (using
|
|
3125
3549
|
// reader._closedPromise below), and we want errors in stream to error both branches immediately. We cannot let
|
|
3126
3550
|
// successful synchronously-available reads get ahead of asynchronously-available errors.
|
|
3127
|
-
|
|
3551
|
+
_queueMicrotask(function () {
|
|
3128
3552
|
readAgain = false;
|
|
3129
3553
|
var chunk1 = chunk;
|
|
3130
3554
|
var chunk2 = chunk;
|
|
@@ -3195,6 +3619,7 @@ function ReadableStreamDefaultTee(stream, cloneForBranch2) {
|
|
|
3195
3619
|
if (!canceled1 || !canceled2) {
|
|
3196
3620
|
resolveCancelPromise(undefined);
|
|
3197
3621
|
}
|
|
3622
|
+
return null;
|
|
3198
3623
|
});
|
|
3199
3624
|
return [branch1, branch2];
|
|
3200
3625
|
}
|
|
@@ -3216,13 +3641,14 @@ function ReadableByteStreamTee(stream) {
|
|
|
3216
3641
|
function forwardReaderError(thisReader) {
|
|
3217
3642
|
uponRejection(thisReader._closedPromise, function (r) {
|
|
3218
3643
|
if (thisReader !== reader) {
|
|
3219
|
-
return;
|
|
3644
|
+
return null;
|
|
3220
3645
|
}
|
|
3221
3646
|
ReadableByteStreamControllerError(branch1._readableStreamController, r);
|
|
3222
3647
|
ReadableByteStreamControllerError(branch2._readableStreamController, r);
|
|
3223
3648
|
if (!canceled1 || !canceled2) {
|
|
3224
3649
|
resolveCancelPromise(undefined);
|
|
3225
3650
|
}
|
|
3651
|
+
return null;
|
|
3226
3652
|
});
|
|
3227
3653
|
}
|
|
3228
3654
|
function pullWithDefaultReader() {
|
|
@@ -3236,7 +3662,7 @@ function ReadableByteStreamTee(stream) {
|
|
|
3236
3662
|
// This needs to be delayed a microtask because it takes at least a microtask to detect errors (using
|
|
3237
3663
|
// reader._closedPromise below), and we want errors in stream to error both branches immediately. We cannot let
|
|
3238
3664
|
// successful synchronously-available reads get ahead of asynchronously-available errors.
|
|
3239
|
-
|
|
3665
|
+
_queueMicrotask(function () {
|
|
3240
3666
|
readAgainForBranch1 = false;
|
|
3241
3667
|
readAgainForBranch2 = false;
|
|
3242
3668
|
var chunk1 = chunk;
|
|
@@ -3304,7 +3730,7 @@ function ReadableByteStreamTee(stream) {
|
|
|
3304
3730
|
// This needs to be delayed a microtask because it takes at least a microtask to detect errors (using
|
|
3305
3731
|
// reader._closedPromise below), and we want errors in stream to error both branches immediately. We cannot let
|
|
3306
3732
|
// successful synchronously-available reads get ahead of asynchronously-available errors.
|
|
3307
|
-
|
|
3733
|
+
_queueMicrotask(function () {
|
|
3308
3734
|
readAgainForBranch1 = false;
|
|
3309
3735
|
readAgainForBranch2 = false;
|
|
3310
3736
|
var byobCanceled = forBranch2 ? canceled2 : canceled1;
|
|
@@ -3363,7 +3789,7 @@ function ReadableByteStreamTee(stream) {
|
|
|
3363
3789
|
reading = false;
|
|
3364
3790
|
}
|
|
3365
3791
|
};
|
|
3366
|
-
ReadableStreamBYOBReaderRead(reader, view, readIntoRequest);
|
|
3792
|
+
ReadableStreamBYOBReaderRead(reader, view, 1, readIntoRequest);
|
|
3367
3793
|
}
|
|
3368
3794
|
function pull1Algorithm() {
|
|
3369
3795
|
if (reading) {
|
|
@@ -3424,6 +3850,109 @@ function ReadableByteStreamTee(stream) {
|
|
|
3424
3850
|
return [branch1, branch2];
|
|
3425
3851
|
}
|
|
3426
3852
|
|
|
3853
|
+
function isReadableStreamLike(stream) {
|
|
3854
|
+
return typeIsObject(stream) && typeof stream.getReader !== 'undefined';
|
|
3855
|
+
}
|
|
3856
|
+
|
|
3857
|
+
function ReadableStreamFrom(source) {
|
|
3858
|
+
if (isReadableStreamLike(source)) {
|
|
3859
|
+
return ReadableStreamFromDefaultReader(source.getReader());
|
|
3860
|
+
}
|
|
3861
|
+
return ReadableStreamFromIterable(source);
|
|
3862
|
+
}
|
|
3863
|
+
function ReadableStreamFromIterable(asyncIterable) {
|
|
3864
|
+
var stream;
|
|
3865
|
+
var iteratorRecord = GetIterator(asyncIterable, 'async');
|
|
3866
|
+
var startAlgorithm = noop;
|
|
3867
|
+
function pullAlgorithm() {
|
|
3868
|
+
var nextResult;
|
|
3869
|
+
try {
|
|
3870
|
+
nextResult = IteratorNext(iteratorRecord);
|
|
3871
|
+
}
|
|
3872
|
+
catch (e) {
|
|
3873
|
+
return promiseRejectedWith(e);
|
|
3874
|
+
}
|
|
3875
|
+
var nextPromise = promiseResolvedWith(nextResult);
|
|
3876
|
+
return transformPromiseWith(nextPromise, function (iterResult) {
|
|
3877
|
+
if (!typeIsObject(iterResult)) {
|
|
3878
|
+
throw new TypeError('The promise returned by the iterator.next() method must fulfill with an object');
|
|
3879
|
+
}
|
|
3880
|
+
var done = IteratorComplete(iterResult);
|
|
3881
|
+
if (done) {
|
|
3882
|
+
ReadableStreamDefaultControllerClose(stream._readableStreamController);
|
|
3883
|
+
}
|
|
3884
|
+
else {
|
|
3885
|
+
var value = IteratorValue(iterResult);
|
|
3886
|
+
ReadableStreamDefaultControllerEnqueue(stream._readableStreamController, value);
|
|
3887
|
+
}
|
|
3888
|
+
});
|
|
3889
|
+
}
|
|
3890
|
+
function cancelAlgorithm(reason) {
|
|
3891
|
+
var iterator = iteratorRecord.iterator;
|
|
3892
|
+
var returnMethod;
|
|
3893
|
+
try {
|
|
3894
|
+
returnMethod = GetMethod(iterator, 'return');
|
|
3895
|
+
}
|
|
3896
|
+
catch (e) {
|
|
3897
|
+
return promiseRejectedWith(e);
|
|
3898
|
+
}
|
|
3899
|
+
if (returnMethod === undefined) {
|
|
3900
|
+
return promiseResolvedWith(undefined);
|
|
3901
|
+
}
|
|
3902
|
+
var returnResult;
|
|
3903
|
+
try {
|
|
3904
|
+
returnResult = reflectCall(returnMethod, iterator, [reason]);
|
|
3905
|
+
}
|
|
3906
|
+
catch (e) {
|
|
3907
|
+
return promiseRejectedWith(e);
|
|
3908
|
+
}
|
|
3909
|
+
var returnPromise = promiseResolvedWith(returnResult);
|
|
3910
|
+
return transformPromiseWith(returnPromise, function (iterResult) {
|
|
3911
|
+
if (!typeIsObject(iterResult)) {
|
|
3912
|
+
throw new TypeError('The promise returned by the iterator.return() method must fulfill with an object');
|
|
3913
|
+
}
|
|
3914
|
+
return undefined;
|
|
3915
|
+
});
|
|
3916
|
+
}
|
|
3917
|
+
stream = CreateReadableStream(startAlgorithm, pullAlgorithm, cancelAlgorithm, 0);
|
|
3918
|
+
return stream;
|
|
3919
|
+
}
|
|
3920
|
+
function ReadableStreamFromDefaultReader(reader) {
|
|
3921
|
+
var stream;
|
|
3922
|
+
var startAlgorithm = noop;
|
|
3923
|
+
function pullAlgorithm() {
|
|
3924
|
+
var readPromise;
|
|
3925
|
+
try {
|
|
3926
|
+
readPromise = reader.read();
|
|
3927
|
+
}
|
|
3928
|
+
catch (e) {
|
|
3929
|
+
return promiseRejectedWith(e);
|
|
3930
|
+
}
|
|
3931
|
+
return transformPromiseWith(readPromise, function (readResult) {
|
|
3932
|
+
if (!typeIsObject(readResult)) {
|
|
3933
|
+
throw new TypeError('The promise returned by the reader.read() method must fulfill with an object');
|
|
3934
|
+
}
|
|
3935
|
+
if (readResult.done) {
|
|
3936
|
+
ReadableStreamDefaultControllerClose(stream._readableStreamController);
|
|
3937
|
+
}
|
|
3938
|
+
else {
|
|
3939
|
+
var value = readResult.value;
|
|
3940
|
+
ReadableStreamDefaultControllerEnqueue(stream._readableStreamController, value);
|
|
3941
|
+
}
|
|
3942
|
+
});
|
|
3943
|
+
}
|
|
3944
|
+
function cancelAlgorithm(reason) {
|
|
3945
|
+
try {
|
|
3946
|
+
return promiseResolvedWith(reader.cancel(reason));
|
|
3947
|
+
}
|
|
3948
|
+
catch (e) {
|
|
3949
|
+
return promiseRejectedWith(e);
|
|
3950
|
+
}
|
|
3951
|
+
}
|
|
3952
|
+
stream = CreateReadableStream(startAlgorithm, pullAlgorithm, cancelAlgorithm, 0);
|
|
3953
|
+
return stream;
|
|
3954
|
+
}
|
|
3955
|
+
|
|
3427
3956
|
function convertUnderlyingDefaultOrByteSource(source, context) {
|
|
3428
3957
|
assertDictionary(source, context);
|
|
3429
3958
|
var original = source;
|
|
@@ -3435,17 +3964,17 @@ function convertUnderlyingDefaultOrByteSource(source, context) {
|
|
|
3435
3964
|
return {
|
|
3436
3965
|
autoAllocateChunkSize: autoAllocateChunkSize === undefined ?
|
|
3437
3966
|
undefined :
|
|
3438
|
-
convertUnsignedLongLongWithEnforceRange(autoAllocateChunkSize, context
|
|
3967
|
+
convertUnsignedLongLongWithEnforceRange(autoAllocateChunkSize, "".concat(context, " has member 'autoAllocateChunkSize' that")),
|
|
3439
3968
|
cancel: cancel === undefined ?
|
|
3440
3969
|
undefined :
|
|
3441
|
-
convertUnderlyingSourceCancelCallback(cancel, original, context
|
|
3970
|
+
convertUnderlyingSourceCancelCallback(cancel, original, "".concat(context, " has member 'cancel' that")),
|
|
3442
3971
|
pull: pull === undefined ?
|
|
3443
3972
|
undefined :
|
|
3444
|
-
convertUnderlyingSourcePullCallback(pull, original, context
|
|
3973
|
+
convertUnderlyingSourcePullCallback(pull, original, "".concat(context, " has member 'pull' that")),
|
|
3445
3974
|
start: start === undefined ?
|
|
3446
3975
|
undefined :
|
|
3447
|
-
convertUnderlyingSourceStartCallback(start, original, context
|
|
3448
|
-
type: type === undefined ? undefined : convertReadableStreamType(type, context
|
|
3976
|
+
convertUnderlyingSourceStartCallback(start, original, "".concat(context, " has member 'start' that")),
|
|
3977
|
+
type: type === undefined ? undefined : convertReadableStreamType(type, "".concat(context, " has member 'type' that"))
|
|
3449
3978
|
};
|
|
3450
3979
|
}
|
|
3451
3980
|
function convertUnderlyingSourceCancelCallback(fn, original, context) {
|
|
@@ -3461,28 +3990,13 @@ function convertUnderlyingSourceStartCallback(fn, original, context) {
|
|
|
3461
3990
|
return function (controller) { return reflectCall(fn, original, [controller]); };
|
|
3462
3991
|
}
|
|
3463
3992
|
function convertReadableStreamType(type, context) {
|
|
3464
|
-
type = ""
|
|
3993
|
+
type = "".concat(type);
|
|
3465
3994
|
if (type !== 'bytes') {
|
|
3466
|
-
throw new TypeError(context
|
|
3995
|
+
throw new TypeError("".concat(context, " '").concat(type, "' is not a valid enumeration value for ReadableStreamType"));
|
|
3467
3996
|
}
|
|
3468
3997
|
return type;
|
|
3469
3998
|
}
|
|
3470
3999
|
|
|
3471
|
-
function convertReaderOptions(options, context) {
|
|
3472
|
-
assertDictionary(options, context);
|
|
3473
|
-
var mode = options === null || options === void 0 ? void 0 : options.mode;
|
|
3474
|
-
return {
|
|
3475
|
-
mode: mode === undefined ? undefined : convertReadableStreamReaderMode(mode, context + " has member 'mode' that")
|
|
3476
|
-
};
|
|
3477
|
-
}
|
|
3478
|
-
function convertReadableStreamReaderMode(mode, context) {
|
|
3479
|
-
mode = "" + mode;
|
|
3480
|
-
if (mode !== 'byob') {
|
|
3481
|
-
throw new TypeError(context + " '" + mode + "' is not a valid enumeration value for ReadableStreamReaderMode");
|
|
3482
|
-
}
|
|
3483
|
-
return mode;
|
|
3484
|
-
}
|
|
3485
|
-
|
|
3486
4000
|
function convertIteratorOptions(options, context) {
|
|
3487
4001
|
assertDictionary(options, context);
|
|
3488
4002
|
var preventCancel = options === null || options === void 0 ? void 0 : options.preventCancel;
|
|
@@ -3496,7 +4010,7 @@ function convertPipeOptions(options, context) {
|
|
|
3496
4010
|
var preventClose = options === null || options === void 0 ? void 0 : options.preventClose;
|
|
3497
4011
|
var signal = options === null || options === void 0 ? void 0 : options.signal;
|
|
3498
4012
|
if (signal !== undefined) {
|
|
3499
|
-
assertAbortSignal(signal, context
|
|
4013
|
+
assertAbortSignal(signal, "".concat(context, " has member 'signal' that"));
|
|
3500
4014
|
}
|
|
3501
4015
|
return {
|
|
3502
4016
|
preventAbort: Boolean(preventAbort),
|
|
@@ -3507,7 +4021,7 @@ function convertPipeOptions(options, context) {
|
|
|
3507
4021
|
}
|
|
3508
4022
|
function assertAbortSignal(signal, context) {
|
|
3509
4023
|
if (!isAbortSignal(signal)) {
|
|
3510
|
-
throw new TypeError(context
|
|
4024
|
+
throw new TypeError("".concat(context, " is not an AbortSignal."));
|
|
3511
4025
|
}
|
|
3512
4026
|
}
|
|
3513
4027
|
|
|
@@ -3515,10 +4029,10 @@ function convertReadableWritablePair(pair, context) {
|
|
|
3515
4029
|
assertDictionary(pair, context);
|
|
3516
4030
|
var readable = pair === null || pair === void 0 ? void 0 : pair.readable;
|
|
3517
4031
|
assertRequiredField(readable, 'readable', 'ReadableWritablePair');
|
|
3518
|
-
assertReadableStream(readable, context
|
|
4032
|
+
assertReadableStream(readable, "".concat(context, " has member 'readable' that"));
|
|
3519
4033
|
var writable = pair === null || pair === void 0 ? void 0 : pair.writable;
|
|
3520
4034
|
assertRequiredField(writable, 'writable', 'ReadableWritablePair');
|
|
3521
|
-
assertWritableStream(writable, context
|
|
4035
|
+
assertWritableStream(writable, "".concat(context, " has member 'writable' that"));
|
|
3522
4036
|
return { readable: readable, writable: writable };
|
|
3523
4037
|
}
|
|
3524
4038
|
|
|
@@ -3663,8 +4177,20 @@ var ReadableStream = /** @class */ (function () {
|
|
|
3663
4177
|
var options = convertIteratorOptions(rawOptions, 'First parameter');
|
|
3664
4178
|
return AcquireReadableStreamAsyncIterator(this, options.preventCancel);
|
|
3665
4179
|
};
|
|
4180
|
+
/**
|
|
4181
|
+
* Creates a new ReadableStream wrapping the provided iterable or async iterable.
|
|
4182
|
+
*
|
|
4183
|
+
* This can be used to adapt various kinds of objects into a readable stream,
|
|
4184
|
+
* such as an array, an async generator, or a Node.js readable stream.
|
|
4185
|
+
*/
|
|
4186
|
+
ReadableStream.from = function (asyncIterable) {
|
|
4187
|
+
return ReadableStreamFrom(asyncIterable);
|
|
4188
|
+
};
|
|
3666
4189
|
return ReadableStream;
|
|
3667
4190
|
}());
|
|
4191
|
+
Object.defineProperties(ReadableStream, {
|
|
4192
|
+
from: { enumerable: true }
|
|
4193
|
+
});
|
|
3668
4194
|
Object.defineProperties(ReadableStream.prototype, {
|
|
3669
4195
|
cancel: { enumerable: true },
|
|
3670
4196
|
getReader: { enumerable: true },
|
|
@@ -3674,6 +4200,13 @@ Object.defineProperties(ReadableStream.prototype, {
|
|
|
3674
4200
|
values: { enumerable: true },
|
|
3675
4201
|
locked: { enumerable: true }
|
|
3676
4202
|
});
|
|
4203
|
+
setFunctionName(ReadableStream.from, 'from');
|
|
4204
|
+
setFunctionName(ReadableStream.prototype.cancel, 'cancel');
|
|
4205
|
+
setFunctionName(ReadableStream.prototype.getReader, 'getReader');
|
|
4206
|
+
setFunctionName(ReadableStream.prototype.pipeThrough, 'pipeThrough');
|
|
4207
|
+
setFunctionName(ReadableStream.prototype.pipeTo, 'pipeTo');
|
|
4208
|
+
setFunctionName(ReadableStream.prototype.tee, 'tee');
|
|
4209
|
+
setFunctionName(ReadableStream.prototype.values, 'values');
|
|
3677
4210
|
if (typeof SymbolPolyfill.toStringTag === 'symbol') {
|
|
3678
4211
|
Object.defineProperty(ReadableStream.prototype, SymbolPolyfill.toStringTag, {
|
|
3679
4212
|
value: 'ReadableStream',
|
|
@@ -3739,10 +4272,11 @@ function ReadableStreamCancel(stream, reason) {
|
|
|
3739
4272
|
ReadableStreamClose(stream);
|
|
3740
4273
|
var reader = stream._reader;
|
|
3741
4274
|
if (reader !== undefined && IsReadableStreamBYOBReader(reader)) {
|
|
3742
|
-
reader._readIntoRequests
|
|
4275
|
+
var readIntoRequests = reader._readIntoRequests;
|
|
4276
|
+
reader._readIntoRequests = new SimpleQueue();
|
|
4277
|
+
readIntoRequests.forEach(function (readIntoRequest) {
|
|
3743
4278
|
readIntoRequest._closeSteps(undefined);
|
|
3744
4279
|
});
|
|
3745
|
-
reader._readIntoRequests = new SimpleQueue();
|
|
3746
4280
|
}
|
|
3747
4281
|
var sourceCancelPromise = stream._readableStreamController[CancelSteps](reason);
|
|
3748
4282
|
return transformPromiseWith(sourceCancelPromise, noop);
|
|
@@ -3755,10 +4289,11 @@ function ReadableStreamClose(stream) {
|
|
|
3755
4289
|
}
|
|
3756
4290
|
defaultReaderClosedPromiseResolve(reader);
|
|
3757
4291
|
if (IsReadableStreamDefaultReader(reader)) {
|
|
3758
|
-
reader._readRequests
|
|
4292
|
+
var readRequests = reader._readRequests;
|
|
4293
|
+
reader._readRequests = new SimpleQueue();
|
|
4294
|
+
readRequests.forEach(function (readRequest) {
|
|
3759
4295
|
readRequest._closeSteps();
|
|
3760
4296
|
});
|
|
3761
|
-
reader._readRequests = new SimpleQueue();
|
|
3762
4297
|
}
|
|
3763
4298
|
}
|
|
3764
4299
|
function ReadableStreamError(stream, e) {
|
|
@@ -3770,21 +4305,15 @@ function ReadableStreamError(stream, e) {
|
|
|
3770
4305
|
}
|
|
3771
4306
|
defaultReaderClosedPromiseReject(reader, e);
|
|
3772
4307
|
if (IsReadableStreamDefaultReader(reader)) {
|
|
3773
|
-
reader
|
|
3774
|
-
readRequest._errorSteps(e);
|
|
3775
|
-
});
|
|
3776
|
-
reader._readRequests = new SimpleQueue();
|
|
4308
|
+
ReadableStreamDefaultReaderErrorReadRequests(reader, e);
|
|
3777
4309
|
}
|
|
3778
4310
|
else {
|
|
3779
|
-
reader
|
|
3780
|
-
readIntoRequest._errorSteps(e);
|
|
3781
|
-
});
|
|
3782
|
-
reader._readIntoRequests = new SimpleQueue();
|
|
4311
|
+
ReadableStreamBYOBReaderErrorReadIntoRequests(reader, e);
|
|
3783
4312
|
}
|
|
3784
4313
|
}
|
|
3785
4314
|
// Helper functions for the ReadableStream.
|
|
3786
4315
|
function streamBrandCheckException$1(name) {
|
|
3787
|
-
return new TypeError("ReadableStream.prototype."
|
|
4316
|
+
return new TypeError("ReadableStream.prototype.".concat(name, " can only be used on a ReadableStream"));
|
|
3788
4317
|
}
|
|
3789
4318
|
|
|
3790
4319
|
function convertQueuingStrategyInit(init, context) {
|
|
@@ -3800,10 +4329,7 @@ function convertQueuingStrategyInit(init, context) {
|
|
|
3800
4329
|
var byteLengthSizeFunction = function (chunk) {
|
|
3801
4330
|
return chunk.byteLength;
|
|
3802
4331
|
};
|
|
3803
|
-
|
|
3804
|
-
value: 'size',
|
|
3805
|
-
configurable: true
|
|
3806
|
-
});
|
|
4332
|
+
setFunctionName(byteLengthSizeFunction, 'size');
|
|
3807
4333
|
/**
|
|
3808
4334
|
* A queuing strategy that counts the number of bytes in each chunk.
|
|
3809
4335
|
*
|
|
@@ -3855,7 +4381,7 @@ if (typeof SymbolPolyfill.toStringTag === 'symbol') {
|
|
|
3855
4381
|
}
|
|
3856
4382
|
// Helper functions for the ByteLengthQueuingStrategy.
|
|
3857
4383
|
function byteLengthBrandCheckException(name) {
|
|
3858
|
-
return new TypeError("ByteLengthQueuingStrategy.prototype."
|
|
4384
|
+
return new TypeError("ByteLengthQueuingStrategy.prototype.".concat(name, " can only be used on a ByteLengthQueuingStrategy"));
|
|
3859
4385
|
}
|
|
3860
4386
|
function IsByteLengthQueuingStrategy(x) {
|
|
3861
4387
|
if (!typeIsObject(x)) {
|
|
@@ -3871,10 +4397,7 @@ function IsByteLengthQueuingStrategy(x) {
|
|
|
3871
4397
|
var countSizeFunction = function () {
|
|
3872
4398
|
return 1;
|
|
3873
4399
|
};
|
|
3874
|
-
|
|
3875
|
-
value: 'size',
|
|
3876
|
-
configurable: true
|
|
3877
|
-
});
|
|
4400
|
+
setFunctionName(countSizeFunction, 'size');
|
|
3878
4401
|
/**
|
|
3879
4402
|
* A queuing strategy that counts the number of chunks.
|
|
3880
4403
|
*
|
|
@@ -3927,7 +4450,7 @@ if (typeof SymbolPolyfill.toStringTag === 'symbol') {
|
|
|
3927
4450
|
}
|
|
3928
4451
|
// Helper functions for the CountQueuingStrategy.
|
|
3929
4452
|
function countBrandCheckException(name) {
|
|
3930
|
-
return new TypeError("CountQueuingStrategy.prototype."
|
|
4453
|
+
return new TypeError("CountQueuingStrategy.prototype.".concat(name, " can only be used on a CountQueuingStrategy"));
|
|
3931
4454
|
}
|
|
3932
4455
|
function IsCountQueuingStrategy(x) {
|
|
3933
4456
|
if (!typeIsObject(x)) {
|
|
@@ -3941,22 +4464,26 @@ function IsCountQueuingStrategy(x) {
|
|
|
3941
4464
|
|
|
3942
4465
|
function convertTransformer(original, context) {
|
|
3943
4466
|
assertDictionary(original, context);
|
|
4467
|
+
var cancel = original === null || original === void 0 ? void 0 : original.cancel;
|
|
3944
4468
|
var flush = original === null || original === void 0 ? void 0 : original.flush;
|
|
3945
4469
|
var readableType = original === null || original === void 0 ? void 0 : original.readableType;
|
|
3946
4470
|
var start = original === null || original === void 0 ? void 0 : original.start;
|
|
3947
4471
|
var transform = original === null || original === void 0 ? void 0 : original.transform;
|
|
3948
4472
|
var writableType = original === null || original === void 0 ? void 0 : original.writableType;
|
|
3949
4473
|
return {
|
|
4474
|
+
cancel: cancel === undefined ?
|
|
4475
|
+
undefined :
|
|
4476
|
+
convertTransformerCancelCallback(cancel, original, "".concat(context, " has member 'cancel' that")),
|
|
3950
4477
|
flush: flush === undefined ?
|
|
3951
4478
|
undefined :
|
|
3952
|
-
convertTransformerFlushCallback(flush, original, context
|
|
4479
|
+
convertTransformerFlushCallback(flush, original, "".concat(context, " has member 'flush' that")),
|
|
3953
4480
|
readableType: readableType,
|
|
3954
4481
|
start: start === undefined ?
|
|
3955
4482
|
undefined :
|
|
3956
|
-
convertTransformerStartCallback(start, original, context
|
|
4483
|
+
convertTransformerStartCallback(start, original, "".concat(context, " has member 'start' that")),
|
|
3957
4484
|
transform: transform === undefined ?
|
|
3958
4485
|
undefined :
|
|
3959
|
-
convertTransformerTransformCallback(transform, original, context
|
|
4486
|
+
convertTransformerTransformCallback(transform, original, "".concat(context, " has member 'transform' that")),
|
|
3960
4487
|
writableType: writableType
|
|
3961
4488
|
};
|
|
3962
4489
|
}
|
|
@@ -3972,6 +4499,10 @@ function convertTransformerTransformCallback(fn, original, context) {
|
|
|
3972
4499
|
assertFunction(fn, context);
|
|
3973
4500
|
return function (chunk, controller) { return promiseCall(fn, original, [chunk, controller]); };
|
|
3974
4501
|
}
|
|
4502
|
+
function convertTransformerCancelCallback(fn, original, context) {
|
|
4503
|
+
assertFunction(fn, context);
|
|
4504
|
+
return function (reason) { return promiseCall(fn, original, [reason]); };
|
|
4505
|
+
}
|
|
3975
4506
|
|
|
3976
4507
|
// Class TransformStream
|
|
3977
4508
|
/**
|
|
@@ -4072,8 +4603,7 @@ function InitializeTransformStream(stream, startPromise, writableHighWaterMark,
|
|
|
4072
4603
|
return TransformStreamDefaultSourcePullAlgorithm(stream);
|
|
4073
4604
|
}
|
|
4074
4605
|
function cancelAlgorithm(reason) {
|
|
4075
|
-
|
|
4076
|
-
return promiseResolvedWith(undefined);
|
|
4606
|
+
return TransformStreamDefaultSourceCancelAlgorithm(stream, reason);
|
|
4077
4607
|
}
|
|
4078
4608
|
stream._readable = CreateReadableStream(startAlgorithm, pullAlgorithm, cancelAlgorithm, readableHighWaterMark, readableSizeAlgorithm);
|
|
4079
4609
|
// The [[backpressure]] slot is set to undefined so that it can be initialised by TransformStreamSetBackpressure.
|
|
@@ -4100,6 +4630,9 @@ function TransformStreamError(stream, e) {
|
|
|
4100
4630
|
function TransformStreamErrorWritableAndUnblockWrite(stream, e) {
|
|
4101
4631
|
TransformStreamDefaultControllerClearAlgorithms(stream._transformStreamController);
|
|
4102
4632
|
WritableStreamDefaultControllerErrorIfNeeded(stream._writable._writableStreamController, e);
|
|
4633
|
+
TransformStreamUnblockWrite(stream);
|
|
4634
|
+
}
|
|
4635
|
+
function TransformStreamUnblockWrite(stream) {
|
|
4103
4636
|
if (stream._backpressure) {
|
|
4104
4637
|
// Pretend that pull() was called to permit any pending write() calls to complete. TransformStreamSetBackpressure()
|
|
4105
4638
|
// cannot be called from enqueue() or pull() once the ReadableStream is errored, so this will will be the final time
|
|
@@ -4177,6 +4710,9 @@ Object.defineProperties(TransformStreamDefaultController.prototype, {
|
|
|
4177
4710
|
terminate: { enumerable: true },
|
|
4178
4711
|
desiredSize: { enumerable: true }
|
|
4179
4712
|
});
|
|
4713
|
+
setFunctionName(TransformStreamDefaultController.prototype.enqueue, 'enqueue');
|
|
4714
|
+
setFunctionName(TransformStreamDefaultController.prototype.error, 'error');
|
|
4715
|
+
setFunctionName(TransformStreamDefaultController.prototype.terminate, 'terminate');
|
|
4180
4716
|
if (typeof SymbolPolyfill.toStringTag === 'symbol') {
|
|
4181
4717
|
Object.defineProperty(TransformStreamDefaultController.prototype, SymbolPolyfill.toStringTag, {
|
|
4182
4718
|
value: 'TransformStreamDefaultController',
|
|
@@ -4193,35 +4729,53 @@ function IsTransformStreamDefaultController(x) {
|
|
|
4193
4729
|
}
|
|
4194
4730
|
return x instanceof TransformStreamDefaultController;
|
|
4195
4731
|
}
|
|
4196
|
-
function SetUpTransformStreamDefaultController(stream, controller, transformAlgorithm, flushAlgorithm) {
|
|
4732
|
+
function SetUpTransformStreamDefaultController(stream, controller, transformAlgorithm, flushAlgorithm, cancelAlgorithm) {
|
|
4197
4733
|
controller._controlledTransformStream = stream;
|
|
4198
4734
|
stream._transformStreamController = controller;
|
|
4199
4735
|
controller._transformAlgorithm = transformAlgorithm;
|
|
4200
4736
|
controller._flushAlgorithm = flushAlgorithm;
|
|
4737
|
+
controller._cancelAlgorithm = cancelAlgorithm;
|
|
4738
|
+
controller._finishPromise = undefined;
|
|
4739
|
+
controller._finishPromise_resolve = undefined;
|
|
4740
|
+
controller._finishPromise_reject = undefined;
|
|
4201
4741
|
}
|
|
4202
4742
|
function SetUpTransformStreamDefaultControllerFromTransformer(stream, transformer) {
|
|
4203
4743
|
var controller = Object.create(TransformStreamDefaultController.prototype);
|
|
4204
|
-
var transformAlgorithm
|
|
4205
|
-
|
|
4206
|
-
|
|
4207
|
-
return promiseResolvedWith(undefined);
|
|
4208
|
-
}
|
|
4209
|
-
catch (transformResultE) {
|
|
4210
|
-
return promiseRejectedWith(transformResultE);
|
|
4211
|
-
}
|
|
4212
|
-
};
|
|
4213
|
-
var flushAlgorithm = function () { return promiseResolvedWith(undefined); };
|
|
4744
|
+
var transformAlgorithm;
|
|
4745
|
+
var flushAlgorithm;
|
|
4746
|
+
var cancelAlgorithm;
|
|
4214
4747
|
if (transformer.transform !== undefined) {
|
|
4215
4748
|
transformAlgorithm = function (chunk) { return transformer.transform(chunk, controller); };
|
|
4216
4749
|
}
|
|
4750
|
+
else {
|
|
4751
|
+
transformAlgorithm = function (chunk) {
|
|
4752
|
+
try {
|
|
4753
|
+
TransformStreamDefaultControllerEnqueue(controller, chunk);
|
|
4754
|
+
return promiseResolvedWith(undefined);
|
|
4755
|
+
}
|
|
4756
|
+
catch (transformResultE) {
|
|
4757
|
+
return promiseRejectedWith(transformResultE);
|
|
4758
|
+
}
|
|
4759
|
+
};
|
|
4760
|
+
}
|
|
4217
4761
|
if (transformer.flush !== undefined) {
|
|
4218
4762
|
flushAlgorithm = function () { return transformer.flush(controller); };
|
|
4219
4763
|
}
|
|
4220
|
-
|
|
4764
|
+
else {
|
|
4765
|
+
flushAlgorithm = function () { return promiseResolvedWith(undefined); };
|
|
4766
|
+
}
|
|
4767
|
+
if (transformer.cancel !== undefined) {
|
|
4768
|
+
cancelAlgorithm = function (reason) { return transformer.cancel(reason); };
|
|
4769
|
+
}
|
|
4770
|
+
else {
|
|
4771
|
+
cancelAlgorithm = function () { return promiseResolvedWith(undefined); };
|
|
4772
|
+
}
|
|
4773
|
+
SetUpTransformStreamDefaultController(stream, controller, transformAlgorithm, flushAlgorithm, cancelAlgorithm);
|
|
4221
4774
|
}
|
|
4222
4775
|
function TransformStreamDefaultControllerClearAlgorithms(controller) {
|
|
4223
4776
|
controller._transformAlgorithm = undefined;
|
|
4224
4777
|
controller._flushAlgorithm = undefined;
|
|
4778
|
+
controller._cancelAlgorithm = undefined;
|
|
4225
4779
|
}
|
|
4226
4780
|
function TransformStreamDefaultControllerEnqueue(controller, chunk) {
|
|
4227
4781
|
var stream = controller._controlledTransformStream;
|
|
@@ -4278,27 +4832,66 @@ function TransformStreamDefaultSinkWriteAlgorithm(stream, chunk) {
|
|
|
4278
4832
|
return TransformStreamDefaultControllerPerformTransform(controller, chunk);
|
|
4279
4833
|
}
|
|
4280
4834
|
function TransformStreamDefaultSinkAbortAlgorithm(stream, reason) {
|
|
4281
|
-
|
|
4282
|
-
|
|
4283
|
-
|
|
4284
|
-
|
|
4835
|
+
var controller = stream._transformStreamController;
|
|
4836
|
+
if (controller._finishPromise !== undefined) {
|
|
4837
|
+
return controller._finishPromise;
|
|
4838
|
+
}
|
|
4839
|
+
// stream._readable cannot change after construction, so caching it across a call to user code is safe.
|
|
4840
|
+
var readable = stream._readable;
|
|
4841
|
+
// Assign the _finishPromise now so that if _cancelAlgorithm calls readable.cancel() internally,
|
|
4842
|
+
// we don't run the _cancelAlgorithm again.
|
|
4843
|
+
controller._finishPromise = newPromise(function (resolve, reject) {
|
|
4844
|
+
controller._finishPromise_resolve = resolve;
|
|
4845
|
+
controller._finishPromise_reject = reject;
|
|
4846
|
+
});
|
|
4847
|
+
var cancelPromise = controller._cancelAlgorithm(reason);
|
|
4848
|
+
TransformStreamDefaultControllerClearAlgorithms(controller);
|
|
4849
|
+
uponPromise(cancelPromise, function () {
|
|
4850
|
+
if (readable._state === 'errored') {
|
|
4851
|
+
defaultControllerFinishPromiseReject(controller, readable._storedError);
|
|
4852
|
+
}
|
|
4853
|
+
else {
|
|
4854
|
+
ReadableStreamDefaultControllerError(readable._readableStreamController, reason);
|
|
4855
|
+
defaultControllerFinishPromiseResolve(controller);
|
|
4856
|
+
}
|
|
4857
|
+
return null;
|
|
4858
|
+
}, function (r) {
|
|
4859
|
+
ReadableStreamDefaultControllerError(readable._readableStreamController, r);
|
|
4860
|
+
defaultControllerFinishPromiseReject(controller, r);
|
|
4861
|
+
return null;
|
|
4862
|
+
});
|
|
4863
|
+
return controller._finishPromise;
|
|
4285
4864
|
}
|
|
4286
4865
|
function TransformStreamDefaultSinkCloseAlgorithm(stream) {
|
|
4866
|
+
var controller = stream._transformStreamController;
|
|
4867
|
+
if (controller._finishPromise !== undefined) {
|
|
4868
|
+
return controller._finishPromise;
|
|
4869
|
+
}
|
|
4287
4870
|
// stream._readable cannot change after construction, so caching it across a call to user code is safe.
|
|
4288
4871
|
var readable = stream._readable;
|
|
4289
|
-
|
|
4872
|
+
// Assign the _finishPromise now so that if _flushAlgorithm calls readable.cancel() internally,
|
|
4873
|
+
// we don't also run the _cancelAlgorithm.
|
|
4874
|
+
controller._finishPromise = newPromise(function (resolve, reject) {
|
|
4875
|
+
controller._finishPromise_resolve = resolve;
|
|
4876
|
+
controller._finishPromise_reject = reject;
|
|
4877
|
+
});
|
|
4290
4878
|
var flushPromise = controller._flushAlgorithm();
|
|
4291
4879
|
TransformStreamDefaultControllerClearAlgorithms(controller);
|
|
4292
|
-
|
|
4293
|
-
return transformPromiseWith(flushPromise, function () {
|
|
4880
|
+
uponPromise(flushPromise, function () {
|
|
4294
4881
|
if (readable._state === 'errored') {
|
|
4295
|
-
|
|
4882
|
+
defaultControllerFinishPromiseReject(controller, readable._storedError);
|
|
4883
|
+
}
|
|
4884
|
+
else {
|
|
4885
|
+
ReadableStreamDefaultControllerClose(readable._readableStreamController);
|
|
4886
|
+
defaultControllerFinishPromiseResolve(controller);
|
|
4296
4887
|
}
|
|
4297
|
-
|
|
4888
|
+
return null;
|
|
4298
4889
|
}, function (r) {
|
|
4299
|
-
|
|
4300
|
-
|
|
4890
|
+
ReadableStreamDefaultControllerError(readable._readableStreamController, r);
|
|
4891
|
+
defaultControllerFinishPromiseReject(controller, r);
|
|
4892
|
+
return null;
|
|
4301
4893
|
});
|
|
4894
|
+
return controller._finishPromise;
|
|
4302
4895
|
}
|
|
4303
4896
|
// TransformStreamDefaultSource Algorithms
|
|
4304
4897
|
function TransformStreamDefaultSourcePullAlgorithm(stream) {
|
|
@@ -4307,13 +4900,64 @@ function TransformStreamDefaultSourcePullAlgorithm(stream) {
|
|
|
4307
4900
|
// Prevent the next pull() call until there is backpressure.
|
|
4308
4901
|
return stream._backpressureChangePromise;
|
|
4309
4902
|
}
|
|
4903
|
+
function TransformStreamDefaultSourceCancelAlgorithm(stream, reason) {
|
|
4904
|
+
var controller = stream._transformStreamController;
|
|
4905
|
+
if (controller._finishPromise !== undefined) {
|
|
4906
|
+
return controller._finishPromise;
|
|
4907
|
+
}
|
|
4908
|
+
// stream._writable cannot change after construction, so caching it across a call to user code is safe.
|
|
4909
|
+
var writable = stream._writable;
|
|
4910
|
+
// Assign the _finishPromise now so that if _flushAlgorithm calls writable.abort() or
|
|
4911
|
+
// writable.cancel() internally, we don't run the _cancelAlgorithm again, or also run the
|
|
4912
|
+
// _flushAlgorithm.
|
|
4913
|
+
controller._finishPromise = newPromise(function (resolve, reject) {
|
|
4914
|
+
controller._finishPromise_resolve = resolve;
|
|
4915
|
+
controller._finishPromise_reject = reject;
|
|
4916
|
+
});
|
|
4917
|
+
var cancelPromise = controller._cancelAlgorithm(reason);
|
|
4918
|
+
TransformStreamDefaultControllerClearAlgorithms(controller);
|
|
4919
|
+
uponPromise(cancelPromise, function () {
|
|
4920
|
+
if (writable._state === 'errored') {
|
|
4921
|
+
defaultControllerFinishPromiseReject(controller, writable._storedError);
|
|
4922
|
+
}
|
|
4923
|
+
else {
|
|
4924
|
+
WritableStreamDefaultControllerErrorIfNeeded(writable._writableStreamController, reason);
|
|
4925
|
+
TransformStreamUnblockWrite(stream);
|
|
4926
|
+
defaultControllerFinishPromiseResolve(controller);
|
|
4927
|
+
}
|
|
4928
|
+
return null;
|
|
4929
|
+
}, function (r) {
|
|
4930
|
+
WritableStreamDefaultControllerErrorIfNeeded(writable._writableStreamController, r);
|
|
4931
|
+
TransformStreamUnblockWrite(stream);
|
|
4932
|
+
defaultControllerFinishPromiseReject(controller, r);
|
|
4933
|
+
return null;
|
|
4934
|
+
});
|
|
4935
|
+
return controller._finishPromise;
|
|
4936
|
+
}
|
|
4310
4937
|
// Helper functions for the TransformStreamDefaultController.
|
|
4311
4938
|
function defaultControllerBrandCheckException(name) {
|
|
4312
|
-
return new TypeError("TransformStreamDefaultController.prototype."
|
|
4939
|
+
return new TypeError("TransformStreamDefaultController.prototype.".concat(name, " can only be used on a TransformStreamDefaultController"));
|
|
4940
|
+
}
|
|
4941
|
+
function defaultControllerFinishPromiseResolve(controller) {
|
|
4942
|
+
if (controller._finishPromise_resolve === undefined) {
|
|
4943
|
+
return;
|
|
4944
|
+
}
|
|
4945
|
+
controller._finishPromise_resolve();
|
|
4946
|
+
controller._finishPromise_resolve = undefined;
|
|
4947
|
+
controller._finishPromise_reject = undefined;
|
|
4948
|
+
}
|
|
4949
|
+
function defaultControllerFinishPromiseReject(controller, reason) {
|
|
4950
|
+
if (controller._finishPromise_reject === undefined) {
|
|
4951
|
+
return;
|
|
4952
|
+
}
|
|
4953
|
+
setPromiseIsHandledToTrue(controller._finishPromise);
|
|
4954
|
+
controller._finishPromise_reject(reason);
|
|
4955
|
+
controller._finishPromise_resolve = undefined;
|
|
4956
|
+
controller._finishPromise_reject = undefined;
|
|
4313
4957
|
}
|
|
4314
4958
|
// Helper functions for the TransformStream.
|
|
4315
4959
|
function streamBrandCheckException(name) {
|
|
4316
|
-
return new TypeError("TransformStream.prototype."
|
|
4960
|
+
return new TypeError("TransformStream.prototype.".concat(name, " can only be used on a TransformStream"));
|
|
4317
4961
|
}
|
|
4318
4962
|
|
|
4319
4963
|
export { ByteLengthQueuingStrategy, CountQueuingStrategy, ReadableByteStreamController, ReadableStream, ReadableStreamBYOBReader, ReadableStreamBYOBRequest, ReadableStreamDefaultController, ReadableStreamDefaultReader, TransformStream, TransformStreamDefaultController, WritableStream, WritableStreamDefaultController, WritableStreamDefaultWriter };
|