@@ -46,6 +46,9 @@ const { |
46 | 46 | genericNodeError, |
47 | 47 | } = require('internal/errors'); |
48 | 48 | const { Transform, finished } = require('stream'); |
| 49 | +const { |
| 50 | + deprecateInstantiation, |
| 51 | +} = require('internal/util'); |
49 | 52 | const { |
50 | 53 | isArrayBufferView, |
51 | 54 | isAnyArrayBuffer, |
@@ -686,57 +689,64 @@ Zlib.prototype.params = function params(level, strategy, callback) { |
686 | 689 | // generic zlib |
687 | 690 | // minimal 2-byte header |
688 | 691 | function Deflate(opts) { |
689 | | - if (!(this instanceof Deflate)) |
690 | | - return new Deflate(opts); |
| 692 | + if (!(this instanceof Deflate)) { |
| 693 | + return deprecateInstantiation(Deflate, 'DEP0184', opts); |
| 694 | + } |
691 | 695 | ReflectApply(Zlib, this, [opts, DEFLATE]); |
692 | 696 | } |
693 | 697 | ObjectSetPrototypeOf(Deflate.prototype, Zlib.prototype); |
694 | 698 | ObjectSetPrototypeOf(Deflate, Zlib); |
695 | 699 |
|
696 | 700 | function Inflate(opts) { |
697 | | - if (!(this instanceof Inflate)) |
698 | | - return new Inflate(opts); |
| 701 | + if (!(this instanceof Inflate)) { |
| 702 | + return deprecateInstantiation(Inflate, 'DEP0184', opts); |
| 703 | + } |
699 | 704 | ReflectApply(Zlib, this, [opts, INFLATE]); |
700 | 705 | } |
701 | 706 | ObjectSetPrototypeOf(Inflate.prototype, Zlib.prototype); |
702 | 707 | ObjectSetPrototypeOf(Inflate, Zlib); |
703 | 708 |
|
704 | 709 | function Gzip(opts) { |
705 | | - if (!(this instanceof Gzip)) |
706 | | - return new Gzip(opts); |
| 710 | + if (!(this instanceof Gzip)) { |
| 711 | + return deprecateInstantiation(Gzip, 'DEP0184', opts); |
| 712 | + } |
707 | 713 | ReflectApply(Zlib, this, [opts, GZIP]); |
708 | 714 | } |
709 | 715 | ObjectSetPrototypeOf(Gzip.prototype, Zlib.prototype); |
710 | 716 | ObjectSetPrototypeOf(Gzip, Zlib); |
711 | 717 |
|
712 | 718 | function Gunzip(opts) { |
713 | | - if (!(this instanceof Gunzip)) |
714 | | - return new Gunzip(opts); |
| 719 | + if (!(this instanceof Gunzip)) { |
| 720 | + return deprecateInstantiation(Gunzip, 'DEP0184', opts); |
| 721 | + } |
715 | 722 | ReflectApply(Zlib, this, [opts, GUNZIP]); |
716 | 723 | } |
717 | 724 | ObjectSetPrototypeOf(Gunzip.prototype, Zlib.prototype); |
718 | 725 | ObjectSetPrototypeOf(Gunzip, Zlib); |
719 | 726 |
|
720 | 727 | function DeflateRaw(opts) { |
721 | 728 | 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 | + } |
724 | 732 | ReflectApply(Zlib, this, [opts, DEFLATERAW]); |
725 | 733 | } |
726 | 734 | ObjectSetPrototypeOf(DeflateRaw.prototype, Zlib.prototype); |
727 | 735 | ObjectSetPrototypeOf(DeflateRaw, Zlib); |
728 | 736 |
|
729 | 737 | function InflateRaw(opts) { |
730 | | - if (!(this instanceof InflateRaw)) |
731 | | - return new InflateRaw(opts); |
| 738 | + if (!(this instanceof InflateRaw)) { |
| 739 | + return deprecateInstantiation(InflateRaw, 'DEP0184', opts); |
| 740 | + } |
732 | 741 | ReflectApply(Zlib, this, [opts, INFLATERAW]); |
733 | 742 | } |
734 | 743 | ObjectSetPrototypeOf(InflateRaw.prototype, Zlib.prototype); |
735 | 744 | ObjectSetPrototypeOf(InflateRaw, Zlib); |
736 | 745 |
|
737 | 746 | function Unzip(opts) { |
738 | | - if (!(this instanceof Unzip)) |
739 | | - return new Unzip(opts); |
| 747 | + if (!(this instanceof Unzip)) { |
| 748 | + return deprecateInstantiation(Unzip, 'DEP0184', opts); |
| 749 | + } |
740 | 750 | ReflectApply(Zlib, this, [opts, UNZIP]); |
741 | 751 | } |
742 | 752 | ObjectSetPrototypeOf(Unzip.prototype, Zlib.prototype); |
@@ -801,16 +811,18 @@ ObjectSetPrototypeOf(Brotli.prototype, Zlib.prototype); |
801 | 811 | ObjectSetPrototypeOf(Brotli, Zlib); |
802 | 812 |
|
803 | 813 | function BrotliCompress(opts) { |
804 | | - if (!(this instanceof BrotliCompress)) |
805 | | - return new BrotliCompress(opts); |
| 814 | + if (!(this instanceof BrotliCompress)) { |
| 815 | + return deprecateInstantiation(BrotliCompress, 'DEP0184', opts); |
| 816 | + } |
806 | 817 | ReflectApply(Brotli, this, [opts, BROTLI_ENCODE]); |
807 | 818 | } |
808 | 819 | ObjectSetPrototypeOf(BrotliCompress.prototype, Brotli.prototype); |
809 | 820 | ObjectSetPrototypeOf(BrotliCompress, Brotli); |
810 | 821 |
|
811 | 822 | function BrotliDecompress(opts) { |
812 | | - if (!(this instanceof BrotliDecompress)) |
813 | | - return new BrotliDecompress(opts); |
| 823 | + if (!(this instanceof BrotliDecompress)) { |
| 824 | + return deprecateInstantiation(BrotliDecompress, 'DEP0184', opts); |
| 825 | + } |
814 | 826 | ReflectApply(Brotli, this, [opts, BROTLI_DECODE]); |
815 | 827 | } |
816 | 828 | ObjectSetPrototypeOf(BrotliDecompress.prototype, Brotli.prototype); |
|