web-streams-polyfill 3.0.0 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +24 -0
- package/README.md +10 -6
- package/dist/polyfill.es2018.js +739 -128
- package/dist/polyfill.es2018.js.map +1 -1
- package/dist/polyfill.es2018.min.js +1 -1
- package/dist/polyfill.es2018.min.js.map +1 -1
- package/dist/polyfill.es2018.mjs +738 -127
- package/dist/polyfill.es2018.mjs.map +1 -1
- package/dist/polyfill.es6.js +739 -128
- package/dist/polyfill.es6.js.map +1 -1
- package/dist/polyfill.es6.min.js +1 -1
- package/dist/polyfill.es6.min.js.map +1 -1
- package/dist/polyfill.es6.mjs +738 -127
- package/dist/polyfill.es6.mjs.map +1 -1
- package/dist/polyfill.js +747 -128
- package/dist/polyfill.js.map +1 -1
- package/dist/polyfill.min.js +1 -1
- package/dist/polyfill.min.js.map +1 -1
- package/dist/polyfill.mjs +746 -127
- package/dist/polyfill.mjs.map +1 -1
- package/dist/ponyfill.es2018.js +739 -128
- package/dist/ponyfill.es2018.js.map +1 -1
- package/dist/ponyfill.es2018.mjs +738 -127
- package/dist/ponyfill.es2018.mjs.map +1 -1
- package/dist/ponyfill.es6.js +739 -128
- package/dist/ponyfill.es6.js.map +1 -1
- package/dist/ponyfill.es6.mjs +738 -127
- package/dist/ponyfill.es6.mjs.map +1 -1
- package/dist/ponyfill.js +747 -128
- package/dist/ponyfill.js.map +1 -1
- package/dist/ponyfill.mjs +746 -127
- package/dist/ponyfill.mjs.map +1 -1
- package/dist/types/polyfill.d.ts +550 -15
- package/dist/types/ts3.6/polyfill.d.ts +550 -15
- package/dist/types/tsdoc-metadata.json +1 -1
- package/package.json +18 -17
package/dist/polyfill.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* web-streams-polyfill v3.
|
|
2
|
+
* web-streams-polyfill v3.1.0
|
|
3
3
|
*/
|
|
4
4
|
(function (global, factory) {
|
|
5
5
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
6
6
|
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
7
|
-
(global = global || self, factory(global.WebStreamsPolyfill = {}));
|
|
7
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.WebStreamsPolyfill = {}));
|
|
8
8
|
}(this, (function (exports) { 'use strict';
|
|
9
9
|
|
|
10
10
|
/// <reference lib="es2015.symbol" />
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
/// <reference lib="dom" />
|
|
16
16
|
function noop() {
|
|
17
|
-
|
|
17
|
+
return undefined;
|
|
18
18
|
}
|
|
19
19
|
function getGlobals() {
|
|
20
20
|
if (typeof self !== 'undefined') {
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
function typeIsObject(x) {
|
|
34
34
|
return (typeof x === 'object' && x !== null) || typeof x === 'function';
|
|
35
35
|
}
|
|
36
|
-
var rethrowAssertionErrorRejection =
|
|
36
|
+
var rethrowAssertionErrorRejection = noop;
|
|
37
37
|
|
|
38
38
|
var originalPromise = Promise;
|
|
39
39
|
var originalPromiseThen = Promise.prototype.then;
|
|
@@ -253,6 +253,9 @@
|
|
|
253
253
|
defaultReaderClosedPromiseResolve(reader);
|
|
254
254
|
}
|
|
255
255
|
function defaultReaderClosedPromiseReject(reader, reason) {
|
|
256
|
+
if (reader._closedPromise_reject === undefined) {
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
256
259
|
setPromiseIsHandledToTrue(reader._closedPromise);
|
|
257
260
|
reader._closedPromise_reject(reason);
|
|
258
261
|
reader._closedPromise_resolve = undefined;
|
|
@@ -262,6 +265,9 @@
|
|
|
262
265
|
defaultReaderClosedPromiseInitializeAsRejected(reader, reason);
|
|
263
266
|
}
|
|
264
267
|
function defaultReaderClosedPromiseResolve(reader) {
|
|
268
|
+
if (reader._closedPromise_resolve === undefined) {
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
265
271
|
reader._closedPromise_resolve(undefined);
|
|
266
272
|
reader._closedPromise_resolve = undefined;
|
|
267
273
|
reader._closedPromise_reject = undefined;
|
|
@@ -388,6 +394,11 @@
|
|
|
388
394
|
}
|
|
389
395
|
return true;
|
|
390
396
|
}
|
|
397
|
+
/**
|
|
398
|
+
* A default reader vended by a {@link ReadableStream}.
|
|
399
|
+
*
|
|
400
|
+
* @public
|
|
401
|
+
*/
|
|
391
402
|
var ReadableStreamDefaultReader = /** @class */ (function () {
|
|
392
403
|
function ReadableStreamDefaultReader(stream) {
|
|
393
404
|
assertRequiredArgument(stream, 1, 'ReadableStreamDefaultReader');
|
|
@@ -399,6 +410,10 @@
|
|
|
399
410
|
this._readRequests = new SimpleQueue();
|
|
400
411
|
}
|
|
401
412
|
Object.defineProperty(ReadableStreamDefaultReader.prototype, "closed", {
|
|
413
|
+
/**
|
|
414
|
+
* Returns a promise that will be fulfilled when the stream becomes closed,
|
|
415
|
+
* or rejected if the stream ever errors or the reader's lock is released before the stream finishes closing.
|
|
416
|
+
*/
|
|
402
417
|
get: function () {
|
|
403
418
|
if (!IsReadableStreamDefaultReader(this)) {
|
|
404
419
|
return promiseRejectedWith(defaultReaderBrandCheckException('closed'));
|
|
@@ -408,6 +423,9 @@
|
|
|
408
423
|
enumerable: false,
|
|
409
424
|
configurable: true
|
|
410
425
|
});
|
|
426
|
+
/**
|
|
427
|
+
* If the reader is active, behaves the same as {@link ReadableStream.cancel | stream.cancel(reason)}.
|
|
428
|
+
*/
|
|
411
429
|
ReadableStreamDefaultReader.prototype.cancel = function (reason) {
|
|
412
430
|
if (reason === void 0) { reason = undefined; }
|
|
413
431
|
if (!IsReadableStreamDefaultReader(this)) {
|
|
@@ -418,6 +436,11 @@
|
|
|
418
436
|
}
|
|
419
437
|
return ReadableStreamReaderGenericCancel(this, reason);
|
|
420
438
|
};
|
|
439
|
+
/**
|
|
440
|
+
* Returns a promise that allows access to the next chunk from the stream's internal queue, if available.
|
|
441
|
+
*
|
|
442
|
+
* If reading a chunk causes the queue to become empty, more data will be pulled from the underlying source.
|
|
443
|
+
*/
|
|
421
444
|
ReadableStreamDefaultReader.prototype.read = function () {
|
|
422
445
|
if (!IsReadableStreamDefaultReader(this)) {
|
|
423
446
|
return promiseRejectedWith(defaultReaderBrandCheckException('read'));
|
|
@@ -439,6 +462,15 @@
|
|
|
439
462
|
ReadableStreamDefaultReaderRead(this, readRequest);
|
|
440
463
|
return promise;
|
|
441
464
|
};
|
|
465
|
+
/**
|
|
466
|
+
* Releases the reader's lock on the corresponding stream. After the lock is released, the reader is no longer active.
|
|
467
|
+
* If the associated stream is errored when the lock is released, the reader will appear errored in the same way
|
|
468
|
+
* from now on; otherwise, the reader will appear closed.
|
|
469
|
+
*
|
|
470
|
+
* A reader's lock cannot be released while it still has a pending read request, i.e., if a promise returned by
|
|
471
|
+
* the reader's {@link ReadableStreamDefaultReader.read | read()} method has not yet been settled. Attempting to
|
|
472
|
+
* do so will throw a `TypeError` and leave the reader locked to the stream.
|
|
473
|
+
*/
|
|
442
474
|
ReadableStreamDefaultReader.prototype.releaseLock = function () {
|
|
443
475
|
if (!IsReadableStreamDefaultReader(this)) {
|
|
444
476
|
throw defaultReaderBrandCheckException('releaseLock');
|
|
@@ -473,7 +505,7 @@
|
|
|
473
505
|
if (!Object.prototype.hasOwnProperty.call(x, '_readRequests')) {
|
|
474
506
|
return false;
|
|
475
507
|
}
|
|
476
|
-
return
|
|
508
|
+
return x instanceof ReadableStreamDefaultReader;
|
|
477
509
|
}
|
|
478
510
|
function ReadableStreamDefaultReaderRead(reader, readRequest) {
|
|
479
511
|
var stream = reader._ownerReadableStream;
|
|
@@ -621,7 +653,14 @@
|
|
|
621
653
|
if (!Object.prototype.hasOwnProperty.call(x, '_asyncIteratorImpl')) {
|
|
622
654
|
return false;
|
|
623
655
|
}
|
|
624
|
-
|
|
656
|
+
try {
|
|
657
|
+
// noinspection SuspiciousTypeOfGuard
|
|
658
|
+
return x._asyncIteratorImpl instanceof
|
|
659
|
+
ReadableStreamAsyncIteratorImpl;
|
|
660
|
+
}
|
|
661
|
+
catch (_a) {
|
|
662
|
+
return false;
|
|
663
|
+
}
|
|
625
664
|
}
|
|
626
665
|
// Helper functions for the ReadableStream.
|
|
627
666
|
function streamAsyncIteratorBrandCheckException(name) {
|
|
@@ -635,15 +674,35 @@
|
|
|
635
674
|
return x !== x;
|
|
636
675
|
};
|
|
637
676
|
|
|
638
|
-
function
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
677
|
+
function CreateArrayFromList(elements) {
|
|
678
|
+
// We use arrays to represent lists, so this is basically a no-op.
|
|
679
|
+
// Do a slice though just in case we happen to depend on the unique-ness.
|
|
680
|
+
return elements.slice();
|
|
681
|
+
}
|
|
682
|
+
function CopyDataBlockBytes(dest, destOffset, src, srcOffset, n) {
|
|
683
|
+
new Uint8Array(dest).set(new Uint8Array(src, srcOffset, n), destOffset);
|
|
684
|
+
}
|
|
685
|
+
// Not implemented correctly
|
|
686
|
+
function TransferArrayBuffer(O) {
|
|
687
|
+
return O;
|
|
688
|
+
}
|
|
689
|
+
// Not implemented correctly
|
|
690
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
691
|
+
function IsDetachedBuffer(O) {
|
|
692
|
+
return false;
|
|
693
|
+
}
|
|
694
|
+
function ArrayBufferSlice(buffer, begin, end) {
|
|
695
|
+
// ArrayBuffer.prototype.slice is not available on IE10
|
|
696
|
+
// https://www.caniuse.com/mdn-javascript_builtins_arraybuffer_slice
|
|
697
|
+
if (buffer.slice) {
|
|
698
|
+
return buffer.slice(begin, end);
|
|
644
699
|
}
|
|
645
|
-
|
|
700
|
+
var length = end - begin;
|
|
701
|
+
var slice = new ArrayBuffer(length);
|
|
702
|
+
CopyDataBlockBytes(slice, 0, buffer, begin, length);
|
|
703
|
+
return slice;
|
|
646
704
|
}
|
|
705
|
+
|
|
647
706
|
function IsNonNegativeNumber(v) {
|
|
648
707
|
if (typeof v !== 'number') {
|
|
649
708
|
return false;
|
|
@@ -656,6 +715,10 @@
|
|
|
656
715
|
}
|
|
657
716
|
return true;
|
|
658
717
|
}
|
|
718
|
+
function CloneAsUint8Array(O) {
|
|
719
|
+
var buffer = ArrayBufferSlice(O.buffer, O.byteOffset, O.byteOffset + O.byteLength);
|
|
720
|
+
return new Uint8Array(buffer);
|
|
721
|
+
}
|
|
659
722
|
|
|
660
723
|
function DequeueValue(container) {
|
|
661
724
|
var pair = container._queue.shift();
|
|
@@ -666,8 +729,7 @@
|
|
|
666
729
|
return pair.value;
|
|
667
730
|
}
|
|
668
731
|
function EnqueueValueWithSize(container, value, size) {
|
|
669
|
-
size
|
|
670
|
-
if (!IsFiniteNonNegativeNumber(size)) {
|
|
732
|
+
if (!IsNonNegativeNumber(size) || size === Infinity) {
|
|
671
733
|
throw new RangeError('Size must be a finite, non-NaN, non-negative number.');
|
|
672
734
|
}
|
|
673
735
|
container._queue.push({ value: value, size: size });
|
|
@@ -682,28 +744,19 @@
|
|
|
682
744
|
container._queueTotalSize = 0;
|
|
683
745
|
}
|
|
684
746
|
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
function CopyDataBlockBytes(dest, destOffset, src, srcOffset, n) {
|
|
691
|
-
new Uint8Array(dest).set(new Uint8Array(src, srcOffset, n), destOffset);
|
|
692
|
-
}
|
|
693
|
-
// Not implemented correctly
|
|
694
|
-
function TransferArrayBuffer(O) {
|
|
695
|
-
return O;
|
|
696
|
-
}
|
|
697
|
-
// Not implemented correctly
|
|
698
|
-
function IsDetachedBuffer(O) {
|
|
699
|
-
return false;
|
|
700
|
-
}
|
|
701
|
-
|
|
747
|
+
/**
|
|
748
|
+
* A pull-into request in a {@link ReadableByteStreamController}.
|
|
749
|
+
*
|
|
750
|
+
* @public
|
|
751
|
+
*/
|
|
702
752
|
var ReadableStreamBYOBRequest = /** @class */ (function () {
|
|
703
753
|
function ReadableStreamBYOBRequest() {
|
|
704
754
|
throw new TypeError('Illegal constructor');
|
|
705
755
|
}
|
|
706
756
|
Object.defineProperty(ReadableStreamBYOBRequest.prototype, "view", {
|
|
757
|
+
/**
|
|
758
|
+
* Returns the view for writing in to, or `null` if the BYOB request has already been responded to.
|
|
759
|
+
*/
|
|
707
760
|
get: function () {
|
|
708
761
|
if (!IsReadableStreamBYOBRequest(this)) {
|
|
709
762
|
throw byobRequestBrandCheckException('view');
|
|
@@ -733,15 +786,10 @@
|
|
|
733
786
|
if (!ArrayBuffer.isView(view)) {
|
|
734
787
|
throw new TypeError('You can only respond with array buffer views');
|
|
735
788
|
}
|
|
736
|
-
if (view.byteLength === 0) {
|
|
737
|
-
throw new TypeError('chunk must have non-zero byteLength');
|
|
738
|
-
}
|
|
739
|
-
if (view.buffer.byteLength === 0) {
|
|
740
|
-
throw new TypeError("chunk's buffer must have non-zero byteLength");
|
|
741
|
-
}
|
|
742
789
|
if (this._associatedReadableByteStreamController === undefined) {
|
|
743
790
|
throw new TypeError('This BYOB request has been invalidated');
|
|
744
791
|
}
|
|
792
|
+
if (IsDetachedBuffer(view.buffer)) ;
|
|
745
793
|
ReadableByteStreamControllerRespondWithNewView(this._associatedReadableByteStreamController, view);
|
|
746
794
|
};
|
|
747
795
|
return ReadableStreamBYOBRequest;
|
|
@@ -757,28 +805,33 @@
|
|
|
757
805
|
configurable: true
|
|
758
806
|
});
|
|
759
807
|
}
|
|
808
|
+
/**
|
|
809
|
+
* Allows control of a {@link ReadableStream | readable byte stream}'s state and internal queue.
|
|
810
|
+
*
|
|
811
|
+
* @public
|
|
812
|
+
*/
|
|
760
813
|
var ReadableByteStreamController = /** @class */ (function () {
|
|
761
814
|
function ReadableByteStreamController() {
|
|
762
815
|
throw new TypeError('Illegal constructor');
|
|
763
816
|
}
|
|
764
817
|
Object.defineProperty(ReadableByteStreamController.prototype, "byobRequest", {
|
|
818
|
+
/**
|
|
819
|
+
* Returns the current BYOB pull request, or `null` if there isn't one.
|
|
820
|
+
*/
|
|
765
821
|
get: function () {
|
|
766
822
|
if (!IsReadableByteStreamController(this)) {
|
|
767
823
|
throw byteStreamControllerBrandCheckException('byobRequest');
|
|
768
824
|
}
|
|
769
|
-
|
|
770
|
-
var firstDescriptor = this._pendingPullIntos.peek();
|
|
771
|
-
var view = new Uint8Array(firstDescriptor.buffer, firstDescriptor.byteOffset + firstDescriptor.bytesFilled, firstDescriptor.byteLength - firstDescriptor.bytesFilled);
|
|
772
|
-
var byobRequest = Object.create(ReadableStreamBYOBRequest.prototype);
|
|
773
|
-
SetUpReadableStreamBYOBRequest(byobRequest, this, view);
|
|
774
|
-
this._byobRequest = byobRequest;
|
|
775
|
-
}
|
|
776
|
-
return this._byobRequest;
|
|
825
|
+
return ReadableByteStreamControllerGetBYOBRequest(this);
|
|
777
826
|
},
|
|
778
827
|
enumerable: false,
|
|
779
828
|
configurable: true
|
|
780
829
|
});
|
|
781
830
|
Object.defineProperty(ReadableByteStreamController.prototype, "desiredSize", {
|
|
831
|
+
/**
|
|
832
|
+
* Returns the desired size to fill the controlled stream's internal queue. It can be negative, if the queue is
|
|
833
|
+
* over-full. An underlying byte source ought to use this information to determine when and how to apply backpressure.
|
|
834
|
+
*/
|
|
782
835
|
get: function () {
|
|
783
836
|
if (!IsReadableByteStreamController(this)) {
|
|
784
837
|
throw byteStreamControllerBrandCheckException('desiredSize');
|
|
@@ -788,6 +841,10 @@
|
|
|
788
841
|
enumerable: false,
|
|
789
842
|
configurable: true
|
|
790
843
|
});
|
|
844
|
+
/**
|
|
845
|
+
* Closes the controlled readable stream. Consumers will still be able to read any previously-enqueued chunks from
|
|
846
|
+
* the stream, but once those are read, the stream will become closed.
|
|
847
|
+
*/
|
|
791
848
|
ReadableByteStreamController.prototype.close = function () {
|
|
792
849
|
if (!IsReadableByteStreamController(this)) {
|
|
793
850
|
throw byteStreamControllerBrandCheckException('close');
|
|
@@ -824,6 +881,9 @@
|
|
|
824
881
|
}
|
|
825
882
|
ReadableByteStreamControllerEnqueue(this, chunk);
|
|
826
883
|
};
|
|
884
|
+
/**
|
|
885
|
+
* Errors the controlled readable stream, making all future interactions with it fail with the given error `e`.
|
|
886
|
+
*/
|
|
827
887
|
ReadableByteStreamController.prototype.error = function (e) {
|
|
828
888
|
if (e === void 0) { e = undefined; }
|
|
829
889
|
if (!IsReadableByteStreamController(this)) {
|
|
@@ -833,10 +893,7 @@
|
|
|
833
893
|
};
|
|
834
894
|
/** @internal */
|
|
835
895
|
ReadableByteStreamController.prototype[CancelSteps] = function (reason) {
|
|
836
|
-
|
|
837
|
-
var firstDescriptor = this._pendingPullIntos.peek();
|
|
838
|
-
firstDescriptor.bytesFilled = 0;
|
|
839
|
-
}
|
|
896
|
+
ReadableByteStreamControllerClearPendingPullIntos(this);
|
|
840
897
|
ResetQueue(this);
|
|
841
898
|
var result = this._cancelAlgorithm(reason);
|
|
842
899
|
ReadableByteStreamControllerClearAlgorithms(this);
|
|
@@ -865,6 +922,7 @@
|
|
|
865
922
|
}
|
|
866
923
|
var pullIntoDescriptor = {
|
|
867
924
|
buffer: buffer,
|
|
925
|
+
bufferByteLength: autoAllocateChunkSize,
|
|
868
926
|
byteOffset: 0,
|
|
869
927
|
byteLength: autoAllocateChunkSize,
|
|
870
928
|
bytesFilled: 0,
|
|
@@ -900,7 +958,7 @@
|
|
|
900
958
|
if (!Object.prototype.hasOwnProperty.call(x, '_controlledReadableByteStream')) {
|
|
901
959
|
return false;
|
|
902
960
|
}
|
|
903
|
-
return
|
|
961
|
+
return x instanceof ReadableByteStreamController;
|
|
904
962
|
}
|
|
905
963
|
function IsReadableStreamBYOBRequest(x) {
|
|
906
964
|
if (!typeIsObject(x)) {
|
|
@@ -909,7 +967,7 @@
|
|
|
909
967
|
if (!Object.prototype.hasOwnProperty.call(x, '_associatedReadableByteStreamController')) {
|
|
910
968
|
return false;
|
|
911
969
|
}
|
|
912
|
-
return
|
|
970
|
+
return x instanceof ReadableStreamBYOBRequest;
|
|
913
971
|
}
|
|
914
972
|
function ReadableByteStreamControllerCallPullIfNeeded(controller) {
|
|
915
973
|
var shouldPull = ReadableByteStreamControllerShouldCallPull(controller);
|
|
@@ -991,7 +1049,6 @@
|
|
|
991
1049
|
return ready;
|
|
992
1050
|
}
|
|
993
1051
|
function ReadableByteStreamControllerFillHeadPullIntoDescriptor(controller, size, pullIntoDescriptor) {
|
|
994
|
-
ReadableByteStreamControllerInvalidateBYOBRequest(controller);
|
|
995
1052
|
pullIntoDescriptor.bytesFilled += size;
|
|
996
1053
|
}
|
|
997
1054
|
function ReadableByteStreamControllerHandleQueueDrain(controller) {
|
|
@@ -1030,9 +1087,15 @@
|
|
|
1030
1087
|
elementSize = view.constructor.BYTES_PER_ELEMENT;
|
|
1031
1088
|
}
|
|
1032
1089
|
var ctor = view.constructor;
|
|
1090
|
+
// try {
|
|
1033
1091
|
var buffer = TransferArrayBuffer(view.buffer);
|
|
1092
|
+
// } catch (e) {
|
|
1093
|
+
// readIntoRequest._errorSteps(e);
|
|
1094
|
+
// return;
|
|
1095
|
+
// }
|
|
1034
1096
|
var pullIntoDescriptor = {
|
|
1035
1097
|
buffer: buffer,
|
|
1098
|
+
bufferByteLength: buffer.byteLength,
|
|
1036
1099
|
byteOffset: view.byteOffset,
|
|
1037
1100
|
byteLength: view.byteLength,
|
|
1038
1101
|
bytesFilled: 0,
|
|
@@ -1072,7 +1135,6 @@
|
|
|
1072
1135
|
ReadableByteStreamControllerCallPullIfNeeded(controller);
|
|
1073
1136
|
}
|
|
1074
1137
|
function ReadableByteStreamControllerRespondInClosedState(controller, firstDescriptor) {
|
|
1075
|
-
firstDescriptor.buffer = TransferArrayBuffer(firstDescriptor.buffer);
|
|
1076
1138
|
var stream = controller._controlledReadableByteStream;
|
|
1077
1139
|
if (ReadableStreamHasBYOBReader(stream)) {
|
|
1078
1140
|
while (ReadableStreamGetNumReadIntoRequests(stream) > 0) {
|
|
@@ -1082,34 +1144,27 @@
|
|
|
1082
1144
|
}
|
|
1083
1145
|
}
|
|
1084
1146
|
function ReadableByteStreamControllerRespondInReadableState(controller, bytesWritten, pullIntoDescriptor) {
|
|
1085
|
-
if (pullIntoDescriptor.bytesFilled + bytesWritten > pullIntoDescriptor.byteLength) {
|
|
1086
|
-
throw new RangeError('bytesWritten out of range');
|
|
1087
|
-
}
|
|
1088
1147
|
ReadableByteStreamControllerFillHeadPullIntoDescriptor(controller, bytesWritten, pullIntoDescriptor);
|
|
1089
1148
|
if (pullIntoDescriptor.bytesFilled < pullIntoDescriptor.elementSize) {
|
|
1090
|
-
// TODO: Figure out whether we should detach the buffer or not here.
|
|
1091
1149
|
return;
|
|
1092
1150
|
}
|
|
1093
1151
|
ReadableByteStreamControllerShiftPendingPullInto(controller);
|
|
1094
1152
|
var remainderSize = pullIntoDescriptor.bytesFilled % pullIntoDescriptor.elementSize;
|
|
1095
1153
|
if (remainderSize > 0) {
|
|
1096
1154
|
var end = pullIntoDescriptor.byteOffset + pullIntoDescriptor.bytesFilled;
|
|
1097
|
-
var remainder = pullIntoDescriptor.buffer
|
|
1155
|
+
var remainder = ArrayBufferSlice(pullIntoDescriptor.buffer, end - remainderSize, end);
|
|
1098
1156
|
ReadableByteStreamControllerEnqueueChunkToQueue(controller, remainder, 0, remainder.byteLength);
|
|
1099
1157
|
}
|
|
1100
|
-
pullIntoDescriptor.buffer = TransferArrayBuffer(pullIntoDescriptor.buffer);
|
|
1101
1158
|
pullIntoDescriptor.bytesFilled -= remainderSize;
|
|
1102
1159
|
ReadableByteStreamControllerCommitPullIntoDescriptor(controller._controlledReadableByteStream, pullIntoDescriptor);
|
|
1103
1160
|
ReadableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(controller);
|
|
1104
1161
|
}
|
|
1105
1162
|
function ReadableByteStreamControllerRespondInternal(controller, bytesWritten) {
|
|
1106
1163
|
var firstDescriptor = controller._pendingPullIntos.peek();
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
}
|
|
1112
|
-
ReadableByteStreamControllerRespondInClosedState(controller, firstDescriptor);
|
|
1164
|
+
ReadableByteStreamControllerInvalidateBYOBRequest(controller);
|
|
1165
|
+
var state = controller._controlledReadableByteStream._state;
|
|
1166
|
+
if (state === 'closed') {
|
|
1167
|
+
ReadableByteStreamControllerRespondInClosedState(controller);
|
|
1113
1168
|
}
|
|
1114
1169
|
else {
|
|
1115
1170
|
ReadableByteStreamControllerRespondInReadableState(controller, bytesWritten, firstDescriptor);
|
|
@@ -1118,7 +1173,6 @@
|
|
|
1118
1173
|
}
|
|
1119
1174
|
function ReadableByteStreamControllerShiftPendingPullInto(controller) {
|
|
1120
1175
|
var descriptor = controller._pendingPullIntos.shift();
|
|
1121
|
-
ReadableByteStreamControllerInvalidateBYOBRequest(controller);
|
|
1122
1176
|
return descriptor;
|
|
1123
1177
|
}
|
|
1124
1178
|
function ReadableByteStreamControllerShouldCallPull(controller) {
|
|
@@ -1178,6 +1232,12 @@
|
|
|
1178
1232
|
var byteOffset = chunk.byteOffset;
|
|
1179
1233
|
var byteLength = chunk.byteLength;
|
|
1180
1234
|
var transferredBuffer = TransferArrayBuffer(buffer);
|
|
1235
|
+
if (controller._pendingPullIntos.length > 0) {
|
|
1236
|
+
var firstPendingPullInto = controller._pendingPullIntos.peek();
|
|
1237
|
+
if (IsDetachedBuffer(firstPendingPullInto.buffer)) ;
|
|
1238
|
+
firstPendingPullInto.buffer = TransferArrayBuffer(firstPendingPullInto.buffer);
|
|
1239
|
+
}
|
|
1240
|
+
ReadableByteStreamControllerInvalidateBYOBRequest(controller);
|
|
1181
1241
|
if (ReadableStreamHasDefaultReader(stream)) {
|
|
1182
1242
|
if (ReadableStreamGetNumReadRequests(stream) === 0) {
|
|
1183
1243
|
ReadableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset, byteLength);
|
|
@@ -1207,9 +1267,18 @@
|
|
|
1207
1267
|
ReadableByteStreamControllerClearAlgorithms(controller);
|
|
1208
1268
|
ReadableStreamError(stream, e);
|
|
1209
1269
|
}
|
|
1270
|
+
function ReadableByteStreamControllerGetBYOBRequest(controller) {
|
|
1271
|
+
if (controller._byobRequest === null && controller._pendingPullIntos.length > 0) {
|
|
1272
|
+
var firstDescriptor = controller._pendingPullIntos.peek();
|
|
1273
|
+
var view = new Uint8Array(firstDescriptor.buffer, firstDescriptor.byteOffset + firstDescriptor.bytesFilled, firstDescriptor.byteLength - firstDescriptor.bytesFilled);
|
|
1274
|
+
var byobRequest = Object.create(ReadableStreamBYOBRequest.prototype);
|
|
1275
|
+
SetUpReadableStreamBYOBRequest(byobRequest, controller, view);
|
|
1276
|
+
controller._byobRequest = byobRequest;
|
|
1277
|
+
}
|
|
1278
|
+
return controller._byobRequest;
|
|
1279
|
+
}
|
|
1210
1280
|
function ReadableByteStreamControllerGetDesiredSize(controller) {
|
|
1211
|
-
var
|
|
1212
|
-
var state = stream._state;
|
|
1281
|
+
var state = controller._controlledReadableByteStream._state;
|
|
1213
1282
|
if (state === 'errored') {
|
|
1214
1283
|
return null;
|
|
1215
1284
|
}
|
|
@@ -1219,21 +1288,47 @@
|
|
|
1219
1288
|
return controller._strategyHWM - controller._queueTotalSize;
|
|
1220
1289
|
}
|
|
1221
1290
|
function ReadableByteStreamControllerRespond(controller, bytesWritten) {
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1291
|
+
var firstDescriptor = controller._pendingPullIntos.peek();
|
|
1292
|
+
var state = controller._controlledReadableByteStream._state;
|
|
1293
|
+
if (state === 'closed') {
|
|
1294
|
+
if (bytesWritten !== 0) {
|
|
1295
|
+
throw new TypeError('bytesWritten must be 0 when calling respond() on a closed stream');
|
|
1296
|
+
}
|
|
1297
|
+
}
|
|
1298
|
+
else {
|
|
1299
|
+
if (bytesWritten === 0) {
|
|
1300
|
+
throw new TypeError('bytesWritten must be greater than 0 when calling respond() on a readable stream');
|
|
1301
|
+
}
|
|
1302
|
+
if (firstDescriptor.bytesFilled + bytesWritten > firstDescriptor.byteLength) {
|
|
1303
|
+
throw new RangeError('bytesWritten out of range');
|
|
1304
|
+
}
|
|
1225
1305
|
}
|
|
1306
|
+
firstDescriptor.buffer = TransferArrayBuffer(firstDescriptor.buffer);
|
|
1226
1307
|
ReadableByteStreamControllerRespondInternal(controller, bytesWritten);
|
|
1227
1308
|
}
|
|
1228
1309
|
function ReadableByteStreamControllerRespondWithNewView(controller, view) {
|
|
1229
1310
|
var firstDescriptor = controller._pendingPullIntos.peek();
|
|
1311
|
+
var state = controller._controlledReadableByteStream._state;
|
|
1312
|
+
if (state === 'closed') {
|
|
1313
|
+
if (view.byteLength !== 0) {
|
|
1314
|
+
throw new TypeError('The view\'s length must be 0 when calling respondWithNewView() on a closed stream');
|
|
1315
|
+
}
|
|
1316
|
+
}
|
|
1317
|
+
else {
|
|
1318
|
+
if (view.byteLength === 0) {
|
|
1319
|
+
throw new TypeError('The view\'s length must be greater than 0 when calling respondWithNewView() on a readable stream');
|
|
1320
|
+
}
|
|
1321
|
+
}
|
|
1230
1322
|
if (firstDescriptor.byteOffset + firstDescriptor.bytesFilled !== view.byteOffset) {
|
|
1231
1323
|
throw new RangeError('The region specified by view does not match byobRequest');
|
|
1232
1324
|
}
|
|
1233
|
-
if (firstDescriptor.
|
|
1325
|
+
if (firstDescriptor.bufferByteLength !== view.buffer.byteLength) {
|
|
1234
1326
|
throw new RangeError('The buffer of view has different capacity than byobRequest');
|
|
1235
1327
|
}
|
|
1236
|
-
firstDescriptor.
|
|
1328
|
+
if (firstDescriptor.bytesFilled + view.byteLength > firstDescriptor.byteLength) {
|
|
1329
|
+
throw new RangeError('The region specified by view is larger than byobRequest');
|
|
1330
|
+
}
|
|
1331
|
+
firstDescriptor.buffer = TransferArrayBuffer(view.buffer);
|
|
1237
1332
|
ReadableByteStreamControllerRespondInternal(controller, view.byteLength);
|
|
1238
1333
|
}
|
|
1239
1334
|
function SetUpReadableByteStreamController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, autoAllocateChunkSize) {
|
|
@@ -1275,6 +1370,9 @@
|
|
|
1275
1370
|
cancelAlgorithm = function (reason) { return underlyingByteSource.cancel(reason); };
|
|
1276
1371
|
}
|
|
1277
1372
|
var autoAllocateChunkSize = underlyingByteSource.autoAllocateChunkSize;
|
|
1373
|
+
if (autoAllocateChunkSize === 0) {
|
|
1374
|
+
throw new TypeError('autoAllocateChunkSize must be greater than 0');
|
|
1375
|
+
}
|
|
1278
1376
|
SetUpReadableByteStreamController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, autoAllocateChunkSize);
|
|
1279
1377
|
}
|
|
1280
1378
|
function SetUpReadableStreamBYOBRequest(request, controller, view) {
|
|
@@ -1321,6 +1419,11 @@
|
|
|
1321
1419
|
}
|
|
1322
1420
|
return true;
|
|
1323
1421
|
}
|
|
1422
|
+
/**
|
|
1423
|
+
* A BYOB reader vended by a {@link ReadableStream}.
|
|
1424
|
+
*
|
|
1425
|
+
* @public
|
|
1426
|
+
*/
|
|
1324
1427
|
var ReadableStreamBYOBReader = /** @class */ (function () {
|
|
1325
1428
|
function ReadableStreamBYOBReader(stream) {
|
|
1326
1429
|
assertRequiredArgument(stream, 1, 'ReadableStreamBYOBReader');
|
|
@@ -1336,6 +1439,10 @@
|
|
|
1336
1439
|
this._readIntoRequests = new SimpleQueue();
|
|
1337
1440
|
}
|
|
1338
1441
|
Object.defineProperty(ReadableStreamBYOBReader.prototype, "closed", {
|
|
1442
|
+
/**
|
|
1443
|
+
* Returns a promise that will be fulfilled when the stream becomes closed, or rejected if the stream ever errors or
|
|
1444
|
+
* the reader's lock is released before the stream finishes closing.
|
|
1445
|
+
*/
|
|
1339
1446
|
get: function () {
|
|
1340
1447
|
if (!IsReadableStreamBYOBReader(this)) {
|
|
1341
1448
|
return promiseRejectedWith(byobReaderBrandCheckException('closed'));
|
|
@@ -1345,6 +1452,9 @@
|
|
|
1345
1452
|
enumerable: false,
|
|
1346
1453
|
configurable: true
|
|
1347
1454
|
});
|
|
1455
|
+
/**
|
|
1456
|
+
* If the reader is active, behaves the same as {@link ReadableStream.cancel | stream.cancel(reason)}.
|
|
1457
|
+
*/
|
|
1348
1458
|
ReadableStreamBYOBReader.prototype.cancel = function (reason) {
|
|
1349
1459
|
if (reason === void 0) { reason = undefined; }
|
|
1350
1460
|
if (!IsReadableStreamBYOBReader(this)) {
|
|
@@ -1355,6 +1465,11 @@
|
|
|
1355
1465
|
}
|
|
1356
1466
|
return ReadableStreamReaderGenericCancel(this, reason);
|
|
1357
1467
|
};
|
|
1468
|
+
/**
|
|
1469
|
+
* Attempts to reads bytes into view, and returns a promise resolved with the result.
|
|
1470
|
+
*
|
|
1471
|
+
* If reading a chunk causes the queue to become empty, more data will be pulled from the underlying source.
|
|
1472
|
+
*/
|
|
1358
1473
|
ReadableStreamBYOBReader.prototype.read = function (view) {
|
|
1359
1474
|
if (!IsReadableStreamBYOBReader(this)) {
|
|
1360
1475
|
return promiseRejectedWith(byobReaderBrandCheckException('read'));
|
|
@@ -1368,6 +1483,7 @@
|
|
|
1368
1483
|
if (view.buffer.byteLength === 0) {
|
|
1369
1484
|
return promiseRejectedWith(new TypeError("view's buffer must have non-zero byteLength"));
|
|
1370
1485
|
}
|
|
1486
|
+
if (IsDetachedBuffer(view.buffer)) ;
|
|
1371
1487
|
if (this._ownerReadableStream === undefined) {
|
|
1372
1488
|
return promiseRejectedWith(readerLockException('read from'));
|
|
1373
1489
|
}
|
|
@@ -1385,6 +1501,15 @@
|
|
|
1385
1501
|
ReadableStreamBYOBReaderRead(this, view, readIntoRequest);
|
|
1386
1502
|
return promise;
|
|
1387
1503
|
};
|
|
1504
|
+
/**
|
|
1505
|
+
* Releases the reader's lock on the corresponding stream. After the lock is released, the reader is no longer active.
|
|
1506
|
+
* If the associated stream is errored when the lock is released, the reader will appear errored in the same way
|
|
1507
|
+
* from now on; otherwise, the reader will appear closed.
|
|
1508
|
+
*
|
|
1509
|
+
* A reader's lock cannot be released while it still has a pending read request, i.e., if a promise returned by
|
|
1510
|
+
* the reader's {@link ReadableStreamBYOBReader.read | read()} method has not yet been settled. Attempting to
|
|
1511
|
+
* do so will throw a `TypeError` and leave the reader locked to the stream.
|
|
1512
|
+
*/
|
|
1388
1513
|
ReadableStreamBYOBReader.prototype.releaseLock = function () {
|
|
1389
1514
|
if (!IsReadableStreamBYOBReader(this)) {
|
|
1390
1515
|
throw byobReaderBrandCheckException('releaseLock');
|
|
@@ -1419,7 +1544,7 @@
|
|
|
1419
1544
|
if (!Object.prototype.hasOwnProperty.call(x, '_readIntoRequests')) {
|
|
1420
1545
|
return false;
|
|
1421
1546
|
}
|
|
1422
|
-
return
|
|
1547
|
+
return x instanceof ReadableStreamBYOBReader;
|
|
1423
1548
|
}
|
|
1424
1549
|
function ReadableStreamBYOBReaderRead(reader, view, readIntoRequest) {
|
|
1425
1550
|
var stream = reader._ownerReadableStream;
|
|
@@ -1514,6 +1639,36 @@
|
|
|
1514
1639
|
}
|
|
1515
1640
|
}
|
|
1516
1641
|
|
|
1642
|
+
function isAbortSignal(value) {
|
|
1643
|
+
if (typeof value !== 'object' || value === null) {
|
|
1644
|
+
return false;
|
|
1645
|
+
}
|
|
1646
|
+
try {
|
|
1647
|
+
return typeof value.aborted === 'boolean';
|
|
1648
|
+
}
|
|
1649
|
+
catch (_a) {
|
|
1650
|
+
// AbortSignal.prototype.aborted throws if its brand check fails
|
|
1651
|
+
return false;
|
|
1652
|
+
}
|
|
1653
|
+
}
|
|
1654
|
+
var supportsAbortController = typeof AbortController === 'function';
|
|
1655
|
+
/**
|
|
1656
|
+
* Construct a new AbortController, if supported by the platform.
|
|
1657
|
+
*
|
|
1658
|
+
* @internal
|
|
1659
|
+
*/
|
|
1660
|
+
function createAbortController() {
|
|
1661
|
+
if (supportsAbortController) {
|
|
1662
|
+
return new AbortController();
|
|
1663
|
+
}
|
|
1664
|
+
return undefined;
|
|
1665
|
+
}
|
|
1666
|
+
|
|
1667
|
+
/**
|
|
1668
|
+
* A writable stream represents a destination for data, into which you can write.
|
|
1669
|
+
*
|
|
1670
|
+
* @public
|
|
1671
|
+
*/
|
|
1517
1672
|
var WritableStream = /** @class */ (function () {
|
|
1518
1673
|
function WritableStream(rawUnderlyingSink, rawStrategy) {
|
|
1519
1674
|
if (rawUnderlyingSink === void 0) { rawUnderlyingSink = {}; }
|
|
@@ -1536,28 +1691,48 @@
|
|
|
1536
1691
|
SetUpWritableStreamDefaultControllerFromUnderlyingSink(this, underlyingSink, highWaterMark, sizeAlgorithm);
|
|
1537
1692
|
}
|
|
1538
1693
|
Object.defineProperty(WritableStream.prototype, "locked", {
|
|
1694
|
+
/**
|
|
1695
|
+
* Returns whether or not the writable stream is locked to a writer.
|
|
1696
|
+
*/
|
|
1539
1697
|
get: function () {
|
|
1540
1698
|
if (!IsWritableStream(this)) {
|
|
1541
|
-
throw streamBrandCheckException('locked');
|
|
1699
|
+
throw streamBrandCheckException$2('locked');
|
|
1542
1700
|
}
|
|
1543
1701
|
return IsWritableStreamLocked(this);
|
|
1544
1702
|
},
|
|
1545
1703
|
enumerable: false,
|
|
1546
1704
|
configurable: true
|
|
1547
1705
|
});
|
|
1706
|
+
/**
|
|
1707
|
+
* Aborts the stream, signaling that the producer can no longer successfully write to the stream and it is to be
|
|
1708
|
+
* immediately moved to an errored state, with any queued-up writes discarded. This will also execute any abort
|
|
1709
|
+
* mechanism of the underlying sink.
|
|
1710
|
+
*
|
|
1711
|
+
* The returned promise will fulfill if the stream shuts down successfully, or reject if the underlying sink signaled
|
|
1712
|
+
* that there was an error doing so. Additionally, it will reject with a `TypeError` (without attempting to cancel
|
|
1713
|
+
* the stream) if the stream is currently locked.
|
|
1714
|
+
*/
|
|
1548
1715
|
WritableStream.prototype.abort = function (reason) {
|
|
1549
1716
|
if (reason === void 0) { reason = undefined; }
|
|
1550
1717
|
if (!IsWritableStream(this)) {
|
|
1551
|
-
return promiseRejectedWith(streamBrandCheckException('abort'));
|
|
1718
|
+
return promiseRejectedWith(streamBrandCheckException$2('abort'));
|
|
1552
1719
|
}
|
|
1553
1720
|
if (IsWritableStreamLocked(this)) {
|
|
1554
1721
|
return promiseRejectedWith(new TypeError('Cannot abort a stream that already has a writer'));
|
|
1555
1722
|
}
|
|
1556
1723
|
return WritableStreamAbort(this, reason);
|
|
1557
1724
|
};
|
|
1725
|
+
/**
|
|
1726
|
+
* Closes the stream. The underlying sink will finish processing any previously-written chunks, before invoking its
|
|
1727
|
+
* close behavior. During this time any further attempts to write will fail (without erroring the stream).
|
|
1728
|
+
*
|
|
1729
|
+
* The method returns a promise that will fulfill if all remaining chunks are successfully written and the stream
|
|
1730
|
+
* successfully closes, or rejects if an error is encountered during this process. Additionally, it will reject with
|
|
1731
|
+
* a `TypeError` (without attempting to cancel the stream) if the stream is currently locked.
|
|
1732
|
+
*/
|
|
1558
1733
|
WritableStream.prototype.close = function () {
|
|
1559
1734
|
if (!IsWritableStream(this)) {
|
|
1560
|
-
return promiseRejectedWith(streamBrandCheckException('close'));
|
|
1735
|
+
return promiseRejectedWith(streamBrandCheckException$2('close'));
|
|
1561
1736
|
}
|
|
1562
1737
|
if (IsWritableStreamLocked(this)) {
|
|
1563
1738
|
return promiseRejectedWith(new TypeError('Cannot close a stream that already has a writer'));
|
|
@@ -1567,9 +1742,17 @@
|
|
|
1567
1742
|
}
|
|
1568
1743
|
return WritableStreamClose(this);
|
|
1569
1744
|
};
|
|
1745
|
+
/**
|
|
1746
|
+
* Creates a {@link WritableStreamDefaultWriter | writer} and locks the stream to the new writer. While the stream
|
|
1747
|
+
* is locked, no other writer can be acquired until this one is released.
|
|
1748
|
+
*
|
|
1749
|
+
* This functionality is especially useful for creating abstractions that desire the ability to write to a stream
|
|
1750
|
+
* without interruption or interleaving. By getting a writer for the stream, you can ensure nobody else can write at
|
|
1751
|
+
* the same time, which would cause the resulting written data to be unpredictable and probably useless.
|
|
1752
|
+
*/
|
|
1570
1753
|
WritableStream.prototype.getWriter = function () {
|
|
1571
1754
|
if (!IsWritableStream(this)) {
|
|
1572
|
-
throw streamBrandCheckException('getWriter');
|
|
1755
|
+
throw streamBrandCheckException$2('getWriter');
|
|
1573
1756
|
}
|
|
1574
1757
|
return AcquireWritableStreamDefaultWriter(this);
|
|
1575
1758
|
};
|
|
@@ -1634,7 +1817,7 @@
|
|
|
1634
1817
|
if (!Object.prototype.hasOwnProperty.call(x, '_writableStreamController')) {
|
|
1635
1818
|
return false;
|
|
1636
1819
|
}
|
|
1637
|
-
return
|
|
1820
|
+
return x instanceof WritableStream;
|
|
1638
1821
|
}
|
|
1639
1822
|
function IsWritableStreamLocked(stream) {
|
|
1640
1823
|
if (stream._writer === undefined) {
|
|
@@ -1643,6 +1826,15 @@
|
|
|
1643
1826
|
return true;
|
|
1644
1827
|
}
|
|
1645
1828
|
function WritableStreamAbort(stream, reason) {
|
|
1829
|
+
var _a;
|
|
1830
|
+
if (stream._state === 'closed' || stream._state === 'errored') {
|
|
1831
|
+
return promiseResolvedWith(undefined);
|
|
1832
|
+
}
|
|
1833
|
+
stream._writableStreamController._abortReason = reason;
|
|
1834
|
+
(_a = stream._writableStreamController._abortController) === null || _a === void 0 ? void 0 : _a.abort();
|
|
1835
|
+
// TypeScript narrows the type of `stream._state` down to 'writable' | 'erroring',
|
|
1836
|
+
// but it doesn't know that signaling abort runs author code that might have changed the state.
|
|
1837
|
+
// Widen the type again by casting to WritableStreamState.
|
|
1646
1838
|
var state = stream._state;
|
|
1647
1839
|
if (state === 'closed' || state === 'errored') {
|
|
1648
1840
|
return promiseResolvedWith(undefined);
|
|
@@ -1828,6 +2020,11 @@
|
|
|
1828
2020
|
}
|
|
1829
2021
|
stream._backpressure = backpressure;
|
|
1830
2022
|
}
|
|
2023
|
+
/**
|
|
2024
|
+
* A default writer vended by a {@link WritableStream}.
|
|
2025
|
+
*
|
|
2026
|
+
* @public
|
|
2027
|
+
*/
|
|
1831
2028
|
var WritableStreamDefaultWriter = /** @class */ (function () {
|
|
1832
2029
|
function WritableStreamDefaultWriter(stream) {
|
|
1833
2030
|
assertRequiredArgument(stream, 1, 'WritableStreamDefaultWriter');
|
|
@@ -1862,6 +2059,10 @@
|
|
|
1862
2059
|
}
|
|
1863
2060
|
}
|
|
1864
2061
|
Object.defineProperty(WritableStreamDefaultWriter.prototype, "closed", {
|
|
2062
|
+
/**
|
|
2063
|
+
* Returns a promise that will be fulfilled when the stream becomes closed, or rejected if the stream ever errors or
|
|
2064
|
+
* the writer’s lock is released before the stream finishes closing.
|
|
2065
|
+
*/
|
|
1865
2066
|
get: function () {
|
|
1866
2067
|
if (!IsWritableStreamDefaultWriter(this)) {
|
|
1867
2068
|
return promiseRejectedWith(defaultWriterBrandCheckException('closed'));
|
|
@@ -1872,6 +2073,14 @@
|
|
|
1872
2073
|
configurable: true
|
|
1873
2074
|
});
|
|
1874
2075
|
Object.defineProperty(WritableStreamDefaultWriter.prototype, "desiredSize", {
|
|
2076
|
+
/**
|
|
2077
|
+
* Returns the desired size to fill the stream’s internal queue. It can be negative, if the queue is over-full.
|
|
2078
|
+
* A producer can use this information to determine the right amount of data to write.
|
|
2079
|
+
*
|
|
2080
|
+
* It will be `null` if the stream cannot be successfully written to (due to either being errored, or having an abort
|
|
2081
|
+
* queued up). It will return zero if the stream is closed. And the getter will throw an exception if invoked when
|
|
2082
|
+
* the writer’s lock is released.
|
|
2083
|
+
*/
|
|
1875
2084
|
get: function () {
|
|
1876
2085
|
if (!IsWritableStreamDefaultWriter(this)) {
|
|
1877
2086
|
throw defaultWriterBrandCheckException('desiredSize');
|
|
@@ -1885,6 +2094,14 @@
|
|
|
1885
2094
|
configurable: true
|
|
1886
2095
|
});
|
|
1887
2096
|
Object.defineProperty(WritableStreamDefaultWriter.prototype, "ready", {
|
|
2097
|
+
/**
|
|
2098
|
+
* Returns a promise that will be fulfilled when the desired size to fill the stream’s internal queue transitions
|
|
2099
|
+
* from non-positive to positive, signaling that it is no longer applying backpressure. Once the desired size dips
|
|
2100
|
+
* back to zero or below, the getter will return a new promise that stays pending until the next transition.
|
|
2101
|
+
*
|
|
2102
|
+
* If the stream becomes errored or aborted, or the writer’s lock is released, the returned promise will become
|
|
2103
|
+
* rejected.
|
|
2104
|
+
*/
|
|
1888
2105
|
get: function () {
|
|
1889
2106
|
if (!IsWritableStreamDefaultWriter(this)) {
|
|
1890
2107
|
return promiseRejectedWith(defaultWriterBrandCheckException('ready'));
|
|
@@ -1894,6 +2111,9 @@
|
|
|
1894
2111
|
enumerable: false,
|
|
1895
2112
|
configurable: true
|
|
1896
2113
|
});
|
|
2114
|
+
/**
|
|
2115
|
+
* If the reader is active, behaves the same as {@link WritableStream.abort | stream.abort(reason)}.
|
|
2116
|
+
*/
|
|
1897
2117
|
WritableStreamDefaultWriter.prototype.abort = function (reason) {
|
|
1898
2118
|
if (reason === void 0) { reason = undefined; }
|
|
1899
2119
|
if (!IsWritableStreamDefaultWriter(this)) {
|
|
@@ -1904,6 +2124,9 @@
|
|
|
1904
2124
|
}
|
|
1905
2125
|
return WritableStreamDefaultWriterAbort(this, reason);
|
|
1906
2126
|
};
|
|
2127
|
+
/**
|
|
2128
|
+
* If the reader is active, behaves the same as {@link WritableStream.close | stream.close()}.
|
|
2129
|
+
*/
|
|
1907
2130
|
WritableStreamDefaultWriter.prototype.close = function () {
|
|
1908
2131
|
if (!IsWritableStreamDefaultWriter(this)) {
|
|
1909
2132
|
return promiseRejectedWith(defaultWriterBrandCheckException('close'));
|
|
@@ -1917,6 +2140,16 @@
|
|
|
1917
2140
|
}
|
|
1918
2141
|
return WritableStreamDefaultWriterClose(this);
|
|
1919
2142
|
};
|
|
2143
|
+
/**
|
|
2144
|
+
* Releases the writer’s lock on the corresponding stream. After the lock is released, the writer is no longer active.
|
|
2145
|
+
* If the associated stream is errored when the lock is released, the writer will appear errored in the same way from
|
|
2146
|
+
* now on; otherwise, the writer will appear closed.
|
|
2147
|
+
*
|
|
2148
|
+
* Note that the lock can still be released even if some ongoing writes have not yet finished (i.e. even if the
|
|
2149
|
+
* promises returned from previous calls to {@link WritableStreamDefaultWriter.write | write()} have not yet settled).
|
|
2150
|
+
* It’s not necessary to hold the lock on the writer for the duration of the write; the lock instead simply prevents
|
|
2151
|
+
* other producers from writing in an interleaved manner.
|
|
2152
|
+
*/
|
|
1920
2153
|
WritableStreamDefaultWriter.prototype.releaseLock = function () {
|
|
1921
2154
|
if (!IsWritableStreamDefaultWriter(this)) {
|
|
1922
2155
|
throw defaultWriterBrandCheckException('releaseLock');
|
|
@@ -1962,7 +2195,7 @@
|
|
|
1962
2195
|
if (!Object.prototype.hasOwnProperty.call(x, '_ownerWritableStream')) {
|
|
1963
2196
|
return false;
|
|
1964
2197
|
}
|
|
1965
|
-
return
|
|
2198
|
+
return x instanceof WritableStreamDefaultWriter;
|
|
1966
2199
|
}
|
|
1967
2200
|
// A client of WritableStreamDefaultWriter may use these functions directly to bypass state check.
|
|
1968
2201
|
function WritableStreamDefaultWriterAbort(writer, reason) {
|
|
@@ -2043,14 +2276,58 @@
|
|
|
2043
2276
|
return promise;
|
|
2044
2277
|
}
|
|
2045
2278
|
var closeSentinel = {};
|
|
2279
|
+
/**
|
|
2280
|
+
* Allows control of a {@link WritableStream | writable stream}'s state and internal queue.
|
|
2281
|
+
*
|
|
2282
|
+
* @public
|
|
2283
|
+
*/
|
|
2046
2284
|
var WritableStreamDefaultController = /** @class */ (function () {
|
|
2047
2285
|
function WritableStreamDefaultController() {
|
|
2048
2286
|
throw new TypeError('Illegal constructor');
|
|
2049
2287
|
}
|
|
2288
|
+
Object.defineProperty(WritableStreamDefaultController.prototype, "abortReason", {
|
|
2289
|
+
/**
|
|
2290
|
+
* The reason which was passed to `WritableStream.abort(reason)` when the stream was aborted.
|
|
2291
|
+
*/
|
|
2292
|
+
get: function () {
|
|
2293
|
+
if (!IsWritableStreamDefaultController(this)) {
|
|
2294
|
+
throw defaultControllerBrandCheckException$2('abortReason');
|
|
2295
|
+
}
|
|
2296
|
+
return this._abortReason;
|
|
2297
|
+
},
|
|
2298
|
+
enumerable: false,
|
|
2299
|
+
configurable: true
|
|
2300
|
+
});
|
|
2301
|
+
Object.defineProperty(WritableStreamDefaultController.prototype, "signal", {
|
|
2302
|
+
/**
|
|
2303
|
+
* An `AbortSignal` that can be used to abort the pending write or close operation when the stream is aborted.
|
|
2304
|
+
*/
|
|
2305
|
+
get: function () {
|
|
2306
|
+
if (!IsWritableStreamDefaultController(this)) {
|
|
2307
|
+
throw defaultControllerBrandCheckException$2('signal');
|
|
2308
|
+
}
|
|
2309
|
+
if (this._abortController === undefined) {
|
|
2310
|
+
// Older browsers or older Node versions may not support `AbortController` or `AbortSignal`.
|
|
2311
|
+
// We don't want to bundle and ship an `AbortController` polyfill together with our polyfill,
|
|
2312
|
+
// so instead we only implement support for `signal` if we find a global `AbortController` constructor.
|
|
2313
|
+
throw new TypeError('WritableStreamDefaultController.prototype.signal is not supported');
|
|
2314
|
+
}
|
|
2315
|
+
return this._abortController.signal;
|
|
2316
|
+
},
|
|
2317
|
+
enumerable: false,
|
|
2318
|
+
configurable: true
|
|
2319
|
+
});
|
|
2320
|
+
/**
|
|
2321
|
+
* Closes the controlled writable stream, making all future interactions with it fail with the given error `e`.
|
|
2322
|
+
*
|
|
2323
|
+
* This method is rarely used, since usually it suffices to return a rejected promise from one of the underlying
|
|
2324
|
+
* sink's methods. However, it can be useful for suddenly shutting down a stream in response to an event outside the
|
|
2325
|
+
* normal lifecycle of interactions with the underlying sink.
|
|
2326
|
+
*/
|
|
2050
2327
|
WritableStreamDefaultController.prototype.error = function (e) {
|
|
2051
2328
|
if (e === void 0) { e = undefined; }
|
|
2052
2329
|
if (!IsWritableStreamDefaultController(this)) {
|
|
2053
|
-
throw
|
|
2330
|
+
throw defaultControllerBrandCheckException$2('error');
|
|
2054
2331
|
}
|
|
2055
2332
|
var state = this._controlledWritableStream._state;
|
|
2056
2333
|
if (state !== 'writable') {
|
|
@@ -2089,7 +2366,7 @@
|
|
|
2089
2366
|
if (!Object.prototype.hasOwnProperty.call(x, '_controlledWritableStream')) {
|
|
2090
2367
|
return false;
|
|
2091
2368
|
}
|
|
2092
|
-
return
|
|
2369
|
+
return x instanceof WritableStreamDefaultController;
|
|
2093
2370
|
}
|
|
2094
2371
|
function SetUpWritableStreamDefaultController(stream, controller, startAlgorithm, writeAlgorithm, closeAlgorithm, abortAlgorithm, highWaterMark, sizeAlgorithm) {
|
|
2095
2372
|
controller._controlledWritableStream = stream;
|
|
@@ -2098,6 +2375,8 @@
|
|
|
2098
2375
|
controller._queue = undefined;
|
|
2099
2376
|
controller._queueTotalSize = undefined;
|
|
2100
2377
|
ResetQueue(controller);
|
|
2378
|
+
controller._abortReason = undefined;
|
|
2379
|
+
controller._abortController = createAbortController();
|
|
2101
2380
|
controller._started = false;
|
|
2102
2381
|
controller._strategySizeAlgorithm = sizeAlgorithm;
|
|
2103
2382
|
controller._strategyHWM = highWaterMark;
|
|
@@ -2247,9 +2526,13 @@
|
|
|
2247
2526
|
WritableStreamStartErroring(stream, error);
|
|
2248
2527
|
}
|
|
2249
2528
|
// Helper functions for the WritableStream.
|
|
2250
|
-
function streamBrandCheckException(name) {
|
|
2529
|
+
function streamBrandCheckException$2(name) {
|
|
2251
2530
|
return new TypeError("WritableStream.prototype." + name + " can only be used on a WritableStream");
|
|
2252
2531
|
}
|
|
2532
|
+
// Helper functions for the WritableStreamDefaultController.
|
|
2533
|
+
function defaultControllerBrandCheckException$2(name) {
|
|
2534
|
+
return new TypeError("WritableStreamDefaultController.prototype." + name + " can only be used on a WritableStreamDefaultController");
|
|
2535
|
+
}
|
|
2253
2536
|
// Helper functions for the WritableStreamDefaultWriter.
|
|
2254
2537
|
function defaultWriterBrandCheckException(name) {
|
|
2255
2538
|
return new TypeError("WritableStreamDefaultWriter.prototype." + name + " can only be used on a WritableStreamDefaultWriter");
|
|
@@ -2273,6 +2556,9 @@
|
|
|
2273
2556
|
defaultWriterClosedPromiseResolve(writer);
|
|
2274
2557
|
}
|
|
2275
2558
|
function defaultWriterClosedPromiseReject(writer, reason) {
|
|
2559
|
+
if (writer._closedPromise_reject === undefined) {
|
|
2560
|
+
return;
|
|
2561
|
+
}
|
|
2276
2562
|
setPromiseIsHandledToTrue(writer._closedPromise);
|
|
2277
2563
|
writer._closedPromise_reject(reason);
|
|
2278
2564
|
writer._closedPromise_resolve = undefined;
|
|
@@ -2283,6 +2569,9 @@
|
|
|
2283
2569
|
defaultWriterClosedPromiseInitializeAsRejected(writer, reason);
|
|
2284
2570
|
}
|
|
2285
2571
|
function defaultWriterClosedPromiseResolve(writer) {
|
|
2572
|
+
if (writer._closedPromise_resolve === undefined) {
|
|
2573
|
+
return;
|
|
2574
|
+
}
|
|
2286
2575
|
writer._closedPromise_resolve(undefined);
|
|
2287
2576
|
writer._closedPromise_resolve = undefined;
|
|
2288
2577
|
writer._closedPromise_reject = undefined;
|
|
@@ -2304,6 +2593,9 @@
|
|
|
2304
2593
|
defaultWriterReadyPromiseResolve(writer);
|
|
2305
2594
|
}
|
|
2306
2595
|
function defaultWriterReadyPromiseReject(writer, reason) {
|
|
2596
|
+
if (writer._readyPromise_reject === undefined) {
|
|
2597
|
+
return;
|
|
2598
|
+
}
|
|
2307
2599
|
setPromiseIsHandledToTrue(writer._readyPromise);
|
|
2308
2600
|
writer._readyPromise_reject(reason);
|
|
2309
2601
|
writer._readyPromise_resolve = undefined;
|
|
@@ -2317,25 +2609,15 @@
|
|
|
2317
2609
|
defaultWriterReadyPromiseInitializeAsRejected(writer, reason);
|
|
2318
2610
|
}
|
|
2319
2611
|
function defaultWriterReadyPromiseResolve(writer) {
|
|
2612
|
+
if (writer._readyPromise_resolve === undefined) {
|
|
2613
|
+
return;
|
|
2614
|
+
}
|
|
2320
2615
|
writer._readyPromise_resolve(undefined);
|
|
2321
2616
|
writer._readyPromise_resolve = undefined;
|
|
2322
2617
|
writer._readyPromise_reject = undefined;
|
|
2323
2618
|
writer._readyPromiseState = 'fulfilled';
|
|
2324
2619
|
}
|
|
2325
2620
|
|
|
2326
|
-
function isAbortSignal(value) {
|
|
2327
|
-
if (typeof value !== 'object' || value === null) {
|
|
2328
|
-
return false;
|
|
2329
|
-
}
|
|
2330
|
-
try {
|
|
2331
|
-
return typeof value.aborted === 'boolean';
|
|
2332
|
-
}
|
|
2333
|
-
catch (_a) {
|
|
2334
|
-
// AbortSignal.prototype.aborted throws if its brand check fails
|
|
2335
|
-
return false;
|
|
2336
|
-
}
|
|
2337
|
-
}
|
|
2338
|
-
|
|
2339
2621
|
/// <reference lib="dom" />
|
|
2340
2622
|
var NativeDOMException = typeof DOMException !== 'undefined' ? DOMException : undefined;
|
|
2341
2623
|
|
|
@@ -2353,6 +2635,7 @@
|
|
|
2353
2635
|
}
|
|
2354
2636
|
}
|
|
2355
2637
|
function createDOMExceptionPolyfill() {
|
|
2638
|
+
// eslint-disable-next-line no-shadow
|
|
2356
2639
|
var ctor = function DOMException(message, name) {
|
|
2357
2640
|
this.message = message || '';
|
|
2358
2641
|
this.name = name || 'Error';
|
|
@@ -2364,6 +2647,7 @@
|
|
|
2364
2647
|
Object.defineProperty(ctor.prototype, 'constructor', { value: ctor, writable: true, configurable: true });
|
|
2365
2648
|
return ctor;
|
|
2366
2649
|
}
|
|
2650
|
+
// eslint-disable-next-line no-redeclare
|
|
2367
2651
|
var DOMException$1 = isDOMExceptionConstructor(NativeDOMException) ? NativeDOMException : createDOMExceptionPolyfill();
|
|
2368
2652
|
|
|
2369
2653
|
function ReadableStreamPipeTo(source, dest, preventClose, preventAbort, preventCancel, signal) {
|
|
@@ -2541,23 +2825,36 @@
|
|
|
2541
2825
|
});
|
|
2542
2826
|
}
|
|
2543
2827
|
|
|
2828
|
+
/**
|
|
2829
|
+
* Allows control of a {@link ReadableStream | readable stream}'s state and internal queue.
|
|
2830
|
+
*
|
|
2831
|
+
* @public
|
|
2832
|
+
*/
|
|
2544
2833
|
var ReadableStreamDefaultController = /** @class */ (function () {
|
|
2545
2834
|
function ReadableStreamDefaultController() {
|
|
2546
2835
|
throw new TypeError('Illegal constructor');
|
|
2547
2836
|
}
|
|
2548
2837
|
Object.defineProperty(ReadableStreamDefaultController.prototype, "desiredSize", {
|
|
2838
|
+
/**
|
|
2839
|
+
* Returns the desired size to fill the controlled stream's internal queue. It can be negative, if the queue is
|
|
2840
|
+
* over-full. An underlying source ought to use this information to determine when and how to apply backpressure.
|
|
2841
|
+
*/
|
|
2549
2842
|
get: function () {
|
|
2550
2843
|
if (!IsReadableStreamDefaultController(this)) {
|
|
2551
|
-
throw defaultControllerBrandCheckException('desiredSize');
|
|
2844
|
+
throw defaultControllerBrandCheckException$1('desiredSize');
|
|
2552
2845
|
}
|
|
2553
2846
|
return ReadableStreamDefaultControllerGetDesiredSize(this);
|
|
2554
2847
|
},
|
|
2555
2848
|
enumerable: false,
|
|
2556
2849
|
configurable: true
|
|
2557
2850
|
});
|
|
2851
|
+
/**
|
|
2852
|
+
* Closes the controlled readable stream. Consumers will still be able to read any previously-enqueued chunks from
|
|
2853
|
+
* the stream, but once those are read, the stream will become closed.
|
|
2854
|
+
*/
|
|
2558
2855
|
ReadableStreamDefaultController.prototype.close = function () {
|
|
2559
2856
|
if (!IsReadableStreamDefaultController(this)) {
|
|
2560
|
-
throw defaultControllerBrandCheckException('close');
|
|
2857
|
+
throw defaultControllerBrandCheckException$1('close');
|
|
2561
2858
|
}
|
|
2562
2859
|
if (!ReadableStreamDefaultControllerCanCloseOrEnqueue(this)) {
|
|
2563
2860
|
throw new TypeError('The stream is not in a state that permits close');
|
|
@@ -2567,17 +2864,20 @@
|
|
|
2567
2864
|
ReadableStreamDefaultController.prototype.enqueue = function (chunk) {
|
|
2568
2865
|
if (chunk === void 0) { chunk = undefined; }
|
|
2569
2866
|
if (!IsReadableStreamDefaultController(this)) {
|
|
2570
|
-
throw defaultControllerBrandCheckException('enqueue');
|
|
2867
|
+
throw defaultControllerBrandCheckException$1('enqueue');
|
|
2571
2868
|
}
|
|
2572
2869
|
if (!ReadableStreamDefaultControllerCanCloseOrEnqueue(this)) {
|
|
2573
2870
|
throw new TypeError('The stream is not in a state that permits enqueue');
|
|
2574
2871
|
}
|
|
2575
2872
|
return ReadableStreamDefaultControllerEnqueue(this, chunk);
|
|
2576
2873
|
};
|
|
2874
|
+
/**
|
|
2875
|
+
* Errors the controlled readable stream, making all future interactions with it fail with the given error `e`.
|
|
2876
|
+
*/
|
|
2577
2877
|
ReadableStreamDefaultController.prototype.error = function (e) {
|
|
2578
2878
|
if (e === void 0) { e = undefined; }
|
|
2579
2879
|
if (!IsReadableStreamDefaultController(this)) {
|
|
2580
|
-
throw defaultControllerBrandCheckException('error');
|
|
2880
|
+
throw defaultControllerBrandCheckException$1('error');
|
|
2581
2881
|
}
|
|
2582
2882
|
ReadableStreamDefaultControllerError(this, e);
|
|
2583
2883
|
};
|
|
@@ -2629,7 +2929,7 @@
|
|
|
2629
2929
|
if (!Object.prototype.hasOwnProperty.call(x, '_controlledReadableStream')) {
|
|
2630
2930
|
return false;
|
|
2631
2931
|
}
|
|
2632
|
-
return
|
|
2932
|
+
return x instanceof ReadableStreamDefaultController;
|
|
2633
2933
|
}
|
|
2634
2934
|
function ReadableStreamDefaultControllerCallPullIfNeeded(controller) {
|
|
2635
2935
|
var shouldPull = ReadableStreamDefaultControllerShouldCallPull(controller);
|
|
@@ -2723,8 +3023,7 @@
|
|
|
2723
3023
|
ReadableStreamError(stream, e);
|
|
2724
3024
|
}
|
|
2725
3025
|
function ReadableStreamDefaultControllerGetDesiredSize(controller) {
|
|
2726
|
-
var
|
|
2727
|
-
var state = stream._state;
|
|
3026
|
+
var state = controller._controlledReadableStream._state;
|
|
2728
3027
|
if (state === 'errored') {
|
|
2729
3028
|
return null;
|
|
2730
3029
|
}
|
|
@@ -2786,11 +3085,17 @@
|
|
|
2786
3085
|
SetUpReadableStreamDefaultController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, sizeAlgorithm);
|
|
2787
3086
|
}
|
|
2788
3087
|
// Helper functions for the ReadableStreamDefaultController.
|
|
2789
|
-
function defaultControllerBrandCheckException(name) {
|
|
3088
|
+
function defaultControllerBrandCheckException$1(name) {
|
|
2790
3089
|
return new TypeError("ReadableStreamDefaultController.prototype." + name + " can only be used on a ReadableStreamDefaultController");
|
|
2791
3090
|
}
|
|
2792
3091
|
|
|
2793
3092
|
function ReadableStreamTee(stream, cloneForBranch2) {
|
|
3093
|
+
if (IsReadableByteStreamController(stream._readableStreamController)) {
|
|
3094
|
+
return ReadableByteStreamTee(stream);
|
|
3095
|
+
}
|
|
3096
|
+
return ReadableStreamDefaultTee(stream);
|
|
3097
|
+
}
|
|
3098
|
+
function ReadableStreamDefaultTee(stream, cloneForBranch2) {
|
|
2794
3099
|
var reader = AcquireReadableStreamDefaultReader(stream);
|
|
2795
3100
|
var reading = false;
|
|
2796
3101
|
var canceled1 = false;
|
|
@@ -2809,24 +3114,24 @@
|
|
|
2809
3114
|
}
|
|
2810
3115
|
reading = true;
|
|
2811
3116
|
var readRequest = {
|
|
2812
|
-
_chunkSteps: function (
|
|
3117
|
+
_chunkSteps: function (chunk) {
|
|
2813
3118
|
// This needs to be delayed a microtask because it takes at least a microtask to detect errors (using
|
|
2814
3119
|
// reader._closedPromise below), and we want errors in stream to error both branches immediately. We cannot let
|
|
2815
3120
|
// successful synchronously-available reads get ahead of asynchronously-available errors.
|
|
2816
3121
|
queueMicrotask(function () {
|
|
2817
3122
|
reading = false;
|
|
2818
|
-
var
|
|
2819
|
-
var
|
|
3123
|
+
var chunk1 = chunk;
|
|
3124
|
+
var chunk2 = chunk;
|
|
2820
3125
|
// There is no way to access the cloning code right now in the reference implementation.
|
|
2821
3126
|
// If we add one then we'll need an implementation for serializable objects.
|
|
2822
3127
|
// if (!canceled2 && cloneForBranch2) {
|
|
2823
|
-
//
|
|
3128
|
+
// chunk2 = StructuredDeserialize(StructuredSerialize(chunk2));
|
|
2824
3129
|
// }
|
|
2825
3130
|
if (!canceled1) {
|
|
2826
|
-
ReadableStreamDefaultControllerEnqueue(branch1._readableStreamController,
|
|
3131
|
+
ReadableStreamDefaultControllerEnqueue(branch1._readableStreamController, chunk1);
|
|
2827
3132
|
}
|
|
2828
3133
|
if (!canceled2) {
|
|
2829
|
-
ReadableStreamDefaultControllerEnqueue(branch2._readableStreamController,
|
|
3134
|
+
ReadableStreamDefaultControllerEnqueue(branch2._readableStreamController, chunk2);
|
|
2830
3135
|
}
|
|
2831
3136
|
});
|
|
2832
3137
|
},
|
|
@@ -2838,6 +3143,9 @@
|
|
|
2838
3143
|
if (!canceled2) {
|
|
2839
3144
|
ReadableStreamDefaultControllerClose(branch2._readableStreamController);
|
|
2840
3145
|
}
|
|
3146
|
+
if (!canceled1 || !canceled2) {
|
|
3147
|
+
resolveCancelPromise(undefined);
|
|
3148
|
+
}
|
|
2841
3149
|
},
|
|
2842
3150
|
_errorSteps: function () {
|
|
2843
3151
|
reading = false;
|
|
@@ -2874,9 +3182,217 @@
|
|
|
2874
3182
|
uponRejection(reader._closedPromise, function (r) {
|
|
2875
3183
|
ReadableStreamDefaultControllerError(branch1._readableStreamController, r);
|
|
2876
3184
|
ReadableStreamDefaultControllerError(branch2._readableStreamController, r);
|
|
3185
|
+
if (!canceled1 || !canceled2) {
|
|
3186
|
+
resolveCancelPromise(undefined);
|
|
3187
|
+
}
|
|
2877
3188
|
});
|
|
2878
3189
|
return [branch1, branch2];
|
|
2879
3190
|
}
|
|
3191
|
+
function ReadableByteStreamTee(stream) {
|
|
3192
|
+
var reader = AcquireReadableStreamDefaultReader(stream);
|
|
3193
|
+
var reading = false;
|
|
3194
|
+
var canceled1 = false;
|
|
3195
|
+
var canceled2 = false;
|
|
3196
|
+
var reason1;
|
|
3197
|
+
var reason2;
|
|
3198
|
+
var branch1;
|
|
3199
|
+
var branch2;
|
|
3200
|
+
var resolveCancelPromise;
|
|
3201
|
+
var cancelPromise = newPromise(function (resolve) {
|
|
3202
|
+
resolveCancelPromise = resolve;
|
|
3203
|
+
});
|
|
3204
|
+
function forwardReaderError(thisReader) {
|
|
3205
|
+
uponRejection(thisReader._closedPromise, function (r) {
|
|
3206
|
+
if (thisReader !== reader) {
|
|
3207
|
+
return;
|
|
3208
|
+
}
|
|
3209
|
+
ReadableByteStreamControllerError(branch1._readableStreamController, r);
|
|
3210
|
+
ReadableByteStreamControllerError(branch2._readableStreamController, r);
|
|
3211
|
+
if (!canceled1 || !canceled2) {
|
|
3212
|
+
resolveCancelPromise(undefined);
|
|
3213
|
+
}
|
|
3214
|
+
});
|
|
3215
|
+
}
|
|
3216
|
+
function pullWithDefaultReader() {
|
|
3217
|
+
if (IsReadableStreamBYOBReader(reader)) {
|
|
3218
|
+
ReadableStreamReaderGenericRelease(reader);
|
|
3219
|
+
reader = AcquireReadableStreamDefaultReader(stream);
|
|
3220
|
+
forwardReaderError(reader);
|
|
3221
|
+
}
|
|
3222
|
+
var readRequest = {
|
|
3223
|
+
_chunkSteps: function (chunk) {
|
|
3224
|
+
// This needs to be delayed a microtask because it takes at least a microtask to detect errors (using
|
|
3225
|
+
// reader._closedPromise below), and we want errors in stream to error both branches immediately. We cannot let
|
|
3226
|
+
// successful synchronously-available reads get ahead of asynchronously-available errors.
|
|
3227
|
+
queueMicrotask(function () {
|
|
3228
|
+
reading = false;
|
|
3229
|
+
var chunk1 = chunk;
|
|
3230
|
+
var chunk2 = chunk;
|
|
3231
|
+
if (!canceled1 && !canceled2) {
|
|
3232
|
+
try {
|
|
3233
|
+
chunk2 = CloneAsUint8Array(chunk);
|
|
3234
|
+
}
|
|
3235
|
+
catch (cloneE) {
|
|
3236
|
+
ReadableByteStreamControllerError(branch1._readableStreamController, cloneE);
|
|
3237
|
+
ReadableByteStreamControllerError(branch2._readableStreamController, cloneE);
|
|
3238
|
+
resolveCancelPromise(ReadableStreamCancel(stream, cloneE));
|
|
3239
|
+
return;
|
|
3240
|
+
}
|
|
3241
|
+
}
|
|
3242
|
+
if (!canceled1) {
|
|
3243
|
+
ReadableByteStreamControllerEnqueue(branch1._readableStreamController, chunk1);
|
|
3244
|
+
}
|
|
3245
|
+
if (!canceled2) {
|
|
3246
|
+
ReadableByteStreamControllerEnqueue(branch2._readableStreamController, chunk2);
|
|
3247
|
+
}
|
|
3248
|
+
});
|
|
3249
|
+
},
|
|
3250
|
+
_closeSteps: function () {
|
|
3251
|
+
reading = false;
|
|
3252
|
+
if (!canceled1) {
|
|
3253
|
+
ReadableByteStreamControllerClose(branch1._readableStreamController);
|
|
3254
|
+
}
|
|
3255
|
+
if (!canceled2) {
|
|
3256
|
+
ReadableByteStreamControllerClose(branch2._readableStreamController);
|
|
3257
|
+
}
|
|
3258
|
+
if (branch1._readableStreamController._pendingPullIntos.length > 0) {
|
|
3259
|
+
ReadableByteStreamControllerRespond(branch1._readableStreamController, 0);
|
|
3260
|
+
}
|
|
3261
|
+
if (branch2._readableStreamController._pendingPullIntos.length > 0) {
|
|
3262
|
+
ReadableByteStreamControllerRespond(branch2._readableStreamController, 0);
|
|
3263
|
+
}
|
|
3264
|
+
if (!canceled1 || !canceled2) {
|
|
3265
|
+
resolveCancelPromise(undefined);
|
|
3266
|
+
}
|
|
3267
|
+
},
|
|
3268
|
+
_errorSteps: function () {
|
|
3269
|
+
reading = false;
|
|
3270
|
+
}
|
|
3271
|
+
};
|
|
3272
|
+
ReadableStreamDefaultReaderRead(reader, readRequest);
|
|
3273
|
+
}
|
|
3274
|
+
function pullWithBYOBReader(view, forBranch2) {
|
|
3275
|
+
if (IsReadableStreamDefaultReader(reader)) {
|
|
3276
|
+
ReadableStreamReaderGenericRelease(reader);
|
|
3277
|
+
reader = AcquireReadableStreamBYOBReader(stream);
|
|
3278
|
+
forwardReaderError(reader);
|
|
3279
|
+
}
|
|
3280
|
+
var byobBranch = forBranch2 ? branch2 : branch1;
|
|
3281
|
+
var otherBranch = forBranch2 ? branch1 : branch2;
|
|
3282
|
+
var readIntoRequest = {
|
|
3283
|
+
_chunkSteps: function (chunk) {
|
|
3284
|
+
// This needs to be delayed a microtask because it takes at least a microtask to detect errors (using
|
|
3285
|
+
// reader._closedPromise below), and we want errors in stream to error both branches immediately. We cannot let
|
|
3286
|
+
// successful synchronously-available reads get ahead of asynchronously-available errors.
|
|
3287
|
+
queueMicrotask(function () {
|
|
3288
|
+
reading = false;
|
|
3289
|
+
var byobCanceled = forBranch2 ? canceled2 : canceled1;
|
|
3290
|
+
var otherCanceled = forBranch2 ? canceled1 : canceled2;
|
|
3291
|
+
if (!otherCanceled) {
|
|
3292
|
+
var clonedChunk = void 0;
|
|
3293
|
+
try {
|
|
3294
|
+
clonedChunk = CloneAsUint8Array(chunk);
|
|
3295
|
+
}
|
|
3296
|
+
catch (cloneE) {
|
|
3297
|
+
ReadableByteStreamControllerError(byobBranch._readableStreamController, cloneE);
|
|
3298
|
+
ReadableByteStreamControllerError(otherBranch._readableStreamController, cloneE);
|
|
3299
|
+
resolveCancelPromise(ReadableStreamCancel(stream, cloneE));
|
|
3300
|
+
return;
|
|
3301
|
+
}
|
|
3302
|
+
if (!byobCanceled) {
|
|
3303
|
+
ReadableByteStreamControllerRespondWithNewView(byobBranch._readableStreamController, chunk);
|
|
3304
|
+
}
|
|
3305
|
+
ReadableByteStreamControllerEnqueue(otherBranch._readableStreamController, clonedChunk);
|
|
3306
|
+
}
|
|
3307
|
+
else if (!byobCanceled) {
|
|
3308
|
+
ReadableByteStreamControllerRespondWithNewView(byobBranch._readableStreamController, chunk);
|
|
3309
|
+
}
|
|
3310
|
+
});
|
|
3311
|
+
},
|
|
3312
|
+
_closeSteps: function (chunk) {
|
|
3313
|
+
reading = false;
|
|
3314
|
+
var byobCanceled = forBranch2 ? canceled2 : canceled1;
|
|
3315
|
+
var otherCanceled = forBranch2 ? canceled1 : canceled2;
|
|
3316
|
+
if (!byobCanceled) {
|
|
3317
|
+
ReadableByteStreamControllerClose(byobBranch._readableStreamController);
|
|
3318
|
+
}
|
|
3319
|
+
if (!otherCanceled) {
|
|
3320
|
+
ReadableByteStreamControllerClose(otherBranch._readableStreamController);
|
|
3321
|
+
}
|
|
3322
|
+
if (chunk !== undefined) {
|
|
3323
|
+
if (!byobCanceled) {
|
|
3324
|
+
ReadableByteStreamControllerRespondWithNewView(byobBranch._readableStreamController, chunk);
|
|
3325
|
+
}
|
|
3326
|
+
if (!otherCanceled && otherBranch._readableStreamController._pendingPullIntos.length > 0) {
|
|
3327
|
+
ReadableByteStreamControllerRespond(otherBranch._readableStreamController, 0);
|
|
3328
|
+
}
|
|
3329
|
+
}
|
|
3330
|
+
if (!byobCanceled || !otherCanceled) {
|
|
3331
|
+
resolveCancelPromise(undefined);
|
|
3332
|
+
}
|
|
3333
|
+
},
|
|
3334
|
+
_errorSteps: function () {
|
|
3335
|
+
reading = false;
|
|
3336
|
+
}
|
|
3337
|
+
};
|
|
3338
|
+
ReadableStreamBYOBReaderRead(reader, view, readIntoRequest);
|
|
3339
|
+
}
|
|
3340
|
+
function pull1Algorithm() {
|
|
3341
|
+
if (reading) {
|
|
3342
|
+
return promiseResolvedWith(undefined);
|
|
3343
|
+
}
|
|
3344
|
+
reading = true;
|
|
3345
|
+
var byobRequest = ReadableByteStreamControllerGetBYOBRequest(branch1._readableStreamController);
|
|
3346
|
+
if (byobRequest === null) {
|
|
3347
|
+
pullWithDefaultReader();
|
|
3348
|
+
}
|
|
3349
|
+
else {
|
|
3350
|
+
pullWithBYOBReader(byobRequest._view, false);
|
|
3351
|
+
}
|
|
3352
|
+
return promiseResolvedWith(undefined);
|
|
3353
|
+
}
|
|
3354
|
+
function pull2Algorithm() {
|
|
3355
|
+
if (reading) {
|
|
3356
|
+
return promiseResolvedWith(undefined);
|
|
3357
|
+
}
|
|
3358
|
+
reading = true;
|
|
3359
|
+
var byobRequest = ReadableByteStreamControllerGetBYOBRequest(branch2._readableStreamController);
|
|
3360
|
+
if (byobRequest === null) {
|
|
3361
|
+
pullWithDefaultReader();
|
|
3362
|
+
}
|
|
3363
|
+
else {
|
|
3364
|
+
pullWithBYOBReader(byobRequest._view, true);
|
|
3365
|
+
}
|
|
3366
|
+
return promiseResolvedWith(undefined);
|
|
3367
|
+
}
|
|
3368
|
+
function cancel1Algorithm(reason) {
|
|
3369
|
+
canceled1 = true;
|
|
3370
|
+
reason1 = reason;
|
|
3371
|
+
if (canceled2) {
|
|
3372
|
+
var compositeReason = CreateArrayFromList([reason1, reason2]);
|
|
3373
|
+
var cancelResult = ReadableStreamCancel(stream, compositeReason);
|
|
3374
|
+
resolveCancelPromise(cancelResult);
|
|
3375
|
+
}
|
|
3376
|
+
return cancelPromise;
|
|
3377
|
+
}
|
|
3378
|
+
function cancel2Algorithm(reason) {
|
|
3379
|
+
canceled2 = true;
|
|
3380
|
+
reason2 = reason;
|
|
3381
|
+
if (canceled1) {
|
|
3382
|
+
var compositeReason = CreateArrayFromList([reason1, reason2]);
|
|
3383
|
+
var cancelResult = ReadableStreamCancel(stream, compositeReason);
|
|
3384
|
+
resolveCancelPromise(cancelResult);
|
|
3385
|
+
}
|
|
3386
|
+
return cancelPromise;
|
|
3387
|
+
}
|
|
3388
|
+
function startAlgorithm() {
|
|
3389
|
+
return;
|
|
3390
|
+
}
|
|
3391
|
+
branch1 = CreateReadableByteStream(startAlgorithm, pull1Algorithm, cancel1Algorithm);
|
|
3392
|
+
branch2 = CreateReadableByteStream(startAlgorithm, pull2Algorithm, cancel2Algorithm);
|
|
3393
|
+
forwardReaderError(reader);
|
|
3394
|
+
return [branch1, branch2];
|
|
3395
|
+
}
|
|
2880
3396
|
|
|
2881
3397
|
function convertUnderlyingDefaultOrByteSource(source, context) {
|
|
2882
3398
|
assertDictionary(source, context);
|
|
@@ -2976,6 +3492,11 @@
|
|
|
2976
3492
|
return { readable: readable, writable: writable };
|
|
2977
3493
|
}
|
|
2978
3494
|
|
|
3495
|
+
/**
|
|
3496
|
+
* A readable stream represents a source of data, from which you can read.
|
|
3497
|
+
*
|
|
3498
|
+
* @public
|
|
3499
|
+
*/
|
|
2979
3500
|
var ReadableStream = /** @class */ (function () {
|
|
2980
3501
|
function ReadableStream(rawUnderlyingSource, rawStrategy) {
|
|
2981
3502
|
if (rawUnderlyingSource === void 0) { rawUnderlyingSource = {}; }
|
|
@@ -3003,6 +3524,9 @@
|
|
|
3003
3524
|
}
|
|
3004
3525
|
}
|
|
3005
3526
|
Object.defineProperty(ReadableStream.prototype, "locked", {
|
|
3527
|
+
/**
|
|
3528
|
+
* Whether or not the readable stream is locked to a {@link ReadableStreamDefaultReader | reader}.
|
|
3529
|
+
*/
|
|
3006
3530
|
get: function () {
|
|
3007
3531
|
if (!IsReadableStream(this)) {
|
|
3008
3532
|
throw streamBrandCheckException$1('locked');
|
|
@@ -3012,6 +3536,12 @@
|
|
|
3012
3536
|
enumerable: false,
|
|
3013
3537
|
configurable: true
|
|
3014
3538
|
});
|
|
3539
|
+
/**
|
|
3540
|
+
* Cancels the stream, signaling a loss of interest in the stream by a consumer.
|
|
3541
|
+
*
|
|
3542
|
+
* The supplied `reason` argument will be given to the underlying source's {@link UnderlyingSource.cancel | cancel()}
|
|
3543
|
+
* method, which might or might not use it.
|
|
3544
|
+
*/
|
|
3015
3545
|
ReadableStream.prototype.cancel = function (reason) {
|
|
3016
3546
|
if (reason === void 0) { reason = undefined; }
|
|
3017
3547
|
if (!IsReadableStream(this)) {
|
|
@@ -3077,6 +3607,17 @@
|
|
|
3077
3607
|
}
|
|
3078
3608
|
return ReadableStreamPipeTo(this, destination, options.preventClose, options.preventAbort, options.preventCancel, options.signal);
|
|
3079
3609
|
};
|
|
3610
|
+
/**
|
|
3611
|
+
* Tees this readable stream, returning a two-element array containing the two resulting branches as
|
|
3612
|
+
* new {@link ReadableStream} instances.
|
|
3613
|
+
*
|
|
3614
|
+
* Teeing a stream will lock it, preventing any other consumer from acquiring a reader.
|
|
3615
|
+
* To cancel the stream, cancel both of the resulting branches; a composite cancellation reason will then be
|
|
3616
|
+
* propagated to the stream's underlying source.
|
|
3617
|
+
*
|
|
3618
|
+
* Note that the chunks seen in each branch will be the same object. If the chunks are not immutable,
|
|
3619
|
+
* this could allow interference between the two branches.
|
|
3620
|
+
*/
|
|
3080
3621
|
ReadableStream.prototype.tee = function () {
|
|
3081
3622
|
if (!IsReadableStream(this)) {
|
|
3082
3623
|
throw streamBrandCheckException$1('tee');
|
|
@@ -3127,6 +3668,14 @@
|
|
|
3127
3668
|
SetUpReadableStreamDefaultController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, sizeAlgorithm);
|
|
3128
3669
|
return stream;
|
|
3129
3670
|
}
|
|
3671
|
+
// Throws if and only if startAlgorithm throws.
|
|
3672
|
+
function CreateReadableByteStream(startAlgorithm, pullAlgorithm, cancelAlgorithm) {
|
|
3673
|
+
var stream = Object.create(ReadableStream.prototype);
|
|
3674
|
+
InitializeReadableStream(stream);
|
|
3675
|
+
var controller = Object.create(ReadableByteStreamController.prototype);
|
|
3676
|
+
SetUpReadableByteStreamController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, 0, undefined);
|
|
3677
|
+
return stream;
|
|
3678
|
+
}
|
|
3130
3679
|
function InitializeReadableStream(stream) {
|
|
3131
3680
|
stream._state = 'readable';
|
|
3132
3681
|
stream._reader = undefined;
|
|
@@ -3140,7 +3689,7 @@
|
|
|
3140
3689
|
if (!Object.prototype.hasOwnProperty.call(x, '_readableStreamController')) {
|
|
3141
3690
|
return false;
|
|
3142
3691
|
}
|
|
3143
|
-
return
|
|
3692
|
+
return x instanceof ReadableStream;
|
|
3144
3693
|
}
|
|
3145
3694
|
function IsReadableStreamLocked(stream) {
|
|
3146
3695
|
if (stream._reader === undefined) {
|
|
@@ -3158,6 +3707,13 @@
|
|
|
3158
3707
|
return promiseRejectedWith(stream._storedError);
|
|
3159
3708
|
}
|
|
3160
3709
|
ReadableStreamClose(stream);
|
|
3710
|
+
var reader = stream._reader;
|
|
3711
|
+
if (reader !== undefined && IsReadableStreamBYOBReader(reader)) {
|
|
3712
|
+
reader._readIntoRequests.forEach(function (readIntoRequest) {
|
|
3713
|
+
readIntoRequest._closeSteps(undefined);
|
|
3714
|
+
});
|
|
3715
|
+
reader._readIntoRequests = new SimpleQueue();
|
|
3716
|
+
}
|
|
3161
3717
|
var sourceCancelPromise = stream._readableStreamController[CancelSteps](reason);
|
|
3162
3718
|
return transformPromiseWith(sourceCancelPromise, noop);
|
|
3163
3719
|
}
|
|
@@ -3167,13 +3723,13 @@
|
|
|
3167
3723
|
if (reader === undefined) {
|
|
3168
3724
|
return;
|
|
3169
3725
|
}
|
|
3726
|
+
defaultReaderClosedPromiseResolve(reader);
|
|
3170
3727
|
if (IsReadableStreamDefaultReader(reader)) {
|
|
3171
3728
|
reader._readRequests.forEach(function (readRequest) {
|
|
3172
3729
|
readRequest._closeSteps();
|
|
3173
3730
|
});
|
|
3174
3731
|
reader._readRequests = new SimpleQueue();
|
|
3175
3732
|
}
|
|
3176
|
-
defaultReaderClosedPromiseResolve(reader);
|
|
3177
3733
|
}
|
|
3178
3734
|
function ReadableStreamError(stream, e) {
|
|
3179
3735
|
stream._state = 'errored';
|
|
@@ -3182,6 +3738,7 @@
|
|
|
3182
3738
|
if (reader === undefined) {
|
|
3183
3739
|
return;
|
|
3184
3740
|
}
|
|
3741
|
+
defaultReaderClosedPromiseReject(reader, e);
|
|
3185
3742
|
if (IsReadableStreamDefaultReader(reader)) {
|
|
3186
3743
|
reader._readRequests.forEach(function (readRequest) {
|
|
3187
3744
|
readRequest._errorSteps(e);
|
|
@@ -3194,7 +3751,6 @@
|
|
|
3194
3751
|
});
|
|
3195
3752
|
reader._readIntoRequests = new SimpleQueue();
|
|
3196
3753
|
}
|
|
3197
|
-
defaultReaderClosedPromiseReject(reader, e);
|
|
3198
3754
|
}
|
|
3199
3755
|
// Helper functions for the ReadableStream.
|
|
3200
3756
|
function streamBrandCheckException$1(name) {
|
|
@@ -3210,9 +3766,19 @@
|
|
|
3210
3766
|
};
|
|
3211
3767
|
}
|
|
3212
3768
|
|
|
3213
|
-
|
|
3769
|
+
// The size function must not have a prototype property nor be a constructor
|
|
3770
|
+
var byteLengthSizeFunction = function (chunk) {
|
|
3214
3771
|
return chunk.byteLength;
|
|
3215
3772
|
};
|
|
3773
|
+
Object.defineProperty(byteLengthSizeFunction, 'name', {
|
|
3774
|
+
value: 'size',
|
|
3775
|
+
configurable: true
|
|
3776
|
+
});
|
|
3777
|
+
/**
|
|
3778
|
+
* A queuing strategy that counts the number of bytes in each chunk.
|
|
3779
|
+
*
|
|
3780
|
+
* @public
|
|
3781
|
+
*/
|
|
3216
3782
|
var ByteLengthQueuingStrategy = /** @class */ (function () {
|
|
3217
3783
|
function ByteLengthQueuingStrategy(options) {
|
|
3218
3784
|
assertRequiredArgument(options, 1, 'ByteLengthQueuingStrategy');
|
|
@@ -3220,6 +3786,9 @@
|
|
|
3220
3786
|
this._byteLengthQueuingStrategyHighWaterMark = options.highWaterMark;
|
|
3221
3787
|
}
|
|
3222
3788
|
Object.defineProperty(ByteLengthQueuingStrategy.prototype, "highWaterMark", {
|
|
3789
|
+
/**
|
|
3790
|
+
* Returns the high water mark provided to the constructor.
|
|
3791
|
+
*/
|
|
3223
3792
|
get: function () {
|
|
3224
3793
|
if (!IsByteLengthQueuingStrategy(this)) {
|
|
3225
3794
|
throw byteLengthBrandCheckException('highWaterMark');
|
|
@@ -3230,6 +3799,9 @@
|
|
|
3230
3799
|
configurable: true
|
|
3231
3800
|
});
|
|
3232
3801
|
Object.defineProperty(ByteLengthQueuingStrategy.prototype, "size", {
|
|
3802
|
+
/**
|
|
3803
|
+
* Measures the size of `chunk` by returning the value of its `byteLength` property.
|
|
3804
|
+
*/
|
|
3233
3805
|
get: function () {
|
|
3234
3806
|
if (!IsByteLengthQueuingStrategy(this)) {
|
|
3235
3807
|
throw byteLengthBrandCheckException('size');
|
|
@@ -3262,12 +3834,22 @@
|
|
|
3262
3834
|
if (!Object.prototype.hasOwnProperty.call(x, '_byteLengthQueuingStrategyHighWaterMark')) {
|
|
3263
3835
|
return false;
|
|
3264
3836
|
}
|
|
3265
|
-
return
|
|
3837
|
+
return x instanceof ByteLengthQueuingStrategy;
|
|
3266
3838
|
}
|
|
3267
3839
|
|
|
3268
|
-
|
|
3840
|
+
// The size function must not have a prototype property nor be a constructor
|
|
3841
|
+
var countSizeFunction = function () {
|
|
3269
3842
|
return 1;
|
|
3270
3843
|
};
|
|
3844
|
+
Object.defineProperty(countSizeFunction, 'name', {
|
|
3845
|
+
value: 'size',
|
|
3846
|
+
configurable: true
|
|
3847
|
+
});
|
|
3848
|
+
/**
|
|
3849
|
+
* A queuing strategy that counts the number of chunks.
|
|
3850
|
+
*
|
|
3851
|
+
* @public
|
|
3852
|
+
*/
|
|
3271
3853
|
var CountQueuingStrategy = /** @class */ (function () {
|
|
3272
3854
|
function CountQueuingStrategy(options) {
|
|
3273
3855
|
assertRequiredArgument(options, 1, 'CountQueuingStrategy');
|
|
@@ -3275,6 +3857,9 @@
|
|
|
3275
3857
|
this._countQueuingStrategyHighWaterMark = options.highWaterMark;
|
|
3276
3858
|
}
|
|
3277
3859
|
Object.defineProperty(CountQueuingStrategy.prototype, "highWaterMark", {
|
|
3860
|
+
/**
|
|
3861
|
+
* Returns the high water mark provided to the constructor.
|
|
3862
|
+
*/
|
|
3278
3863
|
get: function () {
|
|
3279
3864
|
if (!IsCountQueuingStrategy(this)) {
|
|
3280
3865
|
throw countBrandCheckException('highWaterMark');
|
|
@@ -3285,6 +3870,10 @@
|
|
|
3285
3870
|
configurable: true
|
|
3286
3871
|
});
|
|
3287
3872
|
Object.defineProperty(CountQueuingStrategy.prototype, "size", {
|
|
3873
|
+
/**
|
|
3874
|
+
* Measures the size of `chunk` by always returning 1.
|
|
3875
|
+
* This ensures that the total queue size is a count of the number of chunks in the queue.
|
|
3876
|
+
*/
|
|
3288
3877
|
get: function () {
|
|
3289
3878
|
if (!IsCountQueuingStrategy(this)) {
|
|
3290
3879
|
throw countBrandCheckException('size');
|
|
@@ -3317,7 +3906,7 @@
|
|
|
3317
3906
|
if (!Object.prototype.hasOwnProperty.call(x, '_countQueuingStrategyHighWaterMark')) {
|
|
3318
3907
|
return false;
|
|
3319
3908
|
}
|
|
3320
|
-
return
|
|
3909
|
+
return x instanceof CountQueuingStrategy;
|
|
3321
3910
|
}
|
|
3322
3911
|
|
|
3323
3912
|
function convertTransformer(original, context) {
|
|
@@ -3355,6 +3944,14 @@
|
|
|
3355
3944
|
}
|
|
3356
3945
|
|
|
3357
3946
|
// Class TransformStream
|
|
3947
|
+
/**
|
|
3948
|
+
* A transform stream consists of a pair of streams: a {@link WritableStream | writable stream},
|
|
3949
|
+
* known as its writable side, and a {@link ReadableStream | readable stream}, known as its readable side.
|
|
3950
|
+
* In a manner specific to the transform stream in question, writes to the writable side result in new data being
|
|
3951
|
+
* made available for reading from the readable side.
|
|
3952
|
+
*
|
|
3953
|
+
* @public
|
|
3954
|
+
*/
|
|
3358
3955
|
var TransformStream = /** @class */ (function () {
|
|
3359
3956
|
function TransformStream(rawTransformer, rawWritableStrategy, rawReadableStrategy) {
|
|
3360
3957
|
if (rawTransformer === void 0) { rawTransformer = {}; }
|
|
@@ -3390,9 +3987,12 @@
|
|
|
3390
3987
|
}
|
|
3391
3988
|
}
|
|
3392
3989
|
Object.defineProperty(TransformStream.prototype, "readable", {
|
|
3990
|
+
/**
|
|
3991
|
+
* The readable side of the transform stream.
|
|
3992
|
+
*/
|
|
3393
3993
|
get: function () {
|
|
3394
3994
|
if (!IsTransformStream(this)) {
|
|
3395
|
-
throw streamBrandCheckException
|
|
3995
|
+
throw streamBrandCheckException('readable');
|
|
3396
3996
|
}
|
|
3397
3997
|
return this._readable;
|
|
3398
3998
|
},
|
|
@@ -3400,9 +4000,12 @@
|
|
|
3400
4000
|
configurable: true
|
|
3401
4001
|
});
|
|
3402
4002
|
Object.defineProperty(TransformStream.prototype, "writable", {
|
|
4003
|
+
/**
|
|
4004
|
+
* The writable side of the transform stream.
|
|
4005
|
+
*/
|
|
3403
4006
|
get: function () {
|
|
3404
4007
|
if (!IsTransformStream(this)) {
|
|
3405
|
-
throw streamBrandCheckException
|
|
4008
|
+
throw streamBrandCheckException('writable');
|
|
3406
4009
|
}
|
|
3407
4010
|
return this._writable;
|
|
3408
4011
|
},
|
|
@@ -3457,7 +4060,7 @@
|
|
|
3457
4060
|
if (!Object.prototype.hasOwnProperty.call(x, '_transformStreamController')) {
|
|
3458
4061
|
return false;
|
|
3459
4062
|
}
|
|
3460
|
-
return
|
|
4063
|
+
return x instanceof TransformStream;
|
|
3461
4064
|
}
|
|
3462
4065
|
// This is a no-op if both sides are already errored.
|
|
3463
4066
|
function TransformStreamError(stream, e) {
|
|
@@ -3485,14 +4088,22 @@
|
|
|
3485
4088
|
stream._backpressure = backpressure;
|
|
3486
4089
|
}
|
|
3487
4090
|
// Class TransformStreamDefaultController
|
|
4091
|
+
/**
|
|
4092
|
+
* Allows control of the {@link ReadableStream} and {@link WritableStream} of the associated {@link TransformStream}.
|
|
4093
|
+
*
|
|
4094
|
+
* @public
|
|
4095
|
+
*/
|
|
3488
4096
|
var TransformStreamDefaultController = /** @class */ (function () {
|
|
3489
4097
|
function TransformStreamDefaultController() {
|
|
3490
4098
|
throw new TypeError('Illegal constructor');
|
|
3491
4099
|
}
|
|
3492
4100
|
Object.defineProperty(TransformStreamDefaultController.prototype, "desiredSize", {
|
|
4101
|
+
/**
|
|
4102
|
+
* Returns the desired size to fill the readable side’s internal queue. It can be negative, if the queue is over-full.
|
|
4103
|
+
*/
|
|
3493
4104
|
get: function () {
|
|
3494
4105
|
if (!IsTransformStreamDefaultController(this)) {
|
|
3495
|
-
throw defaultControllerBrandCheckException
|
|
4106
|
+
throw defaultControllerBrandCheckException('desiredSize');
|
|
3496
4107
|
}
|
|
3497
4108
|
var readableController = this._controlledTransformStream._readable._readableStreamController;
|
|
3498
4109
|
return ReadableStreamDefaultControllerGetDesiredSize(readableController);
|
|
@@ -3503,20 +4114,28 @@
|
|
|
3503
4114
|
TransformStreamDefaultController.prototype.enqueue = function (chunk) {
|
|
3504
4115
|
if (chunk === void 0) { chunk = undefined; }
|
|
3505
4116
|
if (!IsTransformStreamDefaultController(this)) {
|
|
3506
|
-
throw defaultControllerBrandCheckException
|
|
4117
|
+
throw defaultControllerBrandCheckException('enqueue');
|
|
3507
4118
|
}
|
|
3508
4119
|
TransformStreamDefaultControllerEnqueue(this, chunk);
|
|
3509
4120
|
};
|
|
4121
|
+
/**
|
|
4122
|
+
* Errors both the readable side and the writable side of the controlled transform stream, making all future
|
|
4123
|
+
* interactions with it fail with the given error `e`. Any chunks queued for transformation will be discarded.
|
|
4124
|
+
*/
|
|
3510
4125
|
TransformStreamDefaultController.prototype.error = function (reason) {
|
|
3511
4126
|
if (reason === void 0) { reason = undefined; }
|
|
3512
4127
|
if (!IsTransformStreamDefaultController(this)) {
|
|
3513
|
-
throw defaultControllerBrandCheckException
|
|
4128
|
+
throw defaultControllerBrandCheckException('error');
|
|
3514
4129
|
}
|
|
3515
4130
|
TransformStreamDefaultControllerError(this, reason);
|
|
3516
4131
|
};
|
|
4132
|
+
/**
|
|
4133
|
+
* Closes the readable side and errors the writable side of the controlled transform stream. This is useful when the
|
|
4134
|
+
* transformer only needs to consume a portion of the chunks written to the writable side.
|
|
4135
|
+
*/
|
|
3517
4136
|
TransformStreamDefaultController.prototype.terminate = function () {
|
|
3518
4137
|
if (!IsTransformStreamDefaultController(this)) {
|
|
3519
|
-
throw defaultControllerBrandCheckException
|
|
4138
|
+
throw defaultControllerBrandCheckException('terminate');
|
|
3520
4139
|
}
|
|
3521
4140
|
TransformStreamDefaultControllerTerminate(this);
|
|
3522
4141
|
};
|
|
@@ -3542,7 +4161,7 @@
|
|
|
3542
4161
|
if (!Object.prototype.hasOwnProperty.call(x, '_controlledTransformStream')) {
|
|
3543
4162
|
return false;
|
|
3544
4163
|
}
|
|
3545
|
-
return
|
|
4164
|
+
return x instanceof TransformStreamDefaultController;
|
|
3546
4165
|
}
|
|
3547
4166
|
function SetUpTransformStreamDefaultController(stream, controller, transformAlgorithm, flushAlgorithm) {
|
|
3548
4167
|
controller._controlledTransformStream = stream;
|
|
@@ -3659,11 +4278,11 @@
|
|
|
3659
4278
|
return stream._backpressureChangePromise;
|
|
3660
4279
|
}
|
|
3661
4280
|
// Helper functions for the TransformStreamDefaultController.
|
|
3662
|
-
function defaultControllerBrandCheckException
|
|
4281
|
+
function defaultControllerBrandCheckException(name) {
|
|
3663
4282
|
return new TypeError("TransformStreamDefaultController.prototype." + name + " can only be used on a TransformStreamDefaultController");
|
|
3664
4283
|
}
|
|
3665
4284
|
// Helper functions for the TransformStream.
|
|
3666
|
-
function streamBrandCheckException
|
|
4285
|
+
function streamBrandCheckException(name) {
|
|
3667
4286
|
return new TypeError("TransformStream.prototype." + name + " can only be used on a TransformStream");
|
|
3668
4287
|
}
|
|
3669
4288
|
|