-
-
Notifications
You must be signed in to change notification settings - Fork 163
fix(runtime): dispatch node:stream super() through the legacy Stream base #10805
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| ### Fixed | ||
|
|
||
| - **`class X extends Stream` (the bare `node:stream` base) — `pipe()`, the | ||
| EventEmitter listener/emit surface, and `instanceof Stream` are no longer | ||
| missing.** `#10649` fixed the analogous dynamic-heritage dispatch for | ||
| `Readable`/`Writable`/`Duplex`/`Transform` but stopped short of `Stream` — | ||
| the base those four derive from. Every heritage shape (bare import, | ||
| namespace member, or CJS destructured `require('stream')`) now installs | ||
| the correct surface, matching Node byte-for-byte. `instanceof Stream` is | ||
| scoped to genuine `extends Stream` subclasses only — a plain | ||
| `extends EventEmitter` class does not newly satisfy it. `PassThrough` | ||
| (`#10745`) is a separate, deeper gap and remains unaffected. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| // #10798: `class X extends Stream` (the bare legacy `node:stream` base, not | ||
| // one of its subclasses) threw `TypeError: ... is not a constructor`. This | ||
| // blocked `nodemailer`, which loads `class XOAuth2 extends Stream` on | ||
| // import. | ||
| // | ||
| // PR #10649 fixed the analogous dynamic-heritage-dispatch gap in | ||
| // `js_fetch_or_value_super` (crates/perry-runtime/src/object/global_this/ | ||
| // fetch_globals.rs) for `Readable`/`Writable`/`Duplex`/`Transform`, but its | ||
| // match list stopped short of `Stream` — the base those four themselves | ||
| // derive from. | ||
| // | ||
| // Unlike #10745 (`PassThrough`), this is NOT the deeper HIR-level gap: | ||
| // `canonical_native_parent_name` (crates/perry-hir/src/lower_decl/ | ||
| // class_decl.rs) never recognized ANY spelling of `Stream` as a native | ||
| // parent — unlike Readable/Writable/Duplex/Transform, which have a fast | ||
| // static path for a plain `import`, EVERY `extends Stream` heritage shape | ||
| // (bare ident, namespace member, CJS destructured `require`) already | ||
| // reaches the same dynamic `js_fetch_or_value_super` dispatch #10649 | ||
| // patches, uniformly. And `Stream` carries no hidden per-instance state to | ||
| // pre-seed in the first place — in Node it is literally `EventEmitter` plus | ||
| // a `pipe()` prototype method (`lib/internal/streams/legacy.js`), so the | ||
| // fix reuses the existing `js_event_emitter_subclass_init` shim rather than | ||
| // adding a stream-specific one. | ||
| import { Stream as ImportedStream } from "node:stream"; | ||
| import * as streamNs from "node:stream"; | ||
| import { createRequire } from "node:module"; | ||
|
|
||
| const req = createRequire(import.meta.url); | ||
| const cjsStreamModule: any = req("stream"); | ||
| const { Stream: RequiredStream } = cjsStreamModule; | ||
|
|
||
| class BareTap extends ImportedStream {} | ||
| class NamespaceTap extends streamNs.Stream {} | ||
| class CjsTap extends RequiredStream {} | ||
|
|
||
| function run(name: string, T: any) { | ||
| let t: any; | ||
| try { | ||
| t = new T(); | ||
| } catch (e) { | ||
| console.log(name, "THREW (construct)", (e as Error).message); | ||
| return; | ||
| } | ||
| let got = 0; | ||
| const seen: string[] = []; | ||
| t.on("data", (c: any) => { | ||
| got++; | ||
| seen.push(String(c)); | ||
| }); | ||
| t.emit("data", "a"); | ||
| t.emit("data", "b"); | ||
| console.log( | ||
| name, | ||
| "count:", got, | ||
| "values:", seen.join(","), | ||
| "typeof pipe:", typeof t.pipe, | ||
| "typeof on:", typeof t.on, | ||
| "typeof once:", typeof t.once, | ||
| "instanceof Stream:", t instanceof ImportedStream, | ||
| ); | ||
| } | ||
|
|
||
| run("bare extends Stream ", BareTap); | ||
| run("namespace extends stream.Stream", NamespaceTap); | ||
| run("cjs destructured extends Stream", CjsTap); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 4841
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 6888
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 3458
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 9433
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 7352
Narrow the compatibility claim to the supported method surface.
js_node_stream_legacy_subclass_initinstallspipe()and the EventEmitter methods as own properties on the subclass instance. Node exposes these methods throughEventEmitter.prototypeandStream.prototype. Own-property reflection can therefore differ. Replace “matching Node byte-for-byte” with wording such as “now installs the supportedpipe()and EventEmitter method surface.”🤖 Prompt for AI Agents