Skip to content
Snippets Groups Projects
1.index.js 1.51 MiB
Newer Older
  • Learn to ignore specific revisions
  • Romain CREY's avatar
    Romain CREY committed
    6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477 6478 6479 6480 6481 6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 6493 6494 6495 6496 6497 6498 6499 6500 6501 6502 6503 6504 6505 6506 6507 6508 6509 6510 6511 6512 6513 6514 6515 6516 6517 6518 6519 6520 6521 6522 6523 6524 6525 6526 6527 6528 6529 6530 6531 6532 6533 6534 6535 6536 6537 6538 6539 6540 6541 6542 6543 6544 6545 6546 6547 6548 6549 6550 6551 6552 6553 6554 6555 6556 6557 6558 6559 6560 6561 6562 6563 6564 6565 6566 6567 6568 6569 6570 6571 6572 6573 6574 6575 6576 6577 6578 6579 6580 6581 6582 6583 6584 6585 6586 6587 6588 6589 6590 6591 6592 6593 6594 6595 6596 6597 6598 6599 6600 6601 6602 6603 6604 6605 6606 6607 6608 6609 6610 6611 6612 6613 6614 6615 6616 6617 6618 6619 6620 6621 6622 6623 6624 6625 6626 6627 6628 6629 6630 6631 6632 6633 6634 6635 6636 6637 6638 6639 6640 6641 6642 6643 6644 6645 6646 6647 6648 6649 6650 6651 6652 6653 6654 6655 6656 6657 6658 6659 6660 6661 6662 6663 6664 6665 6666 6667 6668 6669 6670 6671 6672 6673 6674 6675 6676 6677 6678 6679 6680 6681 6682 6683 6684 6685 6686 6687 6688 6689 6690 6691 6692 6693 6694 6695 6696 6697 6698 6699 6700 6701 6702 6703 6704 6705 6706 6707 6708 6709 6710 6711 6712 6713 6714 6715 6716 6717 6718 6719 6720 6721 6722 6723 6724 6725 6726 6727 6728 6729 6730 6731 6732 6733 6734 6735 6736 6737 6738 6739 6740 6741 6742 6743 6744 6745 6746 6747 6748 6749 6750 6751 6752 6753 6754 6755 6756 6757 6758 6759 6760 6761 6762 6763 6764 6765 6766 6767 6768 6769 6770 6771 6772 6773 6774 6775 6776 6777 6778 6779 6780 6781 6782 6783 6784 6785 6786 6787 6788 6789 6790 6791 6792 6793 6794 6795 6796 6797 6798 6799 6800 6801 6802 6803 6804 6805 6806 6807 6808 6809 6810 6811 6812 6813 6814 6815 6816 6817 6818 6819 6820 6821 6822 6823 6824 6825 6826 6827 6828 6829 6830 6831 6832 6833 6834 6835 6836 6837 6838 6839 6840 6841 6842 6843 6844 6845 6846 6847 6848 6849 6850 6851 6852 6853 6854 6855 6856 6857 6858 6859 6860 6861 6862 6863 6864 6865 6866 6867 6868 6869 6870 6871 6872 6873 6874 6875 6876 6877 6878 6879 6880 6881 6882 6883 6884 6885 6886 6887 6888 6889 6890 6891 6892 6893 6894 6895 6896 6897 6898 6899 6900 6901 6902 6903 6904 6905 6906 6907 6908 6909 6910 6911 6912 6913 6914 6915 6916 6917 6918 6919 6920 6921 6922 6923 6924 6925 6926 6927 6928 6929 6930 6931 6932 6933 6934 6935 6936 6937 6938 6939 6940 6941 6942 6943 6944 6945 6946 6947 6948 6949 6950 6951 6952 6953 6954 6955 6956 6957 6958 6959 6960 6961 6962 6963 6964 6965 6966 6967 6968 6969 6970 6971 6972 6973 6974 6975 6976 6977 6978 6979 6980 6981 6982 6983 6984 6985 6986 6987 6988 6989 6990 6991 6992 6993 6994 6995 6996 6997 6998 6999 7000
                if (preventClose === false) {
                  shutdownWithAction(function () {
                    return WritableStreamDefaultWriterCloseWithErrorPropagation(writer);
                  });
                } else {
                  shutdown();
                }
              });
              if (WritableStreamCloseQueuedOrInFlight(dest) === true || dest._state === 'closed') {
                var destClosed = new TypeError('the destination writable stream closed before all data could be piped to it');
                if (preventCancel === false) {
                  shutdownWithAction(function () {
                    return ReadableStreamCancel(_this, destClosed);
                  }, true, destClosed);
                } else {
                  shutdown(true, destClosed);
                }
              }
              pipeLoop().catch(function (err) {
                currentWrite = Promise.resolve();
                rethrowAssertionErrorRejection(err);
              });
              function waitForWritesToFinish() {
                var oldCurrentWrite = currentWrite;
                return currentWrite.then(function () {
                  return oldCurrentWrite !== currentWrite ? waitForWritesToFinish() : undefined;
                });
              }
              function isOrBecomesErrored(stream, promise, action) {
                if (stream._state === 'errored') {
                  action(stream._storedError);
                } else {
                  promise.catch(action).catch(rethrowAssertionErrorRejection);
                }
              }
              function isOrBecomesClosed(stream, promise, action) {
                if (stream._state === 'closed') {
                  action();
                } else {
                  promise.then(action).catch(rethrowAssertionErrorRejection);
                }
              }
              function shutdownWithAction(action, originalIsError, originalError) {
                if (shuttingDown === true) {
                  return;
                }
                shuttingDown = true;
                if (dest._state === 'writable' && WritableStreamCloseQueuedOrInFlight(dest) === false) {
                  waitForWritesToFinish().then(doTheRest);
                } else {
                  doTheRest();
                }
                function doTheRest() {
                  action().then(function () {
                    return finalize(originalIsError, originalError);
                  }, function (newError) {
                    return finalize(true, newError);
                  }).catch(rethrowAssertionErrorRejection);
                }
              }
              function shutdown(isError, error) {
                if (shuttingDown === true) {
                  return;
                }
                shuttingDown = true;
                if (dest._state === 'writable' && WritableStreamCloseQueuedOrInFlight(dest) === false) {
                  waitForWritesToFinish().then(function () {
                    return finalize(isError, error);
                  }).catch(rethrowAssertionErrorRejection);
                } else {
                  finalize(isError, error);
                }
              }
              function finalize(isError, error) {
                WritableStreamDefaultWriterRelease(writer);
                ReadableStreamReaderGenericRelease(reader);
                if (isError) {
                  reject(error);
                } else {
                  resolve(undefined);
                }
              }
            });
          }
        }, {
          key: 'tee',
          value: function tee() {
            if (IsReadableStream(this) === false) {
              throw streamBrandCheckException('tee');
            }
            var branches = ReadableStreamTee(this, false);
            return createArrayFromList(branches);
          }
        }, {
          key: 'locked',
          get: function get() {
            if (IsReadableStream(this) === false) {
              throw streamBrandCheckException('locked');
            }
            return IsReadableStreamLocked(this);
          }
        }]);
        return ReadableStream;
      }();
      module.exports = {
        ReadableStream: ReadableStream,
        IsReadableStreamDisturbed: IsReadableStreamDisturbed,
        ReadableStreamDefaultControllerClose: ReadableStreamDefaultControllerClose,
        ReadableStreamDefaultControllerEnqueue: ReadableStreamDefaultControllerEnqueue,
        ReadableStreamDefaultControllerError: ReadableStreamDefaultControllerError,
        ReadableStreamDefaultControllerGetDesiredSize: ReadableStreamDefaultControllerGetDesiredSize
      };
      function AcquireReadableStreamBYOBReader(stream) {
        return new ReadableStreamBYOBReader(stream);
      }
      function AcquireReadableStreamDefaultReader(stream) {
        return new ReadableStreamDefaultReader(stream);
      }
      function IsReadableStream(x) {
        if (!typeIsObject(x)) {
          return false;
        }
        if (!Object.prototype.hasOwnProperty.call(x, '_readableStreamController')) {
          return false;
        }
        return true;
      }
      function IsReadableStreamDisturbed(stream) {
        assert(IsReadableStream(stream) === true, 'IsReadableStreamDisturbed should only be used on known readable streams');
        return stream._disturbed;
      }
      function IsReadableStreamLocked(stream) {
        assert(IsReadableStream(stream) === true, 'IsReadableStreamLocked should only be used on known readable streams');
        if (stream._reader === undefined) {
          return false;
        }
        return true;
      }
      function ReadableStreamTee(stream, cloneForBranch2) {
        assert(IsReadableStream(stream) === true);
        assert(typeof cloneForBranch2 === 'boolean');
        var reader = AcquireReadableStreamDefaultReader(stream);
        var teeState = {
          closedOrErrored: false,
          canceled1: false,
          canceled2: false,
          reason1: undefined,
          reason2: undefined
        };
        teeState.promise = new Promise(function (resolve) {
          teeState._resolve = resolve;
        });
        var pull = create_ReadableStreamTeePullFunction();
        pull._reader = reader;
        pull._teeState = teeState;
        pull._cloneForBranch2 = cloneForBranch2;
        var cancel1 = create_ReadableStreamTeeBranch1CancelFunction();
        cancel1._stream = stream;
        cancel1._teeState = teeState;
        var cancel2 = create_ReadableStreamTeeBranch2CancelFunction();
        cancel2._stream = stream;
        cancel2._teeState = teeState;
        var underlyingSource1 = Object.create(Object.prototype);
        createDataProperty(underlyingSource1, 'pull', pull);
        createDataProperty(underlyingSource1, 'cancel', cancel1);
        var branch1Stream = new ReadableStream(underlyingSource1);
        var underlyingSource2 = Object.create(Object.prototype);
        createDataProperty(underlyingSource2, 'pull', pull);
        createDataProperty(underlyingSource2, 'cancel', cancel2);
        var branch2Stream = new ReadableStream(underlyingSource2);
        pull._branch1 = branch1Stream._readableStreamController;
        pull._branch2 = branch2Stream._readableStreamController;
        reader._closedPromise.catch(function (r) {
          if (teeState.closedOrErrored === true) {
            return;
          }
          ReadableStreamDefaultControllerError(pull._branch1, r);
          ReadableStreamDefaultControllerError(pull._branch2, r);
          teeState.closedOrErrored = true;
        });
        return [branch1Stream, branch2Stream];
      }
      function create_ReadableStreamTeePullFunction() {
        function f() {
          var reader = f._reader,
              branch1 = f._branch1,
              branch2 = f._branch2,
              teeState = f._teeState;
          return ReadableStreamDefaultReaderRead(reader).then(function (result) {
            assert(typeIsObject(result));
            var value = result.value;
            var done = result.done;
            assert(typeof done === 'boolean');
            if (done === true && teeState.closedOrErrored === false) {
              if (teeState.canceled1 === false) {
                ReadableStreamDefaultControllerClose(branch1);
              }
              if (teeState.canceled2 === false) {
                ReadableStreamDefaultControllerClose(branch2);
              }
              teeState.closedOrErrored = true;
            }
            if (teeState.closedOrErrored === true) {
              return;
            }
            var value1 = value;
            var value2 = value;
            if (teeState.canceled1 === false) {
              ReadableStreamDefaultControllerEnqueue(branch1, value1);
            }
            if (teeState.canceled2 === false) {
              ReadableStreamDefaultControllerEnqueue(branch2, value2);
            }
          });
        }
        return f;
      }
      function create_ReadableStreamTeeBranch1CancelFunction() {
        function f(reason) {
          var stream = f._stream,
              teeState = f._teeState;
          teeState.canceled1 = true;
          teeState.reason1 = reason;
          if (teeState.canceled2 === true) {
            var compositeReason = createArrayFromList([teeState.reason1, teeState.reason2]);
            var cancelResult = ReadableStreamCancel(stream, compositeReason);
            teeState._resolve(cancelResult);
          }
          return teeState.promise;
        }
        return f;
      }
      function create_ReadableStreamTeeBranch2CancelFunction() {
        function f(reason) {
          var stream = f._stream,
              teeState = f._teeState;
          teeState.canceled2 = true;
          teeState.reason2 = reason;
          if (teeState.canceled1 === true) {
            var compositeReason = createArrayFromList([teeState.reason1, teeState.reason2]);
            var cancelResult = ReadableStreamCancel(stream, compositeReason);
            teeState._resolve(cancelResult);
          }
          return teeState.promise;
        }
        return f;
      }
      function ReadableStreamAddReadIntoRequest(stream) {
        assert(IsReadableStreamBYOBReader(stream._reader) === true);
        assert(stream._state === 'readable' || stream._state === 'closed');
        var promise = new Promise(function (resolve, reject) {
          var readIntoRequest = {
            _resolve: resolve,
            _reject: reject
          };
          stream._reader._readIntoRequests.push(readIntoRequest);
        });
        return promise;
      }
      function ReadableStreamAddReadRequest(stream) {
        assert(IsReadableStreamDefaultReader(stream._reader) === true);
        assert(stream._state === 'readable');
        var promise = new Promise(function (resolve, reject) {
          var readRequest = {
            _resolve: resolve,
            _reject: reject
          };
          stream._reader._readRequests.push(readRequest);
        });
        return promise;
      }
      function ReadableStreamCancel(stream, reason) {
        stream._disturbed = true;
        if (stream._state === 'closed') {
          return Promise.resolve(undefined);
        }
        if (stream._state === 'errored') {
          return Promise.reject(stream._storedError);
        }
        ReadableStreamClose(stream);
        var sourceCancelPromise = stream._readableStreamController.__cancelSteps(reason);
        return sourceCancelPromise.then(function () {
          return undefined;
        });
      }
      function ReadableStreamClose(stream) {
        assert(stream._state === 'readable');
        stream._state = 'closed';
        var reader = stream._reader;
        if (reader === undefined) {
          return undefined;
        }
        if (IsReadableStreamDefaultReader(reader) === true) {
          for (var i = 0; i < reader._readRequests.length; i++) {
            var _resolve = reader._readRequests[i]._resolve;
            _resolve(CreateIterResultObject(undefined, true));
          }
          reader._readRequests = [];
        }
        defaultReaderClosedPromiseResolve(reader);
        return undefined;
      }
      function ReadableStreamError(stream, e) {
        assert(IsReadableStream(stream) === true, 'stream must be ReadableStream');
        assert(stream._state === 'readable', 'state must be readable');
        stream._state = 'errored';
        stream._storedError = e;
        var reader = stream._reader;
        if (reader === undefined) {
          return undefined;
        }
        if (IsReadableStreamDefaultReader(reader) === true) {
          for (var i = 0; i < reader._readRequests.length; i++) {
            var readRequest = reader._readRequests[i];
            readRequest._reject(e);
          }
          reader._readRequests = [];
        } else {
          assert(IsReadableStreamBYOBReader(reader), 'reader must be ReadableStreamBYOBReader');
          for (var _i = 0; _i < reader._readIntoRequests.length; _i++) {
            var readIntoRequest = reader._readIntoRequests[_i];
            readIntoRequest._reject(e);
          }
          reader._readIntoRequests = [];
        }
        defaultReaderClosedPromiseReject(reader, e);
        reader._closedPromise.catch(function () {});
      }
      function ReadableStreamFulfillReadIntoRequest(stream, chunk, done) {
        var reader = stream._reader;
        assert(reader._readIntoRequests.length > 0);
        var readIntoRequest = reader._readIntoRequests.shift();
        readIntoRequest._resolve(CreateIterResultObject(chunk, done));
      }
      function ReadableStreamFulfillReadRequest(stream, chunk, done) {
        var reader = stream._reader;
        assert(reader._readRequests.length > 0);
        var readRequest = reader._readRequests.shift();
        readRequest._resolve(CreateIterResultObject(chunk, done));
      }
      function ReadableStreamGetNumReadIntoRequests(stream) {
        return stream._reader._readIntoRequests.length;
      }
      function ReadableStreamGetNumReadRequests(stream) {
        return stream._reader._readRequests.length;
      }
      function ReadableStreamHasBYOBReader(stream) {
        var reader = stream._reader;
        if (reader === undefined) {
          return false;
        }
        if (IsReadableStreamBYOBReader(reader) === false) {
          return false;
        }
        return true;
      }
      function ReadableStreamHasDefaultReader(stream) {
        var reader = stream._reader;
        if (reader === undefined) {
          return false;
        }
        if (IsReadableStreamDefaultReader(reader) === false) {
          return false;
        }
        return true;
      }
      var ReadableStreamDefaultReader = function () {
        function ReadableStreamDefaultReader(stream) {
          _classCallCheck(this, ReadableStreamDefaultReader);
          if (IsReadableStream(stream) === false) {
            throw new TypeError('ReadableStreamDefaultReader can only be constructed with a ReadableStream instance');
          }
          if (IsReadableStreamLocked(stream) === true) {
            throw new TypeError('This stream has already been locked for exclusive reading by another reader');
          }
          ReadableStreamReaderGenericInitialize(this, stream);
          this._readRequests = [];
        }
        _createClass(ReadableStreamDefaultReader, [{
          key: 'cancel',
          value: function cancel(reason) {
            if (IsReadableStreamDefaultReader(this) === false) {
              return Promise.reject(defaultReaderBrandCheckException('cancel'));
            }
            if (this._ownerReadableStream === undefined) {
              return Promise.reject(readerLockException('cancel'));
            }
            return ReadableStreamReaderGenericCancel(this, reason);
          }
        }, {
          key: 'read',
          value: function read() {
            if (IsReadableStreamDefaultReader(this) === false) {
              return Promise.reject(defaultReaderBrandCheckException('read'));
            }
            if (this._ownerReadableStream === undefined) {
              return Promise.reject(readerLockException('read from'));
            }
            return ReadableStreamDefaultReaderRead(this);
          }
        }, {
          key: 'releaseLock',
          value: function releaseLock() {
            if (IsReadableStreamDefaultReader(this) === false) {
              throw defaultReaderBrandCheckException('releaseLock');
            }
            if (this._ownerReadableStream === undefined) {
              return;
            }
            if (this._readRequests.length > 0) {
              throw new TypeError('Tried to release a reader lock when that reader has pending read() calls un-settled');
            }
            ReadableStreamReaderGenericRelease(this);
          }
        }, {
          key: 'closed',
          get: function get() {
            if (IsReadableStreamDefaultReader(this) === false) {
              return Promise.reject(defaultReaderBrandCheckException('closed'));
            }
            return this._closedPromise;
          }
        }]);
        return ReadableStreamDefaultReader;
      }();
      var ReadableStreamBYOBReader = function () {
        function ReadableStreamBYOBReader(stream) {
          _classCallCheck(this, ReadableStreamBYOBReader);
          if (!IsReadableStream(stream)) {
            throw new TypeError('ReadableStreamBYOBReader can only be constructed with a ReadableStream instance given a ' + 'byte source');
          }
          if (IsReadableByteStreamController(stream._readableStreamController) === false) {
            throw new TypeError('Cannot construct a ReadableStreamBYOBReader for a stream not constructed with a byte ' + 'source');
          }
          if (IsReadableStreamLocked(stream)) {
            throw new TypeError('This stream has already been locked for exclusive reading by another reader');
          }
          ReadableStreamReaderGenericInitialize(this, stream);
          this._readIntoRequests = [];
        }
        _createClass(ReadableStreamBYOBReader, [{
          key: 'cancel',
          value: function cancel(reason) {
            if (!IsReadableStreamBYOBReader(this)) {
              return Promise.reject(byobReaderBrandCheckException('cancel'));
            }
            if (this._ownerReadableStream === undefined) {
              return Promise.reject(readerLockException('cancel'));
            }
            return ReadableStreamReaderGenericCancel(this, reason);
          }
        }, {
          key: 'read',
          value: function read(view) {
            if (!IsReadableStreamBYOBReader(this)) {
              return Promise.reject(byobReaderBrandCheckException('read'));
            }
            if (this._ownerReadableStream === undefined) {
              return Promise.reject(readerLockException('read from'));
            }
            if (!ArrayBuffer.isView(view)) {
              return Promise.reject(new TypeError('view must be an array buffer view'));
            }
            if (view.byteLength === 0) {
              return Promise.reject(new TypeError('view must have non-zero byteLength'));
            }
            return ReadableStreamBYOBReaderRead(this, view);
          }
        }, {
          key: 'releaseLock',
          value: function releaseLock() {
            if (!IsReadableStreamBYOBReader(this)) {
              throw byobReaderBrandCheckException('releaseLock');
            }
            if (this._ownerReadableStream === undefined) {
              return;
            }
            if (this._readIntoRequests.length > 0) {
              throw new TypeError('Tried to release a reader lock when that reader has pending read() calls un-settled');
            }
            ReadableStreamReaderGenericRelease(this);
          }
        }, {
          key: 'closed',
          get: function get() {
            if (!IsReadableStreamBYOBReader(this)) {
              return Promise.reject(byobReaderBrandCheckException('closed'));
            }
            return this._closedPromise;
          }
        }]);
        return ReadableStreamBYOBReader;
      }();
      function IsReadableStreamBYOBReader(x) {
        if (!typeIsObject(x)) {
          return false;
        }
        if (!Object.prototype.hasOwnProperty.call(x, '_readIntoRequests')) {
          return false;
        }
        return true;
      }
      function IsReadableStreamDefaultReader(x) {
        if (!typeIsObject(x)) {
          return false;
        }
        if (!Object.prototype.hasOwnProperty.call(x, '_readRequests')) {
          return false;
        }
        return true;
      }
      function ReadableStreamReaderGenericInitialize(reader, stream) {
        reader._ownerReadableStream = stream;
        stream._reader = reader;
        if (stream._state === 'readable') {
          defaultReaderClosedPromiseInitialize(reader);
        } else if (stream._state === 'closed') {
          defaultReaderClosedPromiseInitializeAsResolved(reader);
        } else {
          assert(stream._state === 'errored', 'state must be errored');
          defaultReaderClosedPromiseInitializeAsRejected(reader, stream._storedError);
          reader._closedPromise.catch(function () {});
        }
      }
      function ReadableStreamReaderGenericCancel(reader, reason) {
        var stream = reader._ownerReadableStream;
        assert(stream !== undefined);
        return ReadableStreamCancel(stream, reason);
      }
      function ReadableStreamReaderGenericRelease(reader) {
        assert(reader._ownerReadableStream !== undefined);
        assert(reader._ownerReadableStream._reader === reader);
        if (reader._ownerReadableStream._state === 'readable') {
          defaultReaderClosedPromiseReject(reader, new TypeError('Reader was released and can no longer be used to monitor the stream\'s closedness'));
        } else {
          defaultReaderClosedPromiseResetToRejected(reader, new TypeError('Reader was released and can no longer be used to monitor the stream\'s closedness'));
        }
        reader._closedPromise.catch(function () {});
        reader._ownerReadableStream._reader = undefined;
        reader._ownerReadableStream = undefined;
      }
      function ReadableStreamBYOBReaderRead(reader, view) {
        var stream = reader._ownerReadableStream;
        assert(stream !== undefined);
        stream._disturbed = true;
        if (stream._state === 'errored') {
          return Promise.reject(stream._storedError);
        }
        return ReadableByteStreamControllerPullInto(stream._readableStreamController, view);
      }
      function ReadableStreamDefaultReaderRead(reader) {
        var stream = reader._ownerReadableStream;
        assert(stream !== undefined);
        stream._disturbed = true;
        if (stream._state === 'closed') {
          return Promise.resolve(CreateIterResultObject(undefined, true));
        }
        if (stream._state === 'errored') {
          return Promise.reject(stream._storedError);
        }
        assert(stream._state === 'readable');
        return stream._readableStreamController.__pullSteps();
      }
      var ReadableStreamDefaultController = function () {
        function ReadableStreamDefaultController(stream, underlyingSource, size, highWaterMark) {
          _classCallCheck(this, ReadableStreamDefaultController);
          if (IsReadableStream(stream) === false) {
            throw new TypeError('ReadableStreamDefaultController can only be constructed with a ReadableStream instance');
          }
          if (stream._readableStreamController !== undefined) {
            throw new TypeError('ReadableStreamDefaultController instances can only be created by the ReadableStream constructor');
          }
          this._controlledReadableStream = stream;
          this._underlyingSource = underlyingSource;
          this._queue = undefined;
          this._queueTotalSize = undefined;
          ResetQueue(this);
          this._started = false;
          this._closeRequested = false;
          this._pullAgain = false;
          this._pulling = false;
          var normalizedStrategy = ValidateAndNormalizeQueuingStrategy(size, highWaterMark);
          this._strategySize = normalizedStrategy.size;
          this._strategyHWM = normalizedStrategy.highWaterMark;
          var controller = this;
          var startResult = InvokeOrNoop(underlyingSource, 'start', [this]);
          Promise.resolve(startResult).then(function () {
            controller._started = true;
            assert(controller._pulling === false);
            assert(controller._pullAgain === false);
            ReadableStreamDefaultControllerCallPullIfNeeded(controller);
          }, function (r) {
            ReadableStreamDefaultControllerErrorIfNeeded(controller, r);
          }).catch(rethrowAssertionErrorRejection);
        }
        _createClass(ReadableStreamDefaultController, [{
          key: 'close',
          value: function close() {
            if (IsReadableStreamDefaultController(this) === false) {
              throw defaultControllerBrandCheckException('close');
            }
            if (this._closeRequested === true) {
              throw new TypeError('The stream has already been closed; do not close it again!');
            }
            var state = this._controlledReadableStream._state;
            if (state !== 'readable') {
              throw new TypeError('The stream (in ' + state + ' state) is not in the readable state and cannot be closed');
            }
            ReadableStreamDefaultControllerClose(this);
          }
        }, {
          key: 'enqueue',
          value: function enqueue(chunk) {
            if (IsReadableStreamDefaultController(this) === false) {
              throw defaultControllerBrandCheckException('enqueue');
            }
            if (this._closeRequested === true) {
              throw new TypeError('stream is closed or draining');
            }
            var state = this._controlledReadableStream._state;
            if (state !== 'readable') {
              throw new TypeError('The stream (in ' + state + ' state) is not in the readable state and cannot be enqueued to');
            }
            return ReadableStreamDefaultControllerEnqueue(this, chunk);
          }
        }, {
          key: 'error',
          value: function error(e) {
            if (IsReadableStreamDefaultController(this) === false) {
              throw defaultControllerBrandCheckException('error');
            }
            var stream = this._controlledReadableStream;
            if (stream._state !== 'readable') {
              throw new TypeError('The stream is ' + stream._state + ' and so cannot be errored');
            }
            ReadableStreamDefaultControllerError(this, e);
          }
        }, {
          key: '__cancelSteps',
          value: function __cancelSteps(reason) {
            ResetQueue(this);
            return PromiseInvokeOrNoop(this._underlyingSource, 'cancel', [reason]);
          }
        }, {
          key: '__pullSteps',
          value: function __pullSteps() {
            var stream = this._controlledReadableStream;
            if (this._queue.length > 0) {
              var chunk = DequeueValue(this);
              if (this._closeRequested === true && this._queue.length === 0) {
                ReadableStreamClose(stream);
              } else {
                ReadableStreamDefaultControllerCallPullIfNeeded(this);
              }
              return Promise.resolve(CreateIterResultObject(chunk, false));
            }
            var pendingPromise = ReadableStreamAddReadRequest(stream);
            ReadableStreamDefaultControllerCallPullIfNeeded(this);
            return pendingPromise;
          }
        }, {
          key: 'desiredSize',
          get: function get() {
            if (IsReadableStreamDefaultController(this) === false) {
              throw defaultControllerBrandCheckException('desiredSize');
            }
            return ReadableStreamDefaultControllerGetDesiredSize(this);
          }
        }]);
        return ReadableStreamDefaultController;
      }();
      function IsReadableStreamDefaultController(x) {
        if (!typeIsObject(x)) {
          return false;
        }
        if (!Object.prototype.hasOwnProperty.call(x, '_underlyingSource')) {
          return false;
        }
        return true;
      }
      function ReadableStreamDefaultControllerCallPullIfNeeded(controller) {
        var shouldPull = ReadableStreamDefaultControllerShouldCallPull(controller);
        if (shouldPull === false) {
          return undefined;
        }
        if (controller._pulling === true) {
          controller._pullAgain = true;
          return undefined;
        }
        assert(controller._pullAgain === false);
        controller._pulling = true;
        var pullPromise = PromiseInvokeOrNoop(controller._underlyingSource, 'pull', [controller]);
        pullPromise.then(function () {
          controller._pulling = false;
          if (controller._pullAgain === true) {
            controller._pullAgain = false;
            return ReadableStreamDefaultControllerCallPullIfNeeded(controller);
          }
          return undefined;
        }, function (e) {
          ReadableStreamDefaultControllerErrorIfNeeded(controller, e);
        }).catch(rethrowAssertionErrorRejection);
        return undefined;
      }
      function ReadableStreamDefaultControllerShouldCallPull(controller) {
        var stream = controller._controlledReadableStream;
        if (stream._state === 'closed' || stream._state === 'errored') {
          return false;
        }
        if (controller._closeRequested === true) {
          return false;
        }
        if (controller._started === false) {
          return false;
        }
        if (IsReadableStreamLocked(stream) === true && ReadableStreamGetNumReadRequests(stream) > 0) {
          return true;
        }
        var desiredSize = ReadableStreamDefaultControllerGetDesiredSize(controller);
        if (desiredSize > 0) {
          return true;
        }
        return false;
      }
      function ReadableStreamDefaultControllerClose(controller) {
        var stream = controller._controlledReadableStream;
        assert(controller._closeRequested === false);
        assert(stream._state === 'readable');
        controller._closeRequested = true;
        if (controller._queue.length === 0) {
          ReadableStreamClose(stream);
        }
      }
      function ReadableStreamDefaultControllerEnqueue(controller, chunk) {
        var stream = controller._controlledReadableStream;
        assert(controller._closeRequested === false);
        assert(stream._state === 'readable');
        if (IsReadableStreamLocked(stream) === true && ReadableStreamGetNumReadRequests(stream) > 0) {
          ReadableStreamFulfillReadRequest(stream, chunk, false);
        } else {
          var chunkSize = 1;
          if (controller._strategySize !== undefined) {
            var strategySize = controller._strategySize;
            try {
              chunkSize = strategySize(chunk);
            } catch (chunkSizeE) {
              ReadableStreamDefaultControllerErrorIfNeeded(controller, chunkSizeE);
              throw chunkSizeE;
            }
          }
          try {
            EnqueueValueWithSize(controller, chunk, chunkSize);
          } catch (enqueueE) {
            ReadableStreamDefaultControllerErrorIfNeeded(controller, enqueueE);
            throw enqueueE;
          }
        }
        ReadableStreamDefaultControllerCallPullIfNeeded(controller);
        return undefined;
      }
      function ReadableStreamDefaultControllerError(controller, e) {
        var stream = controller._controlledReadableStream;
        assert(stream._state === 'readable');
        ResetQueue(controller);
        ReadableStreamError(stream, e);
      }
      function ReadableStreamDefaultControllerErrorIfNeeded(controller, e) {
        if (controller._controlledReadableStream._state === 'readable') {
          ReadableStreamDefaultControllerError(controller, e);
        }
      }
      function ReadableStreamDefaultControllerGetDesiredSize(controller) {
        var stream = controller._controlledReadableStream;
        var state = stream._state;
        if (state === 'errored') {
          return null;
        }
        if (state === 'closed') {
          return 0;
        }
        return controller._strategyHWM - controller._queueTotalSize;
      }
      var ReadableStreamBYOBRequest = function () {
        function ReadableStreamBYOBRequest(controller, view) {
          _classCallCheck(this, ReadableStreamBYOBRequest);
          this._associatedReadableByteStreamController = controller;
          this._view = view;
        }
        _createClass(ReadableStreamBYOBRequest, [{
          key: 'respond',
          value: function respond(bytesWritten) {
            if (IsReadableStreamBYOBRequest(this) === false) {
              throw byobRequestBrandCheckException('respond');
            }
            if (this._associatedReadableByteStreamController === undefined) {
              throw new TypeError('This BYOB request has been invalidated');
            }
            ReadableByteStreamControllerRespond(this._associatedReadableByteStreamController, bytesWritten);
          }
        }, {
          key: 'respondWithNewView',
          value: function respondWithNewView(view) {
            if (IsReadableStreamBYOBRequest(this) === false) {
              throw byobRequestBrandCheckException('respond');
            }
            if (this._associatedReadableByteStreamController === undefined) {
              throw new TypeError('This BYOB request has been invalidated');
            }
            if (!ArrayBuffer.isView(view)) {
              throw new TypeError('You can only respond with array buffer views');
            }
            ReadableByteStreamControllerRespondWithNewView(this._associatedReadableByteStreamController, view);
          }
        }, {
          key: 'view',
          get: function get() {
            return this._view;
          }
        }]);
        return ReadableStreamBYOBRequest;
      }();
      var ReadableByteStreamController = function () {
        function ReadableByteStreamController(stream, underlyingByteSource, highWaterMark) {
          _classCallCheck(this, ReadableByteStreamController);
          if (IsReadableStream(stream) === false) {
            throw new TypeError('ReadableByteStreamController can only be constructed with a ReadableStream instance given ' + 'a byte source');
          }
          if (stream._readableStreamController !== undefined) {
            throw new TypeError('ReadableByteStreamController instances can only be created by the ReadableStream constructor given a byte ' + 'source');
          }
          this._controlledReadableStream = stream;
          this._underlyingByteSource = underlyingByteSource;
          this._pullAgain = false;
          this._pulling = false;
          ReadableByteStreamControllerClearPendingPullIntos(this);
          this._queue = this._queueTotalSize = undefined;
          ResetQueue(this);
          this._closeRequested = false;
          this._started = false;
          this._strategyHWM = ValidateAndNormalizeHighWaterMark(highWaterMark);
          var autoAllocateChunkSize = underlyingByteSource.autoAllocateChunkSize;
          if (autoAllocateChunkSize !== undefined) {
            if (Number.isInteger(autoAllocateChunkSize) === false || autoAllocateChunkSize <= 0) {
              throw new RangeError('autoAllocateChunkSize must be a positive integer');
            }
          }
          this._autoAllocateChunkSize = autoAllocateChunkSize;
          this._pendingPullIntos = [];
          var controller = this;
          var startResult = InvokeOrNoop(underlyingByteSource, 'start', [this]);
          Promise.resolve(startResult).then(function () {
            controller._started = true;
            assert(controller._pulling === false);
            assert(controller._pullAgain === false);
            ReadableByteStreamControllerCallPullIfNeeded(controller);
          }, function (r) {
            if (stream._state === 'readable') {
              ReadableByteStreamControllerError(controller, r);
            }
          }).catch(rethrowAssertionErrorRejection);
        }
        _createClass(ReadableByteStreamController, [{
          key: 'close',
          value: function close() {
            if (IsReadableByteStreamController(this) === false) {
              throw byteStreamControllerBrandCheckException('close');
            }
            if (this._closeRequested === true) {
              throw new TypeError('The stream has already been closed; do not close it again!');
            }
            var state = this._controlledReadableStream._state;
            if (state !== 'readable') {
              throw new TypeError('The stream (in ' + state + ' state) is not in the readable state and cannot be closed');
            }
            ReadableByteStreamControllerClose(this);
          }
        }, {
          key: 'enqueue',
          value: function enqueue(chunk) {
            if (IsReadableByteStreamController(this) === false) {
              throw byteStreamControllerBrandCheckException('enqueue');
            }
            if (this._closeRequested === true) {
              throw new TypeError('stream is closed or draining');
            }
            var state = this._controlledReadableStream._state;
            if (state !== 'readable') {
              throw new TypeError('The stream (in ' + state + ' state) is not in the readable state and cannot be enqueued to');
            }
            if (!ArrayBuffer.isView(chunk)) {
              throw new TypeError('You can only enqueue array buffer views when using a ReadableByteStreamController');
            }
            ReadableByteStreamControllerEnqueue(this, chunk);
          }
        }, {
          key: 'error',
          value: function error(e) {
            if (IsReadableByteStreamController(this) === false) {
              throw byteStreamControllerBrandCheckException('error');
            }
            var stream = this._controlledReadableStream;
            if (stream._state !== 'readable') {
              throw new TypeError('The stream is ' + stream._state + ' and so cannot be errored');
            }
            ReadableByteStreamControllerError(this, e);
          }
        }, {
          key: '__cancelSteps',
          value: function __cancelSteps(reason) {
            if (this._pendingPullIntos.length > 0) {
              var firstDescriptor = this._pendingPullIntos[0];
              firstDescriptor.bytesFilled = 0;
            }
            ResetQueue(this);
            return PromiseInvokeOrNoop(this._underlyingByteSource, 'cancel', [reason]);
          }
        }, {
          key: '__pullSteps',
          value: function __pullSteps() {
            var stream = this._controlledReadableStream;
            assert(ReadableStreamHasDefaultReader(stream) === true);
            if (this._queueTotalSize > 0) {
              assert(ReadableStreamGetNumReadRequests(stream) === 0);
              var entry = this._queue.shift();
              this._queueTotalSize -= entry.byteLength;
              ReadableByteStreamControllerHandleQueueDrain(this);
              var view = void 0;
              try {
                view = new Uint8Array(entry.buffer, entry.byteOffset, entry.byteLength);
              } catch (viewE) {
                return Promise.reject(viewE);
              }
              return Promise.resolve(CreateIterResultObject(view, false));
            }
            var autoAllocateChunkSize = this._autoAllocateChunkSize;
            if (autoAllocateChunkSize !== undefined) {
              var buffer = void 0;
              try {
                buffer = new ArrayBuffer(autoAllocateChunkSize);
              } catch (bufferE) {
                return Promise.reject(bufferE);
              }
              var pullIntoDescriptor = {
                buffer: buffer,
                byteOffset: 0,
                byteLength: autoAllocateChunkSize,
                bytesFilled: 0,
                elementSize: 1,
                ctor: Uint8Array,
                readerType: 'default'
              };
              this._pendingPullIntos.push(pullIntoDescriptor);
            }
            var promise = ReadableStreamAddReadRequest(stream);
            ReadableByteStreamControllerCallPullIfNeeded(this);
            return promise;
          }
        }, {
          key: 'byobRequest',
          get: function get() {
            if (IsReadableByteStreamController(this) === false) {
              throw byteStreamControllerBrandCheckException('byobRequest');
            }
            if (this._byobRequest === undefined && this._pendingPullIntos.length > 0) {
              var firstDescriptor = this._pendingPullIntos[0];
              var view = new Uint8Array(firstDescriptor.buffer, firstDescriptor.byteOffset + firstDescriptor.bytesFilled, firstDescriptor.byteLength - firstDescriptor.bytesFilled);
              this._byobRequest = new ReadableStreamBYOBRequest(this, view);
            }
            return this._byobRequest;
          }
        }, {
          key: 'desiredSize',
          get: function get() {
            if (IsReadableByteStreamController(this) === false) {
              throw byteStreamControllerBrandCheckException('desiredSize');
            }
            return ReadableByteStreamControllerGetDesiredSize(this);
          }
        }]);
        return ReadableByteStreamController;
      }();
      function IsReadableByteStreamController(x) {
        if (!typeIsObject(x)) {
          return false;
        }
        if (!Object.prototype.hasOwnProperty.call(x, '_underlyingByteSource')) {
          return false;
        }
        return true;
      }
      function IsReadableStreamBYOBRequest(x) {
        if (!typeIsObject(x)) {
          return false;
        }
        if (!Object.prototype.hasOwnProperty.call(x, '_associatedReadableByteStreamController')) {
          return false;
        }
        return true;
      }
      function ReadableByteStreamControllerCallPullIfNeeded(controller) {