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/dist/polyfill.js CHANGED
@@ -1,10 +1,10 @@
1
1
  /**
2
- * web-streams-polyfill v3.0.1
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
- // do nothing
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
- var rethrowAssertionErrorRejection = noop;
36
+ var rethrowAssertionErrorRejection = noop;
37
37
 
38
38
  var originalPromise = Promise;
39
39
  var originalPromiseThen = Promise.prototype.then;
@@ -505,7 +505,7 @@
505
505
  if (!Object.prototype.hasOwnProperty.call(x, '_readRequests')) {
506
506
  return false;
507
507
  }
508
- return true;
508
+ return x instanceof ReadableStreamDefaultReader;
509
509
  }
510
510
  function ReadableStreamDefaultReaderRead(reader, readRequest) {
511
511
  var stream = reader._ownerReadableStream;
@@ -653,7 +653,14 @@
653
653
  if (!Object.prototype.hasOwnProperty.call(x, '_asyncIteratorImpl')) {
654
654
  return false;
655
655
  }
656
- return true;
656
+ try {
657
+ // noinspection SuspiciousTypeOfGuard
658
+ return x._asyncIteratorImpl instanceof
659
+ ReadableStreamAsyncIteratorImpl;
660
+ }
661
+ catch (_a) {
662
+ return false;
663
+ }
657
664
  }
658
665
  // Helper functions for the ReadableStream.
659
666
  function streamAsyncIteratorBrandCheckException(name) {
@@ -667,15 +674,35 @@
667
674
  return x !== x;
668
675
  };
669
676
 
670
- function IsFiniteNonNegativeNumber(v) {
671
- if (!IsNonNegativeNumber(v)) {
672
- return false;
673
- }
674
- if (v === Infinity) {
675
- return false;
677
+ function CreateArrayFromList(elements) {
678
+ // We use arrays to represent lists, so this is basically a no-op.
679
+ // Do a slice though just in case we happen to depend on the unique-ness.
680
+ return elements.slice();
681
+ }
682
+ function CopyDataBlockBytes(dest, destOffset, src, srcOffset, n) {
683
+ new Uint8Array(dest).set(new Uint8Array(src, srcOffset, n), destOffset);
684
+ }
685
+ // Not implemented correctly
686
+ function TransferArrayBuffer(O) {
687
+ return O;
688
+ }
689
+ // Not implemented correctly
690
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
691
+ function IsDetachedBuffer(O) {
692
+ return false;
693
+ }
694
+ function ArrayBufferSlice(buffer, begin, end) {
695
+ // ArrayBuffer.prototype.slice is not available on IE10
696
+ // https://www.caniuse.com/mdn-javascript_builtins_arraybuffer_slice
697
+ if (buffer.slice) {
698
+ return buffer.slice(begin, end);
676
699
  }
677
- return true;
700
+ var length = end - begin;
701
+ var slice = new ArrayBuffer(length);
702
+ CopyDataBlockBytes(slice, 0, buffer, begin, length);
703
+ return slice;
678
704
  }
705
+
679
706
  function IsNonNegativeNumber(v) {
680
707
  if (typeof v !== 'number') {
681
708
  return false;
@@ -688,6 +715,10 @@
688
715
  }
689
716
  return true;
690
717
  }
718
+ function CloneAsUint8Array(O) {
719
+ var buffer = ArrayBufferSlice(O.buffer, O.byteOffset, O.byteOffset + O.byteLength);
720
+ return new Uint8Array(buffer);
721
+ }
691
722
 
692
723
  function DequeueValue(container) {
693
724
  var pair = container._queue.shift();
@@ -698,8 +729,7 @@
698
729
  return pair.value;
699
730
  }
700
731
  function EnqueueValueWithSize(container, value, size) {
701
- size = Number(size);
702
- if (!IsFiniteNonNegativeNumber(size)) {
732
+ if (!IsNonNegativeNumber(size) || size === Infinity) {
703
733
  throw new RangeError('Size must be a finite, non-NaN, non-negative number.');
704
734
  }
705
735
  container._queue.push({ value: value, size: size });
@@ -714,23 +744,6 @@
714
744
  container._queueTotalSize = 0;
715
745
  }
716
746
 
717
- function CreateArrayFromList(elements) {
718
- // We use arrays to represent lists, so this is basically a no-op.
719
- // Do a slice though just in case we happen to depend on the unique-ness.
720
- return elements.slice();
721
- }
722
- function CopyDataBlockBytes(dest, destOffset, src, srcOffset, n) {
723
- new Uint8Array(dest).set(new Uint8Array(src, srcOffset, n), destOffset);
724
- }
725
- // Not implemented correctly
726
- function TransferArrayBuffer(O) {
727
- return O;
728
- }
729
- // Not implemented correctly
730
- function IsDetachedBuffer(O) {
731
- return false;
732
- }
733
-
734
747
  /**
735
748
  * A pull-into request in a {@link ReadableByteStreamController}.
736
749
  *
@@ -773,15 +786,10 @@
773
786
  if (!ArrayBuffer.isView(view)) {
774
787
  throw new TypeError('You can only respond with array buffer views');
775
788
  }
776
- if (view.byteLength === 0) {
777
- throw new TypeError('chunk must have non-zero byteLength');
778
- }
779
- if (view.buffer.byteLength === 0) {
780
- throw new TypeError("chunk's buffer must have non-zero byteLength");
781
- }
782
789
  if (this._associatedReadableByteStreamController === undefined) {
783
790
  throw new TypeError('This BYOB request has been invalidated');
784
791
  }
792
+ if (IsDetachedBuffer(view.buffer)) ;
785
793
  ReadableByteStreamControllerRespondWithNewView(this._associatedReadableByteStreamController, view);
786
794
  };
787
795
  return ReadableStreamBYOBRequest;
@@ -814,14 +822,7 @@
814
822
  if (!IsReadableByteStreamController(this)) {
815
823
  throw byteStreamControllerBrandCheckException('byobRequest');
816
824
  }
817
- if (this._byobRequest === null && this._pendingPullIntos.length > 0) {
818
- var firstDescriptor = this._pendingPullIntos.peek();
819
- var view = new Uint8Array(firstDescriptor.buffer, firstDescriptor.byteOffset + firstDescriptor.bytesFilled, firstDescriptor.byteLength - firstDescriptor.bytesFilled);
820
- var byobRequest = Object.create(ReadableStreamBYOBRequest.prototype);
821
- SetUpReadableStreamBYOBRequest(byobRequest, this, view);
822
- this._byobRequest = byobRequest;
823
- }
824
- return this._byobRequest;
825
+ return ReadableByteStreamControllerGetBYOBRequest(this);
825
826
  },
826
827
  enumerable: false,
827
828
  configurable: true
@@ -892,10 +893,7 @@
892
893
  };
893
894
  /** @internal */
894
895
  ReadableByteStreamController.prototype[CancelSteps] = function (reason) {
895
- if (this._pendingPullIntos.length > 0) {
896
- var firstDescriptor = this._pendingPullIntos.peek();
897
- firstDescriptor.bytesFilled = 0;
898
- }
896
+ ReadableByteStreamControllerClearPendingPullIntos(this);
899
897
  ResetQueue(this);
900
898
  var result = this._cancelAlgorithm(reason);
901
899
  ReadableByteStreamControllerClearAlgorithms(this);
@@ -924,6 +922,7 @@
924
922
  }
925
923
  var pullIntoDescriptor = {
926
924
  buffer: buffer,
925
+ bufferByteLength: autoAllocateChunkSize,
927
926
  byteOffset: 0,
928
927
  byteLength: autoAllocateChunkSize,
929
928
  bytesFilled: 0,
@@ -959,7 +958,7 @@
959
958
  if (!Object.prototype.hasOwnProperty.call(x, '_controlledReadableByteStream')) {
960
959
  return false;
961
960
  }
962
- return true;
961
+ return x instanceof ReadableByteStreamController;
963
962
  }
964
963
  function IsReadableStreamBYOBRequest(x) {
965
964
  if (!typeIsObject(x)) {
@@ -968,7 +967,7 @@
968
967
  if (!Object.prototype.hasOwnProperty.call(x, '_associatedReadableByteStreamController')) {
969
968
  return false;
970
969
  }
971
- return true;
970
+ return x instanceof ReadableStreamBYOBRequest;
972
971
  }
973
972
  function ReadableByteStreamControllerCallPullIfNeeded(controller) {
974
973
  var shouldPull = ReadableByteStreamControllerShouldCallPull(controller);
@@ -1050,7 +1049,6 @@
1050
1049
  return ready;
1051
1050
  }
1052
1051
  function ReadableByteStreamControllerFillHeadPullIntoDescriptor(controller, size, pullIntoDescriptor) {
1053
- ReadableByteStreamControllerInvalidateBYOBRequest(controller);
1054
1052
  pullIntoDescriptor.bytesFilled += size;
1055
1053
  }
1056
1054
  function ReadableByteStreamControllerHandleQueueDrain(controller) {
@@ -1089,9 +1087,15 @@
1089
1087
  elementSize = view.constructor.BYTES_PER_ELEMENT;
1090
1088
  }
1091
1089
  var ctor = view.constructor;
1090
+ // try {
1092
1091
  var buffer = TransferArrayBuffer(view.buffer);
1092
+ // } catch (e) {
1093
+ // readIntoRequest._errorSteps(e);
1094
+ // return;
1095
+ // }
1093
1096
  var pullIntoDescriptor = {
1094
1097
  buffer: buffer,
1098
+ bufferByteLength: buffer.byteLength,
1095
1099
  byteOffset: view.byteOffset,
1096
1100
  byteLength: view.byteLength,
1097
1101
  bytesFilled: 0,
@@ -1131,7 +1135,6 @@
1131
1135
  ReadableByteStreamControllerCallPullIfNeeded(controller);
1132
1136
  }
1133
1137
  function ReadableByteStreamControllerRespondInClosedState(controller, firstDescriptor) {
1134
- firstDescriptor.buffer = TransferArrayBuffer(firstDescriptor.buffer);
1135
1138
  var stream = controller._controlledReadableByteStream;
1136
1139
  if (ReadableStreamHasBYOBReader(stream)) {
1137
1140
  while (ReadableStreamGetNumReadIntoRequests(stream) > 0) {
@@ -1141,34 +1144,27 @@
1141
1144
  }
1142
1145
  }
1143
1146
  function ReadableByteStreamControllerRespondInReadableState(controller, bytesWritten, pullIntoDescriptor) {
1144
- if (pullIntoDescriptor.bytesFilled + bytesWritten > pullIntoDescriptor.byteLength) {
1145
- throw new RangeError('bytesWritten out of range');
1146
- }
1147
1147
  ReadableByteStreamControllerFillHeadPullIntoDescriptor(controller, bytesWritten, pullIntoDescriptor);
1148
1148
  if (pullIntoDescriptor.bytesFilled < pullIntoDescriptor.elementSize) {
1149
- // TODO: Figure out whether we should detach the buffer or not here.
1150
1149
  return;
1151
1150
  }
1152
1151
  ReadableByteStreamControllerShiftPendingPullInto(controller);
1153
1152
  var remainderSize = pullIntoDescriptor.bytesFilled % pullIntoDescriptor.elementSize;
1154
1153
  if (remainderSize > 0) {
1155
1154
  var end = pullIntoDescriptor.byteOffset + pullIntoDescriptor.bytesFilled;
1156
- var remainder = pullIntoDescriptor.buffer.slice(end - remainderSize, end);
1155
+ var remainder = ArrayBufferSlice(pullIntoDescriptor.buffer, end - remainderSize, end);
1157
1156
  ReadableByteStreamControllerEnqueueChunkToQueue(controller, remainder, 0, remainder.byteLength);
1158
1157
  }
1159
- pullIntoDescriptor.buffer = TransferArrayBuffer(pullIntoDescriptor.buffer);
1160
1158
  pullIntoDescriptor.bytesFilled -= remainderSize;
1161
1159
  ReadableByteStreamControllerCommitPullIntoDescriptor(controller._controlledReadableByteStream, pullIntoDescriptor);
1162
1160
  ReadableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(controller);
1163
1161
  }
1164
1162
  function ReadableByteStreamControllerRespondInternal(controller, bytesWritten) {
1165
1163
  var firstDescriptor = controller._pendingPullIntos.peek();
1164
+ ReadableByteStreamControllerInvalidateBYOBRequest(controller);
1166
1165
  var state = controller._controlledReadableByteStream._state;
1167
1166
  if (state === 'closed') {
1168
- if (bytesWritten !== 0) {
1169
- throw new TypeError('bytesWritten must be 0 when calling respond() on a closed stream');
1170
- }
1171
- ReadableByteStreamControllerRespondInClosedState(controller, firstDescriptor);
1167
+ ReadableByteStreamControllerRespondInClosedState(controller);
1172
1168
  }
1173
1169
  else {
1174
1170
  ReadableByteStreamControllerRespondInReadableState(controller, bytesWritten, firstDescriptor);
@@ -1177,7 +1173,6 @@
1177
1173
  }
1178
1174
  function ReadableByteStreamControllerShiftPendingPullInto(controller) {
1179
1175
  var descriptor = controller._pendingPullIntos.shift();
1180
- ReadableByteStreamControllerInvalidateBYOBRequest(controller);
1181
1176
  return descriptor;
1182
1177
  }
1183
1178
  function ReadableByteStreamControllerShouldCallPull(controller) {
@@ -1237,6 +1232,12 @@
1237
1232
  var byteOffset = chunk.byteOffset;
1238
1233
  var byteLength = chunk.byteLength;
1239
1234
  var transferredBuffer = TransferArrayBuffer(buffer);
1235
+ if (controller._pendingPullIntos.length > 0) {
1236
+ var firstPendingPullInto = controller._pendingPullIntos.peek();
1237
+ if (IsDetachedBuffer(firstPendingPullInto.buffer)) ;
1238
+ firstPendingPullInto.buffer = TransferArrayBuffer(firstPendingPullInto.buffer);
1239
+ }
1240
+ ReadableByteStreamControllerInvalidateBYOBRequest(controller);
1240
1241
  if (ReadableStreamHasDefaultReader(stream)) {
1241
1242
  if (ReadableStreamGetNumReadRequests(stream) === 0) {
1242
1243
  ReadableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset, byteLength);
@@ -1266,6 +1267,16 @@
1266
1267
  ReadableByteStreamControllerClearAlgorithms(controller);
1267
1268
  ReadableStreamError(stream, e);
1268
1269
  }
1270
+ function ReadableByteStreamControllerGetBYOBRequest(controller) {
1271
+ if (controller._byobRequest === null && controller._pendingPullIntos.length > 0) {
1272
+ var firstDescriptor = controller._pendingPullIntos.peek();
1273
+ var view = new Uint8Array(firstDescriptor.buffer, firstDescriptor.byteOffset + firstDescriptor.bytesFilled, firstDescriptor.byteLength - firstDescriptor.bytesFilled);
1274
+ var byobRequest = Object.create(ReadableStreamBYOBRequest.prototype);
1275
+ SetUpReadableStreamBYOBRequest(byobRequest, controller, view);
1276
+ controller._byobRequest = byobRequest;
1277
+ }
1278
+ return controller._byobRequest;
1279
+ }
1269
1280
  function ReadableByteStreamControllerGetDesiredSize(controller) {
1270
1281
  var state = controller._controlledReadableByteStream._state;
1271
1282
  if (state === 'errored') {
@@ -1277,21 +1288,47 @@
1277
1288
  return controller._strategyHWM - controller._queueTotalSize;
1278
1289
  }
1279
1290
  function ReadableByteStreamControllerRespond(controller, bytesWritten) {
1280
- bytesWritten = Number(bytesWritten);
1281
- if (!IsFiniteNonNegativeNumber(bytesWritten)) {
1282
- throw new RangeError('bytesWritten must be a finite');
1291
+ var firstDescriptor = controller._pendingPullIntos.peek();
1292
+ var state = controller._controlledReadableByteStream._state;
1293
+ if (state === 'closed') {
1294
+ if (bytesWritten !== 0) {
1295
+ throw new TypeError('bytesWritten must be 0 when calling respond() on a closed stream');
1296
+ }
1297
+ }
1298
+ else {
1299
+ if (bytesWritten === 0) {
1300
+ throw new TypeError('bytesWritten must be greater than 0 when calling respond() on a readable stream');
1301
+ }
1302
+ if (firstDescriptor.bytesFilled + bytesWritten > firstDescriptor.byteLength) {
1303
+ throw new RangeError('bytesWritten out of range');
1304
+ }
1283
1305
  }
1306
+ firstDescriptor.buffer = TransferArrayBuffer(firstDescriptor.buffer);
1284
1307
  ReadableByteStreamControllerRespondInternal(controller, bytesWritten);
1285
1308
  }
1286
1309
  function ReadableByteStreamControllerRespondWithNewView(controller, view) {
1287
1310
  var firstDescriptor = controller._pendingPullIntos.peek();
1311
+ var state = controller._controlledReadableByteStream._state;
1312
+ if (state === 'closed') {
1313
+ if (view.byteLength !== 0) {
1314
+ throw new TypeError('The view\'s length must be 0 when calling respondWithNewView() on a closed stream');
1315
+ }
1316
+ }
1317
+ else {
1318
+ if (view.byteLength === 0) {
1319
+ throw new TypeError('The view\'s length must be greater than 0 when calling respondWithNewView() on a readable stream');
1320
+ }
1321
+ }
1288
1322
  if (firstDescriptor.byteOffset + firstDescriptor.bytesFilled !== view.byteOffset) {
1289
1323
  throw new RangeError('The region specified by view does not match byobRequest');
1290
1324
  }
1291
- if (firstDescriptor.byteLength !== view.byteLength) {
1325
+ if (firstDescriptor.bufferByteLength !== view.buffer.byteLength) {
1292
1326
  throw new RangeError('The buffer of view has different capacity than byobRequest');
1293
1327
  }
1294
- firstDescriptor.buffer = view.buffer;
1328
+ if (firstDescriptor.bytesFilled + view.byteLength > firstDescriptor.byteLength) {
1329
+ throw new RangeError('The region specified by view is larger than byobRequest');
1330
+ }
1331
+ firstDescriptor.buffer = TransferArrayBuffer(view.buffer);
1295
1332
  ReadableByteStreamControllerRespondInternal(controller, view.byteLength);
1296
1333
  }
1297
1334
  function SetUpReadableByteStreamController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, autoAllocateChunkSize) {
@@ -1333,6 +1370,9 @@
1333
1370
  cancelAlgorithm = function (reason) { return underlyingByteSource.cancel(reason); };
1334
1371
  }
1335
1372
  var autoAllocateChunkSize = underlyingByteSource.autoAllocateChunkSize;
1373
+ if (autoAllocateChunkSize === 0) {
1374
+ throw new TypeError('autoAllocateChunkSize must be greater than 0');
1375
+ }
1336
1376
  SetUpReadableByteStreamController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, autoAllocateChunkSize);
1337
1377
  }
1338
1378
  function SetUpReadableStreamBYOBRequest(request, controller, view) {
@@ -1443,6 +1483,7 @@
1443
1483
  if (view.buffer.byteLength === 0) {
1444
1484
  return promiseRejectedWith(new TypeError("view's buffer must have non-zero byteLength"));
1445
1485
  }
1486
+ if (IsDetachedBuffer(view.buffer)) ;
1446
1487
  if (this._ownerReadableStream === undefined) {
1447
1488
  return promiseRejectedWith(readerLockException('read from'));
1448
1489
  }
@@ -1503,7 +1544,7 @@
1503
1544
  if (!Object.prototype.hasOwnProperty.call(x, '_readIntoRequests')) {
1504
1545
  return false;
1505
1546
  }
1506
- return true;
1547
+ return x instanceof ReadableStreamBYOBReader;
1507
1548
  }
1508
1549
  function ReadableStreamBYOBReaderRead(reader, view, readIntoRequest) {
1509
1550
  var stream = reader._ownerReadableStream;
@@ -1598,6 +1639,31 @@
1598
1639
  }
1599
1640
  }
1600
1641
 
1642
+ function isAbortSignal(value) {
1643
+ if (typeof value !== 'object' || value === null) {
1644
+ return false;
1645
+ }
1646
+ try {
1647
+ return typeof value.aborted === 'boolean';
1648
+ }
1649
+ catch (_a) {
1650
+ // AbortSignal.prototype.aborted throws if its brand check fails
1651
+ return false;
1652
+ }
1653
+ }
1654
+ var supportsAbortController = typeof AbortController === 'function';
1655
+ /**
1656
+ * Construct a new AbortController, if supported by the platform.
1657
+ *
1658
+ * @internal
1659
+ */
1660
+ function createAbortController() {
1661
+ if (supportsAbortController) {
1662
+ return new AbortController();
1663
+ }
1664
+ return undefined;
1665
+ }
1666
+
1601
1667
  /**
1602
1668
  * A writable stream represents a destination for data, into which you can write.
1603
1669
  *
@@ -1630,7 +1696,7 @@
1630
1696
  */
1631
1697
  get: function () {
1632
1698
  if (!IsWritableStream(this)) {
1633
- throw streamBrandCheckException('locked');
1699
+ throw streamBrandCheckException$2('locked');
1634
1700
  }
1635
1701
  return IsWritableStreamLocked(this);
1636
1702
  },
@@ -1649,7 +1715,7 @@
1649
1715
  WritableStream.prototype.abort = function (reason) {
1650
1716
  if (reason === void 0) { reason = undefined; }
1651
1717
  if (!IsWritableStream(this)) {
1652
- return promiseRejectedWith(streamBrandCheckException('abort'));
1718
+ return promiseRejectedWith(streamBrandCheckException$2('abort'));
1653
1719
  }
1654
1720
  if (IsWritableStreamLocked(this)) {
1655
1721
  return promiseRejectedWith(new TypeError('Cannot abort a stream that already has a writer'));
@@ -1666,7 +1732,7 @@
1666
1732
  */
1667
1733
  WritableStream.prototype.close = function () {
1668
1734
  if (!IsWritableStream(this)) {
1669
- return promiseRejectedWith(streamBrandCheckException('close'));
1735
+ return promiseRejectedWith(streamBrandCheckException$2('close'));
1670
1736
  }
1671
1737
  if (IsWritableStreamLocked(this)) {
1672
1738
  return promiseRejectedWith(new TypeError('Cannot close a stream that already has a writer'));
@@ -1686,7 +1752,7 @@
1686
1752
  */
1687
1753
  WritableStream.prototype.getWriter = function () {
1688
1754
  if (!IsWritableStream(this)) {
1689
- throw streamBrandCheckException('getWriter');
1755
+ throw streamBrandCheckException$2('getWriter');
1690
1756
  }
1691
1757
  return AcquireWritableStreamDefaultWriter(this);
1692
1758
  };
@@ -1751,7 +1817,7 @@
1751
1817
  if (!Object.prototype.hasOwnProperty.call(x, '_writableStreamController')) {
1752
1818
  return false;
1753
1819
  }
1754
- return true;
1820
+ return x instanceof WritableStream;
1755
1821
  }
1756
1822
  function IsWritableStreamLocked(stream) {
1757
1823
  if (stream._writer === undefined) {
@@ -1760,6 +1826,15 @@
1760
1826
  return true;
1761
1827
  }
1762
1828
  function WritableStreamAbort(stream, reason) {
1829
+ var _a;
1830
+ if (stream._state === 'closed' || stream._state === 'errored') {
1831
+ return promiseResolvedWith(undefined);
1832
+ }
1833
+ stream._writableStreamController._abortReason = reason;
1834
+ (_a = stream._writableStreamController._abortController) === null || _a === void 0 ? void 0 : _a.abort();
1835
+ // TypeScript narrows the type of `stream._state` down to 'writable' | 'erroring',
1836
+ // but it doesn't know that signaling abort runs author code that might have changed the state.
1837
+ // Widen the type again by casting to WritableStreamState.
1763
1838
  var state = stream._state;
1764
1839
  if (state === 'closed' || state === 'errored') {
1765
1840
  return promiseResolvedWith(undefined);
@@ -2120,7 +2195,7 @@
2120
2195
  if (!Object.prototype.hasOwnProperty.call(x, '_ownerWritableStream')) {
2121
2196
  return false;
2122
2197
  }
2123
- return true;
2198
+ return x instanceof WritableStreamDefaultWriter;
2124
2199
  }
2125
2200
  // A client of WritableStreamDefaultWriter may use these functions directly to bypass state check.
2126
2201
  function WritableStreamDefaultWriterAbort(writer, reason) {
@@ -2210,6 +2285,38 @@
2210
2285
  function WritableStreamDefaultController() {
2211
2286
  throw new TypeError('Illegal constructor');
2212
2287
  }
2288
+ Object.defineProperty(WritableStreamDefaultController.prototype, "abortReason", {
2289
+ /**
2290
+ * The reason which was passed to `WritableStream.abort(reason)` when the stream was aborted.
2291
+ */
2292
+ get: function () {
2293
+ if (!IsWritableStreamDefaultController(this)) {
2294
+ throw defaultControllerBrandCheckException$2('abortReason');
2295
+ }
2296
+ return this._abortReason;
2297
+ },
2298
+ enumerable: false,
2299
+ configurable: true
2300
+ });
2301
+ Object.defineProperty(WritableStreamDefaultController.prototype, "signal", {
2302
+ /**
2303
+ * An `AbortSignal` that can be used to abort the pending write or close operation when the stream is aborted.
2304
+ */
2305
+ get: function () {
2306
+ if (!IsWritableStreamDefaultController(this)) {
2307
+ throw defaultControllerBrandCheckException$2('signal');
2308
+ }
2309
+ if (this._abortController === undefined) {
2310
+ // Older browsers or older Node versions may not support `AbortController` or `AbortSignal`.
2311
+ // We don't want to bundle and ship an `AbortController` polyfill together with our polyfill,
2312
+ // so instead we only implement support for `signal` if we find a global `AbortController` constructor.
2313
+ throw new TypeError('WritableStreamDefaultController.prototype.signal is not supported');
2314
+ }
2315
+ return this._abortController.signal;
2316
+ },
2317
+ enumerable: false,
2318
+ configurable: true
2319
+ });
2213
2320
  /**
2214
2321
  * Closes the controlled writable stream, making all future interactions with it fail with the given error `e`.
2215
2322
  *
@@ -2220,7 +2327,7 @@
2220
2327
  WritableStreamDefaultController.prototype.error = function (e) {
2221
2328
  if (e === void 0) { e = undefined; }
2222
2329
  if (!IsWritableStreamDefaultController(this)) {
2223
- throw new TypeError('WritableStreamDefaultController.prototype.error can only be used on a WritableStreamDefaultController');
2330
+ throw defaultControllerBrandCheckException$2('error');
2224
2331
  }
2225
2332
  var state = this._controlledWritableStream._state;
2226
2333
  if (state !== 'writable') {
@@ -2259,7 +2366,7 @@
2259
2366
  if (!Object.prototype.hasOwnProperty.call(x, '_controlledWritableStream')) {
2260
2367
  return false;
2261
2368
  }
2262
- return true;
2369
+ return x instanceof WritableStreamDefaultController;
2263
2370
  }
2264
2371
  function SetUpWritableStreamDefaultController(stream, controller, startAlgorithm, writeAlgorithm, closeAlgorithm, abortAlgorithm, highWaterMark, sizeAlgorithm) {
2265
2372
  controller._controlledWritableStream = stream;
@@ -2268,6 +2375,8 @@
2268
2375
  controller._queue = undefined;
2269
2376
  controller._queueTotalSize = undefined;
2270
2377
  ResetQueue(controller);
2378
+ controller._abortReason = undefined;
2379
+ controller._abortController = createAbortController();
2271
2380
  controller._started = false;
2272
2381
  controller._strategySizeAlgorithm = sizeAlgorithm;
2273
2382
  controller._strategyHWM = highWaterMark;
@@ -2417,9 +2526,13 @@
2417
2526
  WritableStreamStartErroring(stream, error);
2418
2527
  }
2419
2528
  // Helper functions for the WritableStream.
2420
- function streamBrandCheckException(name) {
2529
+ function streamBrandCheckException$2(name) {
2421
2530
  return new TypeError("WritableStream.prototype." + name + " can only be used on a WritableStream");
2422
2531
  }
2532
+ // Helper functions for the WritableStreamDefaultController.
2533
+ function defaultControllerBrandCheckException$2(name) {
2534
+ return new TypeError("WritableStreamDefaultController.prototype." + name + " can only be used on a WritableStreamDefaultController");
2535
+ }
2423
2536
  // Helper functions for the WritableStreamDefaultWriter.
2424
2537
  function defaultWriterBrandCheckException(name) {
2425
2538
  return new TypeError("WritableStreamDefaultWriter.prototype." + name + " can only be used on a WritableStreamDefaultWriter");
@@ -2505,19 +2618,6 @@
2505
2618
  writer._readyPromiseState = 'fulfilled';
2506
2619
  }
2507
2620
 
2508
- function isAbortSignal(value) {
2509
- if (typeof value !== 'object' || value === null) {
2510
- return false;
2511
- }
2512
- try {
2513
- return typeof value.aborted === 'boolean';
2514
- }
2515
- catch (_a) {
2516
- // AbortSignal.prototype.aborted throws if its brand check fails
2517
- return false;
2518
- }
2519
- }
2520
-
2521
2621
  /// <reference lib="dom" />
2522
2622
  var NativeDOMException = typeof DOMException !== 'undefined' ? DOMException : undefined;
2523
2623
 
@@ -2535,6 +2635,7 @@
2535
2635
  }
2536
2636
  }
2537
2637
  function createDOMExceptionPolyfill() {
2638
+ // eslint-disable-next-line no-shadow
2538
2639
  var ctor = function DOMException(message, name) {
2539
2640
  this.message = message || '';
2540
2641
  this.name = name || 'Error';
@@ -2546,6 +2647,7 @@
2546
2647
  Object.defineProperty(ctor.prototype, 'constructor', { value: ctor, writable: true, configurable: true });
2547
2648
  return ctor;
2548
2649
  }
2650
+ // eslint-disable-next-line no-redeclare
2549
2651
  var DOMException$1 = isDOMExceptionConstructor(NativeDOMException) ? NativeDOMException : createDOMExceptionPolyfill();
2550
2652
 
2551
2653
  function ReadableStreamPipeTo(source, dest, preventClose, preventAbort, preventCancel, signal) {
@@ -2739,7 +2841,7 @@
2739
2841
  */
2740
2842
  get: function () {
2741
2843
  if (!IsReadableStreamDefaultController(this)) {
2742
- throw defaultControllerBrandCheckException('desiredSize');
2844
+ throw defaultControllerBrandCheckException$1('desiredSize');
2743
2845
  }
2744
2846
  return ReadableStreamDefaultControllerGetDesiredSize(this);
2745
2847
  },
@@ -2752,7 +2854,7 @@
2752
2854
  */
2753
2855
  ReadableStreamDefaultController.prototype.close = function () {
2754
2856
  if (!IsReadableStreamDefaultController(this)) {
2755
- throw defaultControllerBrandCheckException('close');
2857
+ throw defaultControllerBrandCheckException$1('close');
2756
2858
  }
2757
2859
  if (!ReadableStreamDefaultControllerCanCloseOrEnqueue(this)) {
2758
2860
  throw new TypeError('The stream is not in a state that permits close');
@@ -2762,7 +2864,7 @@
2762
2864
  ReadableStreamDefaultController.prototype.enqueue = function (chunk) {
2763
2865
  if (chunk === void 0) { chunk = undefined; }
2764
2866
  if (!IsReadableStreamDefaultController(this)) {
2765
- throw defaultControllerBrandCheckException('enqueue');
2867
+ throw defaultControllerBrandCheckException$1('enqueue');
2766
2868
  }
2767
2869
  if (!ReadableStreamDefaultControllerCanCloseOrEnqueue(this)) {
2768
2870
  throw new TypeError('The stream is not in a state that permits enqueue');
@@ -2775,7 +2877,7 @@
2775
2877
  ReadableStreamDefaultController.prototype.error = function (e) {
2776
2878
  if (e === void 0) { e = undefined; }
2777
2879
  if (!IsReadableStreamDefaultController(this)) {
2778
- throw defaultControllerBrandCheckException('error');
2880
+ throw defaultControllerBrandCheckException$1('error');
2779
2881
  }
2780
2882
  ReadableStreamDefaultControllerError(this, e);
2781
2883
  };
@@ -2827,7 +2929,7 @@
2827
2929
  if (!Object.prototype.hasOwnProperty.call(x, '_controlledReadableStream')) {
2828
2930
  return false;
2829
2931
  }
2830
- return true;
2932
+ return x instanceof ReadableStreamDefaultController;
2831
2933
  }
2832
2934
  function ReadableStreamDefaultControllerCallPullIfNeeded(controller) {
2833
2935
  var shouldPull = ReadableStreamDefaultControllerShouldCallPull(controller);
@@ -2983,11 +3085,17 @@
2983
3085
  SetUpReadableStreamDefaultController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, sizeAlgorithm);
2984
3086
  }
2985
3087
  // Helper functions for the ReadableStreamDefaultController.
2986
- function defaultControllerBrandCheckException(name) {
3088
+ function defaultControllerBrandCheckException$1(name) {
2987
3089
  return new TypeError("ReadableStreamDefaultController.prototype." + name + " can only be used on a ReadableStreamDefaultController");
2988
3090
  }
2989
3091
 
2990
3092
  function ReadableStreamTee(stream, cloneForBranch2) {
3093
+ if (IsReadableByteStreamController(stream._readableStreamController)) {
3094
+ return ReadableByteStreamTee(stream);
3095
+ }
3096
+ return ReadableStreamDefaultTee(stream);
3097
+ }
3098
+ function ReadableStreamDefaultTee(stream, cloneForBranch2) {
2991
3099
  var reader = AcquireReadableStreamDefaultReader(stream);
2992
3100
  var reading = false;
2993
3101
  var canceled1 = false;
@@ -3006,26 +3114,25 @@
3006
3114
  }
3007
3115
  reading = true;
3008
3116
  var readRequest = {
3009
- _chunkSteps: function (value) {
3117
+ _chunkSteps: function (chunk) {
3010
3118
  // This needs to be delayed a microtask because it takes at least a microtask to detect errors (using
3011
3119
  // reader._closedPromise below), and we want errors in stream to error both branches immediately. We cannot let
3012
3120
  // successful synchronously-available reads get ahead of asynchronously-available errors.
3013
3121
  queueMicrotask(function () {
3014
3122
  reading = false;
3015
- var value1 = value;
3016
- var value2 = value;
3123
+ var chunk1 = chunk;
3124
+ var chunk2 = chunk;
3017
3125
  // There is no way to access the cloning code right now in the reference implementation.
3018
3126
  // If we add one then we'll need an implementation for serializable objects.
3019
3127
  // if (!canceled2 && cloneForBranch2) {
3020
- // value2 = StructuredDeserialize(StructuredSerialize(value2));
3128
+ // chunk2 = StructuredDeserialize(StructuredSerialize(chunk2));
3021
3129
  // }
3022
3130
  if (!canceled1) {
3023
- ReadableStreamDefaultControllerEnqueue(branch1._readableStreamController, value1);
3131
+ ReadableStreamDefaultControllerEnqueue(branch1._readableStreamController, chunk1);
3024
3132
  }
3025
3133
  if (!canceled2) {
3026
- ReadableStreamDefaultControllerEnqueue(branch2._readableStreamController, value2);
3134
+ ReadableStreamDefaultControllerEnqueue(branch2._readableStreamController, chunk2);
3027
3135
  }
3028
- resolveCancelPromise(undefined);
3029
3136
  });
3030
3137
  },
3031
3138
  _closeSteps: function () {
@@ -3036,6 +3143,9 @@
3036
3143
  if (!canceled2) {
3037
3144
  ReadableStreamDefaultControllerClose(branch2._readableStreamController);
3038
3145
  }
3146
+ if (!canceled1 || !canceled2) {
3147
+ resolveCancelPromise(undefined);
3148
+ }
3039
3149
  },
3040
3150
  _errorSteps: function () {
3041
3151
  reading = false;
@@ -3072,10 +3182,217 @@
3072
3182
  uponRejection(reader._closedPromise, function (r) {
3073
3183
  ReadableStreamDefaultControllerError(branch1._readableStreamController, r);
3074
3184
  ReadableStreamDefaultControllerError(branch2._readableStreamController, r);
3075
- resolveCancelPromise(undefined);
3185
+ if (!canceled1 || !canceled2) {
3186
+ resolveCancelPromise(undefined);
3187
+ }
3076
3188
  });
3077
3189
  return [branch1, branch2];
3078
3190
  }
3191
+ function ReadableByteStreamTee(stream) {
3192
+ var reader = AcquireReadableStreamDefaultReader(stream);
3193
+ var reading = false;
3194
+ var canceled1 = false;
3195
+ var canceled2 = false;
3196
+ var reason1;
3197
+ var reason2;
3198
+ var branch1;
3199
+ var branch2;
3200
+ var resolveCancelPromise;
3201
+ var cancelPromise = newPromise(function (resolve) {
3202
+ resolveCancelPromise = resolve;
3203
+ });
3204
+ function forwardReaderError(thisReader) {
3205
+ uponRejection(thisReader._closedPromise, function (r) {
3206
+ if (thisReader !== reader) {
3207
+ return;
3208
+ }
3209
+ ReadableByteStreamControllerError(branch1._readableStreamController, r);
3210
+ ReadableByteStreamControllerError(branch2._readableStreamController, r);
3211
+ if (!canceled1 || !canceled2) {
3212
+ resolveCancelPromise(undefined);
3213
+ }
3214
+ });
3215
+ }
3216
+ function pullWithDefaultReader() {
3217
+ if (IsReadableStreamBYOBReader(reader)) {
3218
+ ReadableStreamReaderGenericRelease(reader);
3219
+ reader = AcquireReadableStreamDefaultReader(stream);
3220
+ forwardReaderError(reader);
3221
+ }
3222
+ var readRequest = {
3223
+ _chunkSteps: function (chunk) {
3224
+ // This needs to be delayed a microtask because it takes at least a microtask to detect errors (using
3225
+ // reader._closedPromise below), and we want errors in stream to error both branches immediately. We cannot let
3226
+ // successful synchronously-available reads get ahead of asynchronously-available errors.
3227
+ queueMicrotask(function () {
3228
+ reading = false;
3229
+ var chunk1 = chunk;
3230
+ var chunk2 = chunk;
3231
+ if (!canceled1 && !canceled2) {
3232
+ try {
3233
+ chunk2 = CloneAsUint8Array(chunk);
3234
+ }
3235
+ catch (cloneE) {
3236
+ ReadableByteStreamControllerError(branch1._readableStreamController, cloneE);
3237
+ ReadableByteStreamControllerError(branch2._readableStreamController, cloneE);
3238
+ resolveCancelPromise(ReadableStreamCancel(stream, cloneE));
3239
+ return;
3240
+ }
3241
+ }
3242
+ if (!canceled1) {
3243
+ ReadableByteStreamControllerEnqueue(branch1._readableStreamController, chunk1);
3244
+ }
3245
+ if (!canceled2) {
3246
+ ReadableByteStreamControllerEnqueue(branch2._readableStreamController, chunk2);
3247
+ }
3248
+ });
3249
+ },
3250
+ _closeSteps: function () {
3251
+ reading = false;
3252
+ if (!canceled1) {
3253
+ ReadableByteStreamControllerClose(branch1._readableStreamController);
3254
+ }
3255
+ if (!canceled2) {
3256
+ ReadableByteStreamControllerClose(branch2._readableStreamController);
3257
+ }
3258
+ if (branch1._readableStreamController._pendingPullIntos.length > 0) {
3259
+ ReadableByteStreamControllerRespond(branch1._readableStreamController, 0);
3260
+ }
3261
+ if (branch2._readableStreamController._pendingPullIntos.length > 0) {
3262
+ ReadableByteStreamControllerRespond(branch2._readableStreamController, 0);
3263
+ }
3264
+ if (!canceled1 || !canceled2) {
3265
+ resolveCancelPromise(undefined);
3266
+ }
3267
+ },
3268
+ _errorSteps: function () {
3269
+ reading = false;
3270
+ }
3271
+ };
3272
+ ReadableStreamDefaultReaderRead(reader, readRequest);
3273
+ }
3274
+ function pullWithBYOBReader(view, forBranch2) {
3275
+ if (IsReadableStreamDefaultReader(reader)) {
3276
+ ReadableStreamReaderGenericRelease(reader);
3277
+ reader = AcquireReadableStreamBYOBReader(stream);
3278
+ forwardReaderError(reader);
3279
+ }
3280
+ var byobBranch = forBranch2 ? branch2 : branch1;
3281
+ var otherBranch = forBranch2 ? branch1 : branch2;
3282
+ var readIntoRequest = {
3283
+ _chunkSteps: function (chunk) {
3284
+ // This needs to be delayed a microtask because it takes at least a microtask to detect errors (using
3285
+ // reader._closedPromise below), and we want errors in stream to error both branches immediately. We cannot let
3286
+ // successful synchronously-available reads get ahead of asynchronously-available errors.
3287
+ queueMicrotask(function () {
3288
+ reading = false;
3289
+ var byobCanceled = forBranch2 ? canceled2 : canceled1;
3290
+ var otherCanceled = forBranch2 ? canceled1 : canceled2;
3291
+ if (!otherCanceled) {
3292
+ var clonedChunk = void 0;
3293
+ try {
3294
+ clonedChunk = CloneAsUint8Array(chunk);
3295
+ }
3296
+ catch (cloneE) {
3297
+ ReadableByteStreamControllerError(byobBranch._readableStreamController, cloneE);
3298
+ ReadableByteStreamControllerError(otherBranch._readableStreamController, cloneE);
3299
+ resolveCancelPromise(ReadableStreamCancel(stream, cloneE));
3300
+ return;
3301
+ }
3302
+ if (!byobCanceled) {
3303
+ ReadableByteStreamControllerRespondWithNewView(byobBranch._readableStreamController, chunk);
3304
+ }
3305
+ ReadableByteStreamControllerEnqueue(otherBranch._readableStreamController, clonedChunk);
3306
+ }
3307
+ else if (!byobCanceled) {
3308
+ ReadableByteStreamControllerRespondWithNewView(byobBranch._readableStreamController, chunk);
3309
+ }
3310
+ });
3311
+ },
3312
+ _closeSteps: function (chunk) {
3313
+ reading = false;
3314
+ var byobCanceled = forBranch2 ? canceled2 : canceled1;
3315
+ var otherCanceled = forBranch2 ? canceled1 : canceled2;
3316
+ if (!byobCanceled) {
3317
+ ReadableByteStreamControllerClose(byobBranch._readableStreamController);
3318
+ }
3319
+ if (!otherCanceled) {
3320
+ ReadableByteStreamControllerClose(otherBranch._readableStreamController);
3321
+ }
3322
+ if (chunk !== undefined) {
3323
+ if (!byobCanceled) {
3324
+ ReadableByteStreamControllerRespondWithNewView(byobBranch._readableStreamController, chunk);
3325
+ }
3326
+ if (!otherCanceled && otherBranch._readableStreamController._pendingPullIntos.length > 0) {
3327
+ ReadableByteStreamControllerRespond(otherBranch._readableStreamController, 0);
3328
+ }
3329
+ }
3330
+ if (!byobCanceled || !otherCanceled) {
3331
+ resolveCancelPromise(undefined);
3332
+ }
3333
+ },
3334
+ _errorSteps: function () {
3335
+ reading = false;
3336
+ }
3337
+ };
3338
+ ReadableStreamBYOBReaderRead(reader, view, readIntoRequest);
3339
+ }
3340
+ function pull1Algorithm() {
3341
+ if (reading) {
3342
+ return promiseResolvedWith(undefined);
3343
+ }
3344
+ reading = true;
3345
+ var byobRequest = ReadableByteStreamControllerGetBYOBRequest(branch1._readableStreamController);
3346
+ if (byobRequest === null) {
3347
+ pullWithDefaultReader();
3348
+ }
3349
+ else {
3350
+ pullWithBYOBReader(byobRequest._view, false);
3351
+ }
3352
+ return promiseResolvedWith(undefined);
3353
+ }
3354
+ function pull2Algorithm() {
3355
+ if (reading) {
3356
+ return promiseResolvedWith(undefined);
3357
+ }
3358
+ reading = true;
3359
+ var byobRequest = ReadableByteStreamControllerGetBYOBRequest(branch2._readableStreamController);
3360
+ if (byobRequest === null) {
3361
+ pullWithDefaultReader();
3362
+ }
3363
+ else {
3364
+ pullWithBYOBReader(byobRequest._view, true);
3365
+ }
3366
+ return promiseResolvedWith(undefined);
3367
+ }
3368
+ function cancel1Algorithm(reason) {
3369
+ canceled1 = true;
3370
+ reason1 = reason;
3371
+ if (canceled2) {
3372
+ var compositeReason = CreateArrayFromList([reason1, reason2]);
3373
+ var cancelResult = ReadableStreamCancel(stream, compositeReason);
3374
+ resolveCancelPromise(cancelResult);
3375
+ }
3376
+ return cancelPromise;
3377
+ }
3378
+ function cancel2Algorithm(reason) {
3379
+ canceled2 = true;
3380
+ reason2 = reason;
3381
+ if (canceled1) {
3382
+ var compositeReason = CreateArrayFromList([reason1, reason2]);
3383
+ var cancelResult = ReadableStreamCancel(stream, compositeReason);
3384
+ resolveCancelPromise(cancelResult);
3385
+ }
3386
+ return cancelPromise;
3387
+ }
3388
+ function startAlgorithm() {
3389
+ return;
3390
+ }
3391
+ branch1 = CreateReadableByteStream(startAlgorithm, pull1Algorithm, cancel1Algorithm);
3392
+ branch2 = CreateReadableByteStream(startAlgorithm, pull2Algorithm, cancel2Algorithm);
3393
+ forwardReaderError(reader);
3394
+ return [branch1, branch2];
3395
+ }
3079
3396
 
3080
3397
  function convertUnderlyingDefaultOrByteSource(source, context) {
3081
3398
  assertDictionary(source, context);
@@ -3351,6 +3668,14 @@
3351
3668
  SetUpReadableStreamDefaultController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, sizeAlgorithm);
3352
3669
  return stream;
3353
3670
  }
3671
+ // Throws if and only if startAlgorithm throws.
3672
+ function CreateReadableByteStream(startAlgorithm, pullAlgorithm, cancelAlgorithm) {
3673
+ var stream = Object.create(ReadableStream.prototype);
3674
+ InitializeReadableStream(stream);
3675
+ var controller = Object.create(ReadableByteStreamController.prototype);
3676
+ SetUpReadableByteStreamController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, 0, undefined);
3677
+ return stream;
3678
+ }
3354
3679
  function InitializeReadableStream(stream) {
3355
3680
  stream._state = 'readable';
3356
3681
  stream._reader = undefined;
@@ -3364,7 +3689,7 @@
3364
3689
  if (!Object.prototype.hasOwnProperty.call(x, '_readableStreamController')) {
3365
3690
  return false;
3366
3691
  }
3367
- return true;
3692
+ return x instanceof ReadableStream;
3368
3693
  }
3369
3694
  function IsReadableStreamLocked(stream) {
3370
3695
  if (stream._reader === undefined) {
@@ -3382,6 +3707,13 @@
3382
3707
  return promiseRejectedWith(stream._storedError);
3383
3708
  }
3384
3709
  ReadableStreamClose(stream);
3710
+ var reader = stream._reader;
3711
+ if (reader !== undefined && IsReadableStreamBYOBReader(reader)) {
3712
+ reader._readIntoRequests.forEach(function (readIntoRequest) {
3713
+ readIntoRequest._closeSteps(undefined);
3714
+ });
3715
+ reader._readIntoRequests = new SimpleQueue();
3716
+ }
3385
3717
  var sourceCancelPromise = stream._readableStreamController[CancelSteps](reason);
3386
3718
  return transformPromiseWith(sourceCancelPromise, noop);
3387
3719
  }
@@ -3391,13 +3723,13 @@
3391
3723
  if (reader === undefined) {
3392
3724
  return;
3393
3725
  }
3726
+ defaultReaderClosedPromiseResolve(reader);
3394
3727
  if (IsReadableStreamDefaultReader(reader)) {
3395
3728
  reader._readRequests.forEach(function (readRequest) {
3396
3729
  readRequest._closeSteps();
3397
3730
  });
3398
3731
  reader._readRequests = new SimpleQueue();
3399
3732
  }
3400
- defaultReaderClosedPromiseResolve(reader);
3401
3733
  }
3402
3734
  function ReadableStreamError(stream, e) {
3403
3735
  stream._state = 'errored';
@@ -3406,6 +3738,7 @@
3406
3738
  if (reader === undefined) {
3407
3739
  return;
3408
3740
  }
3741
+ defaultReaderClosedPromiseReject(reader, e);
3409
3742
  if (IsReadableStreamDefaultReader(reader)) {
3410
3743
  reader._readRequests.forEach(function (readRequest) {
3411
3744
  readRequest._errorSteps(e);
@@ -3418,7 +3751,6 @@
3418
3751
  });
3419
3752
  reader._readIntoRequests = new SimpleQueue();
3420
3753
  }
3421
- defaultReaderClosedPromiseReject(reader, e);
3422
3754
  }
3423
3755
  // Helper functions for the ReadableStream.
3424
3756
  function streamBrandCheckException$1(name) {
@@ -3434,9 +3766,14 @@
3434
3766
  };
3435
3767
  }
3436
3768
 
3437
- var byteLengthSizeFunction = function size(chunk) {
3769
+ // The size function must not have a prototype property nor be a constructor
3770
+ var byteLengthSizeFunction = function (chunk) {
3438
3771
  return chunk.byteLength;
3439
3772
  };
3773
+ Object.defineProperty(byteLengthSizeFunction, 'name', {
3774
+ value: 'size',
3775
+ configurable: true
3776
+ });
3440
3777
  /**
3441
3778
  * A queuing strategy that counts the number of bytes in each chunk.
3442
3779
  *
@@ -3497,12 +3834,17 @@
3497
3834
  if (!Object.prototype.hasOwnProperty.call(x, '_byteLengthQueuingStrategyHighWaterMark')) {
3498
3835
  return false;
3499
3836
  }
3500
- return true;
3837
+ return x instanceof ByteLengthQueuingStrategy;
3501
3838
  }
3502
3839
 
3503
- var countSizeFunction = function size() {
3840
+ // The size function must not have a prototype property nor be a constructor
3841
+ var countSizeFunction = function () {
3504
3842
  return 1;
3505
3843
  };
3844
+ Object.defineProperty(countSizeFunction, 'name', {
3845
+ value: 'size',
3846
+ configurable: true
3847
+ });
3506
3848
  /**
3507
3849
  * A queuing strategy that counts the number of chunks.
3508
3850
  *
@@ -3564,7 +3906,7 @@
3564
3906
  if (!Object.prototype.hasOwnProperty.call(x, '_countQueuingStrategyHighWaterMark')) {
3565
3907
  return false;
3566
3908
  }
3567
- return true;
3909
+ return x instanceof CountQueuingStrategy;
3568
3910
  }
3569
3911
 
3570
3912
  function convertTransformer(original, context) {
@@ -3650,7 +3992,7 @@
3650
3992
  */
3651
3993
  get: function () {
3652
3994
  if (!IsTransformStream(this)) {
3653
- throw streamBrandCheckException$2('readable');
3995
+ throw streamBrandCheckException('readable');
3654
3996
  }
3655
3997
  return this._readable;
3656
3998
  },
@@ -3663,7 +4005,7 @@
3663
4005
  */
3664
4006
  get: function () {
3665
4007
  if (!IsTransformStream(this)) {
3666
- throw streamBrandCheckException$2('writable');
4008
+ throw streamBrandCheckException('writable');
3667
4009
  }
3668
4010
  return this._writable;
3669
4011
  },
@@ -3718,7 +4060,7 @@
3718
4060
  if (!Object.prototype.hasOwnProperty.call(x, '_transformStreamController')) {
3719
4061
  return false;
3720
4062
  }
3721
- return true;
4063
+ return x instanceof TransformStream;
3722
4064
  }
3723
4065
  // This is a no-op if both sides are already errored.
3724
4066
  function TransformStreamError(stream, e) {
@@ -3761,7 +4103,7 @@
3761
4103
  */
3762
4104
  get: function () {
3763
4105
  if (!IsTransformStreamDefaultController(this)) {
3764
- throw defaultControllerBrandCheckException$1('desiredSize');
4106
+ throw defaultControllerBrandCheckException('desiredSize');
3765
4107
  }
3766
4108
  var readableController = this._controlledTransformStream._readable._readableStreamController;
3767
4109
  return ReadableStreamDefaultControllerGetDesiredSize(readableController);
@@ -3772,7 +4114,7 @@
3772
4114
  TransformStreamDefaultController.prototype.enqueue = function (chunk) {
3773
4115
  if (chunk === void 0) { chunk = undefined; }
3774
4116
  if (!IsTransformStreamDefaultController(this)) {
3775
- throw defaultControllerBrandCheckException$1('enqueue');
4117
+ throw defaultControllerBrandCheckException('enqueue');
3776
4118
  }
3777
4119
  TransformStreamDefaultControllerEnqueue(this, chunk);
3778
4120
  };
@@ -3783,7 +4125,7 @@
3783
4125
  TransformStreamDefaultController.prototype.error = function (reason) {
3784
4126
  if (reason === void 0) { reason = undefined; }
3785
4127
  if (!IsTransformStreamDefaultController(this)) {
3786
- throw defaultControllerBrandCheckException$1('error');
4128
+ throw defaultControllerBrandCheckException('error');
3787
4129
  }
3788
4130
  TransformStreamDefaultControllerError(this, reason);
3789
4131
  };
@@ -3793,7 +4135,7 @@
3793
4135
  */
3794
4136
  TransformStreamDefaultController.prototype.terminate = function () {
3795
4137
  if (!IsTransformStreamDefaultController(this)) {
3796
- throw defaultControllerBrandCheckException$1('terminate');
4138
+ throw defaultControllerBrandCheckException('terminate');
3797
4139
  }
3798
4140
  TransformStreamDefaultControllerTerminate(this);
3799
4141
  };
@@ -3819,7 +4161,7 @@
3819
4161
  if (!Object.prototype.hasOwnProperty.call(x, '_controlledTransformStream')) {
3820
4162
  return false;
3821
4163
  }
3822
- return true;
4164
+ return x instanceof TransformStreamDefaultController;
3823
4165
  }
3824
4166
  function SetUpTransformStreamDefaultController(stream, controller, transformAlgorithm, flushAlgorithm) {
3825
4167
  controller._controlledTransformStream = stream;
@@ -3936,11 +4278,11 @@
3936
4278
  return stream._backpressureChangePromise;
3937
4279
  }
3938
4280
  // Helper functions for the TransformStreamDefaultController.
3939
- function defaultControllerBrandCheckException$1(name) {
4281
+ function defaultControllerBrandCheckException(name) {
3940
4282
  return new TypeError("TransformStreamDefaultController.prototype." + name + " can only be used on a TransformStreamDefaultController");
3941
4283
  }
3942
4284
  // Helper functions for the TransformStream.
3943
- function streamBrandCheckException$2(name) {
4285
+ function streamBrandCheckException(name) {
3944
4286
  return new TypeError("TransformStream.prototype." + name + " can only be used on a TransformStream");
3945
4287
  }
3946
4288