diff --git a/src/lib/abstract-ops/ecmascript.ts b/src/lib/abstract-ops/ecmascript.ts index ec15cb0..d7b9414 100644 --- a/src/lib/abstract-ops/ecmascript.ts +++ b/src/lib/abstract-ops/ecmascript.ts @@ -24,11 +24,13 @@ export function CreateArrayFromList(elements: T): T { return elements.slice() as T; } -export function CopyDataBlockBytes(dest: ArrayBuffer, - destOffset: number, - src: ArrayBuffer, - srcOffset: number, - n: number) { +export function CopyDataBlockBytes( + dest: ArrayBuffer, + destOffset: number, + src: ArrayBuffer, + srcOffset: number, + n: number +) { new Uint8Array(dest).set(new Uint8Array(src, srcOffset, n), destOffset); } @@ -102,9 +104,7 @@ export interface AsyncIteratorRecord { export type SyncOrAsyncIteratorRecord = SyncIteratorRecord | AsyncIteratorRecord; -export function CreateAsyncFromSyncIterator( - syncIteratorRecord: SyncIteratorRecord> -): AsyncIteratorRecord { +export function CreateAsyncFromSyncIterator(syncIteratorRecord: SyncIteratorRecord>): AsyncIteratorRecord { const asyncIterator: AsyncIterator = { // https://tc39.es/ecma262/#sec-%asyncfromsynciteratorprototype%.next next() { @@ -154,10 +154,10 @@ function AsyncFromSyncIteratorContinuation(result: IteratorResult = Iterable | AsyncIterable; export type SyncOrAsyncIteratorMethod = () => (Iterator | AsyncIterator); @@ -205,9 +205,7 @@ export { GetIterator }; export function IteratorNext(iteratorRecord: SyncIteratorRecord): IteratorResult; export function IteratorNext(iteratorRecord: AsyncIteratorRecord): Promise>; -export function IteratorNext( - iteratorRecord: SyncOrAsyncIteratorRecord -): SyncOrAsync>> { +export function IteratorNext(iteratorRecord: SyncOrAsyncIteratorRecord): SyncOrAsync>> { const result = reflectCall(iteratorRecord.nextMethod, iteratorRecord.iterator, []); if (!typeIsObject(result)) { throw new TypeError('The iterator.next() method must return an object'); diff --git a/src/lib/helpers/miscellaneous.ts b/src/lib/helpers/miscellaneous.ts index 2af112c..93f2a61 100644 --- a/src/lib/helpers/miscellaneous.ts +++ b/src/lib/helpers/miscellaneous.ts @@ -5,19 +5,19 @@ export function typeIsObject(x: any): x is object { return (typeof x === 'object' && x !== null) || typeof x === 'function'; } -export const rethrowAssertionErrorRejection: (e: any) => void = - DEBUG ? - (e) => { - // Used throughout the reference implementation, as `.catch(rethrowAssertionErrorRejection)`, to ensure any errors - // get shown. There are places in the spec where we do promise transformations and purposefully ignore or don't - // expect any errors, but assertion errors are always problematic. - if (e && e instanceof AssertionError) { - setTimeout(() => { - throw e; - }, 0); +export const rethrowAssertionErrorRejection: (e: any) => void + = DEBUG + ? (e) => { + // Used throughout the reference implementation, as `.catch(rethrowAssertionErrorRejection)`, to ensure any errors + // get shown. There are places in the spec where we do promise transformations and purposefully ignore or don't + // expect any errors, but assertion errors are always problematic. + if (e && e instanceof AssertionError) { + setTimeout(() => { + throw e; + }, 0); + } } - } : - noop; + : noop; export function setFunctionName(fn: (...args: any[]) => any, name: string): void { try { diff --git a/src/lib/helpers/webidl.ts b/src/lib/helpers/webidl.ts index 2da37ab..bce6b50 100644 --- a/src/lib/helpers/webidl.ts +++ b/src/lib/helpers/webidl.ts @@ -29,7 +29,8 @@ export function promiseRejectedWith(reason: any): Promise { export function PerformPromiseThen( promise: Promise, onFulfilled?: (value: T) => TResult1 | PromiseLike, - onRejected?: (reason: any) => TResult2 | PromiseLike): Promise { + onRejected?: (reason: any) => TResult2 | PromiseLike +): Promise { // There doesn't appear to be any way to correctly emulate the behaviour from JavaScript, so this is just an // approximation. return originalPromiseThen.call(promise, onFulfilled, onRejected) as Promise; @@ -41,7 +42,8 @@ export function PerformPromiseThen( export function uponPromise( promise: Promise, onFulfilled?: (value: T) => null | PromiseLike, - onRejected?: (reason: any) => null | PromiseLike): void { + onRejected?: (reason: any) => null | PromiseLike +): void { PerformPromiseThen( PerformPromiseThen(promise, onFulfilled, onRejected), undefined, @@ -60,7 +62,8 @@ export function uponRejection(promise: Promise, onRejected: (reason: an export function transformPromiseWith( promise: Promise, fulfillmentHandler?: (value: T) => TResult1 | PromiseLike, - rejectionHandler?: (reason: any) => TResult2 | PromiseLike): Promise { + rejectionHandler?: (reason: any) => TResult2 | PromiseLike +): Promise { return PerformPromiseThen(promise, fulfillmentHandler, rejectionHandler); } @@ -87,9 +90,11 @@ export function reflectCall(F: (this: T, ...fnArgs: A) => return Function.prototype.apply.call(F, V, args); } -export function promiseCall(F: (this: T, ...fnArgs: A) => R | PromiseLike, - V: T, - args: A): Promise { +export function promiseCall( + F: (this: T, ...fnArgs: A) => R | PromiseLike, + V: T, + args: A +): Promise { assert(typeof F === 'function'); assert(V !== undefined); assert(Array.isArray(args)); diff --git a/src/lib/readable-stream.ts b/src/lib/readable-stream.ts index e1035db..bd6ef8f 100644 --- a/src/lib/readable-stream.ts +++ b/src/lib/readable-stream.ts @@ -99,8 +99,10 @@ export class ReadableStream implements AsyncIterable { constructor(underlyingSource: UnderlyingByteSource, strategy?: { highWaterMark?: number; size?: undefined }); constructor(underlyingSource?: UnderlyingSource, strategy?: QueuingStrategy); - constructor(rawUnderlyingSource: UnderlyingSource | UnderlyingByteSource | null | undefined = {}, - rawStrategy: QueuingStrategy | null | undefined = {}) { + constructor( +rawUnderlyingSource: UnderlyingSource | UnderlyingByteSource | null | undefined = {}, + rawStrategy: QueuingStrategy | null | undefined = {} + ) { if (rawUnderlyingSource === undefined) { rawUnderlyingSource = null; } else { @@ -183,9 +185,7 @@ export class ReadableStream implements AsyncIterable { * or cancel the stream, which would interfere with your abstraction. */ getReader(): ReadableStreamDefaultReader; - getReader( - rawOptions: ReadableStreamGetReaderOptions | null | undefined = undefined - ): ReadableStreamDefaultReader | ReadableStreamBYOBReader { + getReader(rawOptions: ReadableStreamGetReaderOptions | null | undefined = undefined): ReadableStreamDefaultReader | ReadableStreamBYOBReader { if (!IsReadableStream(this)) { throw streamBrandCheckException('getReader'); } @@ -230,9 +230,7 @@ export class ReadableStream implements AsyncIterable { throw new TypeError('ReadableStream.prototype.pipeThrough cannot be used on a locked WritableStream'); } - const promise = ReadableStreamPipeTo( - this, transform.writable, options.preventClose, options.preventAbort, options.preventCancel, options.signal - ); + const promise = ReadableStreamPipeTo(this, transform.writable, options.preventClose, options.preventAbort, options.preventCancel, options.signal); setPromiseIsHandledToTrue(promise); @@ -247,8 +245,10 @@ export class ReadableStream implements AsyncIterable { * Piping a stream will lock it for the duration of the pipe, preventing any other consumer from acquiring a reader. */ pipeTo(destination: WritableStream, options?: StreamPipeOptions): Promise; - pipeTo(destination: WritableStream | null | undefined, - rawOptions: StreamPipeOptions | null | undefined = {}): Promise { + pipeTo( + destination: WritableStream | null | undefined, + rawOptions: StreamPipeOptions | null | undefined = {} + ): Promise { if (!IsReadableStream(this)) { return promiseRejectedWith(streamBrandCheckException('pipeTo')); } @@ -257,9 +257,7 @@ export class ReadableStream implements AsyncIterable { return promiseRejectedWith(`Parameter 1 is required in 'pipeTo'.`); } if (!IsWritableStream(destination)) { - return promiseRejectedWith( - new TypeError(`ReadableStream.prototype.pipeTo's first argument must be a WritableStream`) - ); + return promiseRejectedWith(new TypeError(`ReadableStream.prototype.pipeTo's first argument must be a WritableStream`)); } let options: ValidatedStreamPipeOptions; @@ -270,19 +268,13 @@ export class ReadableStream implements AsyncIterable { } if (IsReadableStreamLocked(this)) { - return promiseRejectedWith( - new TypeError('ReadableStream.prototype.pipeTo cannot be used on a locked ReadableStream') - ); + return promiseRejectedWith(new TypeError('ReadableStream.prototype.pipeTo cannot be used on a locked ReadableStream')); } if (IsWritableStreamLocked(destination)) { - return promiseRejectedWith( - new TypeError('ReadableStream.prototype.pipeTo cannot be used on a locked WritableStream') - ); + return promiseRejectedWith(new TypeError('ReadableStream.prototype.pipeTo cannot be used on a locked WritableStream')); } - return ReadableStreamPipeTo( - this, destination, options.preventClose, options.preventAbort, options.preventCancel, options.signal - ); + return ReadableStreamPipeTo(this, destination, options.preventClose, options.preventAbort, options.preventCancel, options.signal); } /** @@ -413,9 +405,7 @@ export function CreateReadableStream( InitializeReadableStream(stream); const controller: ReadableStreamDefaultController = Object.create(ReadableStreamDefaultController.prototype); - SetUpReadableStreamDefaultController( - stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, sizeAlgorithm - ); + SetUpReadableStreamDefaultController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, sizeAlgorithm); return stream; } diff --git a/src/lib/readable-stream/async-iterator.ts b/src/lib/readable-stream/async-iterator.ts index 65029f5..590271b 100644 --- a/src/lib/readable-stream/async-iterator.ts +++ b/src/lib/readable-stream/async-iterator.ts @@ -44,17 +44,17 @@ export class ReadableStreamAsyncIteratorImpl { next(): Promise> { const nextSteps = () => this._nextSteps(); - this._ongoingPromise = this._ongoingPromise ? - transformPromiseWith(this._ongoingPromise, nextSteps, nextSteps) : - nextSteps(); + this._ongoingPromise = this._ongoingPromise + ? transformPromiseWith(this._ongoingPromise, nextSteps, nextSteps) + : nextSteps(); return this._ongoingPromise; } return(value: any): Promise> { const returnSteps = () => this._returnSteps(value); - return this._ongoingPromise ? - transformPromiseWith(this._ongoingPromise, returnSteps, returnSteps) : - returnSteps(); + return this._ongoingPromise + ? transformPromiseWith(this._ongoingPromise, returnSteps, returnSteps) + : returnSteps(); } private _nextSteps(): Promise> { @@ -153,8 +153,10 @@ Object.defineProperty(ReadableStreamAsyncIteratorPrototype, SymbolAsyncIterator, // Abstract operations for the ReadableStream. -export function AcquireReadableStreamAsyncIterator(stream: ReadableStream, - preventCancel: boolean): ReadableStreamAsyncIterator { +export function AcquireReadableStreamAsyncIterator( + stream: ReadableStream, + preventCancel: boolean +): ReadableStreamAsyncIterator { const reader = AcquireReadableStreamDefaultReader(stream); const impl = new ReadableStreamAsyncIteratorImpl(reader, preventCancel); const iterator: ReadableStreamAsyncIteratorInstance = Object.create(ReadableStreamAsyncIteratorPrototype); @@ -173,8 +175,8 @@ function IsReadableStreamAsyncIterator(x: any): x is ReadableStreamAsyn try { // noinspection SuspiciousTypeOfGuard - return (x as ReadableStreamAsyncIteratorInstance)._asyncIteratorImpl instanceof - ReadableStreamAsyncIteratorImpl; + return (x as ReadableStreamAsyncIteratorInstance)._asyncIteratorImpl + instanceof ReadableStreamAsyncIteratorImpl; } catch { return false; } diff --git a/src/lib/readable-stream/byob-reader.ts b/src/lib/readable-stream/byob-reader.ts index aad4f68..3419c3a 100644 --- a/src/lib/readable-stream/byob-reader.ts +++ b/src/lib/readable-stream/byob-reader.ts @@ -55,9 +55,11 @@ export function ReadableStreamAddReadIntoRequest 0); @@ -124,8 +126,8 @@ export class ReadableStreamBYOBReader { } if (!IsReadableByteStreamController(stream._readableStreamController)) { - throw new TypeError('Cannot construct a ReadableStreamBYOBReader for a stream not constructed with a byte ' + - 'source'); + throw new TypeError('Cannot construct a ReadableStreamBYOBReader for a stream not constructed with a byte ' + + 'source'); } ReadableStreamReaderGenericInitialize(this, stream); @@ -320,6 +322,5 @@ export function ReadableStreamBYOBReaderErrorReadIntoRequests(reader: ReadableSt // Helper functions for the ReadableStreamBYOBReader. function byobReaderBrandCheckException(name: string): TypeError { - return new TypeError( - `ReadableStreamBYOBReader.prototype.${name} can only be used on a ReadableStreamBYOBReader`); + return new TypeError(`ReadableStreamBYOBReader.prototype.${name} can only be used on a ReadableStreamBYOBReader`); } diff --git a/src/lib/readable-stream/byte-stream-controller.ts b/src/lib/readable-stream/byte-stream-controller.ts index 53528bb..6c951a1 100644 --- a/src/lib/readable-stream/byte-stream-controller.ts +++ b/src/lib/readable-stream/byte-stream-controller.ts @@ -470,31 +470,32 @@ function ReadableByteStreamControllerCommitPullIntoDescriptor>( - pullIntoDescriptor: PullIntoDescriptor -): T { +function ReadableByteStreamControllerConvertPullIntoDescriptor>(pullIntoDescriptor: PullIntoDescriptor): T { const bytesFilled = pullIntoDescriptor.bytesFilled; const elementSize = pullIntoDescriptor.elementSize; assert(bytesFilled <= pullIntoDescriptor.byteLength); assert(bytesFilled % elementSize === 0); - return new pullIntoDescriptor.viewConstructor( - pullIntoDescriptor.buffer, pullIntoDescriptor.byteOffset, bytesFilled / elementSize) as T; + return new pullIntoDescriptor.viewConstructor(pullIntoDescriptor.buffer, pullIntoDescriptor.byteOffset, bytesFilled / elementSize) as T; } -function ReadableByteStreamControllerEnqueueChunkToQueue(controller: ReadableByteStreamController, - buffer: ArrayBuffer, - byteOffset: number, - byteLength: number) { +function ReadableByteStreamControllerEnqueueChunkToQueue( + controller: ReadableByteStreamController, + buffer: ArrayBuffer, + byteOffset: number, + byteLength: number +) { controller._queue.push({ buffer, byteOffset, byteLength }); controller._queueTotalSize += byteLength; } -function ReadableByteStreamControllerEnqueueClonedChunkToQueue(controller: ReadableByteStreamController, - buffer: ArrayBuffer, - byteOffset: number, - byteLength: number) { +function ReadableByteStreamControllerEnqueueClonedChunkToQueue( + controller: ReadableByteStreamController, + buffer: ArrayBuffer, + byteOffset: number, + byteLength: number +) { let clonedChunk; try { clonedChunk = ArrayBufferSlice(buffer, byteOffset, byteOffset + byteLength); @@ -505,8 +506,10 @@ function ReadableByteStreamControllerEnqueueClonedChunkToQueue(controller: Reada ReadableByteStreamControllerEnqueueChunkToQueue(controller, clonedChunk, 0, byteLength); } -function ReadableByteStreamControllerEnqueueDetachedPullIntoToQueue(controller: ReadableByteStreamController, - firstDescriptor: PullIntoDescriptor) { +function ReadableByteStreamControllerEnqueueDetachedPullIntoToQueue( + controller: ReadableByteStreamController, + firstDescriptor: PullIntoDescriptor +) { assert(firstDescriptor.readerType === 'none'); if (firstDescriptor.bytesFilled > 0) { ReadableByteStreamControllerEnqueueClonedChunkToQueue( @@ -519,10 +522,14 @@ function ReadableByteStreamControllerEnqueueDetachedPullIntoToQueue(controller: ReadableByteStreamControllerShiftPendingPullInto(controller); } -function ReadableByteStreamControllerFillPullIntoDescriptorFromQueue(controller: ReadableByteStreamController, - pullIntoDescriptor: PullIntoDescriptor) { - const maxBytesToCopy = Math.min(controller._queueTotalSize, - pullIntoDescriptor.byteLength - pullIntoDescriptor.bytesFilled); +function ReadableByteStreamControllerFillPullIntoDescriptorFromQueue( + controller: ReadableByteStreamController, + pullIntoDescriptor: PullIntoDescriptor +) { + const maxBytesToCopy = Math.min( + controller._queueTotalSize, + pullIntoDescriptor.byteLength - pullIntoDescriptor.bytesFilled + ); const maxBytesFilled = pullIntoDescriptor.bytesFilled + maxBytesToCopy; let totalBytesToCopyRemaining = maxBytesToCopy; @@ -569,9 +576,11 @@ function ReadableByteStreamControllerFillPullIntoDescriptorFromQueue(controller: return ready; } -function ReadableByteStreamControllerFillHeadPullIntoDescriptor(controller: ReadableByteStreamController, - size: number, - pullIntoDescriptor: PullIntoDescriptor) { +function ReadableByteStreamControllerFillHeadPullIntoDescriptor( + controller: ReadableByteStreamController, + size: number, + pullIntoDescriptor: PullIntoDescriptor +) { assert(controller._pendingPullIntos.length === 0 || controller._pendingPullIntos.peek() === pullIntoDescriptor); assert(controller._byobRequest === null); pullIntoDescriptor.bytesFilled += size; @@ -711,8 +720,10 @@ export function ReadableByteStreamControllerPullInto 0) { const firstPendingPullInto = controller._pendingPullIntos.peek(); if (IsDetachedBuffer(firstPendingPullInto.buffer)) { - throw new TypeError( - 'The BYOB request\'s buffer has been detached and so cannot be filled with an enqueued chunk' - ); + throw new TypeError('The BYOB request\'s buffer has been detached and so cannot be filled with an enqueued chunk'); } ReadableByteStreamControllerInvalidateBYOBRequest(controller); firstPendingPullInto.buffer = TransferArrayBuffer(firstPendingPullInto.buffer); @@ -944,14 +953,14 @@ export function ReadableByteStreamControllerFillReadRequestFromQueue( readRequest._chunkSteps(view as NonShared); } -export function ReadableByteStreamControllerGetBYOBRequest( - controller: ReadableByteStreamController -): ReadableStreamBYOBRequest | null { +export function ReadableByteStreamControllerGetBYOBRequest(controller: ReadableByteStreamController): ReadableStreamBYOBRequest | null { if (controller._byobRequest === null && controller._pendingPullIntos.length > 0) { const firstDescriptor = controller._pendingPullIntos.peek(); - const view = new Uint8Array(firstDescriptor.buffer, - firstDescriptor.byteOffset + firstDescriptor.bytesFilled, - firstDescriptor.byteLength - firstDescriptor.bytesFilled); + const view = new Uint8Array( + firstDescriptor.buffer, + firstDescriptor.byteOffset + firstDescriptor.bytesFilled, + firstDescriptor.byteLength - firstDescriptor.bytesFilled + ); const byobRequest: ReadableStreamBYOBRequest = Object.create(ReadableStreamBYOBRequest.prototype); SetUpReadableStreamBYOBRequest(byobRequest, controller, view as NonShared); @@ -998,8 +1007,10 @@ export function ReadableByteStreamControllerRespond(controller: ReadableByteStre ReadableByteStreamControllerRespondInternal(controller, bytesWritten); } -export function ReadableByteStreamControllerRespondWithNewView(controller: ReadableByteStreamController, - view: NonShared) { +export function ReadableByteStreamControllerRespondWithNewView( + controller: ReadableByteStreamController, + view: NonShared +) { assert(controller._pendingPullIntos.length > 0); assert(!IsDetachedBuffer(view.buffer)); @@ -1013,9 +1024,7 @@ export function ReadableByteStreamControllerRespondWithNewView(controller: Reada } else { assert(state === 'readable'); if (view.byteLength === 0) { - throw new TypeError( - 'The view\'s length must be greater than 0 when calling respondWithNewView() on a readable stream' - ); + throw new TypeError('The view\'s length must be greater than 0 when calling respondWithNewView() on a readable stream'); } } @@ -1034,13 +1043,15 @@ export function ReadableByteStreamControllerRespondWithNewView(controller: Reada ReadableByteStreamControllerRespondInternal(controller, viewByteLength); } -export function SetUpReadableByteStreamController(stream: ReadableByteStream, - controller: ReadableByteStreamController, - startAlgorithm: () => void | PromiseLike, - pullAlgorithm: () => Promise, - cancelAlgorithm: (reason: any) => Promise, - highWaterMark: number, - autoAllocateChunkSize: number | undefined) { +export function SetUpReadableByteStreamController( + stream: ReadableByteStream, + controller: ReadableByteStreamController, + startAlgorithm: () => void | PromiseLike, + pullAlgorithm: () => Promise, + cancelAlgorithm: (reason: any) => Promise, + highWaterMark: number, + autoAllocateChunkSize: number | undefined +) { assert(stream._readableStreamController === undefined); if (autoAllocateChunkSize !== undefined) { assert(NumberIsInteger(autoAllocateChunkSize)); @@ -1123,14 +1134,14 @@ export function SetUpReadableByteStreamControllerFromUnderlyingSource( throw new TypeError('autoAllocateChunkSize must be greater than 0'); } - SetUpReadableByteStreamController( - stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, autoAllocateChunkSize - ); + SetUpReadableByteStreamController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, autoAllocateChunkSize); } -function SetUpReadableStreamBYOBRequest(request: ReadableStreamBYOBRequest, - controller: ReadableByteStreamController, - view: NonShared) { +function SetUpReadableStreamBYOBRequest( + request: ReadableStreamBYOBRequest, + controller: ReadableByteStreamController, + view: NonShared +) { assert(IsReadableByteStreamController(controller)); assert(typeof view === 'object'); assert(ArrayBuffer.isView(view)); @@ -1142,13 +1153,11 @@ function SetUpReadableStreamBYOBRequest(request: ReadableStreamBYOBRequest, // Helper functions for the ReadableStreamBYOBRequest. function byobRequestBrandCheckException(name: string): TypeError { - return new TypeError( - `ReadableStreamBYOBRequest.prototype.${name} can only be used on a ReadableStreamBYOBRequest`); + return new TypeError(`ReadableStreamBYOBRequest.prototype.${name} can only be used on a ReadableStreamBYOBRequest`); } // Helper functions for the ReadableByteStreamController. function byteStreamControllerBrandCheckException(name: string): TypeError { - return new TypeError( - `ReadableByteStreamController.prototype.${name} can only be used on a ReadableByteStreamController`); + return new TypeError(`ReadableByteStreamController.prototype.${name} can only be used on a ReadableByteStreamController`); } diff --git a/src/lib/readable-stream/default-controller.ts b/src/lib/readable-stream/default-controller.ts index 6ad8812..91f48d7 100644 --- a/src/lib/readable-stream/default-controller.ts +++ b/src/lib/readable-stream/default-controller.ts @@ -294,9 +294,7 @@ export function ReadableStreamDefaultControllerError(controller: ReadableStreamD ReadableStreamError(stream, e); } -export function ReadableStreamDefaultControllerGetDesiredSize( - controller: ReadableStreamDefaultController -): number | null { +export function ReadableStreamDefaultControllerGetDesiredSize(controller: ReadableStreamDefaultController): number | null { const state = controller._controlledReadableStream._state; if (state === 'errored') { @@ -310,9 +308,7 @@ export function ReadableStreamDefaultControllerGetDesiredSize( } // This is used in the implementation of TransformStream. -export function ReadableStreamDefaultControllerHasBackpressure( - controller: ReadableStreamDefaultController -): boolean { +export function ReadableStreamDefaultControllerHasBackpressure(controller: ReadableStreamDefaultController): boolean { if (ReadableStreamDefaultControllerShouldCallPull(controller)) { return false; } @@ -320,9 +316,7 @@ export function ReadableStreamDefaultControllerHasBackpressure( return true; } -export function ReadableStreamDefaultControllerCanCloseOrEnqueue( - controller: ReadableStreamDefaultController -): boolean { +export function ReadableStreamDefaultControllerCanCloseOrEnqueue(controller: ReadableStreamDefaultController): boolean { const state = controller._controlledReadableStream._state; if (!controller._closeRequested && state === 'readable') { @@ -332,13 +326,15 @@ export function ReadableStreamDefaultControllerCanCloseOrEnqueue( return false; } -export function SetUpReadableStreamDefaultController(stream: ReadableStream, - controller: ReadableStreamDefaultController, - startAlgorithm: () => void | PromiseLike, - pullAlgorithm: () => Promise, - cancelAlgorithm: (reason: any) => Promise, - highWaterMark: number, - sizeAlgorithm: QueuingStrategySizeCallback) { +export function SetUpReadableStreamDefaultController( + stream: ReadableStream, + controller: ReadableStreamDefaultController, + startAlgorithm: () => void | PromiseLike, + pullAlgorithm: () => Promise, + cancelAlgorithm: (reason: any) => Promise, + highWaterMark: number, + sizeAlgorithm: QueuingStrategySizeCallback +) { assert(stream._readableStreamController === undefined); controller._controlledReadableStream = stream; @@ -407,14 +403,11 @@ export function SetUpReadableStreamDefaultControllerFromUnderlyingSource( cancelAlgorithm = () => promiseResolvedWith(undefined); } - SetUpReadableStreamDefaultController( - stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, sizeAlgorithm - ); + SetUpReadableStreamDefaultController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, sizeAlgorithm); } // Helper functions for the ReadableStreamDefaultController. function defaultControllerBrandCheckException(name: string): TypeError { - return new TypeError( - `ReadableStreamDefaultController.prototype.${name} can only be used on a ReadableStreamDefaultController`); + return new TypeError(`ReadableStreamDefaultController.prototype.${name} can only be used on a ReadableStreamDefaultController`); } diff --git a/src/lib/readable-stream/default-reader.ts b/src/lib/readable-stream/default-reader.ts index 48023dd..d48b0ad 100644 --- a/src/lib/readable-stream/default-reader.ts +++ b/src/lib/readable-stream/default-reader.ts @@ -34,8 +34,10 @@ export function AcquireReadableStreamDefaultReader(stream: ReadableStream): R // ReadableStream API exposed for controllers. -export function ReadableStreamAddReadRequest(stream: ReadableStream, - readRequest: ReadRequest): void { +export function ReadableStreamAddReadRequest( + stream: ReadableStream, + readRequest: ReadRequest +): void { assert(IsReadableStreamDefaultReader(stream._reader)); assert(stream._state === 'readable'); @@ -221,8 +223,10 @@ export function IsReadableStreamDefaultReader(x: any): x is ReadableStr return x instanceof ReadableStreamDefaultReader; } -export function ReadableStreamDefaultReaderRead(reader: ReadableStreamDefaultReader, - readRequest: ReadRequest): void { +export function ReadableStreamDefaultReaderRead( + reader: ReadableStreamDefaultReader, + readRequest: ReadRequest +): void { const stream = reader._ownerReadableStream; assert(stream !== undefined); @@ -256,6 +260,5 @@ export function ReadableStreamDefaultReaderErrorReadRequests(reader: ReadableStr // Helper functions for the ReadableStreamDefaultReader. function defaultReaderBrandCheckException(name: string): TypeError { - return new TypeError( - `ReadableStreamDefaultReader.prototype.${name} can only be used on a ReadableStreamDefaultReader`); + return new TypeError(`ReadableStreamDefaultReader.prototype.${name} can only be used on a ReadableStreamDefaultReader`); } diff --git a/src/lib/readable-stream/from.ts b/src/lib/readable-stream/from.ts index d36cea5..d745178 100644 --- a/src/lib/readable-stream/from.ts +++ b/src/lib/readable-stream/from.ts @@ -10,9 +10,7 @@ import { promiseCall, promiseRejectedWith, promiseResolvedWith, transformPromise import { typeIsObject } from '../helpers/miscellaneous'; import { noop } from '../../utils'; -export function ReadableStreamFrom( - source: Iterable | AsyncIterable | ReadableStreamLike -): DefaultReadableStream { +export function ReadableStreamFrom(source: Iterable | AsyncIterable | ReadableStreamLike): DefaultReadableStream { if (isReadableStreamLike(source)) { return ReadableStreamFromDefaultReader(source.getReader()); } @@ -71,9 +69,7 @@ export function ReadableStreamFromIterable(asyncIterable: Iterable | Async return stream; } -export function ReadableStreamFromDefaultReader( - reader: ReadableStreamDefaultReaderLike -): DefaultReadableStream { +export function ReadableStreamFromDefaultReader(reader: ReadableStreamDefaultReaderLike): DefaultReadableStream { let stream: DefaultReadableStream; const startAlgorithm = noop; diff --git a/src/lib/readable-stream/generic-reader.ts b/src/lib/readable-stream/generic-reader.ts index 4563ee9..0ce7120 100644 --- a/src/lib/readable-stream/generic-reader.ts +++ b/src/lib/readable-stream/generic-reader.ts @@ -35,11 +35,13 @@ export function ReadableStreamReaderGenericRelease(reader: ReadableStreamReader< if (stream._state === 'readable') { defaultReaderClosedPromiseReject( reader, - new TypeError(`Reader was released and can no longer be used to monitor the stream's closedness`)); + 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`)); + new TypeError(`Reader was released and can no longer be used to monitor the stream's closedness`) + ); } stream._readableStreamController[ReleaseSteps](); diff --git a/src/lib/readable-stream/pipe.ts b/src/lib/readable-stream/pipe.ts index c84e203..fb3379c 100644 --- a/src/lib/readable-stream/pipe.ts +++ b/src/lib/readable-stream/pipe.ts @@ -26,12 +26,14 @@ import { noop } from '../../utils'; import { type AbortSignal, isAbortSignal } from '../abort-signal'; import { DOMException } from '../../stub/dom-exception'; -export function ReadableStreamPipeTo(source: ReadableStream, - dest: WritableStream, - preventClose: boolean, - preventAbort: boolean, - preventCancel: boolean, - signal: AbortSignal | undefined): Promise { +export function ReadableStreamPipeTo( + source: ReadableStream, + dest: WritableStream, + preventClose: boolean, + preventAbort: boolean, + preventCancel: boolean, + signal: AbortSignal | undefined +): Promise { assert(IsReadableStream(source)); assert(IsWritableStream(dest)); assert(typeof preventClose === 'boolean'); @@ -178,9 +180,11 @@ export function ReadableStreamPipeTo(source: ReadableStream, ); } - function isOrBecomesErrored(stream: ReadableStream | WritableStream, - promise: Promise, - action: (reason: any) => null) { + function isOrBecomesErrored( + stream: ReadableStream | WritableStream, + promise: Promise, + action: (reason: any) => null + ) { if (stream._state === 'errored') { action(stream._storedError); } else { diff --git a/src/lib/readable-stream/tee.ts b/src/lib/readable-stream/tee.ts index ad8f4ba..578c02c 100644 --- a/src/lib/readable-stream/tee.ts +++ b/src/lib/readable-stream/tee.ts @@ -41,8 +41,10 @@ import { CreateArrayFromList } from '../abstract-ops/ecmascript'; import { CloneAsUint8Array } from '../abstract-ops/miscellaneous'; import type { NonShared } from '../helpers/array-buffer-view'; -export function ReadableStreamTee(stream: ReadableStream, - cloneForBranch2: boolean): [ReadableStream, ReadableStream] { +export function ReadableStreamTee( + stream: ReadableStream, + cloneForBranch2: boolean +): [ReadableStream, ReadableStream] { assert(IsReadableStream(stream)); assert(typeof cloneForBranch2 === 'boolean'); if (IsReadableByteStreamController(stream._readableStreamController)) { diff --git a/src/lib/transform-stream.ts b/src/lib/transform-stream.ts index 2d292be..d30c99c 100644 --- a/src/lib/transform-stream.ts +++ b/src/lib/transform-stream.ts @@ -61,9 +61,11 @@ export class TransformStream { writableStrategy?: QueuingStrategy, readableStrategy?: QueuingStrategy ); - constructor(rawTransformer: Transformer | null | undefined = {}, + constructor( +rawTransformer: Transformer | null | undefined = {}, rawWritableStrategy: QueuingStrategy | null | undefined = {}, - rawReadableStrategy: QueuingStrategy | null | undefined = {}) { + rawReadableStrategy: QueuingStrategy | null | undefined = {} + ) { if (rawTransformer === undefined) { rawTransformer = null; } @@ -89,9 +91,7 @@ export class TransformStream { startPromise_resolve = resolve; }); - InitializeTransformStream( - this, startPromise, writableHighWaterMark, writableSizeAlgorithm, readableHighWaterMark, readableSizeAlgorithm - ); + InitializeTransformStream(this, startPromise, writableHighWaterMark, writableSizeAlgorithm, readableHighWaterMark, readableSizeAlgorithm); SetUpTransformStreamDefaultControllerFromTransformer(this, transformer); if (transformer.start !== undefined) { @@ -145,14 +145,16 @@ export type { // Transform Stream Abstract Operations -export function CreateTransformStream(startAlgorithm: () => void | PromiseLike, - transformAlgorithm: (chunk: I) => Promise, - flushAlgorithm: () => Promise, - cancelAlgorithm: (reason: any) => Promise, - writableHighWaterMark = 1, - writableSizeAlgorithm: QueuingStrategySizeCallback = () => 1, - readableHighWaterMark = 0, - readableSizeAlgorithm: QueuingStrategySizeCallback = () => 1) { +export function CreateTransformStream( + startAlgorithm: () => void | PromiseLike, + transformAlgorithm: (chunk: I) => Promise, + flushAlgorithm: () => Promise, + cancelAlgorithm: (reason: any) => Promise, + writableHighWaterMark = 1, + writableSizeAlgorithm: QueuingStrategySizeCallback = () => 1, + readableHighWaterMark = 0, + readableSizeAlgorithm: QueuingStrategySizeCallback = () => 1 +) { assert(IsNonNegativeNumber(writableHighWaterMark)); assert(IsNonNegativeNumber(readableHighWaterMark)); @@ -163,8 +165,10 @@ export function CreateTransformStream(startAlgorithm: () => void | Promise startPromise_resolve = resolve; }); - InitializeTransformStream(stream, startPromise, writableHighWaterMark, writableSizeAlgorithm, readableHighWaterMark, - readableSizeAlgorithm); + InitializeTransformStream( + stream, startPromise, writableHighWaterMark, writableSizeAlgorithm, readableHighWaterMark, + readableSizeAlgorithm + ); const controller: TransformStreamDefaultController = Object.create(TransformStreamDefaultController.prototype); @@ -175,12 +179,14 @@ export function CreateTransformStream(startAlgorithm: () => void | Promise return stream; } -function InitializeTransformStream(stream: TransformStream, - startPromise: Promise, - writableHighWaterMark: number, - writableSizeAlgorithm: QueuingStrategySizeCallback, - readableHighWaterMark: number, - readableSizeAlgorithm: QueuingStrategySizeCallback) { +function InitializeTransformStream( + stream: TransformStream, + startPromise: Promise, + writableHighWaterMark: number, + writableSizeAlgorithm: QueuingStrategySizeCallback, + readableHighWaterMark: number, + readableSizeAlgorithm: QueuingStrategySizeCallback +) { function startAlgorithm(): Promise { return startPromise; } @@ -197,8 +203,10 @@ function InitializeTransformStream(stream: TransformStream, return TransformStreamDefaultSinkCloseAlgorithm(stream); } - stream._writable = CreateWritableStream(startAlgorithm, writeAlgorithm, closeAlgorithm, abortAlgorithm, - writableHighWaterMark, writableSizeAlgorithm); + stream._writable = CreateWritableStream( + startAlgorithm, writeAlgorithm, closeAlgorithm, abortAlgorithm, + writableHighWaterMark, writableSizeAlgorithm + ); function pullAlgorithm(): Promise { return TransformStreamDefaultSourcePullAlgorithm(stream); @@ -208,8 +216,10 @@ function InitializeTransformStream(stream: TransformStream, return TransformStreamDefaultSourceCancelAlgorithm(stream, reason); } - stream._readable = CreateReadableStream(startAlgorithm, pullAlgorithm, cancelAlgorithm, readableHighWaterMark, - readableSizeAlgorithm); + stream._readable = CreateReadableStream( + startAlgorithm, pullAlgorithm, cancelAlgorithm, readableHighWaterMark, + readableSizeAlgorithm + ); // The [[backpressure]] slot is set to undefined so that it can be initialised by TransformStreamSetBackpressure. stream._backpressure = undefined!; @@ -374,11 +384,13 @@ function IsTransformStreamDefaultController(x: any): x is TransformStre return x instanceof TransformStreamDefaultController; } -function SetUpTransformStreamDefaultController(stream: TransformStream, - controller: TransformStreamDefaultController, - transformAlgorithm: (chunk: I) => Promise, - flushAlgorithm: () => Promise, - cancelAlgorithm: (reason: any) => Promise) { +function SetUpTransformStreamDefaultController( + stream: TransformStream, + controller: TransformStreamDefaultController, + transformAlgorithm: (chunk: I) => Promise, + flushAlgorithm: () => Promise, + cancelAlgorithm: (reason: any) => Promise +) { assert(IsTransformStream(stream)); assert(stream._transformStreamController === undefined); @@ -394,8 +406,10 @@ function SetUpTransformStreamDefaultController(stream: TransformStream(stream: TransformStream, - transformer: ValidatedTransformer) { +function SetUpTransformStreamDefaultControllerFromTransformer( + stream: TransformStream, + transformer: ValidatedTransformer +) { const controller: TransformStreamDefaultController = Object.create(TransformStreamDefaultController.prototype); let transformAlgorithm: (chunk: I) => Promise; @@ -466,8 +480,10 @@ function TransformStreamDefaultControllerError(controller: TransformStreamDefaul TransformStreamError(controller._controlledTransformStream, e); } -function TransformStreamDefaultControllerPerformTransform(controller: TransformStreamDefaultController, - chunk: I) { +function TransformStreamDefaultControllerPerformTransform( + controller: TransformStreamDefaultController, + chunk: I +) { const transformPromise = controller._transformAlgorithm(chunk); return transformPromiseWith(transformPromise, undefined, (r) => { TransformStreamError(controller._controlledTransformStream, r); @@ -637,8 +653,7 @@ function TransformStreamDefaultSourceCancelAlgorithm(stream: TransformStre // Helper functions for the TransformStreamDefaultController. function defaultControllerBrandCheckException(name: string): TypeError { - return new TypeError( - `TransformStreamDefaultController.prototype.${name} can only be used on a TransformStreamDefaultController`); + return new TypeError(`TransformStreamDefaultController.prototype.${name} can only be used on a TransformStreamDefaultController`); } export function defaultControllerFinishPromiseResolve(controller: TransformStreamDefaultController) { @@ -665,6 +680,5 @@ export function defaultControllerFinishPromiseReject(controller: TransformStream // Helper functions for the TransformStream. function streamBrandCheckException(name: string): TypeError { - return new TypeError( - `TransformStream.prototype.${name} can only be used on a TransformStream`); + return new TypeError(`TransformStream.prototype.${name} can only be used on a TransformStream`); } diff --git a/src/lib/validators/basic.ts b/src/lib/validators/basic.ts index 4e58084..a310b3f 100644 --- a/src/lib/validators/basic.ts +++ b/src/lib/validators/basic.ts @@ -6,8 +6,10 @@ export function isDictionary(x: any): x is object | null { return typeof x === 'object' || typeof x === 'function'; } -export function assertDictionary(obj: unknown, - context: string): asserts obj is object | null | undefined { +export function assertDictionary( + obj: unknown, + context: string +): asserts obj is object | null | undefined { if (obj !== undefined && !isDictionary(obj)) { throw new TypeError(`${context} is not an object.`); } @@ -27,24 +29,30 @@ export function isObject(x: any): x is object { return (typeof x === 'object' && x !== null) || typeof x === 'function'; } -export function assertObject(x: unknown, - context: string): asserts x is object { +export function assertObject( + x: unknown, + context: string +): asserts x is object { if (!isObject(x)) { throw new TypeError(`${context} is not an object.`); } } -export function assertRequiredArgument(x: T | undefined, - position: number, - context: string): asserts x is T { +export function assertRequiredArgument( + x: T | undefined, + position: number, + context: string +): asserts x is T { if (x === undefined) { throw new TypeError(`Parameter ${position} is required in '${context}'.`); } } -export function assertRequiredField(x: T | undefined, - field: string, - context: string): asserts x is T { +export function assertRequiredField( + x: T | undefined, + field: string, + context: string +): asserts x is T { if (x === undefined) { throw new TypeError(`${field} is required in '${context}'.`); } diff --git a/src/lib/validators/iterator-options.ts b/src/lib/validators/iterator-options.ts index f2d3a41..55de514 100644 --- a/src/lib/validators/iterator-options.ts +++ b/src/lib/validators/iterator-options.ts @@ -4,8 +4,10 @@ import type { ValidatedReadableStreamIteratorOptions } from '../readable-stream/iterator-options'; -export function convertIteratorOptions(options: ReadableStreamIteratorOptions | null | undefined, - context: string): ValidatedReadableStreamIteratorOptions { +export function convertIteratorOptions( + options: ReadableStreamIteratorOptions | null | undefined, + context: string +): ValidatedReadableStreamIteratorOptions { assertDictionary(options, context); const preventCancel = options?.preventCancel; return { preventCancel: Boolean(preventCancel) }; diff --git a/src/lib/validators/pipe-options.ts b/src/lib/validators/pipe-options.ts index 4e53130..70defdc 100644 --- a/src/lib/validators/pipe-options.ts +++ b/src/lib/validators/pipe-options.ts @@ -2,8 +2,10 @@ import { assertDictionary } from './basic'; import type { StreamPipeOptions, ValidatedStreamPipeOptions } from '../readable-stream/pipe-options'; import { type AbortSignal, isAbortSignal } from '../abort-signal'; -export function convertPipeOptions(options: StreamPipeOptions | null | undefined, - context: string): ValidatedStreamPipeOptions { +export function convertPipeOptions( + options: StreamPipeOptions | null | undefined, + context: string +): ValidatedStreamPipeOptions { assertDictionary(options, context); const preventAbort = options?.preventAbort; const preventCancel = options?.preventCancel; diff --git a/src/lib/validators/queuing-strategy-init.ts b/src/lib/validators/queuing-strategy-init.ts index a4d74cc..fbcae89 100644 --- a/src/lib/validators/queuing-strategy-init.ts +++ b/src/lib/validators/queuing-strategy-init.ts @@ -1,8 +1,10 @@ import type { QueuingStrategyInit } from '../queuing-strategy'; import { assertDictionary, assertRequiredField, convertUnrestrictedDouble } from './basic'; -export function convertQueuingStrategyInit(init: QueuingStrategyInit | null | undefined, - context: string): QueuingStrategyInit { +export function convertQueuingStrategyInit( + init: QueuingStrategyInit | null | undefined, + context: string +): QueuingStrategyInit { assertDictionary(init, context); const highWaterMark = init?.highWaterMark; assertRequiredField(highWaterMark, 'highWaterMark', 'QueuingStrategyInit'); diff --git a/src/lib/validators/queuing-strategy.ts b/src/lib/validators/queuing-strategy.ts index 3f88a5f..5e36579 100644 --- a/src/lib/validators/queuing-strategy.ts +++ b/src/lib/validators/queuing-strategy.ts @@ -1,8 +1,10 @@ import type { QueuingStrategy, QueuingStrategySizeCallback } from '../queuing-strategy'; import { assertDictionary, assertFunction, convertUnrestrictedDouble } from './basic'; -export function convertQueuingStrategy(init: QueuingStrategy | null | undefined, - context: string): QueuingStrategy { +export function convertQueuingStrategy( + init: QueuingStrategy | null | undefined, + context: string +): QueuingStrategy { assertDictionary(init, context); const highWaterMark = init?.highWaterMark; const size = init?.size; @@ -12,8 +14,10 @@ export function convertQueuingStrategy(init: QueuingStrategy | null | unde }; } -function convertQueuingStrategySize(fn: QueuingStrategySizeCallback, - context: string): QueuingStrategySizeCallback { +function convertQueuingStrategySize( + fn: QueuingStrategySizeCallback, + context: string +): QueuingStrategySizeCallback { assertFunction(fn, context); return chunk => convertUnrestrictedDouble(fn(chunk)); } diff --git a/src/lib/validators/reader-options.ts b/src/lib/validators/reader-options.ts index a34ee63..7f4b228 100644 --- a/src/lib/validators/reader-options.ts +++ b/src/lib/validators/reader-options.ts @@ -5,8 +5,10 @@ import type { ValidatedReadableStreamBYOBReaderReadOptions } from '../readable-stream/reader-options'; -export function convertReaderOptions(options: ReadableStreamGetReaderOptions | null | undefined, - context: string): ReadableStreamGetReaderOptions { +export function convertReaderOptions( + options: ReadableStreamGetReaderOptions | null | undefined, + context: string +): ReadableStreamGetReaderOptions { assertDictionary(options, context); const mode = options?.mode; return { diff --git a/src/lib/validators/transformer.ts b/src/lib/validators/transformer.ts index 5fef086..25025e2 100644 --- a/src/lib/validators/transformer.ts +++ b/src/lib/validators/transformer.ts @@ -10,8 +10,10 @@ import type { } from '../transform-stream/transformer'; import { TransformStreamDefaultController } from '../transform-stream'; -export function convertTransformer(original: Transformer | null, - context: string): ValidatedTransformer { +export function convertTransformer( + original: Transformer | null, + context: string +): ValidatedTransformer { assertDictionary(original, context); const cancel = original?.cancel; const flush = original?.flush; @@ -20,19 +22,19 @@ export function convertTransformer(original: Transformer | null, const transform = original?.transform; const writableType = original?.writableType; return { - cancel: cancel === undefined ? - undefined : - convertTransformerCancelCallback(cancel, original!, `${context} has member 'cancel' that`), - flush: flush === undefined ? - undefined : - convertTransformerFlushCallback(flush, original!, `${context} has member 'flush' that`), + cancel: cancel === undefined + ? undefined + : convertTransformerCancelCallback(cancel, original!, `${context} has member 'cancel' that`), + flush: flush === undefined + ? undefined + : convertTransformerFlushCallback(flush, original!, `${context} has member 'flush' that`), readableType, - start: start === undefined ? - undefined : - convertTransformerStartCallback(start, original!, `${context} has member 'start' that`), - transform: transform === undefined ? - undefined : - convertTransformerTransformCallback(transform, original!, `${context} has member 'transform' that`), + start: start === undefined + ? undefined + : convertTransformerStartCallback(start, original!, `${context} has member 'start' that`), + transform: transform === undefined + ? undefined + : convertTransformerTransformCallback(transform, original!, `${context} has member 'transform' that`), writableType }; } diff --git a/src/lib/validators/underlying-sink.ts b/src/lib/validators/underlying-sink.ts index a804ef0..7502a55 100644 --- a/src/lib/validators/underlying-sink.ts +++ b/src/lib/validators/underlying-sink.ts @@ -10,8 +10,10 @@ import type { } from '../writable-stream/underlying-sink'; import { WritableStreamDefaultController } from '../writable-stream'; -export function convertUnderlyingSink(original: UnderlyingSink | null, - context: string): ValidatedUnderlyingSink { +export function convertUnderlyingSink( + original: UnderlyingSink | null, + context: string +): ValidatedUnderlyingSink { assertDictionary(original, context); const abort = original?.abort; const close = original?.close; @@ -19,18 +21,18 @@ export function convertUnderlyingSink(original: UnderlyingSink | null, const type = original?.type; const write = original?.write; return { - abort: abort === undefined ? - undefined : - convertUnderlyingSinkAbortCallback(abort, original!, `${context} has member 'abort' that`), - close: close === undefined ? - undefined : - convertUnderlyingSinkCloseCallback(close, original!, `${context} has member 'close' that`), - start: start === undefined ? - undefined : - convertUnderlyingSinkStartCallback(start, original!, `${context} has member 'start' that`), - write: write === undefined ? - undefined : - convertUnderlyingSinkWriteCallback(write, original!, `${context} has member 'write' that`), + abort: abort === undefined + ? undefined + : convertUnderlyingSinkAbortCallback(abort, original!, `${context} has member 'abort' that`), + close: close === undefined + ? undefined + : convertUnderlyingSinkCloseCallback(close, original!, `${context} has member 'close' that`), + start: start === undefined + ? undefined + : convertUnderlyingSinkStartCallback(start, original!, `${context} has member 'start' that`), + write: write === undefined + ? undefined + : convertUnderlyingSinkWriteCallback(write, original!, `${context} has member 'write' that`), type }; } diff --git a/src/lib/validators/underlying-source.ts b/src/lib/validators/underlying-source.ts index 5b1f94c..b70e34f 100644 --- a/src/lib/validators/underlying-source.ts +++ b/src/lib/validators/underlying-source.ts @@ -23,21 +23,21 @@ export function convertUnderlyingDefaultOrByteSource( const start = original?.start; const type = original?.type; return { - autoAllocateChunkSize: autoAllocateChunkSize === undefined ? - undefined : - convertUnsignedLongLongWithEnforceRange( + autoAllocateChunkSize: autoAllocateChunkSize === undefined + ? undefined + : convertUnsignedLongLongWithEnforceRange( autoAllocateChunkSize, `${context} has member 'autoAllocateChunkSize' that` ), - cancel: cancel === undefined ? - undefined : - convertUnderlyingSourceCancelCallback(cancel, original!, `${context} has member 'cancel' that`), - pull: pull === undefined ? - undefined : - convertUnderlyingSourcePullCallback(pull, original!, `${context} has member 'pull' that`), - start: start === undefined ? - undefined : - convertUnderlyingSourceStartCallback(start, original!, `${context} has member 'start' that`), + cancel: cancel === undefined + ? undefined + : convertUnderlyingSourceCancelCallback(cancel, original!, `${context} has member 'cancel' that`), + pull: pull === undefined + ? undefined + : convertUnderlyingSourcePullCallback(pull, original!, `${context} has member 'pull' that`), + start: start === undefined + ? undefined + : convertUnderlyingSourceStartCallback(start, original!, `${context} has member 'start' that`), type: type === undefined ? undefined : convertReadableStreamType(type, `${context} has member 'type' that`) }; } diff --git a/src/lib/writable-stream.ts b/src/lib/writable-stream.ts index 87e484f..495fa55 100644 --- a/src/lib/writable-stream.ts +++ b/src/lib/writable-stream.ts @@ -79,8 +79,10 @@ class WritableStream { _backpressure!: boolean; constructor(underlyingSink?: UnderlyingSink, strategy?: QueuingStrategy); - constructor(rawUnderlyingSink: UnderlyingSink | null | undefined = {}, - rawStrategy: QueuingStrategy | null | undefined = {}) { + constructor( +rawUnderlyingSink: UnderlyingSink | null | undefined = {}, + rawStrategy: QueuingStrategy | null | undefined = {} + ) { if (rawUnderlyingSink === undefined) { rawUnderlyingSink = null; } else { @@ -221,12 +223,14 @@ function AcquireWritableStreamDefaultWriter(stream: WritableStream): Writa } // Throws if and only if startAlgorithm throws. -function CreateWritableStream(startAlgorithm: () => void | PromiseLike, - writeAlgorithm: (chunk: W) => Promise, - closeAlgorithm: () => Promise, - abortAlgorithm: (reason: any) => Promise, - highWaterMark = 1, - sizeAlgorithm: QueuingStrategySizeCallback = () => 1) { +function CreateWritableStream( + startAlgorithm: () => void | PromiseLike, + writeAlgorithm: (chunk: W) => Promise, + closeAlgorithm: () => Promise, + abortAlgorithm: (reason: any) => Promise, + highWaterMark = 1, + sizeAlgorithm: QueuingStrategySizeCallback = () => 1 +) { assert(IsNonNegativeNumber(highWaterMark)); const stream: WritableStream = Object.create(WritableStream.prototype); @@ -234,8 +238,10 @@ function CreateWritableStream(startAlgorithm: () => void | PromiseLike, const controller: WritableStreamDefaultController = Object.create(WritableStreamDefaultController.prototype); - SetUpWritableStreamDefaultController(stream, controller, startAlgorithm, writeAlgorithm, closeAlgorithm, - abortAlgorithm, highWaterMark, sizeAlgorithm); + SetUpWritableStreamDefaultController( + stream, controller, startAlgorithm, writeAlgorithm, closeAlgorithm, + abortAlgorithm, highWaterMark, sizeAlgorithm + ); return stream; } @@ -346,8 +352,7 @@ function WritableStreamAbort(stream: WritableStream, reason: any): Promise): Promise { const state = stream._state; if (state === 'closed' || state === 'errored') { - return promiseRejectedWith(new TypeError( - `The stream (in ${state} state) is not in the writable state and cannot be closed`)); + return promiseRejectedWith(new TypeError(`The stream (in ${state} state) is not in the writable state and cannot be closed`)); } assert(state === 'writable' || state === 'erroring'); @@ -459,7 +464,8 @@ function WritableStreamFinishErroring(stream: WritableStream) { abortRequest._reject(reason); WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream); return null; - }); + } + ); } function WritableStreamFinishInFlightWrite(stream: WritableStream) { @@ -885,8 +891,7 @@ function WritableStreamDefaultWriterRelease(writer: WritableStreamDefaultWriter) assert(stream !== undefined); assert(stream._writer === writer); - const releasedError = new TypeError( - `Writer was released and can no longer be used to monitor the stream's closedness`); + const releasedError = new TypeError(`Writer was released and can no longer be used to monitor the stream's closedness`); WritableStreamDefaultWriterEnsureReadyPromiseRejected(writer, releasedError); @@ -1058,14 +1063,16 @@ function IsWritableStreamDefaultController(x: any): x is WritableStreamDefaultCo return x instanceof WritableStreamDefaultController; } -function SetUpWritableStreamDefaultController(stream: WritableStream, - controller: WritableStreamDefaultController, - startAlgorithm: () => void | PromiseLike, - writeAlgorithm: (chunk: W) => Promise, - closeAlgorithm: () => Promise, - abortAlgorithm: (reason: any) => Promise, - highWaterMark: number, - sizeAlgorithm: QueuingStrategySizeCallback) { +function SetUpWritableStreamDefaultController( + stream: WritableStream, + controller: WritableStreamDefaultController, + startAlgorithm: () => void | PromiseLike, + writeAlgorithm: (chunk: W) => Promise, + closeAlgorithm: () => Promise, + abortAlgorithm: (reason: any) => Promise, + highWaterMark: number, + sizeAlgorithm: QueuingStrategySizeCallback +) { assert(IsWritableStream(stream)); assert(stream._writableStreamController === undefined); @@ -1110,10 +1117,12 @@ function SetUpWritableStreamDefaultController(stream: WritableStream, ); } -function SetUpWritableStreamDefaultControllerFromUnderlyingSink(stream: WritableStream, - underlyingSink: ValidatedUnderlyingSink, - highWaterMark: number, - sizeAlgorithm: QueuingStrategySizeCallback) { +function SetUpWritableStreamDefaultControllerFromUnderlyingSink( + stream: WritableStream, + underlyingSink: ValidatedUnderlyingSink, + highWaterMark: number, + sizeAlgorithm: QueuingStrategySizeCallback +) { const controller = Object.create(WritableStreamDefaultController.prototype); let startAlgorithm: () => void | PromiseLike; @@ -1142,9 +1151,7 @@ function SetUpWritableStreamDefaultControllerFromUnderlyingSink(stream: Writa abortAlgorithm = () => promiseResolvedWith(undefined); } - SetUpWritableStreamDefaultController( - stream, controller, startAlgorithm, writeAlgorithm, closeAlgorithm, abortAlgorithm, highWaterMark, sizeAlgorithm - ); + SetUpWritableStreamDefaultController(stream, controller, startAlgorithm, writeAlgorithm, closeAlgorithm, abortAlgorithm, highWaterMark, sizeAlgorithm); } // ClearAlgorithms may be called twice. Erroring the same stream in multiple ways will often result in redundant calls. @@ -1160,8 +1167,10 @@ function WritableStreamDefaultControllerClose(controller: WritableStreamDefau WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller); } -function WritableStreamDefaultControllerGetChunkSize(controller: WritableStreamDefaultController, - chunk: W): number { +function WritableStreamDefaultControllerGetChunkSize( + controller: WritableStreamDefaultController, + chunk: W +): number { try { return controller._strategySizeAlgorithm(chunk); } catch (chunkSizeE) { @@ -1174,9 +1183,11 @@ function WritableStreamDefaultControllerGetDesiredSize(controller: WritableStrea return controller._strategyHWM - controller._queueTotalSize; } -function WritableStreamDefaultControllerWrite(controller: WritableStreamDefaultController, - chunk: W, - chunkSize: number) { +function WritableStreamDefaultControllerWrite( + controller: WritableStreamDefaultController, + chunk: W, + chunkSize: number +) { try { EnqueueValueWithSize(controller, chunk, chunkSize); } catch (enqueueE) { @@ -1313,15 +1324,13 @@ function streamBrandCheckException(name: string): TypeError { // Helper functions for the WritableStreamDefaultController. function defaultControllerBrandCheckException(name: string): TypeError { - return new TypeError( - `WritableStreamDefaultController.prototype.${name} can only be used on a WritableStreamDefaultController`); + return new TypeError(`WritableStreamDefaultController.prototype.${name} can only be used on a WritableStreamDefaultController`); } // Helper functions for the WritableStreamDefaultWriter. function defaultWriterBrandCheckException(name: string): TypeError { - return new TypeError( - `WritableStreamDefaultWriter.prototype.${name} can only be used on a WritableStreamDefaultWriter`); + return new TypeError(`WritableStreamDefaultWriter.prototype.${name} can only be used on a WritableStreamDefaultWriter`); } function defaultWriterLockException(name: string): TypeError { diff --git a/src/stub/number-isinteger.ts b/src/stub/number-isinteger.ts index b533419..939e4b8 100644 --- a/src/stub/number-isinteger.ts +++ b/src/stub/number-isinteger.ts @@ -2,9 +2,9 @@ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isInteger#Polyfill const NumberIsInteger: typeof Number.isInteger = Number.isInteger || function (value) { - return typeof value === 'number' && - isFinite(value) && - Math.floor(value) === value; + return typeof value === 'number' + && isFinite(value) + && Math.floor(value) === value; }; export default NumberIsInteger; diff --git a/src/stub/symbol.ts b/src/stub/symbol.ts index 8138416..fbdcc79 100644 --- a/src/stub/symbol.ts +++ b/src/stub/symbol.ts @@ -1,8 +1,8 @@ /// -const SymbolPolyfill: (description?: string) => symbol = - typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol' ? - Symbol : - description => `Symbol(${description})` as any as symbol; +const SymbolPolyfill: (description?: string) => symbol + = typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol' + ? Symbol + : description => `Symbol(${description})` as any as symbol; export default SymbolPolyfill;