Skip to content

Commit

Permalink
Merge branch 'master' into next
Browse files Browse the repository at this point in the history
  • Loading branch information
MattiasBuelens committed Nov 6, 2021
2 parents cbe8006 + 224d853 commit d515169
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 13 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
> - 👓 Spec Compliance
> - 🚀 New Feature
> - 🐛 Bug Fix
> - 👎 Deprecation
> - 📝 Documentation
> - 🏠 Internal
> - 💅 Polish
Expand Down Expand Up @@ -32,6 +33,12 @@
| `web-streams-polyfill/ponyfill/es6` | `web-streams-polyfill` | ES2015+ ponyfill |
| `web-streams-polyfill/ponyfill/es2018` | `web-streams-polyfill` | ES2015+ ponyfill |

## v3.2.0 (2021-11-06)

* 👎 Deprecate `WritableStreamDefaultController.abortReason` ([#102](https://github.com/MattiasBuelens/web-streams-polyfill/pull/102))
* Use `WritableStreamDefaultController.signal.reason` instead.
* 👓 Align with [spec version `4b6b93c`](https://github.com/whatwg/streams/tree/4b6b93c69e531e2fe45a6ed4cb1484a7ba4eb8bb/) ([#103](https://github.com/MattiasBuelens/web-streams-polyfill/pull/103))

## v3.1.1 (2021-09-06)

* 🐛 Fix compatibility with TypeScript's DOM types for `ReadableStream` and `TransformStream` ([#85](https://github.com/MattiasBuelens/web-streams-polyfill/issues/85), [#86](https://github.com/MattiasBuelens/web-streams-polyfill/pull/86))
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ If you need to support older browsers or Node versions that do not have a native

## Compliance

The polyfill implements [version `cada812` (8 Jul 2021)][spec-snapshot] of the streams specification.
The polyfill implements [version `4b6b93c` (25 Oct 2021)][spec-snapshot] of the streams specification.

The polyfill is tested against the same [web platform tests][wpt] that are used by browsers to test their native implementations.
It aims to pass all tests, although it allows some exceptions for practical reasons:
Expand Down Expand Up @@ -120,13 +120,13 @@ Thanks to these people for their work on [the original polyfill][creatorrr-polyf
[rs-asynciterator]: https://streams.spec.whatwg.org/#rs-asynciterator
[ws-controller-signal]: https://streams.spec.whatwg.org/#ws-default-controller-signal
[abortcontroller-polyfill]: https://www.npmjs.com/package/abortcontroller-polyfill
[spec-snapshot]: https://streams.spec.whatwg.org/commit-snapshots/cada8129edcc4803b2878a7a3f5e1d8325dc0c23/
[wpt]: https://github.com/web-platform-tests/wpt/tree/87a4c80598aee5178c385628174f1832f5a28ad6/streams
[wpt-bad-buffers]: https://github.com/web-platform-tests/wpt/blob/87a4c80598aee5178c385628174f1832f5a28ad6/streams/readable-byte-streams/bad-buffers-and-views.any.js
[spec-snapshot]: https://streams.spec.whatwg.org/commit-snapshots/4b6b93c69e531e2fe45a6ed4cb1484a7ba4eb8bb/
[wpt]: https://github.com/web-platform-tests/wpt/tree/96ca25f0f7526282c0d47e6bf6a7edd439da1968/streams
[wpt-bad-buffers]: https://github.com/web-platform-tests/wpt/blob/96ca25f0f7526282c0d47e6bf6a7edd439da1968/streams/readable-byte-streams/bad-buffers-and-views.any.js
[proposal-arraybuffer-transfer]: https://github.com/domenic/proposal-arraybuffer-transfer
[ref-impl-transferarraybuffer]: https://github.com/whatwg/streams/blob/cada8129edcc4803b2878a7a3f5e1d8325dc0c23/reference-implementation/lib/abstract-ops/ecmascript.js#L16
[ref-impl-transferarraybuffer]: https://github.com/whatwg/streams/blob/4b6b93c69e531e2fe45a6ed4cb1484a7ba4eb8bb/reference-implementation/lib/abstract-ops/ecmascript.js#L16
[issue-3]: https://github.com/MattiasBuelens/web-streams-polyfill/issues/3
[wpt-async-iterator-prototype]: https://github.com/web-platform-tests/wpt/blob/87a4c80598aee5178c385628174f1832f5a28ad6/streams/readable-streams/async-iterator.any.js#L24
[wpt-async-iterator-prototype]: https://github.com/web-platform-tests/wpt/blob/96ca25f0f7526282c0d47e6bf6a7edd439da1968/streams/readable-streams/async-iterator.any.js#L24
[stub-async-iterator-prototype]: https://github.com/MattiasBuelens/web-streams-polyfill/blob/v4.0.0-beta.1/src/lib/readable-stream/async-iterator.ts#L153-L161
[wpt-rs-patched-global]: https://github.com/web-platform-tests/wpt/blob/887350c2f46def5b01c4dd1f8d2eee35dfb9c5bb/streams/readable-streams/patched-global.any.js
[wpt-then-interception]: https://github.com/web-platform-tests/wpt/blob/cf33f00596af295ee0f207c88e23b5f8b0791307/streams/piping/then-interception.any.js
Expand Down
1 change: 1 addition & 0 deletions etc/web-streams-polyfill.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ export class WritableStream<W = any> {

// @public
export class WritableStreamDefaultController<W = any> {
// @deprecated
get abortReason(): any;
error(e?: any): void;
get signal(): AbortSignal;
Expand Down
10 changes: 7 additions & 3 deletions src/lib/readable-stream/byte-stream-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -809,10 +809,14 @@ export function ReadableByteStreamControllerEnqueue(controller: ReadableByteStre

if (ReadableStreamHasDefaultReader(stream)) {
if (ReadableStreamGetNumReadRequests(stream) === 0) {
assert(controller._pendingPullIntos.length === 0);
ReadableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset, byteLength);
} else {
assert(controller._queue.length === 0);

if (controller._pendingPullIntos.length > 0) {
assert(controller._pendingPullIntos.peek().readerType === 'default');
ReadableByteStreamControllerShiftPendingPullInto(controller);
}
const transferredView = new Uint8Array(transferredBuffer, byteOffset, byteLength);
ReadableStreamFulfillReadRequest(stream, transferredView, false);
}
Expand Down Expand Up @@ -927,9 +931,9 @@ export function ReadableByteStreamControllerRespondWithNewView(controller: Reada
throw new RangeError('The region specified by view is larger than byobRequest');
}

const viewByteLength = view.byteLength;
firstDescriptor.buffer = TransferArrayBuffer(view.buffer);

ReadableByteStreamControllerRespondInternal(controller, view.byteLength);
ReadableByteStreamControllerRespondInternal(controller, viewByteLength);
}

export function SetUpReadableByteStreamController(stream: ReadableByteStream,
Expand Down
36 changes: 33 additions & 3 deletions src/lib/readable-stream/tee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export function ReadableStreamDefaultTee<R>(stream: ReadableStream<R>,
const reader = stream.getReader();

let reading = false;
let readAgain = false;
let canceled1 = false;
let canceled2 = false;
let reason1: any;
Expand All @@ -45,13 +46,14 @@ export function ReadableStreamDefaultTee<R>(stream: ReadableStream<R>,

function pullAlgorithm(): Promise<void> {
if (reading) {
readAgain = true;
return promiseResolvedWith(undefined);
}

reading = true;

uponPromise(reader.read(), result => {
reading = false;
readAgain = false;

if (result.done) {
if (!canceled1) {
Expand Down Expand Up @@ -83,6 +85,12 @@ export function ReadableStreamDefaultTee<R>(stream: ReadableStream<R>,
if (!canceled2) {
controller2.enqueue(chunk2);
}

reading = false;
if (readAgain) {
pullAlgorithm();
}

return null;
}, () => {
reading = false;
Expand Down Expand Up @@ -149,6 +157,8 @@ export function ReadableByteStreamTee(stream: ReadableByteStream): [ReadableByte
let reader: ReadableStreamReader<Uint8Array> = stream.getReader();
let isByobReader = false;
let reading = false;
let readAgainForBranch1 = false;
let readAgainForBranch2 = false;
let canceled1 = false;
let canceled2 = false;
let reason1: any;
Expand Down Expand Up @@ -184,7 +194,8 @@ export function ReadableByteStreamTee(stream: ReadableByteStream): [ReadableByte
}

uponPromise((reader as ReadableStreamDefaultReader<Uint8Array>).read(), result => {
reading = false;
readAgainForBranch1 = false;
readAgainForBranch2 = false;

if (result.done) {
if (!canceled1) {
Expand Down Expand Up @@ -220,6 +231,14 @@ export function ReadableByteStreamTee(stream: ReadableByteStream): [ReadableByte
if (!canceled2) {
controller2.enqueue(chunk2);
}

reading = false;
if (readAgainForBranch1) {
pull1Algorithm();
} else if (readAgainForBranch2) {
pull2Algorithm();
}

return null;
}, () => {
reading = false;
Expand All @@ -239,7 +258,8 @@ export function ReadableByteStreamTee(stream: ReadableByteStream): [ReadableByte
const otherController = forBranch2 ? controller1 : controller2;

uponPromise((reader as ReadableStreamBYOBReader).read(view), result => {
reading = false;
readAgainForBranch1 = false;
readAgainForBranch2 = false;
const byobCanceled = forBranch2 ? canceled2 : canceled1;
const otherCanceled = forBranch2 ? canceled1 : canceled2;
if (result.done) {
Expand Down Expand Up @@ -283,6 +303,14 @@ export function ReadableByteStreamTee(stream: ReadableByteStream): [ReadableByte
} else if (!byobCanceled) {
byobController.byobRequest!.respondWithNewView(chunk);
}

reading = false;
if (readAgainForBranch1) {
pull1Algorithm();
} else if (readAgainForBranch2) {
pull2Algorithm();
}

return null;
}, () => {
reading = false;
Expand All @@ -292,6 +320,7 @@ export function ReadableByteStreamTee(stream: ReadableByteStream): [ReadableByte

function pull1Algorithm(): Promise<void> {
if (reading) {
readAgainForBranch1 = true;
return promiseResolvedWith(undefined);
}

Expand All @@ -309,6 +338,7 @@ export function ReadableByteStreamTee(stream: ReadableByteStream): [ReadableByte

function pull2Algorithm(): Promise<void> {
if (reading) {
readAgainForBranch2 = true;
return promiseResolvedWith(undefined);
}

Expand Down
6 changes: 6 additions & 0 deletions src/lib/writable-stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,10 @@ export class WritableStreamDefaultController<W = any> {

/**
* The reason which was passed to `WritableStream.abort(reason)` when the stream was aborted.
*
* @deprecated
* This property has been removed from the specification, see https://github.com/whatwg/streams/pull/1177.
* Use {@link WritableStreamDefaultController.signal}'s `reason` instead.
*/
get abortReason(): any {
if (!IsWritableStreamDefaultController(this)) {
Expand Down Expand Up @@ -1015,6 +1019,8 @@ export class WritableStreamDefaultController<W = any> {
}

Object.defineProperties(WritableStreamDefaultController.prototype, {
abortReason: { enumerable: true },
signal: { enumerable: true },
error: { enumerable: true }
});
if (typeof Symbol.toStringTag === 'symbol') {
Expand Down
2 changes: 1 addition & 1 deletion test/web-platform-tests

0 comments on commit d515169

Please sign in to comment.