Skip to content

Commit

Permalink
zlib: deprecate initializing without new qualifier
Browse files Browse the repository at this point in the history
  • Loading branch information
anonrig committed Aug 31, 2024
1 parent beabcec commit 34d7201
Showing 1 changed file with 29 additions and 9 deletions.
38 changes: 29 additions & 9 deletions lib/zlib.js
Original file line number Diff line number Diff line change
Expand Up @@ -706,57 +706,72 @@ Zlib.prototype.params = function params(level, strategy, callback) {
// generic zlib
// minimal 2-byte header
function Deflate(opts) {
if (!(this instanceof Deflate))
if (!(this instanceof Deflate)) {
process.emitWarning(`Initializing Deflate without "new" qualifier is deprecated`, 'DEP0000');
return new Deflate(opts);
}
ReflectApply(Zlib, this, [opts, DEFLATE]);
}
ObjectSetPrototypeOf(Deflate.prototype, Zlib.prototype);
ObjectSetPrototypeOf(Deflate, Zlib);

function Inflate(opts) {
if (!(this instanceof Inflate))
if (!(this instanceof Inflate)) {
process.emitWarning(`Initializing Inflate without "new" qualifier is deprecated`, 'DEP0000');
return new Inflate(opts);
}
ReflectApply(Zlib, this, [opts, INFLATE]);
}
ObjectSetPrototypeOf(Inflate.prototype, Zlib.prototype);
ObjectSetPrototypeOf(Inflate, Zlib);

function Gzip(opts) {
if (!(this instanceof Gzip))
if (!(this instanceof Gzip)) {
process.emitWarning(`Initializing Inflate without "new" qualifier is deprecated`, 'DEP0000');
return new Gzip(opts);
}
ReflectApply(Zlib, this, [opts, GZIP]);
}
ObjectSetPrototypeOf(Gzip.prototype, Zlib.prototype);
ObjectSetPrototypeOf(Gzip, Zlib);

function Gunzip(opts) {
if (!(this instanceof Gunzip))
if (!(this instanceof Gunzip)) {
process.emitWarning(`Initializing Gunzip without "new" qualifier is deprecated`, 'DEP0000');
return new Gunzip(opts);
}
ReflectApply(Zlib, this, [opts, GUNZIP]);
}
ObjectSetPrototypeOf(Gunzip.prototype, Zlib.prototype);
ObjectSetPrototypeOf(Gunzip, Zlib);

function DeflateRaw(opts) {
if (opts && opts.windowBits === 8) opts.windowBits = 9;
if (!(this instanceof DeflateRaw))
if (!(this instanceof DeflateRaw)) {
process.emitWarning(`Initializing DeflateRaw without "new" qualifier is deprecated`, 'DEP0000');
return new DeflateRaw(opts);
}
ReflectApply(Zlib, this, [opts, DEFLATERAW]);
}
ObjectSetPrototypeOf(DeflateRaw.prototype, Zlib.prototype);
ObjectSetPrototypeOf(DeflateRaw, Zlib);

function InflateRaw(opts) {
if (!(this instanceof InflateRaw))
if (!(this instanceof InflateRaw)) {
process.emitWarning(`Initializing InflateRaw without "new" qualifier is deprecated`, 'DEP0000');
return new InflateRaw(opts);
}
ReflectApply(Zlib, this, [opts, INFLATERAW]);
}
ObjectSetPrototypeOf(InflateRaw.prototype, Zlib.prototype);
ObjectSetPrototypeOf(InflateRaw, Zlib);

function Unzip(opts) {
if (!(this instanceof Unzip))
if (!(this instanceof Unzip)) {
process.emitWarning(`Initializing Unzip without "new" qualifier is deprecated`, 'DEP0000');
return new Unzip(opts);

}
ReflectApply(Zlib, this, [opts, UNZIP]);
}
ObjectSetPrototypeOf(Unzip.prototype, Zlib.prototype);
Expand Down Expand Up @@ -831,16 +846,21 @@ ObjectSetPrototypeOf(Brotli.prototype, Zlib.prototype);
ObjectSetPrototypeOf(Brotli, Zlib);

function BrotliCompress(opts) {
if (!(this instanceof BrotliCompress))
if (!(this instanceof BrotliCompress)) {
process.emitWarning(`Initializing BrotliCompress without "new" qualifier is deprecated`, 'DEP0000');
return new BrotliCompress(opts);
}
ReflectApply(Brotli, this, [opts, BROTLI_ENCODE]);
}
ObjectSetPrototypeOf(BrotliCompress.prototype, Brotli.prototype);
ObjectSetPrototypeOf(BrotliCompress, Brotli);

function BrotliDecompress(opts) {
if (!(this instanceof BrotliDecompress))
if (!(this instanceof BrotliDecompress)) {
process.emitWarning(`Initializing BrotliDecompress without "new" qualifier is deprecated`, 'DEP0000');
return new BrotliDecompress(opts);

}
ReflectApply(Brotli, this, [opts, BROTLI_DECODE]);
}
ObjectSetPrototypeOf(BrotliDecompress.prototype, Brotli.prototype);
Expand Down

0 comments on commit 34d7201

Please sign in to comment.