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.es2018.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;
|
|
@@ -594,7 +626,14 @@
|
|
|
594
626
|
if (!Object.prototype.hasOwnProperty.call(x, '_asyncIteratorImpl')) {
|
|
595
627
|
return false;
|
|
596
628
|
}
|
|
597
|
-
|
|
629
|
+
try {
|
|
630
|
+
// noinspection SuspiciousTypeOfGuard
|
|
631
|
+
return x._asyncIteratorImpl instanceof
|
|
632
|
+
ReadableStreamAsyncIteratorImpl;
|
|
633
|
+
}
|
|
634
|
+
catch (_a) {
|
|
635
|
+
return false;
|
|
636
|
+
}
|
|
598
637
|
}
|
|
599
638
|
// Helper functions for the ReadableStream.
|
|
600
639
|
function streamAsyncIteratorBrandCheckException(name) {
|
|
@@ -608,15 +647,35 @@
|
|
|
608
647
|
return x !== x;
|
|
609
648
|
};
|
|
610
649
|
|
|
611
|
-
function
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
650
|
+
function CreateArrayFromList(elements) {
|
|
651
|
+
// We use arrays to represent lists, so this is basically a no-op.
|
|
652
|
+
// Do a slice though just in case we happen to depend on the unique-ness.
|
|
653
|
+
return elements.slice();
|
|
654
|
+
}
|
|
655
|
+
function CopyDataBlockBytes(dest, destOffset, src, srcOffset, n) {
|
|
656
|
+
new Uint8Array(dest).set(new Uint8Array(src, srcOffset, n), destOffset);
|
|
657
|
+
}
|
|
658
|
+
// Not implemented correctly
|
|
659
|
+
function TransferArrayBuffer(O) {
|
|
660
|
+
return O;
|
|
661
|
+
}
|
|
662
|
+
// Not implemented correctly
|
|
663
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
664
|
+
function IsDetachedBuffer(O) {
|
|
665
|
+
return false;
|
|
666
|
+
}
|
|
667
|
+
function ArrayBufferSlice(buffer, begin, end) {
|
|
668
|
+
// ArrayBuffer.prototype.slice is not available on IE10
|
|
669
|
+
// https://www.caniuse.com/mdn-javascript_builtins_arraybuffer_slice
|
|
670
|
+
if (buffer.slice) {
|
|
671
|
+
return buffer.slice(begin, end);
|
|
617
672
|
}
|
|
618
|
-
|
|
673
|
+
const length = end - begin;
|
|
674
|
+
const slice = new ArrayBuffer(length);
|
|
675
|
+
CopyDataBlockBytes(slice, 0, buffer, begin, length);
|
|
676
|
+
return slice;
|
|
619
677
|
}
|
|
678
|
+
|
|
620
679
|
function IsNonNegativeNumber(v) {
|
|
621
680
|
if (typeof v !== 'number') {
|
|
622
681
|
return false;
|
|
@@ -629,6 +688,10 @@
|
|
|
629
688
|
}
|
|
630
689
|
return true;
|
|
631
690
|
}
|
|
691
|
+
function CloneAsUint8Array(O) {
|
|
692
|
+
const buffer = ArrayBufferSlice(O.buffer, O.byteOffset, O.byteOffset + O.byteLength);
|
|
693
|
+
return new Uint8Array(buffer);
|
|
694
|
+
}
|
|
632
695
|
|
|
633
696
|
function DequeueValue(container) {
|
|
634
697
|
const pair = container._queue.shift();
|
|
@@ -639,8 +702,7 @@
|
|
|
639
702
|
return pair.value;
|
|
640
703
|
}
|
|
641
704
|
function EnqueueValueWithSize(container, value, size) {
|
|
642
|
-
size
|
|
643
|
-
if (!IsFiniteNonNegativeNumber(size)) {
|
|
705
|
+
if (!IsNonNegativeNumber(size) || size === Infinity) {
|
|
644
706
|
throw new RangeError('Size must be a finite, non-NaN, non-negative number.');
|
|
645
707
|
}
|
|
646
708
|
container._queue.push({ value, size });
|
|
@@ -655,27 +717,18 @@
|
|
|
655
717
|
container._queueTotalSize = 0;
|
|
656
718
|
}
|
|
657
719
|
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
function CopyDataBlockBytes(dest, destOffset, src, srcOffset, n) {
|
|
664
|
-
new Uint8Array(dest).set(new Uint8Array(src, srcOffset, n), destOffset);
|
|
665
|
-
}
|
|
666
|
-
// Not implemented correctly
|
|
667
|
-
function TransferArrayBuffer(O) {
|
|
668
|
-
return O;
|
|
669
|
-
}
|
|
670
|
-
// Not implemented correctly
|
|
671
|
-
function IsDetachedBuffer(O) {
|
|
672
|
-
return false;
|
|
673
|
-
}
|
|
674
|
-
|
|
720
|
+
/**
|
|
721
|
+
* A pull-into request in a {@link ReadableByteStreamController}.
|
|
722
|
+
*
|
|
723
|
+
* @public
|
|
724
|
+
*/
|
|
675
725
|
class ReadableStreamBYOBRequest {
|
|
676
726
|
constructor() {
|
|
677
727
|
throw new TypeError('Illegal constructor');
|
|
678
728
|
}
|
|
729
|
+
/**
|
|
730
|
+
* Returns the view for writing in to, or `null` if the BYOB request has already been responded to.
|
|
731
|
+
*/
|
|
679
732
|
get view() {
|
|
680
733
|
if (!IsReadableStreamBYOBRequest(this)) {
|
|
681
734
|
throw byobRequestBrandCheckException('view');
|
|
@@ -702,15 +755,10 @@
|
|
|
702
755
|
if (!ArrayBuffer.isView(view)) {
|
|
703
756
|
throw new TypeError('You can only respond with array buffer views');
|
|
704
757
|
}
|
|
705
|
-
if (view.byteLength === 0) {
|
|
706
|
-
throw new TypeError('chunk must have non-zero byteLength');
|
|
707
|
-
}
|
|
708
|
-
if (view.buffer.byteLength === 0) {
|
|
709
|
-
throw new TypeError(`chunk's buffer must have non-zero byteLength`);
|
|
710
|
-
}
|
|
711
758
|
if (this._associatedReadableByteStreamController === undefined) {
|
|
712
759
|
throw new TypeError('This BYOB request has been invalidated');
|
|
713
760
|
}
|
|
761
|
+
if (IsDetachedBuffer(view.buffer)) ;
|
|
714
762
|
ReadableByteStreamControllerRespondWithNewView(this._associatedReadableByteStreamController, view);
|
|
715
763
|
}
|
|
716
764
|
}
|
|
@@ -725,29 +773,38 @@
|
|
|
725
773
|
configurable: true
|
|
726
774
|
});
|
|
727
775
|
}
|
|
776
|
+
/**
|
|
777
|
+
* Allows control of a {@link ReadableStream | readable byte stream}'s state and internal queue.
|
|
778
|
+
*
|
|
779
|
+
* @public
|
|
780
|
+
*/
|
|
728
781
|
class ReadableByteStreamController {
|
|
729
782
|
constructor() {
|
|
730
783
|
throw new TypeError('Illegal constructor');
|
|
731
784
|
}
|
|
785
|
+
/**
|
|
786
|
+
* Returns the current BYOB pull request, or `null` if there isn't one.
|
|
787
|
+
*/
|
|
732
788
|
get byobRequest() {
|
|
733
789
|
if (!IsReadableByteStreamController(this)) {
|
|
734
790
|
throw byteStreamControllerBrandCheckException('byobRequest');
|
|
735
791
|
}
|
|
736
|
-
|
|
737
|
-
const firstDescriptor = this._pendingPullIntos.peek();
|
|
738
|
-
const view = new Uint8Array(firstDescriptor.buffer, firstDescriptor.byteOffset + firstDescriptor.bytesFilled, firstDescriptor.byteLength - firstDescriptor.bytesFilled);
|
|
739
|
-
const byobRequest = Object.create(ReadableStreamBYOBRequest.prototype);
|
|
740
|
-
SetUpReadableStreamBYOBRequest(byobRequest, this, view);
|
|
741
|
-
this._byobRequest = byobRequest;
|
|
742
|
-
}
|
|
743
|
-
return this._byobRequest;
|
|
792
|
+
return ReadableByteStreamControllerGetBYOBRequest(this);
|
|
744
793
|
}
|
|
794
|
+
/**
|
|
795
|
+
* Returns the desired size to fill the controlled stream's internal queue. It can be negative, if the queue is
|
|
796
|
+
* over-full. An underlying byte source ought to use this information to determine when and how to apply backpressure.
|
|
797
|
+
*/
|
|
745
798
|
get desiredSize() {
|
|
746
799
|
if (!IsReadableByteStreamController(this)) {
|
|
747
800
|
throw byteStreamControllerBrandCheckException('desiredSize');
|
|
748
801
|
}
|
|
749
802
|
return ReadableByteStreamControllerGetDesiredSize(this);
|
|
750
803
|
}
|
|
804
|
+
/**
|
|
805
|
+
* Closes the controlled readable stream. Consumers will still be able to read any previously-enqueued chunks from
|
|
806
|
+
* the stream, but once those are read, the stream will become closed.
|
|
807
|
+
*/
|
|
751
808
|
close() {
|
|
752
809
|
if (!IsReadableByteStreamController(this)) {
|
|
753
810
|
throw byteStreamControllerBrandCheckException('close');
|
|
@@ -784,6 +841,9 @@
|
|
|
784
841
|
}
|
|
785
842
|
ReadableByteStreamControllerEnqueue(this, chunk);
|
|
786
843
|
}
|
|
844
|
+
/**
|
|
845
|
+
* Errors the controlled readable stream, making all future interactions with it fail with the given error `e`.
|
|
846
|
+
*/
|
|
787
847
|
error(e = undefined) {
|
|
788
848
|
if (!IsReadableByteStreamController(this)) {
|
|
789
849
|
throw byteStreamControllerBrandCheckException('error');
|
|
@@ -792,10 +852,7 @@
|
|
|
792
852
|
}
|
|
793
853
|
/** @internal */
|
|
794
854
|
[CancelSteps](reason) {
|
|
795
|
-
|
|
796
|
-
const firstDescriptor = this._pendingPullIntos.peek();
|
|
797
|
-
firstDescriptor.bytesFilled = 0;
|
|
798
|
-
}
|
|
855
|
+
ReadableByteStreamControllerClearPendingPullIntos(this);
|
|
799
856
|
ResetQueue(this);
|
|
800
857
|
const result = this._cancelAlgorithm(reason);
|
|
801
858
|
ReadableByteStreamControllerClearAlgorithms(this);
|
|
@@ -824,6 +881,7 @@
|
|
|
824
881
|
}
|
|
825
882
|
const pullIntoDescriptor = {
|
|
826
883
|
buffer,
|
|
884
|
+
bufferByteLength: autoAllocateChunkSize,
|
|
827
885
|
byteOffset: 0,
|
|
828
886
|
byteLength: autoAllocateChunkSize,
|
|
829
887
|
bytesFilled: 0,
|
|
@@ -858,7 +916,7 @@
|
|
|
858
916
|
if (!Object.prototype.hasOwnProperty.call(x, '_controlledReadableByteStream')) {
|
|
859
917
|
return false;
|
|
860
918
|
}
|
|
861
|
-
return
|
|
919
|
+
return x instanceof ReadableByteStreamController;
|
|
862
920
|
}
|
|
863
921
|
function IsReadableStreamBYOBRequest(x) {
|
|
864
922
|
if (!typeIsObject(x)) {
|
|
@@ -867,7 +925,7 @@
|
|
|
867
925
|
if (!Object.prototype.hasOwnProperty.call(x, '_associatedReadableByteStreamController')) {
|
|
868
926
|
return false;
|
|
869
927
|
}
|
|
870
|
-
return
|
|
928
|
+
return x instanceof ReadableStreamBYOBRequest;
|
|
871
929
|
}
|
|
872
930
|
function ReadableByteStreamControllerCallPullIfNeeded(controller) {
|
|
873
931
|
const shouldPull = ReadableByteStreamControllerShouldCallPull(controller);
|
|
@@ -949,7 +1007,6 @@
|
|
|
949
1007
|
return ready;
|
|
950
1008
|
}
|
|
951
1009
|
function ReadableByteStreamControllerFillHeadPullIntoDescriptor(controller, size, pullIntoDescriptor) {
|
|
952
|
-
ReadableByteStreamControllerInvalidateBYOBRequest(controller);
|
|
953
1010
|
pullIntoDescriptor.bytesFilled += size;
|
|
954
1011
|
}
|
|
955
1012
|
function ReadableByteStreamControllerHandleQueueDrain(controller) {
|
|
@@ -988,9 +1045,15 @@
|
|
|
988
1045
|
elementSize = view.constructor.BYTES_PER_ELEMENT;
|
|
989
1046
|
}
|
|
990
1047
|
const ctor = view.constructor;
|
|
1048
|
+
// try {
|
|
991
1049
|
const buffer = TransferArrayBuffer(view.buffer);
|
|
1050
|
+
// } catch (e) {
|
|
1051
|
+
// readIntoRequest._errorSteps(e);
|
|
1052
|
+
// return;
|
|
1053
|
+
// }
|
|
992
1054
|
const pullIntoDescriptor = {
|
|
993
1055
|
buffer,
|
|
1056
|
+
bufferByteLength: buffer.byteLength,
|
|
994
1057
|
byteOffset: view.byteOffset,
|
|
995
1058
|
byteLength: view.byteLength,
|
|
996
1059
|
bytesFilled: 0,
|
|
@@ -1030,7 +1093,6 @@
|
|
|
1030
1093
|
ReadableByteStreamControllerCallPullIfNeeded(controller);
|
|
1031
1094
|
}
|
|
1032
1095
|
function ReadableByteStreamControllerRespondInClosedState(controller, firstDescriptor) {
|
|
1033
|
-
firstDescriptor.buffer = TransferArrayBuffer(firstDescriptor.buffer);
|
|
1034
1096
|
const stream = controller._controlledReadableByteStream;
|
|
1035
1097
|
if (ReadableStreamHasBYOBReader(stream)) {
|
|
1036
1098
|
while (ReadableStreamGetNumReadIntoRequests(stream) > 0) {
|
|
@@ -1040,34 +1102,27 @@
|
|
|
1040
1102
|
}
|
|
1041
1103
|
}
|
|
1042
1104
|
function ReadableByteStreamControllerRespondInReadableState(controller, bytesWritten, pullIntoDescriptor) {
|
|
1043
|
-
if (pullIntoDescriptor.bytesFilled + bytesWritten > pullIntoDescriptor.byteLength) {
|
|
1044
|
-
throw new RangeError('bytesWritten out of range');
|
|
1045
|
-
}
|
|
1046
1105
|
ReadableByteStreamControllerFillHeadPullIntoDescriptor(controller, bytesWritten, pullIntoDescriptor);
|
|
1047
1106
|
if (pullIntoDescriptor.bytesFilled < pullIntoDescriptor.elementSize) {
|
|
1048
|
-
// TODO: Figure out whether we should detach the buffer or not here.
|
|
1049
1107
|
return;
|
|
1050
1108
|
}
|
|
1051
1109
|
ReadableByteStreamControllerShiftPendingPullInto(controller);
|
|
1052
1110
|
const remainderSize = pullIntoDescriptor.bytesFilled % pullIntoDescriptor.elementSize;
|
|
1053
1111
|
if (remainderSize > 0) {
|
|
1054
1112
|
const end = pullIntoDescriptor.byteOffset + pullIntoDescriptor.bytesFilled;
|
|
1055
|
-
const remainder = pullIntoDescriptor.buffer
|
|
1113
|
+
const remainder = ArrayBufferSlice(pullIntoDescriptor.buffer, end - remainderSize, end);
|
|
1056
1114
|
ReadableByteStreamControllerEnqueueChunkToQueue(controller, remainder, 0, remainder.byteLength);
|
|
1057
1115
|
}
|
|
1058
|
-
pullIntoDescriptor.buffer = TransferArrayBuffer(pullIntoDescriptor.buffer);
|
|
1059
1116
|
pullIntoDescriptor.bytesFilled -= remainderSize;
|
|
1060
1117
|
ReadableByteStreamControllerCommitPullIntoDescriptor(controller._controlledReadableByteStream, pullIntoDescriptor);
|
|
1061
1118
|
ReadableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(controller);
|
|
1062
1119
|
}
|
|
1063
1120
|
function ReadableByteStreamControllerRespondInternal(controller, bytesWritten) {
|
|
1064
1121
|
const firstDescriptor = controller._pendingPullIntos.peek();
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
}
|
|
1070
|
-
ReadableByteStreamControllerRespondInClosedState(controller, firstDescriptor);
|
|
1122
|
+
ReadableByteStreamControllerInvalidateBYOBRequest(controller);
|
|
1123
|
+
const state = controller._controlledReadableByteStream._state;
|
|
1124
|
+
if (state === 'closed') {
|
|
1125
|
+
ReadableByteStreamControllerRespondInClosedState(controller);
|
|
1071
1126
|
}
|
|
1072
1127
|
else {
|
|
1073
1128
|
ReadableByteStreamControllerRespondInReadableState(controller, bytesWritten, firstDescriptor);
|
|
@@ -1076,7 +1131,6 @@
|
|
|
1076
1131
|
}
|
|
1077
1132
|
function ReadableByteStreamControllerShiftPendingPullInto(controller) {
|
|
1078
1133
|
const descriptor = controller._pendingPullIntos.shift();
|
|
1079
|
-
ReadableByteStreamControllerInvalidateBYOBRequest(controller);
|
|
1080
1134
|
return descriptor;
|
|
1081
1135
|
}
|
|
1082
1136
|
function ReadableByteStreamControllerShouldCallPull(controller) {
|
|
@@ -1136,6 +1190,12 @@
|
|
|
1136
1190
|
const byteOffset = chunk.byteOffset;
|
|
1137
1191
|
const byteLength = chunk.byteLength;
|
|
1138
1192
|
const transferredBuffer = TransferArrayBuffer(buffer);
|
|
1193
|
+
if (controller._pendingPullIntos.length > 0) {
|
|
1194
|
+
const firstPendingPullInto = controller._pendingPullIntos.peek();
|
|
1195
|
+
if (IsDetachedBuffer(firstPendingPullInto.buffer)) ;
|
|
1196
|
+
firstPendingPullInto.buffer = TransferArrayBuffer(firstPendingPullInto.buffer);
|
|
1197
|
+
}
|
|
1198
|
+
ReadableByteStreamControllerInvalidateBYOBRequest(controller);
|
|
1139
1199
|
if (ReadableStreamHasDefaultReader(stream)) {
|
|
1140
1200
|
if (ReadableStreamGetNumReadRequests(stream) === 0) {
|
|
1141
1201
|
ReadableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset, byteLength);
|
|
@@ -1165,9 +1225,18 @@
|
|
|
1165
1225
|
ReadableByteStreamControllerClearAlgorithms(controller);
|
|
1166
1226
|
ReadableStreamError(stream, e);
|
|
1167
1227
|
}
|
|
1228
|
+
function ReadableByteStreamControllerGetBYOBRequest(controller) {
|
|
1229
|
+
if (controller._byobRequest === null && controller._pendingPullIntos.length > 0) {
|
|
1230
|
+
const firstDescriptor = controller._pendingPullIntos.peek();
|
|
1231
|
+
const view = new Uint8Array(firstDescriptor.buffer, firstDescriptor.byteOffset + firstDescriptor.bytesFilled, firstDescriptor.byteLength - firstDescriptor.bytesFilled);
|
|
1232
|
+
const byobRequest = Object.create(ReadableStreamBYOBRequest.prototype);
|
|
1233
|
+
SetUpReadableStreamBYOBRequest(byobRequest, controller, view);
|
|
1234
|
+
controller._byobRequest = byobRequest;
|
|
1235
|
+
}
|
|
1236
|
+
return controller._byobRequest;
|
|
1237
|
+
}
|
|
1168
1238
|
function ReadableByteStreamControllerGetDesiredSize(controller) {
|
|
1169
|
-
const
|
|
1170
|
-
const state = stream._state;
|
|
1239
|
+
const state = controller._controlledReadableByteStream._state;
|
|
1171
1240
|
if (state === 'errored') {
|
|
1172
1241
|
return null;
|
|
1173
1242
|
}
|
|
@@ -1177,21 +1246,47 @@
|
|
|
1177
1246
|
return controller._strategyHWM - controller._queueTotalSize;
|
|
1178
1247
|
}
|
|
1179
1248
|
function ReadableByteStreamControllerRespond(controller, bytesWritten) {
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1249
|
+
const firstDescriptor = controller._pendingPullIntos.peek();
|
|
1250
|
+
const state = controller._controlledReadableByteStream._state;
|
|
1251
|
+
if (state === 'closed') {
|
|
1252
|
+
if (bytesWritten !== 0) {
|
|
1253
|
+
throw new TypeError('bytesWritten must be 0 when calling respond() on a closed stream');
|
|
1254
|
+
}
|
|
1255
|
+
}
|
|
1256
|
+
else {
|
|
1257
|
+
if (bytesWritten === 0) {
|
|
1258
|
+
throw new TypeError('bytesWritten must be greater than 0 when calling respond() on a readable stream');
|
|
1259
|
+
}
|
|
1260
|
+
if (firstDescriptor.bytesFilled + bytesWritten > firstDescriptor.byteLength) {
|
|
1261
|
+
throw new RangeError('bytesWritten out of range');
|
|
1262
|
+
}
|
|
1183
1263
|
}
|
|
1264
|
+
firstDescriptor.buffer = TransferArrayBuffer(firstDescriptor.buffer);
|
|
1184
1265
|
ReadableByteStreamControllerRespondInternal(controller, bytesWritten);
|
|
1185
1266
|
}
|
|
1186
1267
|
function ReadableByteStreamControllerRespondWithNewView(controller, view) {
|
|
1187
1268
|
const firstDescriptor = controller._pendingPullIntos.peek();
|
|
1269
|
+
const state = controller._controlledReadableByteStream._state;
|
|
1270
|
+
if (state === 'closed') {
|
|
1271
|
+
if (view.byteLength !== 0) {
|
|
1272
|
+
throw new TypeError('The view\'s length must be 0 when calling respondWithNewView() on a closed stream');
|
|
1273
|
+
}
|
|
1274
|
+
}
|
|
1275
|
+
else {
|
|
1276
|
+
if (view.byteLength === 0) {
|
|
1277
|
+
throw new TypeError('The view\'s length must be greater than 0 when calling respondWithNewView() on a readable stream');
|
|
1278
|
+
}
|
|
1279
|
+
}
|
|
1188
1280
|
if (firstDescriptor.byteOffset + firstDescriptor.bytesFilled !== view.byteOffset) {
|
|
1189
1281
|
throw new RangeError('The region specified by view does not match byobRequest');
|
|
1190
1282
|
}
|
|
1191
|
-
if (firstDescriptor.
|
|
1283
|
+
if (firstDescriptor.bufferByteLength !== view.buffer.byteLength) {
|
|
1192
1284
|
throw new RangeError('The buffer of view has different capacity than byobRequest');
|
|
1193
1285
|
}
|
|
1194
|
-
firstDescriptor.
|
|
1286
|
+
if (firstDescriptor.bytesFilled + view.byteLength > firstDescriptor.byteLength) {
|
|
1287
|
+
throw new RangeError('The region specified by view is larger than byobRequest');
|
|
1288
|
+
}
|
|
1289
|
+
firstDescriptor.buffer = TransferArrayBuffer(view.buffer);
|
|
1195
1290
|
ReadableByteStreamControllerRespondInternal(controller, view.byteLength);
|
|
1196
1291
|
}
|
|
1197
1292
|
function SetUpReadableByteStreamController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, autoAllocateChunkSize) {
|
|
@@ -1233,6 +1328,9 @@
|
|
|
1233
1328
|
cancelAlgorithm = reason => underlyingByteSource.cancel(reason);
|
|
1234
1329
|
}
|
|
1235
1330
|
const autoAllocateChunkSize = underlyingByteSource.autoAllocateChunkSize;
|
|
1331
|
+
if (autoAllocateChunkSize === 0) {
|
|
1332
|
+
throw new TypeError('autoAllocateChunkSize must be greater than 0');
|
|
1333
|
+
}
|
|
1236
1334
|
SetUpReadableByteStreamController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, autoAllocateChunkSize);
|
|
1237
1335
|
}
|
|
1238
1336
|
function SetUpReadableStreamBYOBRequest(request, controller, view) {
|
|
@@ -1279,6 +1377,11 @@
|
|
|
1279
1377
|
}
|
|
1280
1378
|
return true;
|
|
1281
1379
|
}
|
|
1380
|
+
/**
|
|
1381
|
+
* A BYOB reader vended by a {@link ReadableStream}.
|
|
1382
|
+
*
|
|
1383
|
+
* @public
|
|
1384
|
+
*/
|
|
1282
1385
|
class ReadableStreamBYOBReader {
|
|
1283
1386
|
constructor(stream) {
|
|
1284
1387
|
assertRequiredArgument(stream, 1, 'ReadableStreamBYOBReader');
|
|
@@ -1293,12 +1396,19 @@
|
|
|
1293
1396
|
ReadableStreamReaderGenericInitialize(this, stream);
|
|
1294
1397
|
this._readIntoRequests = new SimpleQueue();
|
|
1295
1398
|
}
|
|
1399
|
+
/**
|
|
1400
|
+
* Returns a promise that will be fulfilled when the stream becomes closed, or rejected if the stream ever errors or
|
|
1401
|
+
* the reader's lock is released before the stream finishes closing.
|
|
1402
|
+
*/
|
|
1296
1403
|
get closed() {
|
|
1297
1404
|
if (!IsReadableStreamBYOBReader(this)) {
|
|
1298
1405
|
return promiseRejectedWith(byobReaderBrandCheckException('closed'));
|
|
1299
1406
|
}
|
|
1300
1407
|
return this._closedPromise;
|
|
1301
1408
|
}
|
|
1409
|
+
/**
|
|
1410
|
+
* If the reader is active, behaves the same as {@link ReadableStream.cancel | stream.cancel(reason)}.
|
|
1411
|
+
*/
|
|
1302
1412
|
cancel(reason = undefined) {
|
|
1303
1413
|
if (!IsReadableStreamBYOBReader(this)) {
|
|
1304
1414
|
return promiseRejectedWith(byobReaderBrandCheckException('cancel'));
|
|
@@ -1308,6 +1418,11 @@
|
|
|
1308
1418
|
}
|
|
1309
1419
|
return ReadableStreamReaderGenericCancel(this, reason);
|
|
1310
1420
|
}
|
|
1421
|
+
/**
|
|
1422
|
+
* Attempts to reads bytes into view, and returns a promise resolved with the result.
|
|
1423
|
+
*
|
|
1424
|
+
* If reading a chunk causes the queue to become empty, more data will be pulled from the underlying source.
|
|
1425
|
+
*/
|
|
1311
1426
|
read(view) {
|
|
1312
1427
|
if (!IsReadableStreamBYOBReader(this)) {
|
|
1313
1428
|
return promiseRejectedWith(byobReaderBrandCheckException('read'));
|
|
@@ -1321,6 +1436,7 @@
|
|
|
1321
1436
|
if (view.buffer.byteLength === 0) {
|
|
1322
1437
|
return promiseRejectedWith(new TypeError(`view's buffer must have non-zero byteLength`));
|
|
1323
1438
|
}
|
|
1439
|
+
if (IsDetachedBuffer(view.buffer)) ;
|
|
1324
1440
|
if (this._ownerReadableStream === undefined) {
|
|
1325
1441
|
return promiseRejectedWith(readerLockException('read from'));
|
|
1326
1442
|
}
|
|
@@ -1338,6 +1454,15 @@
|
|
|
1338
1454
|
ReadableStreamBYOBReaderRead(this, view, readIntoRequest);
|
|
1339
1455
|
return promise;
|
|
1340
1456
|
}
|
|
1457
|
+
/**
|
|
1458
|
+
* Releases the reader's lock on the corresponding stream. After the lock is released, the reader is no longer active.
|
|
1459
|
+
* If the associated stream is errored when the lock is released, the reader will appear errored in the same way
|
|
1460
|
+
* from now on; otherwise, the reader will appear closed.
|
|
1461
|
+
*
|
|
1462
|
+
* A reader's lock cannot be released while it still has a pending read request, i.e., if a promise returned by
|
|
1463
|
+
* the reader's {@link ReadableStreamBYOBReader.read | read()} method has not yet been settled. Attempting to
|
|
1464
|
+
* do so will throw a `TypeError` and leave the reader locked to the stream.
|
|
1465
|
+
*/
|
|
1341
1466
|
releaseLock() {
|
|
1342
1467
|
if (!IsReadableStreamBYOBReader(this)) {
|
|
1343
1468
|
throw byobReaderBrandCheckException('releaseLock');
|
|
@@ -1371,7 +1496,7 @@
|
|
|
1371
1496
|
if (!Object.prototype.hasOwnProperty.call(x, '_readIntoRequests')) {
|
|
1372
1497
|
return false;
|
|
1373
1498
|
}
|
|
1374
|
-
return
|
|
1499
|
+
return x instanceof ReadableStreamBYOBReader;
|
|
1375
1500
|
}
|
|
1376
1501
|
function ReadableStreamBYOBReaderRead(reader, view, readIntoRequest) {
|
|
1377
1502
|
const stream = reader._ownerReadableStream;
|
|
@@ -1466,6 +1591,36 @@
|
|
|
1466
1591
|
}
|
|
1467
1592
|
}
|
|
1468
1593
|
|
|
1594
|
+
function isAbortSignal(value) {
|
|
1595
|
+
if (typeof value !== 'object' || value === null) {
|
|
1596
|
+
return false;
|
|
1597
|
+
}
|
|
1598
|
+
try {
|
|
1599
|
+
return typeof value.aborted === 'boolean';
|
|
1600
|
+
}
|
|
1601
|
+
catch (_a) {
|
|
1602
|
+
// AbortSignal.prototype.aborted throws if its brand check fails
|
|
1603
|
+
return false;
|
|
1604
|
+
}
|
|
1605
|
+
}
|
|
1606
|
+
const supportsAbortController = typeof AbortController === 'function';
|
|
1607
|
+
/**
|
|
1608
|
+
* Construct a new AbortController, if supported by the platform.
|
|
1609
|
+
*
|
|
1610
|
+
* @internal
|
|
1611
|
+
*/
|
|
1612
|
+
function createAbortController() {
|
|
1613
|
+
if (supportsAbortController) {
|
|
1614
|
+
return new AbortController();
|
|
1615
|
+
}
|
|
1616
|
+
return undefined;
|
|
1617
|
+
}
|
|
1618
|
+
|
|
1619
|
+
/**
|
|
1620
|
+
* A writable stream represents a destination for data, into which you can write.
|
|
1621
|
+
*
|
|
1622
|
+
* @public
|
|
1623
|
+
*/
|
|
1469
1624
|
class WritableStream {
|
|
1470
1625
|
constructor(rawUnderlyingSink = {}, rawStrategy = {}) {
|
|
1471
1626
|
if (rawUnderlyingSink === undefined) {
|
|
@@ -1485,24 +1640,44 @@
|
|
|
1485
1640
|
const highWaterMark = ExtractHighWaterMark(strategy, 1);
|
|
1486
1641
|
SetUpWritableStreamDefaultControllerFromUnderlyingSink(this, underlyingSink, highWaterMark, sizeAlgorithm);
|
|
1487
1642
|
}
|
|
1643
|
+
/**
|
|
1644
|
+
* Returns whether or not the writable stream is locked to a writer.
|
|
1645
|
+
*/
|
|
1488
1646
|
get locked() {
|
|
1489
1647
|
if (!IsWritableStream(this)) {
|
|
1490
|
-
throw streamBrandCheckException('locked');
|
|
1648
|
+
throw streamBrandCheckException$2('locked');
|
|
1491
1649
|
}
|
|
1492
1650
|
return IsWritableStreamLocked(this);
|
|
1493
1651
|
}
|
|
1652
|
+
/**
|
|
1653
|
+
* Aborts the stream, signaling that the producer can no longer successfully write to the stream and it is to be
|
|
1654
|
+
* immediately moved to an errored state, with any queued-up writes discarded. This will also execute any abort
|
|
1655
|
+
* mechanism of the underlying sink.
|
|
1656
|
+
*
|
|
1657
|
+
* The returned promise will fulfill if the stream shuts down successfully, or reject if the underlying sink signaled
|
|
1658
|
+
* that there was an error doing so. Additionally, it will reject with a `TypeError` (without attempting to cancel
|
|
1659
|
+
* the stream) if the stream is currently locked.
|
|
1660
|
+
*/
|
|
1494
1661
|
abort(reason = undefined) {
|
|
1495
1662
|
if (!IsWritableStream(this)) {
|
|
1496
|
-
return promiseRejectedWith(streamBrandCheckException('abort'));
|
|
1663
|
+
return promiseRejectedWith(streamBrandCheckException$2('abort'));
|
|
1497
1664
|
}
|
|
1498
1665
|
if (IsWritableStreamLocked(this)) {
|
|
1499
1666
|
return promiseRejectedWith(new TypeError('Cannot abort a stream that already has a writer'));
|
|
1500
1667
|
}
|
|
1501
1668
|
return WritableStreamAbort(this, reason);
|
|
1502
1669
|
}
|
|
1670
|
+
/**
|
|
1671
|
+
* Closes the stream. The underlying sink will finish processing any previously-written chunks, before invoking its
|
|
1672
|
+
* close behavior. During this time any further attempts to write will fail (without erroring the stream).
|
|
1673
|
+
*
|
|
1674
|
+
* The method returns a promise that will fulfill if all remaining chunks are successfully written and the stream
|
|
1675
|
+
* successfully closes, or rejects if an error is encountered during this process. Additionally, it will reject with
|
|
1676
|
+
* a `TypeError` (without attempting to cancel the stream) if the stream is currently locked.
|
|
1677
|
+
*/
|
|
1503
1678
|
close() {
|
|
1504
1679
|
if (!IsWritableStream(this)) {
|
|
1505
|
-
return promiseRejectedWith(streamBrandCheckException('close'));
|
|
1680
|
+
return promiseRejectedWith(streamBrandCheckException$2('close'));
|
|
1506
1681
|
}
|
|
1507
1682
|
if (IsWritableStreamLocked(this)) {
|
|
1508
1683
|
return promiseRejectedWith(new TypeError('Cannot close a stream that already has a writer'));
|
|
@@ -1512,9 +1687,17 @@
|
|
|
1512
1687
|
}
|
|
1513
1688
|
return WritableStreamClose(this);
|
|
1514
1689
|
}
|
|
1690
|
+
/**
|
|
1691
|
+
* Creates a {@link WritableStreamDefaultWriter | writer} and locks the stream to the new writer. While the stream
|
|
1692
|
+
* is locked, no other writer can be acquired until this one is released.
|
|
1693
|
+
*
|
|
1694
|
+
* This functionality is especially useful for creating abstractions that desire the ability to write to a stream
|
|
1695
|
+
* without interruption or interleaving. By getting a writer for the stream, you can ensure nobody else can write at
|
|
1696
|
+
* the same time, which would cause the resulting written data to be unpredictable and probably useless.
|
|
1697
|
+
*/
|
|
1515
1698
|
getWriter() {
|
|
1516
1699
|
if (!IsWritableStream(this)) {
|
|
1517
|
-
throw streamBrandCheckException('getWriter');
|
|
1700
|
+
throw streamBrandCheckException$2('getWriter');
|
|
1518
1701
|
}
|
|
1519
1702
|
return AcquireWritableStreamDefaultWriter(this);
|
|
1520
1703
|
}
|
|
@@ -1576,7 +1759,7 @@
|
|
|
1576
1759
|
if (!Object.prototype.hasOwnProperty.call(x, '_writableStreamController')) {
|
|
1577
1760
|
return false;
|
|
1578
1761
|
}
|
|
1579
|
-
return
|
|
1762
|
+
return x instanceof WritableStream;
|
|
1580
1763
|
}
|
|
1581
1764
|
function IsWritableStreamLocked(stream) {
|
|
1582
1765
|
if (stream._writer === undefined) {
|
|
@@ -1585,6 +1768,15 @@
|
|
|
1585
1768
|
return true;
|
|
1586
1769
|
}
|
|
1587
1770
|
function WritableStreamAbort(stream, reason) {
|
|
1771
|
+
var _a;
|
|
1772
|
+
if (stream._state === 'closed' || stream._state === 'errored') {
|
|
1773
|
+
return promiseResolvedWith(undefined);
|
|
1774
|
+
}
|
|
1775
|
+
stream._writableStreamController._abortReason = reason;
|
|
1776
|
+
(_a = stream._writableStreamController._abortController) === null || _a === void 0 ? void 0 : _a.abort();
|
|
1777
|
+
// TypeScript narrows the type of `stream._state` down to 'writable' | 'erroring',
|
|
1778
|
+
// but it doesn't know that signaling abort runs author code that might have changed the state.
|
|
1779
|
+
// Widen the type again by casting to WritableStreamState.
|
|
1588
1780
|
const state = stream._state;
|
|
1589
1781
|
if (state === 'closed' || state === 'errored') {
|
|
1590
1782
|
return promiseResolvedWith(undefined);
|
|
@@ -1770,6 +1962,11 @@
|
|
|
1770
1962
|
}
|
|
1771
1963
|
stream._backpressure = backpressure;
|
|
1772
1964
|
}
|
|
1965
|
+
/**
|
|
1966
|
+
* A default writer vended by a {@link WritableStream}.
|
|
1967
|
+
*
|
|
1968
|
+
* @public
|
|
1969
|
+
*/
|
|
1773
1970
|
class WritableStreamDefaultWriter {
|
|
1774
1971
|
constructor(stream) {
|
|
1775
1972
|
assertRequiredArgument(stream, 1, 'WritableStreamDefaultWriter');
|
|
@@ -1803,12 +2000,24 @@
|
|
|
1803
2000
|
defaultWriterClosedPromiseInitializeAsRejected(this, storedError);
|
|
1804
2001
|
}
|
|
1805
2002
|
}
|
|
2003
|
+
/**
|
|
2004
|
+
* Returns a promise that will be fulfilled when the stream becomes closed, or rejected if the stream ever errors or
|
|
2005
|
+
* the writer’s lock is released before the stream finishes closing.
|
|
2006
|
+
*/
|
|
1806
2007
|
get closed() {
|
|
1807
2008
|
if (!IsWritableStreamDefaultWriter(this)) {
|
|
1808
2009
|
return promiseRejectedWith(defaultWriterBrandCheckException('closed'));
|
|
1809
2010
|
}
|
|
1810
2011
|
return this._closedPromise;
|
|
1811
2012
|
}
|
|
2013
|
+
/**
|
|
2014
|
+
* Returns the desired size to fill the stream’s internal queue. It can be negative, if the queue is over-full.
|
|
2015
|
+
* A producer can use this information to determine the right amount of data to write.
|
|
2016
|
+
*
|
|
2017
|
+
* It will be `null` if the stream cannot be successfully written to (due to either being errored, or having an abort
|
|
2018
|
+
* queued up). It will return zero if the stream is closed. And the getter will throw an exception if invoked when
|
|
2019
|
+
* the writer’s lock is released.
|
|
2020
|
+
*/
|
|
1812
2021
|
get desiredSize() {
|
|
1813
2022
|
if (!IsWritableStreamDefaultWriter(this)) {
|
|
1814
2023
|
throw defaultWriterBrandCheckException('desiredSize');
|
|
@@ -1818,12 +2027,23 @@
|
|
|
1818
2027
|
}
|
|
1819
2028
|
return WritableStreamDefaultWriterGetDesiredSize(this);
|
|
1820
2029
|
}
|
|
2030
|
+
/**
|
|
2031
|
+
* Returns a promise that will be fulfilled when the desired size to fill the stream’s internal queue transitions
|
|
2032
|
+
* from non-positive to positive, signaling that it is no longer applying backpressure. Once the desired size dips
|
|
2033
|
+
* back to zero or below, the getter will return a new promise that stays pending until the next transition.
|
|
2034
|
+
*
|
|
2035
|
+
* If the stream becomes errored or aborted, or the writer’s lock is released, the returned promise will become
|
|
2036
|
+
* rejected.
|
|
2037
|
+
*/
|
|
1821
2038
|
get ready() {
|
|
1822
2039
|
if (!IsWritableStreamDefaultWriter(this)) {
|
|
1823
2040
|
return promiseRejectedWith(defaultWriterBrandCheckException('ready'));
|
|
1824
2041
|
}
|
|
1825
2042
|
return this._readyPromise;
|
|
1826
2043
|
}
|
|
2044
|
+
/**
|
|
2045
|
+
* If the reader is active, behaves the same as {@link WritableStream.abort | stream.abort(reason)}.
|
|
2046
|
+
*/
|
|
1827
2047
|
abort(reason = undefined) {
|
|
1828
2048
|
if (!IsWritableStreamDefaultWriter(this)) {
|
|
1829
2049
|
return promiseRejectedWith(defaultWriterBrandCheckException('abort'));
|
|
@@ -1833,6 +2053,9 @@
|
|
|
1833
2053
|
}
|
|
1834
2054
|
return WritableStreamDefaultWriterAbort(this, reason);
|
|
1835
2055
|
}
|
|
2056
|
+
/**
|
|
2057
|
+
* If the reader is active, behaves the same as {@link WritableStream.close | stream.close()}.
|
|
2058
|
+
*/
|
|
1836
2059
|
close() {
|
|
1837
2060
|
if (!IsWritableStreamDefaultWriter(this)) {
|
|
1838
2061
|
return promiseRejectedWith(defaultWriterBrandCheckException('close'));
|
|
@@ -1846,6 +2069,16 @@
|
|
|
1846
2069
|
}
|
|
1847
2070
|
return WritableStreamDefaultWriterClose(this);
|
|
1848
2071
|
}
|
|
2072
|
+
/**
|
|
2073
|
+
* Releases the writer’s lock on the corresponding stream. After the lock is released, the writer is no longer active.
|
|
2074
|
+
* If the associated stream is errored when the lock is released, the writer will appear errored in the same way from
|
|
2075
|
+
* now on; otherwise, the writer will appear closed.
|
|
2076
|
+
*
|
|
2077
|
+
* Note that the lock can still be released even if some ongoing writes have not yet finished (i.e. even if the
|
|
2078
|
+
* promises returned from previous calls to {@link WritableStreamDefaultWriter.write | write()} have not yet settled).
|
|
2079
|
+
* It’s not necessary to hold the lock on the writer for the duration of the write; the lock instead simply prevents
|
|
2080
|
+
* other producers from writing in an interleaved manner.
|
|
2081
|
+
*/
|
|
1849
2082
|
releaseLock() {
|
|
1850
2083
|
if (!IsWritableStreamDefaultWriter(this)) {
|
|
1851
2084
|
throw defaultWriterBrandCheckException('releaseLock');
|
|
@@ -1889,7 +2122,7 @@
|
|
|
1889
2122
|
if (!Object.prototype.hasOwnProperty.call(x, '_ownerWritableStream')) {
|
|
1890
2123
|
return false;
|
|
1891
2124
|
}
|
|
1892
|
-
return
|
|
2125
|
+
return x instanceof WritableStreamDefaultWriter;
|
|
1893
2126
|
}
|
|
1894
2127
|
// A client of WritableStreamDefaultWriter may use these functions directly to bypass state check.
|
|
1895
2128
|
function WritableStreamDefaultWriterAbort(writer, reason) {
|
|
@@ -1970,13 +2203,49 @@
|
|
|
1970
2203
|
return promise;
|
|
1971
2204
|
}
|
|
1972
2205
|
const closeSentinel = {};
|
|
2206
|
+
/**
|
|
2207
|
+
* Allows control of a {@link WritableStream | writable stream}'s state and internal queue.
|
|
2208
|
+
*
|
|
2209
|
+
* @public
|
|
2210
|
+
*/
|
|
1973
2211
|
class WritableStreamDefaultController {
|
|
1974
2212
|
constructor() {
|
|
1975
2213
|
throw new TypeError('Illegal constructor');
|
|
1976
2214
|
}
|
|
2215
|
+
/**
|
|
2216
|
+
* The reason which was passed to `WritableStream.abort(reason)` when the stream was aborted.
|
|
2217
|
+
*/
|
|
2218
|
+
get abortReason() {
|
|
2219
|
+
if (!IsWritableStreamDefaultController(this)) {
|
|
2220
|
+
throw defaultControllerBrandCheckException$2('abortReason');
|
|
2221
|
+
}
|
|
2222
|
+
return this._abortReason;
|
|
2223
|
+
}
|
|
2224
|
+
/**
|
|
2225
|
+
* An `AbortSignal` that can be used to abort the pending write or close operation when the stream is aborted.
|
|
2226
|
+
*/
|
|
2227
|
+
get signal() {
|
|
2228
|
+
if (!IsWritableStreamDefaultController(this)) {
|
|
2229
|
+
throw defaultControllerBrandCheckException$2('signal');
|
|
2230
|
+
}
|
|
2231
|
+
if (this._abortController === undefined) {
|
|
2232
|
+
// Older browsers or older Node versions may not support `AbortController` or `AbortSignal`.
|
|
2233
|
+
// We don't want to bundle and ship an `AbortController` polyfill together with our polyfill,
|
|
2234
|
+
// so instead we only implement support for `signal` if we find a global `AbortController` constructor.
|
|
2235
|
+
throw new TypeError('WritableStreamDefaultController.prototype.signal is not supported');
|
|
2236
|
+
}
|
|
2237
|
+
return this._abortController.signal;
|
|
2238
|
+
}
|
|
2239
|
+
/**
|
|
2240
|
+
* Closes the controlled writable stream, making all future interactions with it fail with the given error `e`.
|
|
2241
|
+
*
|
|
2242
|
+
* This method is rarely used, since usually it suffices to return a rejected promise from one of the underlying
|
|
2243
|
+
* sink's methods. However, it can be useful for suddenly shutting down a stream in response to an event outside the
|
|
2244
|
+
* normal lifecycle of interactions with the underlying sink.
|
|
2245
|
+
*/
|
|
1977
2246
|
error(e = undefined) {
|
|
1978
2247
|
if (!IsWritableStreamDefaultController(this)) {
|
|
1979
|
-
throw
|
|
2248
|
+
throw defaultControllerBrandCheckException$2('error');
|
|
1980
2249
|
}
|
|
1981
2250
|
const state = this._controlledWritableStream._state;
|
|
1982
2251
|
if (state !== 'writable') {
|
|
@@ -2014,7 +2283,7 @@
|
|
|
2014
2283
|
if (!Object.prototype.hasOwnProperty.call(x, '_controlledWritableStream')) {
|
|
2015
2284
|
return false;
|
|
2016
2285
|
}
|
|
2017
|
-
return
|
|
2286
|
+
return x instanceof WritableStreamDefaultController;
|
|
2018
2287
|
}
|
|
2019
2288
|
function SetUpWritableStreamDefaultController(stream, controller, startAlgorithm, writeAlgorithm, closeAlgorithm, abortAlgorithm, highWaterMark, sizeAlgorithm) {
|
|
2020
2289
|
controller._controlledWritableStream = stream;
|
|
@@ -2023,6 +2292,8 @@
|
|
|
2023
2292
|
controller._queue = undefined;
|
|
2024
2293
|
controller._queueTotalSize = undefined;
|
|
2025
2294
|
ResetQueue(controller);
|
|
2295
|
+
controller._abortReason = undefined;
|
|
2296
|
+
controller._abortController = createAbortController();
|
|
2026
2297
|
controller._started = false;
|
|
2027
2298
|
controller._strategySizeAlgorithm = sizeAlgorithm;
|
|
2028
2299
|
controller._strategyHWM = highWaterMark;
|
|
@@ -2172,9 +2443,13 @@
|
|
|
2172
2443
|
WritableStreamStartErroring(stream, error);
|
|
2173
2444
|
}
|
|
2174
2445
|
// Helper functions for the WritableStream.
|
|
2175
|
-
function streamBrandCheckException(name) {
|
|
2446
|
+
function streamBrandCheckException$2(name) {
|
|
2176
2447
|
return new TypeError(`WritableStream.prototype.${name} can only be used on a WritableStream`);
|
|
2177
2448
|
}
|
|
2449
|
+
// Helper functions for the WritableStreamDefaultController.
|
|
2450
|
+
function defaultControllerBrandCheckException$2(name) {
|
|
2451
|
+
return new TypeError(`WritableStreamDefaultController.prototype.${name} can only be used on a WritableStreamDefaultController`);
|
|
2452
|
+
}
|
|
2178
2453
|
// Helper functions for the WritableStreamDefaultWriter.
|
|
2179
2454
|
function defaultWriterBrandCheckException(name) {
|
|
2180
2455
|
return new TypeError(`WritableStreamDefaultWriter.prototype.${name} can only be used on a WritableStreamDefaultWriter`);
|
|
@@ -2198,6 +2473,9 @@
|
|
|
2198
2473
|
defaultWriterClosedPromiseResolve(writer);
|
|
2199
2474
|
}
|
|
2200
2475
|
function defaultWriterClosedPromiseReject(writer, reason) {
|
|
2476
|
+
if (writer._closedPromise_reject === undefined) {
|
|
2477
|
+
return;
|
|
2478
|
+
}
|
|
2201
2479
|
setPromiseIsHandledToTrue(writer._closedPromise);
|
|
2202
2480
|
writer._closedPromise_reject(reason);
|
|
2203
2481
|
writer._closedPromise_resolve = undefined;
|
|
@@ -2208,6 +2486,9 @@
|
|
|
2208
2486
|
defaultWriterClosedPromiseInitializeAsRejected(writer, reason);
|
|
2209
2487
|
}
|
|
2210
2488
|
function defaultWriterClosedPromiseResolve(writer) {
|
|
2489
|
+
if (writer._closedPromise_resolve === undefined) {
|
|
2490
|
+
return;
|
|
2491
|
+
}
|
|
2211
2492
|
writer._closedPromise_resolve(undefined);
|
|
2212
2493
|
writer._closedPromise_resolve = undefined;
|
|
2213
2494
|
writer._closedPromise_reject = undefined;
|
|
@@ -2229,6 +2510,9 @@
|
|
|
2229
2510
|
defaultWriterReadyPromiseResolve(writer);
|
|
2230
2511
|
}
|
|
2231
2512
|
function defaultWriterReadyPromiseReject(writer, reason) {
|
|
2513
|
+
if (writer._readyPromise_reject === undefined) {
|
|
2514
|
+
return;
|
|
2515
|
+
}
|
|
2232
2516
|
setPromiseIsHandledToTrue(writer._readyPromise);
|
|
2233
2517
|
writer._readyPromise_reject(reason);
|
|
2234
2518
|
writer._readyPromise_resolve = undefined;
|
|
@@ -2242,25 +2526,15 @@
|
|
|
2242
2526
|
defaultWriterReadyPromiseInitializeAsRejected(writer, reason);
|
|
2243
2527
|
}
|
|
2244
2528
|
function defaultWriterReadyPromiseResolve(writer) {
|
|
2529
|
+
if (writer._readyPromise_resolve === undefined) {
|
|
2530
|
+
return;
|
|
2531
|
+
}
|
|
2245
2532
|
writer._readyPromise_resolve(undefined);
|
|
2246
2533
|
writer._readyPromise_resolve = undefined;
|
|
2247
2534
|
writer._readyPromise_reject = undefined;
|
|
2248
2535
|
writer._readyPromiseState = 'fulfilled';
|
|
2249
2536
|
}
|
|
2250
2537
|
|
|
2251
|
-
function isAbortSignal(value) {
|
|
2252
|
-
if (typeof value !== 'object' || value === null) {
|
|
2253
|
-
return false;
|
|
2254
|
-
}
|
|
2255
|
-
try {
|
|
2256
|
-
return typeof value.aborted === 'boolean';
|
|
2257
|
-
}
|
|
2258
|
-
catch (_a) {
|
|
2259
|
-
// AbortSignal.prototype.aborted throws if its brand check fails
|
|
2260
|
-
return false;
|
|
2261
|
-
}
|
|
2262
|
-
}
|
|
2263
|
-
|
|
2264
2538
|
/// <reference lib="dom" />
|
|
2265
2539
|
const NativeDOMException = typeof DOMException !== 'undefined' ? DOMException : undefined;
|
|
2266
2540
|
|
|
@@ -2278,6 +2552,7 @@
|
|
|
2278
2552
|
}
|
|
2279
2553
|
}
|
|
2280
2554
|
function createDOMExceptionPolyfill() {
|
|
2555
|
+
// eslint-disable-next-line no-shadow
|
|
2281
2556
|
const ctor = function DOMException(message, name) {
|
|
2282
2557
|
this.message = message || '';
|
|
2283
2558
|
this.name = name || 'Error';
|
|
@@ -2289,6 +2564,7 @@
|
|
|
2289
2564
|
Object.defineProperty(ctor.prototype, 'constructor', { value: ctor, writable: true, configurable: true });
|
|
2290
2565
|
return ctor;
|
|
2291
2566
|
}
|
|
2567
|
+
// eslint-disable-next-line no-redeclare
|
|
2292
2568
|
const DOMException$1 = isDOMExceptionConstructor(NativeDOMException) ? NativeDOMException : createDOMExceptionPolyfill();
|
|
2293
2569
|
|
|
2294
2570
|
function ReadableStreamPipeTo(source, dest, preventClose, preventAbort, preventCancel, signal) {
|
|
@@ -2466,19 +2742,32 @@
|
|
|
2466
2742
|
});
|
|
2467
2743
|
}
|
|
2468
2744
|
|
|
2745
|
+
/**
|
|
2746
|
+
* Allows control of a {@link ReadableStream | readable stream}'s state and internal queue.
|
|
2747
|
+
*
|
|
2748
|
+
* @public
|
|
2749
|
+
*/
|
|
2469
2750
|
class ReadableStreamDefaultController {
|
|
2470
2751
|
constructor() {
|
|
2471
2752
|
throw new TypeError('Illegal constructor');
|
|
2472
2753
|
}
|
|
2754
|
+
/**
|
|
2755
|
+
* Returns the desired size to fill the controlled stream's internal queue. It can be negative, if the queue is
|
|
2756
|
+
* over-full. An underlying source ought to use this information to determine when and how to apply backpressure.
|
|
2757
|
+
*/
|
|
2473
2758
|
get desiredSize() {
|
|
2474
2759
|
if (!IsReadableStreamDefaultController(this)) {
|
|
2475
|
-
throw defaultControllerBrandCheckException('desiredSize');
|
|
2760
|
+
throw defaultControllerBrandCheckException$1('desiredSize');
|
|
2476
2761
|
}
|
|
2477
2762
|
return ReadableStreamDefaultControllerGetDesiredSize(this);
|
|
2478
2763
|
}
|
|
2764
|
+
/**
|
|
2765
|
+
* Closes the controlled readable stream. Consumers will still be able to read any previously-enqueued chunks from
|
|
2766
|
+
* the stream, but once those are read, the stream will become closed.
|
|
2767
|
+
*/
|
|
2479
2768
|
close() {
|
|
2480
2769
|
if (!IsReadableStreamDefaultController(this)) {
|
|
2481
|
-
throw defaultControllerBrandCheckException('close');
|
|
2770
|
+
throw defaultControllerBrandCheckException$1('close');
|
|
2482
2771
|
}
|
|
2483
2772
|
if (!ReadableStreamDefaultControllerCanCloseOrEnqueue(this)) {
|
|
2484
2773
|
throw new TypeError('The stream is not in a state that permits close');
|
|
@@ -2487,16 +2776,19 @@
|
|
|
2487
2776
|
}
|
|
2488
2777
|
enqueue(chunk = undefined) {
|
|
2489
2778
|
if (!IsReadableStreamDefaultController(this)) {
|
|
2490
|
-
throw defaultControllerBrandCheckException('enqueue');
|
|
2779
|
+
throw defaultControllerBrandCheckException$1('enqueue');
|
|
2491
2780
|
}
|
|
2492
2781
|
if (!ReadableStreamDefaultControllerCanCloseOrEnqueue(this)) {
|
|
2493
2782
|
throw new TypeError('The stream is not in a state that permits enqueue');
|
|
2494
2783
|
}
|
|
2495
2784
|
return ReadableStreamDefaultControllerEnqueue(this, chunk);
|
|
2496
2785
|
}
|
|
2786
|
+
/**
|
|
2787
|
+
* Errors the controlled readable stream, making all future interactions with it fail with the given error `e`.
|
|
2788
|
+
*/
|
|
2497
2789
|
error(e = undefined) {
|
|
2498
2790
|
if (!IsReadableStreamDefaultController(this)) {
|
|
2499
|
-
throw defaultControllerBrandCheckException('error');
|
|
2791
|
+
throw defaultControllerBrandCheckException$1('error');
|
|
2500
2792
|
}
|
|
2501
2793
|
ReadableStreamDefaultControllerError(this, e);
|
|
2502
2794
|
}
|
|
@@ -2547,7 +2839,7 @@
|
|
|
2547
2839
|
if (!Object.prototype.hasOwnProperty.call(x, '_controlledReadableStream')) {
|
|
2548
2840
|
return false;
|
|
2549
2841
|
}
|
|
2550
|
-
return
|
|
2842
|
+
return x instanceof ReadableStreamDefaultController;
|
|
2551
2843
|
}
|
|
2552
2844
|
function ReadableStreamDefaultControllerCallPullIfNeeded(controller) {
|
|
2553
2845
|
const shouldPull = ReadableStreamDefaultControllerShouldCallPull(controller);
|
|
@@ -2641,8 +2933,7 @@
|
|
|
2641
2933
|
ReadableStreamError(stream, e);
|
|
2642
2934
|
}
|
|
2643
2935
|
function ReadableStreamDefaultControllerGetDesiredSize(controller) {
|
|
2644
|
-
const
|
|
2645
|
-
const state = stream._state;
|
|
2936
|
+
const state = controller._controlledReadableStream._state;
|
|
2646
2937
|
if (state === 'errored') {
|
|
2647
2938
|
return null;
|
|
2648
2939
|
}
|
|
@@ -2704,11 +2995,17 @@
|
|
|
2704
2995
|
SetUpReadableStreamDefaultController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, sizeAlgorithm);
|
|
2705
2996
|
}
|
|
2706
2997
|
// Helper functions for the ReadableStreamDefaultController.
|
|
2707
|
-
function defaultControllerBrandCheckException(name) {
|
|
2998
|
+
function defaultControllerBrandCheckException$1(name) {
|
|
2708
2999
|
return new TypeError(`ReadableStreamDefaultController.prototype.${name} can only be used on a ReadableStreamDefaultController`);
|
|
2709
3000
|
}
|
|
2710
3001
|
|
|
2711
3002
|
function ReadableStreamTee(stream, cloneForBranch2) {
|
|
3003
|
+
if (IsReadableByteStreamController(stream._readableStreamController)) {
|
|
3004
|
+
return ReadableByteStreamTee(stream);
|
|
3005
|
+
}
|
|
3006
|
+
return ReadableStreamDefaultTee(stream);
|
|
3007
|
+
}
|
|
3008
|
+
function ReadableStreamDefaultTee(stream, cloneForBranch2) {
|
|
2712
3009
|
const reader = AcquireReadableStreamDefaultReader(stream);
|
|
2713
3010
|
let reading = false;
|
|
2714
3011
|
let canceled1 = false;
|
|
@@ -2727,24 +3024,24 @@
|
|
|
2727
3024
|
}
|
|
2728
3025
|
reading = true;
|
|
2729
3026
|
const readRequest = {
|
|
2730
|
-
_chunkSteps:
|
|
3027
|
+
_chunkSteps: chunk => {
|
|
2731
3028
|
// This needs to be delayed a microtask because it takes at least a microtask to detect errors (using
|
|
2732
3029
|
// reader._closedPromise below), and we want errors in stream to error both branches immediately. We cannot let
|
|
2733
3030
|
// successful synchronously-available reads get ahead of asynchronously-available errors.
|
|
2734
3031
|
queueMicrotask(() => {
|
|
2735
3032
|
reading = false;
|
|
2736
|
-
const
|
|
2737
|
-
const
|
|
3033
|
+
const chunk1 = chunk;
|
|
3034
|
+
const chunk2 = chunk;
|
|
2738
3035
|
// There is no way to access the cloning code right now in the reference implementation.
|
|
2739
3036
|
// If we add one then we'll need an implementation for serializable objects.
|
|
2740
3037
|
// if (!canceled2 && cloneForBranch2) {
|
|
2741
|
-
//
|
|
3038
|
+
// chunk2 = StructuredDeserialize(StructuredSerialize(chunk2));
|
|
2742
3039
|
// }
|
|
2743
3040
|
if (!canceled1) {
|
|
2744
|
-
ReadableStreamDefaultControllerEnqueue(branch1._readableStreamController,
|
|
3041
|
+
ReadableStreamDefaultControllerEnqueue(branch1._readableStreamController, chunk1);
|
|
2745
3042
|
}
|
|
2746
3043
|
if (!canceled2) {
|
|
2747
|
-
ReadableStreamDefaultControllerEnqueue(branch2._readableStreamController,
|
|
3044
|
+
ReadableStreamDefaultControllerEnqueue(branch2._readableStreamController, chunk2);
|
|
2748
3045
|
}
|
|
2749
3046
|
});
|
|
2750
3047
|
},
|
|
@@ -2756,6 +3053,9 @@
|
|
|
2756
3053
|
if (!canceled2) {
|
|
2757
3054
|
ReadableStreamDefaultControllerClose(branch2._readableStreamController);
|
|
2758
3055
|
}
|
|
3056
|
+
if (!canceled1 || !canceled2) {
|
|
3057
|
+
resolveCancelPromise(undefined);
|
|
3058
|
+
}
|
|
2759
3059
|
},
|
|
2760
3060
|
_errorSteps: () => {
|
|
2761
3061
|
reading = false;
|
|
@@ -2792,9 +3092,217 @@
|
|
|
2792
3092
|
uponRejection(reader._closedPromise, (r) => {
|
|
2793
3093
|
ReadableStreamDefaultControllerError(branch1._readableStreamController, r);
|
|
2794
3094
|
ReadableStreamDefaultControllerError(branch2._readableStreamController, r);
|
|
3095
|
+
if (!canceled1 || !canceled2) {
|
|
3096
|
+
resolveCancelPromise(undefined);
|
|
3097
|
+
}
|
|
2795
3098
|
});
|
|
2796
3099
|
return [branch1, branch2];
|
|
2797
3100
|
}
|
|
3101
|
+
function ReadableByteStreamTee(stream) {
|
|
3102
|
+
let reader = AcquireReadableStreamDefaultReader(stream);
|
|
3103
|
+
let reading = false;
|
|
3104
|
+
let canceled1 = false;
|
|
3105
|
+
let canceled2 = false;
|
|
3106
|
+
let reason1;
|
|
3107
|
+
let reason2;
|
|
3108
|
+
let branch1;
|
|
3109
|
+
let branch2;
|
|
3110
|
+
let resolveCancelPromise;
|
|
3111
|
+
const cancelPromise = newPromise(resolve => {
|
|
3112
|
+
resolveCancelPromise = resolve;
|
|
3113
|
+
});
|
|
3114
|
+
function forwardReaderError(thisReader) {
|
|
3115
|
+
uponRejection(thisReader._closedPromise, r => {
|
|
3116
|
+
if (thisReader !== reader) {
|
|
3117
|
+
return;
|
|
3118
|
+
}
|
|
3119
|
+
ReadableByteStreamControllerError(branch1._readableStreamController, r);
|
|
3120
|
+
ReadableByteStreamControllerError(branch2._readableStreamController, r);
|
|
3121
|
+
if (!canceled1 || !canceled2) {
|
|
3122
|
+
resolveCancelPromise(undefined);
|
|
3123
|
+
}
|
|
3124
|
+
});
|
|
3125
|
+
}
|
|
3126
|
+
function pullWithDefaultReader() {
|
|
3127
|
+
if (IsReadableStreamBYOBReader(reader)) {
|
|
3128
|
+
ReadableStreamReaderGenericRelease(reader);
|
|
3129
|
+
reader = AcquireReadableStreamDefaultReader(stream);
|
|
3130
|
+
forwardReaderError(reader);
|
|
3131
|
+
}
|
|
3132
|
+
const readRequest = {
|
|
3133
|
+
_chunkSteps: chunk => {
|
|
3134
|
+
// This needs to be delayed a microtask because it takes at least a microtask to detect errors (using
|
|
3135
|
+
// reader._closedPromise below), and we want errors in stream to error both branches immediately. We cannot let
|
|
3136
|
+
// successful synchronously-available reads get ahead of asynchronously-available errors.
|
|
3137
|
+
queueMicrotask(() => {
|
|
3138
|
+
reading = false;
|
|
3139
|
+
const chunk1 = chunk;
|
|
3140
|
+
let chunk2 = chunk;
|
|
3141
|
+
if (!canceled1 && !canceled2) {
|
|
3142
|
+
try {
|
|
3143
|
+
chunk2 = CloneAsUint8Array(chunk);
|
|
3144
|
+
}
|
|
3145
|
+
catch (cloneE) {
|
|
3146
|
+
ReadableByteStreamControllerError(branch1._readableStreamController, cloneE);
|
|
3147
|
+
ReadableByteStreamControllerError(branch2._readableStreamController, cloneE);
|
|
3148
|
+
resolveCancelPromise(ReadableStreamCancel(stream, cloneE));
|
|
3149
|
+
return;
|
|
3150
|
+
}
|
|
3151
|
+
}
|
|
3152
|
+
if (!canceled1) {
|
|
3153
|
+
ReadableByteStreamControllerEnqueue(branch1._readableStreamController, chunk1);
|
|
3154
|
+
}
|
|
3155
|
+
if (!canceled2) {
|
|
3156
|
+
ReadableByteStreamControllerEnqueue(branch2._readableStreamController, chunk2);
|
|
3157
|
+
}
|
|
3158
|
+
});
|
|
3159
|
+
},
|
|
3160
|
+
_closeSteps: () => {
|
|
3161
|
+
reading = false;
|
|
3162
|
+
if (!canceled1) {
|
|
3163
|
+
ReadableByteStreamControllerClose(branch1._readableStreamController);
|
|
3164
|
+
}
|
|
3165
|
+
if (!canceled2) {
|
|
3166
|
+
ReadableByteStreamControllerClose(branch2._readableStreamController);
|
|
3167
|
+
}
|
|
3168
|
+
if (branch1._readableStreamController._pendingPullIntos.length > 0) {
|
|
3169
|
+
ReadableByteStreamControllerRespond(branch1._readableStreamController, 0);
|
|
3170
|
+
}
|
|
3171
|
+
if (branch2._readableStreamController._pendingPullIntos.length > 0) {
|
|
3172
|
+
ReadableByteStreamControllerRespond(branch2._readableStreamController, 0);
|
|
3173
|
+
}
|
|
3174
|
+
if (!canceled1 || !canceled2) {
|
|
3175
|
+
resolveCancelPromise(undefined);
|
|
3176
|
+
}
|
|
3177
|
+
},
|
|
3178
|
+
_errorSteps: () => {
|
|
3179
|
+
reading = false;
|
|
3180
|
+
}
|
|
3181
|
+
};
|
|
3182
|
+
ReadableStreamDefaultReaderRead(reader, readRequest);
|
|
3183
|
+
}
|
|
3184
|
+
function pullWithBYOBReader(view, forBranch2) {
|
|
3185
|
+
if (IsReadableStreamDefaultReader(reader)) {
|
|
3186
|
+
ReadableStreamReaderGenericRelease(reader);
|
|
3187
|
+
reader = AcquireReadableStreamBYOBReader(stream);
|
|
3188
|
+
forwardReaderError(reader);
|
|
3189
|
+
}
|
|
3190
|
+
const byobBranch = forBranch2 ? branch2 : branch1;
|
|
3191
|
+
const otherBranch = forBranch2 ? branch1 : branch2;
|
|
3192
|
+
const readIntoRequest = {
|
|
3193
|
+
_chunkSteps: chunk => {
|
|
3194
|
+
// This needs to be delayed a microtask because it takes at least a microtask to detect errors (using
|
|
3195
|
+
// reader._closedPromise below), and we want errors in stream to error both branches immediately. We cannot let
|
|
3196
|
+
// successful synchronously-available reads get ahead of asynchronously-available errors.
|
|
3197
|
+
queueMicrotask(() => {
|
|
3198
|
+
reading = false;
|
|
3199
|
+
const byobCanceled = forBranch2 ? canceled2 : canceled1;
|
|
3200
|
+
const otherCanceled = forBranch2 ? canceled1 : canceled2;
|
|
3201
|
+
if (!otherCanceled) {
|
|
3202
|
+
let clonedChunk;
|
|
3203
|
+
try {
|
|
3204
|
+
clonedChunk = CloneAsUint8Array(chunk);
|
|
3205
|
+
}
|
|
3206
|
+
catch (cloneE) {
|
|
3207
|
+
ReadableByteStreamControllerError(byobBranch._readableStreamController, cloneE);
|
|
3208
|
+
ReadableByteStreamControllerError(otherBranch._readableStreamController, cloneE);
|
|
3209
|
+
resolveCancelPromise(ReadableStreamCancel(stream, cloneE));
|
|
3210
|
+
return;
|
|
3211
|
+
}
|
|
3212
|
+
if (!byobCanceled) {
|
|
3213
|
+
ReadableByteStreamControllerRespondWithNewView(byobBranch._readableStreamController, chunk);
|
|
3214
|
+
}
|
|
3215
|
+
ReadableByteStreamControllerEnqueue(otherBranch._readableStreamController, clonedChunk);
|
|
3216
|
+
}
|
|
3217
|
+
else if (!byobCanceled) {
|
|
3218
|
+
ReadableByteStreamControllerRespondWithNewView(byobBranch._readableStreamController, chunk);
|
|
3219
|
+
}
|
|
3220
|
+
});
|
|
3221
|
+
},
|
|
3222
|
+
_closeSteps: chunk => {
|
|
3223
|
+
reading = false;
|
|
3224
|
+
const byobCanceled = forBranch2 ? canceled2 : canceled1;
|
|
3225
|
+
const otherCanceled = forBranch2 ? canceled1 : canceled2;
|
|
3226
|
+
if (!byobCanceled) {
|
|
3227
|
+
ReadableByteStreamControllerClose(byobBranch._readableStreamController);
|
|
3228
|
+
}
|
|
3229
|
+
if (!otherCanceled) {
|
|
3230
|
+
ReadableByteStreamControllerClose(otherBranch._readableStreamController);
|
|
3231
|
+
}
|
|
3232
|
+
if (chunk !== undefined) {
|
|
3233
|
+
if (!byobCanceled) {
|
|
3234
|
+
ReadableByteStreamControllerRespondWithNewView(byobBranch._readableStreamController, chunk);
|
|
3235
|
+
}
|
|
3236
|
+
if (!otherCanceled && otherBranch._readableStreamController._pendingPullIntos.length > 0) {
|
|
3237
|
+
ReadableByteStreamControllerRespond(otherBranch._readableStreamController, 0);
|
|
3238
|
+
}
|
|
3239
|
+
}
|
|
3240
|
+
if (!byobCanceled || !otherCanceled) {
|
|
3241
|
+
resolveCancelPromise(undefined);
|
|
3242
|
+
}
|
|
3243
|
+
},
|
|
3244
|
+
_errorSteps: () => {
|
|
3245
|
+
reading = false;
|
|
3246
|
+
}
|
|
3247
|
+
};
|
|
3248
|
+
ReadableStreamBYOBReaderRead(reader, view, readIntoRequest);
|
|
3249
|
+
}
|
|
3250
|
+
function pull1Algorithm() {
|
|
3251
|
+
if (reading) {
|
|
3252
|
+
return promiseResolvedWith(undefined);
|
|
3253
|
+
}
|
|
3254
|
+
reading = true;
|
|
3255
|
+
const byobRequest = ReadableByteStreamControllerGetBYOBRequest(branch1._readableStreamController);
|
|
3256
|
+
if (byobRequest === null) {
|
|
3257
|
+
pullWithDefaultReader();
|
|
3258
|
+
}
|
|
3259
|
+
else {
|
|
3260
|
+
pullWithBYOBReader(byobRequest._view, false);
|
|
3261
|
+
}
|
|
3262
|
+
return promiseResolvedWith(undefined);
|
|
3263
|
+
}
|
|
3264
|
+
function pull2Algorithm() {
|
|
3265
|
+
if (reading) {
|
|
3266
|
+
return promiseResolvedWith(undefined);
|
|
3267
|
+
}
|
|
3268
|
+
reading = true;
|
|
3269
|
+
const byobRequest = ReadableByteStreamControllerGetBYOBRequest(branch2._readableStreamController);
|
|
3270
|
+
if (byobRequest === null) {
|
|
3271
|
+
pullWithDefaultReader();
|
|
3272
|
+
}
|
|
3273
|
+
else {
|
|
3274
|
+
pullWithBYOBReader(byobRequest._view, true);
|
|
3275
|
+
}
|
|
3276
|
+
return promiseResolvedWith(undefined);
|
|
3277
|
+
}
|
|
3278
|
+
function cancel1Algorithm(reason) {
|
|
3279
|
+
canceled1 = true;
|
|
3280
|
+
reason1 = reason;
|
|
3281
|
+
if (canceled2) {
|
|
3282
|
+
const compositeReason = CreateArrayFromList([reason1, reason2]);
|
|
3283
|
+
const cancelResult = ReadableStreamCancel(stream, compositeReason);
|
|
3284
|
+
resolveCancelPromise(cancelResult);
|
|
3285
|
+
}
|
|
3286
|
+
return cancelPromise;
|
|
3287
|
+
}
|
|
3288
|
+
function cancel2Algorithm(reason) {
|
|
3289
|
+
canceled2 = true;
|
|
3290
|
+
reason2 = reason;
|
|
3291
|
+
if (canceled1) {
|
|
3292
|
+
const compositeReason = CreateArrayFromList([reason1, reason2]);
|
|
3293
|
+
const cancelResult = ReadableStreamCancel(stream, compositeReason);
|
|
3294
|
+
resolveCancelPromise(cancelResult);
|
|
3295
|
+
}
|
|
3296
|
+
return cancelPromise;
|
|
3297
|
+
}
|
|
3298
|
+
function startAlgorithm() {
|
|
3299
|
+
return;
|
|
3300
|
+
}
|
|
3301
|
+
branch1 = CreateReadableByteStream(startAlgorithm, pull1Algorithm, cancel1Algorithm);
|
|
3302
|
+
branch2 = CreateReadableByteStream(startAlgorithm, pull2Algorithm, cancel2Algorithm);
|
|
3303
|
+
forwardReaderError(reader);
|
|
3304
|
+
return [branch1, branch2];
|
|
3305
|
+
}
|
|
2798
3306
|
|
|
2799
3307
|
function convertUnderlyingDefaultOrByteSource(source, context) {
|
|
2800
3308
|
assertDictionary(source, context);
|
|
@@ -2894,6 +3402,11 @@
|
|
|
2894
3402
|
return { readable, writable };
|
|
2895
3403
|
}
|
|
2896
3404
|
|
|
3405
|
+
/**
|
|
3406
|
+
* A readable stream represents a source of data, from which you can read.
|
|
3407
|
+
*
|
|
3408
|
+
* @public
|
|
3409
|
+
*/
|
|
2897
3410
|
class ReadableStream {
|
|
2898
3411
|
constructor(rawUnderlyingSource = {}, rawStrategy = {}) {
|
|
2899
3412
|
if (rawUnderlyingSource === undefined) {
|
|
@@ -2918,12 +3431,21 @@
|
|
|
2918
3431
|
SetUpReadableStreamDefaultControllerFromUnderlyingSource(this, underlyingSource, highWaterMark, sizeAlgorithm);
|
|
2919
3432
|
}
|
|
2920
3433
|
}
|
|
3434
|
+
/**
|
|
3435
|
+
* Whether or not the readable stream is locked to a {@link ReadableStreamDefaultReader | reader}.
|
|
3436
|
+
*/
|
|
2921
3437
|
get locked() {
|
|
2922
3438
|
if (!IsReadableStream(this)) {
|
|
2923
3439
|
throw streamBrandCheckException$1('locked');
|
|
2924
3440
|
}
|
|
2925
3441
|
return IsReadableStreamLocked(this);
|
|
2926
3442
|
}
|
|
3443
|
+
/**
|
|
3444
|
+
* Cancels the stream, signaling a loss of interest in the stream by a consumer.
|
|
3445
|
+
*
|
|
3446
|
+
* The supplied `reason` argument will be given to the underlying source's {@link UnderlyingSource.cancel | cancel()}
|
|
3447
|
+
* method, which might or might not use it.
|
|
3448
|
+
*/
|
|
2927
3449
|
cancel(reason = undefined) {
|
|
2928
3450
|
if (!IsReadableStream(this)) {
|
|
2929
3451
|
return promiseRejectedWith(streamBrandCheckException$1('cancel'));
|
|
@@ -2985,6 +3507,17 @@
|
|
|
2985
3507
|
}
|
|
2986
3508
|
return ReadableStreamPipeTo(this, destination, options.preventClose, options.preventAbort, options.preventCancel, options.signal);
|
|
2987
3509
|
}
|
|
3510
|
+
/**
|
|
3511
|
+
* Tees this readable stream, returning a two-element array containing the two resulting branches as
|
|
3512
|
+
* new {@link ReadableStream} instances.
|
|
3513
|
+
*
|
|
3514
|
+
* Teeing a stream will lock it, preventing any other consumer from acquiring a reader.
|
|
3515
|
+
* To cancel the stream, cancel both of the resulting branches; a composite cancellation reason will then be
|
|
3516
|
+
* propagated to the stream's underlying source.
|
|
3517
|
+
*
|
|
3518
|
+
* Note that the chunks seen in each branch will be the same object. If the chunks are not immutable,
|
|
3519
|
+
* this could allow interference between the two branches.
|
|
3520
|
+
*/
|
|
2988
3521
|
tee() {
|
|
2989
3522
|
if (!IsReadableStream(this)) {
|
|
2990
3523
|
throw streamBrandCheckException$1('tee');
|
|
@@ -3031,6 +3564,14 @@
|
|
|
3031
3564
|
SetUpReadableStreamDefaultController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, sizeAlgorithm);
|
|
3032
3565
|
return stream;
|
|
3033
3566
|
}
|
|
3567
|
+
// Throws if and only if startAlgorithm throws.
|
|
3568
|
+
function CreateReadableByteStream(startAlgorithm, pullAlgorithm, cancelAlgorithm) {
|
|
3569
|
+
const stream = Object.create(ReadableStream.prototype);
|
|
3570
|
+
InitializeReadableStream(stream);
|
|
3571
|
+
const controller = Object.create(ReadableByteStreamController.prototype);
|
|
3572
|
+
SetUpReadableByteStreamController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, 0, undefined);
|
|
3573
|
+
return stream;
|
|
3574
|
+
}
|
|
3034
3575
|
function InitializeReadableStream(stream) {
|
|
3035
3576
|
stream._state = 'readable';
|
|
3036
3577
|
stream._reader = undefined;
|
|
@@ -3044,7 +3585,7 @@
|
|
|
3044
3585
|
if (!Object.prototype.hasOwnProperty.call(x, '_readableStreamController')) {
|
|
3045
3586
|
return false;
|
|
3046
3587
|
}
|
|
3047
|
-
return
|
|
3588
|
+
return x instanceof ReadableStream;
|
|
3048
3589
|
}
|
|
3049
3590
|
function IsReadableStreamLocked(stream) {
|
|
3050
3591
|
if (stream._reader === undefined) {
|
|
@@ -3062,6 +3603,13 @@
|
|
|
3062
3603
|
return promiseRejectedWith(stream._storedError);
|
|
3063
3604
|
}
|
|
3064
3605
|
ReadableStreamClose(stream);
|
|
3606
|
+
const reader = stream._reader;
|
|
3607
|
+
if (reader !== undefined && IsReadableStreamBYOBReader(reader)) {
|
|
3608
|
+
reader._readIntoRequests.forEach(readIntoRequest => {
|
|
3609
|
+
readIntoRequest._closeSteps(undefined);
|
|
3610
|
+
});
|
|
3611
|
+
reader._readIntoRequests = new SimpleQueue();
|
|
3612
|
+
}
|
|
3065
3613
|
const sourceCancelPromise = stream._readableStreamController[CancelSteps](reason);
|
|
3066
3614
|
return transformPromiseWith(sourceCancelPromise, noop);
|
|
3067
3615
|
}
|
|
@@ -3071,13 +3619,13 @@
|
|
|
3071
3619
|
if (reader === undefined) {
|
|
3072
3620
|
return;
|
|
3073
3621
|
}
|
|
3622
|
+
defaultReaderClosedPromiseResolve(reader);
|
|
3074
3623
|
if (IsReadableStreamDefaultReader(reader)) {
|
|
3075
3624
|
reader._readRequests.forEach(readRequest => {
|
|
3076
3625
|
readRequest._closeSteps();
|
|
3077
3626
|
});
|
|
3078
3627
|
reader._readRequests = new SimpleQueue();
|
|
3079
3628
|
}
|
|
3080
|
-
defaultReaderClosedPromiseResolve(reader);
|
|
3081
3629
|
}
|
|
3082
3630
|
function ReadableStreamError(stream, e) {
|
|
3083
3631
|
stream._state = 'errored';
|
|
@@ -3086,6 +3634,7 @@
|
|
|
3086
3634
|
if (reader === undefined) {
|
|
3087
3635
|
return;
|
|
3088
3636
|
}
|
|
3637
|
+
defaultReaderClosedPromiseReject(reader, e);
|
|
3089
3638
|
if (IsReadableStreamDefaultReader(reader)) {
|
|
3090
3639
|
reader._readRequests.forEach(readRequest => {
|
|
3091
3640
|
readRequest._errorSteps(e);
|
|
@@ -3098,7 +3647,6 @@
|
|
|
3098
3647
|
});
|
|
3099
3648
|
reader._readIntoRequests = new SimpleQueue();
|
|
3100
3649
|
}
|
|
3101
|
-
defaultReaderClosedPromiseReject(reader, e);
|
|
3102
3650
|
}
|
|
3103
3651
|
// Helper functions for the ReadableStream.
|
|
3104
3652
|
function streamBrandCheckException$1(name) {
|
|
@@ -3114,21 +3662,37 @@
|
|
|
3114
3662
|
};
|
|
3115
3663
|
}
|
|
3116
3664
|
|
|
3117
|
-
|
|
3665
|
+
// The size function must not have a prototype property nor be a constructor
|
|
3666
|
+
const byteLengthSizeFunction = (chunk) => {
|
|
3118
3667
|
return chunk.byteLength;
|
|
3119
3668
|
};
|
|
3669
|
+
Object.defineProperty(byteLengthSizeFunction, 'name', {
|
|
3670
|
+
value: 'size',
|
|
3671
|
+
configurable: true
|
|
3672
|
+
});
|
|
3673
|
+
/**
|
|
3674
|
+
* A queuing strategy that counts the number of bytes in each chunk.
|
|
3675
|
+
*
|
|
3676
|
+
* @public
|
|
3677
|
+
*/
|
|
3120
3678
|
class ByteLengthQueuingStrategy {
|
|
3121
3679
|
constructor(options) {
|
|
3122
3680
|
assertRequiredArgument(options, 1, 'ByteLengthQueuingStrategy');
|
|
3123
3681
|
options = convertQueuingStrategyInit(options, 'First parameter');
|
|
3124
3682
|
this._byteLengthQueuingStrategyHighWaterMark = options.highWaterMark;
|
|
3125
3683
|
}
|
|
3684
|
+
/**
|
|
3685
|
+
* Returns the high water mark provided to the constructor.
|
|
3686
|
+
*/
|
|
3126
3687
|
get highWaterMark() {
|
|
3127
3688
|
if (!IsByteLengthQueuingStrategy(this)) {
|
|
3128
3689
|
throw byteLengthBrandCheckException('highWaterMark');
|
|
3129
3690
|
}
|
|
3130
3691
|
return this._byteLengthQueuingStrategyHighWaterMark;
|
|
3131
3692
|
}
|
|
3693
|
+
/**
|
|
3694
|
+
* Measures the size of `chunk` by returning the value of its `byteLength` property.
|
|
3695
|
+
*/
|
|
3132
3696
|
get size() {
|
|
3133
3697
|
if (!IsByteLengthQueuingStrategy(this)) {
|
|
3134
3698
|
throw byteLengthBrandCheckException('size');
|
|
@@ -3157,24 +3721,41 @@
|
|
|
3157
3721
|
if (!Object.prototype.hasOwnProperty.call(x, '_byteLengthQueuingStrategyHighWaterMark')) {
|
|
3158
3722
|
return false;
|
|
3159
3723
|
}
|
|
3160
|
-
return
|
|
3724
|
+
return x instanceof ByteLengthQueuingStrategy;
|
|
3161
3725
|
}
|
|
3162
3726
|
|
|
3163
|
-
|
|
3727
|
+
// The size function must not have a prototype property nor be a constructor
|
|
3728
|
+
const countSizeFunction = () => {
|
|
3164
3729
|
return 1;
|
|
3165
3730
|
};
|
|
3731
|
+
Object.defineProperty(countSizeFunction, 'name', {
|
|
3732
|
+
value: 'size',
|
|
3733
|
+
configurable: true
|
|
3734
|
+
});
|
|
3735
|
+
/**
|
|
3736
|
+
* A queuing strategy that counts the number of chunks.
|
|
3737
|
+
*
|
|
3738
|
+
* @public
|
|
3739
|
+
*/
|
|
3166
3740
|
class CountQueuingStrategy {
|
|
3167
3741
|
constructor(options) {
|
|
3168
3742
|
assertRequiredArgument(options, 1, 'CountQueuingStrategy');
|
|
3169
3743
|
options = convertQueuingStrategyInit(options, 'First parameter');
|
|
3170
3744
|
this._countQueuingStrategyHighWaterMark = options.highWaterMark;
|
|
3171
3745
|
}
|
|
3746
|
+
/**
|
|
3747
|
+
* Returns the high water mark provided to the constructor.
|
|
3748
|
+
*/
|
|
3172
3749
|
get highWaterMark() {
|
|
3173
3750
|
if (!IsCountQueuingStrategy(this)) {
|
|
3174
3751
|
throw countBrandCheckException('highWaterMark');
|
|
3175
3752
|
}
|
|
3176
3753
|
return this._countQueuingStrategyHighWaterMark;
|
|
3177
3754
|
}
|
|
3755
|
+
/**
|
|
3756
|
+
* Measures the size of `chunk` by always returning 1.
|
|
3757
|
+
* This ensures that the total queue size is a count of the number of chunks in the queue.
|
|
3758
|
+
*/
|
|
3178
3759
|
get size() {
|
|
3179
3760
|
if (!IsCountQueuingStrategy(this)) {
|
|
3180
3761
|
throw countBrandCheckException('size');
|
|
@@ -3203,7 +3784,7 @@
|
|
|
3203
3784
|
if (!Object.prototype.hasOwnProperty.call(x, '_countQueuingStrategyHighWaterMark')) {
|
|
3204
3785
|
return false;
|
|
3205
3786
|
}
|
|
3206
|
-
return
|
|
3787
|
+
return x instanceof CountQueuingStrategy;
|
|
3207
3788
|
}
|
|
3208
3789
|
|
|
3209
3790
|
function convertTransformer(original, context) {
|
|
@@ -3241,6 +3822,14 @@
|
|
|
3241
3822
|
}
|
|
3242
3823
|
|
|
3243
3824
|
// Class TransformStream
|
|
3825
|
+
/**
|
|
3826
|
+
* A transform stream consists of a pair of streams: a {@link WritableStream | writable stream},
|
|
3827
|
+
* known as its writable side, and a {@link ReadableStream | readable stream}, known as its readable side.
|
|
3828
|
+
* In a manner specific to the transform stream in question, writes to the writable side result in new data being
|
|
3829
|
+
* made available for reading from the readable side.
|
|
3830
|
+
*
|
|
3831
|
+
* @public
|
|
3832
|
+
*/
|
|
3244
3833
|
class TransformStream {
|
|
3245
3834
|
constructor(rawTransformer = {}, rawWritableStrategy = {}, rawReadableStrategy = {}) {
|
|
3246
3835
|
if (rawTransformer === undefined) {
|
|
@@ -3272,15 +3861,21 @@
|
|
|
3272
3861
|
startPromise_resolve(undefined);
|
|
3273
3862
|
}
|
|
3274
3863
|
}
|
|
3864
|
+
/**
|
|
3865
|
+
* The readable side of the transform stream.
|
|
3866
|
+
*/
|
|
3275
3867
|
get readable() {
|
|
3276
3868
|
if (!IsTransformStream(this)) {
|
|
3277
|
-
throw streamBrandCheckException
|
|
3869
|
+
throw streamBrandCheckException('readable');
|
|
3278
3870
|
}
|
|
3279
3871
|
return this._readable;
|
|
3280
3872
|
}
|
|
3873
|
+
/**
|
|
3874
|
+
* The writable side of the transform stream.
|
|
3875
|
+
*/
|
|
3281
3876
|
get writable() {
|
|
3282
3877
|
if (!IsTransformStream(this)) {
|
|
3283
|
-
throw streamBrandCheckException
|
|
3878
|
+
throw streamBrandCheckException('writable');
|
|
3284
3879
|
}
|
|
3285
3880
|
return this._writable;
|
|
3286
3881
|
}
|
|
@@ -3331,7 +3926,7 @@
|
|
|
3331
3926
|
if (!Object.prototype.hasOwnProperty.call(x, '_transformStreamController')) {
|
|
3332
3927
|
return false;
|
|
3333
3928
|
}
|
|
3334
|
-
return
|
|
3929
|
+
return x instanceof TransformStream;
|
|
3335
3930
|
}
|
|
3336
3931
|
// This is a no-op if both sides are already errored.
|
|
3337
3932
|
function TransformStreamError(stream, e) {
|
|
@@ -3359,32 +3954,48 @@
|
|
|
3359
3954
|
stream._backpressure = backpressure;
|
|
3360
3955
|
}
|
|
3361
3956
|
// Class TransformStreamDefaultController
|
|
3957
|
+
/**
|
|
3958
|
+
* Allows control of the {@link ReadableStream} and {@link WritableStream} of the associated {@link TransformStream}.
|
|
3959
|
+
*
|
|
3960
|
+
* @public
|
|
3961
|
+
*/
|
|
3362
3962
|
class TransformStreamDefaultController {
|
|
3363
3963
|
constructor() {
|
|
3364
3964
|
throw new TypeError('Illegal constructor');
|
|
3365
3965
|
}
|
|
3966
|
+
/**
|
|
3967
|
+
* Returns the desired size to fill the readable side’s internal queue. It can be negative, if the queue is over-full.
|
|
3968
|
+
*/
|
|
3366
3969
|
get desiredSize() {
|
|
3367
3970
|
if (!IsTransformStreamDefaultController(this)) {
|
|
3368
|
-
throw defaultControllerBrandCheckException
|
|
3971
|
+
throw defaultControllerBrandCheckException('desiredSize');
|
|
3369
3972
|
}
|
|
3370
3973
|
const readableController = this._controlledTransformStream._readable._readableStreamController;
|
|
3371
3974
|
return ReadableStreamDefaultControllerGetDesiredSize(readableController);
|
|
3372
3975
|
}
|
|
3373
3976
|
enqueue(chunk = undefined) {
|
|
3374
3977
|
if (!IsTransformStreamDefaultController(this)) {
|
|
3375
|
-
throw defaultControllerBrandCheckException
|
|
3978
|
+
throw defaultControllerBrandCheckException('enqueue');
|
|
3376
3979
|
}
|
|
3377
3980
|
TransformStreamDefaultControllerEnqueue(this, chunk);
|
|
3378
3981
|
}
|
|
3982
|
+
/**
|
|
3983
|
+
* Errors both the readable side and the writable side of the controlled transform stream, making all future
|
|
3984
|
+
* interactions with it fail with the given error `e`. Any chunks queued for transformation will be discarded.
|
|
3985
|
+
*/
|
|
3379
3986
|
error(reason = undefined) {
|
|
3380
3987
|
if (!IsTransformStreamDefaultController(this)) {
|
|
3381
|
-
throw defaultControllerBrandCheckException
|
|
3988
|
+
throw defaultControllerBrandCheckException('error');
|
|
3382
3989
|
}
|
|
3383
3990
|
TransformStreamDefaultControllerError(this, reason);
|
|
3384
3991
|
}
|
|
3992
|
+
/**
|
|
3993
|
+
* Closes the readable side and errors the writable side of the controlled transform stream. This is useful when the
|
|
3994
|
+
* transformer only needs to consume a portion of the chunks written to the writable side.
|
|
3995
|
+
*/
|
|
3385
3996
|
terminate() {
|
|
3386
3997
|
if (!IsTransformStreamDefaultController(this)) {
|
|
3387
|
-
throw defaultControllerBrandCheckException
|
|
3998
|
+
throw defaultControllerBrandCheckException('terminate');
|
|
3388
3999
|
}
|
|
3389
4000
|
TransformStreamDefaultControllerTerminate(this);
|
|
3390
4001
|
}
|
|
@@ -3409,7 +4020,7 @@
|
|
|
3409
4020
|
if (!Object.prototype.hasOwnProperty.call(x, '_controlledTransformStream')) {
|
|
3410
4021
|
return false;
|
|
3411
4022
|
}
|
|
3412
|
-
return
|
|
4023
|
+
return x instanceof TransformStreamDefaultController;
|
|
3413
4024
|
}
|
|
3414
4025
|
function SetUpTransformStreamDefaultController(stream, controller, transformAlgorithm, flushAlgorithm) {
|
|
3415
4026
|
controller._controlledTransformStream = stream;
|
|
@@ -3526,11 +4137,11 @@
|
|
|
3526
4137
|
return stream._backpressureChangePromise;
|
|
3527
4138
|
}
|
|
3528
4139
|
// Helper functions for the TransformStreamDefaultController.
|
|
3529
|
-
function defaultControllerBrandCheckException
|
|
4140
|
+
function defaultControllerBrandCheckException(name) {
|
|
3530
4141
|
return new TypeError(`TransformStreamDefaultController.prototype.${name} can only be used on a TransformStreamDefaultController`);
|
|
3531
4142
|
}
|
|
3532
4143
|
// Helper functions for the TransformStream.
|
|
3533
|
-
function streamBrandCheckException
|
|
4144
|
+
function streamBrandCheckException(name) {
|
|
3534
4145
|
return new TypeError(`TransformStream.prototype.${name} can only be used on a TransformStream`);
|
|
3535
4146
|
}
|
|
3536
4147
|
|