Skip to content

Commit 34d7201

Browse files
committed
zlib: deprecate initializing without new qualifier
1 parent beabcec commit 34d7201

File tree

1 file changed

+29
-9
lines changed

1 file changed

+29
-9
lines changed

lib/zlib.js

+29-9
Original file line numberDiff line numberDiff line change
@@ -706,57 +706,72 @@ Zlib.prototype.params = function params(level, strategy, callback) {
706706
// generic zlib
707707
// minimal 2-byte header
708708
function Deflate(opts) {
709-
if (!(this instanceof Deflate))
709+
if (!(this instanceof Deflate)) {
710+
process.emitWarning(`Initializing Deflate without "new" qualifier is deprecated`, 'DEP0000');
710711
return new Deflate(opts);
712+
}
711713
ReflectApply(Zlib, this, [opts, DEFLATE]);
712714
}
713715
ObjectSetPrototypeOf(Deflate.prototype, Zlib.prototype);
714716
ObjectSetPrototypeOf(Deflate, Zlib);
715717

716718
function Inflate(opts) {
717-
if (!(this instanceof Inflate))
719+
if (!(this instanceof Inflate)) {
720+
process.emitWarning(`Initializing Inflate without "new" qualifier is deprecated`, 'DEP0000');
718721
return new Inflate(opts);
722+
}
719723
ReflectApply(Zlib, this, [opts, INFLATE]);
720724
}
721725
ObjectSetPrototypeOf(Inflate.prototype, Zlib.prototype);
722726
ObjectSetPrototypeOf(Inflate, Zlib);
723727

724728
function Gzip(opts) {
725-
if (!(this instanceof Gzip))
729+
if (!(this instanceof Gzip)) {
730+
process.emitWarning(`Initializing Inflate without "new" qualifier is deprecated`, 'DEP0000');
726731
return new Gzip(opts);
732+
}
727733
ReflectApply(Zlib, this, [opts, GZIP]);
728734
}
729735
ObjectSetPrototypeOf(Gzip.prototype, Zlib.prototype);
730736
ObjectSetPrototypeOf(Gzip, Zlib);
731737

732738
function Gunzip(opts) {
733-
if (!(this instanceof Gunzip))
739+
if (!(this instanceof Gunzip)) {
740+
process.emitWarning(`Initializing Gunzip without "new" qualifier is deprecated`, 'DEP0000');
734741
return new Gunzip(opts);
742+
}
735743
ReflectApply(Zlib, this, [opts, GUNZIP]);
736744
}
737745
ObjectSetPrototypeOf(Gunzip.prototype, Zlib.prototype);
738746
ObjectSetPrototypeOf(Gunzip, Zlib);
739747

740748
function DeflateRaw(opts) {
741749
if (opts && opts.windowBits === 8) opts.windowBits = 9;
742-
if (!(this instanceof DeflateRaw))
750+
if (!(this instanceof DeflateRaw)) {
751+
process.emitWarning(`Initializing DeflateRaw without "new" qualifier is deprecated`, 'DEP0000');
743752
return new DeflateRaw(opts);
753+
}
744754
ReflectApply(Zlib, this, [opts, DEFLATERAW]);
745755
}
746756
ObjectSetPrototypeOf(DeflateRaw.prototype, Zlib.prototype);
747757
ObjectSetPrototypeOf(DeflateRaw, Zlib);
748758

749759
function InflateRaw(opts) {
750-
if (!(this instanceof InflateRaw))
760+
if (!(this instanceof InflateRaw)) {
761+
process.emitWarning(`Initializing InflateRaw without "new" qualifier is deprecated`, 'DEP0000');
751762
return new InflateRaw(opts);
763+
}
752764
ReflectApply(Zlib, this, [opts, INFLATERAW]);
753765
}
754766
ObjectSetPrototypeOf(InflateRaw.prototype, Zlib.prototype);
755767
ObjectSetPrototypeOf(InflateRaw, Zlib);
756768

757769
function Unzip(opts) {
758-
if (!(this instanceof Unzip))
770+
if (!(this instanceof Unzip)) {
771+
process.emitWarning(`Initializing Unzip without "new" qualifier is deprecated`, 'DEP0000');
759772
return new Unzip(opts);
773+
774+
}
760775
ReflectApply(Zlib, this, [opts, UNZIP]);
761776
}
762777
ObjectSetPrototypeOf(Unzip.prototype, Zlib.prototype);
@@ -831,16 +846,21 @@ ObjectSetPrototypeOf(Brotli.prototype, Zlib.prototype);
831846
ObjectSetPrototypeOf(Brotli, Zlib);
832847

833848
function BrotliCompress(opts) {
834-
if (!(this instanceof BrotliCompress))
849+
if (!(this instanceof BrotliCompress)) {
850+
process.emitWarning(`Initializing BrotliCompress without "new" qualifier is deprecated`, 'DEP0000');
835851
return new BrotliCompress(opts);
852+
}
836853
ReflectApply(Brotli, this, [opts, BROTLI_ENCODE]);
837854
}
838855
ObjectSetPrototypeOf(BrotliCompress.prototype, Brotli.prototype);
839856
ObjectSetPrototypeOf(BrotliCompress, Brotli);
840857

841858
function BrotliDecompress(opts) {
842-
if (!(this instanceof BrotliDecompress))
859+
if (!(this instanceof BrotliDecompress)) {
860+
process.emitWarning(`Initializing BrotliDecompress without "new" qualifier is deprecated`, 'DEP0000');
843861
return new BrotliDecompress(opts);
862+
863+
}
844864
ReflectApply(Brotli, this, [opts, BROTLI_DECODE]);
845865
}
846866
ObjectSetPrototypeOf(BrotliDecompress.prototype, Brotli.prototype);

0 commit comments

Comments
 (0)