Skip to content

Commit e776946

Browse files
http2,zlib: prefer call() over apply() if argument list is not array
PR-URL: #60834 Reviewed-By: Luigi Pinca <[email protected]>
1 parent f65b0bc commit e776946

File tree

3 files changed

+19
-22
lines changed

3 files changed

+19
-22
lines changed

lib/internal/http2/compat.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ const {
77
ObjectHasOwn,
88
ObjectKeys,
99
Proxy,
10-
ReflectApply,
1110
ReflectGetPrototypeOf,
1211
Symbol,
1312
} = primordials;
@@ -846,7 +845,7 @@ class Http2ServerResponse extends Stream {
846845
this.writeHead(this[kState].statusCode);
847846

848847
if (this[kState].closed || stream.destroyed)
849-
ReflectApply(onStreamCloseResponse, stream, []);
848+
onStreamCloseResponse.call(stream);
850849
else
851850
stream.end();
852851

lib/internal/http2/core.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1960,7 +1960,7 @@ function shutdownWritable(callback) {
19601960
req.handle = handle;
19611961
const err = handle.shutdown(req);
19621962
if (err === 1) // synchronous finish
1963-
return ReflectApply(afterShutdown, req, [0]);
1963+
return afterShutdown.call(req, 0);
19641964
}
19651965

19661966
function finishSendTrailers(stream, headersList) {
@@ -2327,7 +2327,7 @@ class Http2Stream extends Duplex {
23272327
return;
23282328
}
23292329
debugStreamObj(this, 'shutting down writable on _final');
2330-
ReflectApply(shutdownWritable, this, [cb]);
2330+
shutdownWritable.call(this, cb);
23312331

23322332
if (this.session[kType] === NGHTTP2_SESSION_CLIENT && onClientStreamBodySentChannel.hasSubscribers) {
23332333
onClientStreamBodySentChannel.publish({ stream: this });
@@ -2741,8 +2741,7 @@ function doSendFD(session, options, fd, headers, streamOptions, err, stat) {
27412741
// response is canceled. The user code may also send a separate type
27422742
// of response so check again for the HEADERS_SENT flag
27432743
if ((typeof options.statCheck === 'function' &&
2744-
ReflectApply(options.statCheck, this,
2745-
[stat, headers, statOptions]) === false) ||
2744+
options.statCheck.call(this, stat, headers, statOptions) === false) ||
27462745
(this[kState].flags & STREAM_FLAGS_HEADERS_SENT)) {
27472746
return;
27482747
}
@@ -2801,7 +2800,7 @@ function doSendFileFD(session, options, fd, headers, streamOptions, err, stat) {
28012800
// response is canceled. The user code may also send a separate type
28022801
// of response so check again for the HEADERS_SENT flag
28032802
if ((typeof options.statCheck === 'function' &&
2804-
ReflectApply(options.statCheck, this, [stat, headers]) === false) ||
2803+
options.statCheck.call(this, stat, headers) === false) ||
28052804
(this[kState].flags & STREAM_FLAGS_HEADERS_SENT)) {
28062805
tryClose(fd);
28072806
return;
@@ -3633,9 +3632,9 @@ function getUnpackedSettings(buf, options = kEmptyObject) {
36333632
const settings = {};
36343633
let offset = 0;
36353634
while (offset < buf.length) {
3636-
const id = ReflectApply(readUInt16BE, buf, [offset]);
3635+
const id = readUInt16BE.call(buf, offset);
36373636
offset += 2;
3638-
const value = ReflectApply(readUInt32BE, buf, [offset]);
3637+
const value = readUInt32BE.call(buf, offset);
36393638
switch (id) {
36403639
case NGHTTP2_SETTINGS_HEADER_TABLE_SIZE:
36413640
settings.headerTableSize = value;

lib/zlib.js

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ const {
3131
ObjectFreeze,
3232
ObjectKeys,
3333
ObjectSetPrototypeOf,
34-
ReflectApply,
3534
Symbol,
3635
Uint32Array,
3736
} = primordials;
@@ -255,7 +254,7 @@ function ZlibBase(opts, mode, handle, { flush, finishFlush, fullFlush }) {
255254
}
256255
}
257256

258-
ReflectApply(Transform, this, [{ autoDestroy: true, ...opts }]);
257+
Transform.call(this, { autoDestroy: true, ...opts });
259258
this[kError] = null;
260259
this.bytesWritten = 0;
261260
this._handle = handle;
@@ -681,7 +680,7 @@ function Zlib(opts, mode) {
681680
processCallback,
682681
dictionary);
683682

684-
ReflectApply(ZlibBase, this, [opts, mode, handle, zlibDefaultOpts]);
683+
ZlibBase.call(this, opts, mode, handle, zlibDefaultOpts);
685684

686685
this._level = level;
687686
this._strategy = strategy;
@@ -724,7 +723,7 @@ function Deflate(opts) {
724723
if (!(this instanceof Deflate)) {
725724
return deprecateInstantiation(Deflate, 'DEP0184', opts);
726725
}
727-
ReflectApply(Zlib, this, [opts, DEFLATE]);
726+
Zlib.call(this, opts, DEFLATE);
728727
}
729728
ObjectSetPrototypeOf(Deflate.prototype, Zlib.prototype);
730729
ObjectSetPrototypeOf(Deflate, Zlib);
@@ -733,7 +732,7 @@ function Inflate(opts) {
733732
if (!(this instanceof Inflate)) {
734733
return deprecateInstantiation(Inflate, 'DEP0184', opts);
735734
}
736-
ReflectApply(Zlib, this, [opts, INFLATE]);
735+
Zlib.call(this, opts, INFLATE);
737736
}
738737
ObjectSetPrototypeOf(Inflate.prototype, Zlib.prototype);
739738
ObjectSetPrototypeOf(Inflate, Zlib);
@@ -742,7 +741,7 @@ function Gzip(opts) {
742741
if (!(this instanceof Gzip)) {
743742
return deprecateInstantiation(Gzip, 'DEP0184', opts);
744743
}
745-
ReflectApply(Zlib, this, [opts, GZIP]);
744+
Zlib.call(this, opts, GZIP);
746745
}
747746
ObjectSetPrototypeOf(Gzip.prototype, Zlib.prototype);
748747
ObjectSetPrototypeOf(Gzip, Zlib);
@@ -751,7 +750,7 @@ function Gunzip(opts) {
751750
if (!(this instanceof Gunzip)) {
752751
return deprecateInstantiation(Gunzip, 'DEP0184', opts);
753752
}
754-
ReflectApply(Zlib, this, [opts, GUNZIP]);
753+
Zlib.call(this, opts, GUNZIP);
755754
}
756755
ObjectSetPrototypeOf(Gunzip.prototype, Zlib.prototype);
757756
ObjectSetPrototypeOf(Gunzip, Zlib);
@@ -761,7 +760,7 @@ function DeflateRaw(opts) {
761760
if (!(this instanceof DeflateRaw)) {
762761
return deprecateInstantiation(DeflateRaw, 'DEP0184', opts);
763762
}
764-
ReflectApply(Zlib, this, [opts, DEFLATERAW]);
763+
Zlib.call(this, opts, DEFLATERAW);
765764
}
766765
ObjectSetPrototypeOf(DeflateRaw.prototype, Zlib.prototype);
767766
ObjectSetPrototypeOf(DeflateRaw, Zlib);
@@ -770,7 +769,7 @@ function InflateRaw(opts) {
770769
if (!(this instanceof InflateRaw)) {
771770
return deprecateInstantiation(InflateRaw, 'DEP0184', opts);
772771
}
773-
ReflectApply(Zlib, this, [opts, INFLATERAW]);
772+
Zlib.call(this, opts, INFLATERAW);
774773
}
775774
ObjectSetPrototypeOf(InflateRaw.prototype, Zlib.prototype);
776775
ObjectSetPrototypeOf(InflateRaw, Zlib);
@@ -779,7 +778,7 @@ function Unzip(opts) {
779778
if (!(this instanceof Unzip)) {
780779
return deprecateInstantiation(Unzip, 'DEP0184', opts);
781780
}
782-
ReflectApply(Zlib, this, [opts, UNZIP]);
781+
Zlib.call(this, opts, UNZIP);
783782
}
784783
ObjectSetPrototypeOf(Unzip.prototype, Zlib.prototype);
785784
ObjectSetPrototypeOf(Unzip, Zlib);
@@ -837,7 +836,7 @@ function Brotli(opts, mode) {
837836
this._writeState = new Uint32Array(2);
838837
handle.init(brotliInitParamsArray, this._writeState, processCallback);
839838

840-
ReflectApply(ZlibBase, this, [opts, mode, handle, brotliDefaultOpts]);
839+
ZlibBase.call(this, opts, mode, handle, brotliDefaultOpts);
841840
}
842841
ObjectSetPrototypeOf(Brotli.prototype, Zlib.prototype);
843842
ObjectSetPrototypeOf(Brotli, Zlib);
@@ -846,7 +845,7 @@ function BrotliCompress(opts) {
846845
if (!(this instanceof BrotliCompress)) {
847846
return deprecateInstantiation(BrotliCompress, 'DEP0184', opts);
848847
}
849-
ReflectApply(Brotli, this, [opts, BROTLI_ENCODE]);
848+
Brotli.call(this, opts, BROTLI_ENCODE);
850849
}
851850
ObjectSetPrototypeOf(BrotliCompress.prototype, Brotli.prototype);
852851
ObjectSetPrototypeOf(BrotliCompress, Brotli);
@@ -855,7 +854,7 @@ function BrotliDecompress(opts) {
855854
if (!(this instanceof BrotliDecompress)) {
856855
return deprecateInstantiation(BrotliDecompress, 'DEP0184', opts);
857856
}
858-
ReflectApply(Brotli, this, [opts, BROTLI_DECODE]);
857+
Brotli.call(this, opts, BROTLI_DECODE);
859858
}
860859
ObjectSetPrototypeOf(BrotliDecompress.prototype, Brotli.prototype);
861860
ObjectSetPrototypeOf(BrotliDecompress, Brotli);

0 commit comments

Comments
 (0)