Skip to content

Commit

Permalink
Make it easy to create streams from other standards
Browse files Browse the repository at this point in the history
This adds four new abstract operations which allow creating streams from other standards by supplying appropriate algorithms and values, instead of JavaScript objects: CreateReadableStream, CreateReadableByteStream, CreateWritableStream, and CreateTransformStream. CreateReadableStream and CreateWritableStream are now used when teeing readable streams and when creating TransformStreams, and will be used by Fetch and other standards.

As part of this, the controller constructors no longer take any parameters. This is technically observable via their length property, but has no real impact, since they always threw anyway. As such, the impact on implementations is minimal.

As for the changes to the guts of the spec: 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 initialization 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.

Fixes #813.
  • Loading branch information
domenic committed Nov 29, 2017
1 parent 65752c9 commit 5b9f39d
Show file tree
Hide file tree
Showing 6 changed files with 1,264 additions and 1,029 deletions.
1,123 changes: 603 additions & 520 deletions index.bs

Large diffs are not rendered by default.

28 changes: 21 additions & 7 deletions reference-implementation/lib/helpers.js
Expand Up @@ -33,12 +33,26 @@ exports.CreateIterResultObject = (value, done) => {
};

exports.IsFiniteNonNegativeNumber = v => {
if (Number.isNaN(v)) {
if (exports.IsNonNegativeNumber(v) === false) {
return false;
}

if (v === Infinity) {
return false;
}

return true;
};

exports.IsNonNegativeNumber = v => {
if (typeof v !== 'number') {
return false;
}

if (Number.isNaN(v)) {
return false;
}

if (v < 0) {
return false;
}
Expand Down Expand Up @@ -111,12 +125,12 @@ exports.ValidateAndNormalizeHighWaterMark = highWaterMark => {
return highWaterMark;
};

exports.ValidateAndNormalizeQueuingStrategy = (size, highWaterMark) => {
if (size !== undefined && typeof size !== 'function') {
exports.MakeSizeAlgorithmFromSizeFunction = size => {
if (size === undefined) {
return () => 1;
}
if (typeof size !== 'function') {
throw new TypeError('size property of a queuing strategy must be a function');
}

highWaterMark = exports.ValidateAndNormalizeHighWaterMark(highWaterMark);

return { size, highWaterMark };
return chunk => size(chunk);
};

0 comments on commit 5b9f39d

Please sign in to comment.