From b91cc788ec72ccccbe346bfcc13e987962d5994f Mon Sep 17 00:00:00 2001 From: Dorel Luca Date: Sun, 20 Jan 2019 22:49:26 +0200 Subject: [PATCH] Backed out changeset a5b887c68abd (bug 1521413) for browser-chrome failures in browser/base/content/test/static/browser_all_files_referenced.js --- browser/extensions/pdfjs/README.mozilla | 4 +- browser/extensions/pdfjs/content/build/pdf.js | 3849 +++++++++++++++- .../pdfjs/content/build/pdf.worker.js | 4071 ++++++++++++++++- .../pdfjs/content/build/streams_polyfill.js | 3875 ---------------- .../extensions/pdfjs/content/web/viewer.html | 7 - .../extensions/pdfjs/content/web/viewer.js | 75 +- browser/extensions/pdfjs/moz.yaml | 2 +- 7 files changed, 7769 insertions(+), 4114 deletions(-) delete mode 100644 browser/extensions/pdfjs/content/build/streams_polyfill.js diff --git a/browser/extensions/pdfjs/README.mozilla b/browser/extensions/pdfjs/README.mozilla index dfedb728cfa7..978213a0cb73 100644 --- a/browser/extensions/pdfjs/README.mozilla +++ b/browser/extensions/pdfjs/README.mozilla @@ -1,5 +1,5 @@ This is the PDF.js project output, https://github.com/mozilla/pdf.js -Current extension version is: 2.1.209 +Current extension version is: 2.1.196 -Taken from upstream commit: f26129de +Taken from upstream commit: cdbc33ba diff --git a/browser/extensions/pdfjs/content/build/pdf.js b/browser/extensions/pdfjs/content/build/pdf.js index 9535ea7b72dc..bac3f703b988 100644 --- a/browser/extensions/pdfjs/content/build/pdf.js +++ b/browser/extensions/pdfjs/content/build/pdf.js @@ -123,24 +123,24 @@ return /******/ (function(modules) { // webpackBootstrap "use strict"; -var pdfjsVersion = '2.1.209'; -var pdfjsBuild = 'f26129de'; +var pdfjsVersion = '2.1.196'; +var pdfjsBuild = 'cdbc33ba'; var pdfjsSharedUtil = __w_pdfjs_require__(1); -var pdfjsDisplayAPI = __w_pdfjs_require__(6); +var pdfjsDisplayAPI = __w_pdfjs_require__(7); -var pdfjsDisplayTextLayer = __w_pdfjs_require__(18); +var pdfjsDisplayTextLayer = __w_pdfjs_require__(19); -var pdfjsDisplayAnnotationLayer = __w_pdfjs_require__(19); +var pdfjsDisplayAnnotationLayer = __w_pdfjs_require__(20); -var pdfjsDisplayDOMUtils = __w_pdfjs_require__(7); +var pdfjsDisplayDOMUtils = __w_pdfjs_require__(8); -var pdfjsDisplaySVG = __w_pdfjs_require__(20); +var pdfjsDisplaySVG = __w_pdfjs_require__(21); -let pdfjsDisplayWorkerOptions = __w_pdfjs_require__(12); +let pdfjsDisplayWorkerOptions = __w_pdfjs_require__(13); -let pdfjsDisplayAPICompatibility = __w_pdfjs_require__(9); +let pdfjsDisplayAPICompatibility = __w_pdfjs_require__(10); ; exports.build = pdfjsDisplayAPI.build; @@ -241,7 +241,7 @@ __w_pdfjs_require__(2); var _streams_polyfill = __w_pdfjs_require__(4); -var _url_polyfill = __w_pdfjs_require__(5); +var _url_polyfill = __w_pdfjs_require__(6); const IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0]; exports.IDENTITY_MATRIX = IDENTITY_MATRIX; @@ -1164,8 +1164,24 @@ module.exports = typeof window !== 'undefined' && window.Math === Math ? window "use strict"; -{ +let isReadableStreamSupported = false; + +if (typeof ReadableStream !== 'undefined') { + try { + new ReadableStream({ + start(controller) { + controller.close(); + } + + }); + isReadableStreamSupported = true; + } catch (e) {} +} + +if (isReadableStreamSupported) { exports.ReadableStream = ReadableStream; +} else { + exports.ReadableStream = __w_pdfjs_require__(5).ReadableStream; } /***/ }), @@ -1175,12 +1191,3757 @@ module.exports = typeof window !== 'undefined' && window.Math === Math ? window "use strict"; +(function (e, a) { + for (var i in a) e[i] = a[i]; +})(exports, function (modules) { + var installedModules = {}; + + function __w_pdfjs_require__(moduleId) { + if (installedModules[moduleId]) return installedModules[moduleId].exports; + var module = installedModules[moduleId] = { + i: moduleId, + l: false, + exports: {} + }; + modules[moduleId].call(module.exports, module, module.exports, __w_pdfjs_require__); + module.l = true; + return module.exports; + } + + __w_pdfjs_require__.m = modules; + __w_pdfjs_require__.c = installedModules; + + __w_pdfjs_require__.i = function (value) { + return value; + }; + + __w_pdfjs_require__.d = function (exports, name, getter) { + if (!__w_pdfjs_require__.o(exports, name)) { + Object.defineProperty(exports, name, { + configurable: false, + enumerable: true, + get: getter + }); + } + }; + + __w_pdfjs_require__.n = function (module) { + var getter = module && module.__esModule ? function getDefault() { + return module['default']; + } : function getModuleExports() { + return module; + }; + + __w_pdfjs_require__.d(getter, 'a', getter); + + return getter; + }; + + __w_pdfjs_require__.o = function (object, property) { + return Object.prototype.hasOwnProperty.call(object, property); + }; + + __w_pdfjs_require__.p = ""; + return __w_pdfjs_require__(__w_pdfjs_require__.s = 7); +}([function (module, exports, __w_pdfjs_require__) { + "use strict"; + + var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { + return typeof obj; + } : function (obj) { + return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; + }; + + var _require = __w_pdfjs_require__(1), + assert = _require.assert; + + function IsPropertyKey(argument) { + return typeof argument === 'string' || (typeof argument === 'undefined' ? 'undefined' : _typeof(argument)) === 'symbol'; + } + + exports.typeIsObject = function (x) { + return (typeof x === 'undefined' ? 'undefined' : _typeof(x)) === 'object' && x !== null || typeof x === 'function'; + }; + + exports.createDataProperty = function (o, p, v) { + assert(exports.typeIsObject(o)); + Object.defineProperty(o, p, { + value: v, + writable: true, + enumerable: true, + configurable: true + }); + }; + + exports.createArrayFromList = function (elements) { + return elements.slice(); + }; + + exports.ArrayBufferCopy = function (dest, destOffset, src, srcOffset, n) { + new Uint8Array(dest).set(new Uint8Array(src, srcOffset, n), destOffset); + }; + + exports.CreateIterResultObject = function (value, done) { + assert(typeof done === 'boolean'); + var obj = {}; + Object.defineProperty(obj, 'value', { + value: value, + enumerable: true, + writable: true, + configurable: true + }); + Object.defineProperty(obj, 'done', { + value: done, + enumerable: true, + writable: true, + configurable: true + }); + return obj; + }; + + exports.IsFiniteNonNegativeNumber = function (v) { + if (Number.isNaN(v)) { + return false; + } + + if (v === Infinity) { + return false; + } + + if (v < 0) { + return false; + } + + return true; + }; + + function Call(F, V, args) { + if (typeof F !== 'function') { + throw new TypeError('Argument is not a function'); + } + + return Function.prototype.apply.call(F, V, args); + } + + exports.InvokeOrNoop = function (O, P, args) { + assert(O !== undefined); + assert(IsPropertyKey(P)); + assert(Array.isArray(args)); + var method = O[P]; + + if (method === undefined) { + return undefined; + } + + return Call(method, O, args); + }; + + exports.PromiseInvokeOrNoop = function (O, P, args) { + assert(O !== undefined); + assert(IsPropertyKey(P)); + assert(Array.isArray(args)); + + try { + return Promise.resolve(exports.InvokeOrNoop(O, P, args)); + } catch (returnValueE) { + return Promise.reject(returnValueE); + } + }; + + exports.PromiseInvokeOrPerformFallback = function (O, P, args, F, argsF) { + assert(O !== undefined); + assert(IsPropertyKey(P)); + assert(Array.isArray(args)); + assert(Array.isArray(argsF)); + var method = void 0; + + try { + method = O[P]; + } catch (methodE) { + return Promise.reject(methodE); + } + + if (method === undefined) { + return F.apply(null, argsF); + } + + try { + return Promise.resolve(Call(method, O, args)); + } catch (e) { + return Promise.reject(e); + } + }; + + exports.TransferArrayBuffer = function (O) { + return O.slice(); + }; + + exports.ValidateAndNormalizeHighWaterMark = function (highWaterMark) { + highWaterMark = Number(highWaterMark); + + if (Number.isNaN(highWaterMark) || highWaterMark < 0) { + throw new RangeError('highWaterMark property of a queuing strategy must be non-negative and non-NaN'); + } + + return highWaterMark; + }; + + exports.ValidateAndNormalizeQueuingStrategy = function (size, highWaterMark) { + if (size !== undefined && typeof size !== 'function') { + throw new TypeError('size property of a queuing strategy must be a function'); + } + + highWaterMark = exports.ValidateAndNormalizeHighWaterMark(highWaterMark); + return { + size: size, + highWaterMark: highWaterMark + }; + }; +}, function (module, exports, __w_pdfjs_require__) { + "use strict"; + + function rethrowAssertionErrorRejection(e) { + if (e && e.constructor === AssertionError) { + setTimeout(function () { + throw e; + }, 0); + } + } + + function AssertionError(message) { + this.name = 'AssertionError'; + this.message = message || ''; + this.stack = new Error().stack; + } + + AssertionError.prototype = Object.create(Error.prototype); + AssertionError.prototype.constructor = AssertionError; + + function assert(value, message) { + if (!value) { + throw new AssertionError(message); + } + } + + module.exports = { + rethrowAssertionErrorRejection: rethrowAssertionErrorRejection, + AssertionError: AssertionError, + assert: assert + }; +}, function (module, exports, __w_pdfjs_require__) { + "use strict"; + + var _createClass = function () { + function defineProperties(target, props) { + for (var i = 0; i < props.length; i++) { + var descriptor = props[i]; + descriptor.enumerable = descriptor.enumerable || false; + descriptor.configurable = true; + if ("value" in descriptor) descriptor.writable = true; + Object.defineProperty(target, descriptor.key, descriptor); + } + } + + return function (Constructor, protoProps, staticProps) { + if (protoProps) defineProperties(Constructor.prototype, protoProps); + if (staticProps) defineProperties(Constructor, staticProps); + return Constructor; + }; + }(); + + function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); + } + } + + var _require = __w_pdfjs_require__(0), + InvokeOrNoop = _require.InvokeOrNoop, + PromiseInvokeOrNoop = _require.PromiseInvokeOrNoop, + ValidateAndNormalizeQueuingStrategy = _require.ValidateAndNormalizeQueuingStrategy, + typeIsObject = _require.typeIsObject; + + var _require2 = __w_pdfjs_require__(1), + assert = _require2.assert, + rethrowAssertionErrorRejection = _require2.rethrowAssertionErrorRejection; + + var _require3 = __w_pdfjs_require__(3), + DequeueValue = _require3.DequeueValue, + EnqueueValueWithSize = _require3.EnqueueValueWithSize, + PeekQueueValue = _require3.PeekQueueValue, + ResetQueue = _require3.ResetQueue; + + var WritableStream = function () { + function WritableStream() { + var underlyingSink = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + + var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, + size = _ref.size, + _ref$highWaterMark = _ref.highWaterMark, + highWaterMark = _ref$highWaterMark === undefined ? 1 : _ref$highWaterMark; + + _classCallCheck(this, WritableStream); + + this._state = 'writable'; + this._storedError = undefined; + this._writer = undefined; + this._writableStreamController = undefined; + this._writeRequests = []; + this._inFlightWriteRequest = undefined; + this._closeRequest = undefined; + this._inFlightCloseRequest = undefined; + this._pendingAbortRequest = undefined; + this._backpressure = false; + var type = underlyingSink.type; + + if (type !== undefined) { + throw new RangeError('Invalid type is specified'); + } + + this._writableStreamController = new WritableStreamDefaultController(this, underlyingSink, size, highWaterMark); + + this._writableStreamController.__startSteps(); + } + + _createClass(WritableStream, [{ + key: 'abort', + value: function abort(reason) { + if (IsWritableStream(this) === false) { + return Promise.reject(streamBrandCheckException('abort')); + } + + if (IsWritableStreamLocked(this) === true) { + return Promise.reject(new TypeError('Cannot abort a stream that already has a writer')); + } + + return WritableStreamAbort(this, reason); + } + }, { + key: 'getWriter', + value: function getWriter() { + if (IsWritableStream(this) === false) { + throw streamBrandCheckException('getWriter'); + } + + return AcquireWritableStreamDefaultWriter(this); + } + }, { + key: 'locked', + get: function get() { + if (IsWritableStream(this) === false) { + throw streamBrandCheckException('locked'); + } + + return IsWritableStreamLocked(this); + } + }]); + + return WritableStream; + }(); + + module.exports = { + AcquireWritableStreamDefaultWriter: AcquireWritableStreamDefaultWriter, + IsWritableStream: IsWritableStream, + IsWritableStreamLocked: IsWritableStreamLocked, + WritableStream: WritableStream, + WritableStreamAbort: WritableStreamAbort, + WritableStreamDefaultControllerError: WritableStreamDefaultControllerError, + WritableStreamDefaultWriterCloseWithErrorPropagation: WritableStreamDefaultWriterCloseWithErrorPropagation, + WritableStreamDefaultWriterRelease: WritableStreamDefaultWriterRelease, + WritableStreamDefaultWriterWrite: WritableStreamDefaultWriterWrite, + WritableStreamCloseQueuedOrInFlight: WritableStreamCloseQueuedOrInFlight + }; + + function AcquireWritableStreamDefaultWriter(stream) { + return new WritableStreamDefaultWriter(stream); + } + + function IsWritableStream(x) { + if (!typeIsObject(x)) { + return false; + } + + if (!Object.prototype.hasOwnProperty.call(x, '_writableStreamController')) { + return false; + } + + return true; + } + + function IsWritableStreamLocked(stream) { + assert(IsWritableStream(stream) === true, 'IsWritableStreamLocked should only be used on known writable streams'); + + if (stream._writer === undefined) { + return false; + } + + return true; + } + + function WritableStreamAbort(stream, reason) { + var state = stream._state; + + if (state === 'closed') { + return Promise.resolve(undefined); + } + + if (state === 'errored') { + return Promise.reject(stream._storedError); + } + + var error = new TypeError('Requested to abort'); + + if (stream._pendingAbortRequest !== undefined) { + return Promise.reject(error); + } + + assert(state === 'writable' || state === 'erroring', 'state must be writable or erroring'); + var wasAlreadyErroring = false; + + if (state === 'erroring') { + wasAlreadyErroring = true; + reason = undefined; + } + + var promise = new Promise(function (resolve, reject) { + stream._pendingAbortRequest = { + _resolve: resolve, + _reject: reject, + _reason: reason, + _wasAlreadyErroring: wasAlreadyErroring + }; + }); + + if (wasAlreadyErroring === false) { + WritableStreamStartErroring(stream, error); + } + + return promise; + } + + function WritableStreamAddWriteRequest(stream) { + assert(IsWritableStreamLocked(stream) === true); + assert(stream._state === 'writable'); + var promise = new Promise(function (resolve, reject) { + var writeRequest = { + _resolve: resolve, + _reject: reject + }; + + stream._writeRequests.push(writeRequest); + }); + return promise; + } + + function WritableStreamDealWithRejection(stream, error) { + var state = stream._state; + + if (state === 'writable') { + WritableStreamStartErroring(stream, error); + return; + } + + assert(state === 'erroring'); + WritableStreamFinishErroring(stream); + } + + function WritableStreamStartErroring(stream, reason) { + assert(stream._storedError === undefined, 'stream._storedError === undefined'); + assert(stream._state === 'writable', 'state must be writable'); + var controller = stream._writableStreamController; + assert(controller !== undefined, 'controller must not be undefined'); + stream._state = 'erroring'; + stream._storedError = reason; + var writer = stream._writer; + + if (writer !== undefined) { + WritableStreamDefaultWriterEnsureReadyPromiseRejected(writer, reason); + } + + if (WritableStreamHasOperationMarkedInFlight(stream) === false && controller._started === true) { + WritableStreamFinishErroring(stream); + } + } + + function WritableStreamFinishErroring(stream) { + assert(stream._state === 'erroring', 'stream._state === erroring'); + assert(WritableStreamHasOperationMarkedInFlight(stream) === false, 'WritableStreamHasOperationMarkedInFlight(stream) === false'); + stream._state = 'errored'; + + stream._writableStreamController.__errorSteps(); + + var storedError = stream._storedError; + + for (var i = 0; i < stream._writeRequests.length; i++) { + var writeRequest = stream._writeRequests[i]; + + writeRequest._reject(storedError); + } + + stream._writeRequests = []; + + if (stream._pendingAbortRequest === undefined) { + WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream); + return; + } + + var abortRequest = stream._pendingAbortRequest; + stream._pendingAbortRequest = undefined; + + if (abortRequest._wasAlreadyErroring === true) { + abortRequest._reject(storedError); + + WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream); + return; + } + + var promise = stream._writableStreamController.__abortSteps(abortRequest._reason); + + promise.then(function () { + abortRequest._resolve(); + + WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream); + }, function (reason) { + abortRequest._reject(reason); + + WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream); + }); + } + + function WritableStreamFinishInFlightWrite(stream) { + assert(stream._inFlightWriteRequest !== undefined); + + stream._inFlightWriteRequest._resolve(undefined); + + stream._inFlightWriteRequest = undefined; + } + + function WritableStreamFinishInFlightWriteWithError(stream, error) { + assert(stream._inFlightWriteRequest !== undefined); + + stream._inFlightWriteRequest._reject(error); + + stream._inFlightWriteRequest = undefined; + assert(stream._state === 'writable' || stream._state === 'erroring'); + WritableStreamDealWithRejection(stream, error); + } + + function WritableStreamFinishInFlightClose(stream) { + assert(stream._inFlightCloseRequest !== undefined); + + stream._inFlightCloseRequest._resolve(undefined); + + stream._inFlightCloseRequest = undefined; + var state = stream._state; + assert(state === 'writable' || state === 'erroring'); + + if (state === 'erroring') { + stream._storedError = undefined; + + if (stream._pendingAbortRequest !== undefined) { + stream._pendingAbortRequest._resolve(); + + stream._pendingAbortRequest = undefined; + } + } + + stream._state = 'closed'; + var writer = stream._writer; + + if (writer !== undefined) { + defaultWriterClosedPromiseResolve(writer); + } + + assert(stream._pendingAbortRequest === undefined, 'stream._pendingAbortRequest === undefined'); + assert(stream._storedError === undefined, 'stream._storedError === undefined'); + } + + function WritableStreamFinishInFlightCloseWithError(stream, error) { + assert(stream._inFlightCloseRequest !== undefined); + + stream._inFlightCloseRequest._reject(error); + + stream._inFlightCloseRequest = undefined; + assert(stream._state === 'writable' || stream._state === 'erroring'); + + if (stream._pendingAbortRequest !== undefined) { + stream._pendingAbortRequest._reject(error); + + stream._pendingAbortRequest = undefined; + } + + WritableStreamDealWithRejection(stream, error); + } + + function WritableStreamCloseQueuedOrInFlight(stream) { + if (stream._closeRequest === undefined && stream._inFlightCloseRequest === undefined) { + return false; + } + + return true; + } + + function WritableStreamHasOperationMarkedInFlight(stream) { + if (stream._inFlightWriteRequest === undefined && stream._inFlightCloseRequest === undefined) { + return false; + } + + return true; + } + + function WritableStreamMarkCloseRequestInFlight(stream) { + assert(stream._inFlightCloseRequest === undefined); + assert(stream._closeRequest !== undefined); + stream._inFlightCloseRequest = stream._closeRequest; + stream._closeRequest = undefined; + } + + function WritableStreamMarkFirstWriteRequestInFlight(stream) { + assert(stream._inFlightWriteRequest === undefined, 'there must be no pending write request'); + assert(stream._writeRequests.length !== 0, 'writeRequests must not be empty'); + stream._inFlightWriteRequest = stream._writeRequests.shift(); + } + + function WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream) { + assert(stream._state === 'errored', '_stream_.[[state]] is `"errored"`'); + + if (stream._closeRequest !== undefined) { + assert(stream._inFlightCloseRequest === undefined); + + stream._closeRequest._reject(stream._storedError); + + stream._closeRequest = undefined; + } + + var writer = stream._writer; + + if (writer !== undefined) { + defaultWriterClosedPromiseReject(writer, stream._storedError); + + writer._closedPromise.catch(function () {}); + } + } + + function WritableStreamUpdateBackpressure(stream, backpressure) { + assert(stream._state === 'writable'); + assert(WritableStreamCloseQueuedOrInFlight(stream) === false); + var writer = stream._writer; + + if (writer !== undefined && backpressure !== stream._backpressure) { + if (backpressure === true) { + defaultWriterReadyPromiseReset(writer); + } else { + assert(backpressure === false); + defaultWriterReadyPromiseResolve(writer); + } + } + + stream._backpressure = backpressure; + } + + var WritableStreamDefaultWriter = function () { + function WritableStreamDefaultWriter(stream) { + _classCallCheck(this, WritableStreamDefaultWriter); + + if (IsWritableStream(stream) === false) { + throw new TypeError('WritableStreamDefaultWriter can only be constructed with a WritableStream instance'); + } + + if (IsWritableStreamLocked(stream) === true) { + throw new TypeError('This stream has already been locked for exclusive writing by another writer'); + } + + this._ownerWritableStream = stream; + stream._writer = this; + var state = stream._state; + + if (state === 'writable') { + if (WritableStreamCloseQueuedOrInFlight(stream) === false && stream._backpressure === true) { + defaultWriterReadyPromiseInitialize(this); + } else { + defaultWriterReadyPromiseInitializeAsResolved(this); + } + + defaultWriterClosedPromiseInitialize(this); + } else if (state === 'erroring') { + defaultWriterReadyPromiseInitializeAsRejected(this, stream._storedError); + + this._readyPromise.catch(function () {}); + + defaultWriterClosedPromiseInitialize(this); + } else if (state === 'closed') { + defaultWriterReadyPromiseInitializeAsResolved(this); + defaultWriterClosedPromiseInitializeAsResolved(this); + } else { + assert(state === 'errored', 'state must be errored'); + var storedError = stream._storedError; + defaultWriterReadyPromiseInitializeAsRejected(this, storedError); + + this._readyPromise.catch(function () {}); + + defaultWriterClosedPromiseInitializeAsRejected(this, storedError); + + this._closedPromise.catch(function () {}); + } + } + + _createClass(WritableStreamDefaultWriter, [{ + key: 'abort', + value: function abort(reason) { + if (IsWritableStreamDefaultWriter(this) === false) { + return Promise.reject(defaultWriterBrandCheckException('abort')); + } + + if (this._ownerWritableStream === undefined) { + return Promise.reject(defaultWriterLockException('abort')); + } + + return WritableStreamDefaultWriterAbort(this, reason); + } + }, { + key: 'close', + value: function close() { + if (IsWritableStreamDefaultWriter(this) === false) { + return Promise.reject(defaultWriterBrandCheckException('close')); + } + + var stream = this._ownerWritableStream; + + if (stream === undefined) { + return Promise.reject(defaultWriterLockException('close')); + } + + if (WritableStreamCloseQueuedOrInFlight(stream) === true) { + return Promise.reject(new TypeError('cannot close an already-closing stream')); + } + + return WritableStreamDefaultWriterClose(this); + } + }, { + key: 'releaseLock', + value: function releaseLock() { + if (IsWritableStreamDefaultWriter(this) === false) { + throw defaultWriterBrandCheckException('releaseLock'); + } + + var stream = this._ownerWritableStream; + + if (stream === undefined) { + return; + } + + assert(stream._writer !== undefined); + WritableStreamDefaultWriterRelease(this); + } + }, { + key: 'write', + value: function write(chunk) { + if (IsWritableStreamDefaultWriter(this) === false) { + return Promise.reject(defaultWriterBrandCheckException('write')); + } + + if (this._ownerWritableStream === undefined) { + return Promise.reject(defaultWriterLockException('write to')); + } + + return WritableStreamDefaultWriterWrite(this, chunk); + } + }, { + key: 'closed', + get: function get() { + if (IsWritableStreamDefaultWriter(this) === false) { + return Promise.reject(defaultWriterBrandCheckException('closed')); + } + + return this._closedPromise; + } + }, { + key: 'desiredSize', + get: function get() { + if (IsWritableStreamDefaultWriter(this) === false) { + throw defaultWriterBrandCheckException('desiredSize'); + } + + if (this._ownerWritableStream === undefined) { + throw defaultWriterLockException('desiredSize'); + } + + return WritableStreamDefaultWriterGetDesiredSize(this); + } + }, { + key: 'ready', + get: function get() { + if (IsWritableStreamDefaultWriter(this) === false) { + return Promise.reject(defaultWriterBrandCheckException('ready')); + } + + return this._readyPromise; + } + }]); + + return WritableStreamDefaultWriter; + }(); + + function IsWritableStreamDefaultWriter(x) { + if (!typeIsObject(x)) { + return false; + } + + if (!Object.prototype.hasOwnProperty.call(x, '_ownerWritableStream')) { + return false; + } + + return true; + } + + function WritableStreamDefaultWriterAbort(writer, reason) { + var stream = writer._ownerWritableStream; + assert(stream !== undefined); + return WritableStreamAbort(stream, reason); + } + + function WritableStreamDefaultWriterClose(writer) { + var stream = writer._ownerWritableStream; + assert(stream !== undefined); + var state = stream._state; + + if (state === 'closed' || state === 'errored') { + return Promise.reject(new TypeError('The stream (in ' + state + ' state) is not in the writable state and cannot be closed')); + } + + assert(state === 'writable' || state === 'erroring'); + assert(WritableStreamCloseQueuedOrInFlight(stream) === false); + var promise = new Promise(function (resolve, reject) { + var closeRequest = { + _resolve: resolve, + _reject: reject + }; + stream._closeRequest = closeRequest; + }); + + if (stream._backpressure === true && state === 'writable') { + defaultWriterReadyPromiseResolve(writer); + } + + WritableStreamDefaultControllerClose(stream._writableStreamController); + return promise; + } + + function WritableStreamDefaultWriterCloseWithErrorPropagation(writer) { + var stream = writer._ownerWritableStream; + assert(stream !== undefined); + var state = stream._state; + + if (WritableStreamCloseQueuedOrInFlight(stream) === true || state === 'closed') { + return Promise.resolve(); + } + + if (state === 'errored') { + return Promise.reject(stream._storedError); + } + + assert(state === 'writable' || state === 'erroring'); + return WritableStreamDefaultWriterClose(writer); + } + + function WritableStreamDefaultWriterEnsureClosedPromiseRejected(writer, error) { + if (writer._closedPromiseState === 'pending') { + defaultWriterClosedPromiseReject(writer, error); + } else { + defaultWriterClosedPromiseResetToRejected(writer, error); + } + + writer._closedPromise.catch(function () {}); + } + + function WritableStreamDefaultWriterEnsureReadyPromiseRejected(writer, error) { + if (writer._readyPromiseState === 'pending') { + defaultWriterReadyPromiseReject(writer, error); + } else { + defaultWriterReadyPromiseResetToRejected(writer, error); + } + + writer._readyPromise.catch(function () {}); + } + + function WritableStreamDefaultWriterGetDesiredSize(writer) { + var stream = writer._ownerWritableStream; + var state = stream._state; + + if (state === 'errored' || state === 'erroring') { + return null; + } + + if (state === 'closed') { + return 0; + } + + return WritableStreamDefaultControllerGetDesiredSize(stream._writableStreamController); + } + + function WritableStreamDefaultWriterRelease(writer) { + var stream = writer._ownerWritableStream; + assert(stream !== undefined); + assert(stream._writer === writer); + var releasedError = new TypeError('Writer was released and can no longer be used to monitor the stream\'s closedness'); + WritableStreamDefaultWriterEnsureReadyPromiseRejected(writer, releasedError); + WritableStreamDefaultWriterEnsureClosedPromiseRejected(writer, releasedError); + stream._writer = undefined; + writer._ownerWritableStream = undefined; + } + + function WritableStreamDefaultWriterWrite(writer, chunk) { + var stream = writer._ownerWritableStream; + assert(stream !== undefined); + var controller = stream._writableStreamController; + var chunkSize = WritableStreamDefaultControllerGetChunkSize(controller, chunk); + + if (stream !== writer._ownerWritableStream) { + return Promise.reject(defaultWriterLockException('write to')); + } + + var state = stream._state; + + if (state === 'errored') { + return Promise.reject(stream._storedError); + } + + if (WritableStreamCloseQueuedOrInFlight(stream) === true || state === 'closed') { + return Promise.reject(new TypeError('The stream is closing or closed and cannot be written to')); + } + + if (state === 'erroring') { + return Promise.reject(stream._storedError); + } + + assert(state === 'writable'); + var promise = WritableStreamAddWriteRequest(stream); + WritableStreamDefaultControllerWrite(controller, chunk, chunkSize); + return promise; + } + + var WritableStreamDefaultController = function () { + function WritableStreamDefaultController(stream, underlyingSink, size, highWaterMark) { + _classCallCheck(this, WritableStreamDefaultController); + + if (IsWritableStream(stream) === false) { + throw new TypeError('WritableStreamDefaultController can only be constructed with a WritableStream instance'); + } + + if (stream._writableStreamController !== undefined) { + throw new TypeError('WritableStreamDefaultController instances can only be created by the WritableStream constructor'); + } + + this._controlledWritableStream = stream; + this._underlyingSink = underlyingSink; + this._queue = undefined; + this._queueTotalSize = undefined; + ResetQueue(this); + this._started = false; + var normalizedStrategy = ValidateAndNormalizeQueuingStrategy(size, highWaterMark); + this._strategySize = normalizedStrategy.size; + this._strategyHWM = normalizedStrategy.highWaterMark; + var backpressure = WritableStreamDefaultControllerGetBackpressure(this); + WritableStreamUpdateBackpressure(stream, backpressure); + } + + _createClass(WritableStreamDefaultController, [{ + key: 'error', + value: function error(e) { + if (IsWritableStreamDefaultController(this) === false) { + throw new TypeError('WritableStreamDefaultController.prototype.error can only be used on a WritableStreamDefaultController'); + } + + var state = this._controlledWritableStream._state; + + if (state !== 'writable') { + return; + } + + WritableStreamDefaultControllerError(this, e); + } + }, { + key: '__abortSteps', + value: function __abortSteps(reason) { + return PromiseInvokeOrNoop(this._underlyingSink, 'abort', [reason]); + } + }, { + key: '__errorSteps', + value: function __errorSteps() { + ResetQueue(this); + } + }, { + key: '__startSteps', + value: function __startSteps() { + var _this = this; + + var startResult = InvokeOrNoop(this._underlyingSink, 'start', [this]); + var stream = this._controlledWritableStream; + Promise.resolve(startResult).then(function () { + assert(stream._state === 'writable' || stream._state === 'erroring'); + _this._started = true; + WritableStreamDefaultControllerAdvanceQueueIfNeeded(_this); + }, function (r) { + assert(stream._state === 'writable' || stream._state === 'erroring'); + _this._started = true; + WritableStreamDealWithRejection(stream, r); + }).catch(rethrowAssertionErrorRejection); + } + }]); + + return WritableStreamDefaultController; + }(); + + function WritableStreamDefaultControllerClose(controller) { + EnqueueValueWithSize(controller, 'close', 0); + WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller); + } + + function WritableStreamDefaultControllerGetChunkSize(controller, chunk) { + var strategySize = controller._strategySize; + + if (strategySize === undefined) { + return 1; + } + + try { + return strategySize(chunk); + } catch (chunkSizeE) { + WritableStreamDefaultControllerErrorIfNeeded(controller, chunkSizeE); + return 1; + } + } + + function WritableStreamDefaultControllerGetDesiredSize(controller) { + return controller._strategyHWM - controller._queueTotalSize; + } + + function WritableStreamDefaultControllerWrite(controller, chunk, chunkSize) { + var writeRecord = { + chunk: chunk + }; + + try { + EnqueueValueWithSize(controller, writeRecord, chunkSize); + } catch (enqueueE) { + WritableStreamDefaultControllerErrorIfNeeded(controller, enqueueE); + return; + } + + var stream = controller._controlledWritableStream; + + if (WritableStreamCloseQueuedOrInFlight(stream) === false && stream._state === 'writable') { + var backpressure = WritableStreamDefaultControllerGetBackpressure(controller); + WritableStreamUpdateBackpressure(stream, backpressure); + } + + WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller); + } + + function IsWritableStreamDefaultController(x) { + if (!typeIsObject(x)) { + return false; + } + + if (!Object.prototype.hasOwnProperty.call(x, '_underlyingSink')) { + return false; + } + + return true; + } + + function WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller) { + var stream = controller._controlledWritableStream; + + if (controller._started === false) { + return; + } + + if (stream._inFlightWriteRequest !== undefined) { + return; + } + + var state = stream._state; + + if (state === 'closed' || state === 'errored') { + return; + } + + if (state === 'erroring') { + WritableStreamFinishErroring(stream); + return; + } + + if (controller._queue.length === 0) { + return; + } + + var writeRecord = PeekQueueValue(controller); + + if (writeRecord === 'close') { + WritableStreamDefaultControllerProcessClose(controller); + } else { + WritableStreamDefaultControllerProcessWrite(controller, writeRecord.chunk); + } + } + + function WritableStreamDefaultControllerErrorIfNeeded(controller, error) { + if (controller._controlledWritableStream._state === 'writable') { + WritableStreamDefaultControllerError(controller, error); + } + } + + function WritableStreamDefaultControllerProcessClose(controller) { + var stream = controller._controlledWritableStream; + WritableStreamMarkCloseRequestInFlight(stream); + DequeueValue(controller); + assert(controller._queue.length === 0, 'queue must be empty once the final write record is dequeued'); + var sinkClosePromise = PromiseInvokeOrNoop(controller._underlyingSink, 'close', []); + sinkClosePromise.then(function () { + WritableStreamFinishInFlightClose(stream); + }, function (reason) { + WritableStreamFinishInFlightCloseWithError(stream, reason); + }).catch(rethrowAssertionErrorRejection); + } + + function WritableStreamDefaultControllerProcessWrite(controller, chunk) { + var stream = controller._controlledWritableStream; + WritableStreamMarkFirstWriteRequestInFlight(stream); + var sinkWritePromise = PromiseInvokeOrNoop(controller._underlyingSink, 'write', [chunk, controller]); + sinkWritePromise.then(function () { + WritableStreamFinishInFlightWrite(stream); + var state = stream._state; + assert(state === 'writable' || state === 'erroring'); + DequeueValue(controller); + + if (WritableStreamCloseQueuedOrInFlight(stream) === false && state === 'writable') { + var backpressure = WritableStreamDefaultControllerGetBackpressure(controller); + WritableStreamUpdateBackpressure(stream, backpressure); + } + + WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller); + }, function (reason) { + WritableStreamFinishInFlightWriteWithError(stream, reason); + }).catch(rethrowAssertionErrorRejection); + } + + function WritableStreamDefaultControllerGetBackpressure(controller) { + var desiredSize = WritableStreamDefaultControllerGetDesiredSize(controller); + return desiredSize <= 0; + } + + function WritableStreamDefaultControllerError(controller, error) { + var stream = controller._controlledWritableStream; + assert(stream._state === 'writable'); + WritableStreamStartErroring(stream, error); + } + + function streamBrandCheckException(name) { + return new TypeError('WritableStream.prototype.' + name + ' can only be used on a WritableStream'); + } + + function defaultWriterBrandCheckException(name) { + return new TypeError('WritableStreamDefaultWriter.prototype.' + name + ' can only be used on a WritableStreamDefaultWriter'); + } + + function defaultWriterLockException(name) { + return new TypeError('Cannot ' + name + ' a stream using a released writer'); + } + + function defaultWriterClosedPromiseInitialize(writer) { + writer._closedPromise = new Promise(function (resolve, reject) { + writer._closedPromise_resolve = resolve; + writer._closedPromise_reject = reject; + writer._closedPromiseState = 'pending'; + }); + } + + function defaultWriterClosedPromiseInitializeAsRejected(writer, reason) { + writer._closedPromise = Promise.reject(reason); + writer._closedPromise_resolve = undefined; + writer._closedPromise_reject = undefined; + writer._closedPromiseState = 'rejected'; + } + + function defaultWriterClosedPromiseInitializeAsResolved(writer) { + writer._closedPromise = Promise.resolve(undefined); + writer._closedPromise_resolve = undefined; + writer._closedPromise_reject = undefined; + writer._closedPromiseState = 'resolved'; + } + + function defaultWriterClosedPromiseReject(writer, reason) { + assert(writer._closedPromise_resolve !== undefined, 'writer._closedPromise_resolve !== undefined'); + assert(writer._closedPromise_reject !== undefined, 'writer._closedPromise_reject !== undefined'); + assert(writer._closedPromiseState === 'pending', 'writer._closedPromiseState is pending'); + + writer._closedPromise_reject(reason); + + writer._closedPromise_resolve = undefined; + writer._closedPromise_reject = undefined; + writer._closedPromiseState = 'rejected'; + } + + function defaultWriterClosedPromiseResetToRejected(writer, reason) { + assert(writer._closedPromise_resolve === undefined, 'writer._closedPromise_resolve === undefined'); + assert(writer._closedPromise_reject === undefined, 'writer._closedPromise_reject === undefined'); + assert(writer._closedPromiseState !== 'pending', 'writer._closedPromiseState is not pending'); + writer._closedPromise = Promise.reject(reason); + writer._closedPromiseState = 'rejected'; + } + + function defaultWriterClosedPromiseResolve(writer) { + assert(writer._closedPromise_resolve !== undefined, 'writer._closedPromise_resolve !== undefined'); + assert(writer._closedPromise_reject !== undefined, 'writer._closedPromise_reject !== undefined'); + assert(writer._closedPromiseState === 'pending', 'writer._closedPromiseState is pending'); + + writer._closedPromise_resolve(undefined); + + writer._closedPromise_resolve = undefined; + writer._closedPromise_reject = undefined; + writer._closedPromiseState = 'resolved'; + } + + function defaultWriterReadyPromiseInitialize(writer) { + writer._readyPromise = new Promise(function (resolve, reject) { + writer._readyPromise_resolve = resolve; + writer._readyPromise_reject = reject; + }); + writer._readyPromiseState = 'pending'; + } + + function defaultWriterReadyPromiseInitializeAsRejected(writer, reason) { + writer._readyPromise = Promise.reject(reason); + writer._readyPromise_resolve = undefined; + writer._readyPromise_reject = undefined; + writer._readyPromiseState = 'rejected'; + } + + function defaultWriterReadyPromiseInitializeAsResolved(writer) { + writer._readyPromise = Promise.resolve(undefined); + writer._readyPromise_resolve = undefined; + writer._readyPromise_reject = undefined; + writer._readyPromiseState = 'fulfilled'; + } + + function defaultWriterReadyPromiseReject(writer, reason) { + assert(writer._readyPromise_resolve !== undefined, 'writer._readyPromise_resolve !== undefined'); + assert(writer._readyPromise_reject !== undefined, 'writer._readyPromise_reject !== undefined'); + + writer._readyPromise_reject(reason); + + writer._readyPromise_resolve = undefined; + writer._readyPromise_reject = undefined; + writer._readyPromiseState = 'rejected'; + } + + function defaultWriterReadyPromiseReset(writer) { + assert(writer._readyPromise_resolve === undefined, 'writer._readyPromise_resolve === undefined'); + assert(writer._readyPromise_reject === undefined, 'writer._readyPromise_reject === undefined'); + writer._readyPromise = new Promise(function (resolve, reject) { + writer._readyPromise_resolve = resolve; + writer._readyPromise_reject = reject; + }); + writer._readyPromiseState = 'pending'; + } + + function defaultWriterReadyPromiseResetToRejected(writer, reason) { + assert(writer._readyPromise_resolve === undefined, 'writer._readyPromise_resolve === undefined'); + assert(writer._readyPromise_reject === undefined, 'writer._readyPromise_reject === undefined'); + writer._readyPromise = Promise.reject(reason); + writer._readyPromiseState = 'rejected'; + } + + function defaultWriterReadyPromiseResolve(writer) { + assert(writer._readyPromise_resolve !== undefined, 'writer._readyPromise_resolve !== undefined'); + assert(writer._readyPromise_reject !== undefined, 'writer._readyPromise_reject !== undefined'); + + writer._readyPromise_resolve(undefined); + + writer._readyPromise_resolve = undefined; + writer._readyPromise_reject = undefined; + writer._readyPromiseState = 'fulfilled'; + } +}, function (module, exports, __w_pdfjs_require__) { + "use strict"; + + var _require = __w_pdfjs_require__(0), + IsFiniteNonNegativeNumber = _require.IsFiniteNonNegativeNumber; + + var _require2 = __w_pdfjs_require__(1), + assert = _require2.assert; + + exports.DequeueValue = function (container) { + assert('_queue' in container && '_queueTotalSize' in container, 'Spec-level failure: DequeueValue should only be used on containers with [[queue]] and [[queueTotalSize]].'); + assert(container._queue.length > 0, 'Spec-level failure: should never dequeue from an empty queue.'); + + var pair = container._queue.shift(); + + container._queueTotalSize -= pair.size; + + if (container._queueTotalSize < 0) { + container._queueTotalSize = 0; + } + + return pair.value; + }; + + exports.EnqueueValueWithSize = function (container, value, size) { + assert('_queue' in container && '_queueTotalSize' in container, 'Spec-level failure: EnqueueValueWithSize should only be used on containers with [[queue]] and ' + '[[queueTotalSize]].'); + size = Number(size); + + if (!IsFiniteNonNegativeNumber(size)) { + throw new RangeError('Size must be a finite, non-NaN, non-negative number.'); + } + + container._queue.push({ + value: value, + size: size + }); + + container._queueTotalSize += size; + }; + + exports.PeekQueueValue = function (container) { + assert('_queue' in container && '_queueTotalSize' in container, 'Spec-level failure: PeekQueueValue should only be used on containers with [[queue]] and [[queueTotalSize]].'); + assert(container._queue.length > 0, 'Spec-level failure: should never peek at an empty queue.'); + var pair = container._queue[0]; + return pair.value; + }; + + exports.ResetQueue = function (container) { + assert('_queue' in container && '_queueTotalSize' in container, 'Spec-level failure: ResetQueue should only be used on containers with [[queue]] and [[queueTotalSize]].'); + container._queue = []; + container._queueTotalSize = 0; + }; +}, function (module, exports, __w_pdfjs_require__) { + "use strict"; + + var _createClass = function () { + function defineProperties(target, props) { + for (var i = 0; i < props.length; i++) { + var descriptor = props[i]; + descriptor.enumerable = descriptor.enumerable || false; + descriptor.configurable = true; + if ("value" in descriptor) descriptor.writable = true; + Object.defineProperty(target, descriptor.key, descriptor); + } + } + + return function (Constructor, protoProps, staticProps) { + if (protoProps) defineProperties(Constructor.prototype, protoProps); + if (staticProps) defineProperties(Constructor, staticProps); + return Constructor; + }; + }(); + + function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); + } + } + + var _require = __w_pdfjs_require__(0), + ArrayBufferCopy = _require.ArrayBufferCopy, + CreateIterResultObject = _require.CreateIterResultObject, + IsFiniteNonNegativeNumber = _require.IsFiniteNonNegativeNumber, + InvokeOrNoop = _require.InvokeOrNoop, + PromiseInvokeOrNoop = _require.PromiseInvokeOrNoop, + TransferArrayBuffer = _require.TransferArrayBuffer, + ValidateAndNormalizeQueuingStrategy = _require.ValidateAndNormalizeQueuingStrategy, + ValidateAndNormalizeHighWaterMark = _require.ValidateAndNormalizeHighWaterMark; + + var _require2 = __w_pdfjs_require__(0), + createArrayFromList = _require2.createArrayFromList, + createDataProperty = _require2.createDataProperty, + typeIsObject = _require2.typeIsObject; + + var _require3 = __w_pdfjs_require__(1), + assert = _require3.assert, + rethrowAssertionErrorRejection = _require3.rethrowAssertionErrorRejection; + + var _require4 = __w_pdfjs_require__(3), + DequeueValue = _require4.DequeueValue, + EnqueueValueWithSize = _require4.EnqueueValueWithSize, + ResetQueue = _require4.ResetQueue; + + var _require5 = __w_pdfjs_require__(2), + AcquireWritableStreamDefaultWriter = _require5.AcquireWritableStreamDefaultWriter, + IsWritableStream = _require5.IsWritableStream, + IsWritableStreamLocked = _require5.IsWritableStreamLocked, + WritableStreamAbort = _require5.WritableStreamAbort, + WritableStreamDefaultWriterCloseWithErrorPropagation = _require5.WritableStreamDefaultWriterCloseWithErrorPropagation, + WritableStreamDefaultWriterRelease = _require5.WritableStreamDefaultWriterRelease, + WritableStreamDefaultWriterWrite = _require5.WritableStreamDefaultWriterWrite, + WritableStreamCloseQueuedOrInFlight = _require5.WritableStreamCloseQueuedOrInFlight; + + var ReadableStream = function () { + function ReadableStream() { + var underlyingSource = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + + var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, + size = _ref.size, + highWaterMark = _ref.highWaterMark; + + _classCallCheck(this, ReadableStream); + + this._state = 'readable'; + this._reader = undefined; + this._storedError = undefined; + this._disturbed = false; + this._readableStreamController = undefined; + var type = underlyingSource.type; + var typeString = String(type); + + if (typeString === 'bytes') { + if (highWaterMark === undefined) { + highWaterMark = 0; + } + + this._readableStreamController = new ReadableByteStreamController(this, underlyingSource, highWaterMark); + } else if (type === undefined) { + if (highWaterMark === undefined) { + highWaterMark = 1; + } + + this._readableStreamController = new ReadableStreamDefaultController(this, underlyingSource, size, highWaterMark); + } else { + throw new RangeError('Invalid type is specified'); + } + } + + _createClass(ReadableStream, [{ + key: 'cancel', + value: function cancel(reason) { + if (IsReadableStream(this) === false) { + return Promise.reject(streamBrandCheckException('cancel')); + } + + if (IsReadableStreamLocked(this) === true) { + return Promise.reject(new TypeError('Cannot cancel a stream that already has a reader')); + } + + return ReadableStreamCancel(this, reason); + } + }, { + key: 'getReader', + value: function getReader() { + var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, + mode = _ref2.mode; + + if (IsReadableStream(this) === false) { + throw streamBrandCheckException('getReader'); + } + + if (mode === undefined) { + return AcquireReadableStreamDefaultReader(this); + } + + mode = String(mode); + + if (mode === 'byob') { + return AcquireReadableStreamBYOBReader(this); + } + + throw new RangeError('Invalid mode is specified'); + } + }, { + key: 'pipeThrough', + value: function pipeThrough(_ref3, options) { + var writable = _ref3.writable, + readable = _ref3.readable; + var promise = this.pipeTo(writable, options); + ifIsObjectAndHasAPromiseIsHandledInternalSlotSetPromiseIsHandledToTrue(promise); + return readable; + } + }, { + key: 'pipeTo', + value: function pipeTo(dest) { + var _this = this; + + var _ref4 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, + preventClose = _ref4.preventClose, + preventAbort = _ref4.preventAbort, + preventCancel = _ref4.preventCancel; + + if (IsReadableStream(this) === false) { + return Promise.reject(streamBrandCheckException('pipeTo')); + } + + if (IsWritableStream(dest) === false) { + return Promise.reject(new TypeError('ReadableStream.prototype.pipeTo\'s first argument must be a WritableStream')); + } + + preventClose = Boolean(preventClose); + preventAbort = Boolean(preventAbort); + preventCancel = Boolean(preventCancel); + + if (IsReadableStreamLocked(this) === true) { + return Promise.reject(new TypeError('ReadableStream.prototype.pipeTo cannot be used on a locked ReadableStream')); + } + + if (IsWritableStreamLocked(dest) === true) { + return Promise.reject(new TypeError('ReadableStream.prototype.pipeTo cannot be used on a locked WritableStream')); + } + + var reader = AcquireReadableStreamDefaultReader(this); + var writer = AcquireWritableStreamDefaultWriter(dest); + var shuttingDown = false; + var currentWrite = Promise.resolve(); + return new Promise(function (resolve, reject) { + function pipeLoop() { + currentWrite = Promise.resolve(); + + if (shuttingDown === true) { + return Promise.resolve(); + } + + return writer._readyPromise.then(function () { + return ReadableStreamDefaultReaderRead(reader).then(function (_ref5) { + var value = _ref5.value, + done = _ref5.done; + + if (done === true) { + return; + } + + currentWrite = WritableStreamDefaultWriterWrite(writer, value).catch(function () {}); + }); + }).then(pipeLoop); + } + + isOrBecomesErrored(_this, reader._closedPromise, function (storedError) { + if (preventAbort === false) { + shutdownWithAction(function () { + return WritableStreamAbort(dest, storedError); + }, true, storedError); + } else { + shutdown(true, storedError); + } + }); + isOrBecomesErrored(dest, writer._closedPromise, function (storedError) { + if (preventCancel === false) { + shutdownWithAction(function () { + return ReadableStreamCancel(_this, storedError); + }, true, storedError); + } else { + shutdown(true, storedError); + } + }); + isOrBecomesClosed(_this, reader._closedPromise, function () { + 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) { + var shouldPull = ReadableByteStreamControllerShouldCallPull(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._underlyingByteSource, 'pull', [controller]); + pullPromise.then(function () { + controller._pulling = false; + + if (controller._pullAgain === true) { + controller._pullAgain = false; + ReadableByteStreamControllerCallPullIfNeeded(controller); + } + }, function (e) { + if (controller._controlledReadableStream._state === 'readable') { + ReadableByteStreamControllerError(controller, e); + } + }).catch(rethrowAssertionErrorRejection); + return undefined; + } + + function ReadableByteStreamControllerClearPendingPullIntos(controller) { + ReadableByteStreamControllerInvalidateBYOBRequest(controller); + controller._pendingPullIntos = []; + } + + function ReadableByteStreamControllerCommitPullIntoDescriptor(stream, pullIntoDescriptor) { + assert(stream._state !== 'errored', 'state must not be errored'); + var done = false; + + if (stream._state === 'closed') { + assert(pullIntoDescriptor.bytesFilled === 0); + done = true; + } + + var filledView = ReadableByteStreamControllerConvertPullIntoDescriptor(pullIntoDescriptor); + + if (pullIntoDescriptor.readerType === 'default') { + ReadableStreamFulfillReadRequest(stream, filledView, done); + } else { + assert(pullIntoDescriptor.readerType === 'byob'); + ReadableStreamFulfillReadIntoRequest(stream, filledView, done); + } + } + + function ReadableByteStreamControllerConvertPullIntoDescriptor(pullIntoDescriptor) { + var bytesFilled = pullIntoDescriptor.bytesFilled; + var elementSize = pullIntoDescriptor.elementSize; + assert(bytesFilled <= pullIntoDescriptor.byteLength); + assert(bytesFilled % elementSize === 0); + return new pullIntoDescriptor.ctor(pullIntoDescriptor.buffer, pullIntoDescriptor.byteOffset, bytesFilled / elementSize); + } + + function ReadableByteStreamControllerEnqueueChunkToQueue(controller, buffer, byteOffset, byteLength) { + controller._queue.push({ + buffer: buffer, + byteOffset: byteOffset, + byteLength: byteLength + }); + + controller._queueTotalSize += byteLength; + } + + function ReadableByteStreamControllerFillPullIntoDescriptorFromQueue(controller, pullIntoDescriptor) { + var elementSize = pullIntoDescriptor.elementSize; + var currentAlignedBytes = pullIntoDescriptor.bytesFilled - pullIntoDescriptor.bytesFilled % elementSize; + var maxBytesToCopy = Math.min(controller._queueTotalSize, pullIntoDescriptor.byteLength - pullIntoDescriptor.bytesFilled); + var maxBytesFilled = pullIntoDescriptor.bytesFilled + maxBytesToCopy; + var maxAlignedBytes = maxBytesFilled - maxBytesFilled % elementSize; + var totalBytesToCopyRemaining = maxBytesToCopy; + var ready = false; + + if (maxAlignedBytes > currentAlignedBytes) { + totalBytesToCopyRemaining = maxAlignedBytes - pullIntoDescriptor.bytesFilled; + ready = true; + } + + var queue = controller._queue; + + while (totalBytesToCopyRemaining > 0) { + var headOfQueue = queue[0]; + var bytesToCopy = Math.min(totalBytesToCopyRemaining, headOfQueue.byteLength); + var destStart = pullIntoDescriptor.byteOffset + pullIntoDescriptor.bytesFilled; + ArrayBufferCopy(pullIntoDescriptor.buffer, destStart, headOfQueue.buffer, headOfQueue.byteOffset, bytesToCopy); + + if (headOfQueue.byteLength === bytesToCopy) { + queue.shift(); + } else { + headOfQueue.byteOffset += bytesToCopy; + headOfQueue.byteLength -= bytesToCopy; + } + + controller._queueTotalSize -= bytesToCopy; + ReadableByteStreamControllerFillHeadPullIntoDescriptor(controller, bytesToCopy, pullIntoDescriptor); + totalBytesToCopyRemaining -= bytesToCopy; + } + + if (ready === false) { + assert(controller._queueTotalSize === 0, 'queue must be empty'); + assert(pullIntoDescriptor.bytesFilled > 0); + assert(pullIntoDescriptor.bytesFilled < pullIntoDescriptor.elementSize); + } + + return ready; + } + + function ReadableByteStreamControllerFillHeadPullIntoDescriptor(controller, size, pullIntoDescriptor) { + assert(controller._pendingPullIntos.length === 0 || controller._pendingPullIntos[0] === pullIntoDescriptor); + ReadableByteStreamControllerInvalidateBYOBRequest(controller); + pullIntoDescriptor.bytesFilled += size; + } + + function ReadableByteStreamControllerHandleQueueDrain(controller) { + assert(controller._controlledReadableStream._state === 'readable'); + + if (controller._queueTotalSize === 0 && controller._closeRequested === true) { + ReadableStreamClose(controller._controlledReadableStream); + } else { + ReadableByteStreamControllerCallPullIfNeeded(controller); + } + } + + function ReadableByteStreamControllerInvalidateBYOBRequest(controller) { + if (controller._byobRequest === undefined) { + return; + } + + controller._byobRequest._associatedReadableByteStreamController = undefined; + controller._byobRequest._view = undefined; + controller._byobRequest = undefined; + } + + function ReadableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(controller) { + assert(controller._closeRequested === false); + + while (controller._pendingPullIntos.length > 0) { + if (controller._queueTotalSize === 0) { + return; + } + + var pullIntoDescriptor = controller._pendingPullIntos[0]; + + if (ReadableByteStreamControllerFillPullIntoDescriptorFromQueue(controller, pullIntoDescriptor) === true) { + ReadableByteStreamControllerShiftPendingPullInto(controller); + ReadableByteStreamControllerCommitPullIntoDescriptor(controller._controlledReadableStream, pullIntoDescriptor); + } + } + } + + function ReadableByteStreamControllerPullInto(controller, view) { + var stream = controller._controlledReadableStream; + var elementSize = 1; + + if (view.constructor !== DataView) { + elementSize = view.constructor.BYTES_PER_ELEMENT; + } + + var ctor = view.constructor; + var pullIntoDescriptor = { + buffer: view.buffer, + byteOffset: view.byteOffset, + byteLength: view.byteLength, + bytesFilled: 0, + elementSize: elementSize, + ctor: ctor, + readerType: 'byob' + }; + + if (controller._pendingPullIntos.length > 0) { + pullIntoDescriptor.buffer = TransferArrayBuffer(pullIntoDescriptor.buffer); + + controller._pendingPullIntos.push(pullIntoDescriptor); + + return ReadableStreamAddReadIntoRequest(stream); + } + + if (stream._state === 'closed') { + var emptyView = new view.constructor(pullIntoDescriptor.buffer, pullIntoDescriptor.byteOffset, 0); + return Promise.resolve(CreateIterResultObject(emptyView, true)); + } + + if (controller._queueTotalSize > 0) { + if (ReadableByteStreamControllerFillPullIntoDescriptorFromQueue(controller, pullIntoDescriptor) === true) { + var filledView = ReadableByteStreamControllerConvertPullIntoDescriptor(pullIntoDescriptor); + ReadableByteStreamControllerHandleQueueDrain(controller); + return Promise.resolve(CreateIterResultObject(filledView, false)); + } + + if (controller._closeRequested === true) { + var e = new TypeError('Insufficient bytes to fill elements in the given buffer'); + ReadableByteStreamControllerError(controller, e); + return Promise.reject(e); + } + } + + pullIntoDescriptor.buffer = TransferArrayBuffer(pullIntoDescriptor.buffer); + + controller._pendingPullIntos.push(pullIntoDescriptor); + + var promise = ReadableStreamAddReadIntoRequest(stream); + ReadableByteStreamControllerCallPullIfNeeded(controller); + return promise; + } + + function ReadableByteStreamControllerRespondInClosedState(controller, firstDescriptor) { + firstDescriptor.buffer = TransferArrayBuffer(firstDescriptor.buffer); + assert(firstDescriptor.bytesFilled === 0, 'bytesFilled must be 0'); + var stream = controller._controlledReadableStream; + + if (ReadableStreamHasBYOBReader(stream) === true) { + while (ReadableStreamGetNumReadIntoRequests(stream) > 0) { + var pullIntoDescriptor = ReadableByteStreamControllerShiftPendingPullInto(controller); + ReadableByteStreamControllerCommitPullIntoDescriptor(stream, pullIntoDescriptor); + } + } + } + + function ReadableByteStreamControllerRespondInReadableState(controller, bytesWritten, pullIntoDescriptor) { + if (pullIntoDescriptor.bytesFilled + bytesWritten > pullIntoDescriptor.byteLength) { + throw new RangeError('bytesWritten out of range'); + } + + ReadableByteStreamControllerFillHeadPullIntoDescriptor(controller, bytesWritten, pullIntoDescriptor); + + if (pullIntoDescriptor.bytesFilled < pullIntoDescriptor.elementSize) { + return; + } + + ReadableByteStreamControllerShiftPendingPullInto(controller); + var remainderSize = pullIntoDescriptor.bytesFilled % pullIntoDescriptor.elementSize; + + if (remainderSize > 0) { + var end = pullIntoDescriptor.byteOffset + pullIntoDescriptor.bytesFilled; + var remainder = pullIntoDescriptor.buffer.slice(end - remainderSize, end); + ReadableByteStreamControllerEnqueueChunkToQueue(controller, remainder, 0, remainder.byteLength); + } + + pullIntoDescriptor.buffer = TransferArrayBuffer(pullIntoDescriptor.buffer); + pullIntoDescriptor.bytesFilled -= remainderSize; + ReadableByteStreamControllerCommitPullIntoDescriptor(controller._controlledReadableStream, pullIntoDescriptor); + ReadableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(controller); + } + + function ReadableByteStreamControllerRespondInternal(controller, bytesWritten) { + var firstDescriptor = controller._pendingPullIntos[0]; + var stream = controller._controlledReadableStream; + + if (stream._state === 'closed') { + if (bytesWritten !== 0) { + throw new TypeError('bytesWritten must be 0 when calling respond() on a closed stream'); + } + + ReadableByteStreamControllerRespondInClosedState(controller, firstDescriptor); + } else { + assert(stream._state === 'readable'); + ReadableByteStreamControllerRespondInReadableState(controller, bytesWritten, firstDescriptor); + } + } + + function ReadableByteStreamControllerShiftPendingPullInto(controller) { + var descriptor = controller._pendingPullIntos.shift(); + + ReadableByteStreamControllerInvalidateBYOBRequest(controller); + return descriptor; + } + + function ReadableByteStreamControllerShouldCallPull(controller) { + var stream = controller._controlledReadableStream; + + if (stream._state !== 'readable') { + return false; + } + + if (controller._closeRequested === true) { + return false; + } + + if (controller._started === false) { + return false; + } + + if (ReadableStreamHasDefaultReader(stream) === true && ReadableStreamGetNumReadRequests(stream) > 0) { + return true; + } + + if (ReadableStreamHasBYOBReader(stream) === true && ReadableStreamGetNumReadIntoRequests(stream) > 0) { + return true; + } + + if (ReadableByteStreamControllerGetDesiredSize(controller) > 0) { + return true; + } + + return false; + } + + function ReadableByteStreamControllerClose(controller) { + var stream = controller._controlledReadableStream; + assert(controller._closeRequested === false); + assert(stream._state === 'readable'); + + if (controller._queueTotalSize > 0) { + controller._closeRequested = true; + return; + } + + if (controller._pendingPullIntos.length > 0) { + var firstPendingPullInto = controller._pendingPullIntos[0]; + + if (firstPendingPullInto.bytesFilled > 0) { + var e = new TypeError('Insufficient bytes to fill elements in the given buffer'); + ReadableByteStreamControllerError(controller, e); + throw e; + } + } + + ReadableStreamClose(stream); + } + + function ReadableByteStreamControllerEnqueue(controller, chunk) { + var stream = controller._controlledReadableStream; + assert(controller._closeRequested === false); + assert(stream._state === 'readable'); + var buffer = chunk.buffer; + var byteOffset = chunk.byteOffset; + var byteLength = chunk.byteLength; + var transferredBuffer = TransferArrayBuffer(buffer); + + if (ReadableStreamHasDefaultReader(stream) === true) { + if (ReadableStreamGetNumReadRequests(stream) === 0) { + ReadableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset, byteLength); + } else { + assert(controller._queue.length === 0); + var transferredView = new Uint8Array(transferredBuffer, byteOffset, byteLength); + ReadableStreamFulfillReadRequest(stream, transferredView, false); + } + } else if (ReadableStreamHasBYOBReader(stream) === true) { + ReadableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset, byteLength); + ReadableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(controller); + } else { + assert(IsReadableStreamLocked(stream) === false, 'stream must not be locked'); + ReadableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset, byteLength); + } + } + + function ReadableByteStreamControllerError(controller, e) { + var stream = controller._controlledReadableStream; + assert(stream._state === 'readable'); + ReadableByteStreamControllerClearPendingPullIntos(controller); + ResetQueue(controller); + ReadableStreamError(stream, e); + } + + function ReadableByteStreamControllerGetDesiredSize(controller) { + var stream = controller._controlledReadableStream; + var state = stream._state; + + if (state === 'errored') { + return null; + } + + if (state === 'closed') { + return 0; + } + + return controller._strategyHWM - controller._queueTotalSize; + } + + function ReadableByteStreamControllerRespond(controller, bytesWritten) { + bytesWritten = Number(bytesWritten); + + if (IsFiniteNonNegativeNumber(bytesWritten) === false) { + throw new RangeError('bytesWritten must be a finite'); + } + + assert(controller._pendingPullIntos.length > 0); + ReadableByteStreamControllerRespondInternal(controller, bytesWritten); + } + + function ReadableByteStreamControllerRespondWithNewView(controller, view) { + assert(controller._pendingPullIntos.length > 0); + var firstDescriptor = controller._pendingPullIntos[0]; + + if (firstDescriptor.byteOffset + firstDescriptor.bytesFilled !== view.byteOffset) { + throw new RangeError('The region specified by view does not match byobRequest'); + } + + if (firstDescriptor.byteLength !== view.byteLength) { + throw new RangeError('The buffer of view has different capacity than byobRequest'); + } + + firstDescriptor.buffer = view.buffer; + ReadableByteStreamControllerRespondInternal(controller, view.byteLength); + } + + function streamBrandCheckException(name) { + return new TypeError('ReadableStream.prototype.' + name + ' can only be used on a ReadableStream'); + } + + function readerLockException(name) { + return new TypeError('Cannot ' + name + ' a stream using a released reader'); + } + + function defaultReaderBrandCheckException(name) { + return new TypeError('ReadableStreamDefaultReader.prototype.' + name + ' can only be used on a ReadableStreamDefaultReader'); + } + + function defaultReaderClosedPromiseInitialize(reader) { + reader._closedPromise = new Promise(function (resolve, reject) { + reader._closedPromise_resolve = resolve; + reader._closedPromise_reject = reject; + }); + } + + function defaultReaderClosedPromiseInitializeAsRejected(reader, reason) { + reader._closedPromise = Promise.reject(reason); + reader._closedPromise_resolve = undefined; + reader._closedPromise_reject = undefined; + } + + function defaultReaderClosedPromiseInitializeAsResolved(reader) { + reader._closedPromise = Promise.resolve(undefined); + reader._closedPromise_resolve = undefined; + reader._closedPromise_reject = undefined; + } + + function defaultReaderClosedPromiseReject(reader, reason) { + assert(reader._closedPromise_resolve !== undefined); + assert(reader._closedPromise_reject !== undefined); + + reader._closedPromise_reject(reason); + + reader._closedPromise_resolve = undefined; + reader._closedPromise_reject = undefined; + } + + function defaultReaderClosedPromiseResetToRejected(reader, reason) { + assert(reader._closedPromise_resolve === undefined); + assert(reader._closedPromise_reject === undefined); + reader._closedPromise = Promise.reject(reason); + } + + function defaultReaderClosedPromiseResolve(reader) { + assert(reader._closedPromise_resolve !== undefined); + assert(reader._closedPromise_reject !== undefined); + + reader._closedPromise_resolve(undefined); + + reader._closedPromise_resolve = undefined; + reader._closedPromise_reject = undefined; + } + + function byobReaderBrandCheckException(name) { + return new TypeError('ReadableStreamBYOBReader.prototype.' + name + ' can only be used on a ReadableStreamBYOBReader'); + } + + function defaultControllerBrandCheckException(name) { + return new TypeError('ReadableStreamDefaultController.prototype.' + name + ' can only be used on a ReadableStreamDefaultController'); + } + + function byobRequestBrandCheckException(name) { + return new TypeError('ReadableStreamBYOBRequest.prototype.' + name + ' can only be used on a ReadableStreamBYOBRequest'); + } + + function byteStreamControllerBrandCheckException(name) { + return new TypeError('ReadableByteStreamController.prototype.' + name + ' can only be used on a ReadableByteStreamController'); + } + + function ifIsObjectAndHasAPromiseIsHandledInternalSlotSetPromiseIsHandledToTrue(promise) { + try { + Promise.prototype.then.call(promise, undefined, function () {}); + } catch (e) {} + } +}, function (module, exports, __w_pdfjs_require__) { + "use strict"; + + var transformStream = __w_pdfjs_require__(6); + + var readableStream = __w_pdfjs_require__(4); + + var writableStream = __w_pdfjs_require__(2); + + exports.TransformStream = transformStream.TransformStream; + exports.ReadableStream = readableStream.ReadableStream; + exports.IsReadableStreamDisturbed = readableStream.IsReadableStreamDisturbed; + exports.ReadableStreamDefaultControllerClose = readableStream.ReadableStreamDefaultControllerClose; + exports.ReadableStreamDefaultControllerEnqueue = readableStream.ReadableStreamDefaultControllerEnqueue; + exports.ReadableStreamDefaultControllerError = readableStream.ReadableStreamDefaultControllerError; + exports.ReadableStreamDefaultControllerGetDesiredSize = readableStream.ReadableStreamDefaultControllerGetDesiredSize; + exports.AcquireWritableStreamDefaultWriter = writableStream.AcquireWritableStreamDefaultWriter; + exports.IsWritableStream = writableStream.IsWritableStream; + exports.IsWritableStreamLocked = writableStream.IsWritableStreamLocked; + exports.WritableStream = writableStream.WritableStream; + exports.WritableStreamAbort = writableStream.WritableStreamAbort; + exports.WritableStreamDefaultControllerError = writableStream.WritableStreamDefaultControllerError; + exports.WritableStreamDefaultWriterCloseWithErrorPropagation = writableStream.WritableStreamDefaultWriterCloseWithErrorPropagation; + exports.WritableStreamDefaultWriterRelease = writableStream.WritableStreamDefaultWriterRelease; + exports.WritableStreamDefaultWriterWrite = writableStream.WritableStreamDefaultWriterWrite; +}, function (module, exports, __w_pdfjs_require__) { + "use strict"; + + var _createClass = function () { + function defineProperties(target, props) { + for (var i = 0; i < props.length; i++) { + var descriptor = props[i]; + descriptor.enumerable = descriptor.enumerable || false; + descriptor.configurable = true; + if ("value" in descriptor) descriptor.writable = true; + Object.defineProperty(target, descriptor.key, descriptor); + } + } + + return function (Constructor, protoProps, staticProps) { + if (protoProps) defineProperties(Constructor.prototype, protoProps); + if (staticProps) defineProperties(Constructor, staticProps); + return Constructor; + }; + }(); + + function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); + } + } + + var _require = __w_pdfjs_require__(1), + assert = _require.assert; + + var _require2 = __w_pdfjs_require__(0), + InvokeOrNoop = _require2.InvokeOrNoop, + PromiseInvokeOrPerformFallback = _require2.PromiseInvokeOrPerformFallback, + PromiseInvokeOrNoop = _require2.PromiseInvokeOrNoop, + typeIsObject = _require2.typeIsObject; + + var _require3 = __w_pdfjs_require__(4), + ReadableStream = _require3.ReadableStream, + ReadableStreamDefaultControllerClose = _require3.ReadableStreamDefaultControllerClose, + ReadableStreamDefaultControllerEnqueue = _require3.ReadableStreamDefaultControllerEnqueue, + ReadableStreamDefaultControllerError = _require3.ReadableStreamDefaultControllerError, + ReadableStreamDefaultControllerGetDesiredSize = _require3.ReadableStreamDefaultControllerGetDesiredSize; + + var _require4 = __w_pdfjs_require__(2), + WritableStream = _require4.WritableStream, + WritableStreamDefaultControllerError = _require4.WritableStreamDefaultControllerError; + + function TransformStreamCloseReadable(transformStream) { + if (transformStream._errored === true) { + throw new TypeError('TransformStream is already errored'); + } + + if (transformStream._readableClosed === true) { + throw new TypeError('Readable side is already closed'); + } + + TransformStreamCloseReadableInternal(transformStream); + } + + function TransformStreamEnqueueToReadable(transformStream, chunk) { + if (transformStream._errored === true) { + throw new TypeError('TransformStream is already errored'); + } + + if (transformStream._readableClosed === true) { + throw new TypeError('Readable side is already closed'); + } + + var controller = transformStream._readableController; + + try { + ReadableStreamDefaultControllerEnqueue(controller, chunk); + } catch (e) { + transformStream._readableClosed = true; + TransformStreamErrorIfNeeded(transformStream, e); + throw transformStream._storedError; + } + + var desiredSize = ReadableStreamDefaultControllerGetDesiredSize(controller); + var maybeBackpressure = desiredSize <= 0; + + if (maybeBackpressure === true && transformStream._backpressure === false) { + TransformStreamSetBackpressure(transformStream, true); + } + } + + function TransformStreamError(transformStream, e) { + if (transformStream._errored === true) { + throw new TypeError('TransformStream is already errored'); + } + + TransformStreamErrorInternal(transformStream, e); + } + + function TransformStreamCloseReadableInternal(transformStream) { + assert(transformStream._errored === false); + assert(transformStream._readableClosed === false); + + try { + ReadableStreamDefaultControllerClose(transformStream._readableController); + } catch (e) { + assert(false); + } + + transformStream._readableClosed = true; + } + + function TransformStreamErrorIfNeeded(transformStream, e) { + if (transformStream._errored === false) { + TransformStreamErrorInternal(transformStream, e); + } + } + + function TransformStreamErrorInternal(transformStream, e) { + assert(transformStream._errored === false); + transformStream._errored = true; + transformStream._storedError = e; + + if (transformStream._writableDone === false) { + WritableStreamDefaultControllerError(transformStream._writableController, e); + } + + if (transformStream._readableClosed === false) { + ReadableStreamDefaultControllerError(transformStream._readableController, e); + } + } + + function TransformStreamReadableReadyPromise(transformStream) { + assert(transformStream._backpressureChangePromise !== undefined, '_backpressureChangePromise should have been initialized'); + + if (transformStream._backpressure === false) { + return Promise.resolve(); + } + + assert(transformStream._backpressure === true, '_backpressure should have been initialized'); + return transformStream._backpressureChangePromise; + } + + function TransformStreamSetBackpressure(transformStream, backpressure) { + assert(transformStream._backpressure !== backpressure, 'TransformStreamSetBackpressure() should be called only when backpressure is changed'); + + if (transformStream._backpressureChangePromise !== undefined) { + transformStream._backpressureChangePromise_resolve(backpressure); + } + + transformStream._backpressureChangePromise = new Promise(function (resolve) { + transformStream._backpressureChangePromise_resolve = resolve; + }); + + transformStream._backpressureChangePromise.then(function (resolution) { + assert(resolution !== backpressure, '_backpressureChangePromise should be fulfilled only when backpressure is changed'); + }); + + transformStream._backpressure = backpressure; + } + + function TransformStreamDefaultTransform(chunk, transformStreamController) { + var transformStream = transformStreamController._controlledTransformStream; + TransformStreamEnqueueToReadable(transformStream, chunk); + return Promise.resolve(); + } + + function TransformStreamTransform(transformStream, chunk) { + assert(transformStream._errored === false); + assert(transformStream._transforming === false); + assert(transformStream._backpressure === false); + transformStream._transforming = true; + var transformer = transformStream._transformer; + var controller = transformStream._transformStreamController; + var transformPromise = PromiseInvokeOrPerformFallback(transformer, 'transform', [chunk, controller], TransformStreamDefaultTransform, [chunk, controller]); + return transformPromise.then(function () { + transformStream._transforming = false; + return TransformStreamReadableReadyPromise(transformStream); + }, function (e) { + TransformStreamErrorIfNeeded(transformStream, e); + return Promise.reject(e); + }); + } + + function IsTransformStreamDefaultController(x) { + if (!typeIsObject(x)) { + return false; + } + + if (!Object.prototype.hasOwnProperty.call(x, '_controlledTransformStream')) { + return false; + } + + return true; + } + + function IsTransformStream(x) { + if (!typeIsObject(x)) { + return false; + } + + if (!Object.prototype.hasOwnProperty.call(x, '_transformStreamController')) { + return false; + } + + return true; + } + + var TransformStreamSink = function () { + function TransformStreamSink(transformStream, startPromise) { + _classCallCheck(this, TransformStreamSink); + + this._transformStream = transformStream; + this._startPromise = startPromise; + } + + _createClass(TransformStreamSink, [{ + key: 'start', + value: function start(c) { + var transformStream = this._transformStream; + transformStream._writableController = c; + return this._startPromise.then(function () { + return TransformStreamReadableReadyPromise(transformStream); + }); + } + }, { + key: 'write', + value: function write(chunk) { + var transformStream = this._transformStream; + return TransformStreamTransform(transformStream, chunk); + } + }, { + key: 'abort', + value: function abort() { + var transformStream = this._transformStream; + transformStream._writableDone = true; + TransformStreamErrorInternal(transformStream, new TypeError('Writable side aborted')); + } + }, { + key: 'close', + value: function close() { + var transformStream = this._transformStream; + assert(transformStream._transforming === false); + transformStream._writableDone = true; + var flushPromise = PromiseInvokeOrNoop(transformStream._transformer, 'flush', [transformStream._transformStreamController]); + return flushPromise.then(function () { + if (transformStream._errored === true) { + return Promise.reject(transformStream._storedError); + } + + if (transformStream._readableClosed === false) { + TransformStreamCloseReadableInternal(transformStream); + } + + return Promise.resolve(); + }).catch(function (r) { + TransformStreamErrorIfNeeded(transformStream, r); + return Promise.reject(transformStream._storedError); + }); + } + }]); + + return TransformStreamSink; + }(); + + var TransformStreamSource = function () { + function TransformStreamSource(transformStream, startPromise) { + _classCallCheck(this, TransformStreamSource); + + this._transformStream = transformStream; + this._startPromise = startPromise; + } + + _createClass(TransformStreamSource, [{ + key: 'start', + value: function start(c) { + var transformStream = this._transformStream; + transformStream._readableController = c; + return this._startPromise.then(function () { + assert(transformStream._backpressureChangePromise !== undefined, '_backpressureChangePromise should have been initialized'); + + if (transformStream._backpressure === true) { + return Promise.resolve(); + } + + assert(transformStream._backpressure === false, '_backpressure should have been initialized'); + return transformStream._backpressureChangePromise; + }); + } + }, { + key: 'pull', + value: function pull() { + var transformStream = this._transformStream; + assert(transformStream._backpressure === true, 'pull() should be never called while _backpressure is false'); + assert(transformStream._backpressureChangePromise !== undefined, '_backpressureChangePromise should have been initialized'); + TransformStreamSetBackpressure(transformStream, false); + return transformStream._backpressureChangePromise; + } + }, { + key: 'cancel', + value: function cancel() { + var transformStream = this._transformStream; + transformStream._readableClosed = true; + TransformStreamErrorInternal(transformStream, new TypeError('Readable side canceled')); + } + }]); + + return TransformStreamSource; + }(); + + var TransformStreamDefaultController = function () { + function TransformStreamDefaultController(transformStream) { + _classCallCheck(this, TransformStreamDefaultController); + + if (IsTransformStream(transformStream) === false) { + throw new TypeError('TransformStreamDefaultController can only be ' + 'constructed with a TransformStream instance'); + } + + if (transformStream._transformStreamController !== undefined) { + throw new TypeError('TransformStreamDefaultController instances can ' + 'only be created by the TransformStream constructor'); + } + + this._controlledTransformStream = transformStream; + } + + _createClass(TransformStreamDefaultController, [{ + key: 'enqueue', + value: function enqueue(chunk) { + if (IsTransformStreamDefaultController(this) === false) { + throw defaultControllerBrandCheckException('enqueue'); + } + + TransformStreamEnqueueToReadable(this._controlledTransformStream, chunk); + } + }, { + key: 'close', + value: function close() { + if (IsTransformStreamDefaultController(this) === false) { + throw defaultControllerBrandCheckException('close'); + } + + TransformStreamCloseReadable(this._controlledTransformStream); + } + }, { + key: 'error', + value: function error(reason) { + if (IsTransformStreamDefaultController(this) === false) { + throw defaultControllerBrandCheckException('error'); + } + + TransformStreamError(this._controlledTransformStream, reason); + } + }, { + key: 'desiredSize', + get: function get() { + if (IsTransformStreamDefaultController(this) === false) { + throw defaultControllerBrandCheckException('desiredSize'); + } + + var transformStream = this._controlledTransformStream; + var readableController = transformStream._readableController; + return ReadableStreamDefaultControllerGetDesiredSize(readableController); + } + }]); + + return TransformStreamDefaultController; + }(); + + var TransformStream = function () { + function TransformStream() { + var transformer = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + + _classCallCheck(this, TransformStream); + + this._transformer = transformer; + var readableStrategy = transformer.readableStrategy, + writableStrategy = transformer.writableStrategy; + this._transforming = false; + this._errored = false; + this._storedError = undefined; + this._writableController = undefined; + this._readableController = undefined; + this._transformStreamController = undefined; + this._writableDone = false; + this._readableClosed = false; + this._backpressure = undefined; + this._backpressureChangePromise = undefined; + this._backpressureChangePromise_resolve = undefined; + this._transformStreamController = new TransformStreamDefaultController(this); + var startPromise_resolve = void 0; + var startPromise = new Promise(function (resolve) { + startPromise_resolve = resolve; + }); + var source = new TransformStreamSource(this, startPromise); + this._readable = new ReadableStream(source, readableStrategy); + var sink = new TransformStreamSink(this, startPromise); + this._writable = new WritableStream(sink, writableStrategy); + assert(this._writableController !== undefined); + assert(this._readableController !== undefined); + var desiredSize = ReadableStreamDefaultControllerGetDesiredSize(this._readableController); + TransformStreamSetBackpressure(this, desiredSize <= 0); + var transformStream = this; + var startResult = InvokeOrNoop(transformer, 'start', [transformStream._transformStreamController]); + startPromise_resolve(startResult); + startPromise.catch(function (e) { + if (transformStream._errored === false) { + transformStream._errored = true; + transformStream._storedError = e; + } + }); + } + + _createClass(TransformStream, [{ + key: 'readable', + get: function get() { + if (IsTransformStream(this) === false) { + throw streamBrandCheckException('readable'); + } + + return this._readable; + } + }, { + key: 'writable', + get: function get() { + if (IsTransformStream(this) === false) { + throw streamBrandCheckException('writable'); + } + + return this._writable; + } + }]); + + return TransformStream; + }(); + + module.exports = { + TransformStream: TransformStream + }; + + function defaultControllerBrandCheckException(name) { + return new TypeError('TransformStreamDefaultController.prototype.' + name + ' can only be used on a TransformStreamDefaultController'); + } + + function streamBrandCheckException(name) { + return new TypeError('TransformStream.prototype.' + name + ' can only be used on a TransformStream'); + } +}, function (module, exports, __w_pdfjs_require__) { + module.exports = __w_pdfjs_require__(5); +}])); + +/***/ }), +/* 6 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + { exports.URL = URL; } /***/ }), -/* 6 */ +/* 7 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -1195,25 +4956,25 @@ exports.build = exports.version = exports.PDFPageProxy = exports.PDFDocumentProx var _util = __w_pdfjs_require__(1); -var _dom_utils = __w_pdfjs_require__(7); +var _dom_utils = __w_pdfjs_require__(8); -var _font_loader = __w_pdfjs_require__(8); +var _font_loader = __w_pdfjs_require__(9); -var _api_compatibility = __w_pdfjs_require__(9); +var _api_compatibility = __w_pdfjs_require__(10); -var _canvas = __w_pdfjs_require__(10); +var _canvas = __w_pdfjs_require__(11); var _global_scope = _interopRequireDefault(__w_pdfjs_require__(3)); -var _worker_options = __w_pdfjs_require__(12); +var _worker_options = __w_pdfjs_require__(13); -var _message_handler = __w_pdfjs_require__(13); +var _message_handler = __w_pdfjs_require__(14); -var _metadata = __w_pdfjs_require__(14); +var _metadata = __w_pdfjs_require__(15); -var _transport_stream = __w_pdfjs_require__(16); +var _transport_stream = __w_pdfjs_require__(17); -var _webgl = __w_pdfjs_require__(17); +var _webgl = __w_pdfjs_require__(18); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } @@ -1393,7 +5154,7 @@ function _fetchDocument(worker, source, pdfDataRangeTransport, docId) { return worker.messageHandler.sendWithPromise('GetDocRequest', { docId, - apiVersion: '2.1.209', + apiVersion: '2.1.196', source: { data: source.data, url: source.url, @@ -3124,13 +6885,13 @@ const InternalRenderTask = function InternalRenderTaskClosure() { return InternalRenderTask; }(); -const version = '2.1.209'; +const version = '2.1.196'; exports.version = version; -const build = 'f26129de'; +const build = 'cdbc33ba'; exports.build = build; /***/ }), -/* 7 */ +/* 8 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -3527,7 +7288,7 @@ function loadScript(src) { } /***/ }), -/* 8 */ +/* 9 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -3805,7 +7566,7 @@ class FontFaceObject { exports.FontFaceObject = FontFaceObject; /***/ }), -/* 9 */ +/* 10 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -3816,7 +7577,7 @@ let compatibilityParams = Object.create(null); exports.apiCompatibilityParams = Object.freeze(compatibilityParams); /***/ }), -/* 10 */ +/* 11 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -3829,7 +7590,7 @@ exports.CanvasGraphics = void 0; var _util = __w_pdfjs_require__(1); -var _pattern_helper = __w_pdfjs_require__(11); +var _pattern_helper = __w_pdfjs_require__(12); var MIN_FONT_SIZE = 16; var MAX_FONT_SIZE = 100; @@ -5865,7 +9626,7 @@ var CanvasGraphics = function CanvasGraphicsClosure() { exports.CanvasGraphics = CanvasGraphics; /***/ }), -/* 11 */ +/* 12 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -6298,7 +10059,7 @@ var TilingPattern = function TilingPatternClosure() { exports.TilingPattern = TilingPattern; /***/ }), -/* 12 */ +/* 13 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -6314,7 +10075,7 @@ GlobalWorkerOptions.workerPort = GlobalWorkerOptions.workerPort === undefined ? GlobalWorkerOptions.workerSrc = GlobalWorkerOptions.workerSrc === undefined ? '' : GlobalWorkerOptions.workerSrc; /***/ }), -/* 13 */ +/* 14 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -6776,7 +10537,7 @@ MessageHandler.prototype = { }; /***/ }), -/* 14 */ +/* 15 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -6789,7 +10550,7 @@ exports.Metadata = void 0; var _util = __w_pdfjs_require__(1); -var _xml_parser = __w_pdfjs_require__(15); +var _xml_parser = __w_pdfjs_require__(16); class Metadata { constructor(data) { @@ -6898,7 +10659,7 @@ class Metadata { exports.Metadata = Metadata; /***/ }), -/* 15 */ +/* 16 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -7344,7 +11105,7 @@ class SimpleXMLParser extends XMLParserBase { exports.SimpleXMLParser = SimpleXMLParser; /***/ }), -/* 16 */ +/* 17 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -7648,7 +11409,7 @@ var PDFDataTransportStream = function PDFDataTransportStreamClosure() { exports.PDFDataTransportStream = PDFDataTransportStream; /***/ }), -/* 17 */ +/* 18 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -8095,7 +11856,7 @@ var WebGLUtils = function WebGLUtilsClosure() { }(); /***/ }), -/* 18 */ +/* 19 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -8768,7 +12529,7 @@ var renderTextLayer = function renderTextLayerClosure() { exports.renderTextLayer = renderTextLayer; /***/ }), -/* 19 */ +/* 20 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -8779,7 +12540,7 @@ Object.defineProperty(exports, "__esModule", { }); exports.AnnotationLayer = void 0; -var _dom_utils = __w_pdfjs_require__(7); +var _dom_utils = __w_pdfjs_require__(8); var _util = __w_pdfjs_require__(1); @@ -9727,7 +13488,7 @@ class AnnotationLayer { exports.AnnotationLayer = AnnotationLayer; /***/ }), -/* 20 */ +/* 21 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -9740,9 +13501,9 @@ exports.SVGGraphics = void 0; var _util = __w_pdfjs_require__(1); -var _dom_utils = __w_pdfjs_require__(7); +var _dom_utils = __w_pdfjs_require__(8); -var _is_node = _interopRequireDefault(__w_pdfjs_require__(21)); +var _is_node = _interopRequireDefault(__w_pdfjs_require__(22)); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } @@ -9754,7 +13515,7 @@ exports.SVGGraphics = SVGGraphics; ; /***/ }), -/* 21 */ +/* 22 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; diff --git a/browser/extensions/pdfjs/content/build/pdf.worker.js b/browser/extensions/pdfjs/content/build/pdf.worker.js index 1991c69683dd..fc2b2f4db15c 100644 --- a/browser/extensions/pdfjs/content/build/pdf.worker.js +++ b/browser/extensions/pdfjs/content/build/pdf.worker.js @@ -123,14 +123,10 @@ return /******/ (function(modules) { // webpackBootstrap "use strict"; -if (typeof ReadableStream === 'undefined') { - importScripts('./streams_polyfill.js'); -} +var pdfjsVersion = '2.1.196'; +var pdfjsBuild = 'cdbc33ba'; -const pdfjsVersion = '2.1.209'; -const pdfjsBuild = 'f26129de'; - -const pdfjsCoreWorker = __w_pdfjs_require__(1); +var pdfjsCoreWorker = __w_pdfjs_require__(1); exports.WorkerMessageHandler = pdfjsCoreWorker.WorkerMessageHandler; @@ -148,13 +144,13 @@ exports.WorkerMessageHandler = exports.WorkerTask = void 0; var _util = __w_pdfjs_require__(2); -var _pdf_manager = __w_pdfjs_require__(7); +var _pdf_manager = __w_pdfjs_require__(8); -var _is_node = _interopRequireDefault(__w_pdfjs_require__(45)); +var _is_node = _interopRequireDefault(__w_pdfjs_require__(46)); -var _message_handler = __w_pdfjs_require__(46); +var _message_handler = __w_pdfjs_require__(47); -var _primitives = __w_pdfjs_require__(11); +var _primitives = __w_pdfjs_require__(12); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } @@ -379,7 +375,7 @@ var WorkerMessageHandler = { var cancelXHRs = null; var WorkerTasks = []; let apiVersion = docParams.apiVersion; - let workerVersion = '2.1.209'; + let workerVersion = '2.1.196'; if (apiVersion !== workerVersion) { throw new Error(`The API version "${apiVersion}" does not match ` + `the Worker version "${workerVersion}".`); @@ -882,7 +878,7 @@ __w_pdfjs_require__(3); var _streams_polyfill = __w_pdfjs_require__(5); -var _url_polyfill = __w_pdfjs_require__(6); +var _url_polyfill = __w_pdfjs_require__(7); const IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0]; exports.IDENTITY_MATRIX = IDENTITY_MATRIX; @@ -1805,8 +1801,24 @@ module.exports = typeof window !== 'undefined' && window.Math === Math ? window "use strict"; -{ +let isReadableStreamSupported = false; + +if (typeof ReadableStream !== 'undefined') { + try { + new ReadableStream({ + start(controller) { + controller.close(); + } + + }); + isReadableStreamSupported = true; + } catch (e) {} +} + +if (isReadableStreamSupported) { exports.ReadableStream = ReadableStream; +} else { + exports.ReadableStream = __w_pdfjs_require__(6).ReadableStream; } /***/ }), @@ -1816,12 +1828,3757 @@ module.exports = typeof window !== 'undefined' && window.Math === Math ? window "use strict"; +(function (e, a) { + for (var i in a) e[i] = a[i]; +})(exports, function (modules) { + var installedModules = {}; + + function __w_pdfjs_require__(moduleId) { + if (installedModules[moduleId]) return installedModules[moduleId].exports; + var module = installedModules[moduleId] = { + i: moduleId, + l: false, + exports: {} + }; + modules[moduleId].call(module.exports, module, module.exports, __w_pdfjs_require__); + module.l = true; + return module.exports; + } + + __w_pdfjs_require__.m = modules; + __w_pdfjs_require__.c = installedModules; + + __w_pdfjs_require__.i = function (value) { + return value; + }; + + __w_pdfjs_require__.d = function (exports, name, getter) { + if (!__w_pdfjs_require__.o(exports, name)) { + Object.defineProperty(exports, name, { + configurable: false, + enumerable: true, + get: getter + }); + } + }; + + __w_pdfjs_require__.n = function (module) { + var getter = module && module.__esModule ? function getDefault() { + return module['default']; + } : function getModuleExports() { + return module; + }; + + __w_pdfjs_require__.d(getter, 'a', getter); + + return getter; + }; + + __w_pdfjs_require__.o = function (object, property) { + return Object.prototype.hasOwnProperty.call(object, property); + }; + + __w_pdfjs_require__.p = ""; + return __w_pdfjs_require__(__w_pdfjs_require__.s = 7); +}([function (module, exports, __w_pdfjs_require__) { + "use strict"; + + var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { + return typeof obj; + } : function (obj) { + return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; + }; + + var _require = __w_pdfjs_require__(1), + assert = _require.assert; + + function IsPropertyKey(argument) { + return typeof argument === 'string' || (typeof argument === 'undefined' ? 'undefined' : _typeof(argument)) === 'symbol'; + } + + exports.typeIsObject = function (x) { + return (typeof x === 'undefined' ? 'undefined' : _typeof(x)) === 'object' && x !== null || typeof x === 'function'; + }; + + exports.createDataProperty = function (o, p, v) { + assert(exports.typeIsObject(o)); + Object.defineProperty(o, p, { + value: v, + writable: true, + enumerable: true, + configurable: true + }); + }; + + exports.createArrayFromList = function (elements) { + return elements.slice(); + }; + + exports.ArrayBufferCopy = function (dest, destOffset, src, srcOffset, n) { + new Uint8Array(dest).set(new Uint8Array(src, srcOffset, n), destOffset); + }; + + exports.CreateIterResultObject = function (value, done) { + assert(typeof done === 'boolean'); + var obj = {}; + Object.defineProperty(obj, 'value', { + value: value, + enumerable: true, + writable: true, + configurable: true + }); + Object.defineProperty(obj, 'done', { + value: done, + enumerable: true, + writable: true, + configurable: true + }); + return obj; + }; + + exports.IsFiniteNonNegativeNumber = function (v) { + if (Number.isNaN(v)) { + return false; + } + + if (v === Infinity) { + return false; + } + + if (v < 0) { + return false; + } + + return true; + }; + + function Call(F, V, args) { + if (typeof F !== 'function') { + throw new TypeError('Argument is not a function'); + } + + return Function.prototype.apply.call(F, V, args); + } + + exports.InvokeOrNoop = function (O, P, args) { + assert(O !== undefined); + assert(IsPropertyKey(P)); + assert(Array.isArray(args)); + var method = O[P]; + + if (method === undefined) { + return undefined; + } + + return Call(method, O, args); + }; + + exports.PromiseInvokeOrNoop = function (O, P, args) { + assert(O !== undefined); + assert(IsPropertyKey(P)); + assert(Array.isArray(args)); + + try { + return Promise.resolve(exports.InvokeOrNoop(O, P, args)); + } catch (returnValueE) { + return Promise.reject(returnValueE); + } + }; + + exports.PromiseInvokeOrPerformFallback = function (O, P, args, F, argsF) { + assert(O !== undefined); + assert(IsPropertyKey(P)); + assert(Array.isArray(args)); + assert(Array.isArray(argsF)); + var method = void 0; + + try { + method = O[P]; + } catch (methodE) { + return Promise.reject(methodE); + } + + if (method === undefined) { + return F.apply(null, argsF); + } + + try { + return Promise.resolve(Call(method, O, args)); + } catch (e) { + return Promise.reject(e); + } + }; + + exports.TransferArrayBuffer = function (O) { + return O.slice(); + }; + + exports.ValidateAndNormalizeHighWaterMark = function (highWaterMark) { + highWaterMark = Number(highWaterMark); + + if (Number.isNaN(highWaterMark) || highWaterMark < 0) { + throw new RangeError('highWaterMark property of a queuing strategy must be non-negative and non-NaN'); + } + + return highWaterMark; + }; + + exports.ValidateAndNormalizeQueuingStrategy = function (size, highWaterMark) { + if (size !== undefined && typeof size !== 'function') { + throw new TypeError('size property of a queuing strategy must be a function'); + } + + highWaterMark = exports.ValidateAndNormalizeHighWaterMark(highWaterMark); + return { + size: size, + highWaterMark: highWaterMark + }; + }; +}, function (module, exports, __w_pdfjs_require__) { + "use strict"; + + function rethrowAssertionErrorRejection(e) { + if (e && e.constructor === AssertionError) { + setTimeout(function () { + throw e; + }, 0); + } + } + + function AssertionError(message) { + this.name = 'AssertionError'; + this.message = message || ''; + this.stack = new Error().stack; + } + + AssertionError.prototype = Object.create(Error.prototype); + AssertionError.prototype.constructor = AssertionError; + + function assert(value, message) { + if (!value) { + throw new AssertionError(message); + } + } + + module.exports = { + rethrowAssertionErrorRejection: rethrowAssertionErrorRejection, + AssertionError: AssertionError, + assert: assert + }; +}, function (module, exports, __w_pdfjs_require__) { + "use strict"; + + var _createClass = function () { + function defineProperties(target, props) { + for (var i = 0; i < props.length; i++) { + var descriptor = props[i]; + descriptor.enumerable = descriptor.enumerable || false; + descriptor.configurable = true; + if ("value" in descriptor) descriptor.writable = true; + Object.defineProperty(target, descriptor.key, descriptor); + } + } + + return function (Constructor, protoProps, staticProps) { + if (protoProps) defineProperties(Constructor.prototype, protoProps); + if (staticProps) defineProperties(Constructor, staticProps); + return Constructor; + }; + }(); + + function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); + } + } + + var _require = __w_pdfjs_require__(0), + InvokeOrNoop = _require.InvokeOrNoop, + PromiseInvokeOrNoop = _require.PromiseInvokeOrNoop, + ValidateAndNormalizeQueuingStrategy = _require.ValidateAndNormalizeQueuingStrategy, + typeIsObject = _require.typeIsObject; + + var _require2 = __w_pdfjs_require__(1), + assert = _require2.assert, + rethrowAssertionErrorRejection = _require2.rethrowAssertionErrorRejection; + + var _require3 = __w_pdfjs_require__(3), + DequeueValue = _require3.DequeueValue, + EnqueueValueWithSize = _require3.EnqueueValueWithSize, + PeekQueueValue = _require3.PeekQueueValue, + ResetQueue = _require3.ResetQueue; + + var WritableStream = function () { + function WritableStream() { + var underlyingSink = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + + var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, + size = _ref.size, + _ref$highWaterMark = _ref.highWaterMark, + highWaterMark = _ref$highWaterMark === undefined ? 1 : _ref$highWaterMark; + + _classCallCheck(this, WritableStream); + + this._state = 'writable'; + this._storedError = undefined; + this._writer = undefined; + this._writableStreamController = undefined; + this._writeRequests = []; + this._inFlightWriteRequest = undefined; + this._closeRequest = undefined; + this._inFlightCloseRequest = undefined; + this._pendingAbortRequest = undefined; + this._backpressure = false; + var type = underlyingSink.type; + + if (type !== undefined) { + throw new RangeError('Invalid type is specified'); + } + + this._writableStreamController = new WritableStreamDefaultController(this, underlyingSink, size, highWaterMark); + + this._writableStreamController.__startSteps(); + } + + _createClass(WritableStream, [{ + key: 'abort', + value: function abort(reason) { + if (IsWritableStream(this) === false) { + return Promise.reject(streamBrandCheckException('abort')); + } + + if (IsWritableStreamLocked(this) === true) { + return Promise.reject(new TypeError('Cannot abort a stream that already has a writer')); + } + + return WritableStreamAbort(this, reason); + } + }, { + key: 'getWriter', + value: function getWriter() { + if (IsWritableStream(this) === false) { + throw streamBrandCheckException('getWriter'); + } + + return AcquireWritableStreamDefaultWriter(this); + } + }, { + key: 'locked', + get: function get() { + if (IsWritableStream(this) === false) { + throw streamBrandCheckException('locked'); + } + + return IsWritableStreamLocked(this); + } + }]); + + return WritableStream; + }(); + + module.exports = { + AcquireWritableStreamDefaultWriter: AcquireWritableStreamDefaultWriter, + IsWritableStream: IsWritableStream, + IsWritableStreamLocked: IsWritableStreamLocked, + WritableStream: WritableStream, + WritableStreamAbort: WritableStreamAbort, + WritableStreamDefaultControllerError: WritableStreamDefaultControllerError, + WritableStreamDefaultWriterCloseWithErrorPropagation: WritableStreamDefaultWriterCloseWithErrorPropagation, + WritableStreamDefaultWriterRelease: WritableStreamDefaultWriterRelease, + WritableStreamDefaultWriterWrite: WritableStreamDefaultWriterWrite, + WritableStreamCloseQueuedOrInFlight: WritableStreamCloseQueuedOrInFlight + }; + + function AcquireWritableStreamDefaultWriter(stream) { + return new WritableStreamDefaultWriter(stream); + } + + function IsWritableStream(x) { + if (!typeIsObject(x)) { + return false; + } + + if (!Object.prototype.hasOwnProperty.call(x, '_writableStreamController')) { + return false; + } + + return true; + } + + function IsWritableStreamLocked(stream) { + assert(IsWritableStream(stream) === true, 'IsWritableStreamLocked should only be used on known writable streams'); + + if (stream._writer === undefined) { + return false; + } + + return true; + } + + function WritableStreamAbort(stream, reason) { + var state = stream._state; + + if (state === 'closed') { + return Promise.resolve(undefined); + } + + if (state === 'errored') { + return Promise.reject(stream._storedError); + } + + var error = new TypeError('Requested to abort'); + + if (stream._pendingAbortRequest !== undefined) { + return Promise.reject(error); + } + + assert(state === 'writable' || state === 'erroring', 'state must be writable or erroring'); + var wasAlreadyErroring = false; + + if (state === 'erroring') { + wasAlreadyErroring = true; + reason = undefined; + } + + var promise = new Promise(function (resolve, reject) { + stream._pendingAbortRequest = { + _resolve: resolve, + _reject: reject, + _reason: reason, + _wasAlreadyErroring: wasAlreadyErroring + }; + }); + + if (wasAlreadyErroring === false) { + WritableStreamStartErroring(stream, error); + } + + return promise; + } + + function WritableStreamAddWriteRequest(stream) { + assert(IsWritableStreamLocked(stream) === true); + assert(stream._state === 'writable'); + var promise = new Promise(function (resolve, reject) { + var writeRequest = { + _resolve: resolve, + _reject: reject + }; + + stream._writeRequests.push(writeRequest); + }); + return promise; + } + + function WritableStreamDealWithRejection(stream, error) { + var state = stream._state; + + if (state === 'writable') { + WritableStreamStartErroring(stream, error); + return; + } + + assert(state === 'erroring'); + WritableStreamFinishErroring(stream); + } + + function WritableStreamStartErroring(stream, reason) { + assert(stream._storedError === undefined, 'stream._storedError === undefined'); + assert(stream._state === 'writable', 'state must be writable'); + var controller = stream._writableStreamController; + assert(controller !== undefined, 'controller must not be undefined'); + stream._state = 'erroring'; + stream._storedError = reason; + var writer = stream._writer; + + if (writer !== undefined) { + WritableStreamDefaultWriterEnsureReadyPromiseRejected(writer, reason); + } + + if (WritableStreamHasOperationMarkedInFlight(stream) === false && controller._started === true) { + WritableStreamFinishErroring(stream); + } + } + + function WritableStreamFinishErroring(stream) { + assert(stream._state === 'erroring', 'stream._state === erroring'); + assert(WritableStreamHasOperationMarkedInFlight(stream) === false, 'WritableStreamHasOperationMarkedInFlight(stream) === false'); + stream._state = 'errored'; + + stream._writableStreamController.__errorSteps(); + + var storedError = stream._storedError; + + for (var i = 0; i < stream._writeRequests.length; i++) { + var writeRequest = stream._writeRequests[i]; + + writeRequest._reject(storedError); + } + + stream._writeRequests = []; + + if (stream._pendingAbortRequest === undefined) { + WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream); + return; + } + + var abortRequest = stream._pendingAbortRequest; + stream._pendingAbortRequest = undefined; + + if (abortRequest._wasAlreadyErroring === true) { + abortRequest._reject(storedError); + + WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream); + return; + } + + var promise = stream._writableStreamController.__abortSteps(abortRequest._reason); + + promise.then(function () { + abortRequest._resolve(); + + WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream); + }, function (reason) { + abortRequest._reject(reason); + + WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream); + }); + } + + function WritableStreamFinishInFlightWrite(stream) { + assert(stream._inFlightWriteRequest !== undefined); + + stream._inFlightWriteRequest._resolve(undefined); + + stream._inFlightWriteRequest = undefined; + } + + function WritableStreamFinishInFlightWriteWithError(stream, error) { + assert(stream._inFlightWriteRequest !== undefined); + + stream._inFlightWriteRequest._reject(error); + + stream._inFlightWriteRequest = undefined; + assert(stream._state === 'writable' || stream._state === 'erroring'); + WritableStreamDealWithRejection(stream, error); + } + + function WritableStreamFinishInFlightClose(stream) { + assert(stream._inFlightCloseRequest !== undefined); + + stream._inFlightCloseRequest._resolve(undefined); + + stream._inFlightCloseRequest = undefined; + var state = stream._state; + assert(state === 'writable' || state === 'erroring'); + + if (state === 'erroring') { + stream._storedError = undefined; + + if (stream._pendingAbortRequest !== undefined) { + stream._pendingAbortRequest._resolve(); + + stream._pendingAbortRequest = undefined; + } + } + + stream._state = 'closed'; + var writer = stream._writer; + + if (writer !== undefined) { + defaultWriterClosedPromiseResolve(writer); + } + + assert(stream._pendingAbortRequest === undefined, 'stream._pendingAbortRequest === undefined'); + assert(stream._storedError === undefined, 'stream._storedError === undefined'); + } + + function WritableStreamFinishInFlightCloseWithError(stream, error) { + assert(stream._inFlightCloseRequest !== undefined); + + stream._inFlightCloseRequest._reject(error); + + stream._inFlightCloseRequest = undefined; + assert(stream._state === 'writable' || stream._state === 'erroring'); + + if (stream._pendingAbortRequest !== undefined) { + stream._pendingAbortRequest._reject(error); + + stream._pendingAbortRequest = undefined; + } + + WritableStreamDealWithRejection(stream, error); + } + + function WritableStreamCloseQueuedOrInFlight(stream) { + if (stream._closeRequest === undefined && stream._inFlightCloseRequest === undefined) { + return false; + } + + return true; + } + + function WritableStreamHasOperationMarkedInFlight(stream) { + if (stream._inFlightWriteRequest === undefined && stream._inFlightCloseRequest === undefined) { + return false; + } + + return true; + } + + function WritableStreamMarkCloseRequestInFlight(stream) { + assert(stream._inFlightCloseRequest === undefined); + assert(stream._closeRequest !== undefined); + stream._inFlightCloseRequest = stream._closeRequest; + stream._closeRequest = undefined; + } + + function WritableStreamMarkFirstWriteRequestInFlight(stream) { + assert(stream._inFlightWriteRequest === undefined, 'there must be no pending write request'); + assert(stream._writeRequests.length !== 0, 'writeRequests must not be empty'); + stream._inFlightWriteRequest = stream._writeRequests.shift(); + } + + function WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream) { + assert(stream._state === 'errored', '_stream_.[[state]] is `"errored"`'); + + if (stream._closeRequest !== undefined) { + assert(stream._inFlightCloseRequest === undefined); + + stream._closeRequest._reject(stream._storedError); + + stream._closeRequest = undefined; + } + + var writer = stream._writer; + + if (writer !== undefined) { + defaultWriterClosedPromiseReject(writer, stream._storedError); + + writer._closedPromise.catch(function () {}); + } + } + + function WritableStreamUpdateBackpressure(stream, backpressure) { + assert(stream._state === 'writable'); + assert(WritableStreamCloseQueuedOrInFlight(stream) === false); + var writer = stream._writer; + + if (writer !== undefined && backpressure !== stream._backpressure) { + if (backpressure === true) { + defaultWriterReadyPromiseReset(writer); + } else { + assert(backpressure === false); + defaultWriterReadyPromiseResolve(writer); + } + } + + stream._backpressure = backpressure; + } + + var WritableStreamDefaultWriter = function () { + function WritableStreamDefaultWriter(stream) { + _classCallCheck(this, WritableStreamDefaultWriter); + + if (IsWritableStream(stream) === false) { + throw new TypeError('WritableStreamDefaultWriter can only be constructed with a WritableStream instance'); + } + + if (IsWritableStreamLocked(stream) === true) { + throw new TypeError('This stream has already been locked for exclusive writing by another writer'); + } + + this._ownerWritableStream = stream; + stream._writer = this; + var state = stream._state; + + if (state === 'writable') { + if (WritableStreamCloseQueuedOrInFlight(stream) === false && stream._backpressure === true) { + defaultWriterReadyPromiseInitialize(this); + } else { + defaultWriterReadyPromiseInitializeAsResolved(this); + } + + defaultWriterClosedPromiseInitialize(this); + } else if (state === 'erroring') { + defaultWriterReadyPromiseInitializeAsRejected(this, stream._storedError); + + this._readyPromise.catch(function () {}); + + defaultWriterClosedPromiseInitialize(this); + } else if (state === 'closed') { + defaultWriterReadyPromiseInitializeAsResolved(this); + defaultWriterClosedPromiseInitializeAsResolved(this); + } else { + assert(state === 'errored', 'state must be errored'); + var storedError = stream._storedError; + defaultWriterReadyPromiseInitializeAsRejected(this, storedError); + + this._readyPromise.catch(function () {}); + + defaultWriterClosedPromiseInitializeAsRejected(this, storedError); + + this._closedPromise.catch(function () {}); + } + } + + _createClass(WritableStreamDefaultWriter, [{ + key: 'abort', + value: function abort(reason) { + if (IsWritableStreamDefaultWriter(this) === false) { + return Promise.reject(defaultWriterBrandCheckException('abort')); + } + + if (this._ownerWritableStream === undefined) { + return Promise.reject(defaultWriterLockException('abort')); + } + + return WritableStreamDefaultWriterAbort(this, reason); + } + }, { + key: 'close', + value: function close() { + if (IsWritableStreamDefaultWriter(this) === false) { + return Promise.reject(defaultWriterBrandCheckException('close')); + } + + var stream = this._ownerWritableStream; + + if (stream === undefined) { + return Promise.reject(defaultWriterLockException('close')); + } + + if (WritableStreamCloseQueuedOrInFlight(stream) === true) { + return Promise.reject(new TypeError('cannot close an already-closing stream')); + } + + return WritableStreamDefaultWriterClose(this); + } + }, { + key: 'releaseLock', + value: function releaseLock() { + if (IsWritableStreamDefaultWriter(this) === false) { + throw defaultWriterBrandCheckException('releaseLock'); + } + + var stream = this._ownerWritableStream; + + if (stream === undefined) { + return; + } + + assert(stream._writer !== undefined); + WritableStreamDefaultWriterRelease(this); + } + }, { + key: 'write', + value: function write(chunk) { + if (IsWritableStreamDefaultWriter(this) === false) { + return Promise.reject(defaultWriterBrandCheckException('write')); + } + + if (this._ownerWritableStream === undefined) { + return Promise.reject(defaultWriterLockException('write to')); + } + + return WritableStreamDefaultWriterWrite(this, chunk); + } + }, { + key: 'closed', + get: function get() { + if (IsWritableStreamDefaultWriter(this) === false) { + return Promise.reject(defaultWriterBrandCheckException('closed')); + } + + return this._closedPromise; + } + }, { + key: 'desiredSize', + get: function get() { + if (IsWritableStreamDefaultWriter(this) === false) { + throw defaultWriterBrandCheckException('desiredSize'); + } + + if (this._ownerWritableStream === undefined) { + throw defaultWriterLockException('desiredSize'); + } + + return WritableStreamDefaultWriterGetDesiredSize(this); + } + }, { + key: 'ready', + get: function get() { + if (IsWritableStreamDefaultWriter(this) === false) { + return Promise.reject(defaultWriterBrandCheckException('ready')); + } + + return this._readyPromise; + } + }]); + + return WritableStreamDefaultWriter; + }(); + + function IsWritableStreamDefaultWriter(x) { + if (!typeIsObject(x)) { + return false; + } + + if (!Object.prototype.hasOwnProperty.call(x, '_ownerWritableStream')) { + return false; + } + + return true; + } + + function WritableStreamDefaultWriterAbort(writer, reason) { + var stream = writer._ownerWritableStream; + assert(stream !== undefined); + return WritableStreamAbort(stream, reason); + } + + function WritableStreamDefaultWriterClose(writer) { + var stream = writer._ownerWritableStream; + assert(stream !== undefined); + var state = stream._state; + + if (state === 'closed' || state === 'errored') { + return Promise.reject(new TypeError('The stream (in ' + state + ' state) is not in the writable state and cannot be closed')); + } + + assert(state === 'writable' || state === 'erroring'); + assert(WritableStreamCloseQueuedOrInFlight(stream) === false); + var promise = new Promise(function (resolve, reject) { + var closeRequest = { + _resolve: resolve, + _reject: reject + }; + stream._closeRequest = closeRequest; + }); + + if (stream._backpressure === true && state === 'writable') { + defaultWriterReadyPromiseResolve(writer); + } + + WritableStreamDefaultControllerClose(stream._writableStreamController); + return promise; + } + + function WritableStreamDefaultWriterCloseWithErrorPropagation(writer) { + var stream = writer._ownerWritableStream; + assert(stream !== undefined); + var state = stream._state; + + if (WritableStreamCloseQueuedOrInFlight(stream) === true || state === 'closed') { + return Promise.resolve(); + } + + if (state === 'errored') { + return Promise.reject(stream._storedError); + } + + assert(state === 'writable' || state === 'erroring'); + return WritableStreamDefaultWriterClose(writer); + } + + function WritableStreamDefaultWriterEnsureClosedPromiseRejected(writer, error) { + if (writer._closedPromiseState === 'pending') { + defaultWriterClosedPromiseReject(writer, error); + } else { + defaultWriterClosedPromiseResetToRejected(writer, error); + } + + writer._closedPromise.catch(function () {}); + } + + function WritableStreamDefaultWriterEnsureReadyPromiseRejected(writer, error) { + if (writer._readyPromiseState === 'pending') { + defaultWriterReadyPromiseReject(writer, error); + } else { + defaultWriterReadyPromiseResetToRejected(writer, error); + } + + writer._readyPromise.catch(function () {}); + } + + function WritableStreamDefaultWriterGetDesiredSize(writer) { + var stream = writer._ownerWritableStream; + var state = stream._state; + + if (state === 'errored' || state === 'erroring') { + return null; + } + + if (state === 'closed') { + return 0; + } + + return WritableStreamDefaultControllerGetDesiredSize(stream._writableStreamController); + } + + function WritableStreamDefaultWriterRelease(writer) { + var stream = writer._ownerWritableStream; + assert(stream !== undefined); + assert(stream._writer === writer); + var releasedError = new TypeError('Writer was released and can no longer be used to monitor the stream\'s closedness'); + WritableStreamDefaultWriterEnsureReadyPromiseRejected(writer, releasedError); + WritableStreamDefaultWriterEnsureClosedPromiseRejected(writer, releasedError); + stream._writer = undefined; + writer._ownerWritableStream = undefined; + } + + function WritableStreamDefaultWriterWrite(writer, chunk) { + var stream = writer._ownerWritableStream; + assert(stream !== undefined); + var controller = stream._writableStreamController; + var chunkSize = WritableStreamDefaultControllerGetChunkSize(controller, chunk); + + if (stream !== writer._ownerWritableStream) { + return Promise.reject(defaultWriterLockException('write to')); + } + + var state = stream._state; + + if (state === 'errored') { + return Promise.reject(stream._storedError); + } + + if (WritableStreamCloseQueuedOrInFlight(stream) === true || state === 'closed') { + return Promise.reject(new TypeError('The stream is closing or closed and cannot be written to')); + } + + if (state === 'erroring') { + return Promise.reject(stream._storedError); + } + + assert(state === 'writable'); + var promise = WritableStreamAddWriteRequest(stream); + WritableStreamDefaultControllerWrite(controller, chunk, chunkSize); + return promise; + } + + var WritableStreamDefaultController = function () { + function WritableStreamDefaultController(stream, underlyingSink, size, highWaterMark) { + _classCallCheck(this, WritableStreamDefaultController); + + if (IsWritableStream(stream) === false) { + throw new TypeError('WritableStreamDefaultController can only be constructed with a WritableStream instance'); + } + + if (stream._writableStreamController !== undefined) { + throw new TypeError('WritableStreamDefaultController instances can only be created by the WritableStream constructor'); + } + + this._controlledWritableStream = stream; + this._underlyingSink = underlyingSink; + this._queue = undefined; + this._queueTotalSize = undefined; + ResetQueue(this); + this._started = false; + var normalizedStrategy = ValidateAndNormalizeQueuingStrategy(size, highWaterMark); + this._strategySize = normalizedStrategy.size; + this._strategyHWM = normalizedStrategy.highWaterMark; + var backpressure = WritableStreamDefaultControllerGetBackpressure(this); + WritableStreamUpdateBackpressure(stream, backpressure); + } + + _createClass(WritableStreamDefaultController, [{ + key: 'error', + value: function error(e) { + if (IsWritableStreamDefaultController(this) === false) { + throw new TypeError('WritableStreamDefaultController.prototype.error can only be used on a WritableStreamDefaultController'); + } + + var state = this._controlledWritableStream._state; + + if (state !== 'writable') { + return; + } + + WritableStreamDefaultControllerError(this, e); + } + }, { + key: '__abortSteps', + value: function __abortSteps(reason) { + return PromiseInvokeOrNoop(this._underlyingSink, 'abort', [reason]); + } + }, { + key: '__errorSteps', + value: function __errorSteps() { + ResetQueue(this); + } + }, { + key: '__startSteps', + value: function __startSteps() { + var _this = this; + + var startResult = InvokeOrNoop(this._underlyingSink, 'start', [this]); + var stream = this._controlledWritableStream; + Promise.resolve(startResult).then(function () { + assert(stream._state === 'writable' || stream._state === 'erroring'); + _this._started = true; + WritableStreamDefaultControllerAdvanceQueueIfNeeded(_this); + }, function (r) { + assert(stream._state === 'writable' || stream._state === 'erroring'); + _this._started = true; + WritableStreamDealWithRejection(stream, r); + }).catch(rethrowAssertionErrorRejection); + } + }]); + + return WritableStreamDefaultController; + }(); + + function WritableStreamDefaultControllerClose(controller) { + EnqueueValueWithSize(controller, 'close', 0); + WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller); + } + + function WritableStreamDefaultControllerGetChunkSize(controller, chunk) { + var strategySize = controller._strategySize; + + if (strategySize === undefined) { + return 1; + } + + try { + return strategySize(chunk); + } catch (chunkSizeE) { + WritableStreamDefaultControllerErrorIfNeeded(controller, chunkSizeE); + return 1; + } + } + + function WritableStreamDefaultControllerGetDesiredSize(controller) { + return controller._strategyHWM - controller._queueTotalSize; + } + + function WritableStreamDefaultControllerWrite(controller, chunk, chunkSize) { + var writeRecord = { + chunk: chunk + }; + + try { + EnqueueValueWithSize(controller, writeRecord, chunkSize); + } catch (enqueueE) { + WritableStreamDefaultControllerErrorIfNeeded(controller, enqueueE); + return; + } + + var stream = controller._controlledWritableStream; + + if (WritableStreamCloseQueuedOrInFlight(stream) === false && stream._state === 'writable') { + var backpressure = WritableStreamDefaultControllerGetBackpressure(controller); + WritableStreamUpdateBackpressure(stream, backpressure); + } + + WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller); + } + + function IsWritableStreamDefaultController(x) { + if (!typeIsObject(x)) { + return false; + } + + if (!Object.prototype.hasOwnProperty.call(x, '_underlyingSink')) { + return false; + } + + return true; + } + + function WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller) { + var stream = controller._controlledWritableStream; + + if (controller._started === false) { + return; + } + + if (stream._inFlightWriteRequest !== undefined) { + return; + } + + var state = stream._state; + + if (state === 'closed' || state === 'errored') { + return; + } + + if (state === 'erroring') { + WritableStreamFinishErroring(stream); + return; + } + + if (controller._queue.length === 0) { + return; + } + + var writeRecord = PeekQueueValue(controller); + + if (writeRecord === 'close') { + WritableStreamDefaultControllerProcessClose(controller); + } else { + WritableStreamDefaultControllerProcessWrite(controller, writeRecord.chunk); + } + } + + function WritableStreamDefaultControllerErrorIfNeeded(controller, error) { + if (controller._controlledWritableStream._state === 'writable') { + WritableStreamDefaultControllerError(controller, error); + } + } + + function WritableStreamDefaultControllerProcessClose(controller) { + var stream = controller._controlledWritableStream; + WritableStreamMarkCloseRequestInFlight(stream); + DequeueValue(controller); + assert(controller._queue.length === 0, 'queue must be empty once the final write record is dequeued'); + var sinkClosePromise = PromiseInvokeOrNoop(controller._underlyingSink, 'close', []); + sinkClosePromise.then(function () { + WritableStreamFinishInFlightClose(stream); + }, function (reason) { + WritableStreamFinishInFlightCloseWithError(stream, reason); + }).catch(rethrowAssertionErrorRejection); + } + + function WritableStreamDefaultControllerProcessWrite(controller, chunk) { + var stream = controller._controlledWritableStream; + WritableStreamMarkFirstWriteRequestInFlight(stream); + var sinkWritePromise = PromiseInvokeOrNoop(controller._underlyingSink, 'write', [chunk, controller]); + sinkWritePromise.then(function () { + WritableStreamFinishInFlightWrite(stream); + var state = stream._state; + assert(state === 'writable' || state === 'erroring'); + DequeueValue(controller); + + if (WritableStreamCloseQueuedOrInFlight(stream) === false && state === 'writable') { + var backpressure = WritableStreamDefaultControllerGetBackpressure(controller); + WritableStreamUpdateBackpressure(stream, backpressure); + } + + WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller); + }, function (reason) { + WritableStreamFinishInFlightWriteWithError(stream, reason); + }).catch(rethrowAssertionErrorRejection); + } + + function WritableStreamDefaultControllerGetBackpressure(controller) { + var desiredSize = WritableStreamDefaultControllerGetDesiredSize(controller); + return desiredSize <= 0; + } + + function WritableStreamDefaultControllerError(controller, error) { + var stream = controller._controlledWritableStream; + assert(stream._state === 'writable'); + WritableStreamStartErroring(stream, error); + } + + function streamBrandCheckException(name) { + return new TypeError('WritableStream.prototype.' + name + ' can only be used on a WritableStream'); + } + + function defaultWriterBrandCheckException(name) { + return new TypeError('WritableStreamDefaultWriter.prototype.' + name + ' can only be used on a WritableStreamDefaultWriter'); + } + + function defaultWriterLockException(name) { + return new TypeError('Cannot ' + name + ' a stream using a released writer'); + } + + function defaultWriterClosedPromiseInitialize(writer) { + writer._closedPromise = new Promise(function (resolve, reject) { + writer._closedPromise_resolve = resolve; + writer._closedPromise_reject = reject; + writer._closedPromiseState = 'pending'; + }); + } + + function defaultWriterClosedPromiseInitializeAsRejected(writer, reason) { + writer._closedPromise = Promise.reject(reason); + writer._closedPromise_resolve = undefined; + writer._closedPromise_reject = undefined; + writer._closedPromiseState = 'rejected'; + } + + function defaultWriterClosedPromiseInitializeAsResolved(writer) { + writer._closedPromise = Promise.resolve(undefined); + writer._closedPromise_resolve = undefined; + writer._closedPromise_reject = undefined; + writer._closedPromiseState = 'resolved'; + } + + function defaultWriterClosedPromiseReject(writer, reason) { + assert(writer._closedPromise_resolve !== undefined, 'writer._closedPromise_resolve !== undefined'); + assert(writer._closedPromise_reject !== undefined, 'writer._closedPromise_reject !== undefined'); + assert(writer._closedPromiseState === 'pending', 'writer._closedPromiseState is pending'); + + writer._closedPromise_reject(reason); + + writer._closedPromise_resolve = undefined; + writer._closedPromise_reject = undefined; + writer._closedPromiseState = 'rejected'; + } + + function defaultWriterClosedPromiseResetToRejected(writer, reason) { + assert(writer._closedPromise_resolve === undefined, 'writer._closedPromise_resolve === undefined'); + assert(writer._closedPromise_reject === undefined, 'writer._closedPromise_reject === undefined'); + assert(writer._closedPromiseState !== 'pending', 'writer._closedPromiseState is not pending'); + writer._closedPromise = Promise.reject(reason); + writer._closedPromiseState = 'rejected'; + } + + function defaultWriterClosedPromiseResolve(writer) { + assert(writer._closedPromise_resolve !== undefined, 'writer._closedPromise_resolve !== undefined'); + assert(writer._closedPromise_reject !== undefined, 'writer._closedPromise_reject !== undefined'); + assert(writer._closedPromiseState === 'pending', 'writer._closedPromiseState is pending'); + + writer._closedPromise_resolve(undefined); + + writer._closedPromise_resolve = undefined; + writer._closedPromise_reject = undefined; + writer._closedPromiseState = 'resolved'; + } + + function defaultWriterReadyPromiseInitialize(writer) { + writer._readyPromise = new Promise(function (resolve, reject) { + writer._readyPromise_resolve = resolve; + writer._readyPromise_reject = reject; + }); + writer._readyPromiseState = 'pending'; + } + + function defaultWriterReadyPromiseInitializeAsRejected(writer, reason) { + writer._readyPromise = Promise.reject(reason); + writer._readyPromise_resolve = undefined; + writer._readyPromise_reject = undefined; + writer._readyPromiseState = 'rejected'; + } + + function defaultWriterReadyPromiseInitializeAsResolved(writer) { + writer._readyPromise = Promise.resolve(undefined); + writer._readyPromise_resolve = undefined; + writer._readyPromise_reject = undefined; + writer._readyPromiseState = 'fulfilled'; + } + + function defaultWriterReadyPromiseReject(writer, reason) { + assert(writer._readyPromise_resolve !== undefined, 'writer._readyPromise_resolve !== undefined'); + assert(writer._readyPromise_reject !== undefined, 'writer._readyPromise_reject !== undefined'); + + writer._readyPromise_reject(reason); + + writer._readyPromise_resolve = undefined; + writer._readyPromise_reject = undefined; + writer._readyPromiseState = 'rejected'; + } + + function defaultWriterReadyPromiseReset(writer) { + assert(writer._readyPromise_resolve === undefined, 'writer._readyPromise_resolve === undefined'); + assert(writer._readyPromise_reject === undefined, 'writer._readyPromise_reject === undefined'); + writer._readyPromise = new Promise(function (resolve, reject) { + writer._readyPromise_resolve = resolve; + writer._readyPromise_reject = reject; + }); + writer._readyPromiseState = 'pending'; + } + + function defaultWriterReadyPromiseResetToRejected(writer, reason) { + assert(writer._readyPromise_resolve === undefined, 'writer._readyPromise_resolve === undefined'); + assert(writer._readyPromise_reject === undefined, 'writer._readyPromise_reject === undefined'); + writer._readyPromise = Promise.reject(reason); + writer._readyPromiseState = 'rejected'; + } + + function defaultWriterReadyPromiseResolve(writer) { + assert(writer._readyPromise_resolve !== undefined, 'writer._readyPromise_resolve !== undefined'); + assert(writer._readyPromise_reject !== undefined, 'writer._readyPromise_reject !== undefined'); + + writer._readyPromise_resolve(undefined); + + writer._readyPromise_resolve = undefined; + writer._readyPromise_reject = undefined; + writer._readyPromiseState = 'fulfilled'; + } +}, function (module, exports, __w_pdfjs_require__) { + "use strict"; + + var _require = __w_pdfjs_require__(0), + IsFiniteNonNegativeNumber = _require.IsFiniteNonNegativeNumber; + + var _require2 = __w_pdfjs_require__(1), + assert = _require2.assert; + + exports.DequeueValue = function (container) { + assert('_queue' in container && '_queueTotalSize' in container, 'Spec-level failure: DequeueValue should only be used on containers with [[queue]] and [[queueTotalSize]].'); + assert(container._queue.length > 0, 'Spec-level failure: should never dequeue from an empty queue.'); + + var pair = container._queue.shift(); + + container._queueTotalSize -= pair.size; + + if (container._queueTotalSize < 0) { + container._queueTotalSize = 0; + } + + return pair.value; + }; + + exports.EnqueueValueWithSize = function (container, value, size) { + assert('_queue' in container && '_queueTotalSize' in container, 'Spec-level failure: EnqueueValueWithSize should only be used on containers with [[queue]] and ' + '[[queueTotalSize]].'); + size = Number(size); + + if (!IsFiniteNonNegativeNumber(size)) { + throw new RangeError('Size must be a finite, non-NaN, non-negative number.'); + } + + container._queue.push({ + value: value, + size: size + }); + + container._queueTotalSize += size; + }; + + exports.PeekQueueValue = function (container) { + assert('_queue' in container && '_queueTotalSize' in container, 'Spec-level failure: PeekQueueValue should only be used on containers with [[queue]] and [[queueTotalSize]].'); + assert(container._queue.length > 0, 'Spec-level failure: should never peek at an empty queue.'); + var pair = container._queue[0]; + return pair.value; + }; + + exports.ResetQueue = function (container) { + assert('_queue' in container && '_queueTotalSize' in container, 'Spec-level failure: ResetQueue should only be used on containers with [[queue]] and [[queueTotalSize]].'); + container._queue = []; + container._queueTotalSize = 0; + }; +}, function (module, exports, __w_pdfjs_require__) { + "use strict"; + + var _createClass = function () { + function defineProperties(target, props) { + for (var i = 0; i < props.length; i++) { + var descriptor = props[i]; + descriptor.enumerable = descriptor.enumerable || false; + descriptor.configurable = true; + if ("value" in descriptor) descriptor.writable = true; + Object.defineProperty(target, descriptor.key, descriptor); + } + } + + return function (Constructor, protoProps, staticProps) { + if (protoProps) defineProperties(Constructor.prototype, protoProps); + if (staticProps) defineProperties(Constructor, staticProps); + return Constructor; + }; + }(); + + function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); + } + } + + var _require = __w_pdfjs_require__(0), + ArrayBufferCopy = _require.ArrayBufferCopy, + CreateIterResultObject = _require.CreateIterResultObject, + IsFiniteNonNegativeNumber = _require.IsFiniteNonNegativeNumber, + InvokeOrNoop = _require.InvokeOrNoop, + PromiseInvokeOrNoop = _require.PromiseInvokeOrNoop, + TransferArrayBuffer = _require.TransferArrayBuffer, + ValidateAndNormalizeQueuingStrategy = _require.ValidateAndNormalizeQueuingStrategy, + ValidateAndNormalizeHighWaterMark = _require.ValidateAndNormalizeHighWaterMark; + + var _require2 = __w_pdfjs_require__(0), + createArrayFromList = _require2.createArrayFromList, + createDataProperty = _require2.createDataProperty, + typeIsObject = _require2.typeIsObject; + + var _require3 = __w_pdfjs_require__(1), + assert = _require3.assert, + rethrowAssertionErrorRejection = _require3.rethrowAssertionErrorRejection; + + var _require4 = __w_pdfjs_require__(3), + DequeueValue = _require4.DequeueValue, + EnqueueValueWithSize = _require4.EnqueueValueWithSize, + ResetQueue = _require4.ResetQueue; + + var _require5 = __w_pdfjs_require__(2), + AcquireWritableStreamDefaultWriter = _require5.AcquireWritableStreamDefaultWriter, + IsWritableStream = _require5.IsWritableStream, + IsWritableStreamLocked = _require5.IsWritableStreamLocked, + WritableStreamAbort = _require5.WritableStreamAbort, + WritableStreamDefaultWriterCloseWithErrorPropagation = _require5.WritableStreamDefaultWriterCloseWithErrorPropagation, + WritableStreamDefaultWriterRelease = _require5.WritableStreamDefaultWriterRelease, + WritableStreamDefaultWriterWrite = _require5.WritableStreamDefaultWriterWrite, + WritableStreamCloseQueuedOrInFlight = _require5.WritableStreamCloseQueuedOrInFlight; + + var ReadableStream = function () { + function ReadableStream() { + var underlyingSource = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + + var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, + size = _ref.size, + highWaterMark = _ref.highWaterMark; + + _classCallCheck(this, ReadableStream); + + this._state = 'readable'; + this._reader = undefined; + this._storedError = undefined; + this._disturbed = false; + this._readableStreamController = undefined; + var type = underlyingSource.type; + var typeString = String(type); + + if (typeString === 'bytes') { + if (highWaterMark === undefined) { + highWaterMark = 0; + } + + this._readableStreamController = new ReadableByteStreamController(this, underlyingSource, highWaterMark); + } else if (type === undefined) { + if (highWaterMark === undefined) { + highWaterMark = 1; + } + + this._readableStreamController = new ReadableStreamDefaultController(this, underlyingSource, size, highWaterMark); + } else { + throw new RangeError('Invalid type is specified'); + } + } + + _createClass(ReadableStream, [{ + key: 'cancel', + value: function cancel(reason) { + if (IsReadableStream(this) === false) { + return Promise.reject(streamBrandCheckException('cancel')); + } + + if (IsReadableStreamLocked(this) === true) { + return Promise.reject(new TypeError('Cannot cancel a stream that already has a reader')); + } + + return ReadableStreamCancel(this, reason); + } + }, { + key: 'getReader', + value: function getReader() { + var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, + mode = _ref2.mode; + + if (IsReadableStream(this) === false) { + throw streamBrandCheckException('getReader'); + } + + if (mode === undefined) { + return AcquireReadableStreamDefaultReader(this); + } + + mode = String(mode); + + if (mode === 'byob') { + return AcquireReadableStreamBYOBReader(this); + } + + throw new RangeError('Invalid mode is specified'); + } + }, { + key: 'pipeThrough', + value: function pipeThrough(_ref3, options) { + var writable = _ref3.writable, + readable = _ref3.readable; + var promise = this.pipeTo(writable, options); + ifIsObjectAndHasAPromiseIsHandledInternalSlotSetPromiseIsHandledToTrue(promise); + return readable; + } + }, { + key: 'pipeTo', + value: function pipeTo(dest) { + var _this = this; + + var _ref4 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, + preventClose = _ref4.preventClose, + preventAbort = _ref4.preventAbort, + preventCancel = _ref4.preventCancel; + + if (IsReadableStream(this) === false) { + return Promise.reject(streamBrandCheckException('pipeTo')); + } + + if (IsWritableStream(dest) === false) { + return Promise.reject(new TypeError('ReadableStream.prototype.pipeTo\'s first argument must be a WritableStream')); + } + + preventClose = Boolean(preventClose); + preventAbort = Boolean(preventAbort); + preventCancel = Boolean(preventCancel); + + if (IsReadableStreamLocked(this) === true) { + return Promise.reject(new TypeError('ReadableStream.prototype.pipeTo cannot be used on a locked ReadableStream')); + } + + if (IsWritableStreamLocked(dest) === true) { + return Promise.reject(new TypeError('ReadableStream.prototype.pipeTo cannot be used on a locked WritableStream')); + } + + var reader = AcquireReadableStreamDefaultReader(this); + var writer = AcquireWritableStreamDefaultWriter(dest); + var shuttingDown = false; + var currentWrite = Promise.resolve(); + return new Promise(function (resolve, reject) { + function pipeLoop() { + currentWrite = Promise.resolve(); + + if (shuttingDown === true) { + return Promise.resolve(); + } + + return writer._readyPromise.then(function () { + return ReadableStreamDefaultReaderRead(reader).then(function (_ref5) { + var value = _ref5.value, + done = _ref5.done; + + if (done === true) { + return; + } + + currentWrite = WritableStreamDefaultWriterWrite(writer, value).catch(function () {}); + }); + }).then(pipeLoop); + } + + isOrBecomesErrored(_this, reader._closedPromise, function (storedError) { + if (preventAbort === false) { + shutdownWithAction(function () { + return WritableStreamAbort(dest, storedError); + }, true, storedError); + } else { + shutdown(true, storedError); + } + }); + isOrBecomesErrored(dest, writer._closedPromise, function (storedError) { + if (preventCancel === false) { + shutdownWithAction(function () { + return ReadableStreamCancel(_this, storedError); + }, true, storedError); + } else { + shutdown(true, storedError); + } + }); + isOrBecomesClosed(_this, reader._closedPromise, function () { + 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) { + var shouldPull = ReadableByteStreamControllerShouldCallPull(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._underlyingByteSource, 'pull', [controller]); + pullPromise.then(function () { + controller._pulling = false; + + if (controller._pullAgain === true) { + controller._pullAgain = false; + ReadableByteStreamControllerCallPullIfNeeded(controller); + } + }, function (e) { + if (controller._controlledReadableStream._state === 'readable') { + ReadableByteStreamControllerError(controller, e); + } + }).catch(rethrowAssertionErrorRejection); + return undefined; + } + + function ReadableByteStreamControllerClearPendingPullIntos(controller) { + ReadableByteStreamControllerInvalidateBYOBRequest(controller); + controller._pendingPullIntos = []; + } + + function ReadableByteStreamControllerCommitPullIntoDescriptor(stream, pullIntoDescriptor) { + assert(stream._state !== 'errored', 'state must not be errored'); + var done = false; + + if (stream._state === 'closed') { + assert(pullIntoDescriptor.bytesFilled === 0); + done = true; + } + + var filledView = ReadableByteStreamControllerConvertPullIntoDescriptor(pullIntoDescriptor); + + if (pullIntoDescriptor.readerType === 'default') { + ReadableStreamFulfillReadRequest(stream, filledView, done); + } else { + assert(pullIntoDescriptor.readerType === 'byob'); + ReadableStreamFulfillReadIntoRequest(stream, filledView, done); + } + } + + function ReadableByteStreamControllerConvertPullIntoDescriptor(pullIntoDescriptor) { + var bytesFilled = pullIntoDescriptor.bytesFilled; + var elementSize = pullIntoDescriptor.elementSize; + assert(bytesFilled <= pullIntoDescriptor.byteLength); + assert(bytesFilled % elementSize === 0); + return new pullIntoDescriptor.ctor(pullIntoDescriptor.buffer, pullIntoDescriptor.byteOffset, bytesFilled / elementSize); + } + + function ReadableByteStreamControllerEnqueueChunkToQueue(controller, buffer, byteOffset, byteLength) { + controller._queue.push({ + buffer: buffer, + byteOffset: byteOffset, + byteLength: byteLength + }); + + controller._queueTotalSize += byteLength; + } + + function ReadableByteStreamControllerFillPullIntoDescriptorFromQueue(controller, pullIntoDescriptor) { + var elementSize = pullIntoDescriptor.elementSize; + var currentAlignedBytes = pullIntoDescriptor.bytesFilled - pullIntoDescriptor.bytesFilled % elementSize; + var maxBytesToCopy = Math.min(controller._queueTotalSize, pullIntoDescriptor.byteLength - pullIntoDescriptor.bytesFilled); + var maxBytesFilled = pullIntoDescriptor.bytesFilled + maxBytesToCopy; + var maxAlignedBytes = maxBytesFilled - maxBytesFilled % elementSize; + var totalBytesToCopyRemaining = maxBytesToCopy; + var ready = false; + + if (maxAlignedBytes > currentAlignedBytes) { + totalBytesToCopyRemaining = maxAlignedBytes - pullIntoDescriptor.bytesFilled; + ready = true; + } + + var queue = controller._queue; + + while (totalBytesToCopyRemaining > 0) { + var headOfQueue = queue[0]; + var bytesToCopy = Math.min(totalBytesToCopyRemaining, headOfQueue.byteLength); + var destStart = pullIntoDescriptor.byteOffset + pullIntoDescriptor.bytesFilled; + ArrayBufferCopy(pullIntoDescriptor.buffer, destStart, headOfQueue.buffer, headOfQueue.byteOffset, bytesToCopy); + + if (headOfQueue.byteLength === bytesToCopy) { + queue.shift(); + } else { + headOfQueue.byteOffset += bytesToCopy; + headOfQueue.byteLength -= bytesToCopy; + } + + controller._queueTotalSize -= bytesToCopy; + ReadableByteStreamControllerFillHeadPullIntoDescriptor(controller, bytesToCopy, pullIntoDescriptor); + totalBytesToCopyRemaining -= bytesToCopy; + } + + if (ready === false) { + assert(controller._queueTotalSize === 0, 'queue must be empty'); + assert(pullIntoDescriptor.bytesFilled > 0); + assert(pullIntoDescriptor.bytesFilled < pullIntoDescriptor.elementSize); + } + + return ready; + } + + function ReadableByteStreamControllerFillHeadPullIntoDescriptor(controller, size, pullIntoDescriptor) { + assert(controller._pendingPullIntos.length === 0 || controller._pendingPullIntos[0] === pullIntoDescriptor); + ReadableByteStreamControllerInvalidateBYOBRequest(controller); + pullIntoDescriptor.bytesFilled += size; + } + + function ReadableByteStreamControllerHandleQueueDrain(controller) { + assert(controller._controlledReadableStream._state === 'readable'); + + if (controller._queueTotalSize === 0 && controller._closeRequested === true) { + ReadableStreamClose(controller._controlledReadableStream); + } else { + ReadableByteStreamControllerCallPullIfNeeded(controller); + } + } + + function ReadableByteStreamControllerInvalidateBYOBRequest(controller) { + if (controller._byobRequest === undefined) { + return; + } + + controller._byobRequest._associatedReadableByteStreamController = undefined; + controller._byobRequest._view = undefined; + controller._byobRequest = undefined; + } + + function ReadableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(controller) { + assert(controller._closeRequested === false); + + while (controller._pendingPullIntos.length > 0) { + if (controller._queueTotalSize === 0) { + return; + } + + var pullIntoDescriptor = controller._pendingPullIntos[0]; + + if (ReadableByteStreamControllerFillPullIntoDescriptorFromQueue(controller, pullIntoDescriptor) === true) { + ReadableByteStreamControllerShiftPendingPullInto(controller); + ReadableByteStreamControllerCommitPullIntoDescriptor(controller._controlledReadableStream, pullIntoDescriptor); + } + } + } + + function ReadableByteStreamControllerPullInto(controller, view) { + var stream = controller._controlledReadableStream; + var elementSize = 1; + + if (view.constructor !== DataView) { + elementSize = view.constructor.BYTES_PER_ELEMENT; + } + + var ctor = view.constructor; + var pullIntoDescriptor = { + buffer: view.buffer, + byteOffset: view.byteOffset, + byteLength: view.byteLength, + bytesFilled: 0, + elementSize: elementSize, + ctor: ctor, + readerType: 'byob' + }; + + if (controller._pendingPullIntos.length > 0) { + pullIntoDescriptor.buffer = TransferArrayBuffer(pullIntoDescriptor.buffer); + + controller._pendingPullIntos.push(pullIntoDescriptor); + + return ReadableStreamAddReadIntoRequest(stream); + } + + if (stream._state === 'closed') { + var emptyView = new view.constructor(pullIntoDescriptor.buffer, pullIntoDescriptor.byteOffset, 0); + return Promise.resolve(CreateIterResultObject(emptyView, true)); + } + + if (controller._queueTotalSize > 0) { + if (ReadableByteStreamControllerFillPullIntoDescriptorFromQueue(controller, pullIntoDescriptor) === true) { + var filledView = ReadableByteStreamControllerConvertPullIntoDescriptor(pullIntoDescriptor); + ReadableByteStreamControllerHandleQueueDrain(controller); + return Promise.resolve(CreateIterResultObject(filledView, false)); + } + + if (controller._closeRequested === true) { + var e = new TypeError('Insufficient bytes to fill elements in the given buffer'); + ReadableByteStreamControllerError(controller, e); + return Promise.reject(e); + } + } + + pullIntoDescriptor.buffer = TransferArrayBuffer(pullIntoDescriptor.buffer); + + controller._pendingPullIntos.push(pullIntoDescriptor); + + var promise = ReadableStreamAddReadIntoRequest(stream); + ReadableByteStreamControllerCallPullIfNeeded(controller); + return promise; + } + + function ReadableByteStreamControllerRespondInClosedState(controller, firstDescriptor) { + firstDescriptor.buffer = TransferArrayBuffer(firstDescriptor.buffer); + assert(firstDescriptor.bytesFilled === 0, 'bytesFilled must be 0'); + var stream = controller._controlledReadableStream; + + if (ReadableStreamHasBYOBReader(stream) === true) { + while (ReadableStreamGetNumReadIntoRequests(stream) > 0) { + var pullIntoDescriptor = ReadableByteStreamControllerShiftPendingPullInto(controller); + ReadableByteStreamControllerCommitPullIntoDescriptor(stream, pullIntoDescriptor); + } + } + } + + function ReadableByteStreamControllerRespondInReadableState(controller, bytesWritten, pullIntoDescriptor) { + if (pullIntoDescriptor.bytesFilled + bytesWritten > pullIntoDescriptor.byteLength) { + throw new RangeError('bytesWritten out of range'); + } + + ReadableByteStreamControllerFillHeadPullIntoDescriptor(controller, bytesWritten, pullIntoDescriptor); + + if (pullIntoDescriptor.bytesFilled < pullIntoDescriptor.elementSize) { + return; + } + + ReadableByteStreamControllerShiftPendingPullInto(controller); + var remainderSize = pullIntoDescriptor.bytesFilled % pullIntoDescriptor.elementSize; + + if (remainderSize > 0) { + var end = pullIntoDescriptor.byteOffset + pullIntoDescriptor.bytesFilled; + var remainder = pullIntoDescriptor.buffer.slice(end - remainderSize, end); + ReadableByteStreamControllerEnqueueChunkToQueue(controller, remainder, 0, remainder.byteLength); + } + + pullIntoDescriptor.buffer = TransferArrayBuffer(pullIntoDescriptor.buffer); + pullIntoDescriptor.bytesFilled -= remainderSize; + ReadableByteStreamControllerCommitPullIntoDescriptor(controller._controlledReadableStream, pullIntoDescriptor); + ReadableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(controller); + } + + function ReadableByteStreamControllerRespondInternal(controller, bytesWritten) { + var firstDescriptor = controller._pendingPullIntos[0]; + var stream = controller._controlledReadableStream; + + if (stream._state === 'closed') { + if (bytesWritten !== 0) { + throw new TypeError('bytesWritten must be 0 when calling respond() on a closed stream'); + } + + ReadableByteStreamControllerRespondInClosedState(controller, firstDescriptor); + } else { + assert(stream._state === 'readable'); + ReadableByteStreamControllerRespondInReadableState(controller, bytesWritten, firstDescriptor); + } + } + + function ReadableByteStreamControllerShiftPendingPullInto(controller) { + var descriptor = controller._pendingPullIntos.shift(); + + ReadableByteStreamControllerInvalidateBYOBRequest(controller); + return descriptor; + } + + function ReadableByteStreamControllerShouldCallPull(controller) { + var stream = controller._controlledReadableStream; + + if (stream._state !== 'readable') { + return false; + } + + if (controller._closeRequested === true) { + return false; + } + + if (controller._started === false) { + return false; + } + + if (ReadableStreamHasDefaultReader(stream) === true && ReadableStreamGetNumReadRequests(stream) > 0) { + return true; + } + + if (ReadableStreamHasBYOBReader(stream) === true && ReadableStreamGetNumReadIntoRequests(stream) > 0) { + return true; + } + + if (ReadableByteStreamControllerGetDesiredSize(controller) > 0) { + return true; + } + + return false; + } + + function ReadableByteStreamControllerClose(controller) { + var stream = controller._controlledReadableStream; + assert(controller._closeRequested === false); + assert(stream._state === 'readable'); + + if (controller._queueTotalSize > 0) { + controller._closeRequested = true; + return; + } + + if (controller._pendingPullIntos.length > 0) { + var firstPendingPullInto = controller._pendingPullIntos[0]; + + if (firstPendingPullInto.bytesFilled > 0) { + var e = new TypeError('Insufficient bytes to fill elements in the given buffer'); + ReadableByteStreamControllerError(controller, e); + throw e; + } + } + + ReadableStreamClose(stream); + } + + function ReadableByteStreamControllerEnqueue(controller, chunk) { + var stream = controller._controlledReadableStream; + assert(controller._closeRequested === false); + assert(stream._state === 'readable'); + var buffer = chunk.buffer; + var byteOffset = chunk.byteOffset; + var byteLength = chunk.byteLength; + var transferredBuffer = TransferArrayBuffer(buffer); + + if (ReadableStreamHasDefaultReader(stream) === true) { + if (ReadableStreamGetNumReadRequests(stream) === 0) { + ReadableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset, byteLength); + } else { + assert(controller._queue.length === 0); + var transferredView = new Uint8Array(transferredBuffer, byteOffset, byteLength); + ReadableStreamFulfillReadRequest(stream, transferredView, false); + } + } else if (ReadableStreamHasBYOBReader(stream) === true) { + ReadableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset, byteLength); + ReadableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(controller); + } else { + assert(IsReadableStreamLocked(stream) === false, 'stream must not be locked'); + ReadableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset, byteLength); + } + } + + function ReadableByteStreamControllerError(controller, e) { + var stream = controller._controlledReadableStream; + assert(stream._state === 'readable'); + ReadableByteStreamControllerClearPendingPullIntos(controller); + ResetQueue(controller); + ReadableStreamError(stream, e); + } + + function ReadableByteStreamControllerGetDesiredSize(controller) { + var stream = controller._controlledReadableStream; + var state = stream._state; + + if (state === 'errored') { + return null; + } + + if (state === 'closed') { + return 0; + } + + return controller._strategyHWM - controller._queueTotalSize; + } + + function ReadableByteStreamControllerRespond(controller, bytesWritten) { + bytesWritten = Number(bytesWritten); + + if (IsFiniteNonNegativeNumber(bytesWritten) === false) { + throw new RangeError('bytesWritten must be a finite'); + } + + assert(controller._pendingPullIntos.length > 0); + ReadableByteStreamControllerRespondInternal(controller, bytesWritten); + } + + function ReadableByteStreamControllerRespondWithNewView(controller, view) { + assert(controller._pendingPullIntos.length > 0); + var firstDescriptor = controller._pendingPullIntos[0]; + + if (firstDescriptor.byteOffset + firstDescriptor.bytesFilled !== view.byteOffset) { + throw new RangeError('The region specified by view does not match byobRequest'); + } + + if (firstDescriptor.byteLength !== view.byteLength) { + throw new RangeError('The buffer of view has different capacity than byobRequest'); + } + + firstDescriptor.buffer = view.buffer; + ReadableByteStreamControllerRespondInternal(controller, view.byteLength); + } + + function streamBrandCheckException(name) { + return new TypeError('ReadableStream.prototype.' + name + ' can only be used on a ReadableStream'); + } + + function readerLockException(name) { + return new TypeError('Cannot ' + name + ' a stream using a released reader'); + } + + function defaultReaderBrandCheckException(name) { + return new TypeError('ReadableStreamDefaultReader.prototype.' + name + ' can only be used on a ReadableStreamDefaultReader'); + } + + function defaultReaderClosedPromiseInitialize(reader) { + reader._closedPromise = new Promise(function (resolve, reject) { + reader._closedPromise_resolve = resolve; + reader._closedPromise_reject = reject; + }); + } + + function defaultReaderClosedPromiseInitializeAsRejected(reader, reason) { + reader._closedPromise = Promise.reject(reason); + reader._closedPromise_resolve = undefined; + reader._closedPromise_reject = undefined; + } + + function defaultReaderClosedPromiseInitializeAsResolved(reader) { + reader._closedPromise = Promise.resolve(undefined); + reader._closedPromise_resolve = undefined; + reader._closedPromise_reject = undefined; + } + + function defaultReaderClosedPromiseReject(reader, reason) { + assert(reader._closedPromise_resolve !== undefined); + assert(reader._closedPromise_reject !== undefined); + + reader._closedPromise_reject(reason); + + reader._closedPromise_resolve = undefined; + reader._closedPromise_reject = undefined; + } + + function defaultReaderClosedPromiseResetToRejected(reader, reason) { + assert(reader._closedPromise_resolve === undefined); + assert(reader._closedPromise_reject === undefined); + reader._closedPromise = Promise.reject(reason); + } + + function defaultReaderClosedPromiseResolve(reader) { + assert(reader._closedPromise_resolve !== undefined); + assert(reader._closedPromise_reject !== undefined); + + reader._closedPromise_resolve(undefined); + + reader._closedPromise_resolve = undefined; + reader._closedPromise_reject = undefined; + } + + function byobReaderBrandCheckException(name) { + return new TypeError('ReadableStreamBYOBReader.prototype.' + name + ' can only be used on a ReadableStreamBYOBReader'); + } + + function defaultControllerBrandCheckException(name) { + return new TypeError('ReadableStreamDefaultController.prototype.' + name + ' can only be used on a ReadableStreamDefaultController'); + } + + function byobRequestBrandCheckException(name) { + return new TypeError('ReadableStreamBYOBRequest.prototype.' + name + ' can only be used on a ReadableStreamBYOBRequest'); + } + + function byteStreamControllerBrandCheckException(name) { + return new TypeError('ReadableByteStreamController.prototype.' + name + ' can only be used on a ReadableByteStreamController'); + } + + function ifIsObjectAndHasAPromiseIsHandledInternalSlotSetPromiseIsHandledToTrue(promise) { + try { + Promise.prototype.then.call(promise, undefined, function () {}); + } catch (e) {} + } +}, function (module, exports, __w_pdfjs_require__) { + "use strict"; + + var transformStream = __w_pdfjs_require__(6); + + var readableStream = __w_pdfjs_require__(4); + + var writableStream = __w_pdfjs_require__(2); + + exports.TransformStream = transformStream.TransformStream; + exports.ReadableStream = readableStream.ReadableStream; + exports.IsReadableStreamDisturbed = readableStream.IsReadableStreamDisturbed; + exports.ReadableStreamDefaultControllerClose = readableStream.ReadableStreamDefaultControllerClose; + exports.ReadableStreamDefaultControllerEnqueue = readableStream.ReadableStreamDefaultControllerEnqueue; + exports.ReadableStreamDefaultControllerError = readableStream.ReadableStreamDefaultControllerError; + exports.ReadableStreamDefaultControllerGetDesiredSize = readableStream.ReadableStreamDefaultControllerGetDesiredSize; + exports.AcquireWritableStreamDefaultWriter = writableStream.AcquireWritableStreamDefaultWriter; + exports.IsWritableStream = writableStream.IsWritableStream; + exports.IsWritableStreamLocked = writableStream.IsWritableStreamLocked; + exports.WritableStream = writableStream.WritableStream; + exports.WritableStreamAbort = writableStream.WritableStreamAbort; + exports.WritableStreamDefaultControllerError = writableStream.WritableStreamDefaultControllerError; + exports.WritableStreamDefaultWriterCloseWithErrorPropagation = writableStream.WritableStreamDefaultWriterCloseWithErrorPropagation; + exports.WritableStreamDefaultWriterRelease = writableStream.WritableStreamDefaultWriterRelease; + exports.WritableStreamDefaultWriterWrite = writableStream.WritableStreamDefaultWriterWrite; +}, function (module, exports, __w_pdfjs_require__) { + "use strict"; + + var _createClass = function () { + function defineProperties(target, props) { + for (var i = 0; i < props.length; i++) { + var descriptor = props[i]; + descriptor.enumerable = descriptor.enumerable || false; + descriptor.configurable = true; + if ("value" in descriptor) descriptor.writable = true; + Object.defineProperty(target, descriptor.key, descriptor); + } + } + + return function (Constructor, protoProps, staticProps) { + if (protoProps) defineProperties(Constructor.prototype, protoProps); + if (staticProps) defineProperties(Constructor, staticProps); + return Constructor; + }; + }(); + + function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); + } + } + + var _require = __w_pdfjs_require__(1), + assert = _require.assert; + + var _require2 = __w_pdfjs_require__(0), + InvokeOrNoop = _require2.InvokeOrNoop, + PromiseInvokeOrPerformFallback = _require2.PromiseInvokeOrPerformFallback, + PromiseInvokeOrNoop = _require2.PromiseInvokeOrNoop, + typeIsObject = _require2.typeIsObject; + + var _require3 = __w_pdfjs_require__(4), + ReadableStream = _require3.ReadableStream, + ReadableStreamDefaultControllerClose = _require3.ReadableStreamDefaultControllerClose, + ReadableStreamDefaultControllerEnqueue = _require3.ReadableStreamDefaultControllerEnqueue, + ReadableStreamDefaultControllerError = _require3.ReadableStreamDefaultControllerError, + ReadableStreamDefaultControllerGetDesiredSize = _require3.ReadableStreamDefaultControllerGetDesiredSize; + + var _require4 = __w_pdfjs_require__(2), + WritableStream = _require4.WritableStream, + WritableStreamDefaultControllerError = _require4.WritableStreamDefaultControllerError; + + function TransformStreamCloseReadable(transformStream) { + if (transformStream._errored === true) { + throw new TypeError('TransformStream is already errored'); + } + + if (transformStream._readableClosed === true) { + throw new TypeError('Readable side is already closed'); + } + + TransformStreamCloseReadableInternal(transformStream); + } + + function TransformStreamEnqueueToReadable(transformStream, chunk) { + if (transformStream._errored === true) { + throw new TypeError('TransformStream is already errored'); + } + + if (transformStream._readableClosed === true) { + throw new TypeError('Readable side is already closed'); + } + + var controller = transformStream._readableController; + + try { + ReadableStreamDefaultControllerEnqueue(controller, chunk); + } catch (e) { + transformStream._readableClosed = true; + TransformStreamErrorIfNeeded(transformStream, e); + throw transformStream._storedError; + } + + var desiredSize = ReadableStreamDefaultControllerGetDesiredSize(controller); + var maybeBackpressure = desiredSize <= 0; + + if (maybeBackpressure === true && transformStream._backpressure === false) { + TransformStreamSetBackpressure(transformStream, true); + } + } + + function TransformStreamError(transformStream, e) { + if (transformStream._errored === true) { + throw new TypeError('TransformStream is already errored'); + } + + TransformStreamErrorInternal(transformStream, e); + } + + function TransformStreamCloseReadableInternal(transformStream) { + assert(transformStream._errored === false); + assert(transformStream._readableClosed === false); + + try { + ReadableStreamDefaultControllerClose(transformStream._readableController); + } catch (e) { + assert(false); + } + + transformStream._readableClosed = true; + } + + function TransformStreamErrorIfNeeded(transformStream, e) { + if (transformStream._errored === false) { + TransformStreamErrorInternal(transformStream, e); + } + } + + function TransformStreamErrorInternal(transformStream, e) { + assert(transformStream._errored === false); + transformStream._errored = true; + transformStream._storedError = e; + + if (transformStream._writableDone === false) { + WritableStreamDefaultControllerError(transformStream._writableController, e); + } + + if (transformStream._readableClosed === false) { + ReadableStreamDefaultControllerError(transformStream._readableController, e); + } + } + + function TransformStreamReadableReadyPromise(transformStream) { + assert(transformStream._backpressureChangePromise !== undefined, '_backpressureChangePromise should have been initialized'); + + if (transformStream._backpressure === false) { + return Promise.resolve(); + } + + assert(transformStream._backpressure === true, '_backpressure should have been initialized'); + return transformStream._backpressureChangePromise; + } + + function TransformStreamSetBackpressure(transformStream, backpressure) { + assert(transformStream._backpressure !== backpressure, 'TransformStreamSetBackpressure() should be called only when backpressure is changed'); + + if (transformStream._backpressureChangePromise !== undefined) { + transformStream._backpressureChangePromise_resolve(backpressure); + } + + transformStream._backpressureChangePromise = new Promise(function (resolve) { + transformStream._backpressureChangePromise_resolve = resolve; + }); + + transformStream._backpressureChangePromise.then(function (resolution) { + assert(resolution !== backpressure, '_backpressureChangePromise should be fulfilled only when backpressure is changed'); + }); + + transformStream._backpressure = backpressure; + } + + function TransformStreamDefaultTransform(chunk, transformStreamController) { + var transformStream = transformStreamController._controlledTransformStream; + TransformStreamEnqueueToReadable(transformStream, chunk); + return Promise.resolve(); + } + + function TransformStreamTransform(transformStream, chunk) { + assert(transformStream._errored === false); + assert(transformStream._transforming === false); + assert(transformStream._backpressure === false); + transformStream._transforming = true; + var transformer = transformStream._transformer; + var controller = transformStream._transformStreamController; + var transformPromise = PromiseInvokeOrPerformFallback(transformer, 'transform', [chunk, controller], TransformStreamDefaultTransform, [chunk, controller]); + return transformPromise.then(function () { + transformStream._transforming = false; + return TransformStreamReadableReadyPromise(transformStream); + }, function (e) { + TransformStreamErrorIfNeeded(transformStream, e); + return Promise.reject(e); + }); + } + + function IsTransformStreamDefaultController(x) { + if (!typeIsObject(x)) { + return false; + } + + if (!Object.prototype.hasOwnProperty.call(x, '_controlledTransformStream')) { + return false; + } + + return true; + } + + function IsTransformStream(x) { + if (!typeIsObject(x)) { + return false; + } + + if (!Object.prototype.hasOwnProperty.call(x, '_transformStreamController')) { + return false; + } + + return true; + } + + var TransformStreamSink = function () { + function TransformStreamSink(transformStream, startPromise) { + _classCallCheck(this, TransformStreamSink); + + this._transformStream = transformStream; + this._startPromise = startPromise; + } + + _createClass(TransformStreamSink, [{ + key: 'start', + value: function start(c) { + var transformStream = this._transformStream; + transformStream._writableController = c; + return this._startPromise.then(function () { + return TransformStreamReadableReadyPromise(transformStream); + }); + } + }, { + key: 'write', + value: function write(chunk) { + var transformStream = this._transformStream; + return TransformStreamTransform(transformStream, chunk); + } + }, { + key: 'abort', + value: function abort() { + var transformStream = this._transformStream; + transformStream._writableDone = true; + TransformStreamErrorInternal(transformStream, new TypeError('Writable side aborted')); + } + }, { + key: 'close', + value: function close() { + var transformStream = this._transformStream; + assert(transformStream._transforming === false); + transformStream._writableDone = true; + var flushPromise = PromiseInvokeOrNoop(transformStream._transformer, 'flush', [transformStream._transformStreamController]); + return flushPromise.then(function () { + if (transformStream._errored === true) { + return Promise.reject(transformStream._storedError); + } + + if (transformStream._readableClosed === false) { + TransformStreamCloseReadableInternal(transformStream); + } + + return Promise.resolve(); + }).catch(function (r) { + TransformStreamErrorIfNeeded(transformStream, r); + return Promise.reject(transformStream._storedError); + }); + } + }]); + + return TransformStreamSink; + }(); + + var TransformStreamSource = function () { + function TransformStreamSource(transformStream, startPromise) { + _classCallCheck(this, TransformStreamSource); + + this._transformStream = transformStream; + this._startPromise = startPromise; + } + + _createClass(TransformStreamSource, [{ + key: 'start', + value: function start(c) { + var transformStream = this._transformStream; + transformStream._readableController = c; + return this._startPromise.then(function () { + assert(transformStream._backpressureChangePromise !== undefined, '_backpressureChangePromise should have been initialized'); + + if (transformStream._backpressure === true) { + return Promise.resolve(); + } + + assert(transformStream._backpressure === false, '_backpressure should have been initialized'); + return transformStream._backpressureChangePromise; + }); + } + }, { + key: 'pull', + value: function pull() { + var transformStream = this._transformStream; + assert(transformStream._backpressure === true, 'pull() should be never called while _backpressure is false'); + assert(transformStream._backpressureChangePromise !== undefined, '_backpressureChangePromise should have been initialized'); + TransformStreamSetBackpressure(transformStream, false); + return transformStream._backpressureChangePromise; + } + }, { + key: 'cancel', + value: function cancel() { + var transformStream = this._transformStream; + transformStream._readableClosed = true; + TransformStreamErrorInternal(transformStream, new TypeError('Readable side canceled')); + } + }]); + + return TransformStreamSource; + }(); + + var TransformStreamDefaultController = function () { + function TransformStreamDefaultController(transformStream) { + _classCallCheck(this, TransformStreamDefaultController); + + if (IsTransformStream(transformStream) === false) { + throw new TypeError('TransformStreamDefaultController can only be ' + 'constructed with a TransformStream instance'); + } + + if (transformStream._transformStreamController !== undefined) { + throw new TypeError('TransformStreamDefaultController instances can ' + 'only be created by the TransformStream constructor'); + } + + this._controlledTransformStream = transformStream; + } + + _createClass(TransformStreamDefaultController, [{ + key: 'enqueue', + value: function enqueue(chunk) { + if (IsTransformStreamDefaultController(this) === false) { + throw defaultControllerBrandCheckException('enqueue'); + } + + TransformStreamEnqueueToReadable(this._controlledTransformStream, chunk); + } + }, { + key: 'close', + value: function close() { + if (IsTransformStreamDefaultController(this) === false) { + throw defaultControllerBrandCheckException('close'); + } + + TransformStreamCloseReadable(this._controlledTransformStream); + } + }, { + key: 'error', + value: function error(reason) { + if (IsTransformStreamDefaultController(this) === false) { + throw defaultControllerBrandCheckException('error'); + } + + TransformStreamError(this._controlledTransformStream, reason); + } + }, { + key: 'desiredSize', + get: function get() { + if (IsTransformStreamDefaultController(this) === false) { + throw defaultControllerBrandCheckException('desiredSize'); + } + + var transformStream = this._controlledTransformStream; + var readableController = transformStream._readableController; + return ReadableStreamDefaultControllerGetDesiredSize(readableController); + } + }]); + + return TransformStreamDefaultController; + }(); + + var TransformStream = function () { + function TransformStream() { + var transformer = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + + _classCallCheck(this, TransformStream); + + this._transformer = transformer; + var readableStrategy = transformer.readableStrategy, + writableStrategy = transformer.writableStrategy; + this._transforming = false; + this._errored = false; + this._storedError = undefined; + this._writableController = undefined; + this._readableController = undefined; + this._transformStreamController = undefined; + this._writableDone = false; + this._readableClosed = false; + this._backpressure = undefined; + this._backpressureChangePromise = undefined; + this._backpressureChangePromise_resolve = undefined; + this._transformStreamController = new TransformStreamDefaultController(this); + var startPromise_resolve = void 0; + var startPromise = new Promise(function (resolve) { + startPromise_resolve = resolve; + }); + var source = new TransformStreamSource(this, startPromise); + this._readable = new ReadableStream(source, readableStrategy); + var sink = new TransformStreamSink(this, startPromise); + this._writable = new WritableStream(sink, writableStrategy); + assert(this._writableController !== undefined); + assert(this._readableController !== undefined); + var desiredSize = ReadableStreamDefaultControllerGetDesiredSize(this._readableController); + TransformStreamSetBackpressure(this, desiredSize <= 0); + var transformStream = this; + var startResult = InvokeOrNoop(transformer, 'start', [transformStream._transformStreamController]); + startPromise_resolve(startResult); + startPromise.catch(function (e) { + if (transformStream._errored === false) { + transformStream._errored = true; + transformStream._storedError = e; + } + }); + } + + _createClass(TransformStream, [{ + key: 'readable', + get: function get() { + if (IsTransformStream(this) === false) { + throw streamBrandCheckException('readable'); + } + + return this._readable; + } + }, { + key: 'writable', + get: function get() { + if (IsTransformStream(this) === false) { + throw streamBrandCheckException('writable'); + } + + return this._writable; + } + }]); + + return TransformStream; + }(); + + module.exports = { + TransformStream: TransformStream + }; + + function defaultControllerBrandCheckException(name) { + return new TypeError('TransformStreamDefaultController.prototype.' + name + ' can only be used on a TransformStreamDefaultController'); + } + + function streamBrandCheckException(name) { + return new TypeError('TransformStream.prototype.' + name + ' can only be used on a TransformStream'); + } +}, function (module, exports, __w_pdfjs_require__) { + module.exports = __w_pdfjs_require__(5); +}])); + +/***/ }), +/* 7 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + { exports.URL = URL; } /***/ }), -/* 7 */ +/* 8 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -1834,11 +5591,11 @@ exports.NetworkPdfManager = exports.LocalPdfManager = void 0; var _util = __w_pdfjs_require__(2); -var _chunked_stream = __w_pdfjs_require__(8); +var _chunked_stream = __w_pdfjs_require__(9); -var _document = __w_pdfjs_require__(9); +var _document = __w_pdfjs_require__(10); -var _stream = __w_pdfjs_require__(13); +var _stream = __w_pdfjs_require__(14); class BasePdfManager { constructor() { @@ -2022,7 +5779,7 @@ class NetworkPdfManager extends BasePdfManager { exports.NetworkPdfManager = NetworkPdfManager; /***/ }), -/* 8 */ +/* 9 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -2589,7 +6346,7 @@ class ChunkedStreamManager { exports.ChunkedStreamManager = ChunkedStreamManager; /***/ }), -/* 9 */ +/* 10 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -2602,23 +6359,23 @@ exports.PDFDocument = exports.Page = void 0; var _util = __w_pdfjs_require__(2); -var _obj = __w_pdfjs_require__(10); +var _obj = __w_pdfjs_require__(11); -var _primitives = __w_pdfjs_require__(11); +var _primitives = __w_pdfjs_require__(12); -var _stream = __w_pdfjs_require__(13); +var _stream = __w_pdfjs_require__(14); -var _annotation = __w_pdfjs_require__(25); +var _annotation = __w_pdfjs_require__(26); -var _crypto = __w_pdfjs_require__(23); +var _crypto = __w_pdfjs_require__(24); -var _parser = __w_pdfjs_require__(12); +var _parser = __w_pdfjs_require__(13); -var _operator_list = __w_pdfjs_require__(26); +var _operator_list = __w_pdfjs_require__(27); -var _evaluator = __w_pdfjs_require__(27); +var _evaluator = __w_pdfjs_require__(28); -var _function = __w_pdfjs_require__(41); +var _function = __w_pdfjs_require__(42); const DEFAULT_USER_UNIT = 1.0; const LETTER_SIZE_MEDIABOX = [0, 0, 612, 792]; @@ -3264,7 +7021,7 @@ class PDFDocument { exports.PDFDocument = PDFDocument; /***/ }), -/* 10 */ +/* 11 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -3277,15 +7034,15 @@ exports.FileSpec = exports.XRef = exports.ObjectLoader = exports.Catalog = void var _util = __w_pdfjs_require__(2); -var _primitives = __w_pdfjs_require__(11); +var _primitives = __w_pdfjs_require__(12); -var _parser = __w_pdfjs_require__(12); +var _parser = __w_pdfjs_require__(13); -var _chunked_stream = __w_pdfjs_require__(8); +var _chunked_stream = __w_pdfjs_require__(9); -var _crypto = __w_pdfjs_require__(23); +var _crypto = __w_pdfjs_require__(24); -var _colorspace = __w_pdfjs_require__(24); +var _colorspace = __w_pdfjs_require__(25); function fetchDestination(dest) { return (0, _primitives.isDict)(dest) ? dest.get('D') : dest; @@ -4001,7 +7758,11 @@ class Catalog { static parseDestDictionary(params) { function addDefaultProtocolToUrl(url) { - return url.startsWith('www.') ? `http://${url}` : url; + if (url.indexOf('www.') === 0) { + return `http://${url}`; + } + + return url; } function tryConvertUrlEncoding(url) { @@ -4519,7 +8280,7 @@ var XRef = function XRefClosure() { var token = readToken(buffer, position); var m; - if (token.startsWith('xref') && (token.length === 4 || /\s/.test(token[4]))) { + if (token.indexOf('xref') === 0 && (token.length === 4 || /\s/.test(token[4]))) { position += skipUntil(buffer, position, trailerBytes); trailers.push(position); position += skipUntil(buffer, position, startxrefBytes); @@ -4565,7 +8326,7 @@ var XRef = function XRefClosure() { } position += contentLength; - } else if (token.startsWith('trailer') && (token.length === 7 || /\s/.test(token[7]))) { + } else if (token.indexOf('trailer') === 0 && (token.length === 7 || /\s/.test(token[7]))) { trailers.push(position); position += skipUntil(buffer, position, startxrefBytes); } else { @@ -4788,7 +8549,7 @@ var XRef = function XRefClosure() { } if (obj3.cmd !== 'obj') { - if (obj3.cmd.startsWith('obj')) { + if (obj3.cmd.indexOf('obj') === 0) { num = parseInt(obj3.cmd.substring(3), 10); if (!Number.isNaN(num)) { @@ -5294,7 +9055,7 @@ let ObjectLoader = function () { exports.ObjectLoader = ObjectLoader; /***/ }), -/* 11 */ +/* 12 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -5582,7 +9343,7 @@ function isStream(v) { } /***/ }), -/* 12 */ +/* 13 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -5593,19 +9354,19 @@ Object.defineProperty(exports, "__esModule", { }); exports.Parser = exports.Linearization = exports.Lexer = void 0; -var _stream = __w_pdfjs_require__(13); +var _stream = __w_pdfjs_require__(14); var _util = __w_pdfjs_require__(2); -var _primitives = __w_pdfjs_require__(11); +var _primitives = __w_pdfjs_require__(12); -var _ccitt_stream = __w_pdfjs_require__(14); +var _ccitt_stream = __w_pdfjs_require__(15); -var _jbig2_stream = __w_pdfjs_require__(16); +var _jbig2_stream = __w_pdfjs_require__(17); -var _jpeg_stream = __w_pdfjs_require__(19); +var _jpeg_stream = __w_pdfjs_require__(20); -var _jpx_stream = __w_pdfjs_require__(21); +var _jpx_stream = __w_pdfjs_require__(22); const MAX_LENGTH_TO_CACHE = 1000; const MAX_ADLER32_LENGTH = 5552; @@ -6834,7 +10595,7 @@ var Linearization = { exports.Linearization = Linearization; /***/ }), -/* 13 */ +/* 14 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -6847,7 +10608,7 @@ exports.LZWStream = exports.StringStream = exports.StreamsSequenceStream = expor var _util = __w_pdfjs_require__(2); -var _primitives = __w_pdfjs_require__(11); +var _primitives = __w_pdfjs_require__(12); var Stream = function StreamClosure() { function Stream(arrayBuffer, start, length, dict) { @@ -8111,7 +11872,7 @@ var NullStream = function NullStreamClosure() { exports.NullStream = NullStream; /***/ }), -/* 14 */ +/* 15 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -8122,11 +11883,11 @@ Object.defineProperty(exports, "__esModule", { }); exports.CCITTFaxStream = void 0; -var _primitives = __w_pdfjs_require__(11); +var _primitives = __w_pdfjs_require__(12); -var _ccitt = __w_pdfjs_require__(15); +var _ccitt = __w_pdfjs_require__(16); -var _stream = __w_pdfjs_require__(13); +var _stream = __w_pdfjs_require__(14); var CCITTFaxStream = function CCITTFaxStreamClosure() { function CCITTFaxStream(str, maybeLength, params) { @@ -8178,7 +11939,7 @@ var CCITTFaxStream = function CCITTFaxStreamClosure() { exports.CCITTFaxStream = CCITTFaxStream; /***/ }), -/* 15 */ +/* 16 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -8883,7 +12644,7 @@ let CCITTFaxDecoder = function CCITTFaxDecoder() { exports.CCITTFaxDecoder = CCITTFaxDecoder; /***/ }), -/* 16 */ +/* 17 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -8894,11 +12655,11 @@ Object.defineProperty(exports, "__esModule", { }); exports.Jbig2Stream = void 0; -var _primitives = __w_pdfjs_require__(11); +var _primitives = __w_pdfjs_require__(12); -var _stream = __w_pdfjs_require__(13); +var _stream = __w_pdfjs_require__(14); -var _jbig = __w_pdfjs_require__(17); +var _jbig = __w_pdfjs_require__(18); var _util = __w_pdfjs_require__(2); @@ -8967,7 +12728,7 @@ let Jbig2Stream = function Jbig2StreamClosure() { exports.Jbig2Stream = Jbig2Stream; /***/ }), -/* 17 */ +/* 18 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -8980,9 +12741,9 @@ exports.Jbig2Image = void 0; var _util = __w_pdfjs_require__(2); -var _arithmetic_decoder = __w_pdfjs_require__(18); +var _arithmetic_decoder = __w_pdfjs_require__(19); -var _ccitt = __w_pdfjs_require__(15); +var _ccitt = __w_pdfjs_require__(16); let Jbig2Error = function Jbig2ErrorClosure() { function Jbig2Error(msg) { @@ -11180,7 +14941,7 @@ var Jbig2Image = function Jbig2ImageClosure() { exports.Jbig2Image = Jbig2Image; /***/ }), -/* 18 */ +/* 19 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -11534,7 +15295,7 @@ class ArithmeticDecoder { exports.ArithmeticDecoder = ArithmeticDecoder; /***/ }), -/* 19 */ +/* 20 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -11547,11 +15308,11 @@ exports.JpegStream = void 0; var _util = __w_pdfjs_require__(2); -var _stream = __w_pdfjs_require__(13); +var _stream = __w_pdfjs_require__(14); -var _primitives = __w_pdfjs_require__(11); +var _primitives = __w_pdfjs_require__(12); -var _jpg = __w_pdfjs_require__(20); +var _jpg = __w_pdfjs_require__(21); let JpegStream = function JpegStreamClosure() { function JpegStream(stream, maybeLength, dict, params) { @@ -11645,7 +15406,7 @@ let JpegStream = function JpegStreamClosure() { exports.JpegStream = JpegStream; /***/ }), -/* 20 */ +/* 21 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -12824,7 +16585,7 @@ var JpegImage = function JpegImageClosure() { exports.JpegImage = JpegImage; /***/ }), -/* 21 */ +/* 22 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -12835,9 +16596,9 @@ Object.defineProperty(exports, "__esModule", { }); exports.JpxStream = void 0; -var _stream = __w_pdfjs_require__(13); +var _stream = __w_pdfjs_require__(14); -var _jpx = __w_pdfjs_require__(22); +var _jpx = __w_pdfjs_require__(23); var _util = __w_pdfjs_require__(2); @@ -12911,7 +16672,7 @@ let JpxStream = function JpxStreamClosure() { exports.JpxStream = JpxStream; /***/ }), -/* 22 */ +/* 23 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -12924,7 +16685,7 @@ exports.JpxImage = void 0; var _util = __w_pdfjs_require__(2); -var _arithmetic_decoder = __w_pdfjs_require__(18); +var _arithmetic_decoder = __w_pdfjs_require__(19); let JpxError = function JpxErrorClosure() { function JpxError(msg) { @@ -15229,7 +18990,7 @@ var JpxImage = function JpxImageClosure() { exports.JpxImage = JpxImage; /***/ }), -/* 23 */ +/* 24 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -15242,9 +19003,9 @@ exports.calculateSHA512 = exports.calculateSHA384 = exports.calculateSHA256 = ex var _util = __w_pdfjs_require__(2); -var _primitives = __w_pdfjs_require__(11); +var _primitives = __w_pdfjs_require__(12); -var _stream = __w_pdfjs_require__(13); +var _stream = __w_pdfjs_require__(14); var ARCFourCipher = function ARCFourCipherClosure() { function ARCFourCipher(key) { @@ -16819,7 +20580,7 @@ var CipherTransformFactory = function CipherTransformFactoryClosure() { exports.CipherTransformFactory = CipherTransformFactory; /***/ }), -/* 24 */ +/* 25 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -16832,7 +20593,7 @@ exports.ColorSpace = void 0; var _util = __w_pdfjs_require__(2); -var _primitives = __w_pdfjs_require__(11); +var _primitives = __w_pdfjs_require__(12); function resizeRgbImage(src, dest, w1, h1, w2, h2, alpha01) { const COMPONENTS = 3; @@ -17857,7 +21618,7 @@ const LabCS = function LabCSClosure() { }(); /***/ }), -/* 25 */ +/* 26 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -17870,15 +21631,15 @@ exports.AnnotationFactory = exports.AnnotationBorderStyle = exports.Annotation = var _util = __w_pdfjs_require__(2); -var _obj = __w_pdfjs_require__(10); +var _obj = __w_pdfjs_require__(11); -var _primitives = __w_pdfjs_require__(11); +var _primitives = __w_pdfjs_require__(12); -var _colorspace = __w_pdfjs_require__(24); +var _colorspace = __w_pdfjs_require__(25); -var _operator_list = __w_pdfjs_require__(26); +var _operator_list = __w_pdfjs_require__(27); -var _stream = __w_pdfjs_require__(13); +var _stream = __w_pdfjs_require__(14); class AnnotationFactory { static create(xref, ref, pdfManager, idFactory) { @@ -18798,7 +22559,7 @@ class FileAttachmentAnnotation extends Annotation { } /***/ }), -/* 26 */ +/* 27 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -19440,7 +23201,7 @@ var OperatorList = function OperatorListClosure() { exports.OperatorList = OperatorList; /***/ }), -/* 27 */ +/* 28 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -19453,41 +23214,41 @@ exports.PartialEvaluator = void 0; var _util = __w_pdfjs_require__(2); -var _cmap = __w_pdfjs_require__(28); +var _cmap = __w_pdfjs_require__(29); -var _stream = __w_pdfjs_require__(13); +var _stream = __w_pdfjs_require__(14); -var _primitives = __w_pdfjs_require__(11); +var _primitives = __w_pdfjs_require__(12); -var _fonts = __w_pdfjs_require__(29); +var _fonts = __w_pdfjs_require__(30); -var _encodings = __w_pdfjs_require__(32); +var _encodings = __w_pdfjs_require__(33); -var _unicode = __w_pdfjs_require__(35); +var _unicode = __w_pdfjs_require__(36); -var _standard_fonts = __w_pdfjs_require__(34); +var _standard_fonts = __w_pdfjs_require__(35); -var _pattern = __w_pdfjs_require__(38); +var _pattern = __w_pdfjs_require__(39); -var _parser = __w_pdfjs_require__(12); +var _parser = __w_pdfjs_require__(13); -var _bidi = __w_pdfjs_require__(39); +var _bidi = __w_pdfjs_require__(40); -var _colorspace = __w_pdfjs_require__(24); +var _colorspace = __w_pdfjs_require__(25); -var _glyphlist = __w_pdfjs_require__(33); +var _glyphlist = __w_pdfjs_require__(34); -var _metrics = __w_pdfjs_require__(40); +var _metrics = __w_pdfjs_require__(41); -var _function = __w_pdfjs_require__(41); +var _function = __w_pdfjs_require__(42); -var _jpeg_stream = __w_pdfjs_require__(19); +var _jpeg_stream = __w_pdfjs_require__(20); -var _murmurhash = __w_pdfjs_require__(43); +var _murmurhash = __w_pdfjs_require__(44); -var _operator_list = __w_pdfjs_require__(26); +var _operator_list = __w_pdfjs_require__(27); -var _image = __w_pdfjs_require__(44); +var _image = __w_pdfjs_require__(45); var PartialEvaluator = function PartialEvaluatorClosure() { const DefaultPartialEvaluatorOptions = { @@ -21903,9 +25664,9 @@ var PartialEvaluator = function PartialEvaluatorClosure() { var baseFontStr = baseFont && baseFont.name; if (fontNameStr !== baseFontStr) { - (0, _util.info)(`The FontDescriptor\'s FontName is "${fontNameStr}" but ` + `should be the same as the Font\'s BaseFont "${baseFontStr}".`); + (0, _util.info)('The FontDescriptor\'s FontName is "' + fontNameStr + '" but should be the same as the Font\'s BaseFont "' + baseFontStr + '"'); - if (fontNameStr && baseFontStr && baseFontStr.startsWith(fontNameStr)) { + if (fontNameStr && baseFontStr && baseFontStr.indexOf(fontNameStr) === 0) { fontName = baseFont; } } @@ -22707,7 +26468,7 @@ var EvaluatorPreprocessor = function EvaluatorPreprocessorClosure() { }(); /***/ }), -/* 28 */ +/* 29 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -22720,11 +26481,11 @@ exports.CMapFactory = exports.IdentityCMap = exports.CMap = void 0; var _util = __w_pdfjs_require__(2); -var _primitives = __w_pdfjs_require__(11); +var _primitives = __w_pdfjs_require__(12); -var _parser = __w_pdfjs_require__(12); +var _parser = __w_pdfjs_require__(13); -var _stream = __w_pdfjs_require__(13); +var _stream = __w_pdfjs_require__(14); var BUILT_IN_CMAPS = ['Adobe-GB1-UCS2', 'Adobe-CNS1-UCS2', 'Adobe-Japan1-UCS2', 'Adobe-Korea1-UCS2', '78-EUC-H', '78-EUC-V', '78-H', '78-RKSJ-H', '78-RKSJ-V', '78-V', '78ms-RKSJ-H', '78ms-RKSJ-V', '83pv-RKSJ-H', '90ms-RKSJ-H', '90ms-RKSJ-V', '90msp-RKSJ-H', '90msp-RKSJ-V', '90pv-RKSJ-H', '90pv-RKSJ-V', 'Add-H', 'Add-RKSJ-H', 'Add-RKSJ-V', 'Add-V', 'Adobe-CNS1-0', 'Adobe-CNS1-1', 'Adobe-CNS1-2', 'Adobe-CNS1-3', 'Adobe-CNS1-4', 'Adobe-CNS1-5', 'Adobe-CNS1-6', 'Adobe-GB1-0', 'Adobe-GB1-1', 'Adobe-GB1-2', 'Adobe-GB1-3', 'Adobe-GB1-4', 'Adobe-GB1-5', 'Adobe-Japan1-0', 'Adobe-Japan1-1', 'Adobe-Japan1-2', 'Adobe-Japan1-3', 'Adobe-Japan1-4', 'Adobe-Japan1-5', 'Adobe-Japan1-6', 'Adobe-Korea1-0', 'Adobe-Korea1-1', 'Adobe-Korea1-2', 'B5-H', 'B5-V', 'B5pc-H', 'B5pc-V', 'CNS-EUC-H', 'CNS-EUC-V', 'CNS1-H', 'CNS1-V', 'CNS2-H', 'CNS2-V', 'ETHK-B5-H', 'ETHK-B5-V', 'ETen-B5-H', 'ETen-B5-V', 'ETenms-B5-H', 'ETenms-B5-V', 'EUC-H', 'EUC-V', 'Ext-H', 'Ext-RKSJ-H', 'Ext-RKSJ-V', 'Ext-V', 'GB-EUC-H', 'GB-EUC-V', 'GB-H', 'GB-V', 'GBK-EUC-H', 'GBK-EUC-V', 'GBK2K-H', 'GBK2K-V', 'GBKp-EUC-H', 'GBKp-EUC-V', 'GBT-EUC-H', 'GBT-EUC-V', 'GBT-H', 'GBT-V', 'GBTpc-EUC-H', 'GBTpc-EUC-V', 'GBpc-EUC-H', 'GBpc-EUC-V', 'H', 'HKdla-B5-H', 'HKdla-B5-V', 'HKdlb-B5-H', 'HKdlb-B5-V', 'HKgccs-B5-H', 'HKgccs-B5-V', 'HKm314-B5-H', 'HKm314-B5-V', 'HKm471-B5-H', 'HKm471-B5-V', 'HKscs-B5-H', 'HKscs-B5-V', 'Hankaku', 'Hiragana', 'KSC-EUC-H', 'KSC-EUC-V', 'KSC-H', 'KSC-Johab-H', 'KSC-Johab-V', 'KSC-V', 'KSCms-UHC-H', 'KSCms-UHC-HW-H', 'KSCms-UHC-HW-V', 'KSCms-UHC-V', 'KSCpc-EUC-H', 'KSCpc-EUC-V', 'Katakana', 'NWP-H', 'NWP-V', 'RKSJ-H', 'RKSJ-V', 'Roman', 'UniCNS-UCS2-H', 'UniCNS-UCS2-V', 'UniCNS-UTF16-H', 'UniCNS-UTF16-V', 'UniCNS-UTF32-H', 'UniCNS-UTF32-V', 'UniCNS-UTF8-H', 'UniCNS-UTF8-V', 'UniGB-UCS2-H', 'UniGB-UCS2-V', 'UniGB-UTF16-H', 'UniGB-UTF16-V', 'UniGB-UTF32-H', 'UniGB-UTF32-V', 'UniGB-UTF8-H', 'UniGB-UTF8-V', 'UniJIS-UCS2-H', 'UniJIS-UCS2-HW-H', 'UniJIS-UCS2-HW-V', 'UniJIS-UCS2-V', 'UniJIS-UTF16-H', 'UniJIS-UTF16-V', 'UniJIS-UTF32-H', 'UniJIS-UTF32-V', 'UniJIS-UTF8-H', 'UniJIS-UTF8-V', 'UniJIS2004-UTF16-H', 'UniJIS2004-UTF16-V', 'UniJIS2004-UTF32-H', 'UniJIS2004-UTF32-V', 'UniJIS2004-UTF8-H', 'UniJIS2004-UTF8-V', 'UniJISPro-UCS2-HW-V', 'UniJISPro-UCS2-V', 'UniJISPro-UTF8-V', 'UniJISX0213-UTF32-H', 'UniJISX0213-UTF32-V', 'UniJISX02132004-UTF32-H', 'UniJISX02132004-UTF32-V', 'UniKS-UCS2-H', 'UniKS-UCS2-V', 'UniKS-UTF16-H', 'UniKS-UTF16-V', 'UniKS-UTF32-H', 'UniKS-UTF32-V', 'UniKS-UTF8-H', 'UniKS-UTF8-V', 'V', 'WP-Symbol']; @@ -23602,7 +27363,7 @@ var CMapFactory = function CMapFactoryClosure() { exports.CMapFactory = CMapFactory; /***/ }), -/* 29 */ +/* 30 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -23616,23 +27377,23 @@ exports.IdentityToUnicodeMap = exports.ToUnicodeMap = exports.FontFlags = export var _util = __w_pdfjs_require__(2); -var _cff_parser = __w_pdfjs_require__(30); +var _cff_parser = __w_pdfjs_require__(31); -var _glyphlist = __w_pdfjs_require__(33); +var _glyphlist = __w_pdfjs_require__(34); -var _encodings = __w_pdfjs_require__(32); +var _encodings = __w_pdfjs_require__(33); -var _standard_fonts = __w_pdfjs_require__(34); +var _standard_fonts = __w_pdfjs_require__(35); -var _unicode = __w_pdfjs_require__(35); +var _unicode = __w_pdfjs_require__(36); -var _font_renderer = __w_pdfjs_require__(36); +var _font_renderer = __w_pdfjs_require__(37); -var _cmap = __w_pdfjs_require__(28); +var _cmap = __w_pdfjs_require__(29); -var _stream = __w_pdfjs_require__(13); +var _stream = __w_pdfjs_require__(14); -var _type1_parser = __w_pdfjs_require__(37); +var _type1_parser = __w_pdfjs_require__(38); const PRIVATE_USE_AREAS = [[0xE000, 0xF8FF], [0x100000, 0x10FFFD]]; var PDF_GLYPH_SPACE_UNITS = 1000; @@ -24611,7 +28372,7 @@ var Font = function FontClosure() { this.black = name.search(/Black/g) !== -1; this.remeasure = Object.keys(this.widths).length > 0; - if (isStandardFont && type === 'CIDFontType2' && this.cidEncoding.startsWith('Identity-')) { + if (isStandardFont && type === 'CIDFontType2' && this.cidEncoding.indexOf('Identity-') === 0) { var GlyphMapForStandardFonts = (0, _standard_fonts.getGlyphMapForStandardFonts)(); var map = []; @@ -26753,7 +30514,7 @@ var CFFFont = function CFFFontClosure() { }(); /***/ }), -/* 30 */ +/* 31 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -26766,9 +30527,9 @@ exports.CFFFDSelect = exports.CFFCompiler = exports.CFFPrivateDict = exports.CFF var _util = __w_pdfjs_require__(2); -var _charsets = __w_pdfjs_require__(31); +var _charsets = __w_pdfjs_require__(32); -var _encodings = __w_pdfjs_require__(32); +var _encodings = __w_pdfjs_require__(33); var MAX_SUBR_NESTING = 10; var CFFStandardStrings = ['.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent', 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright', 'asciicircum', 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent', 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency', 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl', 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase', 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis', 'perthousand', 'questiondown', 'grave', 'acute', 'circumflex', 'tilde', 'macron', 'breve', 'dotaccent', 'dieresis', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron', 'emdash', 'AE', 'ordfeminine', 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae', 'dotlessi', 'lslash', 'oslash', 'oe', 'germandbls', 'onesuperior', 'logicalnot', 'mu', 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn', 'onequarter', 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters', 'twosuperior', 'registered', 'minus', 'eth', 'multiply', 'threesuperior', 'copyright', 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring', 'Atilde', 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave', 'Iacute', 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute', 'Ocircumflex', 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute', 'Ucircumflex', 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron', 'aacute', 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde', 'ccedilla', 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute', 'icircumflex', 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex', 'odieresis', 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex', 'udieresis', 'ugrave', 'yacute', 'ydieresis', 'zcaron', 'exclamsmall', 'Hungarumlautsmall', 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'zerooldstyle', 'oneoldstyle', 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'commasuperior', 'threequartersemdash', 'periodsuperior', 'questionsmall', 'asuperior', 'bsuperior', 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior', 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior', 'tsuperior', 'ff', 'ffi', 'ffl', 'parenleftinferior', 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall', 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah', 'Tildesmall', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall', 'Caronsmall', 'Dotaccentsmall', 'Macronsmall', 'figuredash', 'hypheninferior', 'Ogoneksmall', 'Ringsmall', 'Cedillasmall', 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths', 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'foursuperior', 'fivesuperior', 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior', 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior', 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior', 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior', 'periodinferior', 'commainferior', 'Agravesmall', 'Aacutesmall', 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall', 'Aringsmall', 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall', 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall', 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall', 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall', 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall', 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall', 'Ydieresissmall', '001.000', '001.001', '001.002', '001.003', 'Black', 'Bold', 'Book', 'Light', 'Medium', 'Regular', 'Roman', 'Semibold']; @@ -28507,7 +32268,7 @@ var CFFCompiler = function CFFCompilerClosure() { exports.CFFCompiler = CFFCompiler; /***/ }), -/* 31 */ +/* 32 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -28525,7 +32286,7 @@ const ExpertSubsetCharset = ['.notdef', 'space', 'dollaroldstyle', 'dollarsuperi exports.ExpertSubsetCharset = ExpertSubsetCharset; /***/ }), -/* 32 */ +/* 33 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -28579,7 +32340,7 @@ function getEncoding(encodingName) { } /***/ }), -/* 33 */ +/* 34 */ /***/ (function(module, exports, __w_pdfjs_require__) { var getLookupTableFactory = __w_pdfjs_require__(2).getLookupTableFactory; @@ -33115,7 +36876,7 @@ exports.getGlyphsUnicode = getGlyphsUnicode; exports.getDingbatsGlyphsUnicode = getDingbatsGlyphsUnicode; /***/ }), -/* 34 */ +/* 35 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -33858,7 +37619,7 @@ const getSupplementalGlyphMapForCalibri = (0, _util.getLookupTableFactory)(funct exports.getSupplementalGlyphMapForCalibri = getSupplementalGlyphMapForCalibri; /***/ }), -/* 35 */ +/* 36 */ /***/ (function(module, exports, __w_pdfjs_require__) { var getLookupTableFactory = __w_pdfjs_require__(2).getLookupTableFactory; @@ -35835,7 +39596,7 @@ exports.getNormalizedUnicodes = getNormalizedUnicodes; exports.getUnicodeForGlyph = getUnicodeForGlyph; /***/ }), -/* 36 */ +/* 37 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -35848,13 +39609,13 @@ exports.FontRendererFactory = void 0; var _util = __w_pdfjs_require__(2); -var _cff_parser = __w_pdfjs_require__(30); +var _cff_parser = __w_pdfjs_require__(31); -var _glyphlist = __w_pdfjs_require__(33); +var _glyphlist = __w_pdfjs_require__(34); -var _encodings = __w_pdfjs_require__(32); +var _encodings = __w_pdfjs_require__(33); -var _stream = __w_pdfjs_require__(13); +var _stream = __w_pdfjs_require__(14); var FontRendererFactory = function FontRendererFactoryClosure() { function getLong(data, offset) { @@ -36789,7 +40550,7 @@ var FontRendererFactory = function FontRendererFactoryClosure() { exports.FontRendererFactory = FontRendererFactory; /***/ }), -/* 37 */ +/* 38 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -36802,9 +40563,9 @@ exports.Type1Parser = void 0; var _util = __w_pdfjs_require__(2); -var _encodings = __w_pdfjs_require__(32); +var _encodings = __w_pdfjs_require__(33); -var _stream = __w_pdfjs_require__(13); +var _stream = __w_pdfjs_require__(14); var HINTING_ENABLED = false; @@ -37484,7 +41245,7 @@ var Type1Parser = function Type1ParserClosure() { exports.Type1Parser = Type1Parser; /***/ }), -/* 38 */ +/* 39 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -37498,9 +41259,9 @@ exports.Pattern = void 0; var _util = __w_pdfjs_require__(2); -var _colorspace = __w_pdfjs_require__(24); +var _colorspace = __w_pdfjs_require__(25); -var _primitives = __w_pdfjs_require__(11); +var _primitives = __w_pdfjs_require__(12); var ShadingType = { FUNCTION_BASED: 1, @@ -38406,7 +42167,7 @@ function getTilingPatternIR(operatorList, dict, args) { } /***/ }), -/* 39 */ +/* 40 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -38710,7 +42471,7 @@ function bidi(str, startLevel, vertical) { } /***/ }), -/* 40 */ +/* 41 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -41664,7 +45425,7 @@ var getMetrics = (0, _util.getLookupTableFactory)(function (t) { exports.getMetrics = getMetrics; /***/ }), -/* 41 */ +/* 42 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -41678,9 +45439,9 @@ exports.PostScriptCompiler = exports.PostScriptEvaluator = exports.PDFFunctionFa var _util = __w_pdfjs_require__(2); -var _primitives = __w_pdfjs_require__(11); +var _primitives = __w_pdfjs_require__(12); -var _ps_parser = __w_pdfjs_require__(42); +var _ps_parser = __w_pdfjs_require__(43); let IsEvalSupportedCached = { get value() { @@ -43022,7 +46783,7 @@ var PostScriptCompiler = function PostScriptCompilerClosure() { exports.PostScriptCompiler = PostScriptCompiler; /***/ }), -/* 42 */ +/* 43 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -43035,7 +46796,7 @@ exports.PostScriptParser = exports.PostScriptLexer = void 0; var _util = __w_pdfjs_require__(2); -var _primitives = __w_pdfjs_require__(11); +var _primitives = __w_pdfjs_require__(12); class PostScriptParser { constructor(lexer) { @@ -43274,7 +47035,7 @@ class PostScriptLexer { exports.PostScriptLexer = PostScriptLexer; /***/ }), -/* 43 */ +/* 44 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -43411,7 +47172,7 @@ var MurmurHash3_64 = function MurmurHash3_64Closure(seed) { exports.MurmurHash3_64 = MurmurHash3_64; /***/ }), -/* 44 */ +/* 45 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -43424,15 +47185,15 @@ exports.PDFImage = void 0; var _util = __w_pdfjs_require__(2); -var _primitives = __w_pdfjs_require__(11); +var _primitives = __w_pdfjs_require__(12); -var _colorspace = __w_pdfjs_require__(24); +var _colorspace = __w_pdfjs_require__(25); -var _stream = __w_pdfjs_require__(13); +var _stream = __w_pdfjs_require__(14); -var _jpeg_stream = __w_pdfjs_require__(19); +var _jpeg_stream = __w_pdfjs_require__(20); -var _jpx = __w_pdfjs_require__(22); +var _jpx = __w_pdfjs_require__(23); var PDFImage = function PDFImageClosure() { function handleImageData(image, nativeDecoder) { @@ -44070,7 +47831,7 @@ var PDFImage = function PDFImageClosure() { exports.PDFImage = PDFImage; /***/ }), -/* 45 */ +/* 46 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; @@ -44081,7 +47842,7 @@ module.exports = function isNodeJS() { }; /***/ }), -/* 46 */ +/* 47 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; diff --git a/browser/extensions/pdfjs/content/build/streams_polyfill.js b/browser/extensions/pdfjs/content/build/streams_polyfill.js deleted file mode 100644 index 31921f1a03ae..000000000000 --- a/browser/extensions/pdfjs/content/build/streams_polyfill.js +++ /dev/null @@ -1,3875 +0,0 @@ -/** - * @licstart The following is the entire license notice for the - * Javascript code in this page - * - * Copyright 2018 Mozilla Foundation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * @licend The above is the entire license notice for the - * Javascript code in this page - */ - -/******/ (function(modules) { // webpackBootstrap -/******/ // The module cache -/******/ var installedModules = {}; -/******/ -/******/ // The require function -/******/ function __webpack_require__(moduleId) { -/******/ -/******/ // Check if module is in cache -/******/ if(installedModules[moduleId]) { -/******/ return installedModules[moduleId].exports; -/******/ } -/******/ // Create a new module (and put it into the cache) -/******/ var module = installedModules[moduleId] = { -/******/ i: moduleId, -/******/ l: false, -/******/ exports: {} -/******/ }; -/******/ -/******/ // Execute the module function -/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); -/******/ -/******/ // Flag the module as loaded -/******/ module.l = true; -/******/ -/******/ // Return the exports of the module -/******/ return module.exports; -/******/ } -/******/ -/******/ -/******/ // expose the modules object (__webpack_modules__) -/******/ __webpack_require__.m = modules; -/******/ -/******/ // expose the module cache -/******/ __webpack_require__.c = installedModules; -/******/ -/******/ // define getter function for harmony exports -/******/ __webpack_require__.d = function(exports, name, getter) { -/******/ if(!__webpack_require__.o(exports, name)) { -/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); -/******/ } -/******/ }; -/******/ -/******/ // define __esModule on exports -/******/ __webpack_require__.r = function(exports) { -/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { -/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); -/******/ } -/******/ Object.defineProperty(exports, '__esModule', { value: true }); -/******/ }; -/******/ -/******/ // create a fake namespace object -/******/ // mode & 1: value is a module id, require it -/******/ // mode & 2: merge all properties of value into the ns -/******/ // mode & 4: return value when already ns object -/******/ // mode & 8|1: behave like require -/******/ __webpack_require__.t = function(value, mode) { -/******/ if(mode & 1) value = __webpack_require__(value); -/******/ if(mode & 8) return value; -/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; -/******/ var ns = Object.create(null); -/******/ __webpack_require__.r(ns); -/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); -/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); -/******/ return ns; -/******/ }; -/******/ -/******/ // getDefaultExport function for compatibility with non-harmony modules -/******/ __webpack_require__.n = function(module) { -/******/ var getter = module && module.__esModule ? -/******/ function getDefault() { return module['default']; } : -/******/ function getModuleExports() { return module; }; -/******/ __webpack_require__.d(getter, 'a', getter); -/******/ return getter; -/******/ }; -/******/ -/******/ // Object.prototype.hasOwnProperty.call -/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; -/******/ -/******/ // __webpack_public_path__ -/******/ __webpack_require__.p = ""; -/******/ -/******/ -/******/ // Load entry module and return exports -/******/ return __webpack_require__(__webpack_require__.s = 0); -/******/ }) -/************************************************************************/ -/******/ ([ -/* 0 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - - -if (typeof ReadableStream === "undefined") { - __webpack_require__(1).ReadableStream = __webpack_require__(2).ReadableStream; -} - -/***/ }), -/* 1 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - - -module.exports = typeof window !== 'undefined' && window.Math === Math ? window : typeof global !== 'undefined' && global.Math === Math ? global : typeof self !== 'undefined' && self.Math === Math ? self : {}; - -/***/ }), -/* 2 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - - -(function (e, a) { - for (var i in a) e[i] = a[i]; -})(exports, function (modules) { - var installedModules = {}; - - function __webpack_require__(moduleId) { - if (installedModules[moduleId]) return installedModules[moduleId].exports; - var module = installedModules[moduleId] = { - i: moduleId, - l: false, - exports: {} - }; - modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); - module.l = true; - return module.exports; - } - - __webpack_require__.m = modules; - __webpack_require__.c = installedModules; - - __webpack_require__.i = function (value) { - return value; - }; - - __webpack_require__.d = function (exports, name, getter) { - if (!__webpack_require__.o(exports, name)) { - Object.defineProperty(exports, name, { - configurable: false, - enumerable: true, - get: getter - }); - } - }; - - __webpack_require__.n = function (module) { - var getter = module && module.__esModule ? function getDefault() { - return module['default']; - } : function getModuleExports() { - return module; - }; - - __webpack_require__.d(getter, 'a', getter); - - return getter; - }; - - __webpack_require__.o = function (object, property) { - return Object.prototype.hasOwnProperty.call(object, property); - }; - - __webpack_require__.p = ""; - return __webpack_require__(__webpack_require__.s = 7); -}([function (module, exports, __webpack_require__) { - "use strict"; - - var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { - return typeof obj; - } : function (obj) { - return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; - }; - - var _require = __webpack_require__(1), - assert = _require.assert; - - function IsPropertyKey(argument) { - return typeof argument === 'string' || (typeof argument === 'undefined' ? 'undefined' : _typeof(argument)) === 'symbol'; - } - - exports.typeIsObject = function (x) { - return (typeof x === 'undefined' ? 'undefined' : _typeof(x)) === 'object' && x !== null || typeof x === 'function'; - }; - - exports.createDataProperty = function (o, p, v) { - assert(exports.typeIsObject(o)); - Object.defineProperty(o, p, { - value: v, - writable: true, - enumerable: true, - configurable: true - }); - }; - - exports.createArrayFromList = function (elements) { - return elements.slice(); - }; - - exports.ArrayBufferCopy = function (dest, destOffset, src, srcOffset, n) { - new Uint8Array(dest).set(new Uint8Array(src, srcOffset, n), destOffset); - }; - - exports.CreateIterResultObject = function (value, done) { - assert(typeof done === 'boolean'); - var obj = {}; - Object.defineProperty(obj, 'value', { - value: value, - enumerable: true, - writable: true, - configurable: true - }); - Object.defineProperty(obj, 'done', { - value: done, - enumerable: true, - writable: true, - configurable: true - }); - return obj; - }; - - exports.IsFiniteNonNegativeNumber = function (v) { - if (Number.isNaN(v)) { - return false; - } - - if (v === Infinity) { - return false; - } - - if (v < 0) { - return false; - } - - return true; - }; - - function Call(F, V, args) { - if (typeof F !== 'function') { - throw new TypeError('Argument is not a function'); - } - - return Function.prototype.apply.call(F, V, args); - } - - exports.InvokeOrNoop = function (O, P, args) { - assert(O !== undefined); - assert(IsPropertyKey(P)); - assert(Array.isArray(args)); - var method = O[P]; - - if (method === undefined) { - return undefined; - } - - return Call(method, O, args); - }; - - exports.PromiseInvokeOrNoop = function (O, P, args) { - assert(O !== undefined); - assert(IsPropertyKey(P)); - assert(Array.isArray(args)); - - try { - return Promise.resolve(exports.InvokeOrNoop(O, P, args)); - } catch (returnValueE) { - return Promise.reject(returnValueE); - } - }; - - exports.PromiseInvokeOrPerformFallback = function (O, P, args, F, argsF) { - assert(O !== undefined); - assert(IsPropertyKey(P)); - assert(Array.isArray(args)); - assert(Array.isArray(argsF)); - var method = void 0; - - try { - method = O[P]; - } catch (methodE) { - return Promise.reject(methodE); - } - - if (method === undefined) { - return F.apply(null, argsF); - } - - try { - return Promise.resolve(Call(method, O, args)); - } catch (e) { - return Promise.reject(e); - } - }; - - exports.TransferArrayBuffer = function (O) { - return O.slice(); - }; - - exports.ValidateAndNormalizeHighWaterMark = function (highWaterMark) { - highWaterMark = Number(highWaterMark); - - if (Number.isNaN(highWaterMark) || highWaterMark < 0) { - throw new RangeError('highWaterMark property of a queuing strategy must be non-negative and non-NaN'); - } - - return highWaterMark; - }; - - exports.ValidateAndNormalizeQueuingStrategy = function (size, highWaterMark) { - if (size !== undefined && typeof size !== 'function') { - throw new TypeError('size property of a queuing strategy must be a function'); - } - - highWaterMark = exports.ValidateAndNormalizeHighWaterMark(highWaterMark); - return { - size: size, - highWaterMark: highWaterMark - }; - }; -}, function (module, exports, __webpack_require__) { - "use strict"; - - function rethrowAssertionErrorRejection(e) { - if (e && e.constructor === AssertionError) { - setTimeout(function () { - throw e; - }, 0); - } - } - - function AssertionError(message) { - this.name = 'AssertionError'; - this.message = message || ''; - this.stack = new Error().stack; - } - - AssertionError.prototype = Object.create(Error.prototype); - AssertionError.prototype.constructor = AssertionError; - - function assert(value, message) { - if (!value) { - throw new AssertionError(message); - } - } - - module.exports = { - rethrowAssertionErrorRejection: rethrowAssertionErrorRejection, - AssertionError: AssertionError, - assert: assert - }; -}, function (module, exports, __webpack_require__) { - "use strict"; - - var _createClass = function () { - function defineProperties(target, props) { - for (var i = 0; i < props.length; i++) { - var descriptor = props[i]; - descriptor.enumerable = descriptor.enumerable || false; - descriptor.configurable = true; - if ("value" in descriptor) descriptor.writable = true; - Object.defineProperty(target, descriptor.key, descriptor); - } - } - - return function (Constructor, protoProps, staticProps) { - if (protoProps) defineProperties(Constructor.prototype, protoProps); - if (staticProps) defineProperties(Constructor, staticProps); - return Constructor; - }; - }(); - - function _classCallCheck(instance, Constructor) { - if (!(instance instanceof Constructor)) { - throw new TypeError("Cannot call a class as a function"); - } - } - - var _require = __webpack_require__(0), - InvokeOrNoop = _require.InvokeOrNoop, - PromiseInvokeOrNoop = _require.PromiseInvokeOrNoop, - ValidateAndNormalizeQueuingStrategy = _require.ValidateAndNormalizeQueuingStrategy, - typeIsObject = _require.typeIsObject; - - var _require2 = __webpack_require__(1), - assert = _require2.assert, - rethrowAssertionErrorRejection = _require2.rethrowAssertionErrorRejection; - - var _require3 = __webpack_require__(3), - DequeueValue = _require3.DequeueValue, - EnqueueValueWithSize = _require3.EnqueueValueWithSize, - PeekQueueValue = _require3.PeekQueueValue, - ResetQueue = _require3.ResetQueue; - - var WritableStream = function () { - function WritableStream() { - var underlyingSink = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - - var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, - size = _ref.size, - _ref$highWaterMark = _ref.highWaterMark, - highWaterMark = _ref$highWaterMark === undefined ? 1 : _ref$highWaterMark; - - _classCallCheck(this, WritableStream); - - this._state = 'writable'; - this._storedError = undefined; - this._writer = undefined; - this._writableStreamController = undefined; - this._writeRequests = []; - this._inFlightWriteRequest = undefined; - this._closeRequest = undefined; - this._inFlightCloseRequest = undefined; - this._pendingAbortRequest = undefined; - this._backpressure = false; - var type = underlyingSink.type; - - if (type !== undefined) { - throw new RangeError('Invalid type is specified'); - } - - this._writableStreamController = new WritableStreamDefaultController(this, underlyingSink, size, highWaterMark); - - this._writableStreamController.__startSteps(); - } - - _createClass(WritableStream, [{ - key: 'abort', - value: function abort(reason) { - if (IsWritableStream(this) === false) { - return Promise.reject(streamBrandCheckException('abort')); - } - - if (IsWritableStreamLocked(this) === true) { - return Promise.reject(new TypeError('Cannot abort a stream that already has a writer')); - } - - return WritableStreamAbort(this, reason); - } - }, { - key: 'getWriter', - value: function getWriter() { - if (IsWritableStream(this) === false) { - throw streamBrandCheckException('getWriter'); - } - - return AcquireWritableStreamDefaultWriter(this); - } - }, { - key: 'locked', - get: function get() { - if (IsWritableStream(this) === false) { - throw streamBrandCheckException('locked'); - } - - return IsWritableStreamLocked(this); - } - }]); - - return WritableStream; - }(); - - module.exports = { - AcquireWritableStreamDefaultWriter: AcquireWritableStreamDefaultWriter, - IsWritableStream: IsWritableStream, - IsWritableStreamLocked: IsWritableStreamLocked, - WritableStream: WritableStream, - WritableStreamAbort: WritableStreamAbort, - WritableStreamDefaultControllerError: WritableStreamDefaultControllerError, - WritableStreamDefaultWriterCloseWithErrorPropagation: WritableStreamDefaultWriterCloseWithErrorPropagation, - WritableStreamDefaultWriterRelease: WritableStreamDefaultWriterRelease, - WritableStreamDefaultWriterWrite: WritableStreamDefaultWriterWrite, - WritableStreamCloseQueuedOrInFlight: WritableStreamCloseQueuedOrInFlight - }; - - function AcquireWritableStreamDefaultWriter(stream) { - return new WritableStreamDefaultWriter(stream); - } - - function IsWritableStream(x) { - if (!typeIsObject(x)) { - return false; - } - - if (!Object.prototype.hasOwnProperty.call(x, '_writableStreamController')) { - return false; - } - - return true; - } - - function IsWritableStreamLocked(stream) { - assert(IsWritableStream(stream) === true, 'IsWritableStreamLocked should only be used on known writable streams'); - - if (stream._writer === undefined) { - return false; - } - - return true; - } - - function WritableStreamAbort(stream, reason) { - var state = stream._state; - - if (state === 'closed') { - return Promise.resolve(undefined); - } - - if (state === 'errored') { - return Promise.reject(stream._storedError); - } - - var error = new TypeError('Requested to abort'); - - if (stream._pendingAbortRequest !== undefined) { - return Promise.reject(error); - } - - assert(state === 'writable' || state === 'erroring', 'state must be writable or erroring'); - var wasAlreadyErroring = false; - - if (state === 'erroring') { - wasAlreadyErroring = true; - reason = undefined; - } - - var promise = new Promise(function (resolve, reject) { - stream._pendingAbortRequest = { - _resolve: resolve, - _reject: reject, - _reason: reason, - _wasAlreadyErroring: wasAlreadyErroring - }; - }); - - if (wasAlreadyErroring === false) { - WritableStreamStartErroring(stream, error); - } - - return promise; - } - - function WritableStreamAddWriteRequest(stream) { - assert(IsWritableStreamLocked(stream) === true); - assert(stream._state === 'writable'); - var promise = new Promise(function (resolve, reject) { - var writeRequest = { - _resolve: resolve, - _reject: reject - }; - - stream._writeRequests.push(writeRequest); - }); - return promise; - } - - function WritableStreamDealWithRejection(stream, error) { - var state = stream._state; - - if (state === 'writable') { - WritableStreamStartErroring(stream, error); - return; - } - - assert(state === 'erroring'); - WritableStreamFinishErroring(stream); - } - - function WritableStreamStartErroring(stream, reason) { - assert(stream._storedError === undefined, 'stream._storedError === undefined'); - assert(stream._state === 'writable', 'state must be writable'); - var controller = stream._writableStreamController; - assert(controller !== undefined, 'controller must not be undefined'); - stream._state = 'erroring'; - stream._storedError = reason; - var writer = stream._writer; - - if (writer !== undefined) { - WritableStreamDefaultWriterEnsureReadyPromiseRejected(writer, reason); - } - - if (WritableStreamHasOperationMarkedInFlight(stream) === false && controller._started === true) { - WritableStreamFinishErroring(stream); - } - } - - function WritableStreamFinishErroring(stream) { - assert(stream._state === 'erroring', 'stream._state === erroring'); - assert(WritableStreamHasOperationMarkedInFlight(stream) === false, 'WritableStreamHasOperationMarkedInFlight(stream) === false'); - stream._state = 'errored'; - - stream._writableStreamController.__errorSteps(); - - var storedError = stream._storedError; - - for (var i = 0; i < stream._writeRequests.length; i++) { - var writeRequest = stream._writeRequests[i]; - - writeRequest._reject(storedError); - } - - stream._writeRequests = []; - - if (stream._pendingAbortRequest === undefined) { - WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream); - return; - } - - var abortRequest = stream._pendingAbortRequest; - stream._pendingAbortRequest = undefined; - - if (abortRequest._wasAlreadyErroring === true) { - abortRequest._reject(storedError); - - WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream); - return; - } - - var promise = stream._writableStreamController.__abortSteps(abortRequest._reason); - - promise.then(function () { - abortRequest._resolve(); - - WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream); - }, function (reason) { - abortRequest._reject(reason); - - WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream); - }); - } - - function WritableStreamFinishInFlightWrite(stream) { - assert(stream._inFlightWriteRequest !== undefined); - - stream._inFlightWriteRequest._resolve(undefined); - - stream._inFlightWriteRequest = undefined; - } - - function WritableStreamFinishInFlightWriteWithError(stream, error) { - assert(stream._inFlightWriteRequest !== undefined); - - stream._inFlightWriteRequest._reject(error); - - stream._inFlightWriteRequest = undefined; - assert(stream._state === 'writable' || stream._state === 'erroring'); - WritableStreamDealWithRejection(stream, error); - } - - function WritableStreamFinishInFlightClose(stream) { - assert(stream._inFlightCloseRequest !== undefined); - - stream._inFlightCloseRequest._resolve(undefined); - - stream._inFlightCloseRequest = undefined; - var state = stream._state; - assert(state === 'writable' || state === 'erroring'); - - if (state === 'erroring') { - stream._storedError = undefined; - - if (stream._pendingAbortRequest !== undefined) { - stream._pendingAbortRequest._resolve(); - - stream._pendingAbortRequest = undefined; - } - } - - stream._state = 'closed'; - var writer = stream._writer; - - if (writer !== undefined) { - defaultWriterClosedPromiseResolve(writer); - } - - assert(stream._pendingAbortRequest === undefined, 'stream._pendingAbortRequest === undefined'); - assert(stream._storedError === undefined, 'stream._storedError === undefined'); - } - - function WritableStreamFinishInFlightCloseWithError(stream, error) { - assert(stream._inFlightCloseRequest !== undefined); - - stream._inFlightCloseRequest._reject(error); - - stream._inFlightCloseRequest = undefined; - assert(stream._state === 'writable' || stream._state === 'erroring'); - - if (stream._pendingAbortRequest !== undefined) { - stream._pendingAbortRequest._reject(error); - - stream._pendingAbortRequest = undefined; - } - - WritableStreamDealWithRejection(stream, error); - } - - function WritableStreamCloseQueuedOrInFlight(stream) { - if (stream._closeRequest === undefined && stream._inFlightCloseRequest === undefined) { - return false; - } - - return true; - } - - function WritableStreamHasOperationMarkedInFlight(stream) { - if (stream._inFlightWriteRequest === undefined && stream._inFlightCloseRequest === undefined) { - return false; - } - - return true; - } - - function WritableStreamMarkCloseRequestInFlight(stream) { - assert(stream._inFlightCloseRequest === undefined); - assert(stream._closeRequest !== undefined); - stream._inFlightCloseRequest = stream._closeRequest; - stream._closeRequest = undefined; - } - - function WritableStreamMarkFirstWriteRequestInFlight(stream) { - assert(stream._inFlightWriteRequest === undefined, 'there must be no pending write request'); - assert(stream._writeRequests.length !== 0, 'writeRequests must not be empty'); - stream._inFlightWriteRequest = stream._writeRequests.shift(); - } - - function WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream) { - assert(stream._state === 'errored', '_stream_.[[state]] is `"errored"`'); - - if (stream._closeRequest !== undefined) { - assert(stream._inFlightCloseRequest === undefined); - - stream._closeRequest._reject(stream._storedError); - - stream._closeRequest = undefined; - } - - var writer = stream._writer; - - if (writer !== undefined) { - defaultWriterClosedPromiseReject(writer, stream._storedError); - - writer._closedPromise.catch(function () {}); - } - } - - function WritableStreamUpdateBackpressure(stream, backpressure) { - assert(stream._state === 'writable'); - assert(WritableStreamCloseQueuedOrInFlight(stream) === false); - var writer = stream._writer; - - if (writer !== undefined && backpressure !== stream._backpressure) { - if (backpressure === true) { - defaultWriterReadyPromiseReset(writer); - } else { - assert(backpressure === false); - defaultWriterReadyPromiseResolve(writer); - } - } - - stream._backpressure = backpressure; - } - - var WritableStreamDefaultWriter = function () { - function WritableStreamDefaultWriter(stream) { - _classCallCheck(this, WritableStreamDefaultWriter); - - if (IsWritableStream(stream) === false) { - throw new TypeError('WritableStreamDefaultWriter can only be constructed with a WritableStream instance'); - } - - if (IsWritableStreamLocked(stream) === true) { - throw new TypeError('This stream has already been locked for exclusive writing by another writer'); - } - - this._ownerWritableStream = stream; - stream._writer = this; - var state = stream._state; - - if (state === 'writable') { - if (WritableStreamCloseQueuedOrInFlight(stream) === false && stream._backpressure === true) { - defaultWriterReadyPromiseInitialize(this); - } else { - defaultWriterReadyPromiseInitializeAsResolved(this); - } - - defaultWriterClosedPromiseInitialize(this); - } else if (state === 'erroring') { - defaultWriterReadyPromiseInitializeAsRejected(this, stream._storedError); - - this._readyPromise.catch(function () {}); - - defaultWriterClosedPromiseInitialize(this); - } else if (state === 'closed') { - defaultWriterReadyPromiseInitializeAsResolved(this); - defaultWriterClosedPromiseInitializeAsResolved(this); - } else { - assert(state === 'errored', 'state must be errored'); - var storedError = stream._storedError; - defaultWriterReadyPromiseInitializeAsRejected(this, storedError); - - this._readyPromise.catch(function () {}); - - defaultWriterClosedPromiseInitializeAsRejected(this, storedError); - - this._closedPromise.catch(function () {}); - } - } - - _createClass(WritableStreamDefaultWriter, [{ - key: 'abort', - value: function abort(reason) { - if (IsWritableStreamDefaultWriter(this) === false) { - return Promise.reject(defaultWriterBrandCheckException('abort')); - } - - if (this._ownerWritableStream === undefined) { - return Promise.reject(defaultWriterLockException('abort')); - } - - return WritableStreamDefaultWriterAbort(this, reason); - } - }, { - key: 'close', - value: function close() { - if (IsWritableStreamDefaultWriter(this) === false) { - return Promise.reject(defaultWriterBrandCheckException('close')); - } - - var stream = this._ownerWritableStream; - - if (stream === undefined) { - return Promise.reject(defaultWriterLockException('close')); - } - - if (WritableStreamCloseQueuedOrInFlight(stream) === true) { - return Promise.reject(new TypeError('cannot close an already-closing stream')); - } - - return WritableStreamDefaultWriterClose(this); - } - }, { - key: 'releaseLock', - value: function releaseLock() { - if (IsWritableStreamDefaultWriter(this) === false) { - throw defaultWriterBrandCheckException('releaseLock'); - } - - var stream = this._ownerWritableStream; - - if (stream === undefined) { - return; - } - - assert(stream._writer !== undefined); - WritableStreamDefaultWriterRelease(this); - } - }, { - key: 'write', - value: function write(chunk) { - if (IsWritableStreamDefaultWriter(this) === false) { - return Promise.reject(defaultWriterBrandCheckException('write')); - } - - if (this._ownerWritableStream === undefined) { - return Promise.reject(defaultWriterLockException('write to')); - } - - return WritableStreamDefaultWriterWrite(this, chunk); - } - }, { - key: 'closed', - get: function get() { - if (IsWritableStreamDefaultWriter(this) === false) { - return Promise.reject(defaultWriterBrandCheckException('closed')); - } - - return this._closedPromise; - } - }, { - key: 'desiredSize', - get: function get() { - if (IsWritableStreamDefaultWriter(this) === false) { - throw defaultWriterBrandCheckException('desiredSize'); - } - - if (this._ownerWritableStream === undefined) { - throw defaultWriterLockException('desiredSize'); - } - - return WritableStreamDefaultWriterGetDesiredSize(this); - } - }, { - key: 'ready', - get: function get() { - if (IsWritableStreamDefaultWriter(this) === false) { - return Promise.reject(defaultWriterBrandCheckException('ready')); - } - - return this._readyPromise; - } - }]); - - return WritableStreamDefaultWriter; - }(); - - function IsWritableStreamDefaultWriter(x) { - if (!typeIsObject(x)) { - return false; - } - - if (!Object.prototype.hasOwnProperty.call(x, '_ownerWritableStream')) { - return false; - } - - return true; - } - - function WritableStreamDefaultWriterAbort(writer, reason) { - var stream = writer._ownerWritableStream; - assert(stream !== undefined); - return WritableStreamAbort(stream, reason); - } - - function WritableStreamDefaultWriterClose(writer) { - var stream = writer._ownerWritableStream; - assert(stream !== undefined); - var state = stream._state; - - if (state === 'closed' || state === 'errored') { - return Promise.reject(new TypeError('The stream (in ' + state + ' state) is not in the writable state and cannot be closed')); - } - - assert(state === 'writable' || state === 'erroring'); - assert(WritableStreamCloseQueuedOrInFlight(stream) === false); - var promise = new Promise(function (resolve, reject) { - var closeRequest = { - _resolve: resolve, - _reject: reject - }; - stream._closeRequest = closeRequest; - }); - - if (stream._backpressure === true && state === 'writable') { - defaultWriterReadyPromiseResolve(writer); - } - - WritableStreamDefaultControllerClose(stream._writableStreamController); - return promise; - } - - function WritableStreamDefaultWriterCloseWithErrorPropagation(writer) { - var stream = writer._ownerWritableStream; - assert(stream !== undefined); - var state = stream._state; - - if (WritableStreamCloseQueuedOrInFlight(stream) === true || state === 'closed') { - return Promise.resolve(); - } - - if (state === 'errored') { - return Promise.reject(stream._storedError); - } - - assert(state === 'writable' || state === 'erroring'); - return WritableStreamDefaultWriterClose(writer); - } - - function WritableStreamDefaultWriterEnsureClosedPromiseRejected(writer, error) { - if (writer._closedPromiseState === 'pending') { - defaultWriterClosedPromiseReject(writer, error); - } else { - defaultWriterClosedPromiseResetToRejected(writer, error); - } - - writer._closedPromise.catch(function () {}); - } - - function WritableStreamDefaultWriterEnsureReadyPromiseRejected(writer, error) { - if (writer._readyPromiseState === 'pending') { - defaultWriterReadyPromiseReject(writer, error); - } else { - defaultWriterReadyPromiseResetToRejected(writer, error); - } - - writer._readyPromise.catch(function () {}); - } - - function WritableStreamDefaultWriterGetDesiredSize(writer) { - var stream = writer._ownerWritableStream; - var state = stream._state; - - if (state === 'errored' || state === 'erroring') { - return null; - } - - if (state === 'closed') { - return 0; - } - - return WritableStreamDefaultControllerGetDesiredSize(stream._writableStreamController); - } - - function WritableStreamDefaultWriterRelease(writer) { - var stream = writer._ownerWritableStream; - assert(stream !== undefined); - assert(stream._writer === writer); - var releasedError = new TypeError('Writer was released and can no longer be used to monitor the stream\'s closedness'); - WritableStreamDefaultWriterEnsureReadyPromiseRejected(writer, releasedError); - WritableStreamDefaultWriterEnsureClosedPromiseRejected(writer, releasedError); - stream._writer = undefined; - writer._ownerWritableStream = undefined; - } - - function WritableStreamDefaultWriterWrite(writer, chunk) { - var stream = writer._ownerWritableStream; - assert(stream !== undefined); - var controller = stream._writableStreamController; - var chunkSize = WritableStreamDefaultControllerGetChunkSize(controller, chunk); - - if (stream !== writer._ownerWritableStream) { - return Promise.reject(defaultWriterLockException('write to')); - } - - var state = stream._state; - - if (state === 'errored') { - return Promise.reject(stream._storedError); - } - - if (WritableStreamCloseQueuedOrInFlight(stream) === true || state === 'closed') { - return Promise.reject(new TypeError('The stream is closing or closed and cannot be written to')); - } - - if (state === 'erroring') { - return Promise.reject(stream._storedError); - } - - assert(state === 'writable'); - var promise = WritableStreamAddWriteRequest(stream); - WritableStreamDefaultControllerWrite(controller, chunk, chunkSize); - return promise; - } - - var WritableStreamDefaultController = function () { - function WritableStreamDefaultController(stream, underlyingSink, size, highWaterMark) { - _classCallCheck(this, WritableStreamDefaultController); - - if (IsWritableStream(stream) === false) { - throw new TypeError('WritableStreamDefaultController can only be constructed with a WritableStream instance'); - } - - if (stream._writableStreamController !== undefined) { - throw new TypeError('WritableStreamDefaultController instances can only be created by the WritableStream constructor'); - } - - this._controlledWritableStream = stream; - this._underlyingSink = underlyingSink; - this._queue = undefined; - this._queueTotalSize = undefined; - ResetQueue(this); - this._started = false; - var normalizedStrategy = ValidateAndNormalizeQueuingStrategy(size, highWaterMark); - this._strategySize = normalizedStrategy.size; - this._strategyHWM = normalizedStrategy.highWaterMark; - var backpressure = WritableStreamDefaultControllerGetBackpressure(this); - WritableStreamUpdateBackpressure(stream, backpressure); - } - - _createClass(WritableStreamDefaultController, [{ - key: 'error', - value: function error(e) { - if (IsWritableStreamDefaultController(this) === false) { - throw new TypeError('WritableStreamDefaultController.prototype.error can only be used on a WritableStreamDefaultController'); - } - - var state = this._controlledWritableStream._state; - - if (state !== 'writable') { - return; - } - - WritableStreamDefaultControllerError(this, e); - } - }, { - key: '__abortSteps', - value: function __abortSteps(reason) { - return PromiseInvokeOrNoop(this._underlyingSink, 'abort', [reason]); - } - }, { - key: '__errorSteps', - value: function __errorSteps() { - ResetQueue(this); - } - }, { - key: '__startSteps', - value: function __startSteps() { - var _this = this; - - var startResult = InvokeOrNoop(this._underlyingSink, 'start', [this]); - var stream = this._controlledWritableStream; - Promise.resolve(startResult).then(function () { - assert(stream._state === 'writable' || stream._state === 'erroring'); - _this._started = true; - WritableStreamDefaultControllerAdvanceQueueIfNeeded(_this); - }, function (r) { - assert(stream._state === 'writable' || stream._state === 'erroring'); - _this._started = true; - WritableStreamDealWithRejection(stream, r); - }).catch(rethrowAssertionErrorRejection); - } - }]); - - return WritableStreamDefaultController; - }(); - - function WritableStreamDefaultControllerClose(controller) { - EnqueueValueWithSize(controller, 'close', 0); - WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller); - } - - function WritableStreamDefaultControllerGetChunkSize(controller, chunk) { - var strategySize = controller._strategySize; - - if (strategySize === undefined) { - return 1; - } - - try { - return strategySize(chunk); - } catch (chunkSizeE) { - WritableStreamDefaultControllerErrorIfNeeded(controller, chunkSizeE); - return 1; - } - } - - function WritableStreamDefaultControllerGetDesiredSize(controller) { - return controller._strategyHWM - controller._queueTotalSize; - } - - function WritableStreamDefaultControllerWrite(controller, chunk, chunkSize) { - var writeRecord = { - chunk: chunk - }; - - try { - EnqueueValueWithSize(controller, writeRecord, chunkSize); - } catch (enqueueE) { - WritableStreamDefaultControllerErrorIfNeeded(controller, enqueueE); - return; - } - - var stream = controller._controlledWritableStream; - - if (WritableStreamCloseQueuedOrInFlight(stream) === false && stream._state === 'writable') { - var backpressure = WritableStreamDefaultControllerGetBackpressure(controller); - WritableStreamUpdateBackpressure(stream, backpressure); - } - - WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller); - } - - function IsWritableStreamDefaultController(x) { - if (!typeIsObject(x)) { - return false; - } - - if (!Object.prototype.hasOwnProperty.call(x, '_underlyingSink')) { - return false; - } - - return true; - } - - function WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller) { - var stream = controller._controlledWritableStream; - - if (controller._started === false) { - return; - } - - if (stream._inFlightWriteRequest !== undefined) { - return; - } - - var state = stream._state; - - if (state === 'closed' || state === 'errored') { - return; - } - - if (state === 'erroring') { - WritableStreamFinishErroring(stream); - return; - } - - if (controller._queue.length === 0) { - return; - } - - var writeRecord = PeekQueueValue(controller); - - if (writeRecord === 'close') { - WritableStreamDefaultControllerProcessClose(controller); - } else { - WritableStreamDefaultControllerProcessWrite(controller, writeRecord.chunk); - } - } - - function WritableStreamDefaultControllerErrorIfNeeded(controller, error) { - if (controller._controlledWritableStream._state === 'writable') { - WritableStreamDefaultControllerError(controller, error); - } - } - - function WritableStreamDefaultControllerProcessClose(controller) { - var stream = controller._controlledWritableStream; - WritableStreamMarkCloseRequestInFlight(stream); - DequeueValue(controller); - assert(controller._queue.length === 0, 'queue must be empty once the final write record is dequeued'); - var sinkClosePromise = PromiseInvokeOrNoop(controller._underlyingSink, 'close', []); - sinkClosePromise.then(function () { - WritableStreamFinishInFlightClose(stream); - }, function (reason) { - WritableStreamFinishInFlightCloseWithError(stream, reason); - }).catch(rethrowAssertionErrorRejection); - } - - function WritableStreamDefaultControllerProcessWrite(controller, chunk) { - var stream = controller._controlledWritableStream; - WritableStreamMarkFirstWriteRequestInFlight(stream); - var sinkWritePromise = PromiseInvokeOrNoop(controller._underlyingSink, 'write', [chunk, controller]); - sinkWritePromise.then(function () { - WritableStreamFinishInFlightWrite(stream); - var state = stream._state; - assert(state === 'writable' || state === 'erroring'); - DequeueValue(controller); - - if (WritableStreamCloseQueuedOrInFlight(stream) === false && state === 'writable') { - var backpressure = WritableStreamDefaultControllerGetBackpressure(controller); - WritableStreamUpdateBackpressure(stream, backpressure); - } - - WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller); - }, function (reason) { - WritableStreamFinishInFlightWriteWithError(stream, reason); - }).catch(rethrowAssertionErrorRejection); - } - - function WritableStreamDefaultControllerGetBackpressure(controller) { - var desiredSize = WritableStreamDefaultControllerGetDesiredSize(controller); - return desiredSize <= 0; - } - - function WritableStreamDefaultControllerError(controller, error) { - var stream = controller._controlledWritableStream; - assert(stream._state === 'writable'); - WritableStreamStartErroring(stream, error); - } - - function streamBrandCheckException(name) { - return new TypeError('WritableStream.prototype.' + name + ' can only be used on a WritableStream'); - } - - function defaultWriterBrandCheckException(name) { - return new TypeError('WritableStreamDefaultWriter.prototype.' + name + ' can only be used on a WritableStreamDefaultWriter'); - } - - function defaultWriterLockException(name) { - return new TypeError('Cannot ' + name + ' a stream using a released writer'); - } - - function defaultWriterClosedPromiseInitialize(writer) { - writer._closedPromise = new Promise(function (resolve, reject) { - writer._closedPromise_resolve = resolve; - writer._closedPromise_reject = reject; - writer._closedPromiseState = 'pending'; - }); - } - - function defaultWriterClosedPromiseInitializeAsRejected(writer, reason) { - writer._closedPromise = Promise.reject(reason); - writer._closedPromise_resolve = undefined; - writer._closedPromise_reject = undefined; - writer._closedPromiseState = 'rejected'; - } - - function defaultWriterClosedPromiseInitializeAsResolved(writer) { - writer._closedPromise = Promise.resolve(undefined); - writer._closedPromise_resolve = undefined; - writer._closedPromise_reject = undefined; - writer._closedPromiseState = 'resolved'; - } - - function defaultWriterClosedPromiseReject(writer, reason) { - assert(writer._closedPromise_resolve !== undefined, 'writer._closedPromise_resolve !== undefined'); - assert(writer._closedPromise_reject !== undefined, 'writer._closedPromise_reject !== undefined'); - assert(writer._closedPromiseState === 'pending', 'writer._closedPromiseState is pending'); - - writer._closedPromise_reject(reason); - - writer._closedPromise_resolve = undefined; - writer._closedPromise_reject = undefined; - writer._closedPromiseState = 'rejected'; - } - - function defaultWriterClosedPromiseResetToRejected(writer, reason) { - assert(writer._closedPromise_resolve === undefined, 'writer._closedPromise_resolve === undefined'); - assert(writer._closedPromise_reject === undefined, 'writer._closedPromise_reject === undefined'); - assert(writer._closedPromiseState !== 'pending', 'writer._closedPromiseState is not pending'); - writer._closedPromise = Promise.reject(reason); - writer._closedPromiseState = 'rejected'; - } - - function defaultWriterClosedPromiseResolve(writer) { - assert(writer._closedPromise_resolve !== undefined, 'writer._closedPromise_resolve !== undefined'); - assert(writer._closedPromise_reject !== undefined, 'writer._closedPromise_reject !== undefined'); - assert(writer._closedPromiseState === 'pending', 'writer._closedPromiseState is pending'); - - writer._closedPromise_resolve(undefined); - - writer._closedPromise_resolve = undefined; - writer._closedPromise_reject = undefined; - writer._closedPromiseState = 'resolved'; - } - - function defaultWriterReadyPromiseInitialize(writer) { - writer._readyPromise = new Promise(function (resolve, reject) { - writer._readyPromise_resolve = resolve; - writer._readyPromise_reject = reject; - }); - writer._readyPromiseState = 'pending'; - } - - function defaultWriterReadyPromiseInitializeAsRejected(writer, reason) { - writer._readyPromise = Promise.reject(reason); - writer._readyPromise_resolve = undefined; - writer._readyPromise_reject = undefined; - writer._readyPromiseState = 'rejected'; - } - - function defaultWriterReadyPromiseInitializeAsResolved(writer) { - writer._readyPromise = Promise.resolve(undefined); - writer._readyPromise_resolve = undefined; - writer._readyPromise_reject = undefined; - writer._readyPromiseState = 'fulfilled'; - } - - function defaultWriterReadyPromiseReject(writer, reason) { - assert(writer._readyPromise_resolve !== undefined, 'writer._readyPromise_resolve !== undefined'); - assert(writer._readyPromise_reject !== undefined, 'writer._readyPromise_reject !== undefined'); - - writer._readyPromise_reject(reason); - - writer._readyPromise_resolve = undefined; - writer._readyPromise_reject = undefined; - writer._readyPromiseState = 'rejected'; - } - - function defaultWriterReadyPromiseReset(writer) { - assert(writer._readyPromise_resolve === undefined, 'writer._readyPromise_resolve === undefined'); - assert(writer._readyPromise_reject === undefined, 'writer._readyPromise_reject === undefined'); - writer._readyPromise = new Promise(function (resolve, reject) { - writer._readyPromise_resolve = resolve; - writer._readyPromise_reject = reject; - }); - writer._readyPromiseState = 'pending'; - } - - function defaultWriterReadyPromiseResetToRejected(writer, reason) { - assert(writer._readyPromise_resolve === undefined, 'writer._readyPromise_resolve === undefined'); - assert(writer._readyPromise_reject === undefined, 'writer._readyPromise_reject === undefined'); - writer._readyPromise = Promise.reject(reason); - writer._readyPromiseState = 'rejected'; - } - - function defaultWriterReadyPromiseResolve(writer) { - assert(writer._readyPromise_resolve !== undefined, 'writer._readyPromise_resolve !== undefined'); - assert(writer._readyPromise_reject !== undefined, 'writer._readyPromise_reject !== undefined'); - - writer._readyPromise_resolve(undefined); - - writer._readyPromise_resolve = undefined; - writer._readyPromise_reject = undefined; - writer._readyPromiseState = 'fulfilled'; - } -}, function (module, exports, __webpack_require__) { - "use strict"; - - var _require = __webpack_require__(0), - IsFiniteNonNegativeNumber = _require.IsFiniteNonNegativeNumber; - - var _require2 = __webpack_require__(1), - assert = _require2.assert; - - exports.DequeueValue = function (container) { - assert('_queue' in container && '_queueTotalSize' in container, 'Spec-level failure: DequeueValue should only be used on containers with [[queue]] and [[queueTotalSize]].'); - assert(container._queue.length > 0, 'Spec-level failure: should never dequeue from an empty queue.'); - - var pair = container._queue.shift(); - - container._queueTotalSize -= pair.size; - - if (container._queueTotalSize < 0) { - container._queueTotalSize = 0; - } - - return pair.value; - }; - - exports.EnqueueValueWithSize = function (container, value, size) { - assert('_queue' in container && '_queueTotalSize' in container, 'Spec-level failure: EnqueueValueWithSize should only be used on containers with [[queue]] and ' + '[[queueTotalSize]].'); - size = Number(size); - - if (!IsFiniteNonNegativeNumber(size)) { - throw new RangeError('Size must be a finite, non-NaN, non-negative number.'); - } - - container._queue.push({ - value: value, - size: size - }); - - container._queueTotalSize += size; - }; - - exports.PeekQueueValue = function (container) { - assert('_queue' in container && '_queueTotalSize' in container, 'Spec-level failure: PeekQueueValue should only be used on containers with [[queue]] and [[queueTotalSize]].'); - assert(container._queue.length > 0, 'Spec-level failure: should never peek at an empty queue.'); - var pair = container._queue[0]; - return pair.value; - }; - - exports.ResetQueue = function (container) { - assert('_queue' in container && '_queueTotalSize' in container, 'Spec-level failure: ResetQueue should only be used on containers with [[queue]] and [[queueTotalSize]].'); - container._queue = []; - container._queueTotalSize = 0; - }; -}, function (module, exports, __webpack_require__) { - "use strict"; - - var _createClass = function () { - function defineProperties(target, props) { - for (var i = 0; i < props.length; i++) { - var descriptor = props[i]; - descriptor.enumerable = descriptor.enumerable || false; - descriptor.configurable = true; - if ("value" in descriptor) descriptor.writable = true; - Object.defineProperty(target, descriptor.key, descriptor); - } - } - - return function (Constructor, protoProps, staticProps) { - if (protoProps) defineProperties(Constructor.prototype, protoProps); - if (staticProps) defineProperties(Constructor, staticProps); - return Constructor; - }; - }(); - - function _classCallCheck(instance, Constructor) { - if (!(instance instanceof Constructor)) { - throw new TypeError("Cannot call a class as a function"); - } - } - - var _require = __webpack_require__(0), - ArrayBufferCopy = _require.ArrayBufferCopy, - CreateIterResultObject = _require.CreateIterResultObject, - IsFiniteNonNegativeNumber = _require.IsFiniteNonNegativeNumber, - InvokeOrNoop = _require.InvokeOrNoop, - PromiseInvokeOrNoop = _require.PromiseInvokeOrNoop, - TransferArrayBuffer = _require.TransferArrayBuffer, - ValidateAndNormalizeQueuingStrategy = _require.ValidateAndNormalizeQueuingStrategy, - ValidateAndNormalizeHighWaterMark = _require.ValidateAndNormalizeHighWaterMark; - - var _require2 = __webpack_require__(0), - createArrayFromList = _require2.createArrayFromList, - createDataProperty = _require2.createDataProperty, - typeIsObject = _require2.typeIsObject; - - var _require3 = __webpack_require__(1), - assert = _require3.assert, - rethrowAssertionErrorRejection = _require3.rethrowAssertionErrorRejection; - - var _require4 = __webpack_require__(3), - DequeueValue = _require4.DequeueValue, - EnqueueValueWithSize = _require4.EnqueueValueWithSize, - ResetQueue = _require4.ResetQueue; - - var _require5 = __webpack_require__(2), - AcquireWritableStreamDefaultWriter = _require5.AcquireWritableStreamDefaultWriter, - IsWritableStream = _require5.IsWritableStream, - IsWritableStreamLocked = _require5.IsWritableStreamLocked, - WritableStreamAbort = _require5.WritableStreamAbort, - WritableStreamDefaultWriterCloseWithErrorPropagation = _require5.WritableStreamDefaultWriterCloseWithErrorPropagation, - WritableStreamDefaultWriterRelease = _require5.WritableStreamDefaultWriterRelease, - WritableStreamDefaultWriterWrite = _require5.WritableStreamDefaultWriterWrite, - WritableStreamCloseQueuedOrInFlight = _require5.WritableStreamCloseQueuedOrInFlight; - - var ReadableStream = function () { - function ReadableStream() { - var underlyingSource = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - - var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, - size = _ref.size, - highWaterMark = _ref.highWaterMark; - - _classCallCheck(this, ReadableStream); - - this._state = 'readable'; - this._reader = undefined; - this._storedError = undefined; - this._disturbed = false; - this._readableStreamController = undefined; - var type = underlyingSource.type; - var typeString = String(type); - - if (typeString === 'bytes') { - if (highWaterMark === undefined) { - highWaterMark = 0; - } - - this._readableStreamController = new ReadableByteStreamController(this, underlyingSource, highWaterMark); - } else if (type === undefined) { - if (highWaterMark === undefined) { - highWaterMark = 1; - } - - this._readableStreamController = new ReadableStreamDefaultController(this, underlyingSource, size, highWaterMark); - } else { - throw new RangeError('Invalid type is specified'); - } - } - - _createClass(ReadableStream, [{ - key: 'cancel', - value: function cancel(reason) { - if (IsReadableStream(this) === false) { - return Promise.reject(streamBrandCheckException('cancel')); - } - - if (IsReadableStreamLocked(this) === true) { - return Promise.reject(new TypeError('Cannot cancel a stream that already has a reader')); - } - - return ReadableStreamCancel(this, reason); - } - }, { - key: 'getReader', - value: function getReader() { - var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, - mode = _ref2.mode; - - if (IsReadableStream(this) === false) { - throw streamBrandCheckException('getReader'); - } - - if (mode === undefined) { - return AcquireReadableStreamDefaultReader(this); - } - - mode = String(mode); - - if (mode === 'byob') { - return AcquireReadableStreamBYOBReader(this); - } - - throw new RangeError('Invalid mode is specified'); - } - }, { - key: 'pipeThrough', - value: function pipeThrough(_ref3, options) { - var writable = _ref3.writable, - readable = _ref3.readable; - var promise = this.pipeTo(writable, options); - ifIsObjectAndHasAPromiseIsHandledInternalSlotSetPromiseIsHandledToTrue(promise); - return readable; - } - }, { - key: 'pipeTo', - value: function pipeTo(dest) { - var _this = this; - - var _ref4 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, - preventClose = _ref4.preventClose, - preventAbort = _ref4.preventAbort, - preventCancel = _ref4.preventCancel; - - if (IsReadableStream(this) === false) { - return Promise.reject(streamBrandCheckException('pipeTo')); - } - - if (IsWritableStream(dest) === false) { - return Promise.reject(new TypeError('ReadableStream.prototype.pipeTo\'s first argument must be a WritableStream')); - } - - preventClose = Boolean(preventClose); - preventAbort = Boolean(preventAbort); - preventCancel = Boolean(preventCancel); - - if (IsReadableStreamLocked(this) === true) { - return Promise.reject(new TypeError('ReadableStream.prototype.pipeTo cannot be used on a locked ReadableStream')); - } - - if (IsWritableStreamLocked(dest) === true) { - return Promise.reject(new TypeError('ReadableStream.prototype.pipeTo cannot be used on a locked WritableStream')); - } - - var reader = AcquireReadableStreamDefaultReader(this); - var writer = AcquireWritableStreamDefaultWriter(dest); - var shuttingDown = false; - var currentWrite = Promise.resolve(); - return new Promise(function (resolve, reject) { - function pipeLoop() { - currentWrite = Promise.resolve(); - - if (shuttingDown === true) { - return Promise.resolve(); - } - - return writer._readyPromise.then(function () { - return ReadableStreamDefaultReaderRead(reader).then(function (_ref5) { - var value = _ref5.value, - done = _ref5.done; - - if (done === true) { - return; - } - - currentWrite = WritableStreamDefaultWriterWrite(writer, value).catch(function () {}); - }); - }).then(pipeLoop); - } - - isOrBecomesErrored(_this, reader._closedPromise, function (storedError) { - if (preventAbort === false) { - shutdownWithAction(function () { - return WritableStreamAbort(dest, storedError); - }, true, storedError); - } else { - shutdown(true, storedError); - } - }); - isOrBecomesErrored(dest, writer._closedPromise, function (storedError) { - if (preventCancel === false) { - shutdownWithAction(function () { - return ReadableStreamCancel(_this, storedError); - }, true, storedError); - } else { - shutdown(true, storedError); - } - }); - isOrBecomesClosed(_this, reader._closedPromise, function () { - 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) { - var shouldPull = ReadableByteStreamControllerShouldCallPull(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._underlyingByteSource, 'pull', [controller]); - pullPromise.then(function () { - controller._pulling = false; - - if (controller._pullAgain === true) { - controller._pullAgain = false; - ReadableByteStreamControllerCallPullIfNeeded(controller); - } - }, function (e) { - if (controller._controlledReadableStream._state === 'readable') { - ReadableByteStreamControllerError(controller, e); - } - }).catch(rethrowAssertionErrorRejection); - return undefined; - } - - function ReadableByteStreamControllerClearPendingPullIntos(controller) { - ReadableByteStreamControllerInvalidateBYOBRequest(controller); - controller._pendingPullIntos = []; - } - - function ReadableByteStreamControllerCommitPullIntoDescriptor(stream, pullIntoDescriptor) { - assert(stream._state !== 'errored', 'state must not be errored'); - var done = false; - - if (stream._state === 'closed') { - assert(pullIntoDescriptor.bytesFilled === 0); - done = true; - } - - var filledView = ReadableByteStreamControllerConvertPullIntoDescriptor(pullIntoDescriptor); - - if (pullIntoDescriptor.readerType === 'default') { - ReadableStreamFulfillReadRequest(stream, filledView, done); - } else { - assert(pullIntoDescriptor.readerType === 'byob'); - ReadableStreamFulfillReadIntoRequest(stream, filledView, done); - } - } - - function ReadableByteStreamControllerConvertPullIntoDescriptor(pullIntoDescriptor) { - var bytesFilled = pullIntoDescriptor.bytesFilled; - var elementSize = pullIntoDescriptor.elementSize; - assert(bytesFilled <= pullIntoDescriptor.byteLength); - assert(bytesFilled % elementSize === 0); - return new pullIntoDescriptor.ctor(pullIntoDescriptor.buffer, pullIntoDescriptor.byteOffset, bytesFilled / elementSize); - } - - function ReadableByteStreamControllerEnqueueChunkToQueue(controller, buffer, byteOffset, byteLength) { - controller._queue.push({ - buffer: buffer, - byteOffset: byteOffset, - byteLength: byteLength - }); - - controller._queueTotalSize += byteLength; - } - - function ReadableByteStreamControllerFillPullIntoDescriptorFromQueue(controller, pullIntoDescriptor) { - var elementSize = pullIntoDescriptor.elementSize; - var currentAlignedBytes = pullIntoDescriptor.bytesFilled - pullIntoDescriptor.bytesFilled % elementSize; - var maxBytesToCopy = Math.min(controller._queueTotalSize, pullIntoDescriptor.byteLength - pullIntoDescriptor.bytesFilled); - var maxBytesFilled = pullIntoDescriptor.bytesFilled + maxBytesToCopy; - var maxAlignedBytes = maxBytesFilled - maxBytesFilled % elementSize; - var totalBytesToCopyRemaining = maxBytesToCopy; - var ready = false; - - if (maxAlignedBytes > currentAlignedBytes) { - totalBytesToCopyRemaining = maxAlignedBytes - pullIntoDescriptor.bytesFilled; - ready = true; - } - - var queue = controller._queue; - - while (totalBytesToCopyRemaining > 0) { - var headOfQueue = queue[0]; - var bytesToCopy = Math.min(totalBytesToCopyRemaining, headOfQueue.byteLength); - var destStart = pullIntoDescriptor.byteOffset + pullIntoDescriptor.bytesFilled; - ArrayBufferCopy(pullIntoDescriptor.buffer, destStart, headOfQueue.buffer, headOfQueue.byteOffset, bytesToCopy); - - if (headOfQueue.byteLength === bytesToCopy) { - queue.shift(); - } else { - headOfQueue.byteOffset += bytesToCopy; - headOfQueue.byteLength -= bytesToCopy; - } - - controller._queueTotalSize -= bytesToCopy; - ReadableByteStreamControllerFillHeadPullIntoDescriptor(controller, bytesToCopy, pullIntoDescriptor); - totalBytesToCopyRemaining -= bytesToCopy; - } - - if (ready === false) { - assert(controller._queueTotalSize === 0, 'queue must be empty'); - assert(pullIntoDescriptor.bytesFilled > 0); - assert(pullIntoDescriptor.bytesFilled < pullIntoDescriptor.elementSize); - } - - return ready; - } - - function ReadableByteStreamControllerFillHeadPullIntoDescriptor(controller, size, pullIntoDescriptor) { - assert(controller._pendingPullIntos.length === 0 || controller._pendingPullIntos[0] === pullIntoDescriptor); - ReadableByteStreamControllerInvalidateBYOBRequest(controller); - pullIntoDescriptor.bytesFilled += size; - } - - function ReadableByteStreamControllerHandleQueueDrain(controller) { - assert(controller._controlledReadableStream._state === 'readable'); - - if (controller._queueTotalSize === 0 && controller._closeRequested === true) { - ReadableStreamClose(controller._controlledReadableStream); - } else { - ReadableByteStreamControllerCallPullIfNeeded(controller); - } - } - - function ReadableByteStreamControllerInvalidateBYOBRequest(controller) { - if (controller._byobRequest === undefined) { - return; - } - - controller._byobRequest._associatedReadableByteStreamController = undefined; - controller._byobRequest._view = undefined; - controller._byobRequest = undefined; - } - - function ReadableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(controller) { - assert(controller._closeRequested === false); - - while (controller._pendingPullIntos.length > 0) { - if (controller._queueTotalSize === 0) { - return; - } - - var pullIntoDescriptor = controller._pendingPullIntos[0]; - - if (ReadableByteStreamControllerFillPullIntoDescriptorFromQueue(controller, pullIntoDescriptor) === true) { - ReadableByteStreamControllerShiftPendingPullInto(controller); - ReadableByteStreamControllerCommitPullIntoDescriptor(controller._controlledReadableStream, pullIntoDescriptor); - } - } - } - - function ReadableByteStreamControllerPullInto(controller, view) { - var stream = controller._controlledReadableStream; - var elementSize = 1; - - if (view.constructor !== DataView) { - elementSize = view.constructor.BYTES_PER_ELEMENT; - } - - var ctor = view.constructor; - var pullIntoDescriptor = { - buffer: view.buffer, - byteOffset: view.byteOffset, - byteLength: view.byteLength, - bytesFilled: 0, - elementSize: elementSize, - ctor: ctor, - readerType: 'byob' - }; - - if (controller._pendingPullIntos.length > 0) { - pullIntoDescriptor.buffer = TransferArrayBuffer(pullIntoDescriptor.buffer); - - controller._pendingPullIntos.push(pullIntoDescriptor); - - return ReadableStreamAddReadIntoRequest(stream); - } - - if (stream._state === 'closed') { - var emptyView = new view.constructor(pullIntoDescriptor.buffer, pullIntoDescriptor.byteOffset, 0); - return Promise.resolve(CreateIterResultObject(emptyView, true)); - } - - if (controller._queueTotalSize > 0) { - if (ReadableByteStreamControllerFillPullIntoDescriptorFromQueue(controller, pullIntoDescriptor) === true) { - var filledView = ReadableByteStreamControllerConvertPullIntoDescriptor(pullIntoDescriptor); - ReadableByteStreamControllerHandleQueueDrain(controller); - return Promise.resolve(CreateIterResultObject(filledView, false)); - } - - if (controller._closeRequested === true) { - var e = new TypeError('Insufficient bytes to fill elements in the given buffer'); - ReadableByteStreamControllerError(controller, e); - return Promise.reject(e); - } - } - - pullIntoDescriptor.buffer = TransferArrayBuffer(pullIntoDescriptor.buffer); - - controller._pendingPullIntos.push(pullIntoDescriptor); - - var promise = ReadableStreamAddReadIntoRequest(stream); - ReadableByteStreamControllerCallPullIfNeeded(controller); - return promise; - } - - function ReadableByteStreamControllerRespondInClosedState(controller, firstDescriptor) { - firstDescriptor.buffer = TransferArrayBuffer(firstDescriptor.buffer); - assert(firstDescriptor.bytesFilled === 0, 'bytesFilled must be 0'); - var stream = controller._controlledReadableStream; - - if (ReadableStreamHasBYOBReader(stream) === true) { - while (ReadableStreamGetNumReadIntoRequests(stream) > 0) { - var pullIntoDescriptor = ReadableByteStreamControllerShiftPendingPullInto(controller); - ReadableByteStreamControllerCommitPullIntoDescriptor(stream, pullIntoDescriptor); - } - } - } - - function ReadableByteStreamControllerRespondInReadableState(controller, bytesWritten, pullIntoDescriptor) { - if (pullIntoDescriptor.bytesFilled + bytesWritten > pullIntoDescriptor.byteLength) { - throw new RangeError('bytesWritten out of range'); - } - - ReadableByteStreamControllerFillHeadPullIntoDescriptor(controller, bytesWritten, pullIntoDescriptor); - - if (pullIntoDescriptor.bytesFilled < pullIntoDescriptor.elementSize) { - return; - } - - ReadableByteStreamControllerShiftPendingPullInto(controller); - var remainderSize = pullIntoDescriptor.bytesFilled % pullIntoDescriptor.elementSize; - - if (remainderSize > 0) { - var end = pullIntoDescriptor.byteOffset + pullIntoDescriptor.bytesFilled; - var remainder = pullIntoDescriptor.buffer.slice(end - remainderSize, end); - ReadableByteStreamControllerEnqueueChunkToQueue(controller, remainder, 0, remainder.byteLength); - } - - pullIntoDescriptor.buffer = TransferArrayBuffer(pullIntoDescriptor.buffer); - pullIntoDescriptor.bytesFilled -= remainderSize; - ReadableByteStreamControllerCommitPullIntoDescriptor(controller._controlledReadableStream, pullIntoDescriptor); - ReadableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(controller); - } - - function ReadableByteStreamControllerRespondInternal(controller, bytesWritten) { - var firstDescriptor = controller._pendingPullIntos[0]; - var stream = controller._controlledReadableStream; - - if (stream._state === 'closed') { - if (bytesWritten !== 0) { - throw new TypeError('bytesWritten must be 0 when calling respond() on a closed stream'); - } - - ReadableByteStreamControllerRespondInClosedState(controller, firstDescriptor); - } else { - assert(stream._state === 'readable'); - ReadableByteStreamControllerRespondInReadableState(controller, bytesWritten, firstDescriptor); - } - } - - function ReadableByteStreamControllerShiftPendingPullInto(controller) { - var descriptor = controller._pendingPullIntos.shift(); - - ReadableByteStreamControllerInvalidateBYOBRequest(controller); - return descriptor; - } - - function ReadableByteStreamControllerShouldCallPull(controller) { - var stream = controller._controlledReadableStream; - - if (stream._state !== 'readable') { - return false; - } - - if (controller._closeRequested === true) { - return false; - } - - if (controller._started === false) { - return false; - } - - if (ReadableStreamHasDefaultReader(stream) === true && ReadableStreamGetNumReadRequests(stream) > 0) { - return true; - } - - if (ReadableStreamHasBYOBReader(stream) === true && ReadableStreamGetNumReadIntoRequests(stream) > 0) { - return true; - } - - if (ReadableByteStreamControllerGetDesiredSize(controller) > 0) { - return true; - } - - return false; - } - - function ReadableByteStreamControllerClose(controller) { - var stream = controller._controlledReadableStream; - assert(controller._closeRequested === false); - assert(stream._state === 'readable'); - - if (controller._queueTotalSize > 0) { - controller._closeRequested = true; - return; - } - - if (controller._pendingPullIntos.length > 0) { - var firstPendingPullInto = controller._pendingPullIntos[0]; - - if (firstPendingPullInto.bytesFilled > 0) { - var e = new TypeError('Insufficient bytes to fill elements in the given buffer'); - ReadableByteStreamControllerError(controller, e); - throw e; - } - } - - ReadableStreamClose(stream); - } - - function ReadableByteStreamControllerEnqueue(controller, chunk) { - var stream = controller._controlledReadableStream; - assert(controller._closeRequested === false); - assert(stream._state === 'readable'); - var buffer = chunk.buffer; - var byteOffset = chunk.byteOffset; - var byteLength = chunk.byteLength; - var transferredBuffer = TransferArrayBuffer(buffer); - - if (ReadableStreamHasDefaultReader(stream) === true) { - if (ReadableStreamGetNumReadRequests(stream) === 0) { - ReadableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset, byteLength); - } else { - assert(controller._queue.length === 0); - var transferredView = new Uint8Array(transferredBuffer, byteOffset, byteLength); - ReadableStreamFulfillReadRequest(stream, transferredView, false); - } - } else if (ReadableStreamHasBYOBReader(stream) === true) { - ReadableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset, byteLength); - ReadableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(controller); - } else { - assert(IsReadableStreamLocked(stream) === false, 'stream must not be locked'); - ReadableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset, byteLength); - } - } - - function ReadableByteStreamControllerError(controller, e) { - var stream = controller._controlledReadableStream; - assert(stream._state === 'readable'); - ReadableByteStreamControllerClearPendingPullIntos(controller); - ResetQueue(controller); - ReadableStreamError(stream, e); - } - - function ReadableByteStreamControllerGetDesiredSize(controller) { - var stream = controller._controlledReadableStream; - var state = stream._state; - - if (state === 'errored') { - return null; - } - - if (state === 'closed') { - return 0; - } - - return controller._strategyHWM - controller._queueTotalSize; - } - - function ReadableByteStreamControllerRespond(controller, bytesWritten) { - bytesWritten = Number(bytesWritten); - - if (IsFiniteNonNegativeNumber(bytesWritten) === false) { - throw new RangeError('bytesWritten must be a finite'); - } - - assert(controller._pendingPullIntos.length > 0); - ReadableByteStreamControllerRespondInternal(controller, bytesWritten); - } - - function ReadableByteStreamControllerRespondWithNewView(controller, view) { - assert(controller._pendingPullIntos.length > 0); - var firstDescriptor = controller._pendingPullIntos[0]; - - if (firstDescriptor.byteOffset + firstDescriptor.bytesFilled !== view.byteOffset) { - throw new RangeError('The region specified by view does not match byobRequest'); - } - - if (firstDescriptor.byteLength !== view.byteLength) { - throw new RangeError('The buffer of view has different capacity than byobRequest'); - } - - firstDescriptor.buffer = view.buffer; - ReadableByteStreamControllerRespondInternal(controller, view.byteLength); - } - - function streamBrandCheckException(name) { - return new TypeError('ReadableStream.prototype.' + name + ' can only be used on a ReadableStream'); - } - - function readerLockException(name) { - return new TypeError('Cannot ' + name + ' a stream using a released reader'); - } - - function defaultReaderBrandCheckException(name) { - return new TypeError('ReadableStreamDefaultReader.prototype.' + name + ' can only be used on a ReadableStreamDefaultReader'); - } - - function defaultReaderClosedPromiseInitialize(reader) { - reader._closedPromise = new Promise(function (resolve, reject) { - reader._closedPromise_resolve = resolve; - reader._closedPromise_reject = reject; - }); - } - - function defaultReaderClosedPromiseInitializeAsRejected(reader, reason) { - reader._closedPromise = Promise.reject(reason); - reader._closedPromise_resolve = undefined; - reader._closedPromise_reject = undefined; - } - - function defaultReaderClosedPromiseInitializeAsResolved(reader) { - reader._closedPromise = Promise.resolve(undefined); - reader._closedPromise_resolve = undefined; - reader._closedPromise_reject = undefined; - } - - function defaultReaderClosedPromiseReject(reader, reason) { - assert(reader._closedPromise_resolve !== undefined); - assert(reader._closedPromise_reject !== undefined); - - reader._closedPromise_reject(reason); - - reader._closedPromise_resolve = undefined; - reader._closedPromise_reject = undefined; - } - - function defaultReaderClosedPromiseResetToRejected(reader, reason) { - assert(reader._closedPromise_resolve === undefined); - assert(reader._closedPromise_reject === undefined); - reader._closedPromise = Promise.reject(reason); - } - - function defaultReaderClosedPromiseResolve(reader) { - assert(reader._closedPromise_resolve !== undefined); - assert(reader._closedPromise_reject !== undefined); - - reader._closedPromise_resolve(undefined); - - reader._closedPromise_resolve = undefined; - reader._closedPromise_reject = undefined; - } - - function byobReaderBrandCheckException(name) { - return new TypeError('ReadableStreamBYOBReader.prototype.' + name + ' can only be used on a ReadableStreamBYOBReader'); - } - - function defaultControllerBrandCheckException(name) { - return new TypeError('ReadableStreamDefaultController.prototype.' + name + ' can only be used on a ReadableStreamDefaultController'); - } - - function byobRequestBrandCheckException(name) { - return new TypeError('ReadableStreamBYOBRequest.prototype.' + name + ' can only be used on a ReadableStreamBYOBRequest'); - } - - function byteStreamControllerBrandCheckException(name) { - return new TypeError('ReadableByteStreamController.prototype.' + name + ' can only be used on a ReadableByteStreamController'); - } - - function ifIsObjectAndHasAPromiseIsHandledInternalSlotSetPromiseIsHandledToTrue(promise) { - try { - Promise.prototype.then.call(promise, undefined, function () {}); - } catch (e) {} - } -}, function (module, exports, __webpack_require__) { - "use strict"; - - var transformStream = __webpack_require__(6); - - var readableStream = __webpack_require__(4); - - var writableStream = __webpack_require__(2); - - exports.TransformStream = transformStream.TransformStream; - exports.ReadableStream = readableStream.ReadableStream; - exports.IsReadableStreamDisturbed = readableStream.IsReadableStreamDisturbed; - exports.ReadableStreamDefaultControllerClose = readableStream.ReadableStreamDefaultControllerClose; - exports.ReadableStreamDefaultControllerEnqueue = readableStream.ReadableStreamDefaultControllerEnqueue; - exports.ReadableStreamDefaultControllerError = readableStream.ReadableStreamDefaultControllerError; - exports.ReadableStreamDefaultControllerGetDesiredSize = readableStream.ReadableStreamDefaultControllerGetDesiredSize; - exports.AcquireWritableStreamDefaultWriter = writableStream.AcquireWritableStreamDefaultWriter; - exports.IsWritableStream = writableStream.IsWritableStream; - exports.IsWritableStreamLocked = writableStream.IsWritableStreamLocked; - exports.WritableStream = writableStream.WritableStream; - exports.WritableStreamAbort = writableStream.WritableStreamAbort; - exports.WritableStreamDefaultControllerError = writableStream.WritableStreamDefaultControllerError; - exports.WritableStreamDefaultWriterCloseWithErrorPropagation = writableStream.WritableStreamDefaultWriterCloseWithErrorPropagation; - exports.WritableStreamDefaultWriterRelease = writableStream.WritableStreamDefaultWriterRelease; - exports.WritableStreamDefaultWriterWrite = writableStream.WritableStreamDefaultWriterWrite; -}, function (module, exports, __webpack_require__) { - "use strict"; - - var _createClass = function () { - function defineProperties(target, props) { - for (var i = 0; i < props.length; i++) { - var descriptor = props[i]; - descriptor.enumerable = descriptor.enumerable || false; - descriptor.configurable = true; - if ("value" in descriptor) descriptor.writable = true; - Object.defineProperty(target, descriptor.key, descriptor); - } - } - - return function (Constructor, protoProps, staticProps) { - if (protoProps) defineProperties(Constructor.prototype, protoProps); - if (staticProps) defineProperties(Constructor, staticProps); - return Constructor; - }; - }(); - - function _classCallCheck(instance, Constructor) { - if (!(instance instanceof Constructor)) { - throw new TypeError("Cannot call a class as a function"); - } - } - - var _require = __webpack_require__(1), - assert = _require.assert; - - var _require2 = __webpack_require__(0), - InvokeOrNoop = _require2.InvokeOrNoop, - PromiseInvokeOrPerformFallback = _require2.PromiseInvokeOrPerformFallback, - PromiseInvokeOrNoop = _require2.PromiseInvokeOrNoop, - typeIsObject = _require2.typeIsObject; - - var _require3 = __webpack_require__(4), - ReadableStream = _require3.ReadableStream, - ReadableStreamDefaultControllerClose = _require3.ReadableStreamDefaultControllerClose, - ReadableStreamDefaultControllerEnqueue = _require3.ReadableStreamDefaultControllerEnqueue, - ReadableStreamDefaultControllerError = _require3.ReadableStreamDefaultControllerError, - ReadableStreamDefaultControllerGetDesiredSize = _require3.ReadableStreamDefaultControllerGetDesiredSize; - - var _require4 = __webpack_require__(2), - WritableStream = _require4.WritableStream, - WritableStreamDefaultControllerError = _require4.WritableStreamDefaultControllerError; - - function TransformStreamCloseReadable(transformStream) { - if (transformStream._errored === true) { - throw new TypeError('TransformStream is already errored'); - } - - if (transformStream._readableClosed === true) { - throw new TypeError('Readable side is already closed'); - } - - TransformStreamCloseReadableInternal(transformStream); - } - - function TransformStreamEnqueueToReadable(transformStream, chunk) { - if (transformStream._errored === true) { - throw new TypeError('TransformStream is already errored'); - } - - if (transformStream._readableClosed === true) { - throw new TypeError('Readable side is already closed'); - } - - var controller = transformStream._readableController; - - try { - ReadableStreamDefaultControllerEnqueue(controller, chunk); - } catch (e) { - transformStream._readableClosed = true; - TransformStreamErrorIfNeeded(transformStream, e); - throw transformStream._storedError; - } - - var desiredSize = ReadableStreamDefaultControllerGetDesiredSize(controller); - var maybeBackpressure = desiredSize <= 0; - - if (maybeBackpressure === true && transformStream._backpressure === false) { - TransformStreamSetBackpressure(transformStream, true); - } - } - - function TransformStreamError(transformStream, e) { - if (transformStream._errored === true) { - throw new TypeError('TransformStream is already errored'); - } - - TransformStreamErrorInternal(transformStream, e); - } - - function TransformStreamCloseReadableInternal(transformStream) { - assert(transformStream._errored === false); - assert(transformStream._readableClosed === false); - - try { - ReadableStreamDefaultControllerClose(transformStream._readableController); - } catch (e) { - assert(false); - } - - transformStream._readableClosed = true; - } - - function TransformStreamErrorIfNeeded(transformStream, e) { - if (transformStream._errored === false) { - TransformStreamErrorInternal(transformStream, e); - } - } - - function TransformStreamErrorInternal(transformStream, e) { - assert(transformStream._errored === false); - transformStream._errored = true; - transformStream._storedError = e; - - if (transformStream._writableDone === false) { - WritableStreamDefaultControllerError(transformStream._writableController, e); - } - - if (transformStream._readableClosed === false) { - ReadableStreamDefaultControllerError(transformStream._readableController, e); - } - } - - function TransformStreamReadableReadyPromise(transformStream) { - assert(transformStream._backpressureChangePromise !== undefined, '_backpressureChangePromise should have been initialized'); - - if (transformStream._backpressure === false) { - return Promise.resolve(); - } - - assert(transformStream._backpressure === true, '_backpressure should have been initialized'); - return transformStream._backpressureChangePromise; - } - - function TransformStreamSetBackpressure(transformStream, backpressure) { - assert(transformStream._backpressure !== backpressure, 'TransformStreamSetBackpressure() should be called only when backpressure is changed'); - - if (transformStream._backpressureChangePromise !== undefined) { - transformStream._backpressureChangePromise_resolve(backpressure); - } - - transformStream._backpressureChangePromise = new Promise(function (resolve) { - transformStream._backpressureChangePromise_resolve = resolve; - }); - - transformStream._backpressureChangePromise.then(function (resolution) { - assert(resolution !== backpressure, '_backpressureChangePromise should be fulfilled only when backpressure is changed'); - }); - - transformStream._backpressure = backpressure; - } - - function TransformStreamDefaultTransform(chunk, transformStreamController) { - var transformStream = transformStreamController._controlledTransformStream; - TransformStreamEnqueueToReadable(transformStream, chunk); - return Promise.resolve(); - } - - function TransformStreamTransform(transformStream, chunk) { - assert(transformStream._errored === false); - assert(transformStream._transforming === false); - assert(transformStream._backpressure === false); - transformStream._transforming = true; - var transformer = transformStream._transformer; - var controller = transformStream._transformStreamController; - var transformPromise = PromiseInvokeOrPerformFallback(transformer, 'transform', [chunk, controller], TransformStreamDefaultTransform, [chunk, controller]); - return transformPromise.then(function () { - transformStream._transforming = false; - return TransformStreamReadableReadyPromise(transformStream); - }, function (e) { - TransformStreamErrorIfNeeded(transformStream, e); - return Promise.reject(e); - }); - } - - function IsTransformStreamDefaultController(x) { - if (!typeIsObject(x)) { - return false; - } - - if (!Object.prototype.hasOwnProperty.call(x, '_controlledTransformStream')) { - return false; - } - - return true; - } - - function IsTransformStream(x) { - if (!typeIsObject(x)) { - return false; - } - - if (!Object.prototype.hasOwnProperty.call(x, '_transformStreamController')) { - return false; - } - - return true; - } - - var TransformStreamSink = function () { - function TransformStreamSink(transformStream, startPromise) { - _classCallCheck(this, TransformStreamSink); - - this._transformStream = transformStream; - this._startPromise = startPromise; - } - - _createClass(TransformStreamSink, [{ - key: 'start', - value: function start(c) { - var transformStream = this._transformStream; - transformStream._writableController = c; - return this._startPromise.then(function () { - return TransformStreamReadableReadyPromise(transformStream); - }); - } - }, { - key: 'write', - value: function write(chunk) { - var transformStream = this._transformStream; - return TransformStreamTransform(transformStream, chunk); - } - }, { - key: 'abort', - value: function abort() { - var transformStream = this._transformStream; - transformStream._writableDone = true; - TransformStreamErrorInternal(transformStream, new TypeError('Writable side aborted')); - } - }, { - key: 'close', - value: function close() { - var transformStream = this._transformStream; - assert(transformStream._transforming === false); - transformStream._writableDone = true; - var flushPromise = PromiseInvokeOrNoop(transformStream._transformer, 'flush', [transformStream._transformStreamController]); - return flushPromise.then(function () { - if (transformStream._errored === true) { - return Promise.reject(transformStream._storedError); - } - - if (transformStream._readableClosed === false) { - TransformStreamCloseReadableInternal(transformStream); - } - - return Promise.resolve(); - }).catch(function (r) { - TransformStreamErrorIfNeeded(transformStream, r); - return Promise.reject(transformStream._storedError); - }); - } - }]); - - return TransformStreamSink; - }(); - - var TransformStreamSource = function () { - function TransformStreamSource(transformStream, startPromise) { - _classCallCheck(this, TransformStreamSource); - - this._transformStream = transformStream; - this._startPromise = startPromise; - } - - _createClass(TransformStreamSource, [{ - key: 'start', - value: function start(c) { - var transformStream = this._transformStream; - transformStream._readableController = c; - return this._startPromise.then(function () { - assert(transformStream._backpressureChangePromise !== undefined, '_backpressureChangePromise should have been initialized'); - - if (transformStream._backpressure === true) { - return Promise.resolve(); - } - - assert(transformStream._backpressure === false, '_backpressure should have been initialized'); - return transformStream._backpressureChangePromise; - }); - } - }, { - key: 'pull', - value: function pull() { - var transformStream = this._transformStream; - assert(transformStream._backpressure === true, 'pull() should be never called while _backpressure is false'); - assert(transformStream._backpressureChangePromise !== undefined, '_backpressureChangePromise should have been initialized'); - TransformStreamSetBackpressure(transformStream, false); - return transformStream._backpressureChangePromise; - } - }, { - key: 'cancel', - value: function cancel() { - var transformStream = this._transformStream; - transformStream._readableClosed = true; - TransformStreamErrorInternal(transformStream, new TypeError('Readable side canceled')); - } - }]); - - return TransformStreamSource; - }(); - - var TransformStreamDefaultController = function () { - function TransformStreamDefaultController(transformStream) { - _classCallCheck(this, TransformStreamDefaultController); - - if (IsTransformStream(transformStream) === false) { - throw new TypeError('TransformStreamDefaultController can only be ' + 'constructed with a TransformStream instance'); - } - - if (transformStream._transformStreamController !== undefined) { - throw new TypeError('TransformStreamDefaultController instances can ' + 'only be created by the TransformStream constructor'); - } - - this._controlledTransformStream = transformStream; - } - - _createClass(TransformStreamDefaultController, [{ - key: 'enqueue', - value: function enqueue(chunk) { - if (IsTransformStreamDefaultController(this) === false) { - throw defaultControllerBrandCheckException('enqueue'); - } - - TransformStreamEnqueueToReadable(this._controlledTransformStream, chunk); - } - }, { - key: 'close', - value: function close() { - if (IsTransformStreamDefaultController(this) === false) { - throw defaultControllerBrandCheckException('close'); - } - - TransformStreamCloseReadable(this._controlledTransformStream); - } - }, { - key: 'error', - value: function error(reason) { - if (IsTransformStreamDefaultController(this) === false) { - throw defaultControllerBrandCheckException('error'); - } - - TransformStreamError(this._controlledTransformStream, reason); - } - }, { - key: 'desiredSize', - get: function get() { - if (IsTransformStreamDefaultController(this) === false) { - throw defaultControllerBrandCheckException('desiredSize'); - } - - var transformStream = this._controlledTransformStream; - var readableController = transformStream._readableController; - return ReadableStreamDefaultControllerGetDesiredSize(readableController); - } - }]); - - return TransformStreamDefaultController; - }(); - - var TransformStream = function () { - function TransformStream() { - var transformer = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - - _classCallCheck(this, TransformStream); - - this._transformer = transformer; - var readableStrategy = transformer.readableStrategy, - writableStrategy = transformer.writableStrategy; - this._transforming = false; - this._errored = false; - this._storedError = undefined; - this._writableController = undefined; - this._readableController = undefined; - this._transformStreamController = undefined; - this._writableDone = false; - this._readableClosed = false; - this._backpressure = undefined; - this._backpressureChangePromise = undefined; - this._backpressureChangePromise_resolve = undefined; - this._transformStreamController = new TransformStreamDefaultController(this); - var startPromise_resolve = void 0; - var startPromise = new Promise(function (resolve) { - startPromise_resolve = resolve; - }); - var source = new TransformStreamSource(this, startPromise); - this._readable = new ReadableStream(source, readableStrategy); - var sink = new TransformStreamSink(this, startPromise); - this._writable = new WritableStream(sink, writableStrategy); - assert(this._writableController !== undefined); - assert(this._readableController !== undefined); - var desiredSize = ReadableStreamDefaultControllerGetDesiredSize(this._readableController); - TransformStreamSetBackpressure(this, desiredSize <= 0); - var transformStream = this; - var startResult = InvokeOrNoop(transformer, 'start', [transformStream._transformStreamController]); - startPromise_resolve(startResult); - startPromise.catch(function (e) { - if (transformStream._errored === false) { - transformStream._errored = true; - transformStream._storedError = e; - } - }); - } - - _createClass(TransformStream, [{ - key: 'readable', - get: function get() { - if (IsTransformStream(this) === false) { - throw streamBrandCheckException('readable'); - } - - return this._readable; - } - }, { - key: 'writable', - get: function get() { - if (IsTransformStream(this) === false) { - throw streamBrandCheckException('writable'); - } - - return this._writable; - } - }]); - - return TransformStream; - }(); - - module.exports = { - TransformStream: TransformStream - }; - - function defaultControllerBrandCheckException(name) { - return new TypeError('TransformStreamDefaultController.prototype.' + name + ' can only be used on a TransformStreamDefaultController'); - } - - function streamBrandCheckException(name) { - return new TypeError('TransformStream.prototype.' + name + ' can only be used on a TransformStream'); - } -}, function (module, exports, __webpack_require__) { - module.exports = __webpack_require__(5); -}])); - -/***/ }) -/******/ ]); \ No newline at end of file diff --git a/browser/extensions/pdfjs/content/web/viewer.html b/browser/extensions/pdfjs/content/web/viewer.html index acb40dd12809..11fc1b7a7193 100644 --- a/browser/extensions/pdfjs/content/web/viewer.html +++ b/browser/extensions/pdfjs/content/web/viewer.html @@ -28,13 +28,6 @@ See https://github.com/adobe-type-tools/cmap-resources - diff --git a/browser/extensions/pdfjs/content/web/viewer.js b/browser/extensions/pdfjs/content/web/viewer.js index d24f24ab5656..126d20662bf0 100644 --- a/browser/extensions/pdfjs/content/web/viewer.js +++ b/browser/extensions/pdfjs/content/web/viewer.js @@ -8168,15 +8168,25 @@ class PDFViewer extends _base_viewer.BaseViewer { return this._getCurrentVisiblePage(); } - _updateHelper(visiblePages) { - if (this.isInPresentationMode) { + update() { + let visible = this._getVisiblePages(); + + let visiblePages = visible.views, + numVisiblePages = visiblePages.length; + + if (numVisiblePages === 0) { return; } + this._resizeBuffer(numVisiblePages, visiblePages); + + this.renderingQueue.renderHighestPriority(visible); let currentId = this._currentPageNumber; let stillFullyVisible = false; - for (const page of visiblePages) { + for (let i = 0; i < numVisiblePages; ++i) { + let page = visiblePages[i]; + if (page.percent < 100) { break; } @@ -8191,7 +8201,16 @@ class PDFViewer extends _base_viewer.BaseViewer { currentId = visiblePages[0].id; } - this._setCurrentPageNumber(currentId); + if (!this.isInPresentationMode) { + this._setCurrentPageNumber(currentId); + } + + this._updateLocation(visible.first); + + this.eventBus.dispatch('updateviewarea', { + source: this, + location: this._location + }); } get _isScrollModeHorizontal() { @@ -8943,32 +8962,8 @@ class BaseViewer { }; } - _updateHelper(visiblePages) { - throw new Error('Not implemented: _updateHelper'); - } - update() { - const visible = this._getVisiblePages(); - - const visiblePages = visible.views, - numVisiblePages = visiblePages.length; - - if (numVisiblePages === 0) { - return; - } - - this._resizeBuffer(numVisiblePages, visiblePages); - - this.renderingQueue.renderHighestPriority(visible); - - this._updateHelper(visiblePages); - - this._updateLocation(visible.first); - - this.eventBus.dispatch('updateviewarea', { - source: this, - location: this._location - }); + throw new Error('Not implemented: update'); } containsElement(element) { @@ -10804,7 +10799,27 @@ class PDFSinglePageViewer extends _base_viewer.BaseViewer { return this._getCurrentVisiblePage(); } - _updateHelper(visiblePages) {} + update() { + let visible = this._getVisiblePages(); + + let visiblePages = visible.views, + numVisiblePages = visiblePages.length; + + if (numVisiblePages === 0) { + return; + } + + this._resizeBuffer(numVisiblePages); + + this.renderingQueue.renderHighestPriority(visible); + + this._updateLocation(visible.first); + + this.eventBus.dispatch('updateviewarea', { + source: this, + location: this._location + }); + } get _isScrollModeHorizontal() { return (0, _pdfjsLib.shadow)(this, '_isScrollModeHorizontal', false); diff --git a/browser/extensions/pdfjs/moz.yaml b/browser/extensions/pdfjs/moz.yaml index f7cee8b56ece..384a82d1ebfe 100644 --- a/browser/extensions/pdfjs/moz.yaml +++ b/browser/extensions/pdfjs/moz.yaml @@ -20,7 +20,7 @@ origin: # Human-readable identifier for this version/release # Generally "version NNN", "tag SSS", "bookmark SSS" - release: version 2.1.209 + release: version 2.1.196 # The package's license, where possible using the mnemonic from # https://spdx.org/licenses/