Skip to content

Commit b273664

Browse files
LiviaMedeirosRafaelGSS
authored andcommitted
http2,zlib: prefer call() over apply() if argument list is not array
PR-URL: #60834 Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 550e8a7 commit b273664

3 files changed

Lines changed: 19 additions & 22 deletions

File tree

‎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
consterr=handle.shutdown(req);
19621962
if(err===1)// synchronous finish
1963-
returnReflectApply(afterShutdown,req,[0]);
1963+
returnafterShutdown.call(req,0);
19641964
}
19651965

19661966
functionfinishSendTrailers(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((typeofoptions.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((typeofoptions.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
constsettings={};
36343633
letoffset=0;
36353634
while(offset<buf.length){
3636-
constid=ReflectApply(readUInt16BE,buf,[offset]);
3635+
constid=readUInt16BE.call(buf,offset);
36373636
offset+=2;
3638-
constvalue=ReflectApply(readUInt32BE,buf,[offset]);
3637+
constvalue=readUInt32BE.call(buf,offset);
36393638
switch(id){
36403639
caseNGHTTP2_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(!(thisinstanceofDeflate)){
725724
returndeprecateInstantiation(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(!(thisinstanceofInflate)){
734733
returndeprecateInstantiation(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(!(thisinstanceofGzip)){
743742
returndeprecateInstantiation(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(!(thisinstanceofGunzip)){
752751
returndeprecateInstantiation(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(!(thisinstanceofDeflateRaw)){
762761
returndeprecateInstantiation(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(!(thisinstanceofInflateRaw)){
771770
returndeprecateInstantiation(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(!(thisinstanceofUnzip)){
780779
returndeprecateInstantiation(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=newUint32Array(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(!(thisinstanceofBrotliCompress)){
847846
returndeprecateInstantiation(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(!(thisinstanceofBrotliDecompress)){
856855
returndeprecateInstantiation(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)