web-streams-polyfill 3.0.3 → 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 +10 -2
- package/README.md +10 -6
- package/dist/polyfill.es2018.js +424 -99
- 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 +424 -99
- package/dist/polyfill.es2018.mjs.map +1 -1
- package/dist/polyfill.es6.js +424 -99
- 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 +424 -99
- package/dist/polyfill.es6.mjs.map +1 -1
- package/dist/polyfill.js +432 -99
- 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 +432 -99
- package/dist/polyfill.mjs.map +1 -1
- package/dist/ponyfill.es2018.js +424 -99
- package/dist/ponyfill.es2018.js.map +1 -1
- package/dist/ponyfill.es2018.mjs +424 -99
- package/dist/ponyfill.es2018.mjs.map +1 -1
- package/dist/ponyfill.es6.js +424 -99
- package/dist/ponyfill.es6.js.map +1 -1
- package/dist/ponyfill.es6.mjs +424 -99
- package/dist/ponyfill.es6.mjs.map +1 -1
- package/dist/ponyfill.js +432 -99
- package/dist/ponyfill.js.map +1 -1
- package/dist/ponyfill.mjs +432 -99
- package/dist/ponyfill.mjs.map +1 -1
- package/dist/types/polyfill.d.ts +15 -2
- package/dist/types/ts3.6/polyfill.d.ts +15 -2
- package/package.json +1 -1
package/dist/ponyfill.es2018.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* web-streams-polyfill v3.0
|
|
2
|
+
* web-streams-polyfill v3.1.0
|
|
3
3
|
*/
|
|
4
4
|
(function (global, factory) {
|
|
5
5
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
@@ -494,7 +494,7 @@
|
|
|
494
494
|
if (!Object.prototype.hasOwnProperty.call(x, '_readRequests')) {
|
|
495
495
|
return false;
|
|
496
496
|
}
|
|
497
|
-
return
|
|
497
|
+
return x instanceof ReadableStreamDefaultReader;
|
|
498
498
|
}
|
|
499
499
|
function ReadableStreamDefaultReaderRead(reader, readRequest) {
|
|
500
500
|
const stream = reader._ownerReadableStream;
|
|
@@ -626,7 +626,14 @@
|
|
|
626
626
|
if (!Object.prototype.hasOwnProperty.call(x, '_asyncIteratorImpl')) {
|
|
627
627
|
return false;
|
|
628
628
|
}
|
|
629
|
-
|
|
629
|
+
try {
|
|
630
|
+
// noinspection SuspiciousTypeOfGuard
|
|
631
|
+
return x._asyncIteratorImpl instanceof
|
|
632
|
+
ReadableStreamAsyncIteratorImpl;
|
|
633
|
+
}
|
|
634
|
+
catch (_a) {
|
|
635
|
+
return false;
|
|
636
|
+
}
|
|
630
637
|
}
|
|
631
638
|
// Helper functions for the ReadableStream.
|
|
632
639
|
function streamAsyncIteratorBrandCheckException(name) {
|
|
@@ -640,15 +647,35 @@
|
|
|
640
647
|
return x !== x;
|
|
641
648
|
};
|
|
642
649
|
|
|
643
|
-
function
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
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);
|
|
649
672
|
}
|
|
650
|
-
|
|
673
|
+
const length = end - begin;
|
|
674
|
+
const slice = new ArrayBuffer(length);
|
|
675
|
+
CopyDataBlockBytes(slice, 0, buffer, begin, length);
|
|
676
|
+
return slice;
|
|
651
677
|
}
|
|
678
|
+
|
|
652
679
|
function IsNonNegativeNumber(v) {
|
|
653
680
|
if (typeof v !== 'number') {
|
|
654
681
|
return false;
|
|
@@ -661,6 +688,10 @@
|
|
|
661
688
|
}
|
|
662
689
|
return true;
|
|
663
690
|
}
|
|
691
|
+
function CloneAsUint8Array(O) {
|
|
692
|
+
const buffer = ArrayBufferSlice(O.buffer, O.byteOffset, O.byteOffset + O.byteLength);
|
|
693
|
+
return new Uint8Array(buffer);
|
|
694
|
+
}
|
|
664
695
|
|
|
665
696
|
function DequeueValue(container) {
|
|
666
697
|
const pair = container._queue.shift();
|
|
@@ -671,8 +702,7 @@
|
|
|
671
702
|
return pair.value;
|
|
672
703
|
}
|
|
673
704
|
function EnqueueValueWithSize(container, value, size) {
|
|
674
|
-
size
|
|
675
|
-
if (!IsFiniteNonNegativeNumber(size)) {
|
|
705
|
+
if (!IsNonNegativeNumber(size) || size === Infinity) {
|
|
676
706
|
throw new RangeError('Size must be a finite, non-NaN, non-negative number.');
|
|
677
707
|
}
|
|
678
708
|
container._queue.push({ value, size });
|
|
@@ -687,23 +717,6 @@
|
|
|
687
717
|
container._queueTotalSize = 0;
|
|
688
718
|
}
|
|
689
719
|
|
|
690
|
-
function CreateArrayFromList(elements) {
|
|
691
|
-
// We use arrays to represent lists, so this is basically a no-op.
|
|
692
|
-
// Do a slice though just in case we happen to depend on the unique-ness.
|
|
693
|
-
return elements.slice();
|
|
694
|
-
}
|
|
695
|
-
function CopyDataBlockBytes(dest, destOffset, src, srcOffset, n) {
|
|
696
|
-
new Uint8Array(dest).set(new Uint8Array(src, srcOffset, n), destOffset);
|
|
697
|
-
}
|
|
698
|
-
// Not implemented correctly
|
|
699
|
-
function TransferArrayBuffer(O) {
|
|
700
|
-
return O;
|
|
701
|
-
}
|
|
702
|
-
// Not implemented correctly
|
|
703
|
-
function IsDetachedBuffer(O) {
|
|
704
|
-
return false;
|
|
705
|
-
}
|
|
706
|
-
|
|
707
720
|
/**
|
|
708
721
|
* A pull-into request in a {@link ReadableByteStreamController}.
|
|
709
722
|
*
|
|
@@ -742,15 +755,10 @@
|
|
|
742
755
|
if (!ArrayBuffer.isView(view)) {
|
|
743
756
|
throw new TypeError('You can only respond with array buffer views');
|
|
744
757
|
}
|
|
745
|
-
if (view.byteLength === 0) {
|
|
746
|
-
throw new TypeError('chunk must have non-zero byteLength');
|
|
747
|
-
}
|
|
748
|
-
if (view.buffer.byteLength === 0) {
|
|
749
|
-
throw new TypeError(`chunk's buffer must have non-zero byteLength`);
|
|
750
|
-
}
|
|
751
758
|
if (this._associatedReadableByteStreamController === undefined) {
|
|
752
759
|
throw new TypeError('This BYOB request has been invalidated');
|
|
753
760
|
}
|
|
761
|
+
if (IsDetachedBuffer(view.buffer)) ;
|
|
754
762
|
ReadableByteStreamControllerRespondWithNewView(this._associatedReadableByteStreamController, view);
|
|
755
763
|
}
|
|
756
764
|
}
|
|
@@ -781,14 +789,7 @@
|
|
|
781
789
|
if (!IsReadableByteStreamController(this)) {
|
|
782
790
|
throw byteStreamControllerBrandCheckException('byobRequest');
|
|
783
791
|
}
|
|
784
|
-
|
|
785
|
-
const firstDescriptor = this._pendingPullIntos.peek();
|
|
786
|
-
const view = new Uint8Array(firstDescriptor.buffer, firstDescriptor.byteOffset + firstDescriptor.bytesFilled, firstDescriptor.byteLength - firstDescriptor.bytesFilled);
|
|
787
|
-
const byobRequest = Object.create(ReadableStreamBYOBRequest.prototype);
|
|
788
|
-
SetUpReadableStreamBYOBRequest(byobRequest, this, view);
|
|
789
|
-
this._byobRequest = byobRequest;
|
|
790
|
-
}
|
|
791
|
-
return this._byobRequest;
|
|
792
|
+
return ReadableByteStreamControllerGetBYOBRequest(this);
|
|
792
793
|
}
|
|
793
794
|
/**
|
|
794
795
|
* Returns the desired size to fill the controlled stream's internal queue. It can be negative, if the queue is
|
|
@@ -851,10 +852,7 @@
|
|
|
851
852
|
}
|
|
852
853
|
/** @internal */
|
|
853
854
|
[CancelSteps](reason) {
|
|
854
|
-
|
|
855
|
-
const firstDescriptor = this._pendingPullIntos.peek();
|
|
856
|
-
firstDescriptor.bytesFilled = 0;
|
|
857
|
-
}
|
|
855
|
+
ReadableByteStreamControllerClearPendingPullIntos(this);
|
|
858
856
|
ResetQueue(this);
|
|
859
857
|
const result = this._cancelAlgorithm(reason);
|
|
860
858
|
ReadableByteStreamControllerClearAlgorithms(this);
|
|
@@ -883,6 +881,7 @@
|
|
|
883
881
|
}
|
|
884
882
|
const pullIntoDescriptor = {
|
|
885
883
|
buffer,
|
|
884
|
+
bufferByteLength: autoAllocateChunkSize,
|
|
886
885
|
byteOffset: 0,
|
|
887
886
|
byteLength: autoAllocateChunkSize,
|
|
888
887
|
bytesFilled: 0,
|
|
@@ -917,7 +916,7 @@
|
|
|
917
916
|
if (!Object.prototype.hasOwnProperty.call(x, '_controlledReadableByteStream')) {
|
|
918
917
|
return false;
|
|
919
918
|
}
|
|
920
|
-
return
|
|
919
|
+
return x instanceof ReadableByteStreamController;
|
|
921
920
|
}
|
|
922
921
|
function IsReadableStreamBYOBRequest(x) {
|
|
923
922
|
if (!typeIsObject(x)) {
|
|
@@ -926,7 +925,7 @@
|
|
|
926
925
|
if (!Object.prototype.hasOwnProperty.call(x, '_associatedReadableByteStreamController')) {
|
|
927
926
|
return false;
|
|
928
927
|
}
|
|
929
|
-
return
|
|
928
|
+
return x instanceof ReadableStreamBYOBRequest;
|
|
930
929
|
}
|
|
931
930
|
function ReadableByteStreamControllerCallPullIfNeeded(controller) {
|
|
932
931
|
const shouldPull = ReadableByteStreamControllerShouldCallPull(controller);
|
|
@@ -1008,7 +1007,6 @@
|
|
|
1008
1007
|
return ready;
|
|
1009
1008
|
}
|
|
1010
1009
|
function ReadableByteStreamControllerFillHeadPullIntoDescriptor(controller, size, pullIntoDescriptor) {
|
|
1011
|
-
ReadableByteStreamControllerInvalidateBYOBRequest(controller);
|
|
1012
1010
|
pullIntoDescriptor.bytesFilled += size;
|
|
1013
1011
|
}
|
|
1014
1012
|
function ReadableByteStreamControllerHandleQueueDrain(controller) {
|
|
@@ -1047,9 +1045,15 @@
|
|
|
1047
1045
|
elementSize = view.constructor.BYTES_PER_ELEMENT;
|
|
1048
1046
|
}
|
|
1049
1047
|
const ctor = view.constructor;
|
|
1048
|
+
// try {
|
|
1050
1049
|
const buffer = TransferArrayBuffer(view.buffer);
|
|
1050
|
+
// } catch (e) {
|
|
1051
|
+
// readIntoRequest._errorSteps(e);
|
|
1052
|
+
// return;
|
|
1053
|
+
// }
|
|
1051
1054
|
const pullIntoDescriptor = {
|
|
1052
1055
|
buffer,
|
|
1056
|
+
bufferByteLength: buffer.byteLength,
|
|
1053
1057
|
byteOffset: view.byteOffset,
|
|
1054
1058
|
byteLength: view.byteLength,
|
|
1055
1059
|
bytesFilled: 0,
|
|
@@ -1089,7 +1093,6 @@
|
|
|
1089
1093
|
ReadableByteStreamControllerCallPullIfNeeded(controller);
|
|
1090
1094
|
}
|
|
1091
1095
|
function ReadableByteStreamControllerRespondInClosedState(controller, firstDescriptor) {
|
|
1092
|
-
firstDescriptor.buffer = TransferArrayBuffer(firstDescriptor.buffer);
|
|
1093
1096
|
const stream = controller._controlledReadableByteStream;
|
|
1094
1097
|
if (ReadableStreamHasBYOBReader(stream)) {
|
|
1095
1098
|
while (ReadableStreamGetNumReadIntoRequests(stream) > 0) {
|
|
@@ -1099,34 +1102,27 @@
|
|
|
1099
1102
|
}
|
|
1100
1103
|
}
|
|
1101
1104
|
function ReadableByteStreamControllerRespondInReadableState(controller, bytesWritten, pullIntoDescriptor) {
|
|
1102
|
-
if (pullIntoDescriptor.bytesFilled + bytesWritten > pullIntoDescriptor.byteLength) {
|
|
1103
|
-
throw new RangeError('bytesWritten out of range');
|
|
1104
|
-
}
|
|
1105
1105
|
ReadableByteStreamControllerFillHeadPullIntoDescriptor(controller, bytesWritten, pullIntoDescriptor);
|
|
1106
1106
|
if (pullIntoDescriptor.bytesFilled < pullIntoDescriptor.elementSize) {
|
|
1107
|
-
// TODO: Figure out whether we should detach the buffer or not here.
|
|
1108
1107
|
return;
|
|
1109
1108
|
}
|
|
1110
1109
|
ReadableByteStreamControllerShiftPendingPullInto(controller);
|
|
1111
1110
|
const remainderSize = pullIntoDescriptor.bytesFilled % pullIntoDescriptor.elementSize;
|
|
1112
1111
|
if (remainderSize > 0) {
|
|
1113
1112
|
const end = pullIntoDescriptor.byteOffset + pullIntoDescriptor.bytesFilled;
|
|
1114
|
-
const remainder = pullIntoDescriptor.buffer
|
|
1113
|
+
const remainder = ArrayBufferSlice(pullIntoDescriptor.buffer, end - remainderSize, end);
|
|
1115
1114
|
ReadableByteStreamControllerEnqueueChunkToQueue(controller, remainder, 0, remainder.byteLength);
|
|
1116
1115
|
}
|
|
1117
|
-
pullIntoDescriptor.buffer = TransferArrayBuffer(pullIntoDescriptor.buffer);
|
|
1118
1116
|
pullIntoDescriptor.bytesFilled -= remainderSize;
|
|
1119
1117
|
ReadableByteStreamControllerCommitPullIntoDescriptor(controller._controlledReadableByteStream, pullIntoDescriptor);
|
|
1120
1118
|
ReadableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(controller);
|
|
1121
1119
|
}
|
|
1122
1120
|
function ReadableByteStreamControllerRespondInternal(controller, bytesWritten) {
|
|
1123
1121
|
const firstDescriptor = controller._pendingPullIntos.peek();
|
|
1122
|
+
ReadableByteStreamControllerInvalidateBYOBRequest(controller);
|
|
1124
1123
|
const state = controller._controlledReadableByteStream._state;
|
|
1125
1124
|
if (state === 'closed') {
|
|
1126
|
-
|
|
1127
|
-
throw new TypeError('bytesWritten must be 0 when calling respond() on a closed stream');
|
|
1128
|
-
}
|
|
1129
|
-
ReadableByteStreamControllerRespondInClosedState(controller, firstDescriptor);
|
|
1125
|
+
ReadableByteStreamControllerRespondInClosedState(controller);
|
|
1130
1126
|
}
|
|
1131
1127
|
else {
|
|
1132
1128
|
ReadableByteStreamControllerRespondInReadableState(controller, bytesWritten, firstDescriptor);
|
|
@@ -1135,7 +1131,6 @@
|
|
|
1135
1131
|
}
|
|
1136
1132
|
function ReadableByteStreamControllerShiftPendingPullInto(controller) {
|
|
1137
1133
|
const descriptor = controller._pendingPullIntos.shift();
|
|
1138
|
-
ReadableByteStreamControllerInvalidateBYOBRequest(controller);
|
|
1139
1134
|
return descriptor;
|
|
1140
1135
|
}
|
|
1141
1136
|
function ReadableByteStreamControllerShouldCallPull(controller) {
|
|
@@ -1195,6 +1190,12 @@
|
|
|
1195
1190
|
const byteOffset = chunk.byteOffset;
|
|
1196
1191
|
const byteLength = chunk.byteLength;
|
|
1197
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);
|
|
1198
1199
|
if (ReadableStreamHasDefaultReader(stream)) {
|
|
1199
1200
|
if (ReadableStreamGetNumReadRequests(stream) === 0) {
|
|
1200
1201
|
ReadableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset, byteLength);
|
|
@@ -1224,6 +1225,16 @@
|
|
|
1224
1225
|
ReadableByteStreamControllerClearAlgorithms(controller);
|
|
1225
1226
|
ReadableStreamError(stream, e);
|
|
1226
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
|
+
}
|
|
1227
1238
|
function ReadableByteStreamControllerGetDesiredSize(controller) {
|
|
1228
1239
|
const state = controller._controlledReadableByteStream._state;
|
|
1229
1240
|
if (state === 'errored') {
|
|
@@ -1235,21 +1246,47 @@
|
|
|
1235
1246
|
return controller._strategyHWM - controller._queueTotalSize;
|
|
1236
1247
|
}
|
|
1237
1248
|
function ReadableByteStreamControllerRespond(controller, bytesWritten) {
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
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
|
+
}
|
|
1241
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
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
firstDescriptor.buffer = TransferArrayBuffer(firstDescriptor.buffer);
|
|
1242
1265
|
ReadableByteStreamControllerRespondInternal(controller, bytesWritten);
|
|
1243
1266
|
}
|
|
1244
1267
|
function ReadableByteStreamControllerRespondWithNewView(controller, view) {
|
|
1245
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
|
+
}
|
|
1246
1280
|
if (firstDescriptor.byteOffset + firstDescriptor.bytesFilled !== view.byteOffset) {
|
|
1247
1281
|
throw new RangeError('The region specified by view does not match byobRequest');
|
|
1248
1282
|
}
|
|
1249
|
-
if (firstDescriptor.
|
|
1283
|
+
if (firstDescriptor.bufferByteLength !== view.buffer.byteLength) {
|
|
1250
1284
|
throw new RangeError('The buffer of view has different capacity than byobRequest');
|
|
1251
1285
|
}
|
|
1252
|
-
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);
|
|
1253
1290
|
ReadableByteStreamControllerRespondInternal(controller, view.byteLength);
|
|
1254
1291
|
}
|
|
1255
1292
|
function SetUpReadableByteStreamController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, autoAllocateChunkSize) {
|
|
@@ -1399,6 +1436,7 @@
|
|
|
1399
1436
|
if (view.buffer.byteLength === 0) {
|
|
1400
1437
|
return promiseRejectedWith(new TypeError(`view's buffer must have non-zero byteLength`));
|
|
1401
1438
|
}
|
|
1439
|
+
if (IsDetachedBuffer(view.buffer)) ;
|
|
1402
1440
|
if (this._ownerReadableStream === undefined) {
|
|
1403
1441
|
return promiseRejectedWith(readerLockException('read from'));
|
|
1404
1442
|
}
|
|
@@ -1458,7 +1496,7 @@
|
|
|
1458
1496
|
if (!Object.prototype.hasOwnProperty.call(x, '_readIntoRequests')) {
|
|
1459
1497
|
return false;
|
|
1460
1498
|
}
|
|
1461
|
-
return
|
|
1499
|
+
return x instanceof ReadableStreamBYOBReader;
|
|
1462
1500
|
}
|
|
1463
1501
|
function ReadableStreamBYOBReaderRead(reader, view, readIntoRequest) {
|
|
1464
1502
|
const stream = reader._ownerReadableStream;
|
|
@@ -1553,6 +1591,31 @@
|
|
|
1553
1591
|
}
|
|
1554
1592
|
}
|
|
1555
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
|
+
|
|
1556
1619
|
/**
|
|
1557
1620
|
* A writable stream represents a destination for data, into which you can write.
|
|
1558
1621
|
*
|
|
@@ -1696,7 +1759,7 @@
|
|
|
1696
1759
|
if (!Object.prototype.hasOwnProperty.call(x, '_writableStreamController')) {
|
|
1697
1760
|
return false;
|
|
1698
1761
|
}
|
|
1699
|
-
return
|
|
1762
|
+
return x instanceof WritableStream;
|
|
1700
1763
|
}
|
|
1701
1764
|
function IsWritableStreamLocked(stream) {
|
|
1702
1765
|
if (stream._writer === undefined) {
|
|
@@ -1705,6 +1768,15 @@
|
|
|
1705
1768
|
return true;
|
|
1706
1769
|
}
|
|
1707
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.
|
|
1708
1780
|
const state = stream._state;
|
|
1709
1781
|
if (state === 'closed' || state === 'errored') {
|
|
1710
1782
|
return promiseResolvedWith(undefined);
|
|
@@ -2050,7 +2122,7 @@
|
|
|
2050
2122
|
if (!Object.prototype.hasOwnProperty.call(x, '_ownerWritableStream')) {
|
|
2051
2123
|
return false;
|
|
2052
2124
|
}
|
|
2053
|
-
return
|
|
2125
|
+
return x instanceof WritableStreamDefaultWriter;
|
|
2054
2126
|
}
|
|
2055
2127
|
// A client of WritableStreamDefaultWriter may use these functions directly to bypass state check.
|
|
2056
2128
|
function WritableStreamDefaultWriterAbort(writer, reason) {
|
|
@@ -2140,6 +2212,30 @@
|
|
|
2140
2212
|
constructor() {
|
|
2141
2213
|
throw new TypeError('Illegal constructor');
|
|
2142
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
|
+
}
|
|
2143
2239
|
/**
|
|
2144
2240
|
* Closes the controlled writable stream, making all future interactions with it fail with the given error `e`.
|
|
2145
2241
|
*
|
|
@@ -2149,7 +2245,7 @@
|
|
|
2149
2245
|
*/
|
|
2150
2246
|
error(e = undefined) {
|
|
2151
2247
|
if (!IsWritableStreamDefaultController(this)) {
|
|
2152
|
-
throw
|
|
2248
|
+
throw defaultControllerBrandCheckException$2('error');
|
|
2153
2249
|
}
|
|
2154
2250
|
const state = this._controlledWritableStream._state;
|
|
2155
2251
|
if (state !== 'writable') {
|
|
@@ -2187,7 +2283,7 @@
|
|
|
2187
2283
|
if (!Object.prototype.hasOwnProperty.call(x, '_controlledWritableStream')) {
|
|
2188
2284
|
return false;
|
|
2189
2285
|
}
|
|
2190
|
-
return
|
|
2286
|
+
return x instanceof WritableStreamDefaultController;
|
|
2191
2287
|
}
|
|
2192
2288
|
function SetUpWritableStreamDefaultController(stream, controller, startAlgorithm, writeAlgorithm, closeAlgorithm, abortAlgorithm, highWaterMark, sizeAlgorithm) {
|
|
2193
2289
|
controller._controlledWritableStream = stream;
|
|
@@ -2196,6 +2292,8 @@
|
|
|
2196
2292
|
controller._queue = undefined;
|
|
2197
2293
|
controller._queueTotalSize = undefined;
|
|
2198
2294
|
ResetQueue(controller);
|
|
2295
|
+
controller._abortReason = undefined;
|
|
2296
|
+
controller._abortController = createAbortController();
|
|
2199
2297
|
controller._started = false;
|
|
2200
2298
|
controller._strategySizeAlgorithm = sizeAlgorithm;
|
|
2201
2299
|
controller._strategyHWM = highWaterMark;
|
|
@@ -2348,6 +2446,10 @@
|
|
|
2348
2446
|
function streamBrandCheckException$2(name) {
|
|
2349
2447
|
return new TypeError(`WritableStream.prototype.${name} can only be used on a WritableStream`);
|
|
2350
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
|
+
}
|
|
2351
2453
|
// Helper functions for the WritableStreamDefaultWriter.
|
|
2352
2454
|
function defaultWriterBrandCheckException(name) {
|
|
2353
2455
|
return new TypeError(`WritableStreamDefaultWriter.prototype.${name} can only be used on a WritableStreamDefaultWriter`);
|
|
@@ -2433,19 +2535,6 @@
|
|
|
2433
2535
|
writer._readyPromiseState = 'fulfilled';
|
|
2434
2536
|
}
|
|
2435
2537
|
|
|
2436
|
-
function isAbortSignal(value) {
|
|
2437
|
-
if (typeof value !== 'object' || value === null) {
|
|
2438
|
-
return false;
|
|
2439
|
-
}
|
|
2440
|
-
try {
|
|
2441
|
-
return typeof value.aborted === 'boolean';
|
|
2442
|
-
}
|
|
2443
|
-
catch (_a) {
|
|
2444
|
-
// AbortSignal.prototype.aborted throws if its brand check fails
|
|
2445
|
-
return false;
|
|
2446
|
-
}
|
|
2447
|
-
}
|
|
2448
|
-
|
|
2449
2538
|
/// <reference lib="dom" />
|
|
2450
2539
|
const NativeDOMException = typeof DOMException !== 'undefined' ? DOMException : undefined;
|
|
2451
2540
|
|
|
@@ -2750,7 +2839,7 @@
|
|
|
2750
2839
|
if (!Object.prototype.hasOwnProperty.call(x, '_controlledReadableStream')) {
|
|
2751
2840
|
return false;
|
|
2752
2841
|
}
|
|
2753
|
-
return
|
|
2842
|
+
return x instanceof ReadableStreamDefaultController;
|
|
2754
2843
|
}
|
|
2755
2844
|
function ReadableStreamDefaultControllerCallPullIfNeeded(controller) {
|
|
2756
2845
|
const shouldPull = ReadableStreamDefaultControllerShouldCallPull(controller);
|
|
@@ -2911,6 +3000,12 @@
|
|
|
2911
3000
|
}
|
|
2912
3001
|
|
|
2913
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) {
|
|
2914
3009
|
const reader = AcquireReadableStreamDefaultReader(stream);
|
|
2915
3010
|
let reading = false;
|
|
2916
3011
|
let canceled1 = false;
|
|
@@ -2929,24 +3024,24 @@
|
|
|
2929
3024
|
}
|
|
2930
3025
|
reading = true;
|
|
2931
3026
|
const readRequest = {
|
|
2932
|
-
_chunkSteps:
|
|
3027
|
+
_chunkSteps: chunk => {
|
|
2933
3028
|
// This needs to be delayed a microtask because it takes at least a microtask to detect errors (using
|
|
2934
3029
|
// reader._closedPromise below), and we want errors in stream to error both branches immediately. We cannot let
|
|
2935
3030
|
// successful synchronously-available reads get ahead of asynchronously-available errors.
|
|
2936
3031
|
queueMicrotask(() => {
|
|
2937
3032
|
reading = false;
|
|
2938
|
-
const
|
|
2939
|
-
const
|
|
3033
|
+
const chunk1 = chunk;
|
|
3034
|
+
const chunk2 = chunk;
|
|
2940
3035
|
// There is no way to access the cloning code right now in the reference implementation.
|
|
2941
3036
|
// If we add one then we'll need an implementation for serializable objects.
|
|
2942
3037
|
// if (!canceled2 && cloneForBranch2) {
|
|
2943
|
-
//
|
|
3038
|
+
// chunk2 = StructuredDeserialize(StructuredSerialize(chunk2));
|
|
2944
3039
|
// }
|
|
2945
3040
|
if (!canceled1) {
|
|
2946
|
-
ReadableStreamDefaultControllerEnqueue(branch1._readableStreamController,
|
|
3041
|
+
ReadableStreamDefaultControllerEnqueue(branch1._readableStreamController, chunk1);
|
|
2947
3042
|
}
|
|
2948
3043
|
if (!canceled2) {
|
|
2949
|
-
ReadableStreamDefaultControllerEnqueue(branch2._readableStreamController,
|
|
3044
|
+
ReadableStreamDefaultControllerEnqueue(branch2._readableStreamController, chunk2);
|
|
2950
3045
|
}
|
|
2951
3046
|
});
|
|
2952
3047
|
},
|
|
@@ -3003,6 +3098,211 @@
|
|
|
3003
3098
|
});
|
|
3004
3099
|
return [branch1, branch2];
|
|
3005
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
|
+
}
|
|
3006
3306
|
|
|
3007
3307
|
function convertUnderlyingDefaultOrByteSource(source, context) {
|
|
3008
3308
|
assertDictionary(source, context);
|
|
@@ -3264,6 +3564,14 @@
|
|
|
3264
3564
|
SetUpReadableStreamDefaultController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, sizeAlgorithm);
|
|
3265
3565
|
return stream;
|
|
3266
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
|
+
}
|
|
3267
3575
|
function InitializeReadableStream(stream) {
|
|
3268
3576
|
stream._state = 'readable';
|
|
3269
3577
|
stream._reader = undefined;
|
|
@@ -3277,7 +3585,7 @@
|
|
|
3277
3585
|
if (!Object.prototype.hasOwnProperty.call(x, '_readableStreamController')) {
|
|
3278
3586
|
return false;
|
|
3279
3587
|
}
|
|
3280
|
-
return
|
|
3588
|
+
return x instanceof ReadableStream;
|
|
3281
3589
|
}
|
|
3282
3590
|
function IsReadableStreamLocked(stream) {
|
|
3283
3591
|
if (stream._reader === undefined) {
|
|
@@ -3295,6 +3603,13 @@
|
|
|
3295
3603
|
return promiseRejectedWith(stream._storedError);
|
|
3296
3604
|
}
|
|
3297
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
|
+
}
|
|
3298
3613
|
const sourceCancelPromise = stream._readableStreamController[CancelSteps](reason);
|
|
3299
3614
|
return transformPromiseWith(sourceCancelPromise, noop);
|
|
3300
3615
|
}
|
|
@@ -3347,9 +3662,14 @@
|
|
|
3347
3662
|
};
|
|
3348
3663
|
}
|
|
3349
3664
|
|
|
3350
|
-
|
|
3665
|
+
// The size function must not have a prototype property nor be a constructor
|
|
3666
|
+
const byteLengthSizeFunction = (chunk) => {
|
|
3351
3667
|
return chunk.byteLength;
|
|
3352
3668
|
};
|
|
3669
|
+
Object.defineProperty(byteLengthSizeFunction, 'name', {
|
|
3670
|
+
value: 'size',
|
|
3671
|
+
configurable: true
|
|
3672
|
+
});
|
|
3353
3673
|
/**
|
|
3354
3674
|
* A queuing strategy that counts the number of bytes in each chunk.
|
|
3355
3675
|
*
|
|
@@ -3401,12 +3721,17 @@
|
|
|
3401
3721
|
if (!Object.prototype.hasOwnProperty.call(x, '_byteLengthQueuingStrategyHighWaterMark')) {
|
|
3402
3722
|
return false;
|
|
3403
3723
|
}
|
|
3404
|
-
return
|
|
3724
|
+
return x instanceof ByteLengthQueuingStrategy;
|
|
3405
3725
|
}
|
|
3406
3726
|
|
|
3407
|
-
|
|
3727
|
+
// The size function must not have a prototype property nor be a constructor
|
|
3728
|
+
const countSizeFunction = () => {
|
|
3408
3729
|
return 1;
|
|
3409
3730
|
};
|
|
3731
|
+
Object.defineProperty(countSizeFunction, 'name', {
|
|
3732
|
+
value: 'size',
|
|
3733
|
+
configurable: true
|
|
3734
|
+
});
|
|
3410
3735
|
/**
|
|
3411
3736
|
* A queuing strategy that counts the number of chunks.
|
|
3412
3737
|
*
|
|
@@ -3459,7 +3784,7 @@
|
|
|
3459
3784
|
if (!Object.prototype.hasOwnProperty.call(x, '_countQueuingStrategyHighWaterMark')) {
|
|
3460
3785
|
return false;
|
|
3461
3786
|
}
|
|
3462
|
-
return
|
|
3787
|
+
return x instanceof CountQueuingStrategy;
|
|
3463
3788
|
}
|
|
3464
3789
|
|
|
3465
3790
|
function convertTransformer(original, context) {
|
|
@@ -3601,7 +3926,7 @@
|
|
|
3601
3926
|
if (!Object.prototype.hasOwnProperty.call(x, '_transformStreamController')) {
|
|
3602
3927
|
return false;
|
|
3603
3928
|
}
|
|
3604
|
-
return
|
|
3929
|
+
return x instanceof TransformStream;
|
|
3605
3930
|
}
|
|
3606
3931
|
// This is a no-op if both sides are already errored.
|
|
3607
3932
|
function TransformStreamError(stream, e) {
|
|
@@ -3695,7 +4020,7 @@
|
|
|
3695
4020
|
if (!Object.prototype.hasOwnProperty.call(x, '_controlledTransformStream')) {
|
|
3696
4021
|
return false;
|
|
3697
4022
|
}
|
|
3698
|
-
return
|
|
4023
|
+
return x instanceof TransformStreamDefaultController;
|
|
3699
4024
|
}
|
|
3700
4025
|
function SetUpTransformStreamDefaultController(stream, controller, transformAlgorithm, flushAlgorithm) {
|
|
3701
4026
|
controller._controlledTransformStream = stream;
|