// TODO reenable this code when we enable writableStreams and transport types // // Forked from https://github.com/stardazed/sd-streams/tree/8928cf04b035fd02fb1340b7eb541c76be37e546 // // Copyright (c) 2018-Present by Arthur Langereis - @zenmumbler MIT // /** // * streams/writable-internals - internal types and functions for writable streams // * Part of Stardazed // * (c) 2018-Present by Arthur Langereis - @zenmumbler // * https://github.com/stardazed/sd-streams // */ // /* eslint-disable @typescript-eslint/no-explicit-any */ // // TODO reenable this lint here // import * as shared from "./shared-internals.ts"; // import * as q from "./queue-mixin.ts"; // import { QueuingStrategy, QueuingStrategySizeCallback } from "../dom_types.ts"; // export const backpressure_ = Symbol("backpressure_"); // export const closeRequest_ = Symbol("closeRequest_"); // export const inFlightWriteRequest_ = Symbol("inFlightWriteRequest_"); // export const inFlightCloseRequest_ = Symbol("inFlightCloseRequest_"); // export const pendingAbortRequest_ = Symbol("pendingAbortRequest_"); // export const writableStreamController_ = Symbol("writableStreamController_"); // export const writer_ = Symbol("writer_"); // export const writeRequests_ = Symbol("writeRequests_"); // export const abortAlgorithm_ = Symbol("abortAlgorithm_"); // export const closeAlgorithm_ = Symbol("closeAlgorithm_"); // export const controlledWritableStream_ = Symbol("controlledWritableStream_"); // export const started_ = Symbol("started_"); // export const strategyHWM_ = Symbol("strategyHWM_"); // export const strategySizeAlgorithm_ = Symbol("strategySizeAlgorithm_"); // export const writeAlgorithm_ = Symbol("writeAlgorithm_"); // export const ownerWritableStream_ = Symbol("ownerWritableStream_"); // export const closedPromise_ = Symbol("closedPromise_"); // export const readyPromise_ = Symbol("readyPromise_"); // export const errorSteps_ = Symbol("errorSteps_"); // export const abortSteps_ = Symbol("abortSteps_"); // export type StartFunction = ( // controller: WritableStreamController // ) => void | PromiseLike; // export type StartAlgorithm = () => Promise | void; // export type WriteFunction = ( // chunk: InputType, // controller: WritableStreamController // ) => void | PromiseLike; // export type WriteAlgorithm = (chunk: InputType) => Promise; // export type CloseAlgorithm = () => Promise; // export type AbortAlgorithm = (reason?: shared.ErrorResult) => Promise; // // ---- // export interface WritableStreamController { // error(e?: shared.ErrorResult): void; // [errorSteps_](): void; // [abortSteps_](reason: shared.ErrorResult): Promise; // } // export interface WriteRecord { // chunk: InputType; // } // export interface WritableStreamDefaultController // extends WritableStreamController, // q.QueueContainer | "close"> { // [abortAlgorithm_]: AbortAlgorithm; // A promise - returning algorithm, taking one argument(the abort reason), which communicates a requested abort to the underlying sink // [closeAlgorithm_]: CloseAlgorithm; // A promise - returning algorithm which communicates a requested close to the underlying sink // [controlledWritableStream_]: WritableStream; // The WritableStream instance controlled // [started_]: boolean; // A boolean flag indicating whether the underlying sink has finished starting // [strategyHWM_]: number; // A number supplied by the creator of the stream as part of the stream’s queuing strategy, indicating the point at which the stream will apply backpressure to its underlying sink // [strategySizeAlgorithm_]: QueuingStrategySizeCallback; // An algorithm to calculate the size of enqueued chunks, as part of the stream’s queuing strategy // [writeAlgorithm_]: WriteAlgorithm; // A promise-returning algorithm, taking one argument (the chunk to write), which writes data to the underlying sink // } // // ---- // export interface WritableStreamWriter { // readonly closed: Promise; // readonly desiredSize: number | null; // readonly ready: Promise; // abort(reason: shared.ErrorResult): Promise; // close(): Promise; // releaseLock(): void; // write(chunk: InputType): Promise; // } // export interface WritableStreamDefaultWriter // extends WritableStreamWriter { // [ownerWritableStream_]: WritableStream | undefined; // [closedPromise_]: shared.ControlledPromise; // [readyPromise_]: shared.ControlledPromise; // } // // ---- // export type WritableStreamState = // | "writable" // | "closed" // | "erroring" // | "errored"; // export interface WritableStreamSink { // start?: StartFunction; // write?: WriteFunction; // close?(): void | PromiseLike; // abort?(reason?: shared.ErrorResult): void; // type?: undefined; // unused, for future revisions // } // export interface AbortRequest { // reason: shared.ErrorResult; // wasAlreadyErroring: boolean; // promise: Promise; // resolve(): void; // reject(error: shared.ErrorResult): void; // } // export declare class WritableStream { // constructor( // underlyingSink?: WritableStreamSink, // strategy?: QueuingStrategy // ); // readonly locked: boolean; // abort(reason?: shared.ErrorResult): Promise; // getWriter(): WritableStreamWriter; // [shared.state_]: WritableStreamState; // [backpressure_]: boolean; // [closeRequest_]: shared.ControlledPromise | undefined; // [inFlightWriteRequest_]: shared.ControlledPromise | undefined; // [inFlightCloseRequest_]: shared.ControlledPromise | undefined; // [pendingAbortRequest_]: AbortRequest | undefined; // [shared.storedError_]: shared.ErrorResult; // [writableStreamController_]: // | WritableStreamDefaultController // | undefined; // [writer_]: WritableStreamDefaultWriter | undefined; // [writeRequests_]: Array>; // } // // ---- Stream // export function initializeWritableStream( // stream: WritableStream // ): void { // stream[shared.state_] = "writable"; // stream[shared.storedError_] = undefined; // stream[writer_] = undefined; // stream[writableStreamController_] = undefined; // stream[inFlightWriteRequest_] = undefined; // stream[closeRequest_] = undefined; // stream[inFlightCloseRequest_] = undefined; // stream[pendingAbortRequest_] = undefined; // stream[writeRequests_] = []; // stream[backpressure_] = false; // } // export function isWritableStream(value: unknown): value is WritableStream { // if (typeof value !== "object" || value === null) { // return false; // } // return writableStreamController_ in value; // } // export function isWritableStreamLocked( // stream: WritableStream // ): boolean { // return stream[writer_] !== undefined; // } // export function writableStreamAbort( // stream: WritableStream, // reason: shared.ErrorResult // ): Promise { // const state = stream[shared.state_]; // if (state === "closed" || state === "errored") { // return Promise.resolve(undefined); // } // let pending = stream[pendingAbortRequest_]; // if (pending !== undefined) { // return pending.promise; // } // // Assert: state is "writable" or "erroring". // let wasAlreadyErroring = false; // if (state === "erroring") { // wasAlreadyErroring = true; // reason = undefined; // } // pending = { // reason, // wasAlreadyErroring // } as AbortRequest; // const promise = new Promise((resolve, reject) => { // pending!.resolve = resolve; // pending!.reject = reject; // }); // pending.promise = promise; // stream[pendingAbortRequest_] = pending; // if (!wasAlreadyErroring) { // writableStreamStartErroring(stream, reason); // } // return promise; // } // export function writableStreamAddWriteRequest( // stream: WritableStream // ): Promise { // // Assert: !IsWritableStreamLocked(stream) is true. // // Assert: stream.[[state]] is "writable". // const writePromise = shared.createControlledPromise(); // stream[writeRequests_].push(writePromise); // return writePromise.promise; // } // export function writableStreamDealWithRejection( // stream: WritableStream, // error: shared.ErrorResult // ): void { // const state = stream[shared.state_]; // if (state === "writable") { // writableStreamStartErroring(stream, error); // return; // } // // Assert: state is "erroring" // writableStreamFinishErroring(stream); // } // export function writableStreamStartErroring( // stream: WritableStream, // reason: shared.ErrorResult // ): void { // // Assert: stream.[[storedError]] is undefined. // // Assert: stream.[[state]] is "writable". // const controller = stream[writableStreamController_]!; // // Assert: controller is not undefined. // stream[shared.state_] = "erroring"; // stream[shared.storedError_] = reason; // const writer = stream[writer_]; // if (writer !== undefined) { // writableStreamDefaultWriterEnsureReadyPromiseRejected(writer, reason); // } // if ( // !writableStreamHasOperationMarkedInFlight(stream) && // controller[started_] // ) { // writableStreamFinishErroring(stream); // } // } // export function writableStreamFinishErroring( // stream: WritableStream // ): void { // // Assert: stream.[[state]] is "erroring". // // Assert: writableStreamHasOperationMarkedInFlight(stream) is false. // stream[shared.state_] = "errored"; // const controller = stream[writableStreamController_]!; // controller[errorSteps_](); // const storedError = stream[shared.storedError_]; // for (const writeRequest of stream[writeRequests_]) { // writeRequest.reject(storedError); // } // stream[writeRequests_] = []; // const abortRequest = stream[pendingAbortRequest_]; // if (abortRequest === undefined) { // writableStreamRejectCloseAndClosedPromiseIfNeeded(stream); // return; // } // stream[pendingAbortRequest_] = undefined; // if (abortRequest.wasAlreadyErroring) { // abortRequest.reject(storedError); // writableStreamRejectCloseAndClosedPromiseIfNeeded(stream); // return; // } // const promise = controller[abortSteps_](abortRequest.reason); // promise.then( // _ => { // abortRequest.resolve(); // writableStreamRejectCloseAndClosedPromiseIfNeeded(stream); // }, // error => { // abortRequest.reject(error); // writableStreamRejectCloseAndClosedPromiseIfNeeded(stream); // } // ); // } // export function writableStreamFinishInFlightWrite( // stream: WritableStream // ): void { // // Assert: stream.[[inFlightWriteRequest]] is not undefined. // stream[inFlightWriteRequest_]!.resolve(undefined); // stream[inFlightWriteRequest_] = undefined; // } // export function writableStreamFinishInFlightWriteWithError( // stream: WritableStream, // error: shared.ErrorResult // ): void { // // Assert: stream.[[inFlightWriteRequest]] is not undefined. // stream[inFlightWriteRequest_]!.reject(error); // stream[inFlightWriteRequest_] = undefined; // // Assert: stream.[[state]] is "writable" or "erroring". // writableStreamDealWithRejection(stream, error); // } // export function writableStreamFinishInFlightClose( // stream: WritableStream // ): void { // // Assert: stream.[[inFlightCloseRequest]] is not undefined. // stream[inFlightCloseRequest_]!.resolve(undefined); // stream[inFlightCloseRequest_] = undefined; // const state = stream[shared.state_]; // // Assert: stream.[[state]] is "writable" or "erroring". // if (state === "erroring") { // stream[shared.storedError_] = undefined; // if (stream[pendingAbortRequest_] !== undefined) { // stream[pendingAbortRequest_]!.resolve(); // stream[pendingAbortRequest_] = undefined; // } // } // stream[shared.state_] = "closed"; // const writer = stream[writer_]; // if (writer !== undefined) { // writer[closedPromise_].resolve(undefined); // } // // Assert: stream.[[pendingAbortRequest]] is undefined. // // Assert: stream.[[storedError]] is undefined. // } // export function writableStreamFinishInFlightCloseWithError( // stream: WritableStream, // error: shared.ErrorResult // ): void { // // Assert: stream.[[inFlightCloseRequest]] is not undefined. // stream[inFlightCloseRequest_]!.reject(error); // stream[inFlightCloseRequest_] = undefined; // // Assert: stream.[[state]] is "writable" or "erroring". // if (stream[pendingAbortRequest_] !== undefined) { // stream[pendingAbortRequest_]!.reject(error); // stream[pendingAbortRequest_] = undefined; // } // writableStreamDealWithRejection(stream, error); // } // export function writableStreamCloseQueuedOrInFlight( // stream: WritableStream // ): boolean { // return ( // stream[closeRequest_] !== undefined || // stream[inFlightCloseRequest_] !== undefined // ); // } // export function writableStreamHasOperationMarkedInFlight( // stream: WritableStream // ): boolean { // return ( // stream[inFlightWriteRequest_] !== undefined || // stream[inFlightCloseRequest_] !== undefined // ); // } // export function writableStreamMarkCloseRequestInFlight( // stream: WritableStream // ): void { // // Assert: stream.[[inFlightCloseRequest]] is undefined. // // Assert: stream.[[closeRequest]] is not undefined. // stream[inFlightCloseRequest_] = stream[closeRequest_]; // stream[closeRequest_] = undefined; // } // export function writableStreamMarkFirstWriteRequestInFlight( // stream: WritableStream // ): void { // // Assert: stream.[[inFlightWriteRequest]] is undefined. // // Assert: stream.[[writeRequests]] is not empty. // const writeRequest = stream[writeRequests_].shift()!; // stream[inFlightWriteRequest_] = writeRequest; // } // export function writableStreamRejectCloseAndClosedPromiseIfNeeded( // stream: WritableStream // ): void { // // Assert: stream.[[state]] is "errored". // const closeRequest = stream[closeRequest_]; // if (closeRequest !== undefined) { // // Assert: stream.[[inFlightCloseRequest]] is undefined. // closeRequest.reject(stream[shared.storedError_]); // stream[closeRequest_] = undefined; // } // const writer = stream[writer_]; // if (writer !== undefined) { // writer[closedPromise_].reject(stream[shared.storedError_]); // writer[closedPromise_].promise.catch(() => {}); // } // } // export function writableStreamUpdateBackpressure( // stream: WritableStream, // backpressure: boolean // ): void { // // Assert: stream.[[state]] is "writable". // // Assert: !WritableStreamCloseQueuedOrInFlight(stream) is false. // const writer = stream[writer_]; // if (writer !== undefined && backpressure !== stream[backpressure_]) { // if (backpressure) { // writer[readyPromise_] = shared.createControlledPromise(); // } else { // writer[readyPromise_].resolve(undefined); // } // } // stream[backpressure_] = backpressure; // } // // ---- Writers // export function isWritableStreamDefaultWriter( // value: unknown // ): value is WritableStreamDefaultWriter { // if (typeof value !== "object" || value === null) { // return false; // } // return ownerWritableStream_ in value; // } // export function writableStreamDefaultWriterAbort( // writer: WritableStreamDefaultWriter, // reason: shared.ErrorResult // ): Promise { // const stream = writer[ownerWritableStream_]!; // // Assert: stream is not undefined. // return writableStreamAbort(stream, reason); // } // export function writableStreamDefaultWriterClose( // writer: WritableStreamDefaultWriter // ): Promise { // const stream = writer[ownerWritableStream_]!; // // Assert: stream is not undefined. // const state = stream[shared.state_]; // if (state === "closed" || state === "errored") { // return Promise.reject( // new TypeError("Writer stream is already closed or errored") // ); // } // // Assert: state is "writable" or "erroring". // // Assert: writableStreamCloseQueuedOrInFlight(stream) is false. // const closePromise = shared.createControlledPromise(); // stream[closeRequest_] = closePromise; // if (stream[backpressure_] && state === "writable") { // writer[readyPromise_].resolve(undefined); // } // writableStreamDefaultControllerClose(stream[writableStreamController_]!); // return closePromise.promise; // } // export function writableStreamDefaultWriterCloseWithErrorPropagation( // writer: WritableStreamDefaultWriter // ): Promise { // const stream = writer[ownerWritableStream_]!; // // Assert: stream is not undefined. // const state = stream[shared.state_]; // if (writableStreamCloseQueuedOrInFlight(stream) || state === "closed") { // return Promise.resolve(undefined); // } // if (state === "errored") { // return Promise.reject(stream[shared.storedError_]); // } // // Assert: state is "writable" or "erroring". // return writableStreamDefaultWriterClose(writer); // } // export function writableStreamDefaultWriterEnsureClosedPromiseRejected< // InputType // >( // writer: WritableStreamDefaultWriter, // error: shared.ErrorResult // ): void { // const closedPromise = writer[closedPromise_]; // if (closedPromise.state === shared.ControlledPromiseState.Pending) { // closedPromise.reject(error); // } else { // writer[closedPromise_] = shared.createControlledPromise(); // writer[closedPromise_].reject(error); // } // writer[closedPromise_].promise.catch(() => {}); // } // export function writableStreamDefaultWriterEnsureReadyPromiseRejected< // InputType // >( // writer: WritableStreamDefaultWriter, // error: shared.ErrorResult // ): void { // const readyPromise = writer[readyPromise_]; // if (readyPromise.state === shared.ControlledPromiseState.Pending) { // readyPromise.reject(error); // } else { // writer[readyPromise_] = shared.createControlledPromise(); // writer[readyPromise_].reject(error); // } // writer[readyPromise_].promise.catch(() => {}); // } // export function writableStreamDefaultWriterGetDesiredSize( // writer: WritableStreamDefaultWriter // ): number | null { // const stream = writer[ownerWritableStream_]!; // const state = stream[shared.state_]; // if (state === "errored" || state === "erroring") { // return null; // } // if (state === "closed") { // return 0; // } // return writableStreamDefaultControllerGetDesiredSize( // stream[writableStreamController_]! // ); // } // export function writableStreamDefaultWriterRelease( // writer: WritableStreamDefaultWriter // ): void { // const stream = writer[ownerWritableStream_]!; // // Assert: stream is not undefined. // // Assert: stream.[[writer]] is writer. // const releasedError = new TypeError(); // writableStreamDefaultWriterEnsureReadyPromiseRejected(writer, releasedError); // writableStreamDefaultWriterEnsureClosedPromiseRejected(writer, releasedError); // stream[writer_] = undefined; // writer[ownerWritableStream_] = undefined; // } // export function writableStreamDefaultWriterWrite( // writer: WritableStreamDefaultWriter, // chunk: InputType // ): Promise { // const stream = writer[ownerWritableStream_]!; // // Assert: stream is not undefined. // const controller = stream[writableStreamController_]!; // const chunkSize = writableStreamDefaultControllerGetChunkSize( // controller, // chunk // ); // if (writer[ownerWritableStream_] !== stream) { // return Promise.reject(new TypeError()); // } // const state = stream[shared.state_]; // if (state === "errored") { // return Promise.reject(stream[shared.storedError_]); // } // if (writableStreamCloseQueuedOrInFlight(stream) || state === "closed") { // return Promise.reject( // new TypeError("Cannot write to a closing or closed stream") // ); // } // if (state === "erroring") { // return Promise.reject(stream[shared.storedError_]); // } // // Assert: state is "writable". // const promise = writableStreamAddWriteRequest(stream); // writableStreamDefaultControllerWrite(controller, chunk, chunkSize); // return promise; // } // // ---- Controller // export function setUpWritableStreamDefaultController( // stream: WritableStream, // controller: WritableStreamDefaultController, // startAlgorithm: StartAlgorithm, // writeAlgorithm: WriteAlgorithm, // closeAlgorithm: CloseAlgorithm, // abortAlgorithm: AbortAlgorithm, // highWaterMark: number, // sizeAlgorithm: QueuingStrategySizeCallback // ): void { // if (!isWritableStream(stream)) { // throw new TypeError(); // } // if (stream[writableStreamController_] !== undefined) { // throw new TypeError(); // } // controller[controlledWritableStream_] = stream; // stream[writableStreamController_] = controller; // q.resetQueue(controller); // controller[started_] = false; // controller[strategySizeAlgorithm_] = sizeAlgorithm; // controller[strategyHWM_] = highWaterMark; // controller[writeAlgorithm_] = writeAlgorithm; // controller[closeAlgorithm_] = closeAlgorithm; // controller[abortAlgorithm_] = abortAlgorithm; // const backpressure = writableStreamDefaultControllerGetBackpressure( // controller // ); // writableStreamUpdateBackpressure(stream, backpressure); // const startResult = startAlgorithm(); // Promise.resolve(startResult).then( // _ => { // // Assert: stream.[[state]] is "writable" or "erroring". // controller[started_] = true; // writableStreamDefaultControllerAdvanceQueueIfNeeded(controller); // }, // error => { // // Assert: stream.[[state]] is "writable" or "erroring". // controller[started_] = true; // writableStreamDealWithRejection(stream, error); // } // ); // } // export function isWritableStreamDefaultController( // value: unknown // ): value is WritableStreamDefaultController { // if (typeof value !== "object" || value === null) { // return false; // } // return controlledWritableStream_ in value; // } // export function writableStreamDefaultControllerClearAlgorithms( // controller: WritableStreamDefaultController // ): void { // // Use ! assertions to override type check here, this way we don't // // have to perform type checks/assertions everywhere else. // controller[writeAlgorithm_] = undefined!; // controller[closeAlgorithm_] = undefined!; // controller[abortAlgorithm_] = undefined!; // controller[strategySizeAlgorithm_] = undefined!; // } // export function writableStreamDefaultControllerClose( // controller: WritableStreamDefaultController // ): void { // q.enqueueValueWithSize(controller, "close", 0); // writableStreamDefaultControllerAdvanceQueueIfNeeded(controller); // } // export function writableStreamDefaultControllerGetChunkSize( // controller: WritableStreamDefaultController, // chunk: InputType // ): number { // let chunkSize: number; // try { // chunkSize = controller[strategySizeAlgorithm_](chunk); // } catch (error) { // writableStreamDefaultControllerErrorIfNeeded(controller, error); // chunkSize = 1; // } // return chunkSize; // } // export function writableStreamDefaultControllerGetDesiredSize( // controller: WritableStreamDefaultController // ): number { // return controller[strategyHWM_] - controller[q.queueTotalSize_]; // } // export function writableStreamDefaultControllerWrite( // controller: WritableStreamDefaultController, // chunk: InputType, // chunkSize: number // ): void { // try { // q.enqueueValueWithSize(controller, { chunk }, chunkSize); // } catch (error) { // writableStreamDefaultControllerErrorIfNeeded(controller, error); // return; // } // const stream = controller[controlledWritableStream_]; // if ( // !writableStreamCloseQueuedOrInFlight(stream) && // stream[shared.state_] === "writable" // ) { // const backpressure = writableStreamDefaultControllerGetBackpressure( // controller // ); // writableStreamUpdateBackpressure(stream, backpressure); // } // writableStreamDefaultControllerAdvanceQueueIfNeeded(controller); // } // export function writableStreamDefaultControllerAdvanceQueueIfNeeded( // controller: WritableStreamDefaultController // ): void { // if (!controller[started_]) { // return; // } // const stream = controller[controlledWritableStream_]; // if (stream[inFlightWriteRequest_] !== undefined) { // return; // } // const state = stream[shared.state_]; // if (state === "closed" || state === "errored") { // return; // } // if (state === "erroring") { // writableStreamFinishErroring(stream); // return; // } // if (controller[q.queue_].length === 0) { // return; // } // const writeRecord = q.peekQueueValue(controller); // if (writeRecord === "close") { // writableStreamDefaultControllerProcessClose(controller); // } else { // writableStreamDefaultControllerProcessWrite(controller, writeRecord.chunk); // } // } // export function writableStreamDefaultControllerErrorIfNeeded( // controller: WritableStreamDefaultController, // error: shared.ErrorResult // ): void { // if (controller[controlledWritableStream_][shared.state_] === "writable") { // writableStreamDefaultControllerError(controller, error); // } // } // export function writableStreamDefaultControllerProcessClose( // controller: WritableStreamDefaultController // ): void { // const stream = controller[controlledWritableStream_]; // writableStreamMarkCloseRequestInFlight(stream); // q.dequeueValue(controller); // // Assert: controller.[[queue]] is empty. // const sinkClosePromise = controller[closeAlgorithm_](); // writableStreamDefaultControllerClearAlgorithms(controller); // sinkClosePromise.then( // _ => { // writableStreamFinishInFlightClose(stream); // }, // error => { // writableStreamFinishInFlightCloseWithError(stream, error); // } // ); // } // export function writableStreamDefaultControllerProcessWrite( // controller: WritableStreamDefaultController, // chunk: InputType // ): void { // const stream = controller[controlledWritableStream_]; // writableStreamMarkFirstWriteRequestInFlight(stream); // controller[writeAlgorithm_](chunk).then( // _ => { // writableStreamFinishInFlightWrite(stream); // const state = stream[shared.state_]; // // Assert: state is "writable" or "erroring". // q.dequeueValue(controller); // if ( // !writableStreamCloseQueuedOrInFlight(stream) && // state === "writable" // ) { // const backpressure = writableStreamDefaultControllerGetBackpressure( // controller // ); // writableStreamUpdateBackpressure(stream, backpressure); // } // writableStreamDefaultControllerAdvanceQueueIfNeeded(controller); // }, // error => { // if (stream[shared.state_] === "writable") { // writableStreamDefaultControllerClearAlgorithms(controller); // } // writableStreamFinishInFlightWriteWithError(stream, error); // } // ); // } // export function writableStreamDefaultControllerGetBackpressure( // controller: WritableStreamDefaultController // ): boolean { // const desiredSize = writableStreamDefaultControllerGetDesiredSize(controller); // return desiredSize <= 0; // } // export function writableStreamDefaultControllerError( // controller: WritableStreamDefaultController, // error: shared.ErrorResult // ): void { // const stream = controller[controlledWritableStream_]; // // Assert: stream.[[state]] is "writable". // writableStreamDefaultControllerClearAlgorithms(controller); // writableStreamStartErroring(stream, error); // }