web-streams-polyfill 3.0.1 → 3.1.1
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 +22 -0
- package/README.md +10 -6
- package/dist/polyfill.es2018.js +458 -124
- 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 +457 -123
- package/dist/polyfill.es2018.mjs.map +1 -1
- package/dist/polyfill.es6.js +458 -124
- 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 +457 -123
- package/dist/polyfill.es6.mjs.map +1 -1
- package/dist/polyfill.js +466 -124
- 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 +465 -123
- package/dist/polyfill.mjs.map +1 -1
- package/dist/ponyfill.es2018.js +458 -124
- package/dist/ponyfill.es2018.js.map +1 -1
- package/dist/ponyfill.es2018.mjs +457 -123
- package/dist/ponyfill.es2018.mjs.map +1 -1
- package/dist/ponyfill.es6.js +458 -124
- package/dist/ponyfill.es6.js.map +1 -1
- package/dist/ponyfill.es6.mjs +457 -123
- package/dist/ponyfill.es6.mjs.map +1 -1
- package/dist/ponyfill.js +466 -124
- package/dist/ponyfill.js.map +1 -1
- package/dist/ponyfill.mjs +465 -123
- package/dist/ponyfill.mjs.map +1 -1
- package/dist/types/polyfill.d.ts +26 -10
- package/dist/types/ts3.6/polyfill.d.ts +26 -10
- package/dist/types/tsdoc-metadata.json +1 -1
- package/package.json +16 -16
package/dist/ponyfill.es2018.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* web-streams-polyfill v3.
|
|
2
|
+
* web-streams-polyfill v3.1.1
|
|
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;
|
|
@@ -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
|
+
}
|
|
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
|
+
}
|
|
1241
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) {
|
|
@@ -1291,6 +1328,9 @@
|
|
|
1291
1328
|
cancelAlgorithm = reason => underlyingByteSource.cancel(reason);
|
|
1292
1329
|
}
|
|
1293
1330
|
const autoAllocateChunkSize = underlyingByteSource.autoAllocateChunkSize;
|
|
1331
|
+
if (autoAllocateChunkSize === 0) {
|
|
1332
|
+
throw new TypeError('autoAllocateChunkSize must be greater than 0');
|
|
1333
|
+
}
|
|
1294
1334
|
SetUpReadableByteStreamController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, autoAllocateChunkSize);
|
|
1295
1335
|
}
|
|
1296
1336
|
function SetUpReadableStreamBYOBRequest(request, controller, view) {
|
|
@@ -1396,6 +1436,7 @@
|
|
|
1396
1436
|
if (view.buffer.byteLength === 0) {
|
|
1397
1437
|
return promiseRejectedWith(new TypeError(`view's buffer must have non-zero byteLength`));
|
|
1398
1438
|
}
|
|
1439
|
+
if (IsDetachedBuffer(view.buffer)) ;
|
|
1399
1440
|
if (this._ownerReadableStream === undefined) {
|
|
1400
1441
|
return promiseRejectedWith(readerLockException('read from'));
|
|
1401
1442
|
}
|
|
@@ -1455,7 +1496,7 @@
|
|
|
1455
1496
|
if (!Object.prototype.hasOwnProperty.call(x, '_readIntoRequests')) {
|
|
1456
1497
|
return false;
|
|
1457
1498
|
}
|
|
1458
|
-
return
|
|
1499
|
+
return x instanceof ReadableStreamBYOBReader;
|
|
1459
1500
|
}
|
|
1460
1501
|
function ReadableStreamBYOBReaderRead(reader, view, readIntoRequest) {
|
|
1461
1502
|
const stream = reader._ownerReadableStream;
|
|
@@ -1550,6 +1591,31 @@
|
|
|
1550
1591
|
}
|
|
1551
1592
|
}
|
|
1552
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
|
+
|
|
1553
1619
|
/**
|
|
1554
1620
|
* A writable stream represents a destination for data, into which you can write.
|
|
1555
1621
|
*
|
|
@@ -1579,7 +1645,7 @@
|
|
|
1579
1645
|
*/
|
|
1580
1646
|
get locked() {
|
|
1581
1647
|
if (!IsWritableStream(this)) {
|
|
1582
|
-
throw streamBrandCheckException('locked');
|
|
1648
|
+
throw streamBrandCheckException$2('locked');
|
|
1583
1649
|
}
|
|
1584
1650
|
return IsWritableStreamLocked(this);
|
|
1585
1651
|
}
|
|
@@ -1594,7 +1660,7 @@
|
|
|
1594
1660
|
*/
|
|
1595
1661
|
abort(reason = undefined) {
|
|
1596
1662
|
if (!IsWritableStream(this)) {
|
|
1597
|
-
return promiseRejectedWith(streamBrandCheckException('abort'));
|
|
1663
|
+
return promiseRejectedWith(streamBrandCheckException$2('abort'));
|
|
1598
1664
|
}
|
|
1599
1665
|
if (IsWritableStreamLocked(this)) {
|
|
1600
1666
|
return promiseRejectedWith(new TypeError('Cannot abort a stream that already has a writer'));
|
|
@@ -1611,7 +1677,7 @@
|
|
|
1611
1677
|
*/
|
|
1612
1678
|
close() {
|
|
1613
1679
|
if (!IsWritableStream(this)) {
|
|
1614
|
-
return promiseRejectedWith(streamBrandCheckException('close'));
|
|
1680
|
+
return promiseRejectedWith(streamBrandCheckException$2('close'));
|
|
1615
1681
|
}
|
|
1616
1682
|
if (IsWritableStreamLocked(this)) {
|
|
1617
1683
|
return promiseRejectedWith(new TypeError('Cannot close a stream that already has a writer'));
|
|
@@ -1631,7 +1697,7 @@
|
|
|
1631
1697
|
*/
|
|
1632
1698
|
getWriter() {
|
|
1633
1699
|
if (!IsWritableStream(this)) {
|
|
1634
|
-
throw streamBrandCheckException('getWriter');
|
|
1700
|
+
throw streamBrandCheckException$2('getWriter');
|
|
1635
1701
|
}
|
|
1636
1702
|
return AcquireWritableStreamDefaultWriter(this);
|
|
1637
1703
|
}
|
|
@@ -1693,7 +1759,7 @@
|
|
|
1693
1759
|
if (!Object.prototype.hasOwnProperty.call(x, '_writableStreamController')) {
|
|
1694
1760
|
return false;
|
|
1695
1761
|
}
|
|
1696
|
-
return
|
|
1762
|
+
return x instanceof WritableStream;
|
|
1697
1763
|
}
|
|
1698
1764
|
function IsWritableStreamLocked(stream) {
|
|
1699
1765
|
if (stream._writer === undefined) {
|
|
@@ -1702,6 +1768,15 @@
|
|
|
1702
1768
|
return true;
|
|
1703
1769
|
}
|
|
1704
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.
|
|
1705
1780
|
const state = stream._state;
|
|
1706
1781
|
if (state === 'closed' || state === 'errored') {
|
|
1707
1782
|
return promiseResolvedWith(undefined);
|
|
@@ -2047,7 +2122,7 @@
|
|
|
2047
2122
|
if (!Object.prototype.hasOwnProperty.call(x, '_ownerWritableStream')) {
|
|
2048
2123
|
return false;
|
|
2049
2124
|
}
|
|
2050
|
-
return
|
|
2125
|
+
return x instanceof WritableStreamDefaultWriter;
|
|
2051
2126
|
}
|
|
2052
2127
|
// A client of WritableStreamDefaultWriter may use these functions directly to bypass state check.
|
|
2053
2128
|
function WritableStreamDefaultWriterAbort(writer, reason) {
|
|
@@ -2137,6 +2212,30 @@
|
|
|
2137
2212
|
constructor() {
|
|
2138
2213
|
throw new TypeError('Illegal constructor');
|
|
2139
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
|
+
}
|
|
2140
2239
|
/**
|
|
2141
2240
|
* Closes the controlled writable stream, making all future interactions with it fail with the given error `e`.
|
|
2142
2241
|
*
|
|
@@ -2146,7 +2245,7 @@
|
|
|
2146
2245
|
*/
|
|
2147
2246
|
error(e = undefined) {
|
|
2148
2247
|
if (!IsWritableStreamDefaultController(this)) {
|
|
2149
|
-
throw
|
|
2248
|
+
throw defaultControllerBrandCheckException$2('error');
|
|
2150
2249
|
}
|
|
2151
2250
|
const state = this._controlledWritableStream._state;
|
|
2152
2251
|
if (state !== 'writable') {
|
|
@@ -2184,7 +2283,7 @@
|
|
|
2184
2283
|
if (!Object.prototype.hasOwnProperty.call(x, '_controlledWritableStream')) {
|
|
2185
2284
|
return false;
|
|
2186
2285
|
}
|
|
2187
|
-
return
|
|
2286
|
+
return x instanceof WritableStreamDefaultController;
|
|
2188
2287
|
}
|
|
2189
2288
|
function SetUpWritableStreamDefaultController(stream, controller, startAlgorithm, writeAlgorithm, closeAlgorithm, abortAlgorithm, highWaterMark, sizeAlgorithm) {
|
|
2190
2289
|
controller._controlledWritableStream = stream;
|
|
@@ -2193,6 +2292,8 @@
|
|
|
2193
2292
|
controller._queue = undefined;
|
|
2194
2293
|
controller._queueTotalSize = undefined;
|
|
2195
2294
|
ResetQueue(controller);
|
|
2295
|
+
controller._abortReason = undefined;
|
|
2296
|
+
controller._abortController = createAbortController();
|
|
2196
2297
|
controller._started = false;
|
|
2197
2298
|
controller._strategySizeAlgorithm = sizeAlgorithm;
|
|
2198
2299
|
controller._strategyHWM = highWaterMark;
|
|
@@ -2342,9 +2443,13 @@
|
|
|
2342
2443
|
WritableStreamStartErroring(stream, error);
|
|
2343
2444
|
}
|
|
2344
2445
|
// Helper functions for the WritableStream.
|
|
2345
|
-
function streamBrandCheckException(name) {
|
|
2446
|
+
function streamBrandCheckException$2(name) {
|
|
2346
2447
|
return new TypeError(`WritableStream.prototype.${name} can only be used on a WritableStream`);
|
|
2347
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
|
+
}
|
|
2348
2453
|
// Helper functions for the WritableStreamDefaultWriter.
|
|
2349
2454
|
function defaultWriterBrandCheckException(name) {
|
|
2350
2455
|
return new TypeError(`WritableStreamDefaultWriter.prototype.${name} can only be used on a WritableStreamDefaultWriter`);
|
|
@@ -2430,19 +2535,6 @@
|
|
|
2430
2535
|
writer._readyPromiseState = 'fulfilled';
|
|
2431
2536
|
}
|
|
2432
2537
|
|
|
2433
|
-
function isAbortSignal(value) {
|
|
2434
|
-
if (typeof value !== 'object' || value === null) {
|
|
2435
|
-
return false;
|
|
2436
|
-
}
|
|
2437
|
-
try {
|
|
2438
|
-
return typeof value.aborted === 'boolean';
|
|
2439
|
-
}
|
|
2440
|
-
catch (_a) {
|
|
2441
|
-
// AbortSignal.prototype.aborted throws if its brand check fails
|
|
2442
|
-
return false;
|
|
2443
|
-
}
|
|
2444
|
-
}
|
|
2445
|
-
|
|
2446
2538
|
/// <reference lib="dom" />
|
|
2447
2539
|
const NativeDOMException = typeof DOMException !== 'undefined' ? DOMException : undefined;
|
|
2448
2540
|
|
|
@@ -2460,6 +2552,7 @@
|
|
|
2460
2552
|
}
|
|
2461
2553
|
}
|
|
2462
2554
|
function createDOMExceptionPolyfill() {
|
|
2555
|
+
// eslint-disable-next-line no-shadow
|
|
2463
2556
|
const ctor = function DOMException(message, name) {
|
|
2464
2557
|
this.message = message || '';
|
|
2465
2558
|
this.name = name || 'Error';
|
|
@@ -2471,6 +2564,7 @@
|
|
|
2471
2564
|
Object.defineProperty(ctor.prototype, 'constructor', { value: ctor, writable: true, configurable: true });
|
|
2472
2565
|
return ctor;
|
|
2473
2566
|
}
|
|
2567
|
+
// eslint-disable-next-line no-redeclare
|
|
2474
2568
|
const DOMException$1 = isDOMExceptionConstructor(NativeDOMException) ? NativeDOMException : createDOMExceptionPolyfill();
|
|
2475
2569
|
|
|
2476
2570
|
function ReadableStreamPipeTo(source, dest, preventClose, preventAbort, preventCancel, signal) {
|
|
@@ -2663,7 +2757,7 @@
|
|
|
2663
2757
|
*/
|
|
2664
2758
|
get desiredSize() {
|
|
2665
2759
|
if (!IsReadableStreamDefaultController(this)) {
|
|
2666
|
-
throw defaultControllerBrandCheckException('desiredSize');
|
|
2760
|
+
throw defaultControllerBrandCheckException$1('desiredSize');
|
|
2667
2761
|
}
|
|
2668
2762
|
return ReadableStreamDefaultControllerGetDesiredSize(this);
|
|
2669
2763
|
}
|
|
@@ -2673,7 +2767,7 @@
|
|
|
2673
2767
|
*/
|
|
2674
2768
|
close() {
|
|
2675
2769
|
if (!IsReadableStreamDefaultController(this)) {
|
|
2676
|
-
throw defaultControllerBrandCheckException('close');
|
|
2770
|
+
throw defaultControllerBrandCheckException$1('close');
|
|
2677
2771
|
}
|
|
2678
2772
|
if (!ReadableStreamDefaultControllerCanCloseOrEnqueue(this)) {
|
|
2679
2773
|
throw new TypeError('The stream is not in a state that permits close');
|
|
@@ -2682,7 +2776,7 @@
|
|
|
2682
2776
|
}
|
|
2683
2777
|
enqueue(chunk = undefined) {
|
|
2684
2778
|
if (!IsReadableStreamDefaultController(this)) {
|
|
2685
|
-
throw defaultControllerBrandCheckException('enqueue');
|
|
2779
|
+
throw defaultControllerBrandCheckException$1('enqueue');
|
|
2686
2780
|
}
|
|
2687
2781
|
if (!ReadableStreamDefaultControllerCanCloseOrEnqueue(this)) {
|
|
2688
2782
|
throw new TypeError('The stream is not in a state that permits enqueue');
|
|
@@ -2694,7 +2788,7 @@
|
|
|
2694
2788
|
*/
|
|
2695
2789
|
error(e = undefined) {
|
|
2696
2790
|
if (!IsReadableStreamDefaultController(this)) {
|
|
2697
|
-
throw defaultControllerBrandCheckException('error');
|
|
2791
|
+
throw defaultControllerBrandCheckException$1('error');
|
|
2698
2792
|
}
|
|
2699
2793
|
ReadableStreamDefaultControllerError(this, e);
|
|
2700
2794
|
}
|
|
@@ -2745,7 +2839,7 @@
|
|
|
2745
2839
|
if (!Object.prototype.hasOwnProperty.call(x, '_controlledReadableStream')) {
|
|
2746
2840
|
return false;
|
|
2747
2841
|
}
|
|
2748
|
-
return
|
|
2842
|
+
return x instanceof ReadableStreamDefaultController;
|
|
2749
2843
|
}
|
|
2750
2844
|
function ReadableStreamDefaultControllerCallPullIfNeeded(controller) {
|
|
2751
2845
|
const shouldPull = ReadableStreamDefaultControllerShouldCallPull(controller);
|
|
@@ -2901,11 +2995,17 @@
|
|
|
2901
2995
|
SetUpReadableStreamDefaultController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, sizeAlgorithm);
|
|
2902
2996
|
}
|
|
2903
2997
|
// Helper functions for the ReadableStreamDefaultController.
|
|
2904
|
-
function defaultControllerBrandCheckException(name) {
|
|
2998
|
+
function defaultControllerBrandCheckException$1(name) {
|
|
2905
2999
|
return new TypeError(`ReadableStreamDefaultController.prototype.${name} can only be used on a ReadableStreamDefaultController`);
|
|
2906
3000
|
}
|
|
2907
3001
|
|
|
2908
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) {
|
|
2909
3009
|
const reader = AcquireReadableStreamDefaultReader(stream);
|
|
2910
3010
|
let reading = false;
|
|
2911
3011
|
let canceled1 = false;
|
|
@@ -2924,26 +3024,25 @@
|
|
|
2924
3024
|
}
|
|
2925
3025
|
reading = true;
|
|
2926
3026
|
const readRequest = {
|
|
2927
|
-
_chunkSteps:
|
|
3027
|
+
_chunkSteps: chunk => {
|
|
2928
3028
|
// This needs to be delayed a microtask because it takes at least a microtask to detect errors (using
|
|
2929
3029
|
// reader._closedPromise below), and we want errors in stream to error both branches immediately. We cannot let
|
|
2930
3030
|
// successful synchronously-available reads get ahead of asynchronously-available errors.
|
|
2931
3031
|
queueMicrotask(() => {
|
|
2932
3032
|
reading = false;
|
|
2933
|
-
const
|
|
2934
|
-
const
|
|
3033
|
+
const chunk1 = chunk;
|
|
3034
|
+
const chunk2 = chunk;
|
|
2935
3035
|
// There is no way to access the cloning code right now in the reference implementation.
|
|
2936
3036
|
// If we add one then we'll need an implementation for serializable objects.
|
|
2937
3037
|
// if (!canceled2 && cloneForBranch2) {
|
|
2938
|
-
//
|
|
3038
|
+
// chunk2 = StructuredDeserialize(StructuredSerialize(chunk2));
|
|
2939
3039
|
// }
|
|
2940
3040
|
if (!canceled1) {
|
|
2941
|
-
ReadableStreamDefaultControllerEnqueue(branch1._readableStreamController,
|
|
3041
|
+
ReadableStreamDefaultControllerEnqueue(branch1._readableStreamController, chunk1);
|
|
2942
3042
|
}
|
|
2943
3043
|
if (!canceled2) {
|
|
2944
|
-
ReadableStreamDefaultControllerEnqueue(branch2._readableStreamController,
|
|
3044
|
+
ReadableStreamDefaultControllerEnqueue(branch2._readableStreamController, chunk2);
|
|
2945
3045
|
}
|
|
2946
|
-
resolveCancelPromise(undefined);
|
|
2947
3046
|
});
|
|
2948
3047
|
},
|
|
2949
3048
|
_closeSteps: () => {
|
|
@@ -2954,6 +3053,9 @@
|
|
|
2954
3053
|
if (!canceled2) {
|
|
2955
3054
|
ReadableStreamDefaultControllerClose(branch2._readableStreamController);
|
|
2956
3055
|
}
|
|
3056
|
+
if (!canceled1 || !canceled2) {
|
|
3057
|
+
resolveCancelPromise(undefined);
|
|
3058
|
+
}
|
|
2957
3059
|
},
|
|
2958
3060
|
_errorSteps: () => {
|
|
2959
3061
|
reading = false;
|
|
@@ -2990,8 +3092,215 @@
|
|
|
2990
3092
|
uponRejection(reader._closedPromise, (r) => {
|
|
2991
3093
|
ReadableStreamDefaultControllerError(branch1._readableStreamController, r);
|
|
2992
3094
|
ReadableStreamDefaultControllerError(branch2._readableStreamController, r);
|
|
2993
|
-
|
|
3095
|
+
if (!canceled1 || !canceled2) {
|
|
3096
|
+
resolveCancelPromise(undefined);
|
|
3097
|
+
}
|
|
3098
|
+
});
|
|
3099
|
+
return [branch1, branch2];
|
|
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;
|
|
2994
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);
|
|
2995
3304
|
return [branch1, branch2];
|
|
2996
3305
|
}
|
|
2997
3306
|
|
|
@@ -3255,6 +3564,14 @@
|
|
|
3255
3564
|
SetUpReadableStreamDefaultController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, sizeAlgorithm);
|
|
3256
3565
|
return stream;
|
|
3257
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
|
+
}
|
|
3258
3575
|
function InitializeReadableStream(stream) {
|
|
3259
3576
|
stream._state = 'readable';
|
|
3260
3577
|
stream._reader = undefined;
|
|
@@ -3268,7 +3585,7 @@
|
|
|
3268
3585
|
if (!Object.prototype.hasOwnProperty.call(x, '_readableStreamController')) {
|
|
3269
3586
|
return false;
|
|
3270
3587
|
}
|
|
3271
|
-
return
|
|
3588
|
+
return x instanceof ReadableStream;
|
|
3272
3589
|
}
|
|
3273
3590
|
function IsReadableStreamLocked(stream) {
|
|
3274
3591
|
if (stream._reader === undefined) {
|
|
@@ -3286,6 +3603,13 @@
|
|
|
3286
3603
|
return promiseRejectedWith(stream._storedError);
|
|
3287
3604
|
}
|
|
3288
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
|
+
}
|
|
3289
3613
|
const sourceCancelPromise = stream._readableStreamController[CancelSteps](reason);
|
|
3290
3614
|
return transformPromiseWith(sourceCancelPromise, noop);
|
|
3291
3615
|
}
|
|
@@ -3295,13 +3619,13 @@
|
|
|
3295
3619
|
if (reader === undefined) {
|
|
3296
3620
|
return;
|
|
3297
3621
|
}
|
|
3622
|
+
defaultReaderClosedPromiseResolve(reader);
|
|
3298
3623
|
if (IsReadableStreamDefaultReader(reader)) {
|
|
3299
3624
|
reader._readRequests.forEach(readRequest => {
|
|
3300
3625
|
readRequest._closeSteps();
|
|
3301
3626
|
});
|
|
3302
3627
|
reader._readRequests = new SimpleQueue();
|
|
3303
3628
|
}
|
|
3304
|
-
defaultReaderClosedPromiseResolve(reader);
|
|
3305
3629
|
}
|
|
3306
3630
|
function ReadableStreamError(stream, e) {
|
|
3307
3631
|
stream._state = 'errored';
|
|
@@ -3310,6 +3634,7 @@
|
|
|
3310
3634
|
if (reader === undefined) {
|
|
3311
3635
|
return;
|
|
3312
3636
|
}
|
|
3637
|
+
defaultReaderClosedPromiseReject(reader, e);
|
|
3313
3638
|
if (IsReadableStreamDefaultReader(reader)) {
|
|
3314
3639
|
reader._readRequests.forEach(readRequest => {
|
|
3315
3640
|
readRequest._errorSteps(e);
|
|
@@ -3322,7 +3647,6 @@
|
|
|
3322
3647
|
});
|
|
3323
3648
|
reader._readIntoRequests = new SimpleQueue();
|
|
3324
3649
|
}
|
|
3325
|
-
defaultReaderClosedPromiseReject(reader, e);
|
|
3326
3650
|
}
|
|
3327
3651
|
// Helper functions for the ReadableStream.
|
|
3328
3652
|
function streamBrandCheckException$1(name) {
|
|
@@ -3338,9 +3662,14 @@
|
|
|
3338
3662
|
};
|
|
3339
3663
|
}
|
|
3340
3664
|
|
|
3341
|
-
|
|
3665
|
+
// The size function must not have a prototype property nor be a constructor
|
|
3666
|
+
const byteLengthSizeFunction = (chunk) => {
|
|
3342
3667
|
return chunk.byteLength;
|
|
3343
3668
|
};
|
|
3669
|
+
Object.defineProperty(byteLengthSizeFunction, 'name', {
|
|
3670
|
+
value: 'size',
|
|
3671
|
+
configurable: true
|
|
3672
|
+
});
|
|
3344
3673
|
/**
|
|
3345
3674
|
* A queuing strategy that counts the number of bytes in each chunk.
|
|
3346
3675
|
*
|
|
@@ -3392,12 +3721,17 @@
|
|
|
3392
3721
|
if (!Object.prototype.hasOwnProperty.call(x, '_byteLengthQueuingStrategyHighWaterMark')) {
|
|
3393
3722
|
return false;
|
|
3394
3723
|
}
|
|
3395
|
-
return
|
|
3724
|
+
return x instanceof ByteLengthQueuingStrategy;
|
|
3396
3725
|
}
|
|
3397
3726
|
|
|
3398
|
-
|
|
3727
|
+
// The size function must not have a prototype property nor be a constructor
|
|
3728
|
+
const countSizeFunction = () => {
|
|
3399
3729
|
return 1;
|
|
3400
3730
|
};
|
|
3731
|
+
Object.defineProperty(countSizeFunction, 'name', {
|
|
3732
|
+
value: 'size',
|
|
3733
|
+
configurable: true
|
|
3734
|
+
});
|
|
3401
3735
|
/**
|
|
3402
3736
|
* A queuing strategy that counts the number of chunks.
|
|
3403
3737
|
*
|
|
@@ -3450,7 +3784,7 @@
|
|
|
3450
3784
|
if (!Object.prototype.hasOwnProperty.call(x, '_countQueuingStrategyHighWaterMark')) {
|
|
3451
3785
|
return false;
|
|
3452
3786
|
}
|
|
3453
|
-
return
|
|
3787
|
+
return x instanceof CountQueuingStrategy;
|
|
3454
3788
|
}
|
|
3455
3789
|
|
|
3456
3790
|
function convertTransformer(original, context) {
|
|
@@ -3532,7 +3866,7 @@
|
|
|
3532
3866
|
*/
|
|
3533
3867
|
get readable() {
|
|
3534
3868
|
if (!IsTransformStream(this)) {
|
|
3535
|
-
throw streamBrandCheckException
|
|
3869
|
+
throw streamBrandCheckException('readable');
|
|
3536
3870
|
}
|
|
3537
3871
|
return this._readable;
|
|
3538
3872
|
}
|
|
@@ -3541,7 +3875,7 @@
|
|
|
3541
3875
|
*/
|
|
3542
3876
|
get writable() {
|
|
3543
3877
|
if (!IsTransformStream(this)) {
|
|
3544
|
-
throw streamBrandCheckException
|
|
3878
|
+
throw streamBrandCheckException('writable');
|
|
3545
3879
|
}
|
|
3546
3880
|
return this._writable;
|
|
3547
3881
|
}
|
|
@@ -3592,7 +3926,7 @@
|
|
|
3592
3926
|
if (!Object.prototype.hasOwnProperty.call(x, '_transformStreamController')) {
|
|
3593
3927
|
return false;
|
|
3594
3928
|
}
|
|
3595
|
-
return
|
|
3929
|
+
return x instanceof TransformStream;
|
|
3596
3930
|
}
|
|
3597
3931
|
// This is a no-op if both sides are already errored.
|
|
3598
3932
|
function TransformStreamError(stream, e) {
|
|
@@ -3634,14 +3968,14 @@
|
|
|
3634
3968
|
*/
|
|
3635
3969
|
get desiredSize() {
|
|
3636
3970
|
if (!IsTransformStreamDefaultController(this)) {
|
|
3637
|
-
throw defaultControllerBrandCheckException
|
|
3971
|
+
throw defaultControllerBrandCheckException('desiredSize');
|
|
3638
3972
|
}
|
|
3639
3973
|
const readableController = this._controlledTransformStream._readable._readableStreamController;
|
|
3640
3974
|
return ReadableStreamDefaultControllerGetDesiredSize(readableController);
|
|
3641
3975
|
}
|
|
3642
3976
|
enqueue(chunk = undefined) {
|
|
3643
3977
|
if (!IsTransformStreamDefaultController(this)) {
|
|
3644
|
-
throw defaultControllerBrandCheckException
|
|
3978
|
+
throw defaultControllerBrandCheckException('enqueue');
|
|
3645
3979
|
}
|
|
3646
3980
|
TransformStreamDefaultControllerEnqueue(this, chunk);
|
|
3647
3981
|
}
|
|
@@ -3651,7 +3985,7 @@
|
|
|
3651
3985
|
*/
|
|
3652
3986
|
error(reason = undefined) {
|
|
3653
3987
|
if (!IsTransformStreamDefaultController(this)) {
|
|
3654
|
-
throw defaultControllerBrandCheckException
|
|
3988
|
+
throw defaultControllerBrandCheckException('error');
|
|
3655
3989
|
}
|
|
3656
3990
|
TransformStreamDefaultControllerError(this, reason);
|
|
3657
3991
|
}
|
|
@@ -3661,7 +3995,7 @@
|
|
|
3661
3995
|
*/
|
|
3662
3996
|
terminate() {
|
|
3663
3997
|
if (!IsTransformStreamDefaultController(this)) {
|
|
3664
|
-
throw defaultControllerBrandCheckException
|
|
3998
|
+
throw defaultControllerBrandCheckException('terminate');
|
|
3665
3999
|
}
|
|
3666
4000
|
TransformStreamDefaultControllerTerminate(this);
|
|
3667
4001
|
}
|
|
@@ -3686,7 +4020,7 @@
|
|
|
3686
4020
|
if (!Object.prototype.hasOwnProperty.call(x, '_controlledTransformStream')) {
|
|
3687
4021
|
return false;
|
|
3688
4022
|
}
|
|
3689
|
-
return
|
|
4023
|
+
return x instanceof TransformStreamDefaultController;
|
|
3690
4024
|
}
|
|
3691
4025
|
function SetUpTransformStreamDefaultController(stream, controller, transformAlgorithm, flushAlgorithm) {
|
|
3692
4026
|
controller._controlledTransformStream = stream;
|
|
@@ -3803,11 +4137,11 @@
|
|
|
3803
4137
|
return stream._backpressureChangePromise;
|
|
3804
4138
|
}
|
|
3805
4139
|
// Helper functions for the TransformStreamDefaultController.
|
|
3806
|
-
function defaultControllerBrandCheckException
|
|
4140
|
+
function defaultControllerBrandCheckException(name) {
|
|
3807
4141
|
return new TypeError(`TransformStreamDefaultController.prototype.${name} can only be used on a TransformStreamDefaultController`);
|
|
3808
4142
|
}
|
|
3809
4143
|
// Helper functions for the TransformStream.
|
|
3810
|
-
function streamBrandCheckException
|
|
4144
|
+
function streamBrandCheckException(name) {
|
|
3811
4145
|
return new TypeError(`TransformStream.prototype.${name} can only be used on a TransformStream`);
|
|
3812
4146
|
}
|
|
3813
4147
|
|