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/ponyfill.es6.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
|
-
const rethrowAssertionErrorRejection =
|
|
36
|
+
const rethrowAssertionErrorRejection = noop;
|
|
37
37
|
|
|
38
38
|
const originalPromise = Promise;
|
|
39
39
|
const originalPromiseThen = Promise.prototype.then;
|
|
@@ -248,6 +248,9 @@
|
|
|
248
248
|
defaultReaderClosedPromiseResolve(reader);
|
|
249
249
|
}
|
|
250
250
|
function defaultReaderClosedPromiseReject(reader, reason) {
|
|
251
|
+
if (reader._closedPromise_reject === undefined) {
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
251
254
|
setPromiseIsHandledToTrue(reader._closedPromise);
|
|
252
255
|
reader._closedPromise_reject(reason);
|
|
253
256
|
reader._closedPromise_resolve = undefined;
|
|
@@ -257,6 +260,9 @@
|
|
|
257
260
|
defaultReaderClosedPromiseInitializeAsRejected(reader, reason);
|
|
258
261
|
}
|
|
259
262
|
function defaultReaderClosedPromiseResolve(reader) {
|
|
263
|
+
if (reader._closedPromise_resolve === undefined) {
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
260
266
|
reader._closedPromise_resolve(undefined);
|
|
261
267
|
reader._closedPromise_resolve = undefined;
|
|
262
268
|
reader._closedPromise_reject = undefined;
|
|
@@ -383,6 +389,11 @@
|
|
|
383
389
|
}
|
|
384
390
|
return true;
|
|
385
391
|
}
|
|
392
|
+
/**
|
|
393
|
+
* A default reader vended by a {@link ReadableStream}.
|
|
394
|
+
*
|
|
395
|
+
* @public
|
|
396
|
+
*/
|
|
386
397
|
class ReadableStreamDefaultReader {
|
|
387
398
|
constructor(stream) {
|
|
388
399
|
assertRequiredArgument(stream, 1, 'ReadableStreamDefaultReader');
|
|
@@ -393,12 +404,19 @@
|
|
|
393
404
|
ReadableStreamReaderGenericInitialize(this, stream);
|
|
394
405
|
this._readRequests = new SimpleQueue();
|
|
395
406
|
}
|
|
407
|
+
/**
|
|
408
|
+
* Returns a promise that will be fulfilled when the stream becomes closed,
|
|
409
|
+
* or rejected if the stream ever errors or the reader's lock is released before the stream finishes closing.
|
|
410
|
+
*/
|
|
396
411
|
get closed() {
|
|
397
412
|
if (!IsReadableStreamDefaultReader(this)) {
|
|
398
413
|
return promiseRejectedWith(defaultReaderBrandCheckException('closed'));
|
|
399
414
|
}
|
|
400
415
|
return this._closedPromise;
|
|
401
416
|
}
|
|
417
|
+
/**
|
|
418
|
+
* If the reader is active, behaves the same as {@link ReadableStream.cancel | stream.cancel(reason)}.
|
|
419
|
+
*/
|
|
402
420
|
cancel(reason = undefined) {
|
|
403
421
|
if (!IsReadableStreamDefaultReader(this)) {
|
|
404
422
|
return promiseRejectedWith(defaultReaderBrandCheckException('cancel'));
|
|
@@ -408,6 +426,11 @@
|
|
|
408
426
|
}
|
|
409
427
|
return ReadableStreamReaderGenericCancel(this, reason);
|
|
410
428
|
}
|
|
429
|
+
/**
|
|
430
|
+
* Returns a promise that allows access to the next chunk from the stream's internal queue, if available.
|
|
431
|
+
*
|
|
432
|
+
* If reading a chunk causes the queue to become empty, more data will be pulled from the underlying source.
|
|
433
|
+
*/
|
|
411
434
|
read() {
|
|
412
435
|
if (!IsReadableStreamDefaultReader(this)) {
|
|
413
436
|
return promiseRejectedWith(defaultReaderBrandCheckException('read'));
|
|
@@ -429,6 +452,15 @@
|
|
|
429
452
|
ReadableStreamDefaultReaderRead(this, readRequest);
|
|
430
453
|
return promise;
|
|
431
454
|
}
|
|
455
|
+
/**
|
|
456
|
+
* Releases the reader's lock on the corresponding stream. After the lock is released, the reader is no longer active.
|
|
457
|
+
* If the associated stream is errored when the lock is released, the reader will appear errored in the same way
|
|
458
|
+
* from now on; otherwise, the reader will appear closed.
|
|
459
|
+
*
|
|
460
|
+
* A reader's lock cannot be released while it still has a pending read request, i.e., if a promise returned by
|
|
461
|
+
* the reader's {@link ReadableStreamDefaultReader.read | read()} method has not yet been settled. Attempting to
|
|
462
|
+
* do so will throw a `TypeError` and leave the reader locked to the stream.
|
|
463
|
+
*/
|
|
432
464
|
releaseLock() {
|
|
433
465
|
if (!IsReadableStreamDefaultReader(this)) {
|
|
434
466
|
throw defaultReaderBrandCheckException('releaseLock');
|
|
@@ -462,7 +494,7 @@
|
|
|
462
494
|
if (!Object.prototype.hasOwnProperty.call(x, '_readRequests')) {
|
|
463
495
|
return false;
|
|
464
496
|
}
|
|
465
|
-
return
|
|
497
|
+
return x instanceof ReadableStreamDefaultReader;
|
|
466
498
|
}
|
|
467
499
|
function ReadableStreamDefaultReaderRead(reader, readRequest) {
|
|
468
500
|
const stream = reader._ownerReadableStream;
|
|
@@ -605,7 +637,14 @@
|
|
|
605
637
|
if (!Object.prototype.hasOwnProperty.call(x, '_asyncIteratorImpl')) {
|
|
606
638
|
return false;
|
|
607
639
|
}
|
|
608
|
-
|
|
640
|
+
try {
|
|
641
|
+
// noinspection SuspiciousTypeOfGuard
|
|
642
|
+
return x._asyncIteratorImpl instanceof
|
|
643
|
+
ReadableStreamAsyncIteratorImpl;
|
|
644
|
+
}
|
|
645
|
+
catch (_a) {
|
|
646
|
+
return false;
|
|
647
|
+
}
|
|
609
648
|
}
|
|
610
649
|
// Helper functions for the ReadableStream.
|
|
611
650
|
function streamAsyncIteratorBrandCheckException(name) {
|
|
@@ -619,15 +658,35 @@
|
|
|
619
658
|
return x !== x;
|
|
620
659
|
};
|
|
621
660
|
|
|
622
|
-
function
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
661
|
+
function CreateArrayFromList(elements) {
|
|
662
|
+
// We use arrays to represent lists, so this is basically a no-op.
|
|
663
|
+
// Do a slice though just in case we happen to depend on the unique-ness.
|
|
664
|
+
return elements.slice();
|
|
665
|
+
}
|
|
666
|
+
function CopyDataBlockBytes(dest, destOffset, src, srcOffset, n) {
|
|
667
|
+
new Uint8Array(dest).set(new Uint8Array(src, srcOffset, n), destOffset);
|
|
668
|
+
}
|
|
669
|
+
// Not implemented correctly
|
|
670
|
+
function TransferArrayBuffer(O) {
|
|
671
|
+
return O;
|
|
672
|
+
}
|
|
673
|
+
// Not implemented correctly
|
|
674
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
675
|
+
function IsDetachedBuffer(O) {
|
|
676
|
+
return false;
|
|
677
|
+
}
|
|
678
|
+
function ArrayBufferSlice(buffer, begin, end) {
|
|
679
|
+
// ArrayBuffer.prototype.slice is not available on IE10
|
|
680
|
+
// https://www.caniuse.com/mdn-javascript_builtins_arraybuffer_slice
|
|
681
|
+
if (buffer.slice) {
|
|
682
|
+
return buffer.slice(begin, end);
|
|
628
683
|
}
|
|
629
|
-
|
|
684
|
+
const length = end - begin;
|
|
685
|
+
const slice = new ArrayBuffer(length);
|
|
686
|
+
CopyDataBlockBytes(slice, 0, buffer, begin, length);
|
|
687
|
+
return slice;
|
|
630
688
|
}
|
|
689
|
+
|
|
631
690
|
function IsNonNegativeNumber(v) {
|
|
632
691
|
if (typeof v !== 'number') {
|
|
633
692
|
return false;
|
|
@@ -640,6 +699,10 @@
|
|
|
640
699
|
}
|
|
641
700
|
return true;
|
|
642
701
|
}
|
|
702
|
+
function CloneAsUint8Array(O) {
|
|
703
|
+
const buffer = ArrayBufferSlice(O.buffer, O.byteOffset, O.byteOffset + O.byteLength);
|
|
704
|
+
return new Uint8Array(buffer);
|
|
705
|
+
}
|
|
643
706
|
|
|
644
707
|
function DequeueValue(container) {
|
|
645
708
|
const pair = container._queue.shift();
|
|
@@ -650,8 +713,7 @@
|
|
|
650
713
|
return pair.value;
|
|
651
714
|
}
|
|
652
715
|
function EnqueueValueWithSize(container, value, size) {
|
|
653
|
-
size
|
|
654
|
-
if (!IsFiniteNonNegativeNumber(size)) {
|
|
716
|
+
if (!IsNonNegativeNumber(size) || size === Infinity) {
|
|
655
717
|
throw new RangeError('Size must be a finite, non-NaN, non-negative number.');
|
|
656
718
|
}
|
|
657
719
|
container._queue.push({ value, size });
|
|
@@ -666,27 +728,18 @@
|
|
|
666
728
|
container._queueTotalSize = 0;
|
|
667
729
|
}
|
|
668
730
|
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
function CopyDataBlockBytes(dest, destOffset, src, srcOffset, n) {
|
|
675
|
-
new Uint8Array(dest).set(new Uint8Array(src, srcOffset, n), destOffset);
|
|
676
|
-
}
|
|
677
|
-
// Not implemented correctly
|
|
678
|
-
function TransferArrayBuffer(O) {
|
|
679
|
-
return O;
|
|
680
|
-
}
|
|
681
|
-
// Not implemented correctly
|
|
682
|
-
function IsDetachedBuffer(O) {
|
|
683
|
-
return false;
|
|
684
|
-
}
|
|
685
|
-
|
|
731
|
+
/**
|
|
732
|
+
* A pull-into request in a {@link ReadableByteStreamController}.
|
|
733
|
+
*
|
|
734
|
+
* @public
|
|
735
|
+
*/
|
|
686
736
|
class ReadableStreamBYOBRequest {
|
|
687
737
|
constructor() {
|
|
688
738
|
throw new TypeError('Illegal constructor');
|
|
689
739
|
}
|
|
740
|
+
/**
|
|
741
|
+
* Returns the view for writing in to, or `null` if the BYOB request has already been responded to.
|
|
742
|
+
*/
|
|
690
743
|
get view() {
|
|
691
744
|
if (!IsReadableStreamBYOBRequest(this)) {
|
|
692
745
|
throw byobRequestBrandCheckException('view');
|
|
@@ -713,15 +766,10 @@
|
|
|
713
766
|
if (!ArrayBuffer.isView(view)) {
|
|
714
767
|
throw new TypeError('You can only respond with array buffer views');
|
|
715
768
|
}
|
|
716
|
-
if (view.byteLength === 0) {
|
|
717
|
-
throw new TypeError('chunk must have non-zero byteLength');
|
|
718
|
-
}
|
|
719
|
-
if (view.buffer.byteLength === 0) {
|
|
720
|
-
throw new TypeError(`chunk's buffer must have non-zero byteLength`);
|
|
721
|
-
}
|
|
722
769
|
if (this._associatedReadableByteStreamController === undefined) {
|
|
723
770
|
throw new TypeError('This BYOB request has been invalidated');
|
|
724
771
|
}
|
|
772
|
+
if (IsDetachedBuffer(view.buffer)) ;
|
|
725
773
|
ReadableByteStreamControllerRespondWithNewView(this._associatedReadableByteStreamController, view);
|
|
726
774
|
}
|
|
727
775
|
}
|
|
@@ -736,29 +784,38 @@
|
|
|
736
784
|
configurable: true
|
|
737
785
|
});
|
|
738
786
|
}
|
|
787
|
+
/**
|
|
788
|
+
* Allows control of a {@link ReadableStream | readable byte stream}'s state and internal queue.
|
|
789
|
+
*
|
|
790
|
+
* @public
|
|
791
|
+
*/
|
|
739
792
|
class ReadableByteStreamController {
|
|
740
793
|
constructor() {
|
|
741
794
|
throw new TypeError('Illegal constructor');
|
|
742
795
|
}
|
|
796
|
+
/**
|
|
797
|
+
* Returns the current BYOB pull request, or `null` if there isn't one.
|
|
798
|
+
*/
|
|
743
799
|
get byobRequest() {
|
|
744
800
|
if (!IsReadableByteStreamController(this)) {
|
|
745
801
|
throw byteStreamControllerBrandCheckException('byobRequest');
|
|
746
802
|
}
|
|
747
|
-
|
|
748
|
-
const firstDescriptor = this._pendingPullIntos.peek();
|
|
749
|
-
const view = new Uint8Array(firstDescriptor.buffer, firstDescriptor.byteOffset + firstDescriptor.bytesFilled, firstDescriptor.byteLength - firstDescriptor.bytesFilled);
|
|
750
|
-
const byobRequest = Object.create(ReadableStreamBYOBRequest.prototype);
|
|
751
|
-
SetUpReadableStreamBYOBRequest(byobRequest, this, view);
|
|
752
|
-
this._byobRequest = byobRequest;
|
|
753
|
-
}
|
|
754
|
-
return this._byobRequest;
|
|
803
|
+
return ReadableByteStreamControllerGetBYOBRequest(this);
|
|
755
804
|
}
|
|
805
|
+
/**
|
|
806
|
+
* Returns the desired size to fill the controlled stream's internal queue. It can be negative, if the queue is
|
|
807
|
+
* over-full. An underlying byte source ought to use this information to determine when and how to apply backpressure.
|
|
808
|
+
*/
|
|
756
809
|
get desiredSize() {
|
|
757
810
|
if (!IsReadableByteStreamController(this)) {
|
|
758
811
|
throw byteStreamControllerBrandCheckException('desiredSize');
|
|
759
812
|
}
|
|
760
813
|
return ReadableByteStreamControllerGetDesiredSize(this);
|
|
761
814
|
}
|
|
815
|
+
/**
|
|
816
|
+
* Closes the controlled readable stream. Consumers will still be able to read any previously-enqueued chunks from
|
|
817
|
+
* the stream, but once those are read, the stream will become closed.
|
|
818
|
+
*/
|
|
762
819
|
close() {
|
|
763
820
|
if (!IsReadableByteStreamController(this)) {
|
|
764
821
|
throw byteStreamControllerBrandCheckException('close');
|
|
@@ -795,6 +852,9 @@
|
|
|
795
852
|
}
|
|
796
853
|
ReadableByteStreamControllerEnqueue(this, chunk);
|
|
797
854
|
}
|
|
855
|
+
/**
|
|
856
|
+
* Errors the controlled readable stream, making all future interactions with it fail with the given error `e`.
|
|
857
|
+
*/
|
|
798
858
|
error(e = undefined) {
|
|
799
859
|
if (!IsReadableByteStreamController(this)) {
|
|
800
860
|
throw byteStreamControllerBrandCheckException('error');
|
|
@@ -803,10 +863,7 @@
|
|
|
803
863
|
}
|
|
804
864
|
/** @internal */
|
|
805
865
|
[CancelSteps](reason) {
|
|
806
|
-
|
|
807
|
-
const firstDescriptor = this._pendingPullIntos.peek();
|
|
808
|
-
firstDescriptor.bytesFilled = 0;
|
|
809
|
-
}
|
|
866
|
+
ReadableByteStreamControllerClearPendingPullIntos(this);
|
|
810
867
|
ResetQueue(this);
|
|
811
868
|
const result = this._cancelAlgorithm(reason);
|
|
812
869
|
ReadableByteStreamControllerClearAlgorithms(this);
|
|
@@ -835,6 +892,7 @@
|
|
|
835
892
|
}
|
|
836
893
|
const pullIntoDescriptor = {
|
|
837
894
|
buffer,
|
|
895
|
+
bufferByteLength: autoAllocateChunkSize,
|
|
838
896
|
byteOffset: 0,
|
|
839
897
|
byteLength: autoAllocateChunkSize,
|
|
840
898
|
bytesFilled: 0,
|
|
@@ -869,7 +927,7 @@
|
|
|
869
927
|
if (!Object.prototype.hasOwnProperty.call(x, '_controlledReadableByteStream')) {
|
|
870
928
|
return false;
|
|
871
929
|
}
|
|
872
|
-
return
|
|
930
|
+
return x instanceof ReadableByteStreamController;
|
|
873
931
|
}
|
|
874
932
|
function IsReadableStreamBYOBRequest(x) {
|
|
875
933
|
if (!typeIsObject(x)) {
|
|
@@ -878,7 +936,7 @@
|
|
|
878
936
|
if (!Object.prototype.hasOwnProperty.call(x, '_associatedReadableByteStreamController')) {
|
|
879
937
|
return false;
|
|
880
938
|
}
|
|
881
|
-
return
|
|
939
|
+
return x instanceof ReadableStreamBYOBRequest;
|
|
882
940
|
}
|
|
883
941
|
function ReadableByteStreamControllerCallPullIfNeeded(controller) {
|
|
884
942
|
const shouldPull = ReadableByteStreamControllerShouldCallPull(controller);
|
|
@@ -960,7 +1018,6 @@
|
|
|
960
1018
|
return ready;
|
|
961
1019
|
}
|
|
962
1020
|
function ReadableByteStreamControllerFillHeadPullIntoDescriptor(controller, size, pullIntoDescriptor) {
|
|
963
|
-
ReadableByteStreamControllerInvalidateBYOBRequest(controller);
|
|
964
1021
|
pullIntoDescriptor.bytesFilled += size;
|
|
965
1022
|
}
|
|
966
1023
|
function ReadableByteStreamControllerHandleQueueDrain(controller) {
|
|
@@ -999,9 +1056,15 @@
|
|
|
999
1056
|
elementSize = view.constructor.BYTES_PER_ELEMENT;
|
|
1000
1057
|
}
|
|
1001
1058
|
const ctor = view.constructor;
|
|
1059
|
+
// try {
|
|
1002
1060
|
const buffer = TransferArrayBuffer(view.buffer);
|
|
1061
|
+
// } catch (e) {
|
|
1062
|
+
// readIntoRequest._errorSteps(e);
|
|
1063
|
+
// return;
|
|
1064
|
+
// }
|
|
1003
1065
|
const pullIntoDescriptor = {
|
|
1004
1066
|
buffer,
|
|
1067
|
+
bufferByteLength: buffer.byteLength,
|
|
1005
1068
|
byteOffset: view.byteOffset,
|
|
1006
1069
|
byteLength: view.byteLength,
|
|
1007
1070
|
bytesFilled: 0,
|
|
@@ -1041,7 +1104,6 @@
|
|
|
1041
1104
|
ReadableByteStreamControllerCallPullIfNeeded(controller);
|
|
1042
1105
|
}
|
|
1043
1106
|
function ReadableByteStreamControllerRespondInClosedState(controller, firstDescriptor) {
|
|
1044
|
-
firstDescriptor.buffer = TransferArrayBuffer(firstDescriptor.buffer);
|
|
1045
1107
|
const stream = controller._controlledReadableByteStream;
|
|
1046
1108
|
if (ReadableStreamHasBYOBReader(stream)) {
|
|
1047
1109
|
while (ReadableStreamGetNumReadIntoRequests(stream) > 0) {
|
|
@@ -1051,34 +1113,27 @@
|
|
|
1051
1113
|
}
|
|
1052
1114
|
}
|
|
1053
1115
|
function ReadableByteStreamControllerRespondInReadableState(controller, bytesWritten, pullIntoDescriptor) {
|
|
1054
|
-
if (pullIntoDescriptor.bytesFilled + bytesWritten > pullIntoDescriptor.byteLength) {
|
|
1055
|
-
throw new RangeError('bytesWritten out of range');
|
|
1056
|
-
}
|
|
1057
1116
|
ReadableByteStreamControllerFillHeadPullIntoDescriptor(controller, bytesWritten, pullIntoDescriptor);
|
|
1058
1117
|
if (pullIntoDescriptor.bytesFilled < pullIntoDescriptor.elementSize) {
|
|
1059
|
-
// TODO: Figure out whether we should detach the buffer or not here.
|
|
1060
1118
|
return;
|
|
1061
1119
|
}
|
|
1062
1120
|
ReadableByteStreamControllerShiftPendingPullInto(controller);
|
|
1063
1121
|
const remainderSize = pullIntoDescriptor.bytesFilled % pullIntoDescriptor.elementSize;
|
|
1064
1122
|
if (remainderSize > 0) {
|
|
1065
1123
|
const end = pullIntoDescriptor.byteOffset + pullIntoDescriptor.bytesFilled;
|
|
1066
|
-
const remainder = pullIntoDescriptor.buffer
|
|
1124
|
+
const remainder = ArrayBufferSlice(pullIntoDescriptor.buffer, end - remainderSize, end);
|
|
1067
1125
|
ReadableByteStreamControllerEnqueueChunkToQueue(controller, remainder, 0, remainder.byteLength);
|
|
1068
1126
|
}
|
|
1069
|
-
pullIntoDescriptor.buffer = TransferArrayBuffer(pullIntoDescriptor.buffer);
|
|
1070
1127
|
pullIntoDescriptor.bytesFilled -= remainderSize;
|
|
1071
1128
|
ReadableByteStreamControllerCommitPullIntoDescriptor(controller._controlledReadableByteStream, pullIntoDescriptor);
|
|
1072
1129
|
ReadableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(controller);
|
|
1073
1130
|
}
|
|
1074
1131
|
function ReadableByteStreamControllerRespondInternal(controller, bytesWritten) {
|
|
1075
1132
|
const firstDescriptor = controller._pendingPullIntos.peek();
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
}
|
|
1081
|
-
ReadableByteStreamControllerRespondInClosedState(controller, firstDescriptor);
|
|
1133
|
+
ReadableByteStreamControllerInvalidateBYOBRequest(controller);
|
|
1134
|
+
const state = controller._controlledReadableByteStream._state;
|
|
1135
|
+
if (state === 'closed') {
|
|
1136
|
+
ReadableByteStreamControllerRespondInClosedState(controller);
|
|
1082
1137
|
}
|
|
1083
1138
|
else {
|
|
1084
1139
|
ReadableByteStreamControllerRespondInReadableState(controller, bytesWritten, firstDescriptor);
|
|
@@ -1087,7 +1142,6 @@
|
|
|
1087
1142
|
}
|
|
1088
1143
|
function ReadableByteStreamControllerShiftPendingPullInto(controller) {
|
|
1089
1144
|
const descriptor = controller._pendingPullIntos.shift();
|
|
1090
|
-
ReadableByteStreamControllerInvalidateBYOBRequest(controller);
|
|
1091
1145
|
return descriptor;
|
|
1092
1146
|
}
|
|
1093
1147
|
function ReadableByteStreamControllerShouldCallPull(controller) {
|
|
@@ -1147,6 +1201,12 @@
|
|
|
1147
1201
|
const byteOffset = chunk.byteOffset;
|
|
1148
1202
|
const byteLength = chunk.byteLength;
|
|
1149
1203
|
const transferredBuffer = TransferArrayBuffer(buffer);
|
|
1204
|
+
if (controller._pendingPullIntos.length > 0) {
|
|
1205
|
+
const firstPendingPullInto = controller._pendingPullIntos.peek();
|
|
1206
|
+
if (IsDetachedBuffer(firstPendingPullInto.buffer)) ;
|
|
1207
|
+
firstPendingPullInto.buffer = TransferArrayBuffer(firstPendingPullInto.buffer);
|
|
1208
|
+
}
|
|
1209
|
+
ReadableByteStreamControllerInvalidateBYOBRequest(controller);
|
|
1150
1210
|
if (ReadableStreamHasDefaultReader(stream)) {
|
|
1151
1211
|
if (ReadableStreamGetNumReadRequests(stream) === 0) {
|
|
1152
1212
|
ReadableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset, byteLength);
|
|
@@ -1176,9 +1236,18 @@
|
|
|
1176
1236
|
ReadableByteStreamControllerClearAlgorithms(controller);
|
|
1177
1237
|
ReadableStreamError(stream, e);
|
|
1178
1238
|
}
|
|
1239
|
+
function ReadableByteStreamControllerGetBYOBRequest(controller) {
|
|
1240
|
+
if (controller._byobRequest === null && controller._pendingPullIntos.length > 0) {
|
|
1241
|
+
const firstDescriptor = controller._pendingPullIntos.peek();
|
|
1242
|
+
const view = new Uint8Array(firstDescriptor.buffer, firstDescriptor.byteOffset + firstDescriptor.bytesFilled, firstDescriptor.byteLength - firstDescriptor.bytesFilled);
|
|
1243
|
+
const byobRequest = Object.create(ReadableStreamBYOBRequest.prototype);
|
|
1244
|
+
SetUpReadableStreamBYOBRequest(byobRequest, controller, view);
|
|
1245
|
+
controller._byobRequest = byobRequest;
|
|
1246
|
+
}
|
|
1247
|
+
return controller._byobRequest;
|
|
1248
|
+
}
|
|
1179
1249
|
function ReadableByteStreamControllerGetDesiredSize(controller) {
|
|
1180
|
-
const
|
|
1181
|
-
const state = stream._state;
|
|
1250
|
+
const state = controller._controlledReadableByteStream._state;
|
|
1182
1251
|
if (state === 'errored') {
|
|
1183
1252
|
return null;
|
|
1184
1253
|
}
|
|
@@ -1188,21 +1257,47 @@
|
|
|
1188
1257
|
return controller._strategyHWM - controller._queueTotalSize;
|
|
1189
1258
|
}
|
|
1190
1259
|
function ReadableByteStreamControllerRespond(controller, bytesWritten) {
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1260
|
+
const firstDescriptor = controller._pendingPullIntos.peek();
|
|
1261
|
+
const state = controller._controlledReadableByteStream._state;
|
|
1262
|
+
if (state === 'closed') {
|
|
1263
|
+
if (bytesWritten !== 0) {
|
|
1264
|
+
throw new TypeError('bytesWritten must be 0 when calling respond() on a closed stream');
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
else {
|
|
1268
|
+
if (bytesWritten === 0) {
|
|
1269
|
+
throw new TypeError('bytesWritten must be greater than 0 when calling respond() on a readable stream');
|
|
1270
|
+
}
|
|
1271
|
+
if (firstDescriptor.bytesFilled + bytesWritten > firstDescriptor.byteLength) {
|
|
1272
|
+
throw new RangeError('bytesWritten out of range');
|
|
1273
|
+
}
|
|
1194
1274
|
}
|
|
1275
|
+
firstDescriptor.buffer = TransferArrayBuffer(firstDescriptor.buffer);
|
|
1195
1276
|
ReadableByteStreamControllerRespondInternal(controller, bytesWritten);
|
|
1196
1277
|
}
|
|
1197
1278
|
function ReadableByteStreamControllerRespondWithNewView(controller, view) {
|
|
1198
1279
|
const firstDescriptor = controller._pendingPullIntos.peek();
|
|
1280
|
+
const state = controller._controlledReadableByteStream._state;
|
|
1281
|
+
if (state === 'closed') {
|
|
1282
|
+
if (view.byteLength !== 0) {
|
|
1283
|
+
throw new TypeError('The view\'s length must be 0 when calling respondWithNewView() on a closed stream');
|
|
1284
|
+
}
|
|
1285
|
+
}
|
|
1286
|
+
else {
|
|
1287
|
+
if (view.byteLength === 0) {
|
|
1288
|
+
throw new TypeError('The view\'s length must be greater than 0 when calling respondWithNewView() on a readable stream');
|
|
1289
|
+
}
|
|
1290
|
+
}
|
|
1199
1291
|
if (firstDescriptor.byteOffset + firstDescriptor.bytesFilled !== view.byteOffset) {
|
|
1200
1292
|
throw new RangeError('The region specified by view does not match byobRequest');
|
|
1201
1293
|
}
|
|
1202
|
-
if (firstDescriptor.
|
|
1294
|
+
if (firstDescriptor.bufferByteLength !== view.buffer.byteLength) {
|
|
1203
1295
|
throw new RangeError('The buffer of view has different capacity than byobRequest');
|
|
1204
1296
|
}
|
|
1205
|
-
firstDescriptor.
|
|
1297
|
+
if (firstDescriptor.bytesFilled + view.byteLength > firstDescriptor.byteLength) {
|
|
1298
|
+
throw new RangeError('The region specified by view is larger than byobRequest');
|
|
1299
|
+
}
|
|
1300
|
+
firstDescriptor.buffer = TransferArrayBuffer(view.buffer);
|
|
1206
1301
|
ReadableByteStreamControllerRespondInternal(controller, view.byteLength);
|
|
1207
1302
|
}
|
|
1208
1303
|
function SetUpReadableByteStreamController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, autoAllocateChunkSize) {
|
|
@@ -1244,6 +1339,9 @@
|
|
|
1244
1339
|
cancelAlgorithm = reason => underlyingByteSource.cancel(reason);
|
|
1245
1340
|
}
|
|
1246
1341
|
const autoAllocateChunkSize = underlyingByteSource.autoAllocateChunkSize;
|
|
1342
|
+
if (autoAllocateChunkSize === 0) {
|
|
1343
|
+
throw new TypeError('autoAllocateChunkSize must be greater than 0');
|
|
1344
|
+
}
|
|
1247
1345
|
SetUpReadableByteStreamController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, autoAllocateChunkSize);
|
|
1248
1346
|
}
|
|
1249
1347
|
function SetUpReadableStreamBYOBRequest(request, controller, view) {
|
|
@@ -1290,6 +1388,11 @@
|
|
|
1290
1388
|
}
|
|
1291
1389
|
return true;
|
|
1292
1390
|
}
|
|
1391
|
+
/**
|
|
1392
|
+
* A BYOB reader vended by a {@link ReadableStream}.
|
|
1393
|
+
*
|
|
1394
|
+
* @public
|
|
1395
|
+
*/
|
|
1293
1396
|
class ReadableStreamBYOBReader {
|
|
1294
1397
|
constructor(stream) {
|
|
1295
1398
|
assertRequiredArgument(stream, 1, 'ReadableStreamBYOBReader');
|
|
@@ -1304,12 +1407,19 @@
|
|
|
1304
1407
|
ReadableStreamReaderGenericInitialize(this, stream);
|
|
1305
1408
|
this._readIntoRequests = new SimpleQueue();
|
|
1306
1409
|
}
|
|
1410
|
+
/**
|
|
1411
|
+
* Returns a promise that will be fulfilled when the stream becomes closed, or rejected if the stream ever errors or
|
|
1412
|
+
* the reader's lock is released before the stream finishes closing.
|
|
1413
|
+
*/
|
|
1307
1414
|
get closed() {
|
|
1308
1415
|
if (!IsReadableStreamBYOBReader(this)) {
|
|
1309
1416
|
return promiseRejectedWith(byobReaderBrandCheckException('closed'));
|
|
1310
1417
|
}
|
|
1311
1418
|
return this._closedPromise;
|
|
1312
1419
|
}
|
|
1420
|
+
/**
|
|
1421
|
+
* If the reader is active, behaves the same as {@link ReadableStream.cancel | stream.cancel(reason)}.
|
|
1422
|
+
*/
|
|
1313
1423
|
cancel(reason = undefined) {
|
|
1314
1424
|
if (!IsReadableStreamBYOBReader(this)) {
|
|
1315
1425
|
return promiseRejectedWith(byobReaderBrandCheckException('cancel'));
|
|
@@ -1319,6 +1429,11 @@
|
|
|
1319
1429
|
}
|
|
1320
1430
|
return ReadableStreamReaderGenericCancel(this, reason);
|
|
1321
1431
|
}
|
|
1432
|
+
/**
|
|
1433
|
+
* Attempts to reads bytes into view, and returns a promise resolved with the result.
|
|
1434
|
+
*
|
|
1435
|
+
* If reading a chunk causes the queue to become empty, more data will be pulled from the underlying source.
|
|
1436
|
+
*/
|
|
1322
1437
|
read(view) {
|
|
1323
1438
|
if (!IsReadableStreamBYOBReader(this)) {
|
|
1324
1439
|
return promiseRejectedWith(byobReaderBrandCheckException('read'));
|
|
@@ -1332,6 +1447,7 @@
|
|
|
1332
1447
|
if (view.buffer.byteLength === 0) {
|
|
1333
1448
|
return promiseRejectedWith(new TypeError(`view's buffer must have non-zero byteLength`));
|
|
1334
1449
|
}
|
|
1450
|
+
if (IsDetachedBuffer(view.buffer)) ;
|
|
1335
1451
|
if (this._ownerReadableStream === undefined) {
|
|
1336
1452
|
return promiseRejectedWith(readerLockException('read from'));
|
|
1337
1453
|
}
|
|
@@ -1349,6 +1465,15 @@
|
|
|
1349
1465
|
ReadableStreamBYOBReaderRead(this, view, readIntoRequest);
|
|
1350
1466
|
return promise;
|
|
1351
1467
|
}
|
|
1468
|
+
/**
|
|
1469
|
+
* Releases the reader's lock on the corresponding stream. After the lock is released, the reader is no longer active.
|
|
1470
|
+
* If the associated stream is errored when the lock is released, the reader will appear errored in the same way
|
|
1471
|
+
* from now on; otherwise, the reader will appear closed.
|
|
1472
|
+
*
|
|
1473
|
+
* A reader's lock cannot be released while it still has a pending read request, i.e., if a promise returned by
|
|
1474
|
+
* the reader's {@link ReadableStreamBYOBReader.read | read()} method has not yet been settled. Attempting to
|
|
1475
|
+
* do so will throw a `TypeError` and leave the reader locked to the stream.
|
|
1476
|
+
*/
|
|
1352
1477
|
releaseLock() {
|
|
1353
1478
|
if (!IsReadableStreamBYOBReader(this)) {
|
|
1354
1479
|
throw byobReaderBrandCheckException('releaseLock');
|
|
@@ -1382,7 +1507,7 @@
|
|
|
1382
1507
|
if (!Object.prototype.hasOwnProperty.call(x, '_readIntoRequests')) {
|
|
1383
1508
|
return false;
|
|
1384
1509
|
}
|
|
1385
|
-
return
|
|
1510
|
+
return x instanceof ReadableStreamBYOBReader;
|
|
1386
1511
|
}
|
|
1387
1512
|
function ReadableStreamBYOBReaderRead(reader, view, readIntoRequest) {
|
|
1388
1513
|
const stream = reader._ownerReadableStream;
|
|
@@ -1477,6 +1602,36 @@
|
|
|
1477
1602
|
}
|
|
1478
1603
|
}
|
|
1479
1604
|
|
|
1605
|
+
function isAbortSignal(value) {
|
|
1606
|
+
if (typeof value !== 'object' || value === null) {
|
|
1607
|
+
return false;
|
|
1608
|
+
}
|
|
1609
|
+
try {
|
|
1610
|
+
return typeof value.aborted === 'boolean';
|
|
1611
|
+
}
|
|
1612
|
+
catch (_a) {
|
|
1613
|
+
// AbortSignal.prototype.aborted throws if its brand check fails
|
|
1614
|
+
return false;
|
|
1615
|
+
}
|
|
1616
|
+
}
|
|
1617
|
+
const supportsAbortController = typeof AbortController === 'function';
|
|
1618
|
+
/**
|
|
1619
|
+
* Construct a new AbortController, if supported by the platform.
|
|
1620
|
+
*
|
|
1621
|
+
* @internal
|
|
1622
|
+
*/
|
|
1623
|
+
function createAbortController() {
|
|
1624
|
+
if (supportsAbortController) {
|
|
1625
|
+
return new AbortController();
|
|
1626
|
+
}
|
|
1627
|
+
return undefined;
|
|
1628
|
+
}
|
|
1629
|
+
|
|
1630
|
+
/**
|
|
1631
|
+
* A writable stream represents a destination for data, into which you can write.
|
|
1632
|
+
*
|
|
1633
|
+
* @public
|
|
1634
|
+
*/
|
|
1480
1635
|
class WritableStream {
|
|
1481
1636
|
constructor(rawUnderlyingSink = {}, rawStrategy = {}) {
|
|
1482
1637
|
if (rawUnderlyingSink === undefined) {
|
|
@@ -1496,24 +1651,44 @@
|
|
|
1496
1651
|
const highWaterMark = ExtractHighWaterMark(strategy, 1);
|
|
1497
1652
|
SetUpWritableStreamDefaultControllerFromUnderlyingSink(this, underlyingSink, highWaterMark, sizeAlgorithm);
|
|
1498
1653
|
}
|
|
1654
|
+
/**
|
|
1655
|
+
* Returns whether or not the writable stream is locked to a writer.
|
|
1656
|
+
*/
|
|
1499
1657
|
get locked() {
|
|
1500
1658
|
if (!IsWritableStream(this)) {
|
|
1501
|
-
throw streamBrandCheckException('locked');
|
|
1659
|
+
throw streamBrandCheckException$2('locked');
|
|
1502
1660
|
}
|
|
1503
1661
|
return IsWritableStreamLocked(this);
|
|
1504
1662
|
}
|
|
1663
|
+
/**
|
|
1664
|
+
* Aborts the stream, signaling that the producer can no longer successfully write to the stream and it is to be
|
|
1665
|
+
* immediately moved to an errored state, with any queued-up writes discarded. This will also execute any abort
|
|
1666
|
+
* mechanism of the underlying sink.
|
|
1667
|
+
*
|
|
1668
|
+
* The returned promise will fulfill if the stream shuts down successfully, or reject if the underlying sink signaled
|
|
1669
|
+
* that there was an error doing so. Additionally, it will reject with a `TypeError` (without attempting to cancel
|
|
1670
|
+
* the stream) if the stream is currently locked.
|
|
1671
|
+
*/
|
|
1505
1672
|
abort(reason = undefined) {
|
|
1506
1673
|
if (!IsWritableStream(this)) {
|
|
1507
|
-
return promiseRejectedWith(streamBrandCheckException('abort'));
|
|
1674
|
+
return promiseRejectedWith(streamBrandCheckException$2('abort'));
|
|
1508
1675
|
}
|
|
1509
1676
|
if (IsWritableStreamLocked(this)) {
|
|
1510
1677
|
return promiseRejectedWith(new TypeError('Cannot abort a stream that already has a writer'));
|
|
1511
1678
|
}
|
|
1512
1679
|
return WritableStreamAbort(this, reason);
|
|
1513
1680
|
}
|
|
1681
|
+
/**
|
|
1682
|
+
* Closes the stream. The underlying sink will finish processing any previously-written chunks, before invoking its
|
|
1683
|
+
* close behavior. During this time any further attempts to write will fail (without erroring the stream).
|
|
1684
|
+
*
|
|
1685
|
+
* The method returns a promise that will fulfill if all remaining chunks are successfully written and the stream
|
|
1686
|
+
* successfully closes, or rejects if an error is encountered during this process. Additionally, it will reject with
|
|
1687
|
+
* a `TypeError` (without attempting to cancel the stream) if the stream is currently locked.
|
|
1688
|
+
*/
|
|
1514
1689
|
close() {
|
|
1515
1690
|
if (!IsWritableStream(this)) {
|
|
1516
|
-
return promiseRejectedWith(streamBrandCheckException('close'));
|
|
1691
|
+
return promiseRejectedWith(streamBrandCheckException$2('close'));
|
|
1517
1692
|
}
|
|
1518
1693
|
if (IsWritableStreamLocked(this)) {
|
|
1519
1694
|
return promiseRejectedWith(new TypeError('Cannot close a stream that already has a writer'));
|
|
@@ -1523,9 +1698,17 @@
|
|
|
1523
1698
|
}
|
|
1524
1699
|
return WritableStreamClose(this);
|
|
1525
1700
|
}
|
|
1701
|
+
/**
|
|
1702
|
+
* Creates a {@link WritableStreamDefaultWriter | writer} and locks the stream to the new writer. While the stream
|
|
1703
|
+
* is locked, no other writer can be acquired until this one is released.
|
|
1704
|
+
*
|
|
1705
|
+
* This functionality is especially useful for creating abstractions that desire the ability to write to a stream
|
|
1706
|
+
* without interruption or interleaving. By getting a writer for the stream, you can ensure nobody else can write at
|
|
1707
|
+
* the same time, which would cause the resulting written data to be unpredictable and probably useless.
|
|
1708
|
+
*/
|
|
1526
1709
|
getWriter() {
|
|
1527
1710
|
if (!IsWritableStream(this)) {
|
|
1528
|
-
throw streamBrandCheckException('getWriter');
|
|
1711
|
+
throw streamBrandCheckException$2('getWriter');
|
|
1529
1712
|
}
|
|
1530
1713
|
return AcquireWritableStreamDefaultWriter(this);
|
|
1531
1714
|
}
|
|
@@ -1587,7 +1770,7 @@
|
|
|
1587
1770
|
if (!Object.prototype.hasOwnProperty.call(x, '_writableStreamController')) {
|
|
1588
1771
|
return false;
|
|
1589
1772
|
}
|
|
1590
|
-
return
|
|
1773
|
+
return x instanceof WritableStream;
|
|
1591
1774
|
}
|
|
1592
1775
|
function IsWritableStreamLocked(stream) {
|
|
1593
1776
|
if (stream._writer === undefined) {
|
|
@@ -1596,6 +1779,15 @@
|
|
|
1596
1779
|
return true;
|
|
1597
1780
|
}
|
|
1598
1781
|
function WritableStreamAbort(stream, reason) {
|
|
1782
|
+
var _a;
|
|
1783
|
+
if (stream._state === 'closed' || stream._state === 'errored') {
|
|
1784
|
+
return promiseResolvedWith(undefined);
|
|
1785
|
+
}
|
|
1786
|
+
stream._writableStreamController._abortReason = reason;
|
|
1787
|
+
(_a = stream._writableStreamController._abortController) === null || _a === void 0 ? void 0 : _a.abort();
|
|
1788
|
+
// TypeScript narrows the type of `stream._state` down to 'writable' | 'erroring',
|
|
1789
|
+
// but it doesn't know that signaling abort runs author code that might have changed the state.
|
|
1790
|
+
// Widen the type again by casting to WritableStreamState.
|
|
1599
1791
|
const state = stream._state;
|
|
1600
1792
|
if (state === 'closed' || state === 'errored') {
|
|
1601
1793
|
return promiseResolvedWith(undefined);
|
|
@@ -1781,6 +1973,11 @@
|
|
|
1781
1973
|
}
|
|
1782
1974
|
stream._backpressure = backpressure;
|
|
1783
1975
|
}
|
|
1976
|
+
/**
|
|
1977
|
+
* A default writer vended by a {@link WritableStream}.
|
|
1978
|
+
*
|
|
1979
|
+
* @public
|
|
1980
|
+
*/
|
|
1784
1981
|
class WritableStreamDefaultWriter {
|
|
1785
1982
|
constructor(stream) {
|
|
1786
1983
|
assertRequiredArgument(stream, 1, 'WritableStreamDefaultWriter');
|
|
@@ -1814,12 +2011,24 @@
|
|
|
1814
2011
|
defaultWriterClosedPromiseInitializeAsRejected(this, storedError);
|
|
1815
2012
|
}
|
|
1816
2013
|
}
|
|
2014
|
+
/**
|
|
2015
|
+
* Returns a promise that will be fulfilled when the stream becomes closed, or rejected if the stream ever errors or
|
|
2016
|
+
* the writer’s lock is released before the stream finishes closing.
|
|
2017
|
+
*/
|
|
1817
2018
|
get closed() {
|
|
1818
2019
|
if (!IsWritableStreamDefaultWriter(this)) {
|
|
1819
2020
|
return promiseRejectedWith(defaultWriterBrandCheckException('closed'));
|
|
1820
2021
|
}
|
|
1821
2022
|
return this._closedPromise;
|
|
1822
2023
|
}
|
|
2024
|
+
/**
|
|
2025
|
+
* Returns the desired size to fill the stream’s internal queue. It can be negative, if the queue is over-full.
|
|
2026
|
+
* A producer can use this information to determine the right amount of data to write.
|
|
2027
|
+
*
|
|
2028
|
+
* It will be `null` if the stream cannot be successfully written to (due to either being errored, or having an abort
|
|
2029
|
+
* queued up). It will return zero if the stream is closed. And the getter will throw an exception if invoked when
|
|
2030
|
+
* the writer’s lock is released.
|
|
2031
|
+
*/
|
|
1823
2032
|
get desiredSize() {
|
|
1824
2033
|
if (!IsWritableStreamDefaultWriter(this)) {
|
|
1825
2034
|
throw defaultWriterBrandCheckException('desiredSize');
|
|
@@ -1829,12 +2038,23 @@
|
|
|
1829
2038
|
}
|
|
1830
2039
|
return WritableStreamDefaultWriterGetDesiredSize(this);
|
|
1831
2040
|
}
|
|
2041
|
+
/**
|
|
2042
|
+
* Returns a promise that will be fulfilled when the desired size to fill the stream’s internal queue transitions
|
|
2043
|
+
* from non-positive to positive, signaling that it is no longer applying backpressure. Once the desired size dips
|
|
2044
|
+
* back to zero or below, the getter will return a new promise that stays pending until the next transition.
|
|
2045
|
+
*
|
|
2046
|
+
* If the stream becomes errored or aborted, or the writer’s lock is released, the returned promise will become
|
|
2047
|
+
* rejected.
|
|
2048
|
+
*/
|
|
1832
2049
|
get ready() {
|
|
1833
2050
|
if (!IsWritableStreamDefaultWriter(this)) {
|
|
1834
2051
|
return promiseRejectedWith(defaultWriterBrandCheckException('ready'));
|
|
1835
2052
|
}
|
|
1836
2053
|
return this._readyPromise;
|
|
1837
2054
|
}
|
|
2055
|
+
/**
|
|
2056
|
+
* If the reader is active, behaves the same as {@link WritableStream.abort | stream.abort(reason)}.
|
|
2057
|
+
*/
|
|
1838
2058
|
abort(reason = undefined) {
|
|
1839
2059
|
if (!IsWritableStreamDefaultWriter(this)) {
|
|
1840
2060
|
return promiseRejectedWith(defaultWriterBrandCheckException('abort'));
|
|
@@ -1844,6 +2064,9 @@
|
|
|
1844
2064
|
}
|
|
1845
2065
|
return WritableStreamDefaultWriterAbort(this, reason);
|
|
1846
2066
|
}
|
|
2067
|
+
/**
|
|
2068
|
+
* If the reader is active, behaves the same as {@link WritableStream.close | stream.close()}.
|
|
2069
|
+
*/
|
|
1847
2070
|
close() {
|
|
1848
2071
|
if (!IsWritableStreamDefaultWriter(this)) {
|
|
1849
2072
|
return promiseRejectedWith(defaultWriterBrandCheckException('close'));
|
|
@@ -1857,6 +2080,16 @@
|
|
|
1857
2080
|
}
|
|
1858
2081
|
return WritableStreamDefaultWriterClose(this);
|
|
1859
2082
|
}
|
|
2083
|
+
/**
|
|
2084
|
+
* Releases the writer’s lock on the corresponding stream. After the lock is released, the writer is no longer active.
|
|
2085
|
+
* If the associated stream is errored when the lock is released, the writer will appear errored in the same way from
|
|
2086
|
+
* now on; otherwise, the writer will appear closed.
|
|
2087
|
+
*
|
|
2088
|
+
* Note that the lock can still be released even if some ongoing writes have not yet finished (i.e. even if the
|
|
2089
|
+
* promises returned from previous calls to {@link WritableStreamDefaultWriter.write | write()} have not yet settled).
|
|
2090
|
+
* It’s not necessary to hold the lock on the writer for the duration of the write; the lock instead simply prevents
|
|
2091
|
+
* other producers from writing in an interleaved manner.
|
|
2092
|
+
*/
|
|
1860
2093
|
releaseLock() {
|
|
1861
2094
|
if (!IsWritableStreamDefaultWriter(this)) {
|
|
1862
2095
|
throw defaultWriterBrandCheckException('releaseLock');
|
|
@@ -1900,7 +2133,7 @@
|
|
|
1900
2133
|
if (!Object.prototype.hasOwnProperty.call(x, '_ownerWritableStream')) {
|
|
1901
2134
|
return false;
|
|
1902
2135
|
}
|
|
1903
|
-
return
|
|
2136
|
+
return x instanceof WritableStreamDefaultWriter;
|
|
1904
2137
|
}
|
|
1905
2138
|
// A client of WritableStreamDefaultWriter may use these functions directly to bypass state check.
|
|
1906
2139
|
function WritableStreamDefaultWriterAbort(writer, reason) {
|
|
@@ -1981,13 +2214,49 @@
|
|
|
1981
2214
|
return promise;
|
|
1982
2215
|
}
|
|
1983
2216
|
const closeSentinel = {};
|
|
2217
|
+
/**
|
|
2218
|
+
* Allows control of a {@link WritableStream | writable stream}'s state and internal queue.
|
|
2219
|
+
*
|
|
2220
|
+
* @public
|
|
2221
|
+
*/
|
|
1984
2222
|
class WritableStreamDefaultController {
|
|
1985
2223
|
constructor() {
|
|
1986
2224
|
throw new TypeError('Illegal constructor');
|
|
1987
2225
|
}
|
|
2226
|
+
/**
|
|
2227
|
+
* The reason which was passed to `WritableStream.abort(reason)` when the stream was aborted.
|
|
2228
|
+
*/
|
|
2229
|
+
get abortReason() {
|
|
2230
|
+
if (!IsWritableStreamDefaultController(this)) {
|
|
2231
|
+
throw defaultControllerBrandCheckException$2('abortReason');
|
|
2232
|
+
}
|
|
2233
|
+
return this._abortReason;
|
|
2234
|
+
}
|
|
2235
|
+
/**
|
|
2236
|
+
* An `AbortSignal` that can be used to abort the pending write or close operation when the stream is aborted.
|
|
2237
|
+
*/
|
|
2238
|
+
get signal() {
|
|
2239
|
+
if (!IsWritableStreamDefaultController(this)) {
|
|
2240
|
+
throw defaultControllerBrandCheckException$2('signal');
|
|
2241
|
+
}
|
|
2242
|
+
if (this._abortController === undefined) {
|
|
2243
|
+
// Older browsers or older Node versions may not support `AbortController` or `AbortSignal`.
|
|
2244
|
+
// We don't want to bundle and ship an `AbortController` polyfill together with our polyfill,
|
|
2245
|
+
// so instead we only implement support for `signal` if we find a global `AbortController` constructor.
|
|
2246
|
+
throw new TypeError('WritableStreamDefaultController.prototype.signal is not supported');
|
|
2247
|
+
}
|
|
2248
|
+
return this._abortController.signal;
|
|
2249
|
+
}
|
|
2250
|
+
/**
|
|
2251
|
+
* Closes the controlled writable stream, making all future interactions with it fail with the given error `e`.
|
|
2252
|
+
*
|
|
2253
|
+
* This method is rarely used, since usually it suffices to return a rejected promise from one of the underlying
|
|
2254
|
+
* sink's methods. However, it can be useful for suddenly shutting down a stream in response to an event outside the
|
|
2255
|
+
* normal lifecycle of interactions with the underlying sink.
|
|
2256
|
+
*/
|
|
1988
2257
|
error(e = undefined) {
|
|
1989
2258
|
if (!IsWritableStreamDefaultController(this)) {
|
|
1990
|
-
throw
|
|
2259
|
+
throw defaultControllerBrandCheckException$2('error');
|
|
1991
2260
|
}
|
|
1992
2261
|
const state = this._controlledWritableStream._state;
|
|
1993
2262
|
if (state !== 'writable') {
|
|
@@ -2025,7 +2294,7 @@
|
|
|
2025
2294
|
if (!Object.prototype.hasOwnProperty.call(x, '_controlledWritableStream')) {
|
|
2026
2295
|
return false;
|
|
2027
2296
|
}
|
|
2028
|
-
return
|
|
2297
|
+
return x instanceof WritableStreamDefaultController;
|
|
2029
2298
|
}
|
|
2030
2299
|
function SetUpWritableStreamDefaultController(stream, controller, startAlgorithm, writeAlgorithm, closeAlgorithm, abortAlgorithm, highWaterMark, sizeAlgorithm) {
|
|
2031
2300
|
controller._controlledWritableStream = stream;
|
|
@@ -2034,6 +2303,8 @@
|
|
|
2034
2303
|
controller._queue = undefined;
|
|
2035
2304
|
controller._queueTotalSize = undefined;
|
|
2036
2305
|
ResetQueue(controller);
|
|
2306
|
+
controller._abortReason = undefined;
|
|
2307
|
+
controller._abortController = createAbortController();
|
|
2037
2308
|
controller._started = false;
|
|
2038
2309
|
controller._strategySizeAlgorithm = sizeAlgorithm;
|
|
2039
2310
|
controller._strategyHWM = highWaterMark;
|
|
@@ -2183,9 +2454,13 @@
|
|
|
2183
2454
|
WritableStreamStartErroring(stream, error);
|
|
2184
2455
|
}
|
|
2185
2456
|
// Helper functions for the WritableStream.
|
|
2186
|
-
function streamBrandCheckException(name) {
|
|
2457
|
+
function streamBrandCheckException$2(name) {
|
|
2187
2458
|
return new TypeError(`WritableStream.prototype.${name} can only be used on a WritableStream`);
|
|
2188
2459
|
}
|
|
2460
|
+
// Helper functions for the WritableStreamDefaultController.
|
|
2461
|
+
function defaultControllerBrandCheckException$2(name) {
|
|
2462
|
+
return new TypeError(`WritableStreamDefaultController.prototype.${name} can only be used on a WritableStreamDefaultController`);
|
|
2463
|
+
}
|
|
2189
2464
|
// Helper functions for the WritableStreamDefaultWriter.
|
|
2190
2465
|
function defaultWriterBrandCheckException(name) {
|
|
2191
2466
|
return new TypeError(`WritableStreamDefaultWriter.prototype.${name} can only be used on a WritableStreamDefaultWriter`);
|
|
@@ -2209,6 +2484,9 @@
|
|
|
2209
2484
|
defaultWriterClosedPromiseResolve(writer);
|
|
2210
2485
|
}
|
|
2211
2486
|
function defaultWriterClosedPromiseReject(writer, reason) {
|
|
2487
|
+
if (writer._closedPromise_reject === undefined) {
|
|
2488
|
+
return;
|
|
2489
|
+
}
|
|
2212
2490
|
setPromiseIsHandledToTrue(writer._closedPromise);
|
|
2213
2491
|
writer._closedPromise_reject(reason);
|
|
2214
2492
|
writer._closedPromise_resolve = undefined;
|
|
@@ -2219,6 +2497,9 @@
|
|
|
2219
2497
|
defaultWriterClosedPromiseInitializeAsRejected(writer, reason);
|
|
2220
2498
|
}
|
|
2221
2499
|
function defaultWriterClosedPromiseResolve(writer) {
|
|
2500
|
+
if (writer._closedPromise_resolve === undefined) {
|
|
2501
|
+
return;
|
|
2502
|
+
}
|
|
2222
2503
|
writer._closedPromise_resolve(undefined);
|
|
2223
2504
|
writer._closedPromise_resolve = undefined;
|
|
2224
2505
|
writer._closedPromise_reject = undefined;
|
|
@@ -2240,6 +2521,9 @@
|
|
|
2240
2521
|
defaultWriterReadyPromiseResolve(writer);
|
|
2241
2522
|
}
|
|
2242
2523
|
function defaultWriterReadyPromiseReject(writer, reason) {
|
|
2524
|
+
if (writer._readyPromise_reject === undefined) {
|
|
2525
|
+
return;
|
|
2526
|
+
}
|
|
2243
2527
|
setPromiseIsHandledToTrue(writer._readyPromise);
|
|
2244
2528
|
writer._readyPromise_reject(reason);
|
|
2245
2529
|
writer._readyPromise_resolve = undefined;
|
|
@@ -2253,25 +2537,15 @@
|
|
|
2253
2537
|
defaultWriterReadyPromiseInitializeAsRejected(writer, reason);
|
|
2254
2538
|
}
|
|
2255
2539
|
function defaultWriterReadyPromiseResolve(writer) {
|
|
2540
|
+
if (writer._readyPromise_resolve === undefined) {
|
|
2541
|
+
return;
|
|
2542
|
+
}
|
|
2256
2543
|
writer._readyPromise_resolve(undefined);
|
|
2257
2544
|
writer._readyPromise_resolve = undefined;
|
|
2258
2545
|
writer._readyPromise_reject = undefined;
|
|
2259
2546
|
writer._readyPromiseState = 'fulfilled';
|
|
2260
2547
|
}
|
|
2261
2548
|
|
|
2262
|
-
function isAbortSignal(value) {
|
|
2263
|
-
if (typeof value !== 'object' || value === null) {
|
|
2264
|
-
return false;
|
|
2265
|
-
}
|
|
2266
|
-
try {
|
|
2267
|
-
return typeof value.aborted === 'boolean';
|
|
2268
|
-
}
|
|
2269
|
-
catch (_a) {
|
|
2270
|
-
// AbortSignal.prototype.aborted throws if its brand check fails
|
|
2271
|
-
return false;
|
|
2272
|
-
}
|
|
2273
|
-
}
|
|
2274
|
-
|
|
2275
2549
|
/// <reference lib="dom" />
|
|
2276
2550
|
const NativeDOMException = typeof DOMException !== 'undefined' ? DOMException : undefined;
|
|
2277
2551
|
|
|
@@ -2289,6 +2563,7 @@
|
|
|
2289
2563
|
}
|
|
2290
2564
|
}
|
|
2291
2565
|
function createDOMExceptionPolyfill() {
|
|
2566
|
+
// eslint-disable-next-line no-shadow
|
|
2292
2567
|
const ctor = function DOMException(message, name) {
|
|
2293
2568
|
this.message = message || '';
|
|
2294
2569
|
this.name = name || 'Error';
|
|
@@ -2300,6 +2575,7 @@
|
|
|
2300
2575
|
Object.defineProperty(ctor.prototype, 'constructor', { value: ctor, writable: true, configurable: true });
|
|
2301
2576
|
return ctor;
|
|
2302
2577
|
}
|
|
2578
|
+
// eslint-disable-next-line no-redeclare
|
|
2303
2579
|
const DOMException$1 = isDOMExceptionConstructor(NativeDOMException) ? NativeDOMException : createDOMExceptionPolyfill();
|
|
2304
2580
|
|
|
2305
2581
|
function ReadableStreamPipeTo(source, dest, preventClose, preventAbort, preventCancel, signal) {
|
|
@@ -2477,19 +2753,32 @@
|
|
|
2477
2753
|
});
|
|
2478
2754
|
}
|
|
2479
2755
|
|
|
2756
|
+
/**
|
|
2757
|
+
* Allows control of a {@link ReadableStream | readable stream}'s state and internal queue.
|
|
2758
|
+
*
|
|
2759
|
+
* @public
|
|
2760
|
+
*/
|
|
2480
2761
|
class ReadableStreamDefaultController {
|
|
2481
2762
|
constructor() {
|
|
2482
2763
|
throw new TypeError('Illegal constructor');
|
|
2483
2764
|
}
|
|
2765
|
+
/**
|
|
2766
|
+
* Returns the desired size to fill the controlled stream's internal queue. It can be negative, if the queue is
|
|
2767
|
+
* over-full. An underlying source ought to use this information to determine when and how to apply backpressure.
|
|
2768
|
+
*/
|
|
2484
2769
|
get desiredSize() {
|
|
2485
2770
|
if (!IsReadableStreamDefaultController(this)) {
|
|
2486
|
-
throw defaultControllerBrandCheckException('desiredSize');
|
|
2771
|
+
throw defaultControllerBrandCheckException$1('desiredSize');
|
|
2487
2772
|
}
|
|
2488
2773
|
return ReadableStreamDefaultControllerGetDesiredSize(this);
|
|
2489
2774
|
}
|
|
2775
|
+
/**
|
|
2776
|
+
* Closes the controlled readable stream. Consumers will still be able to read any previously-enqueued chunks from
|
|
2777
|
+
* the stream, but once those are read, the stream will become closed.
|
|
2778
|
+
*/
|
|
2490
2779
|
close() {
|
|
2491
2780
|
if (!IsReadableStreamDefaultController(this)) {
|
|
2492
|
-
throw defaultControllerBrandCheckException('close');
|
|
2781
|
+
throw defaultControllerBrandCheckException$1('close');
|
|
2493
2782
|
}
|
|
2494
2783
|
if (!ReadableStreamDefaultControllerCanCloseOrEnqueue(this)) {
|
|
2495
2784
|
throw new TypeError('The stream is not in a state that permits close');
|
|
@@ -2498,16 +2787,19 @@
|
|
|
2498
2787
|
}
|
|
2499
2788
|
enqueue(chunk = undefined) {
|
|
2500
2789
|
if (!IsReadableStreamDefaultController(this)) {
|
|
2501
|
-
throw defaultControllerBrandCheckException('enqueue');
|
|
2790
|
+
throw defaultControllerBrandCheckException$1('enqueue');
|
|
2502
2791
|
}
|
|
2503
2792
|
if (!ReadableStreamDefaultControllerCanCloseOrEnqueue(this)) {
|
|
2504
2793
|
throw new TypeError('The stream is not in a state that permits enqueue');
|
|
2505
2794
|
}
|
|
2506
2795
|
return ReadableStreamDefaultControllerEnqueue(this, chunk);
|
|
2507
2796
|
}
|
|
2797
|
+
/**
|
|
2798
|
+
* Errors the controlled readable stream, making all future interactions with it fail with the given error `e`.
|
|
2799
|
+
*/
|
|
2508
2800
|
error(e = undefined) {
|
|
2509
2801
|
if (!IsReadableStreamDefaultController(this)) {
|
|
2510
|
-
throw defaultControllerBrandCheckException('error');
|
|
2802
|
+
throw defaultControllerBrandCheckException$1('error');
|
|
2511
2803
|
}
|
|
2512
2804
|
ReadableStreamDefaultControllerError(this, e);
|
|
2513
2805
|
}
|
|
@@ -2558,7 +2850,7 @@
|
|
|
2558
2850
|
if (!Object.prototype.hasOwnProperty.call(x, '_controlledReadableStream')) {
|
|
2559
2851
|
return false;
|
|
2560
2852
|
}
|
|
2561
|
-
return
|
|
2853
|
+
return x instanceof ReadableStreamDefaultController;
|
|
2562
2854
|
}
|
|
2563
2855
|
function ReadableStreamDefaultControllerCallPullIfNeeded(controller) {
|
|
2564
2856
|
const shouldPull = ReadableStreamDefaultControllerShouldCallPull(controller);
|
|
@@ -2652,8 +2944,7 @@
|
|
|
2652
2944
|
ReadableStreamError(stream, e);
|
|
2653
2945
|
}
|
|
2654
2946
|
function ReadableStreamDefaultControllerGetDesiredSize(controller) {
|
|
2655
|
-
const
|
|
2656
|
-
const state = stream._state;
|
|
2947
|
+
const state = controller._controlledReadableStream._state;
|
|
2657
2948
|
if (state === 'errored') {
|
|
2658
2949
|
return null;
|
|
2659
2950
|
}
|
|
@@ -2715,11 +3006,17 @@
|
|
|
2715
3006
|
SetUpReadableStreamDefaultController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, sizeAlgorithm);
|
|
2716
3007
|
}
|
|
2717
3008
|
// Helper functions for the ReadableStreamDefaultController.
|
|
2718
|
-
function defaultControllerBrandCheckException(name) {
|
|
3009
|
+
function defaultControllerBrandCheckException$1(name) {
|
|
2719
3010
|
return new TypeError(`ReadableStreamDefaultController.prototype.${name} can only be used on a ReadableStreamDefaultController`);
|
|
2720
3011
|
}
|
|
2721
3012
|
|
|
2722
3013
|
function ReadableStreamTee(stream, cloneForBranch2) {
|
|
3014
|
+
if (IsReadableByteStreamController(stream._readableStreamController)) {
|
|
3015
|
+
return ReadableByteStreamTee(stream);
|
|
3016
|
+
}
|
|
3017
|
+
return ReadableStreamDefaultTee(stream);
|
|
3018
|
+
}
|
|
3019
|
+
function ReadableStreamDefaultTee(stream, cloneForBranch2) {
|
|
2723
3020
|
const reader = AcquireReadableStreamDefaultReader(stream);
|
|
2724
3021
|
let reading = false;
|
|
2725
3022
|
let canceled1 = false;
|
|
@@ -2738,24 +3035,24 @@
|
|
|
2738
3035
|
}
|
|
2739
3036
|
reading = true;
|
|
2740
3037
|
const readRequest = {
|
|
2741
|
-
_chunkSteps:
|
|
3038
|
+
_chunkSteps: chunk => {
|
|
2742
3039
|
// This needs to be delayed a microtask because it takes at least a microtask to detect errors (using
|
|
2743
3040
|
// reader._closedPromise below), and we want errors in stream to error both branches immediately. We cannot let
|
|
2744
3041
|
// successful synchronously-available reads get ahead of asynchronously-available errors.
|
|
2745
3042
|
queueMicrotask(() => {
|
|
2746
3043
|
reading = false;
|
|
2747
|
-
const
|
|
2748
|
-
const
|
|
3044
|
+
const chunk1 = chunk;
|
|
3045
|
+
const chunk2 = chunk;
|
|
2749
3046
|
// There is no way to access the cloning code right now in the reference implementation.
|
|
2750
3047
|
// If we add one then we'll need an implementation for serializable objects.
|
|
2751
3048
|
// if (!canceled2 && cloneForBranch2) {
|
|
2752
|
-
//
|
|
3049
|
+
// chunk2 = StructuredDeserialize(StructuredSerialize(chunk2));
|
|
2753
3050
|
// }
|
|
2754
3051
|
if (!canceled1) {
|
|
2755
|
-
ReadableStreamDefaultControllerEnqueue(branch1._readableStreamController,
|
|
3052
|
+
ReadableStreamDefaultControllerEnqueue(branch1._readableStreamController, chunk1);
|
|
2756
3053
|
}
|
|
2757
3054
|
if (!canceled2) {
|
|
2758
|
-
ReadableStreamDefaultControllerEnqueue(branch2._readableStreamController,
|
|
3055
|
+
ReadableStreamDefaultControllerEnqueue(branch2._readableStreamController, chunk2);
|
|
2759
3056
|
}
|
|
2760
3057
|
});
|
|
2761
3058
|
},
|
|
@@ -2767,6 +3064,9 @@
|
|
|
2767
3064
|
if (!canceled2) {
|
|
2768
3065
|
ReadableStreamDefaultControllerClose(branch2._readableStreamController);
|
|
2769
3066
|
}
|
|
3067
|
+
if (!canceled1 || !canceled2) {
|
|
3068
|
+
resolveCancelPromise(undefined);
|
|
3069
|
+
}
|
|
2770
3070
|
},
|
|
2771
3071
|
_errorSteps: () => {
|
|
2772
3072
|
reading = false;
|
|
@@ -2803,9 +3103,217 @@
|
|
|
2803
3103
|
uponRejection(reader._closedPromise, (r) => {
|
|
2804
3104
|
ReadableStreamDefaultControllerError(branch1._readableStreamController, r);
|
|
2805
3105
|
ReadableStreamDefaultControllerError(branch2._readableStreamController, r);
|
|
3106
|
+
if (!canceled1 || !canceled2) {
|
|
3107
|
+
resolveCancelPromise(undefined);
|
|
3108
|
+
}
|
|
2806
3109
|
});
|
|
2807
3110
|
return [branch1, branch2];
|
|
2808
3111
|
}
|
|
3112
|
+
function ReadableByteStreamTee(stream) {
|
|
3113
|
+
let reader = AcquireReadableStreamDefaultReader(stream);
|
|
3114
|
+
let reading = false;
|
|
3115
|
+
let canceled1 = false;
|
|
3116
|
+
let canceled2 = false;
|
|
3117
|
+
let reason1;
|
|
3118
|
+
let reason2;
|
|
3119
|
+
let branch1;
|
|
3120
|
+
let branch2;
|
|
3121
|
+
let resolveCancelPromise;
|
|
3122
|
+
const cancelPromise = newPromise(resolve => {
|
|
3123
|
+
resolveCancelPromise = resolve;
|
|
3124
|
+
});
|
|
3125
|
+
function forwardReaderError(thisReader) {
|
|
3126
|
+
uponRejection(thisReader._closedPromise, r => {
|
|
3127
|
+
if (thisReader !== reader) {
|
|
3128
|
+
return;
|
|
3129
|
+
}
|
|
3130
|
+
ReadableByteStreamControllerError(branch1._readableStreamController, r);
|
|
3131
|
+
ReadableByteStreamControllerError(branch2._readableStreamController, r);
|
|
3132
|
+
if (!canceled1 || !canceled2) {
|
|
3133
|
+
resolveCancelPromise(undefined);
|
|
3134
|
+
}
|
|
3135
|
+
});
|
|
3136
|
+
}
|
|
3137
|
+
function pullWithDefaultReader() {
|
|
3138
|
+
if (IsReadableStreamBYOBReader(reader)) {
|
|
3139
|
+
ReadableStreamReaderGenericRelease(reader);
|
|
3140
|
+
reader = AcquireReadableStreamDefaultReader(stream);
|
|
3141
|
+
forwardReaderError(reader);
|
|
3142
|
+
}
|
|
3143
|
+
const readRequest = {
|
|
3144
|
+
_chunkSteps: chunk => {
|
|
3145
|
+
// This needs to be delayed a microtask because it takes at least a microtask to detect errors (using
|
|
3146
|
+
// reader._closedPromise below), and we want errors in stream to error both branches immediately. We cannot let
|
|
3147
|
+
// successful synchronously-available reads get ahead of asynchronously-available errors.
|
|
3148
|
+
queueMicrotask(() => {
|
|
3149
|
+
reading = false;
|
|
3150
|
+
const chunk1 = chunk;
|
|
3151
|
+
let chunk2 = chunk;
|
|
3152
|
+
if (!canceled1 && !canceled2) {
|
|
3153
|
+
try {
|
|
3154
|
+
chunk2 = CloneAsUint8Array(chunk);
|
|
3155
|
+
}
|
|
3156
|
+
catch (cloneE) {
|
|
3157
|
+
ReadableByteStreamControllerError(branch1._readableStreamController, cloneE);
|
|
3158
|
+
ReadableByteStreamControllerError(branch2._readableStreamController, cloneE);
|
|
3159
|
+
resolveCancelPromise(ReadableStreamCancel(stream, cloneE));
|
|
3160
|
+
return;
|
|
3161
|
+
}
|
|
3162
|
+
}
|
|
3163
|
+
if (!canceled1) {
|
|
3164
|
+
ReadableByteStreamControllerEnqueue(branch1._readableStreamController, chunk1);
|
|
3165
|
+
}
|
|
3166
|
+
if (!canceled2) {
|
|
3167
|
+
ReadableByteStreamControllerEnqueue(branch2._readableStreamController, chunk2);
|
|
3168
|
+
}
|
|
3169
|
+
});
|
|
3170
|
+
},
|
|
3171
|
+
_closeSteps: () => {
|
|
3172
|
+
reading = false;
|
|
3173
|
+
if (!canceled1) {
|
|
3174
|
+
ReadableByteStreamControllerClose(branch1._readableStreamController);
|
|
3175
|
+
}
|
|
3176
|
+
if (!canceled2) {
|
|
3177
|
+
ReadableByteStreamControllerClose(branch2._readableStreamController);
|
|
3178
|
+
}
|
|
3179
|
+
if (branch1._readableStreamController._pendingPullIntos.length > 0) {
|
|
3180
|
+
ReadableByteStreamControllerRespond(branch1._readableStreamController, 0);
|
|
3181
|
+
}
|
|
3182
|
+
if (branch2._readableStreamController._pendingPullIntos.length > 0) {
|
|
3183
|
+
ReadableByteStreamControllerRespond(branch2._readableStreamController, 0);
|
|
3184
|
+
}
|
|
3185
|
+
if (!canceled1 || !canceled2) {
|
|
3186
|
+
resolveCancelPromise(undefined);
|
|
3187
|
+
}
|
|
3188
|
+
},
|
|
3189
|
+
_errorSteps: () => {
|
|
3190
|
+
reading = false;
|
|
3191
|
+
}
|
|
3192
|
+
};
|
|
3193
|
+
ReadableStreamDefaultReaderRead(reader, readRequest);
|
|
3194
|
+
}
|
|
3195
|
+
function pullWithBYOBReader(view, forBranch2) {
|
|
3196
|
+
if (IsReadableStreamDefaultReader(reader)) {
|
|
3197
|
+
ReadableStreamReaderGenericRelease(reader);
|
|
3198
|
+
reader = AcquireReadableStreamBYOBReader(stream);
|
|
3199
|
+
forwardReaderError(reader);
|
|
3200
|
+
}
|
|
3201
|
+
const byobBranch = forBranch2 ? branch2 : branch1;
|
|
3202
|
+
const otherBranch = forBranch2 ? branch1 : branch2;
|
|
3203
|
+
const readIntoRequest = {
|
|
3204
|
+
_chunkSteps: chunk => {
|
|
3205
|
+
// This needs to be delayed a microtask because it takes at least a microtask to detect errors (using
|
|
3206
|
+
// reader._closedPromise below), and we want errors in stream to error both branches immediately. We cannot let
|
|
3207
|
+
// successful synchronously-available reads get ahead of asynchronously-available errors.
|
|
3208
|
+
queueMicrotask(() => {
|
|
3209
|
+
reading = false;
|
|
3210
|
+
const byobCanceled = forBranch2 ? canceled2 : canceled1;
|
|
3211
|
+
const otherCanceled = forBranch2 ? canceled1 : canceled2;
|
|
3212
|
+
if (!otherCanceled) {
|
|
3213
|
+
let clonedChunk;
|
|
3214
|
+
try {
|
|
3215
|
+
clonedChunk = CloneAsUint8Array(chunk);
|
|
3216
|
+
}
|
|
3217
|
+
catch (cloneE) {
|
|
3218
|
+
ReadableByteStreamControllerError(byobBranch._readableStreamController, cloneE);
|
|
3219
|
+
ReadableByteStreamControllerError(otherBranch._readableStreamController, cloneE);
|
|
3220
|
+
resolveCancelPromise(ReadableStreamCancel(stream, cloneE));
|
|
3221
|
+
return;
|
|
3222
|
+
}
|
|
3223
|
+
if (!byobCanceled) {
|
|
3224
|
+
ReadableByteStreamControllerRespondWithNewView(byobBranch._readableStreamController, chunk);
|
|
3225
|
+
}
|
|
3226
|
+
ReadableByteStreamControllerEnqueue(otherBranch._readableStreamController, clonedChunk);
|
|
3227
|
+
}
|
|
3228
|
+
else if (!byobCanceled) {
|
|
3229
|
+
ReadableByteStreamControllerRespondWithNewView(byobBranch._readableStreamController, chunk);
|
|
3230
|
+
}
|
|
3231
|
+
});
|
|
3232
|
+
},
|
|
3233
|
+
_closeSteps: chunk => {
|
|
3234
|
+
reading = false;
|
|
3235
|
+
const byobCanceled = forBranch2 ? canceled2 : canceled1;
|
|
3236
|
+
const otherCanceled = forBranch2 ? canceled1 : canceled2;
|
|
3237
|
+
if (!byobCanceled) {
|
|
3238
|
+
ReadableByteStreamControllerClose(byobBranch._readableStreamController);
|
|
3239
|
+
}
|
|
3240
|
+
if (!otherCanceled) {
|
|
3241
|
+
ReadableByteStreamControllerClose(otherBranch._readableStreamController);
|
|
3242
|
+
}
|
|
3243
|
+
if (chunk !== undefined) {
|
|
3244
|
+
if (!byobCanceled) {
|
|
3245
|
+
ReadableByteStreamControllerRespondWithNewView(byobBranch._readableStreamController, chunk);
|
|
3246
|
+
}
|
|
3247
|
+
if (!otherCanceled && otherBranch._readableStreamController._pendingPullIntos.length > 0) {
|
|
3248
|
+
ReadableByteStreamControllerRespond(otherBranch._readableStreamController, 0);
|
|
3249
|
+
}
|
|
3250
|
+
}
|
|
3251
|
+
if (!byobCanceled || !otherCanceled) {
|
|
3252
|
+
resolveCancelPromise(undefined);
|
|
3253
|
+
}
|
|
3254
|
+
},
|
|
3255
|
+
_errorSteps: () => {
|
|
3256
|
+
reading = false;
|
|
3257
|
+
}
|
|
3258
|
+
};
|
|
3259
|
+
ReadableStreamBYOBReaderRead(reader, view, readIntoRequest);
|
|
3260
|
+
}
|
|
3261
|
+
function pull1Algorithm() {
|
|
3262
|
+
if (reading) {
|
|
3263
|
+
return promiseResolvedWith(undefined);
|
|
3264
|
+
}
|
|
3265
|
+
reading = true;
|
|
3266
|
+
const byobRequest = ReadableByteStreamControllerGetBYOBRequest(branch1._readableStreamController);
|
|
3267
|
+
if (byobRequest === null) {
|
|
3268
|
+
pullWithDefaultReader();
|
|
3269
|
+
}
|
|
3270
|
+
else {
|
|
3271
|
+
pullWithBYOBReader(byobRequest._view, false);
|
|
3272
|
+
}
|
|
3273
|
+
return promiseResolvedWith(undefined);
|
|
3274
|
+
}
|
|
3275
|
+
function pull2Algorithm() {
|
|
3276
|
+
if (reading) {
|
|
3277
|
+
return promiseResolvedWith(undefined);
|
|
3278
|
+
}
|
|
3279
|
+
reading = true;
|
|
3280
|
+
const byobRequest = ReadableByteStreamControllerGetBYOBRequest(branch2._readableStreamController);
|
|
3281
|
+
if (byobRequest === null) {
|
|
3282
|
+
pullWithDefaultReader();
|
|
3283
|
+
}
|
|
3284
|
+
else {
|
|
3285
|
+
pullWithBYOBReader(byobRequest._view, true);
|
|
3286
|
+
}
|
|
3287
|
+
return promiseResolvedWith(undefined);
|
|
3288
|
+
}
|
|
3289
|
+
function cancel1Algorithm(reason) {
|
|
3290
|
+
canceled1 = true;
|
|
3291
|
+
reason1 = reason;
|
|
3292
|
+
if (canceled2) {
|
|
3293
|
+
const compositeReason = CreateArrayFromList([reason1, reason2]);
|
|
3294
|
+
const cancelResult = ReadableStreamCancel(stream, compositeReason);
|
|
3295
|
+
resolveCancelPromise(cancelResult);
|
|
3296
|
+
}
|
|
3297
|
+
return cancelPromise;
|
|
3298
|
+
}
|
|
3299
|
+
function cancel2Algorithm(reason) {
|
|
3300
|
+
canceled2 = true;
|
|
3301
|
+
reason2 = reason;
|
|
3302
|
+
if (canceled1) {
|
|
3303
|
+
const compositeReason = CreateArrayFromList([reason1, reason2]);
|
|
3304
|
+
const cancelResult = ReadableStreamCancel(stream, compositeReason);
|
|
3305
|
+
resolveCancelPromise(cancelResult);
|
|
3306
|
+
}
|
|
3307
|
+
return cancelPromise;
|
|
3308
|
+
}
|
|
3309
|
+
function startAlgorithm() {
|
|
3310
|
+
return;
|
|
3311
|
+
}
|
|
3312
|
+
branch1 = CreateReadableByteStream(startAlgorithm, pull1Algorithm, cancel1Algorithm);
|
|
3313
|
+
branch2 = CreateReadableByteStream(startAlgorithm, pull2Algorithm, cancel2Algorithm);
|
|
3314
|
+
forwardReaderError(reader);
|
|
3315
|
+
return [branch1, branch2];
|
|
3316
|
+
}
|
|
2809
3317
|
|
|
2810
3318
|
function convertUnderlyingDefaultOrByteSource(source, context) {
|
|
2811
3319
|
assertDictionary(source, context);
|
|
@@ -2905,6 +3413,11 @@
|
|
|
2905
3413
|
return { readable, writable };
|
|
2906
3414
|
}
|
|
2907
3415
|
|
|
3416
|
+
/**
|
|
3417
|
+
* A readable stream represents a source of data, from which you can read.
|
|
3418
|
+
*
|
|
3419
|
+
* @public
|
|
3420
|
+
*/
|
|
2908
3421
|
class ReadableStream {
|
|
2909
3422
|
constructor(rawUnderlyingSource = {}, rawStrategy = {}) {
|
|
2910
3423
|
if (rawUnderlyingSource === undefined) {
|
|
@@ -2929,12 +3442,21 @@
|
|
|
2929
3442
|
SetUpReadableStreamDefaultControllerFromUnderlyingSource(this, underlyingSource, highWaterMark, sizeAlgorithm);
|
|
2930
3443
|
}
|
|
2931
3444
|
}
|
|
3445
|
+
/**
|
|
3446
|
+
* Whether or not the readable stream is locked to a {@link ReadableStreamDefaultReader | reader}.
|
|
3447
|
+
*/
|
|
2932
3448
|
get locked() {
|
|
2933
3449
|
if (!IsReadableStream(this)) {
|
|
2934
3450
|
throw streamBrandCheckException$1('locked');
|
|
2935
3451
|
}
|
|
2936
3452
|
return IsReadableStreamLocked(this);
|
|
2937
3453
|
}
|
|
3454
|
+
/**
|
|
3455
|
+
* Cancels the stream, signaling a loss of interest in the stream by a consumer.
|
|
3456
|
+
*
|
|
3457
|
+
* The supplied `reason` argument will be given to the underlying source's {@link UnderlyingSource.cancel | cancel()}
|
|
3458
|
+
* method, which might or might not use it.
|
|
3459
|
+
*/
|
|
2938
3460
|
cancel(reason = undefined) {
|
|
2939
3461
|
if (!IsReadableStream(this)) {
|
|
2940
3462
|
return promiseRejectedWith(streamBrandCheckException$1('cancel'));
|
|
@@ -2996,6 +3518,17 @@
|
|
|
2996
3518
|
}
|
|
2997
3519
|
return ReadableStreamPipeTo(this, destination, options.preventClose, options.preventAbort, options.preventCancel, options.signal);
|
|
2998
3520
|
}
|
|
3521
|
+
/**
|
|
3522
|
+
* Tees this readable stream, returning a two-element array containing the two resulting branches as
|
|
3523
|
+
* new {@link ReadableStream} instances.
|
|
3524
|
+
*
|
|
3525
|
+
* Teeing a stream will lock it, preventing any other consumer from acquiring a reader.
|
|
3526
|
+
* To cancel the stream, cancel both of the resulting branches; a composite cancellation reason will then be
|
|
3527
|
+
* propagated to the stream's underlying source.
|
|
3528
|
+
*
|
|
3529
|
+
* Note that the chunks seen in each branch will be the same object. If the chunks are not immutable,
|
|
3530
|
+
* this could allow interference between the two branches.
|
|
3531
|
+
*/
|
|
2999
3532
|
tee() {
|
|
3000
3533
|
if (!IsReadableStream(this)) {
|
|
3001
3534
|
throw streamBrandCheckException$1('tee');
|
|
@@ -3042,6 +3575,14 @@
|
|
|
3042
3575
|
SetUpReadableStreamDefaultController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, sizeAlgorithm);
|
|
3043
3576
|
return stream;
|
|
3044
3577
|
}
|
|
3578
|
+
// Throws if and only if startAlgorithm throws.
|
|
3579
|
+
function CreateReadableByteStream(startAlgorithm, pullAlgorithm, cancelAlgorithm) {
|
|
3580
|
+
const stream = Object.create(ReadableStream.prototype);
|
|
3581
|
+
InitializeReadableStream(stream);
|
|
3582
|
+
const controller = Object.create(ReadableByteStreamController.prototype);
|
|
3583
|
+
SetUpReadableByteStreamController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, 0, undefined);
|
|
3584
|
+
return stream;
|
|
3585
|
+
}
|
|
3045
3586
|
function InitializeReadableStream(stream) {
|
|
3046
3587
|
stream._state = 'readable';
|
|
3047
3588
|
stream._reader = undefined;
|
|
@@ -3055,7 +3596,7 @@
|
|
|
3055
3596
|
if (!Object.prototype.hasOwnProperty.call(x, '_readableStreamController')) {
|
|
3056
3597
|
return false;
|
|
3057
3598
|
}
|
|
3058
|
-
return
|
|
3599
|
+
return x instanceof ReadableStream;
|
|
3059
3600
|
}
|
|
3060
3601
|
function IsReadableStreamLocked(stream) {
|
|
3061
3602
|
if (stream._reader === undefined) {
|
|
@@ -3073,6 +3614,13 @@
|
|
|
3073
3614
|
return promiseRejectedWith(stream._storedError);
|
|
3074
3615
|
}
|
|
3075
3616
|
ReadableStreamClose(stream);
|
|
3617
|
+
const reader = stream._reader;
|
|
3618
|
+
if (reader !== undefined && IsReadableStreamBYOBReader(reader)) {
|
|
3619
|
+
reader._readIntoRequests.forEach(readIntoRequest => {
|
|
3620
|
+
readIntoRequest._closeSteps(undefined);
|
|
3621
|
+
});
|
|
3622
|
+
reader._readIntoRequests = new SimpleQueue();
|
|
3623
|
+
}
|
|
3076
3624
|
const sourceCancelPromise = stream._readableStreamController[CancelSteps](reason);
|
|
3077
3625
|
return transformPromiseWith(sourceCancelPromise, noop);
|
|
3078
3626
|
}
|
|
@@ -3082,13 +3630,13 @@
|
|
|
3082
3630
|
if (reader === undefined) {
|
|
3083
3631
|
return;
|
|
3084
3632
|
}
|
|
3633
|
+
defaultReaderClosedPromiseResolve(reader);
|
|
3085
3634
|
if (IsReadableStreamDefaultReader(reader)) {
|
|
3086
3635
|
reader._readRequests.forEach(readRequest => {
|
|
3087
3636
|
readRequest._closeSteps();
|
|
3088
3637
|
});
|
|
3089
3638
|
reader._readRequests = new SimpleQueue();
|
|
3090
3639
|
}
|
|
3091
|
-
defaultReaderClosedPromiseResolve(reader);
|
|
3092
3640
|
}
|
|
3093
3641
|
function ReadableStreamError(stream, e) {
|
|
3094
3642
|
stream._state = 'errored';
|
|
@@ -3097,6 +3645,7 @@
|
|
|
3097
3645
|
if (reader === undefined) {
|
|
3098
3646
|
return;
|
|
3099
3647
|
}
|
|
3648
|
+
defaultReaderClosedPromiseReject(reader, e);
|
|
3100
3649
|
if (IsReadableStreamDefaultReader(reader)) {
|
|
3101
3650
|
reader._readRequests.forEach(readRequest => {
|
|
3102
3651
|
readRequest._errorSteps(e);
|
|
@@ -3109,7 +3658,6 @@
|
|
|
3109
3658
|
});
|
|
3110
3659
|
reader._readIntoRequests = new SimpleQueue();
|
|
3111
3660
|
}
|
|
3112
|
-
defaultReaderClosedPromiseReject(reader, e);
|
|
3113
3661
|
}
|
|
3114
3662
|
// Helper functions for the ReadableStream.
|
|
3115
3663
|
function streamBrandCheckException$1(name) {
|
|
@@ -3125,21 +3673,37 @@
|
|
|
3125
3673
|
};
|
|
3126
3674
|
}
|
|
3127
3675
|
|
|
3128
|
-
|
|
3676
|
+
// The size function must not have a prototype property nor be a constructor
|
|
3677
|
+
const byteLengthSizeFunction = (chunk) => {
|
|
3129
3678
|
return chunk.byteLength;
|
|
3130
3679
|
};
|
|
3680
|
+
Object.defineProperty(byteLengthSizeFunction, 'name', {
|
|
3681
|
+
value: 'size',
|
|
3682
|
+
configurable: true
|
|
3683
|
+
});
|
|
3684
|
+
/**
|
|
3685
|
+
* A queuing strategy that counts the number of bytes in each chunk.
|
|
3686
|
+
*
|
|
3687
|
+
* @public
|
|
3688
|
+
*/
|
|
3131
3689
|
class ByteLengthQueuingStrategy {
|
|
3132
3690
|
constructor(options) {
|
|
3133
3691
|
assertRequiredArgument(options, 1, 'ByteLengthQueuingStrategy');
|
|
3134
3692
|
options = convertQueuingStrategyInit(options, 'First parameter');
|
|
3135
3693
|
this._byteLengthQueuingStrategyHighWaterMark = options.highWaterMark;
|
|
3136
3694
|
}
|
|
3695
|
+
/**
|
|
3696
|
+
* Returns the high water mark provided to the constructor.
|
|
3697
|
+
*/
|
|
3137
3698
|
get highWaterMark() {
|
|
3138
3699
|
if (!IsByteLengthQueuingStrategy(this)) {
|
|
3139
3700
|
throw byteLengthBrandCheckException('highWaterMark');
|
|
3140
3701
|
}
|
|
3141
3702
|
return this._byteLengthQueuingStrategyHighWaterMark;
|
|
3142
3703
|
}
|
|
3704
|
+
/**
|
|
3705
|
+
* Measures the size of `chunk` by returning the value of its `byteLength` property.
|
|
3706
|
+
*/
|
|
3143
3707
|
get size() {
|
|
3144
3708
|
if (!IsByteLengthQueuingStrategy(this)) {
|
|
3145
3709
|
throw byteLengthBrandCheckException('size');
|
|
@@ -3168,24 +3732,41 @@
|
|
|
3168
3732
|
if (!Object.prototype.hasOwnProperty.call(x, '_byteLengthQueuingStrategyHighWaterMark')) {
|
|
3169
3733
|
return false;
|
|
3170
3734
|
}
|
|
3171
|
-
return
|
|
3735
|
+
return x instanceof ByteLengthQueuingStrategy;
|
|
3172
3736
|
}
|
|
3173
3737
|
|
|
3174
|
-
|
|
3738
|
+
// The size function must not have a prototype property nor be a constructor
|
|
3739
|
+
const countSizeFunction = () => {
|
|
3175
3740
|
return 1;
|
|
3176
3741
|
};
|
|
3742
|
+
Object.defineProperty(countSizeFunction, 'name', {
|
|
3743
|
+
value: 'size',
|
|
3744
|
+
configurable: true
|
|
3745
|
+
});
|
|
3746
|
+
/**
|
|
3747
|
+
* A queuing strategy that counts the number of chunks.
|
|
3748
|
+
*
|
|
3749
|
+
* @public
|
|
3750
|
+
*/
|
|
3177
3751
|
class CountQueuingStrategy {
|
|
3178
3752
|
constructor(options) {
|
|
3179
3753
|
assertRequiredArgument(options, 1, 'CountQueuingStrategy');
|
|
3180
3754
|
options = convertQueuingStrategyInit(options, 'First parameter');
|
|
3181
3755
|
this._countQueuingStrategyHighWaterMark = options.highWaterMark;
|
|
3182
3756
|
}
|
|
3757
|
+
/**
|
|
3758
|
+
* Returns the high water mark provided to the constructor.
|
|
3759
|
+
*/
|
|
3183
3760
|
get highWaterMark() {
|
|
3184
3761
|
if (!IsCountQueuingStrategy(this)) {
|
|
3185
3762
|
throw countBrandCheckException('highWaterMark');
|
|
3186
3763
|
}
|
|
3187
3764
|
return this._countQueuingStrategyHighWaterMark;
|
|
3188
3765
|
}
|
|
3766
|
+
/**
|
|
3767
|
+
* Measures the size of `chunk` by always returning 1.
|
|
3768
|
+
* This ensures that the total queue size is a count of the number of chunks in the queue.
|
|
3769
|
+
*/
|
|
3189
3770
|
get size() {
|
|
3190
3771
|
if (!IsCountQueuingStrategy(this)) {
|
|
3191
3772
|
throw countBrandCheckException('size');
|
|
@@ -3214,7 +3795,7 @@
|
|
|
3214
3795
|
if (!Object.prototype.hasOwnProperty.call(x, '_countQueuingStrategyHighWaterMark')) {
|
|
3215
3796
|
return false;
|
|
3216
3797
|
}
|
|
3217
|
-
return
|
|
3798
|
+
return x instanceof CountQueuingStrategy;
|
|
3218
3799
|
}
|
|
3219
3800
|
|
|
3220
3801
|
function convertTransformer(original, context) {
|
|
@@ -3252,6 +3833,14 @@
|
|
|
3252
3833
|
}
|
|
3253
3834
|
|
|
3254
3835
|
// Class TransformStream
|
|
3836
|
+
/**
|
|
3837
|
+
* A transform stream consists of a pair of streams: a {@link WritableStream | writable stream},
|
|
3838
|
+
* known as its writable side, and a {@link ReadableStream | readable stream}, known as its readable side.
|
|
3839
|
+
* In a manner specific to the transform stream in question, writes to the writable side result in new data being
|
|
3840
|
+
* made available for reading from the readable side.
|
|
3841
|
+
*
|
|
3842
|
+
* @public
|
|
3843
|
+
*/
|
|
3255
3844
|
class TransformStream {
|
|
3256
3845
|
constructor(rawTransformer = {}, rawWritableStrategy = {}, rawReadableStrategy = {}) {
|
|
3257
3846
|
if (rawTransformer === undefined) {
|
|
@@ -3283,15 +3872,21 @@
|
|
|
3283
3872
|
startPromise_resolve(undefined);
|
|
3284
3873
|
}
|
|
3285
3874
|
}
|
|
3875
|
+
/**
|
|
3876
|
+
* The readable side of the transform stream.
|
|
3877
|
+
*/
|
|
3286
3878
|
get readable() {
|
|
3287
3879
|
if (!IsTransformStream(this)) {
|
|
3288
|
-
throw streamBrandCheckException
|
|
3880
|
+
throw streamBrandCheckException('readable');
|
|
3289
3881
|
}
|
|
3290
3882
|
return this._readable;
|
|
3291
3883
|
}
|
|
3884
|
+
/**
|
|
3885
|
+
* The writable side of the transform stream.
|
|
3886
|
+
*/
|
|
3292
3887
|
get writable() {
|
|
3293
3888
|
if (!IsTransformStream(this)) {
|
|
3294
|
-
throw streamBrandCheckException
|
|
3889
|
+
throw streamBrandCheckException('writable');
|
|
3295
3890
|
}
|
|
3296
3891
|
return this._writable;
|
|
3297
3892
|
}
|
|
@@ -3342,7 +3937,7 @@
|
|
|
3342
3937
|
if (!Object.prototype.hasOwnProperty.call(x, '_transformStreamController')) {
|
|
3343
3938
|
return false;
|
|
3344
3939
|
}
|
|
3345
|
-
return
|
|
3940
|
+
return x instanceof TransformStream;
|
|
3346
3941
|
}
|
|
3347
3942
|
// This is a no-op if both sides are already errored.
|
|
3348
3943
|
function TransformStreamError(stream, e) {
|
|
@@ -3370,32 +3965,48 @@
|
|
|
3370
3965
|
stream._backpressure = backpressure;
|
|
3371
3966
|
}
|
|
3372
3967
|
// Class TransformStreamDefaultController
|
|
3968
|
+
/**
|
|
3969
|
+
* Allows control of the {@link ReadableStream} and {@link WritableStream} of the associated {@link TransformStream}.
|
|
3970
|
+
*
|
|
3971
|
+
* @public
|
|
3972
|
+
*/
|
|
3373
3973
|
class TransformStreamDefaultController {
|
|
3374
3974
|
constructor() {
|
|
3375
3975
|
throw new TypeError('Illegal constructor');
|
|
3376
3976
|
}
|
|
3977
|
+
/**
|
|
3978
|
+
* Returns the desired size to fill the readable side’s internal queue. It can be negative, if the queue is over-full.
|
|
3979
|
+
*/
|
|
3377
3980
|
get desiredSize() {
|
|
3378
3981
|
if (!IsTransformStreamDefaultController(this)) {
|
|
3379
|
-
throw defaultControllerBrandCheckException
|
|
3982
|
+
throw defaultControllerBrandCheckException('desiredSize');
|
|
3380
3983
|
}
|
|
3381
3984
|
const readableController = this._controlledTransformStream._readable._readableStreamController;
|
|
3382
3985
|
return ReadableStreamDefaultControllerGetDesiredSize(readableController);
|
|
3383
3986
|
}
|
|
3384
3987
|
enqueue(chunk = undefined) {
|
|
3385
3988
|
if (!IsTransformStreamDefaultController(this)) {
|
|
3386
|
-
throw defaultControllerBrandCheckException
|
|
3989
|
+
throw defaultControllerBrandCheckException('enqueue');
|
|
3387
3990
|
}
|
|
3388
3991
|
TransformStreamDefaultControllerEnqueue(this, chunk);
|
|
3389
3992
|
}
|
|
3993
|
+
/**
|
|
3994
|
+
* Errors both the readable side and the writable side of the controlled transform stream, making all future
|
|
3995
|
+
* interactions with it fail with the given error `e`. Any chunks queued for transformation will be discarded.
|
|
3996
|
+
*/
|
|
3390
3997
|
error(reason = undefined) {
|
|
3391
3998
|
if (!IsTransformStreamDefaultController(this)) {
|
|
3392
|
-
throw defaultControllerBrandCheckException
|
|
3999
|
+
throw defaultControllerBrandCheckException('error');
|
|
3393
4000
|
}
|
|
3394
4001
|
TransformStreamDefaultControllerError(this, reason);
|
|
3395
4002
|
}
|
|
4003
|
+
/**
|
|
4004
|
+
* Closes the readable side and errors the writable side of the controlled transform stream. This is useful when the
|
|
4005
|
+
* transformer only needs to consume a portion of the chunks written to the writable side.
|
|
4006
|
+
*/
|
|
3396
4007
|
terminate() {
|
|
3397
4008
|
if (!IsTransformStreamDefaultController(this)) {
|
|
3398
|
-
throw defaultControllerBrandCheckException
|
|
4009
|
+
throw defaultControllerBrandCheckException('terminate');
|
|
3399
4010
|
}
|
|
3400
4011
|
TransformStreamDefaultControllerTerminate(this);
|
|
3401
4012
|
}
|
|
@@ -3420,7 +4031,7 @@
|
|
|
3420
4031
|
if (!Object.prototype.hasOwnProperty.call(x, '_controlledTransformStream')) {
|
|
3421
4032
|
return false;
|
|
3422
4033
|
}
|
|
3423
|
-
return
|
|
4034
|
+
return x instanceof TransformStreamDefaultController;
|
|
3424
4035
|
}
|
|
3425
4036
|
function SetUpTransformStreamDefaultController(stream, controller, transformAlgorithm, flushAlgorithm) {
|
|
3426
4037
|
controller._controlledTransformStream = stream;
|
|
@@ -3537,11 +4148,11 @@
|
|
|
3537
4148
|
return stream._backpressureChangePromise;
|
|
3538
4149
|
}
|
|
3539
4150
|
// Helper functions for the TransformStreamDefaultController.
|
|
3540
|
-
function defaultControllerBrandCheckException
|
|
4151
|
+
function defaultControllerBrandCheckException(name) {
|
|
3541
4152
|
return new TypeError(`TransformStreamDefaultController.prototype.${name} can only be used on a TransformStreamDefaultController`);
|
|
3542
4153
|
}
|
|
3543
4154
|
// Helper functions for the TransformStream.
|
|
3544
|
-
function streamBrandCheckException
|
|
4155
|
+
function streamBrandCheckException(name) {
|
|
3545
4156
|
return new TypeError(`TransformStream.prototype.${name} can only be used on a TransformStream`);
|
|
3546
4157
|
}
|
|
3547
4158
|
|