web-streams-polyfill 3.0.2 → 3.2.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 +26 -1
- package/README.md +10 -6
- package/dist/polyfill.es2018.js +491 -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 +490 -123
- package/dist/polyfill.es2018.mjs.map +1 -1
- package/dist/polyfill.es6.js +491 -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 +490 -123
- package/dist/polyfill.es6.mjs.map +1 -1
- package/dist/polyfill.js +499 -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 +498 -123
- package/dist/polyfill.mjs.map +1 -1
- package/dist/ponyfill.es2018.js +491 -124
- package/dist/ponyfill.es2018.js.map +1 -1
- package/dist/ponyfill.es2018.mjs +490 -123
- package/dist/ponyfill.es2018.mjs.map +1 -1
- package/dist/ponyfill.es6.js +491 -124
- package/dist/ponyfill.es6.js.map +1 -1
- package/dist/ponyfill.es6.mjs +490 -123
- package/dist/ponyfill.es6.mjs.map +1 -1
- package/dist/ponyfill.js +499 -124
- package/dist/ponyfill.js.map +1 -1
- package/dist/ponyfill.mjs +498 -123
- package/dist/ponyfill.mjs.map +1 -1
- package/dist/types/polyfill.d.ts +30 -10
- package/dist/types/ts3.6/polyfill.d.ts +30 -10
- package/dist/types/tsdoc-metadata.json +1 -1
- package/package.json +16 -16
package/dist/polyfill.es6.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* web-streams-polyfill v3.0
|
|
2
|
+
* web-streams-polyfill v3.2.0
|
|
3
3
|
*/
|
|
4
4
|
(function (global, factory) {
|
|
5
5
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
6
6
|
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
7
|
-
(global = global || self, factory(global.WebStreamsPolyfill = {}));
|
|
7
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.WebStreamsPolyfill = {}));
|
|
8
8
|
}(this, (function (exports) { 'use strict';
|
|
9
9
|
|
|
10
10
|
/// <reference lib="es2015.symbol" />
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
/// <reference lib="dom" />
|
|
16
16
|
function noop() {
|
|
17
|
-
|
|
17
|
+
return undefined;
|
|
18
18
|
}
|
|
19
19
|
function getGlobals() {
|
|
20
20
|
if (typeof self !== 'undefined') {
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
function typeIsObject(x) {
|
|
34
34
|
return (typeof x === 'object' && x !== null) || typeof x === 'function';
|
|
35
35
|
}
|
|
36
|
-
const rethrowAssertionErrorRejection =
|
|
36
|
+
const rethrowAssertionErrorRejection = noop;
|
|
37
37
|
|
|
38
38
|
const originalPromise = Promise;
|
|
39
39
|
const originalPromiseThen = Promise.prototype.then;
|
|
@@ -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;
|
|
@@ -637,7 +637,14 @@
|
|
|
637
637
|
if (!Object.prototype.hasOwnProperty.call(x, '_asyncIteratorImpl')) {
|
|
638
638
|
return false;
|
|
639
639
|
}
|
|
640
|
-
|
|
640
|
+
try {
|
|
641
|
+
// noinspection SuspiciousTypeOfGuard
|
|
642
|
+
return x._asyncIteratorImpl instanceof
|
|
643
|
+
ReadableStreamAsyncIteratorImpl;
|
|
644
|
+
}
|
|
645
|
+
catch (_a) {
|
|
646
|
+
return false;
|
|
647
|
+
}
|
|
641
648
|
}
|
|
642
649
|
// Helper functions for the ReadableStream.
|
|
643
650
|
function streamAsyncIteratorBrandCheckException(name) {
|
|
@@ -651,15 +658,35 @@
|
|
|
651
658
|
return x !== x;
|
|
652
659
|
};
|
|
653
660
|
|
|
654
|
-
function
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
661
|
+
function CreateArrayFromList(elements) {
|
|
662
|
+
// We use arrays to represent lists, so this is basically a no-op.
|
|
663
|
+
// Do a slice though just in case we happen to depend on the unique-ness.
|
|
664
|
+
return elements.slice();
|
|
665
|
+
}
|
|
666
|
+
function CopyDataBlockBytes(dest, destOffset, src, srcOffset, n) {
|
|
667
|
+
new Uint8Array(dest).set(new Uint8Array(src, srcOffset, n), destOffset);
|
|
668
|
+
}
|
|
669
|
+
// Not implemented correctly
|
|
670
|
+
function TransferArrayBuffer(O) {
|
|
671
|
+
return O;
|
|
672
|
+
}
|
|
673
|
+
// Not implemented correctly
|
|
674
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
675
|
+
function IsDetachedBuffer(O) {
|
|
676
|
+
return false;
|
|
677
|
+
}
|
|
678
|
+
function ArrayBufferSlice(buffer, begin, end) {
|
|
679
|
+
// ArrayBuffer.prototype.slice is not available on IE10
|
|
680
|
+
// https://www.caniuse.com/mdn-javascript_builtins_arraybuffer_slice
|
|
681
|
+
if (buffer.slice) {
|
|
682
|
+
return buffer.slice(begin, end);
|
|
660
683
|
}
|
|
661
|
-
|
|
684
|
+
const length = end - begin;
|
|
685
|
+
const slice = new ArrayBuffer(length);
|
|
686
|
+
CopyDataBlockBytes(slice, 0, buffer, begin, length);
|
|
687
|
+
return slice;
|
|
662
688
|
}
|
|
689
|
+
|
|
663
690
|
function IsNonNegativeNumber(v) {
|
|
664
691
|
if (typeof v !== 'number') {
|
|
665
692
|
return false;
|
|
@@ -672,6 +699,10 @@
|
|
|
672
699
|
}
|
|
673
700
|
return true;
|
|
674
701
|
}
|
|
702
|
+
function CloneAsUint8Array(O) {
|
|
703
|
+
const buffer = ArrayBufferSlice(O.buffer, O.byteOffset, O.byteOffset + O.byteLength);
|
|
704
|
+
return new Uint8Array(buffer);
|
|
705
|
+
}
|
|
675
706
|
|
|
676
707
|
function DequeueValue(container) {
|
|
677
708
|
const pair = container._queue.shift();
|
|
@@ -682,8 +713,7 @@
|
|
|
682
713
|
return pair.value;
|
|
683
714
|
}
|
|
684
715
|
function EnqueueValueWithSize(container, value, size) {
|
|
685
|
-
size
|
|
686
|
-
if (!IsFiniteNonNegativeNumber(size)) {
|
|
716
|
+
if (!IsNonNegativeNumber(size) || size === Infinity) {
|
|
687
717
|
throw new RangeError('Size must be a finite, non-NaN, non-negative number.');
|
|
688
718
|
}
|
|
689
719
|
container._queue.push({ value, size });
|
|
@@ -698,23 +728,6 @@
|
|
|
698
728
|
container._queueTotalSize = 0;
|
|
699
729
|
}
|
|
700
730
|
|
|
701
|
-
function CreateArrayFromList(elements) {
|
|
702
|
-
// We use arrays to represent lists, so this is basically a no-op.
|
|
703
|
-
// Do a slice though just in case we happen to depend on the unique-ness.
|
|
704
|
-
return elements.slice();
|
|
705
|
-
}
|
|
706
|
-
function CopyDataBlockBytes(dest, destOffset, src, srcOffset, n) {
|
|
707
|
-
new Uint8Array(dest).set(new Uint8Array(src, srcOffset, n), destOffset);
|
|
708
|
-
}
|
|
709
|
-
// Not implemented correctly
|
|
710
|
-
function TransferArrayBuffer(O) {
|
|
711
|
-
return O;
|
|
712
|
-
}
|
|
713
|
-
// Not implemented correctly
|
|
714
|
-
function IsDetachedBuffer(O) {
|
|
715
|
-
return false;
|
|
716
|
-
}
|
|
717
|
-
|
|
718
731
|
/**
|
|
719
732
|
* A pull-into request in a {@link ReadableByteStreamController}.
|
|
720
733
|
*
|
|
@@ -753,15 +766,10 @@
|
|
|
753
766
|
if (!ArrayBuffer.isView(view)) {
|
|
754
767
|
throw new TypeError('You can only respond with array buffer views');
|
|
755
768
|
}
|
|
756
|
-
if (view.byteLength === 0) {
|
|
757
|
-
throw new TypeError('chunk must have non-zero byteLength');
|
|
758
|
-
}
|
|
759
|
-
if (view.buffer.byteLength === 0) {
|
|
760
|
-
throw new TypeError(`chunk's buffer must have non-zero byteLength`);
|
|
761
|
-
}
|
|
762
769
|
if (this._associatedReadableByteStreamController === undefined) {
|
|
763
770
|
throw new TypeError('This BYOB request has been invalidated');
|
|
764
771
|
}
|
|
772
|
+
if (IsDetachedBuffer(view.buffer)) ;
|
|
765
773
|
ReadableByteStreamControllerRespondWithNewView(this._associatedReadableByteStreamController, view);
|
|
766
774
|
}
|
|
767
775
|
}
|
|
@@ -792,14 +800,7 @@
|
|
|
792
800
|
if (!IsReadableByteStreamController(this)) {
|
|
793
801
|
throw byteStreamControllerBrandCheckException('byobRequest');
|
|
794
802
|
}
|
|
795
|
-
|
|
796
|
-
const firstDescriptor = this._pendingPullIntos.peek();
|
|
797
|
-
const view = new Uint8Array(firstDescriptor.buffer, firstDescriptor.byteOffset + firstDescriptor.bytesFilled, firstDescriptor.byteLength - firstDescriptor.bytesFilled);
|
|
798
|
-
const byobRequest = Object.create(ReadableStreamBYOBRequest.prototype);
|
|
799
|
-
SetUpReadableStreamBYOBRequest(byobRequest, this, view);
|
|
800
|
-
this._byobRequest = byobRequest;
|
|
801
|
-
}
|
|
802
|
-
return this._byobRequest;
|
|
803
|
+
return ReadableByteStreamControllerGetBYOBRequest(this);
|
|
803
804
|
}
|
|
804
805
|
/**
|
|
805
806
|
* Returns the desired size to fill the controlled stream's internal queue. It can be negative, if the queue is
|
|
@@ -862,10 +863,7 @@
|
|
|
862
863
|
}
|
|
863
864
|
/** @internal */
|
|
864
865
|
[CancelSteps](reason) {
|
|
865
|
-
|
|
866
|
-
const firstDescriptor = this._pendingPullIntos.peek();
|
|
867
|
-
firstDescriptor.bytesFilled = 0;
|
|
868
|
-
}
|
|
866
|
+
ReadableByteStreamControllerClearPendingPullIntos(this);
|
|
869
867
|
ResetQueue(this);
|
|
870
868
|
const result = this._cancelAlgorithm(reason);
|
|
871
869
|
ReadableByteStreamControllerClearAlgorithms(this);
|
|
@@ -894,6 +892,7 @@
|
|
|
894
892
|
}
|
|
895
893
|
const pullIntoDescriptor = {
|
|
896
894
|
buffer,
|
|
895
|
+
bufferByteLength: autoAllocateChunkSize,
|
|
897
896
|
byteOffset: 0,
|
|
898
897
|
byteLength: autoAllocateChunkSize,
|
|
899
898
|
bytesFilled: 0,
|
|
@@ -928,7 +927,7 @@
|
|
|
928
927
|
if (!Object.prototype.hasOwnProperty.call(x, '_controlledReadableByteStream')) {
|
|
929
928
|
return false;
|
|
930
929
|
}
|
|
931
|
-
return
|
|
930
|
+
return x instanceof ReadableByteStreamController;
|
|
932
931
|
}
|
|
933
932
|
function IsReadableStreamBYOBRequest(x) {
|
|
934
933
|
if (!typeIsObject(x)) {
|
|
@@ -937,7 +936,7 @@
|
|
|
937
936
|
if (!Object.prototype.hasOwnProperty.call(x, '_associatedReadableByteStreamController')) {
|
|
938
937
|
return false;
|
|
939
938
|
}
|
|
940
|
-
return
|
|
939
|
+
return x instanceof ReadableStreamBYOBRequest;
|
|
941
940
|
}
|
|
942
941
|
function ReadableByteStreamControllerCallPullIfNeeded(controller) {
|
|
943
942
|
const shouldPull = ReadableByteStreamControllerShouldCallPull(controller);
|
|
@@ -1019,7 +1018,6 @@
|
|
|
1019
1018
|
return ready;
|
|
1020
1019
|
}
|
|
1021
1020
|
function ReadableByteStreamControllerFillHeadPullIntoDescriptor(controller, size, pullIntoDescriptor) {
|
|
1022
|
-
ReadableByteStreamControllerInvalidateBYOBRequest(controller);
|
|
1023
1021
|
pullIntoDescriptor.bytesFilled += size;
|
|
1024
1022
|
}
|
|
1025
1023
|
function ReadableByteStreamControllerHandleQueueDrain(controller) {
|
|
@@ -1058,9 +1056,15 @@
|
|
|
1058
1056
|
elementSize = view.constructor.BYTES_PER_ELEMENT;
|
|
1059
1057
|
}
|
|
1060
1058
|
const ctor = view.constructor;
|
|
1059
|
+
// try {
|
|
1061
1060
|
const buffer = TransferArrayBuffer(view.buffer);
|
|
1061
|
+
// } catch (e) {
|
|
1062
|
+
// readIntoRequest._errorSteps(e);
|
|
1063
|
+
// return;
|
|
1064
|
+
// }
|
|
1062
1065
|
const pullIntoDescriptor = {
|
|
1063
1066
|
buffer,
|
|
1067
|
+
bufferByteLength: buffer.byteLength,
|
|
1064
1068
|
byteOffset: view.byteOffset,
|
|
1065
1069
|
byteLength: view.byteLength,
|
|
1066
1070
|
bytesFilled: 0,
|
|
@@ -1100,7 +1104,6 @@
|
|
|
1100
1104
|
ReadableByteStreamControllerCallPullIfNeeded(controller);
|
|
1101
1105
|
}
|
|
1102
1106
|
function ReadableByteStreamControllerRespondInClosedState(controller, firstDescriptor) {
|
|
1103
|
-
firstDescriptor.buffer = TransferArrayBuffer(firstDescriptor.buffer);
|
|
1104
1107
|
const stream = controller._controlledReadableByteStream;
|
|
1105
1108
|
if (ReadableStreamHasBYOBReader(stream)) {
|
|
1106
1109
|
while (ReadableStreamGetNumReadIntoRequests(stream) > 0) {
|
|
@@ -1110,34 +1113,27 @@
|
|
|
1110
1113
|
}
|
|
1111
1114
|
}
|
|
1112
1115
|
function ReadableByteStreamControllerRespondInReadableState(controller, bytesWritten, pullIntoDescriptor) {
|
|
1113
|
-
if (pullIntoDescriptor.bytesFilled + bytesWritten > pullIntoDescriptor.byteLength) {
|
|
1114
|
-
throw new RangeError('bytesWritten out of range');
|
|
1115
|
-
}
|
|
1116
1116
|
ReadableByteStreamControllerFillHeadPullIntoDescriptor(controller, bytesWritten, pullIntoDescriptor);
|
|
1117
1117
|
if (pullIntoDescriptor.bytesFilled < pullIntoDescriptor.elementSize) {
|
|
1118
|
-
// TODO: Figure out whether we should detach the buffer or not here.
|
|
1119
1118
|
return;
|
|
1120
1119
|
}
|
|
1121
1120
|
ReadableByteStreamControllerShiftPendingPullInto(controller);
|
|
1122
1121
|
const remainderSize = pullIntoDescriptor.bytesFilled % pullIntoDescriptor.elementSize;
|
|
1123
1122
|
if (remainderSize > 0) {
|
|
1124
1123
|
const end = pullIntoDescriptor.byteOffset + pullIntoDescriptor.bytesFilled;
|
|
1125
|
-
const remainder = pullIntoDescriptor.buffer
|
|
1124
|
+
const remainder = ArrayBufferSlice(pullIntoDescriptor.buffer, end - remainderSize, end);
|
|
1126
1125
|
ReadableByteStreamControllerEnqueueChunkToQueue(controller, remainder, 0, remainder.byteLength);
|
|
1127
1126
|
}
|
|
1128
|
-
pullIntoDescriptor.buffer = TransferArrayBuffer(pullIntoDescriptor.buffer);
|
|
1129
1127
|
pullIntoDescriptor.bytesFilled -= remainderSize;
|
|
1130
1128
|
ReadableByteStreamControllerCommitPullIntoDescriptor(controller._controlledReadableByteStream, pullIntoDescriptor);
|
|
1131
1129
|
ReadableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(controller);
|
|
1132
1130
|
}
|
|
1133
1131
|
function ReadableByteStreamControllerRespondInternal(controller, bytesWritten) {
|
|
1134
1132
|
const firstDescriptor = controller._pendingPullIntos.peek();
|
|
1133
|
+
ReadableByteStreamControllerInvalidateBYOBRequest(controller);
|
|
1135
1134
|
const state = controller._controlledReadableByteStream._state;
|
|
1136
1135
|
if (state === 'closed') {
|
|
1137
|
-
|
|
1138
|
-
throw new TypeError('bytesWritten must be 0 when calling respond() on a closed stream');
|
|
1139
|
-
}
|
|
1140
|
-
ReadableByteStreamControllerRespondInClosedState(controller, firstDescriptor);
|
|
1136
|
+
ReadableByteStreamControllerRespondInClosedState(controller);
|
|
1141
1137
|
}
|
|
1142
1138
|
else {
|
|
1143
1139
|
ReadableByteStreamControllerRespondInReadableState(controller, bytesWritten, firstDescriptor);
|
|
@@ -1146,7 +1142,6 @@
|
|
|
1146
1142
|
}
|
|
1147
1143
|
function ReadableByteStreamControllerShiftPendingPullInto(controller) {
|
|
1148
1144
|
const descriptor = controller._pendingPullIntos.shift();
|
|
1149
|
-
ReadableByteStreamControllerInvalidateBYOBRequest(controller);
|
|
1150
1145
|
return descriptor;
|
|
1151
1146
|
}
|
|
1152
1147
|
function ReadableByteStreamControllerShouldCallPull(controller) {
|
|
@@ -1206,11 +1201,20 @@
|
|
|
1206
1201
|
const byteOffset = chunk.byteOffset;
|
|
1207
1202
|
const byteLength = chunk.byteLength;
|
|
1208
1203
|
const transferredBuffer = TransferArrayBuffer(buffer);
|
|
1204
|
+
if (controller._pendingPullIntos.length > 0) {
|
|
1205
|
+
const firstPendingPullInto = controller._pendingPullIntos.peek();
|
|
1206
|
+
if (IsDetachedBuffer(firstPendingPullInto.buffer)) ;
|
|
1207
|
+
firstPendingPullInto.buffer = TransferArrayBuffer(firstPendingPullInto.buffer);
|
|
1208
|
+
}
|
|
1209
|
+
ReadableByteStreamControllerInvalidateBYOBRequest(controller);
|
|
1209
1210
|
if (ReadableStreamHasDefaultReader(stream)) {
|
|
1210
1211
|
if (ReadableStreamGetNumReadRequests(stream) === 0) {
|
|
1211
1212
|
ReadableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset, byteLength);
|
|
1212
1213
|
}
|
|
1213
1214
|
else {
|
|
1215
|
+
if (controller._pendingPullIntos.length > 0) {
|
|
1216
|
+
ReadableByteStreamControllerShiftPendingPullInto(controller);
|
|
1217
|
+
}
|
|
1214
1218
|
const transferredView = new Uint8Array(transferredBuffer, byteOffset, byteLength);
|
|
1215
1219
|
ReadableStreamFulfillReadRequest(stream, transferredView, false);
|
|
1216
1220
|
}
|
|
@@ -1235,6 +1239,16 @@
|
|
|
1235
1239
|
ReadableByteStreamControllerClearAlgorithms(controller);
|
|
1236
1240
|
ReadableStreamError(stream, e);
|
|
1237
1241
|
}
|
|
1242
|
+
function ReadableByteStreamControllerGetBYOBRequest(controller) {
|
|
1243
|
+
if (controller._byobRequest === null && controller._pendingPullIntos.length > 0) {
|
|
1244
|
+
const firstDescriptor = controller._pendingPullIntos.peek();
|
|
1245
|
+
const view = new Uint8Array(firstDescriptor.buffer, firstDescriptor.byteOffset + firstDescriptor.bytesFilled, firstDescriptor.byteLength - firstDescriptor.bytesFilled);
|
|
1246
|
+
const byobRequest = Object.create(ReadableStreamBYOBRequest.prototype);
|
|
1247
|
+
SetUpReadableStreamBYOBRequest(byobRequest, controller, view);
|
|
1248
|
+
controller._byobRequest = byobRequest;
|
|
1249
|
+
}
|
|
1250
|
+
return controller._byobRequest;
|
|
1251
|
+
}
|
|
1238
1252
|
function ReadableByteStreamControllerGetDesiredSize(controller) {
|
|
1239
1253
|
const state = controller._controlledReadableByteStream._state;
|
|
1240
1254
|
if (state === 'errored') {
|
|
@@ -1246,22 +1260,49 @@
|
|
|
1246
1260
|
return controller._strategyHWM - controller._queueTotalSize;
|
|
1247
1261
|
}
|
|
1248
1262
|
function ReadableByteStreamControllerRespond(controller, bytesWritten) {
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1263
|
+
const firstDescriptor = controller._pendingPullIntos.peek();
|
|
1264
|
+
const state = controller._controlledReadableByteStream._state;
|
|
1265
|
+
if (state === 'closed') {
|
|
1266
|
+
if (bytesWritten !== 0) {
|
|
1267
|
+
throw new TypeError('bytesWritten must be 0 when calling respond() on a closed stream');
|
|
1268
|
+
}
|
|
1269
|
+
}
|
|
1270
|
+
else {
|
|
1271
|
+
if (bytesWritten === 0) {
|
|
1272
|
+
throw new TypeError('bytesWritten must be greater than 0 when calling respond() on a readable stream');
|
|
1273
|
+
}
|
|
1274
|
+
if (firstDescriptor.bytesFilled + bytesWritten > firstDescriptor.byteLength) {
|
|
1275
|
+
throw new RangeError('bytesWritten out of range');
|
|
1276
|
+
}
|
|
1252
1277
|
}
|
|
1278
|
+
firstDescriptor.buffer = TransferArrayBuffer(firstDescriptor.buffer);
|
|
1253
1279
|
ReadableByteStreamControllerRespondInternal(controller, bytesWritten);
|
|
1254
1280
|
}
|
|
1255
1281
|
function ReadableByteStreamControllerRespondWithNewView(controller, view) {
|
|
1256
1282
|
const firstDescriptor = controller._pendingPullIntos.peek();
|
|
1283
|
+
const state = controller._controlledReadableByteStream._state;
|
|
1284
|
+
if (state === 'closed') {
|
|
1285
|
+
if (view.byteLength !== 0) {
|
|
1286
|
+
throw new TypeError('The view\'s length must be 0 when calling respondWithNewView() on a closed stream');
|
|
1287
|
+
}
|
|
1288
|
+
}
|
|
1289
|
+
else {
|
|
1290
|
+
if (view.byteLength === 0) {
|
|
1291
|
+
throw new TypeError('The view\'s length must be greater than 0 when calling respondWithNewView() on a readable stream');
|
|
1292
|
+
}
|
|
1293
|
+
}
|
|
1257
1294
|
if (firstDescriptor.byteOffset + firstDescriptor.bytesFilled !== view.byteOffset) {
|
|
1258
1295
|
throw new RangeError('The region specified by view does not match byobRequest');
|
|
1259
1296
|
}
|
|
1260
|
-
if (firstDescriptor.
|
|
1297
|
+
if (firstDescriptor.bufferByteLength !== view.buffer.byteLength) {
|
|
1261
1298
|
throw new RangeError('The buffer of view has different capacity than byobRequest');
|
|
1262
1299
|
}
|
|
1263
|
-
firstDescriptor.
|
|
1264
|
-
|
|
1300
|
+
if (firstDescriptor.bytesFilled + view.byteLength > firstDescriptor.byteLength) {
|
|
1301
|
+
throw new RangeError('The region specified by view is larger than byobRequest');
|
|
1302
|
+
}
|
|
1303
|
+
const viewByteLength = view.byteLength;
|
|
1304
|
+
firstDescriptor.buffer = TransferArrayBuffer(view.buffer);
|
|
1305
|
+
ReadableByteStreamControllerRespondInternal(controller, viewByteLength);
|
|
1265
1306
|
}
|
|
1266
1307
|
function SetUpReadableByteStreamController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, autoAllocateChunkSize) {
|
|
1267
1308
|
controller._controlledReadableByteStream = stream;
|
|
@@ -1410,6 +1451,7 @@
|
|
|
1410
1451
|
if (view.buffer.byteLength === 0) {
|
|
1411
1452
|
return promiseRejectedWith(new TypeError(`view's buffer must have non-zero byteLength`));
|
|
1412
1453
|
}
|
|
1454
|
+
if (IsDetachedBuffer(view.buffer)) ;
|
|
1413
1455
|
if (this._ownerReadableStream === undefined) {
|
|
1414
1456
|
return promiseRejectedWith(readerLockException('read from'));
|
|
1415
1457
|
}
|
|
@@ -1469,7 +1511,7 @@
|
|
|
1469
1511
|
if (!Object.prototype.hasOwnProperty.call(x, '_readIntoRequests')) {
|
|
1470
1512
|
return false;
|
|
1471
1513
|
}
|
|
1472
|
-
return
|
|
1514
|
+
return x instanceof ReadableStreamBYOBReader;
|
|
1473
1515
|
}
|
|
1474
1516
|
function ReadableStreamBYOBReaderRead(reader, view, readIntoRequest) {
|
|
1475
1517
|
const stream = reader._ownerReadableStream;
|
|
@@ -1564,6 +1606,31 @@
|
|
|
1564
1606
|
}
|
|
1565
1607
|
}
|
|
1566
1608
|
|
|
1609
|
+
function isAbortSignal(value) {
|
|
1610
|
+
if (typeof value !== 'object' || value === null) {
|
|
1611
|
+
return false;
|
|
1612
|
+
}
|
|
1613
|
+
try {
|
|
1614
|
+
return typeof value.aborted === 'boolean';
|
|
1615
|
+
}
|
|
1616
|
+
catch (_a) {
|
|
1617
|
+
// AbortSignal.prototype.aborted throws if its brand check fails
|
|
1618
|
+
return false;
|
|
1619
|
+
}
|
|
1620
|
+
}
|
|
1621
|
+
const supportsAbortController = typeof AbortController === 'function';
|
|
1622
|
+
/**
|
|
1623
|
+
* Construct a new AbortController, if supported by the platform.
|
|
1624
|
+
*
|
|
1625
|
+
* @internal
|
|
1626
|
+
*/
|
|
1627
|
+
function createAbortController() {
|
|
1628
|
+
if (supportsAbortController) {
|
|
1629
|
+
return new AbortController();
|
|
1630
|
+
}
|
|
1631
|
+
return undefined;
|
|
1632
|
+
}
|
|
1633
|
+
|
|
1567
1634
|
/**
|
|
1568
1635
|
* A writable stream represents a destination for data, into which you can write.
|
|
1569
1636
|
*
|
|
@@ -1593,7 +1660,7 @@
|
|
|
1593
1660
|
*/
|
|
1594
1661
|
get locked() {
|
|
1595
1662
|
if (!IsWritableStream(this)) {
|
|
1596
|
-
throw streamBrandCheckException('locked');
|
|
1663
|
+
throw streamBrandCheckException$2('locked');
|
|
1597
1664
|
}
|
|
1598
1665
|
return IsWritableStreamLocked(this);
|
|
1599
1666
|
}
|
|
@@ -1608,7 +1675,7 @@
|
|
|
1608
1675
|
*/
|
|
1609
1676
|
abort(reason = undefined) {
|
|
1610
1677
|
if (!IsWritableStream(this)) {
|
|
1611
|
-
return promiseRejectedWith(streamBrandCheckException('abort'));
|
|
1678
|
+
return promiseRejectedWith(streamBrandCheckException$2('abort'));
|
|
1612
1679
|
}
|
|
1613
1680
|
if (IsWritableStreamLocked(this)) {
|
|
1614
1681
|
return promiseRejectedWith(new TypeError('Cannot abort a stream that already has a writer'));
|
|
@@ -1625,7 +1692,7 @@
|
|
|
1625
1692
|
*/
|
|
1626
1693
|
close() {
|
|
1627
1694
|
if (!IsWritableStream(this)) {
|
|
1628
|
-
return promiseRejectedWith(streamBrandCheckException('close'));
|
|
1695
|
+
return promiseRejectedWith(streamBrandCheckException$2('close'));
|
|
1629
1696
|
}
|
|
1630
1697
|
if (IsWritableStreamLocked(this)) {
|
|
1631
1698
|
return promiseRejectedWith(new TypeError('Cannot close a stream that already has a writer'));
|
|
@@ -1645,7 +1712,7 @@
|
|
|
1645
1712
|
*/
|
|
1646
1713
|
getWriter() {
|
|
1647
1714
|
if (!IsWritableStream(this)) {
|
|
1648
|
-
throw streamBrandCheckException('getWriter');
|
|
1715
|
+
throw streamBrandCheckException$2('getWriter');
|
|
1649
1716
|
}
|
|
1650
1717
|
return AcquireWritableStreamDefaultWriter(this);
|
|
1651
1718
|
}
|
|
@@ -1707,7 +1774,7 @@
|
|
|
1707
1774
|
if (!Object.prototype.hasOwnProperty.call(x, '_writableStreamController')) {
|
|
1708
1775
|
return false;
|
|
1709
1776
|
}
|
|
1710
|
-
return
|
|
1777
|
+
return x instanceof WritableStream;
|
|
1711
1778
|
}
|
|
1712
1779
|
function IsWritableStreamLocked(stream) {
|
|
1713
1780
|
if (stream._writer === undefined) {
|
|
@@ -1716,6 +1783,15 @@
|
|
|
1716
1783
|
return true;
|
|
1717
1784
|
}
|
|
1718
1785
|
function WritableStreamAbort(stream, reason) {
|
|
1786
|
+
var _a;
|
|
1787
|
+
if (stream._state === 'closed' || stream._state === 'errored') {
|
|
1788
|
+
return promiseResolvedWith(undefined);
|
|
1789
|
+
}
|
|
1790
|
+
stream._writableStreamController._abortReason = reason;
|
|
1791
|
+
(_a = stream._writableStreamController._abortController) === null || _a === void 0 ? void 0 : _a.abort();
|
|
1792
|
+
// TypeScript narrows the type of `stream._state` down to 'writable' | 'erroring',
|
|
1793
|
+
// but it doesn't know that signaling abort runs author code that might have changed the state.
|
|
1794
|
+
// Widen the type again by casting to WritableStreamState.
|
|
1719
1795
|
const state = stream._state;
|
|
1720
1796
|
if (state === 'closed' || state === 'errored') {
|
|
1721
1797
|
return promiseResolvedWith(undefined);
|
|
@@ -2061,7 +2137,7 @@
|
|
|
2061
2137
|
if (!Object.prototype.hasOwnProperty.call(x, '_ownerWritableStream')) {
|
|
2062
2138
|
return false;
|
|
2063
2139
|
}
|
|
2064
|
-
return
|
|
2140
|
+
return x instanceof WritableStreamDefaultWriter;
|
|
2065
2141
|
}
|
|
2066
2142
|
// A client of WritableStreamDefaultWriter may use these functions directly to bypass state check.
|
|
2067
2143
|
function WritableStreamDefaultWriterAbort(writer, reason) {
|
|
@@ -2151,6 +2227,34 @@
|
|
|
2151
2227
|
constructor() {
|
|
2152
2228
|
throw new TypeError('Illegal constructor');
|
|
2153
2229
|
}
|
|
2230
|
+
/**
|
|
2231
|
+
* The reason which was passed to `WritableStream.abort(reason)` when the stream was aborted.
|
|
2232
|
+
*
|
|
2233
|
+
* @deprecated
|
|
2234
|
+
* This property has been removed from the specification, see https://github.com/whatwg/streams/pull/1177.
|
|
2235
|
+
* Use {@link WritableStreamDefaultController.signal}'s `reason` instead.
|
|
2236
|
+
*/
|
|
2237
|
+
get abortReason() {
|
|
2238
|
+
if (!IsWritableStreamDefaultController(this)) {
|
|
2239
|
+
throw defaultControllerBrandCheckException$2('abortReason');
|
|
2240
|
+
}
|
|
2241
|
+
return this._abortReason;
|
|
2242
|
+
}
|
|
2243
|
+
/**
|
|
2244
|
+
* An `AbortSignal` that can be used to abort the pending write or close operation when the stream is aborted.
|
|
2245
|
+
*/
|
|
2246
|
+
get signal() {
|
|
2247
|
+
if (!IsWritableStreamDefaultController(this)) {
|
|
2248
|
+
throw defaultControllerBrandCheckException$2('signal');
|
|
2249
|
+
}
|
|
2250
|
+
if (this._abortController === undefined) {
|
|
2251
|
+
// Older browsers or older Node versions may not support `AbortController` or `AbortSignal`.
|
|
2252
|
+
// We don't want to bundle and ship an `AbortController` polyfill together with our polyfill,
|
|
2253
|
+
// so instead we only implement support for `signal` if we find a global `AbortController` constructor.
|
|
2254
|
+
throw new TypeError('WritableStreamDefaultController.prototype.signal is not supported');
|
|
2255
|
+
}
|
|
2256
|
+
return this._abortController.signal;
|
|
2257
|
+
}
|
|
2154
2258
|
/**
|
|
2155
2259
|
* Closes the controlled writable stream, making all future interactions with it fail with the given error `e`.
|
|
2156
2260
|
*
|
|
@@ -2160,7 +2264,7 @@
|
|
|
2160
2264
|
*/
|
|
2161
2265
|
error(e = undefined) {
|
|
2162
2266
|
if (!IsWritableStreamDefaultController(this)) {
|
|
2163
|
-
throw
|
|
2267
|
+
throw defaultControllerBrandCheckException$2('error');
|
|
2164
2268
|
}
|
|
2165
2269
|
const state = this._controlledWritableStream._state;
|
|
2166
2270
|
if (state !== 'writable') {
|
|
@@ -2182,6 +2286,8 @@
|
|
|
2182
2286
|
}
|
|
2183
2287
|
}
|
|
2184
2288
|
Object.defineProperties(WritableStreamDefaultController.prototype, {
|
|
2289
|
+
abortReason: { enumerable: true },
|
|
2290
|
+
signal: { enumerable: true },
|
|
2185
2291
|
error: { enumerable: true }
|
|
2186
2292
|
});
|
|
2187
2293
|
if (typeof SymbolPolyfill.toStringTag === 'symbol') {
|
|
@@ -2198,7 +2304,7 @@
|
|
|
2198
2304
|
if (!Object.prototype.hasOwnProperty.call(x, '_controlledWritableStream')) {
|
|
2199
2305
|
return false;
|
|
2200
2306
|
}
|
|
2201
|
-
return
|
|
2307
|
+
return x instanceof WritableStreamDefaultController;
|
|
2202
2308
|
}
|
|
2203
2309
|
function SetUpWritableStreamDefaultController(stream, controller, startAlgorithm, writeAlgorithm, closeAlgorithm, abortAlgorithm, highWaterMark, sizeAlgorithm) {
|
|
2204
2310
|
controller._controlledWritableStream = stream;
|
|
@@ -2207,6 +2313,8 @@
|
|
|
2207
2313
|
controller._queue = undefined;
|
|
2208
2314
|
controller._queueTotalSize = undefined;
|
|
2209
2315
|
ResetQueue(controller);
|
|
2316
|
+
controller._abortReason = undefined;
|
|
2317
|
+
controller._abortController = createAbortController();
|
|
2210
2318
|
controller._started = false;
|
|
2211
2319
|
controller._strategySizeAlgorithm = sizeAlgorithm;
|
|
2212
2320
|
controller._strategyHWM = highWaterMark;
|
|
@@ -2356,9 +2464,13 @@
|
|
|
2356
2464
|
WritableStreamStartErroring(stream, error);
|
|
2357
2465
|
}
|
|
2358
2466
|
// Helper functions for the WritableStream.
|
|
2359
|
-
function streamBrandCheckException(name) {
|
|
2467
|
+
function streamBrandCheckException$2(name) {
|
|
2360
2468
|
return new TypeError(`WritableStream.prototype.${name} can only be used on a WritableStream`);
|
|
2361
2469
|
}
|
|
2470
|
+
// Helper functions for the WritableStreamDefaultController.
|
|
2471
|
+
function defaultControllerBrandCheckException$2(name) {
|
|
2472
|
+
return new TypeError(`WritableStreamDefaultController.prototype.${name} can only be used on a WritableStreamDefaultController`);
|
|
2473
|
+
}
|
|
2362
2474
|
// Helper functions for the WritableStreamDefaultWriter.
|
|
2363
2475
|
function defaultWriterBrandCheckException(name) {
|
|
2364
2476
|
return new TypeError(`WritableStreamDefaultWriter.prototype.${name} can only be used on a WritableStreamDefaultWriter`);
|
|
@@ -2444,19 +2556,6 @@
|
|
|
2444
2556
|
writer._readyPromiseState = 'fulfilled';
|
|
2445
2557
|
}
|
|
2446
2558
|
|
|
2447
|
-
function isAbortSignal(value) {
|
|
2448
|
-
if (typeof value !== 'object' || value === null) {
|
|
2449
|
-
return false;
|
|
2450
|
-
}
|
|
2451
|
-
try {
|
|
2452
|
-
return typeof value.aborted === 'boolean';
|
|
2453
|
-
}
|
|
2454
|
-
catch (_a) {
|
|
2455
|
-
// AbortSignal.prototype.aborted throws if its brand check fails
|
|
2456
|
-
return false;
|
|
2457
|
-
}
|
|
2458
|
-
}
|
|
2459
|
-
|
|
2460
2559
|
/// <reference lib="dom" />
|
|
2461
2560
|
const NativeDOMException = typeof DOMException !== 'undefined' ? DOMException : undefined;
|
|
2462
2561
|
|
|
@@ -2474,6 +2573,7 @@
|
|
|
2474
2573
|
}
|
|
2475
2574
|
}
|
|
2476
2575
|
function createDOMExceptionPolyfill() {
|
|
2576
|
+
// eslint-disable-next-line no-shadow
|
|
2477
2577
|
const ctor = function DOMException(message, name) {
|
|
2478
2578
|
this.message = message || '';
|
|
2479
2579
|
this.name = name || 'Error';
|
|
@@ -2485,6 +2585,7 @@
|
|
|
2485
2585
|
Object.defineProperty(ctor.prototype, 'constructor', { value: ctor, writable: true, configurable: true });
|
|
2486
2586
|
return ctor;
|
|
2487
2587
|
}
|
|
2588
|
+
// eslint-disable-next-line no-redeclare
|
|
2488
2589
|
const DOMException$1 = isDOMExceptionConstructor(NativeDOMException) ? NativeDOMException : createDOMExceptionPolyfill();
|
|
2489
2590
|
|
|
2490
2591
|
function ReadableStreamPipeTo(source, dest, preventClose, preventAbort, preventCancel, signal) {
|
|
@@ -2677,7 +2778,7 @@
|
|
|
2677
2778
|
*/
|
|
2678
2779
|
get desiredSize() {
|
|
2679
2780
|
if (!IsReadableStreamDefaultController(this)) {
|
|
2680
|
-
throw defaultControllerBrandCheckException('desiredSize');
|
|
2781
|
+
throw defaultControllerBrandCheckException$1('desiredSize');
|
|
2681
2782
|
}
|
|
2682
2783
|
return ReadableStreamDefaultControllerGetDesiredSize(this);
|
|
2683
2784
|
}
|
|
@@ -2687,7 +2788,7 @@
|
|
|
2687
2788
|
*/
|
|
2688
2789
|
close() {
|
|
2689
2790
|
if (!IsReadableStreamDefaultController(this)) {
|
|
2690
|
-
throw defaultControllerBrandCheckException('close');
|
|
2791
|
+
throw defaultControllerBrandCheckException$1('close');
|
|
2691
2792
|
}
|
|
2692
2793
|
if (!ReadableStreamDefaultControllerCanCloseOrEnqueue(this)) {
|
|
2693
2794
|
throw new TypeError('The stream is not in a state that permits close');
|
|
@@ -2696,7 +2797,7 @@
|
|
|
2696
2797
|
}
|
|
2697
2798
|
enqueue(chunk = undefined) {
|
|
2698
2799
|
if (!IsReadableStreamDefaultController(this)) {
|
|
2699
|
-
throw defaultControllerBrandCheckException('enqueue');
|
|
2800
|
+
throw defaultControllerBrandCheckException$1('enqueue');
|
|
2700
2801
|
}
|
|
2701
2802
|
if (!ReadableStreamDefaultControllerCanCloseOrEnqueue(this)) {
|
|
2702
2803
|
throw new TypeError('The stream is not in a state that permits enqueue');
|
|
@@ -2708,7 +2809,7 @@
|
|
|
2708
2809
|
*/
|
|
2709
2810
|
error(e = undefined) {
|
|
2710
2811
|
if (!IsReadableStreamDefaultController(this)) {
|
|
2711
|
-
throw defaultControllerBrandCheckException('error');
|
|
2812
|
+
throw defaultControllerBrandCheckException$1('error');
|
|
2712
2813
|
}
|
|
2713
2814
|
ReadableStreamDefaultControllerError(this, e);
|
|
2714
2815
|
}
|
|
@@ -2759,7 +2860,7 @@
|
|
|
2759
2860
|
if (!Object.prototype.hasOwnProperty.call(x, '_controlledReadableStream')) {
|
|
2760
2861
|
return false;
|
|
2761
2862
|
}
|
|
2762
|
-
return
|
|
2863
|
+
return x instanceof ReadableStreamDefaultController;
|
|
2763
2864
|
}
|
|
2764
2865
|
function ReadableStreamDefaultControllerCallPullIfNeeded(controller) {
|
|
2765
2866
|
const shouldPull = ReadableStreamDefaultControllerShouldCallPull(controller);
|
|
@@ -2915,13 +3016,20 @@
|
|
|
2915
3016
|
SetUpReadableStreamDefaultController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, sizeAlgorithm);
|
|
2916
3017
|
}
|
|
2917
3018
|
// Helper functions for the ReadableStreamDefaultController.
|
|
2918
|
-
function defaultControllerBrandCheckException(name) {
|
|
3019
|
+
function defaultControllerBrandCheckException$1(name) {
|
|
2919
3020
|
return new TypeError(`ReadableStreamDefaultController.prototype.${name} can only be used on a ReadableStreamDefaultController`);
|
|
2920
3021
|
}
|
|
2921
3022
|
|
|
2922
3023
|
function ReadableStreamTee(stream, cloneForBranch2) {
|
|
3024
|
+
if (IsReadableByteStreamController(stream._readableStreamController)) {
|
|
3025
|
+
return ReadableByteStreamTee(stream);
|
|
3026
|
+
}
|
|
3027
|
+
return ReadableStreamDefaultTee(stream);
|
|
3028
|
+
}
|
|
3029
|
+
function ReadableStreamDefaultTee(stream, cloneForBranch2) {
|
|
2923
3030
|
const reader = AcquireReadableStreamDefaultReader(stream);
|
|
2924
3031
|
let reading = false;
|
|
3032
|
+
let readAgain = false;
|
|
2925
3033
|
let canceled1 = false;
|
|
2926
3034
|
let canceled2 = false;
|
|
2927
3035
|
let reason1;
|
|
@@ -2934,30 +3042,34 @@
|
|
|
2934
3042
|
});
|
|
2935
3043
|
function pullAlgorithm() {
|
|
2936
3044
|
if (reading) {
|
|
3045
|
+
readAgain = true;
|
|
2937
3046
|
return promiseResolvedWith(undefined);
|
|
2938
3047
|
}
|
|
2939
3048
|
reading = true;
|
|
2940
3049
|
const readRequest = {
|
|
2941
|
-
_chunkSteps:
|
|
3050
|
+
_chunkSteps: chunk => {
|
|
2942
3051
|
// This needs to be delayed a microtask because it takes at least a microtask to detect errors (using
|
|
2943
3052
|
// reader._closedPromise below), and we want errors in stream to error both branches immediately. We cannot let
|
|
2944
3053
|
// successful synchronously-available reads get ahead of asynchronously-available errors.
|
|
2945
3054
|
queueMicrotask(() => {
|
|
2946
|
-
|
|
2947
|
-
const
|
|
2948
|
-
const
|
|
3055
|
+
readAgain = false;
|
|
3056
|
+
const chunk1 = chunk;
|
|
3057
|
+
const chunk2 = chunk;
|
|
2949
3058
|
// There is no way to access the cloning code right now in the reference implementation.
|
|
2950
3059
|
// If we add one then we'll need an implementation for serializable objects.
|
|
2951
3060
|
// if (!canceled2 && cloneForBranch2) {
|
|
2952
|
-
//
|
|
3061
|
+
// chunk2 = StructuredDeserialize(StructuredSerialize(chunk2));
|
|
2953
3062
|
// }
|
|
2954
3063
|
if (!canceled1) {
|
|
2955
|
-
ReadableStreamDefaultControllerEnqueue(branch1._readableStreamController,
|
|
3064
|
+
ReadableStreamDefaultControllerEnqueue(branch1._readableStreamController, chunk1);
|
|
2956
3065
|
}
|
|
2957
3066
|
if (!canceled2) {
|
|
2958
|
-
ReadableStreamDefaultControllerEnqueue(branch2._readableStreamController,
|
|
3067
|
+
ReadableStreamDefaultControllerEnqueue(branch2._readableStreamController, chunk2);
|
|
3068
|
+
}
|
|
3069
|
+
reading = false;
|
|
3070
|
+
if (readAgain) {
|
|
3071
|
+
pullAlgorithm();
|
|
2959
3072
|
}
|
|
2960
|
-
resolveCancelPromise(undefined);
|
|
2961
3073
|
});
|
|
2962
3074
|
},
|
|
2963
3075
|
_closeSteps: () => {
|
|
@@ -2968,6 +3080,9 @@
|
|
|
2968
3080
|
if (!canceled2) {
|
|
2969
3081
|
ReadableStreamDefaultControllerClose(branch2._readableStreamController);
|
|
2970
3082
|
}
|
|
3083
|
+
if (!canceled1 || !canceled2) {
|
|
3084
|
+
resolveCancelPromise(undefined);
|
|
3085
|
+
}
|
|
2971
3086
|
},
|
|
2972
3087
|
_errorSteps: () => {
|
|
2973
3088
|
reading = false;
|
|
@@ -3004,8 +3119,235 @@
|
|
|
3004
3119
|
uponRejection(reader._closedPromise, (r) => {
|
|
3005
3120
|
ReadableStreamDefaultControllerError(branch1._readableStreamController, r);
|
|
3006
3121
|
ReadableStreamDefaultControllerError(branch2._readableStreamController, r);
|
|
3007
|
-
|
|
3122
|
+
if (!canceled1 || !canceled2) {
|
|
3123
|
+
resolveCancelPromise(undefined);
|
|
3124
|
+
}
|
|
3125
|
+
});
|
|
3126
|
+
return [branch1, branch2];
|
|
3127
|
+
}
|
|
3128
|
+
function ReadableByteStreamTee(stream) {
|
|
3129
|
+
let reader = AcquireReadableStreamDefaultReader(stream);
|
|
3130
|
+
let reading = false;
|
|
3131
|
+
let readAgainForBranch1 = false;
|
|
3132
|
+
let readAgainForBranch2 = false;
|
|
3133
|
+
let canceled1 = false;
|
|
3134
|
+
let canceled2 = false;
|
|
3135
|
+
let reason1;
|
|
3136
|
+
let reason2;
|
|
3137
|
+
let branch1;
|
|
3138
|
+
let branch2;
|
|
3139
|
+
let resolveCancelPromise;
|
|
3140
|
+
const cancelPromise = newPromise(resolve => {
|
|
3141
|
+
resolveCancelPromise = resolve;
|
|
3008
3142
|
});
|
|
3143
|
+
function forwardReaderError(thisReader) {
|
|
3144
|
+
uponRejection(thisReader._closedPromise, r => {
|
|
3145
|
+
if (thisReader !== reader) {
|
|
3146
|
+
return;
|
|
3147
|
+
}
|
|
3148
|
+
ReadableByteStreamControllerError(branch1._readableStreamController, r);
|
|
3149
|
+
ReadableByteStreamControllerError(branch2._readableStreamController, r);
|
|
3150
|
+
if (!canceled1 || !canceled2) {
|
|
3151
|
+
resolveCancelPromise(undefined);
|
|
3152
|
+
}
|
|
3153
|
+
});
|
|
3154
|
+
}
|
|
3155
|
+
function pullWithDefaultReader() {
|
|
3156
|
+
if (IsReadableStreamBYOBReader(reader)) {
|
|
3157
|
+
ReadableStreamReaderGenericRelease(reader);
|
|
3158
|
+
reader = AcquireReadableStreamDefaultReader(stream);
|
|
3159
|
+
forwardReaderError(reader);
|
|
3160
|
+
}
|
|
3161
|
+
const readRequest = {
|
|
3162
|
+
_chunkSteps: chunk => {
|
|
3163
|
+
// This needs to be delayed a microtask because it takes at least a microtask to detect errors (using
|
|
3164
|
+
// reader._closedPromise below), and we want errors in stream to error both branches immediately. We cannot let
|
|
3165
|
+
// successful synchronously-available reads get ahead of asynchronously-available errors.
|
|
3166
|
+
queueMicrotask(() => {
|
|
3167
|
+
readAgainForBranch1 = false;
|
|
3168
|
+
readAgainForBranch2 = false;
|
|
3169
|
+
const chunk1 = chunk;
|
|
3170
|
+
let chunk2 = chunk;
|
|
3171
|
+
if (!canceled1 && !canceled2) {
|
|
3172
|
+
try {
|
|
3173
|
+
chunk2 = CloneAsUint8Array(chunk);
|
|
3174
|
+
}
|
|
3175
|
+
catch (cloneE) {
|
|
3176
|
+
ReadableByteStreamControllerError(branch1._readableStreamController, cloneE);
|
|
3177
|
+
ReadableByteStreamControllerError(branch2._readableStreamController, cloneE);
|
|
3178
|
+
resolveCancelPromise(ReadableStreamCancel(stream, cloneE));
|
|
3179
|
+
return;
|
|
3180
|
+
}
|
|
3181
|
+
}
|
|
3182
|
+
if (!canceled1) {
|
|
3183
|
+
ReadableByteStreamControllerEnqueue(branch1._readableStreamController, chunk1);
|
|
3184
|
+
}
|
|
3185
|
+
if (!canceled2) {
|
|
3186
|
+
ReadableByteStreamControllerEnqueue(branch2._readableStreamController, chunk2);
|
|
3187
|
+
}
|
|
3188
|
+
reading = false;
|
|
3189
|
+
if (readAgainForBranch1) {
|
|
3190
|
+
pull1Algorithm();
|
|
3191
|
+
}
|
|
3192
|
+
else if (readAgainForBranch2) {
|
|
3193
|
+
pull2Algorithm();
|
|
3194
|
+
}
|
|
3195
|
+
});
|
|
3196
|
+
},
|
|
3197
|
+
_closeSteps: () => {
|
|
3198
|
+
reading = false;
|
|
3199
|
+
if (!canceled1) {
|
|
3200
|
+
ReadableByteStreamControllerClose(branch1._readableStreamController);
|
|
3201
|
+
}
|
|
3202
|
+
if (!canceled2) {
|
|
3203
|
+
ReadableByteStreamControllerClose(branch2._readableStreamController);
|
|
3204
|
+
}
|
|
3205
|
+
if (branch1._readableStreamController._pendingPullIntos.length > 0) {
|
|
3206
|
+
ReadableByteStreamControllerRespond(branch1._readableStreamController, 0);
|
|
3207
|
+
}
|
|
3208
|
+
if (branch2._readableStreamController._pendingPullIntos.length > 0) {
|
|
3209
|
+
ReadableByteStreamControllerRespond(branch2._readableStreamController, 0);
|
|
3210
|
+
}
|
|
3211
|
+
if (!canceled1 || !canceled2) {
|
|
3212
|
+
resolveCancelPromise(undefined);
|
|
3213
|
+
}
|
|
3214
|
+
},
|
|
3215
|
+
_errorSteps: () => {
|
|
3216
|
+
reading = false;
|
|
3217
|
+
}
|
|
3218
|
+
};
|
|
3219
|
+
ReadableStreamDefaultReaderRead(reader, readRequest);
|
|
3220
|
+
}
|
|
3221
|
+
function pullWithBYOBReader(view, forBranch2) {
|
|
3222
|
+
if (IsReadableStreamDefaultReader(reader)) {
|
|
3223
|
+
ReadableStreamReaderGenericRelease(reader);
|
|
3224
|
+
reader = AcquireReadableStreamBYOBReader(stream);
|
|
3225
|
+
forwardReaderError(reader);
|
|
3226
|
+
}
|
|
3227
|
+
const byobBranch = forBranch2 ? branch2 : branch1;
|
|
3228
|
+
const otherBranch = forBranch2 ? branch1 : branch2;
|
|
3229
|
+
const readIntoRequest = {
|
|
3230
|
+
_chunkSteps: chunk => {
|
|
3231
|
+
// This needs to be delayed a microtask because it takes at least a microtask to detect errors (using
|
|
3232
|
+
// reader._closedPromise below), and we want errors in stream to error both branches immediately. We cannot let
|
|
3233
|
+
// successful synchronously-available reads get ahead of asynchronously-available errors.
|
|
3234
|
+
queueMicrotask(() => {
|
|
3235
|
+
readAgainForBranch1 = false;
|
|
3236
|
+
readAgainForBranch2 = false;
|
|
3237
|
+
const byobCanceled = forBranch2 ? canceled2 : canceled1;
|
|
3238
|
+
const otherCanceled = forBranch2 ? canceled1 : canceled2;
|
|
3239
|
+
if (!otherCanceled) {
|
|
3240
|
+
let clonedChunk;
|
|
3241
|
+
try {
|
|
3242
|
+
clonedChunk = CloneAsUint8Array(chunk);
|
|
3243
|
+
}
|
|
3244
|
+
catch (cloneE) {
|
|
3245
|
+
ReadableByteStreamControllerError(byobBranch._readableStreamController, cloneE);
|
|
3246
|
+
ReadableByteStreamControllerError(otherBranch._readableStreamController, cloneE);
|
|
3247
|
+
resolveCancelPromise(ReadableStreamCancel(stream, cloneE));
|
|
3248
|
+
return;
|
|
3249
|
+
}
|
|
3250
|
+
if (!byobCanceled) {
|
|
3251
|
+
ReadableByteStreamControllerRespondWithNewView(byobBranch._readableStreamController, chunk);
|
|
3252
|
+
}
|
|
3253
|
+
ReadableByteStreamControllerEnqueue(otherBranch._readableStreamController, clonedChunk);
|
|
3254
|
+
}
|
|
3255
|
+
else if (!byobCanceled) {
|
|
3256
|
+
ReadableByteStreamControllerRespondWithNewView(byobBranch._readableStreamController, chunk);
|
|
3257
|
+
}
|
|
3258
|
+
reading = false;
|
|
3259
|
+
if (readAgainForBranch1) {
|
|
3260
|
+
pull1Algorithm();
|
|
3261
|
+
}
|
|
3262
|
+
else if (readAgainForBranch2) {
|
|
3263
|
+
pull2Algorithm();
|
|
3264
|
+
}
|
|
3265
|
+
});
|
|
3266
|
+
},
|
|
3267
|
+
_closeSteps: chunk => {
|
|
3268
|
+
reading = false;
|
|
3269
|
+
const byobCanceled = forBranch2 ? canceled2 : canceled1;
|
|
3270
|
+
const otherCanceled = forBranch2 ? canceled1 : canceled2;
|
|
3271
|
+
if (!byobCanceled) {
|
|
3272
|
+
ReadableByteStreamControllerClose(byobBranch._readableStreamController);
|
|
3273
|
+
}
|
|
3274
|
+
if (!otherCanceled) {
|
|
3275
|
+
ReadableByteStreamControllerClose(otherBranch._readableStreamController);
|
|
3276
|
+
}
|
|
3277
|
+
if (chunk !== undefined) {
|
|
3278
|
+
if (!byobCanceled) {
|
|
3279
|
+
ReadableByteStreamControllerRespondWithNewView(byobBranch._readableStreamController, chunk);
|
|
3280
|
+
}
|
|
3281
|
+
if (!otherCanceled && otherBranch._readableStreamController._pendingPullIntos.length > 0) {
|
|
3282
|
+
ReadableByteStreamControllerRespond(otherBranch._readableStreamController, 0);
|
|
3283
|
+
}
|
|
3284
|
+
}
|
|
3285
|
+
if (!byobCanceled || !otherCanceled) {
|
|
3286
|
+
resolveCancelPromise(undefined);
|
|
3287
|
+
}
|
|
3288
|
+
},
|
|
3289
|
+
_errorSteps: () => {
|
|
3290
|
+
reading = false;
|
|
3291
|
+
}
|
|
3292
|
+
};
|
|
3293
|
+
ReadableStreamBYOBReaderRead(reader, view, readIntoRequest);
|
|
3294
|
+
}
|
|
3295
|
+
function pull1Algorithm() {
|
|
3296
|
+
if (reading) {
|
|
3297
|
+
readAgainForBranch1 = true;
|
|
3298
|
+
return promiseResolvedWith(undefined);
|
|
3299
|
+
}
|
|
3300
|
+
reading = true;
|
|
3301
|
+
const byobRequest = ReadableByteStreamControllerGetBYOBRequest(branch1._readableStreamController);
|
|
3302
|
+
if (byobRequest === null) {
|
|
3303
|
+
pullWithDefaultReader();
|
|
3304
|
+
}
|
|
3305
|
+
else {
|
|
3306
|
+
pullWithBYOBReader(byobRequest._view, false);
|
|
3307
|
+
}
|
|
3308
|
+
return promiseResolvedWith(undefined);
|
|
3309
|
+
}
|
|
3310
|
+
function pull2Algorithm() {
|
|
3311
|
+
if (reading) {
|
|
3312
|
+
readAgainForBranch2 = true;
|
|
3313
|
+
return promiseResolvedWith(undefined);
|
|
3314
|
+
}
|
|
3315
|
+
reading = true;
|
|
3316
|
+
const byobRequest = ReadableByteStreamControllerGetBYOBRequest(branch2._readableStreamController);
|
|
3317
|
+
if (byobRequest === null) {
|
|
3318
|
+
pullWithDefaultReader();
|
|
3319
|
+
}
|
|
3320
|
+
else {
|
|
3321
|
+
pullWithBYOBReader(byobRequest._view, true);
|
|
3322
|
+
}
|
|
3323
|
+
return promiseResolvedWith(undefined);
|
|
3324
|
+
}
|
|
3325
|
+
function cancel1Algorithm(reason) {
|
|
3326
|
+
canceled1 = true;
|
|
3327
|
+
reason1 = reason;
|
|
3328
|
+
if (canceled2) {
|
|
3329
|
+
const compositeReason = CreateArrayFromList([reason1, reason2]);
|
|
3330
|
+
const cancelResult = ReadableStreamCancel(stream, compositeReason);
|
|
3331
|
+
resolveCancelPromise(cancelResult);
|
|
3332
|
+
}
|
|
3333
|
+
return cancelPromise;
|
|
3334
|
+
}
|
|
3335
|
+
function cancel2Algorithm(reason) {
|
|
3336
|
+
canceled2 = true;
|
|
3337
|
+
reason2 = reason;
|
|
3338
|
+
if (canceled1) {
|
|
3339
|
+
const compositeReason = CreateArrayFromList([reason1, reason2]);
|
|
3340
|
+
const cancelResult = ReadableStreamCancel(stream, compositeReason);
|
|
3341
|
+
resolveCancelPromise(cancelResult);
|
|
3342
|
+
}
|
|
3343
|
+
return cancelPromise;
|
|
3344
|
+
}
|
|
3345
|
+
function startAlgorithm() {
|
|
3346
|
+
return;
|
|
3347
|
+
}
|
|
3348
|
+
branch1 = CreateReadableByteStream(startAlgorithm, pull1Algorithm, cancel1Algorithm);
|
|
3349
|
+
branch2 = CreateReadableByteStream(startAlgorithm, pull2Algorithm, cancel2Algorithm);
|
|
3350
|
+
forwardReaderError(reader);
|
|
3009
3351
|
return [branch1, branch2];
|
|
3010
3352
|
}
|
|
3011
3353
|
|
|
@@ -3269,6 +3611,14 @@
|
|
|
3269
3611
|
SetUpReadableStreamDefaultController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, sizeAlgorithm);
|
|
3270
3612
|
return stream;
|
|
3271
3613
|
}
|
|
3614
|
+
// Throws if and only if startAlgorithm throws.
|
|
3615
|
+
function CreateReadableByteStream(startAlgorithm, pullAlgorithm, cancelAlgorithm) {
|
|
3616
|
+
const stream = Object.create(ReadableStream.prototype);
|
|
3617
|
+
InitializeReadableStream(stream);
|
|
3618
|
+
const controller = Object.create(ReadableByteStreamController.prototype);
|
|
3619
|
+
SetUpReadableByteStreamController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, 0, undefined);
|
|
3620
|
+
return stream;
|
|
3621
|
+
}
|
|
3272
3622
|
function InitializeReadableStream(stream) {
|
|
3273
3623
|
stream._state = 'readable';
|
|
3274
3624
|
stream._reader = undefined;
|
|
@@ -3282,7 +3632,7 @@
|
|
|
3282
3632
|
if (!Object.prototype.hasOwnProperty.call(x, '_readableStreamController')) {
|
|
3283
3633
|
return false;
|
|
3284
3634
|
}
|
|
3285
|
-
return
|
|
3635
|
+
return x instanceof ReadableStream;
|
|
3286
3636
|
}
|
|
3287
3637
|
function IsReadableStreamLocked(stream) {
|
|
3288
3638
|
if (stream._reader === undefined) {
|
|
@@ -3300,6 +3650,13 @@
|
|
|
3300
3650
|
return promiseRejectedWith(stream._storedError);
|
|
3301
3651
|
}
|
|
3302
3652
|
ReadableStreamClose(stream);
|
|
3653
|
+
const reader = stream._reader;
|
|
3654
|
+
if (reader !== undefined && IsReadableStreamBYOBReader(reader)) {
|
|
3655
|
+
reader._readIntoRequests.forEach(readIntoRequest => {
|
|
3656
|
+
readIntoRequest._closeSteps(undefined);
|
|
3657
|
+
});
|
|
3658
|
+
reader._readIntoRequests = new SimpleQueue();
|
|
3659
|
+
}
|
|
3303
3660
|
const sourceCancelPromise = stream._readableStreamController[CancelSteps](reason);
|
|
3304
3661
|
return transformPromiseWith(sourceCancelPromise, noop);
|
|
3305
3662
|
}
|
|
@@ -3352,9 +3709,14 @@
|
|
|
3352
3709
|
};
|
|
3353
3710
|
}
|
|
3354
3711
|
|
|
3355
|
-
|
|
3712
|
+
// The size function must not have a prototype property nor be a constructor
|
|
3713
|
+
const byteLengthSizeFunction = (chunk) => {
|
|
3356
3714
|
return chunk.byteLength;
|
|
3357
3715
|
};
|
|
3716
|
+
Object.defineProperty(byteLengthSizeFunction, 'name', {
|
|
3717
|
+
value: 'size',
|
|
3718
|
+
configurable: true
|
|
3719
|
+
});
|
|
3358
3720
|
/**
|
|
3359
3721
|
* A queuing strategy that counts the number of bytes in each chunk.
|
|
3360
3722
|
*
|
|
@@ -3406,12 +3768,17 @@
|
|
|
3406
3768
|
if (!Object.prototype.hasOwnProperty.call(x, '_byteLengthQueuingStrategyHighWaterMark')) {
|
|
3407
3769
|
return false;
|
|
3408
3770
|
}
|
|
3409
|
-
return
|
|
3771
|
+
return x instanceof ByteLengthQueuingStrategy;
|
|
3410
3772
|
}
|
|
3411
3773
|
|
|
3412
|
-
|
|
3774
|
+
// The size function must not have a prototype property nor be a constructor
|
|
3775
|
+
const countSizeFunction = () => {
|
|
3413
3776
|
return 1;
|
|
3414
3777
|
};
|
|
3778
|
+
Object.defineProperty(countSizeFunction, 'name', {
|
|
3779
|
+
value: 'size',
|
|
3780
|
+
configurable: true
|
|
3781
|
+
});
|
|
3415
3782
|
/**
|
|
3416
3783
|
* A queuing strategy that counts the number of chunks.
|
|
3417
3784
|
*
|
|
@@ -3464,7 +3831,7 @@
|
|
|
3464
3831
|
if (!Object.prototype.hasOwnProperty.call(x, '_countQueuingStrategyHighWaterMark')) {
|
|
3465
3832
|
return false;
|
|
3466
3833
|
}
|
|
3467
|
-
return
|
|
3834
|
+
return x instanceof CountQueuingStrategy;
|
|
3468
3835
|
}
|
|
3469
3836
|
|
|
3470
3837
|
function convertTransformer(original, context) {
|
|
@@ -3546,7 +3913,7 @@
|
|
|
3546
3913
|
*/
|
|
3547
3914
|
get readable() {
|
|
3548
3915
|
if (!IsTransformStream(this)) {
|
|
3549
|
-
throw streamBrandCheckException
|
|
3916
|
+
throw streamBrandCheckException('readable');
|
|
3550
3917
|
}
|
|
3551
3918
|
return this._readable;
|
|
3552
3919
|
}
|
|
@@ -3555,7 +3922,7 @@
|
|
|
3555
3922
|
*/
|
|
3556
3923
|
get writable() {
|
|
3557
3924
|
if (!IsTransformStream(this)) {
|
|
3558
|
-
throw streamBrandCheckException
|
|
3925
|
+
throw streamBrandCheckException('writable');
|
|
3559
3926
|
}
|
|
3560
3927
|
return this._writable;
|
|
3561
3928
|
}
|
|
@@ -3606,7 +3973,7 @@
|
|
|
3606
3973
|
if (!Object.prototype.hasOwnProperty.call(x, '_transformStreamController')) {
|
|
3607
3974
|
return false;
|
|
3608
3975
|
}
|
|
3609
|
-
return
|
|
3976
|
+
return x instanceof TransformStream;
|
|
3610
3977
|
}
|
|
3611
3978
|
// This is a no-op if both sides are already errored.
|
|
3612
3979
|
function TransformStreamError(stream, e) {
|
|
@@ -3648,14 +4015,14 @@
|
|
|
3648
4015
|
*/
|
|
3649
4016
|
get desiredSize() {
|
|
3650
4017
|
if (!IsTransformStreamDefaultController(this)) {
|
|
3651
|
-
throw defaultControllerBrandCheckException
|
|
4018
|
+
throw defaultControllerBrandCheckException('desiredSize');
|
|
3652
4019
|
}
|
|
3653
4020
|
const readableController = this._controlledTransformStream._readable._readableStreamController;
|
|
3654
4021
|
return ReadableStreamDefaultControllerGetDesiredSize(readableController);
|
|
3655
4022
|
}
|
|
3656
4023
|
enqueue(chunk = undefined) {
|
|
3657
4024
|
if (!IsTransformStreamDefaultController(this)) {
|
|
3658
|
-
throw defaultControllerBrandCheckException
|
|
4025
|
+
throw defaultControllerBrandCheckException('enqueue');
|
|
3659
4026
|
}
|
|
3660
4027
|
TransformStreamDefaultControllerEnqueue(this, chunk);
|
|
3661
4028
|
}
|
|
@@ -3665,7 +4032,7 @@
|
|
|
3665
4032
|
*/
|
|
3666
4033
|
error(reason = undefined) {
|
|
3667
4034
|
if (!IsTransformStreamDefaultController(this)) {
|
|
3668
|
-
throw defaultControllerBrandCheckException
|
|
4035
|
+
throw defaultControllerBrandCheckException('error');
|
|
3669
4036
|
}
|
|
3670
4037
|
TransformStreamDefaultControllerError(this, reason);
|
|
3671
4038
|
}
|
|
@@ -3675,7 +4042,7 @@
|
|
|
3675
4042
|
*/
|
|
3676
4043
|
terminate() {
|
|
3677
4044
|
if (!IsTransformStreamDefaultController(this)) {
|
|
3678
|
-
throw defaultControllerBrandCheckException
|
|
4045
|
+
throw defaultControllerBrandCheckException('terminate');
|
|
3679
4046
|
}
|
|
3680
4047
|
TransformStreamDefaultControllerTerminate(this);
|
|
3681
4048
|
}
|
|
@@ -3700,7 +4067,7 @@
|
|
|
3700
4067
|
if (!Object.prototype.hasOwnProperty.call(x, '_controlledTransformStream')) {
|
|
3701
4068
|
return false;
|
|
3702
4069
|
}
|
|
3703
|
-
return
|
|
4070
|
+
return x instanceof TransformStreamDefaultController;
|
|
3704
4071
|
}
|
|
3705
4072
|
function SetUpTransformStreamDefaultController(stream, controller, transformAlgorithm, flushAlgorithm) {
|
|
3706
4073
|
controller._controlledTransformStream = stream;
|
|
@@ -3817,11 +4184,11 @@
|
|
|
3817
4184
|
return stream._backpressureChangePromise;
|
|
3818
4185
|
}
|
|
3819
4186
|
// Helper functions for the TransformStreamDefaultController.
|
|
3820
|
-
function defaultControllerBrandCheckException
|
|
4187
|
+
function defaultControllerBrandCheckException(name) {
|
|
3821
4188
|
return new TypeError(`TransformStreamDefaultController.prototype.${name} can only be used on a TransformStreamDefaultController`);
|
|
3822
4189
|
}
|
|
3823
4190
|
// Helper functions for the TransformStream.
|
|
3824
|
-
function streamBrandCheckException
|
|
4191
|
+
function streamBrandCheckException(name) {
|
|
3825
4192
|
return new TypeError(`TransformStream.prototype.${name} can only be used on a TransformStream`);
|
|
3826
4193
|
}
|
|
3827
4194
|
|