Use new.target instead of instanceof

This commit is contained in:
Jarred Sumner
2023-12-02 18:59:48 -08:00
parent 2f83f32582
commit ca18ef068e
6 changed files with 26 additions and 26 deletions

View File

@@ -7461,7 +7461,7 @@ var require__ = __commonJS({
BlockHash = common.BlockHash,
sha1_K = [1518500249, 1859775393, 2400959708, 3395469782];
function SHA1() {
if (!(this instanceof SHA1)) return new SHA1();
if (!new.target) return new SHA1();
BlockHash.$call(this),
(this.h = [1732584193, 4023233417, 2562383102, 271733878, 3285377520]),
(this.W = new Array(80));
@@ -7526,7 +7526,7 @@ var require__2 = __commonJS({
3329325298,
];
function SHA256() {
if (!(this instanceof SHA256)) return new SHA256();
if (!new.target) return new SHA256();
BlockHash.$call(this),
(this.h = [1779033703, 3144134277, 1013904242, 2773480762, 1359893119, 2600822924, 528734635, 1541459225]),
(this.k = sha256_K),
@@ -7576,7 +7576,7 @@ var require__3 = __commonJS({
var utils = require_utils4(),
SHA256 = require__2();
function SHA224() {
if (!(this instanceof SHA224)) return new SHA224();
if (!new.target) return new SHA224();
SHA256.$call(this),
(this.h = [3238371032, 914150663, 812702999, 4144912697, 4290775857, 1750603025, 1694076839, 3204075428]);
}
@@ -7632,7 +7632,7 @@ var require__4 = __commonJS({
3409855158, 1501505948, 4234509866, 1607167915, 987167468, 1816402316, 1246189591,
];
function SHA512() {
if (!(this instanceof SHA512)) return new SHA512();
if (!new.target) return new SHA512();
BlockHash.$call(this),
(this.h = [
1779033703, 4089235720, 3144134277, 2227873595, 1013904242, 4271175723, 2773480762, 1595750129, 1359893119,
@@ -7812,7 +7812,7 @@ var require__5 = __commonJS({
var utils = require_utils4(),
SHA512 = require__4();
function SHA384() {
if (!(this instanceof SHA384)) return new SHA384();
if (!new.target) return new SHA384();
SHA512.$call(this),
(this.h = [
3418070365, 3238371032, 1654270250, 914150663, 2438529370, 812702999, 355462360, 4144912697, 1731405415,
@@ -7855,7 +7855,7 @@ var require_ripemd = __commonJS({
sum32_4 = utils.sum32_4,
BlockHash = common.BlockHash;
function RIPEMD160() {
if (!(this instanceof RIPEMD160)) return new RIPEMD160();
if (!new.target) return new RIPEMD160();
BlockHash.$call(this),
(this.h = [1732584193, 4023233417, 2562383102, 271733878, 3285377520]),
(this.endian = "little");
@@ -7954,7 +7954,7 @@ var require_hmac = __commonJS({
function Hmac(hash, key, enc) {
key = exportIfKeyObject(key);
if (!(this instanceof Hmac)) return new Hmac(hash, key, enc);
if (!new.target) return new Hmac(hash, key, enc);
(this.Hash = hash),
(this.blockSize = hash.blockSize / 8),
(this.outSize = hash.outSize / 8),
@@ -8965,7 +8965,7 @@ var require_hmac_drbg = __commonJS({
utils = require_utils2(),
assert = require_minimalistic_assert();
function HmacDRBG(options) {
if (!(this instanceof HmacDRBG)) return new HmacDRBG(options);
if (!new.target) return new HmacDRBG(options);
(this.hash = options.hash),
(this.predResist = !!options.predResist),
(this.outLen = this.hash.outSize),
@@ -9196,7 +9196,7 @@ var require_ec = __commonJS({
KeyPair = require_key(),
Signature = require_signature();
function EC(options) {
if (!(this instanceof EC)) return new EC(options);
if (!new.target) return new EC(options);
typeof options == "string" &&
(assert(Object.prototype.hasOwnProperty.$call(curves, options), "Unknown curve " + options),
(options = curves[options])),

View File

@@ -851,7 +851,7 @@ var defaultWriteStreamOptions = {
};
var WriteStreamClass = (WriteStream = function WriteStream(path, options = defaultWriteStreamOptions) {
if (!(this instanceof WriteStream)) {
if (!new.target) {
return new WriteStream(path, options);
}

View File

@@ -1411,7 +1411,7 @@ function onResize() {
}
function InterfaceConstructor(input, output, completer, terminal) {
if (!(this instanceof InterfaceConstructor)) {
if (!new.target) {
return new InterfaceConstructor(input, output, completer, terminal);
}
@@ -2536,7 +2536,7 @@ var _Interface = class Interface extends InterfaceConstructor {
};
function Interface(input, output, completer, terminal) {
if (!(this instanceof Interface)) {
if (!new.target) {
return new Interface(input, output, completer, terminal);
}

View File

@@ -2000,7 +2000,7 @@ var require_legacy = __commonJS({
var { ArrayIsArray, ObjectSetPrototypeOf } = require_primordials();
function Stream(options) {
if (!(this instanceof Stream)) return new Stream(options);
if (!new.target) return new Stream(options);
EE.$call(this, options);
}
Stream.prototype = {};
@@ -2264,7 +2264,7 @@ var require_readable = __commonJS({
var { Stream, prependListener } = require_legacy();
function Readable(options) {
if (!(this instanceof Readable)) return new Readable(options);
if (!new.target) return new Readable(options);
const isDuplex = this instanceof require_duplex();
this._readableState = new ReadableState(options, this, isDuplex);
if (options) {
@@ -4386,7 +4386,7 @@ var require_duplex = __commonJS({
var Readable = require_readable();
function Duplex(options) {
if (!(this instanceof Duplex)) return new Duplex(options);
if (!new.target) return new Duplex(options);
Readable.$call(this, options);
Writable.$call(this, options);
@@ -4472,7 +4472,7 @@ var require_transform = __commonJS({
var { ERR_METHOD_NOT_IMPLEMENTED } = require_errors().codes;
var Duplex = require_duplex();
function Transform(options) {
if (!(this instanceof Transform)) return new Transform(options);
if (!new.target) return new Transform(options);
Duplex.$call(this, options);
this._readableState.sync = false;
@@ -4569,7 +4569,7 @@ var require_passthrough = __commonJS({
var Transform = require_transform();
function PassThrough(options) {
if (!(this instanceof PassThrough)) return new PassThrough(options);
if (!new.target) return new PassThrough(options);
Transform.$call(this, options);
}
PassThrough.prototype = {};

View File

@@ -4,7 +4,7 @@ const { ttySetMode, isatty, getWindowSize: _getWindowSize } = $lazy("tty");
const NumberIsInteger = Number.isInteger;
function ReadStream(fd) {
if (!(this instanceof ReadStream)) return new ReadStream(fd);
if (!new.target) return new ReadStream(fd);
if (fd >> 0 !== fd || fd < 0) throw new RangeError("fd must be a positive integer");
const stream = require("node:fs").ReadStream.$call(this, "", {
@@ -99,7 +99,7 @@ function warnOnDeactivatedColors(env) {
}
function WriteStream(fd) {
if (!(this instanceof WriteStream)) return new WriteStream(fd);
if (!new.target) return new WriteStream(fd);
if (fd >> 0 !== fd || fd < 0) throw new RangeError("fd must be a positive integer");
const stream = require("node:fs").WriteStream.$call(this, "", {

View File

@@ -4123,31 +4123,31 @@ var require_lib = __commonJS({
return engine._processChunk(buffer, flushFlag);
}
function Deflate(opts) {
if (!(this instanceof Deflate)) return new Deflate(opts);
if (!new.target) return new Deflate(opts);
Zlib.$call(this, opts, binding.DEFLATE);
}
function Inflate(opts) {
if (!(this instanceof Inflate)) return new Inflate(opts);
if (!new.target) return new Inflate(opts);
Zlib.$call(this, opts, binding.INFLATE);
}
function Gzip(opts) {
if (!(this instanceof Gzip)) return new Gzip(opts);
if (!new.target) return new Gzip(opts);
Zlib.$call(this, opts, binding.GZIP);
}
function Gunzip(opts) {
if (!(this instanceof Gunzip)) return new Gunzip(opts);
if (!new.target) return new Gunzip(opts);
Zlib.$call(this, opts, binding.GUNZIP);
}
function DeflateRaw(opts) {
if (!(this instanceof DeflateRaw)) return new DeflateRaw(opts);
if (!new.target) return new DeflateRaw(opts);
Zlib.$call(this, opts, binding.DEFLATERAW);
}
function InflateRaw(opts) {
if (!(this instanceof InflateRaw)) return new InflateRaw(opts);
if (!new.target) return new InflateRaw(opts);
Zlib.$call(this, opts, binding.INFLATERAW);
}
function Unzip(opts) {
if (!(this instanceof Unzip)) return new Unzip(opts);
if (!new.target) return new Unzip(opts);
Zlib.$call(this, opts, binding.UNZIP);
}
function isValidFlushFlag(flag) {