GeezerVison is showing github.com — stream: fix pipeTo to defer writes per WHATWG spec · nodejs/node@ea2df2a
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: lib/internal/webstreams/readablestream.js +8-3Lines changed: 8 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1662,9 +1662,14 @@ class PipeToReadableStreamReadRequest { |
1662 | 1662 | } |
1663 | 1663 |
|
1664 | 1664 | [kChunk](chunk) { |
1665 | | - this.state.currentWrite = writableStreamDefaultWriterWrite(this.writer, chunk); |
1666 | | - setPromiseHandled(this.state.currentWrite); |
1667 | | - this.promise.resolve(false); |
| 1665 | + // Per spec, pipeTo must queue a microtask for the write to avoid |
| 1666 | + // synchronous write during enqueue(). See WHATWG Streams spec |
| 1667 | + // "ReadableStreamPipeTo" step 15's "chunk steps". |
| 1668 | + queueMicrotask(() => { |
| 1669 | + this.state.currentWrite = writableStreamDefaultWriterWrite(this.writer, chunk); |
| 1670 | + setPromiseHandled(this.state.currentWrite); |
| 1671 | + this.promise.resolve(false); |
| 1672 | + }); |
1668 | 1673 | } |
1669 | 1674 |
|
1670 | 1675 | [kClose]() { |
|
Collapse file
Copy file name to clipboardExpand all lines: test/wpt/status/streams.json -8Lines changed: 0 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
2 | 2 | "idlharness-shadowrealm.window.js": { |
3 | 3 | "skip": "ShadowRealm support is not enabled" |
4 | 4 | }, |
5 | | - "piping/general-addition.any.js": { |
6 | | - "fail": { |
7 | | - "note": "Blocked on https://github.com/whatwg/streams/issues/1243", |
8 | | - "expected": [ |
9 | | - "enqueue() must not synchronously call write algorithm" |
10 | | - ] |
11 | | - } |
12 | | - }, |
13 | 5 | "queuing-strategies-size-function-per-global.window.js": { |
14 | 6 | "skip": "Browser-specific test" |
15 | 7 | }, |
|