http2,zlib: prefer call() over apply() if argument list is not array

PR-URL: https://github.com/nodejs/node/pull/60834
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
Livia Medeiros
2025-12-04 22:36:16 +08:00
committed by GitHub
parent f65b0bc81a
commit e77694631f
3 changed files with 19 additions and 22 deletions

View File

@@ -7,7 +7,6 @@ const {
ObjectHasOwn,
ObjectKeys,
Proxy,
ReflectApply,
ReflectGetPrototypeOf,
Symbol,
} = primordials;
@@ -846,7 +845,7 @@ class Http2ServerResponse extends Stream {
this.writeHead(this[kState].statusCode);
if (this[kState].closed || stream.destroyed)
ReflectApply(onStreamCloseResponse, stream, []);
onStreamCloseResponse.call(stream);
else
stream.end();

View File

@@ -1960,7 +1960,7 @@ function shutdownWritable(callback) {
req.handle = handle;
const err = handle.shutdown(req);
if (err === 1) // synchronous finish
return ReflectApply(afterShutdown, req, [0]);
return afterShutdown.call(req, 0);
}
function finishSendTrailers(stream, headersList) {
@@ -2327,7 +2327,7 @@ class Http2Stream extends Duplex {
return;
}
debugStreamObj(this, 'shutting down writable on _final');
ReflectApply(shutdownWritable, this, [cb]);
shutdownWritable.call(this, cb);
if (this.session[kType] === NGHTTP2_SESSION_CLIENT && onClientStreamBodySentChannel.hasSubscribers) {
onClientStreamBodySentChannel.publish({ stream: this });
@@ -2741,8 +2741,7 @@ function doSendFD(session, options, fd, headers, streamOptions, err, stat) {
// response is canceled. The user code may also send a separate type
// of response so check again for the HEADERS_SENT flag
if ((typeof options.statCheck === 'function' &&
ReflectApply(options.statCheck, this,
[stat, headers, statOptions]) === false) ||
options.statCheck.call(this, stat, headers, statOptions) === false) ||
(this[kState].flags & STREAM_FLAGS_HEADERS_SENT)) {
return;
}
@@ -2801,7 +2800,7 @@ function doSendFileFD(session, options, fd, headers, streamOptions, err, stat) {
// response is canceled. The user code may also send a separate type
// of response so check again for the HEADERS_SENT flag
if ((typeof options.statCheck === 'function' &&
ReflectApply(options.statCheck, this, [stat, headers]) === false) ||
options.statCheck.call(this, stat, headers) === false) ||
(this[kState].flags & STREAM_FLAGS_HEADERS_SENT)) {
tryClose(fd);
return;
@@ -3633,9 +3632,9 @@ function getUnpackedSettings(buf, options = kEmptyObject) {
const settings = {};
let offset = 0;
while (offset < buf.length) {
const id = ReflectApply(readUInt16BE, buf, [offset]);
const id = readUInt16BE.call(buf, offset);
offset += 2;
const value = ReflectApply(readUInt32BE, buf, [offset]);
const value = readUInt32BE.call(buf, offset);
switch (id) {
case NGHTTP2_SETTINGS_HEADER_TABLE_SIZE:
settings.headerTableSize = value;

View File

@@ -31,7 +31,6 @@ const {
ObjectFreeze,
ObjectKeys,
ObjectSetPrototypeOf,
ReflectApply,
Symbol,
Uint32Array,
} = primordials;
@@ -255,7 +254,7 @@ function ZlibBase(opts, mode, handle, { flush, finishFlush, fullFlush }) {
}
}
ReflectApply(Transform, this, [{ autoDestroy: true, ...opts }]);
Transform.call(this, { autoDestroy: true, ...opts });
this[kError] = null;
this.bytesWritten = 0;
this._handle = handle;
@@ -681,7 +680,7 @@ function Zlib(opts, mode) {
processCallback,
dictionary);
ReflectApply(ZlibBase, this, [opts, mode, handle, zlibDefaultOpts]);
ZlibBase.call(this, opts, mode, handle, zlibDefaultOpts);
this._level = level;
this._strategy = strategy;
@@ -724,7 +723,7 @@ function Deflate(opts) {
if (!(this instanceof Deflate)) {
return deprecateInstantiation(Deflate, 'DEP0184', opts);
}
ReflectApply(Zlib, this, [opts, DEFLATE]);
Zlib.call(this, opts, DEFLATE);
}
ObjectSetPrototypeOf(Deflate.prototype, Zlib.prototype);
ObjectSetPrototypeOf(Deflate, Zlib);
@@ -733,7 +732,7 @@ function Inflate(opts) {
if (!(this instanceof Inflate)) {
return deprecateInstantiation(Inflate, 'DEP0184', opts);
}
ReflectApply(Zlib, this, [opts, INFLATE]);
Zlib.call(this, opts, INFLATE);
}
ObjectSetPrototypeOf(Inflate.prototype, Zlib.prototype);
ObjectSetPrototypeOf(Inflate, Zlib);
@@ -742,7 +741,7 @@ function Gzip(opts) {
if (!(this instanceof Gzip)) {
return deprecateInstantiation(Gzip, 'DEP0184', opts);
}
ReflectApply(Zlib, this, [opts, GZIP]);
Zlib.call(this, opts, GZIP);
}
ObjectSetPrototypeOf(Gzip.prototype, Zlib.prototype);
ObjectSetPrototypeOf(Gzip, Zlib);
@@ -751,7 +750,7 @@ function Gunzip(opts) {
if (!(this instanceof Gunzip)) {
return deprecateInstantiation(Gunzip, 'DEP0184', opts);
}
ReflectApply(Zlib, this, [opts, GUNZIP]);
Zlib.call(this, opts, GUNZIP);
}
ObjectSetPrototypeOf(Gunzip.prototype, Zlib.prototype);
ObjectSetPrototypeOf(Gunzip, Zlib);
@@ -761,7 +760,7 @@ function DeflateRaw(opts) {
if (!(this instanceof DeflateRaw)) {
return deprecateInstantiation(DeflateRaw, 'DEP0184', opts);
}
ReflectApply(Zlib, this, [opts, DEFLATERAW]);
Zlib.call(this, opts, DEFLATERAW);
}
ObjectSetPrototypeOf(DeflateRaw.prototype, Zlib.prototype);
ObjectSetPrototypeOf(DeflateRaw, Zlib);
@@ -770,7 +769,7 @@ function InflateRaw(opts) {
if (!(this instanceof InflateRaw)) {
return deprecateInstantiation(InflateRaw, 'DEP0184', opts);
}
ReflectApply(Zlib, this, [opts, INFLATERAW]);
Zlib.call(this, opts, INFLATERAW);
}
ObjectSetPrototypeOf(InflateRaw.prototype, Zlib.prototype);
ObjectSetPrototypeOf(InflateRaw, Zlib);
@@ -779,7 +778,7 @@ function Unzip(opts) {
if (!(this instanceof Unzip)) {
return deprecateInstantiation(Unzip, 'DEP0184', opts);
}
ReflectApply(Zlib, this, [opts, UNZIP]);
Zlib.call(this, opts, UNZIP);
}
ObjectSetPrototypeOf(Unzip.prototype, Zlib.prototype);
ObjectSetPrototypeOf(Unzip, Zlib);
@@ -837,7 +836,7 @@ function Brotli(opts, mode) {
this._writeState = new Uint32Array(2);
handle.init(brotliInitParamsArray, this._writeState, processCallback);
ReflectApply(ZlibBase, this, [opts, mode, handle, brotliDefaultOpts]);
ZlibBase.call(this, opts, mode, handle, brotliDefaultOpts);
}
ObjectSetPrototypeOf(Brotli.prototype, Zlib.prototype);
ObjectSetPrototypeOf(Brotli, Zlib);
@@ -846,7 +845,7 @@ function BrotliCompress(opts) {
if (!(this instanceof BrotliCompress)) {
return deprecateInstantiation(BrotliCompress, 'DEP0184', opts);
}
ReflectApply(Brotli, this, [opts, BROTLI_ENCODE]);
Brotli.call(this, opts, BROTLI_ENCODE);
}
ObjectSetPrototypeOf(BrotliCompress.prototype, Brotli.prototype);
ObjectSetPrototypeOf(BrotliCompress, Brotli);
@@ -855,7 +854,7 @@ function BrotliDecompress(opts) {
if (!(this instanceof BrotliDecompress)) {
return deprecateInstantiation(BrotliDecompress, 'DEP0184', opts);
}
ReflectApply(Brotli, this, [opts, BROTLI_DECODE]);
Brotli.call(this, opts, BROTLI_DECODE);
}
ObjectSetPrototypeOf(BrotliDecompress.prototype, Brotli.prototype);
ObjectSetPrototypeOf(BrotliDecompress, Brotli);