Skip to content

Commit 2979113

Browse files
LiviaMedeirosRafaelGSS
authored andcommitted
lib: prefer call() over apply() if argument list is not array
PR-URL: #60796 Reviewed-By: René <contact.9a5d6388@renegade334.me.uk> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 1c38f80 commit 2979113

23 files changed

Lines changed: 75 additions & 82 deletions

‎lib/assert.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ const {
2727
ArrayPrototypePush,
2828
ArrayPrototypeSlice,
2929
Error,
30+
FunctionPrototypeCall,
3031
NumberIsNaN,
3132
ObjectAssign,
3233
ObjectDefineProperty,
3334
ObjectIs,
3435
ObjectKeys,
3536
ObjectPrototypeIsPrototypeOf,
36-
ReflectApply,
3737
RegExpPrototypeExec,
3838
String,
3939
StringPrototypeIndexOf,
@@ -550,7 +550,7 @@ function expectedException(actual, expected, message, fn) {
550550
throwError=true;
551551
}else{
552552
// Check validation functions return value.
553-
constres=ReflectApply(expected,{},[actual]);
553+
constres=FunctionPrototypeCall(expected,{},actual);
554554
if(res!==true){
555555
if(!message){
556556
generatedMessage=true;
@@ -695,7 +695,7 @@ function hasMatchingError(actual, expected) {
695695
if(ObjectPrototypeIsPrototypeOf(Error,expected)){
696696
returnfalse;
697697
}
698-
returnReflectApply(expected,{},[actual])===true;
698+
returnFunctionPrototypeCall(expected,{},actual)===true;
699699
}
700700

701701
functionexpectsNoError(stackStartFn,actual,error,message){

‎lib/dgram.js‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ const {
2929
FunctionPrototypeCall,
3030
ObjectDefineProperty,
3131
ObjectSetPrototypeOf,
32-
ReflectApply,
3332
SymbolAsyncDispose,
3433
SymbolDispose,
3534
}=primordials;
@@ -436,7 +435,7 @@ Socket.prototype.connect = function(port, address, callback) {
436435
return;
437436
}
438437

439-
ReflectApply(_connect,this,[port,address,callback]);
438+
FunctionPrototypeCall(_connect,this,port,address,callback);
440439
};
441440

442441

‎lib/fs.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const {
2929
ArrayPrototypePush,
3030
BigIntPrototypeToString,
3131
Boolean,
32+
FunctionPrototypeCall,
3233
MathMax,
3334
Number,
3435
ObjectDefineProperties,
@@ -365,7 +366,7 @@ function readFile(path, options, callback) {
365366
}
366367
if(context.isUserFd){
367368
process.nextTick(functiontick(context){
368-
ReflectApply(readFileAfterOpen,{ context },[null,path]);
369+
FunctionPrototypeCall(readFileAfterOpen,{ context },null,path);
369370
},context);
370371
return;
371372
}

‎lib/internal/child_process.js‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -805,8 +805,7 @@ function setupChannel(target, channel, serializationMode) {
805805
obj=handleConversion[message.type];
806806

807807
// convert TCP object to native handle object
808-
handle=ReflectApply(handleConversion[message.type].send,
809-
target,[message,handle,options]);
808+
handle=FunctionPrototypeCall(handleConversion[message.type].send,target,message,handle,options);
810809

811810
// If handle was sent twice, or it is impossible to get native handle
812811
// out of it - just send a text without the handle.

‎lib/internal/cluster/child.js‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
const{
44
ArrayPrototypeJoin,
55
FunctionPrototype,
6+
FunctionPrototypeCall,
67
ObjectAssign,
78
ReflectApply,
89
SafeMap,
@@ -58,7 +59,7 @@ cluster._setupWorker = function() {
5859
if(message.act==='newconn')
5960
onconnection(message,handle);
6061
elseif(message.act==='disconnect')
61-
ReflectApply(_disconnect,worker,[true]);
62+
FunctionPrototypeCall(_disconnect,worker,true);
6263
}
6364
};
6465

@@ -287,7 +288,7 @@ function _disconnect(primaryInitiated) {
287288
Worker.prototype.disconnect=function(){
288289
if(this.state!=='disconnecting'&&this.state!=='destroying'){
289290
this.state='disconnecting';
290-
ReflectApply(_disconnect,this,[]);
291+
FunctionPrototypeCall(_disconnect,this);
291292
}
292293

293294
returnthis;

‎lib/internal/cluster/worker.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
const{
4+
FunctionPrototypeCall,
45
ObjectSetPrototypeOf,
56
ReflectApply,
67
}=primordials;
@@ -16,7 +17,7 @@ function Worker(options) {
1617
if(!(thisinstanceofWorker))
1718
returnnewWorker(options);
1819

19-
ReflectApply(EventEmitter,this,[]);
20+
FunctionPrototypeCall(EventEmitter,this);
2021

2122
if(options===null||typeofoptions!=='object')
2223
options=kEmptyObject;

‎lib/internal/crypto/cipher.js‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
'use strict';
22

33
const{
4+
FunctionPrototypeCall,
45
NumberIsInteger,
56
ObjectSetPrototypeOf,
6-
ReflectApply,
77
}=primordials;
88

99
const{
@@ -117,15 +117,15 @@ function createCipherBase(cipher, credential, options, isEncrypt, iv) {
117117
this[kHandle]=newCipherBase(isEncrypt,cipher,credential,iv,authTagLength);
118118
this._decoder=null;
119119

120-
ReflectApply(LazyTransform,this,[options]);
120+
FunctionPrototypeCall(LazyTransform,this,options);
121121
}
122122

123123
functioncreateCipherWithIV(cipher,key,options,isEncrypt,iv){
124124
validateString(cipher,'cipher');
125125
constencoding=getStringOption(options,'encoding');
126126
key=prepareSecretKey(key,encoding);
127127
iv=iv===null ? null : getArrayBufferOrView(iv,'iv');
128-
ReflectApply(createCipherBase,this,[cipher,key,options,isEncrypt,iv]);
128+
FunctionPrototypeCall(createCipherBase,this,cipher,key,options,isEncrypt,iv);
129129
}
130130

131131
// The Cipher class is part of the legacy Node.js crypto API. It exposes
@@ -215,7 +215,7 @@ function Cipheriv(cipher, key, iv, options) {
215215
if(!(thisinstanceofCipheriv))
216216
returnnewCipheriv(cipher,key,iv,options);
217217

218-
ReflectApply(createCipherWithIV,this,[cipher,key,options,true,iv]);
218+
FunctionPrototypeCall(createCipherWithIV,this,cipher,key,options,true,iv);
219219
}
220220

221221
functionaddCipherPrototypeFunctions(constructor){
@@ -244,7 +244,7 @@ function Decipheriv(cipher, key, iv, options) {
244244
if(!(thisinstanceofDecipheriv))
245245
returnnewDecipheriv(cipher,key,iv,options);
246246

247-
ReflectApply(createCipherWithIV,this,[cipher,key,options,false,iv]);
247+
FunctionPrototypeCall(createCipherWithIV,this,cipher,key,options,false,iv);
248248
}
249249

250250
ObjectSetPrototypeOf(Decipheriv.prototype,LazyTransform.prototype);

‎lib/internal/crypto/hash.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
'use strict';
22

33
const{
4+
FunctionPrototypeCall,
45
ObjectSetPrototypeOf,
5-
ReflectApply,
66
StringPrototypeReplace,
77
StringPrototypeToLowerCase,
88
Symbol,
@@ -105,7 +105,7 @@ function Hash(algorithm, options) {
105105
if(!isCopy&&xofLen===undefined){
106106
maybeEmitDeprecationWarning(algorithm);
107107
}
108-
ReflectApply(LazyTransform,this,[options]);
108+
FunctionPrototypeCall(LazyTransform,this,options);
109109
}
110110

111111
ObjectSetPrototypeOf(Hash.prototype,LazyTransform.prototype);
@@ -169,7 +169,7 @@ function Hmac(hmac, key, options) {
169169
this[kState]={
170170
[kFinalized]: false,
171171
};
172-
ReflectApply(LazyTransform,this,[options]);
172+
FunctionPrototypeCall(LazyTransform,this,options);
173173
}
174174

175175
ObjectSetPrototypeOf(Hmac.prototype,LazyTransform.prototype);

‎lib/internal/crypto/sig.js‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
const{
44
FunctionPrototypeCall,
55
ObjectSetPrototypeOf,
6-
ReflectApply,
76
}=primordials;
87

98
const{
@@ -59,7 +58,7 @@ function Sign(algorithm, options) {
5958
this[kHandle]=new_Sign();
6059
this[kHandle].init(algorithm);
6160

62-
ReflectApply(Writable,this,[options]);
61+
FunctionPrototypeCall(Writable,this,options);
6362
}
6463

6564
ObjectSetPrototypeOf(Sign.prototype,Writable.prototype);
@@ -219,7 +218,7 @@ function Verify(algorithm, options) {
219218
this[kHandle]=new_Verify();
220219
this[kHandle].init(algorithm);
221220

222-
ReflectApply(Writable,this,[options]);
221+
FunctionPrototypeCall(Writable,this,options);
223222
}
224223

225224
ObjectSetPrototypeOf(Verify.prototype,Writable.prototype);

‎lib/internal/crypto/webcrypto.js‎

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const{
44
ArrayPrototypeIncludes,
5+
FunctionPrototypeCall,
56
JSONParse,
67
JSONStringify,
78
ObjectDefineProperties,
@@ -84,7 +85,7 @@ async function digest(algorithm, data) {
8485

8586
algorithm=normalizeAlgorithm(algorithm,'digest');
8687

87-
returnawaitReflectApply(asyncDigest,this,[algorithm,data]);
88+
returnawaitFunctionPrototypeCall(asyncDigest,this,algorithm,data);
8889
}
8990

9091
functionrandomUUID(){
@@ -377,10 +378,10 @@ async function deriveKey(
377378
throwlazyDOMException('Unrecognized algorithm name','NotSupportedError');
378379
}
379380

380-
returnReflectApply(
381+
returnFunctionPrototypeCall(
381382
importKeySync,
382383
this,
383-
['raw-secret',bits,derivedKeyAlgorithm,extractable,keyUsages],
384+
'raw-secret',bits,derivedKeyAlgorithm,extractable,keyUsages,
384385
);
385386
}
386387

@@ -889,10 +890,10 @@ async function importKey(
889890

890891
algorithm=normalizeAlgorithm(algorithm,'importKey');
891892

892-
returnReflectApply(
893+
returnFunctionPrototypeCall(
893894
importKeySync,
894895
this,
895-
[format,keyData,algorithm,extractable,keyUsages],
896+
format,keyData,algorithm,extractable,keyUsages,
896897
);
897898
}
898899

@@ -926,7 +927,7 @@ async function wrapKey(format, key, wrappingKey, algorithm) {
926927
}catch{
927928
algorithm=normalizeAlgorithm(algorithm,'encrypt');
928929
}
929-
letkeyData=awaitReflectApply(exportKey,this,[format,key]);
930+
letkeyData=awaitFunctionPrototypeCall(exportKey,this,format,key);
930931

931932
if(format==='jwk'){
932933
constec=newTextEncoder();
@@ -1023,10 +1024,10 @@ async function unwrapKey(
10231024
}
10241025
}
10251026

1026-
returnReflectApply(
1027+
returnFunctionPrototypeCall(
10271028
importKeySync,
10281029
this,
1029-
[format,keyData,unwrappedKeyAlgo,extractable,keyUsages],
1030+
format,keyData,unwrappedKeyAlgo,extractable,keyUsages,
10301031
);
10311032
}
10321033

@@ -1349,10 +1350,10 @@ async function encapsulateKey(encapsulationAlgorithm, encapsulationKey, sharedKe
13491350
throwlazyDOMException('Unrecognized algorithm name','NotSupportedError');
13501351
}
13511352

1352-
constsharedKey=ReflectApply(
1353+
constsharedKey=FunctionPrototypeCall(
13531354
importKeySync,
13541355
this,
1355-
['raw-secret',encapsulateBits.sharedKey,normalizedSharedKeyAlgorithm,extractable,usages],
1356+
'raw-secret',encapsulateBits.sharedKey,normalizedSharedKeyAlgorithm,extractable,usages,
13561357
);
13571358

13581359
constencapsulatedKey={
@@ -1469,10 +1470,10 @@ async function decapsulateKey(
14691470
throwlazyDOMException('Unrecognized algorithm name','NotSupportedError');
14701471
}
14711472

1472-
returnReflectApply(
1473+
returnFunctionPrototypeCall(
14731474
importKeySync,
14741475
this,
1475-
['raw-secret',decapsulatedBits,normalizedSharedKeyAlgorithm,extractable,usages],
1476+
'raw-secret',decapsulatedBits,normalizedSharedKeyAlgorithm,extractable,usages,
14761477
);
14771478
}
14781479

0 commit comments

Comments
 (0)