zlib: deprecate classes usage without new

PR-URL: https://github.com/nodejs/node/pull/55718
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
This commit is contained in:
Yagiz Nizipli
2024-11-29 15:55:03 -05:00
committed by GitHub
parent 22792b852c
commit 4ee87b8bc3
3 changed files with 42 additions and 19 deletions

View File

@@ -46,6 +46,9 @@ const {
genericNodeError,
} = require('internal/errors');
const { Transform, finished } = require('stream');
const {
deprecateInstantiation,
} = require('internal/util');
const {
isArrayBufferView,
isAnyArrayBuffer,
@@ -686,32 +689,36 @@ Zlib.prototype.params = function params(level, strategy, callback) {
// generic zlib
// minimal 2-byte header
function Deflate(opts) {
if (!(this instanceof Deflate))
return new Deflate(opts);
if (!(this instanceof Deflate)) {
return deprecateInstantiation(Deflate, 'DEP0184', opts);
}
ReflectApply(Zlib, this, [opts, DEFLATE]);
}
ObjectSetPrototypeOf(Deflate.prototype, Zlib.prototype);
ObjectSetPrototypeOf(Deflate, Zlib);
function Inflate(opts) {
if (!(this instanceof Inflate))
return new Inflate(opts);
if (!(this instanceof Inflate)) {
return deprecateInstantiation(Inflate, 'DEP0184', opts);
}
ReflectApply(Zlib, this, [opts, INFLATE]);
}
ObjectSetPrototypeOf(Inflate.prototype, Zlib.prototype);
ObjectSetPrototypeOf(Inflate, Zlib);
function Gzip(opts) {
if (!(this instanceof Gzip))
return new Gzip(opts);
if (!(this instanceof Gzip)) {
return deprecateInstantiation(Gzip, 'DEP0184', opts);
}
ReflectApply(Zlib, this, [opts, GZIP]);
}
ObjectSetPrototypeOf(Gzip.prototype, Zlib.prototype);
ObjectSetPrototypeOf(Gzip, Zlib);
function Gunzip(opts) {
if (!(this instanceof Gunzip))
return new Gunzip(opts);
if (!(this instanceof Gunzip)) {
return deprecateInstantiation(Gunzip, 'DEP0184', opts);
}
ReflectApply(Zlib, this, [opts, GUNZIP]);
}
ObjectSetPrototypeOf(Gunzip.prototype, Zlib.prototype);
@@ -719,24 +726,27 @@ ObjectSetPrototypeOf(Gunzip, Zlib);
function DeflateRaw(opts) {
if (opts && opts.windowBits === 8) opts.windowBits = 9;
if (!(this instanceof DeflateRaw))
return new DeflateRaw(opts);
if (!(this instanceof DeflateRaw)) {
return deprecateInstantiation(DeflateRaw, 'DEP0184', opts);
}
ReflectApply(Zlib, this, [opts, DEFLATERAW]);
}
ObjectSetPrototypeOf(DeflateRaw.prototype, Zlib.prototype);
ObjectSetPrototypeOf(DeflateRaw, Zlib);
function InflateRaw(opts) {
if (!(this instanceof InflateRaw))
return new InflateRaw(opts);
if (!(this instanceof InflateRaw)) {
return deprecateInstantiation(InflateRaw, 'DEP0184', opts);
}
ReflectApply(Zlib, this, [opts, INFLATERAW]);
}
ObjectSetPrototypeOf(InflateRaw.prototype, Zlib.prototype);
ObjectSetPrototypeOf(InflateRaw, Zlib);
function Unzip(opts) {
if (!(this instanceof Unzip))
return new Unzip(opts);
if (!(this instanceof Unzip)) {
return deprecateInstantiation(Unzip, 'DEP0184', opts);
}
ReflectApply(Zlib, this, [opts, UNZIP]);
}
ObjectSetPrototypeOf(Unzip.prototype, Zlib.prototype);
@@ -801,16 +811,18 @@ ObjectSetPrototypeOf(Brotli.prototype, Zlib.prototype);
ObjectSetPrototypeOf(Brotli, Zlib);
function BrotliCompress(opts) {
if (!(this instanceof BrotliCompress))
return new BrotliCompress(opts);
if (!(this instanceof BrotliCompress)) {
return deprecateInstantiation(BrotliCompress, 'DEP0184', opts);
}
ReflectApply(Brotli, this, [opts, BROTLI_ENCODE]);
}
ObjectSetPrototypeOf(BrotliCompress.prototype, Brotli.prototype);
ObjectSetPrototypeOf(BrotliCompress, Brotli);
function BrotliDecompress(opts) {
if (!(this instanceof BrotliDecompress))
return new BrotliDecompress(opts);
if (!(this instanceof BrotliDecompress)) {
return deprecateInstantiation(BrotliDecompress, 'DEP0184', opts);
}
ReflectApply(Brotli, this, [opts, BROTLI_DECODE]);
}
ObjectSetPrototypeOf(BrotliDecompress.prototype, Brotli.prototype);