constructors part 2 electric boogaloo

This commit is contained in:
snwy
2024-11-05 16:21:33 -08:00
parent 848c1a0547
commit 3e4524656d
6 changed files with 9 additions and 0 deletions

View File

@@ -40,6 +40,8 @@ const { kOnConstructed } = require("internal/streams/utils");
function Duplex(options) {
if (!(this instanceof Duplex)) return new Duplex(options);
this.constructor = Duplex;
this._events ??= {
close: undefined,
error: undefined,

View File

@@ -8,6 +8,7 @@ const EE = require("node:events");
function Stream(opts) {
EE.$call(this, opts);
this.constructor = Stream;
}
Stream.constructor = Stream;

View File

@@ -37,6 +37,8 @@ ObjectSetPrototypeOf(PassThrough, Transform);
function PassThrough(options) {
if (!(this instanceof PassThrough)) return new PassThrough(options);
this.constructor = PassThrough;
Transform.$call(this, options);
}

View File

@@ -311,6 +311,7 @@ ReadableState.prototype[kOnConstructed] = function onConstructed(stream) {
function Readable(options) {
if (!(this instanceof Readable)) return new Readable(options);
this.constructor = Readable;
this._events ??= {
close: undefined,
error: undefined,

View File

@@ -77,6 +77,8 @@ const kCallback = Symbol("kCallback");
function Transform(options) {
if (!(this instanceof Transform)) return new Transform(options);
this.constructor = Transform;
// TODO (ronag): This should preferably always be
// applied but would be semver-major. Or even better;
// make Transform a Readable with the Writable interface.

View File

@@ -388,6 +388,7 @@ WritableState.prototype[kOnConstructed] = function onConstructed(stream) {
function Writable(options) {
if (!(this instanceof Writable)) return new Writable(options);
this.constructor = Writable;
this._events ??= {
close: undefined,
error: undefined,