Re: [whatwg/streams] WIP: allow creating streams from specs while using fewer JS objects (#857)

# Overview of changes:

## For use from other standards:
Four new operations have been added to permit creating streams from other standards without having to create Javascript objects. Instead the underlying operations and the strategy size function are implemented as abstract algorithms.
* new ReadableStream() => CreateReadableStream(), CreateReadableByteStream()
* new WritableStream() => CreateWritableStream()
* new TransformStream() => CreateTransformStream()

## For developers:
No changes. The controller constructors now take no parameters, which is visible, but since this constructor was never useful outside of implementations anyway it should make no difference.

## For implementators:
No immediate changes required. To make tests pass the constructor length for the controllers needs to be changed to 0, but that is not particularly urgent and should be trivial.
In the longer term it will be beneficial to use the new structure to make creating streams from other code simple and to align with the standard text.

## Internals:
Controllers are now created by a SetUpFooController operation instead of the constructor. The set-up operation takes algorithms as arguments. Each controller also has a SetUpFooControllerFromBar operation that extracts algorithms from the Javascript object that is passed to the stream constructor. This is used by the user-facing constructor. The algorithms are stored on the controller object.
Each stream has an additional InitializeFooStream operation which performs common initialisation and is called from both the constructor and the Create operation.
Where previously there were calls to PromiseInvokeOrNoop there are now "calls" to the algorithms stored on the controller object.
Summary of new operations:
* **ReadableStream:** CreateReadableStream, CreateReadableByteStream, InitializeReadableStream, SetUpReadableStreamDefaultController, SetUpReadableStreamDefaultControllerFromUnderlyingSource, SetUpReadableByteStreamController, SetUpReadableByteStreamControllerFromUnderlyingSource
* **WritableStream:** CreateWritableStream, InitializeWritableStream, SetUpWritableStreamDefaultController, SetUpWritableStreamDefaultControllerFromUnderlyingSink
* **TransformStream:** CreateTransformStream, InitializeTransformStream, SetUpTransformStreamDefaultController, SetUpTransformStreamDefaultControllerFromTransformer

## Reference implementation:
In the reference implementation algorithms are concretely represented by Javascript functions. The object to operate on and other relevant state is stored in variables captured from the lexical scope.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/streams/pull/857#issuecomment-347473737

Received on Tuesday, 28 November 2017 10:05:52 UTC