Commit 52616e8
authored
fix(ext/node): expose internal/js_stream_socket and add default read path (#34088)
## Summary
Implements the `internal/js_stream_socket` Node compat polyfill so test
fixtures and library code can `require('internal/js_stream_socket')` to
wrap arbitrary `Duplex` streams in a `net.Socket` interface.
The class itself already existed (used internally by `_tls_wrap.js` for
TLS-over-Duplex), but two things prevented the 10 listed tests from
running:
1. **It was not registered as a require()-able builtin.** Add it to the
builtin module map in `ext/node/polyfills/01_require.js`.
2. **The non-TLS read path was unimplemented.** The handle's
`readBuffer`/`emitEOF` were stubbed `null` and only populated by
`TLSWrap.attachJsStream()`. For a bare `new JSStreamSocket(duplex)`,
data read from the underlying Duplex was silently dropped and EOF
never propagated, so the wrapping `Socket` never emitted `'data'` or
`'end'`. Default both to forward through the standard `onread`
callback installed by `net._initSocketHandle`;
`TLSWrap.attachJsStream()`
still overrides them when needed.
Small follow-ups uncovered by the now-runnable tests:
- Emit `ERR_STREAM_WRAP` (Node-style error code with the standard
message) instead of a plain `Error` when the wrapped stream is in
string/objectMode.
- Attach `StreamWrap` as a self-reference on `JSStreamSocket` so both
`const StreamWrap = require('internal/js_stream_socket')` and
`const { StreamWrap } = require('internal/js_stream_socket')` patterns
work — Node's module exports the class and self-references the name.
- `Socket.prototype.bufferSize` returns `undefined` (not `0`) after the
handle is gone, matching Node.
## Tests
8 of the 10 tests from denoland/orchid#90 now pass and are added to
`tests/node_compat/config.jsonc`:
- `parallel/test-stream-wrap-drain.js`
- `parallel/test-stream-wrap-encoding.js`
- `parallel/test-stream-wrap.js`
- `parallel/test-tls-streamwrap-buffersize.js`
- `parallel/test-wrap-js-stream-destroy.js`
- `parallel/test-wrap-js-stream-duplex.js`
- `parallel/test-wrap-js-stream-exceptions.js`
- `parallel/test-wrap-js-stream-read-stop.js`
Two tests still fail because of unrelated polyfill gaps and are left out
of `config.jsonc`:
- `parallel/test-tls-generic-stream.js` — asserts
`TLSSocket._handle.writeQueueSize > 0` after a buffered write. The
Rust `TLSWrap` op doesn't expose `writeQueueSize`.
- `parallel/test-http-agent-domain-reused-gc.js` — relies on
`handle.asyncReset(new ReusedHandle(...))` firing an `init` async hook
for the `ReusedHandle` resource and a matching `before` hook on reuse.
Our handles don't implement `asyncReset` and `_http_agent.js` short-
circuits when the method is missing, so the hook never fires.
Both are pre-existing Deno limitations beyond the scope of implementing
`internal/js_stream_socket`.
## Test plan
- [x] `cargo test -p node_compat_tests test-stream-wrap` — 3 pass
- [x] `cargo test -p node_compat_tests test-wrap-js-stream` — 4 pass
- [x] `cargo test -p node_compat_tests test-tls-streamwrap` — 1 pass
- [x] Existing `test-net-buffersize.js`, `test-net-after-close.js`,
`test-tls-buffersize.js`, `test-net-pingpong.js`,
`test-tls-handshake-error.js`, `test-tls-server-verify.js` still
pass (`bufferSize` getter change verified non-regressing)
- [x] `./x fmt` clean
- [x] `./x lint-js` clean
Closes denoland/orchid#901 parent b049dfc commit 52616e8
4 files changed
Lines changed: 42 additions & 6 deletions
File tree
- ext/node/polyfills
- internal
- tests/node_compat
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
215 | 215 | | |
216 | 216 | | |
217 | 217 | | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
218 | 221 | | |
219 | 222 | | |
220 | 223 | | |
| |||
346 | 349 | | |
347 | 350 | | |
348 | 351 | | |
| 352 | + | |
349 | 353 | | |
350 | 354 | | |
351 | 355 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
| 23 | + | |
22 | 24 | | |
23 | 25 | | |
24 | 26 | | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
25 | 30 | | |
26 | 31 | | |
27 | 32 | | |
| |||
126 | 131 | | |
127 | 132 | | |
128 | 133 | | |
129 | | - | |
130 | | - | |
131 | | - | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
132 | 151 | | |
133 | 152 | | |
134 | 153 | | |
| |||
142 | 161 | | |
143 | 162 | | |
144 | 163 | | |
145 | | - | |
| 164 | + | |
146 | 165 | | |
147 | 166 | | |
148 | 167 | | |
| |||
289 | 308 | | |
290 | 309 | | |
291 | 310 | | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
292 | 317 | | |
293 | 318 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1621 | 1621 | | |
1622 | 1622 | | |
1623 | 1623 | | |
1624 | | - | |
1625 | | - | |
| 1624 | + | |
1626 | 1625 | | |
1627 | 1626 | | |
1628 | 1627 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3340 | 3340 | | |
3341 | 3341 | | |
3342 | 3342 | | |
| 3343 | + | |
| 3344 | + | |
| 3345 | + | |
3343 | 3346 | | |
3344 | 3347 | | |
3345 | 3348 | | |
| |||
3579 | 3582 | | |
3580 | 3583 | | |
3581 | 3584 | | |
| 3585 | + | |
3582 | 3586 | | |
3583 | 3587 | | |
3584 | 3588 | | |
| |||
3591 | 3595 | | |
3592 | 3596 | | |
3593 | 3597 | | |
| 3598 | + | |
| 3599 | + | |
| 3600 | + | |
| 3601 | + | |
3594 | 3602 | | |
3595 | 3603 | | |
3596 | 3604 | | |
| |||
0 commit comments