Compare commits

...

1 Commits

Author SHA1 Message Date
Jarred Sumner
0c77e5ca59 Remove unnecessary usages of Reflect.construct 2025-08-26 23:10:38 -07:00
6 changed files with 9 additions and 7 deletions

View File

@@ -270,8 +270,8 @@ export function createConsoleConstructor(console: typeof globalThis.console) {
// We have to test new.target here to see if this function is called
// with new, because we need to define a custom instanceof to accommodate
// the global console.
if (new.target === undefined) {
return Reflect.construct(Console, arguments);
if (!new.target) {
return new (Console as unknown as typeof import("node:console").Console)(...arguments);
}
if (!options || typeof options.write === "function") {

View File

@@ -17,7 +17,7 @@ const ObjectDefineProperties = Object.defineProperties;
const ObjectGetOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
function Duplex(options) {
if (!(this instanceof Duplex)) return Reflect.construct(Duplex, [options]);
if (!(this instanceof Duplex)) return new (Duplex as unknown as typeof import("node:stream").Duplex)(options);
this._events ??= {
close: undefined,

View File

@@ -7,7 +7,8 @@
const Transform = require("internal/streams/transform");
function PassThrough(options) {
if (!(this instanceof PassThrough)) return Reflect.construct(PassThrough, [options]);
if (!(this instanceof PassThrough))
return new (PassThrough as unknown as typeof import("node:stream").PassThrough)(options);
Transform.$call(this, options);
}

View File

@@ -261,7 +261,7 @@ ReadableState.prototype[kOnConstructed] = function onConstructed(stream) {
};
function Readable(options) {
if (!(this instanceof Readable)) return Reflect.construct(Readable, [options]);
if (!(this instanceof Readable)) return new (Readable as unknown as typeof import("node:stream").Readable)(options);
this._events ??= {
close: undefined,

View File

@@ -48,7 +48,8 @@ const { getHighWaterMark } = require("internal/streams/state");
const kCallback = Symbol("kCallback");
function Transform(options) {
if (!(this instanceof Transform)) return Reflect.construct(Transform, [options]);
if (!(this instanceof Transform))
return new (Transform as unknown as typeof import("node:stream").Transform)(options);
// TODO (ronag): This should preferably always be
// applied but would be semver-major. Or even better;

View File

@@ -357,7 +357,7 @@ WritableState.prototype[kOnConstructed] = function onConstructed(stream) {
};
function Writable(options) {
if (!(this instanceof Writable)) return Reflect.construct(Writable, [options]);
if (!(this instanceof Writable)) return new (Writable as unknown as typeof import("node:stream").Writable)(options);
this._events ??= {
close: undefined,