@@ -46,6 +46,9 @@ const {
4646 genericNodeError,
4747} = require ( 'internal/errors' ) ;
4848const { Transform, finished } = require ( 'stream' ) ;
49+ const {
50+ deprecateInstantiation,
51+ } = require ( 'internal/util' ) ;
4952const {
5053 isArrayBufferView,
5154 isAnyArrayBuffer,
@@ -686,57 +689,64 @@ Zlib.prototype.params = function params(level, strategy, callback) {
686689// generic zlib
687690// minimal 2-byte header
688691function Deflate ( opts ) {
689- if ( ! ( this instanceof Deflate ) )
690- return new Deflate ( opts ) ;
692+ if ( ! ( this instanceof Deflate ) ) {
693+ return deprecateInstantiation ( Deflate , 'DEP0184' , opts ) ;
694+ }
691695 ReflectApply ( Zlib , this , [ opts , DEFLATE ] ) ;
692696}
693697ObjectSetPrototypeOf ( Deflate . prototype , Zlib . prototype ) ;
694698ObjectSetPrototypeOf ( Deflate , Zlib ) ;
695699
696700function Inflate ( opts ) {
697- if ( ! ( this instanceof Inflate ) )
698- return new Inflate ( opts ) ;
701+ if ( ! ( this instanceof Inflate ) ) {
702+ return deprecateInstantiation ( Inflate , 'DEP0184' , opts ) ;
703+ }
699704 ReflectApply ( Zlib , this , [ opts , INFLATE ] ) ;
700705}
701706ObjectSetPrototypeOf ( Inflate . prototype , Zlib . prototype ) ;
702707ObjectSetPrototypeOf ( Inflate , Zlib ) ;
703708
704709function Gzip ( opts ) {
705- if ( ! ( this instanceof Gzip ) )
706- return new Gzip ( opts ) ;
710+ if ( ! ( this instanceof Gzip ) ) {
711+ return deprecateInstantiation ( Gzip , 'DEP0184' , opts ) ;
712+ }
707713 ReflectApply ( Zlib , this , [ opts , GZIP ] ) ;
708714}
709715ObjectSetPrototypeOf ( Gzip . prototype , Zlib . prototype ) ;
710716ObjectSetPrototypeOf ( Gzip , Zlib ) ;
711717
712718function Gunzip ( opts ) {
713- if ( ! ( this instanceof Gunzip ) )
714- return new Gunzip ( opts ) ;
719+ if ( ! ( this instanceof Gunzip ) ) {
720+ return deprecateInstantiation ( Gunzip , 'DEP0184' , opts ) ;
721+ }
715722 ReflectApply ( Zlib , this , [ opts , GUNZIP ] ) ;
716723}
717724ObjectSetPrototypeOf ( Gunzip . prototype , Zlib . prototype ) ;
718725ObjectSetPrototypeOf ( Gunzip , Zlib ) ;
719726
720727function DeflateRaw ( opts ) {
721728 if ( opts && opts . windowBits === 8 ) opts . windowBits = 9 ;
722- if ( ! ( this instanceof DeflateRaw ) )
723- return new DeflateRaw ( opts ) ;
729+ if ( ! ( this instanceof DeflateRaw ) ) {
730+ return deprecateInstantiation ( DeflateRaw , 'DEP0184' , opts ) ;
731+ }
724732 ReflectApply ( Zlib , this , [ opts , DEFLATERAW ] ) ;
725733}
726734ObjectSetPrototypeOf ( DeflateRaw . prototype , Zlib . prototype ) ;
727735ObjectSetPrototypeOf ( DeflateRaw , Zlib ) ;
728736
729737function InflateRaw ( opts ) {
730- if ( ! ( this instanceof InflateRaw ) )
731- return new InflateRaw ( opts ) ;
738+ if ( ! ( this instanceof InflateRaw ) ) {
739+ return deprecateInstantiation ( InflateRaw , 'DEP0184' , opts ) ;
740+ }
732741 ReflectApply ( Zlib , this , [ opts , INFLATERAW ] ) ;
733742}
734743ObjectSetPrototypeOf ( InflateRaw . prototype , Zlib . prototype ) ;
735744ObjectSetPrototypeOf ( InflateRaw , Zlib ) ;
736745
737746function Unzip ( opts ) {
738- if ( ! ( this instanceof Unzip ) )
739- return new Unzip ( opts ) ;
747+ if ( ! ( this instanceof Unzip ) ) {
748+ return deprecateInstantiation ( Unzip , 'DEP0184' , opts ) ;
749+ }
740750 ReflectApply ( Zlib , this , [ opts , UNZIP ] ) ;
741751}
742752ObjectSetPrototypeOf ( Unzip . prototype , Zlib . prototype ) ;
@@ -801,16 +811,18 @@ ObjectSetPrototypeOf(Brotli.prototype, Zlib.prototype);
801811ObjectSetPrototypeOf ( Brotli , Zlib ) ;
802812
803813function BrotliCompress ( opts ) {
804- if ( ! ( this instanceof BrotliCompress ) )
805- return new BrotliCompress ( opts ) ;
814+ if ( ! ( this instanceof BrotliCompress ) ) {
815+ return deprecateInstantiation ( BrotliCompress , 'DEP0184' , opts ) ;
816+ }
806817 ReflectApply ( Brotli , this , [ opts , BROTLI_ENCODE ] ) ;
807818}
808819ObjectSetPrototypeOf ( BrotliCompress . prototype , Brotli . prototype ) ;
809820ObjectSetPrototypeOf ( BrotliCompress , Brotli ) ;
810821
811822function BrotliDecompress ( opts ) {
812- if ( ! ( this instanceof BrotliDecompress ) )
813- return new BrotliDecompress ( opts ) ;
823+ if ( ! ( this instanceof BrotliDecompress ) ) {
824+ return deprecateInstantiation ( BrotliDecompress , 'DEP0184' , opts ) ;
825+ }
814826 ReflectApply ( Brotli , this , [ opts , BROTLI_DECODE ] ) ;
815827}
816828ObjectSetPrototypeOf ( BrotliDecompress . prototype , Brotli . prototype ) ;
0 commit comments