mirror of
https://github.com/denoland/deno.git
synced 2024-11-04 08:54:20 -05:00
fc4819e1e0
Refactors Event and EventTarget so that they better encapsulate their non-public data as well as are more forward compatible with things like DOM Nodes. Moves `dom_types.ts` -> `dom_types.d.ts` which was always the intention, it was a legacy of when we used to build the types from the code and the limitations of the compiler. There was a lot of cruft in `dom_types` which shouldn't have been there, and mis-alignment to the DOM standards. This generally has been eliminated, though we still have some minor differences from the DOM (like the removal of some deprecated methods/properties). Adds `DOMException`. Strictly it shouldn't inherit from `Error`, but most browsers provide a stack trace when one is thrown, so the behaviour in Deno actually better matches the browser. `Event` still doesn't log to console like it does in the browser. I wanted to get this raised and that could be an enhancement later on (it currently doesn't either).
147 lines
5.6 KiB
TypeScript
147 lines
5.6 KiB
TypeScript
// 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/transform-stream - TransformStream class implementation
|
|
// * 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 rs from "./readable-internals.ts";
|
|
// import * as ws from "./writable-internals.ts";
|
|
// import * as ts from "./transform-internals.ts";
|
|
// import * as shared from "./shared-internals.ts";
|
|
// import { TransformStreamDefaultController } from "./transform-stream-default-controller.ts";
|
|
// import { QueuingStrategy } from "../dom_types.d.ts";
|
|
|
|
// export class TransformStream<InputType, OutputType> {
|
|
// [ts.backpressure_]: boolean | undefined; // Whether there was backpressure on [[readable]] the last time it was observed
|
|
// [ts.backpressureChangePromise_]: shared.ControlledPromise<void>; // A promise which is fulfilled and replaced every time the value of[[backpressure]] changes
|
|
// [ts.readable_]: rs.SDReadableStream<OutputType>; // The ReadableStream instance controlled by this object
|
|
// [ts.transformStreamController_]: TransformStreamDefaultController<
|
|
// InputType,
|
|
// OutputType
|
|
// >; // A TransformStreamDefaultController created with the ability to control[[readable]] and[[writable]]; also used for the IsTransformStream brand check
|
|
// [ts.writable_]: ws.WritableStream<InputType>; // The WritableStream instance controlled by this object
|
|
|
|
// constructor(
|
|
// transformer: ts.Transformer<InputType, OutputType> = {},
|
|
// writableStrategy: QueuingStrategy<InputType> = {},
|
|
// readableStrategy: QueuingStrategy<OutputType> = {}
|
|
// ) {
|
|
// const writableSizeFunction = writableStrategy.size;
|
|
// const writableHighWaterMark = writableStrategy.highWaterMark;
|
|
// const readableSizeFunction = readableStrategy.size;
|
|
// const readableHighWaterMark = readableStrategy.highWaterMark;
|
|
|
|
// const writableType = transformer.writableType;
|
|
// if (writableType !== undefined) {
|
|
// throw new RangeError(
|
|
// "The transformer's `writableType` field must be undefined"
|
|
// );
|
|
// }
|
|
// const writableSizeAlgorithm = shared.makeSizeAlgorithmFromSizeFunction(
|
|
// writableSizeFunction
|
|
// );
|
|
// const writableHWM = shared.validateAndNormalizeHighWaterMark(
|
|
// writableHighWaterMark === undefined ? 1 : writableHighWaterMark
|
|
// );
|
|
|
|
// const readableType = transformer.readableType;
|
|
// if (readableType !== undefined) {
|
|
// throw new RangeError(
|
|
// "The transformer's `readableType` field must be undefined"
|
|
// );
|
|
// }
|
|
// const readableSizeAlgorithm = shared.makeSizeAlgorithmFromSizeFunction(
|
|
// readableSizeFunction
|
|
// );
|
|
// const readableHWM = shared.validateAndNormalizeHighWaterMark(
|
|
// readableHighWaterMark === undefined ? 0 : readableHighWaterMark
|
|
// );
|
|
|
|
// const startPromise = shared.createControlledPromise<void>();
|
|
// ts.initializeTransformStream(
|
|
// this,
|
|
// startPromise.promise,
|
|
// writableHWM,
|
|
// writableSizeAlgorithm,
|
|
// readableHWM,
|
|
// readableSizeAlgorithm
|
|
// );
|
|
// setUpTransformStreamDefaultControllerFromTransformer(this, transformer);
|
|
|
|
// const startResult = shared.invokeOrNoop(transformer, "start", [
|
|
// this[ts.transformStreamController_]
|
|
// ]);
|
|
// startPromise.resolve(startResult);
|
|
// }
|
|
|
|
// get readable(): rs.SDReadableStream<OutputType> {
|
|
// if (!ts.isTransformStream(this)) {
|
|
// throw new TypeError();
|
|
// }
|
|
// return this[ts.readable_];
|
|
// }
|
|
|
|
// get writable(): ws.WritableStream<InputType> {
|
|
// if (!ts.isTransformStream(this)) {
|
|
// throw new TypeError();
|
|
// }
|
|
// return this[ts.writable_];
|
|
// }
|
|
// }
|
|
|
|
// function setUpTransformStreamDefaultControllerFromTransformer<
|
|
// InputType,
|
|
// OutputType
|
|
// >(
|
|
// stream: TransformStream<InputType, OutputType>,
|
|
// transformer: ts.Transformer<InputType, OutputType>
|
|
// ): void {
|
|
// const controller = Object.create(
|
|
// TransformStreamDefaultController.prototype
|
|
// ) as TransformStreamDefaultController<InputType, OutputType>;
|
|
// let transformAlgorithm: ts.TransformAlgorithm<InputType>;
|
|
|
|
// const transformMethod = transformer.transform;
|
|
// if (transformMethod !== undefined) {
|
|
// if (typeof transformMethod !== "function") {
|
|
// throw new TypeError(
|
|
// "`transform` field of the transformer must be a function"
|
|
// );
|
|
// }
|
|
// transformAlgorithm = (chunk: InputType): Promise<any> =>
|
|
// shared.promiseCall(transformMethod, transformer, [chunk, controller]);
|
|
// } else {
|
|
// // use identity transform
|
|
// transformAlgorithm = function(chunk: InputType): Promise<void> {
|
|
// try {
|
|
// // OutputType and InputType are the same here
|
|
// ts.transformStreamDefaultControllerEnqueue(
|
|
// controller,
|
|
// (chunk as unknown) as OutputType
|
|
// );
|
|
// } catch (error) {
|
|
// return Promise.reject(error);
|
|
// }
|
|
// return Promise.resolve(undefined);
|
|
// };
|
|
// }
|
|
// const flushAlgorithm = shared.createAlgorithmFromUnderlyingMethod(
|
|
// transformer,
|
|
// "flush",
|
|
// [controller]
|
|
// );
|
|
// ts.setUpTransformStreamDefaultController(
|
|
// stream,
|
|
// controller,
|
|
// transformAlgorithm,
|
|
// flushAlgorithm
|
|
// );
|
|
// }
|