11
11
// message may change, the code should not.
12
12
13
13
const {
14
+ ArrayFrom,
14
15
ArrayIsArray,
16
+ ArrayPrototypeIncludes,
17
+ ArrayPrototypeIndexOf,
18
+ ArrayPrototypeJoin,
19
+ ArrayPrototypeMap,
20
+ ArrayPrototypePop,
21
+ ArrayPrototypePush,
22
+ ArrayPrototypeSlice,
23
+ ArrayPrototypeSplice,
24
+ ArrayPrototypeUnshift,
15
25
Error,
16
26
ErrorCaptureStackTrace,
17
27
ErrorPrototypeToString,
18
28
JSONStringify,
19
- Map,
20
29
MathAbs,
21
30
MathMax,
31
+ Number,
22
32
NumberIsInteger,
23
33
ObjectDefineProperty,
24
34
ObjectKeys,
25
35
RangeError,
36
+ ReflectApply,
37
+ RegExpPrototypeTest,
38
+ SafeMap,
39
+ SafeWeakMap,
26
40
String,
41
+ StringPrototypeEndsWith,
42
+ StringPrototypeIncludes,
43
+ StringPrototypeSlice,
44
+ StringPrototypeSplit,
27
45
StringPrototypeStartsWith,
46
+ StringPrototypeToLowerCase,
28
47
Symbol,
29
48
SymbolFor,
30
49
SyntaxError,
31
50
TypeError,
32
51
URIError,
33
- WeakMap,
34
52
} = primordials ;
35
53
36
54
const isWindows = process . platform === 'win32' ;
37
55
38
- const messages = new Map ( ) ;
56
+ const messages = new SafeMap ( ) ;
39
57
const codes = { } ;
40
58
41
59
const classRegExp = / ^ ( [ A - Z ] [ a - z 0 - 9 ] * ) + $ / ;
@@ -54,7 +72,7 @@ const kTypes = [
54
72
] ;
55
73
56
74
const MainContextError = Error ;
57
- const overrideStackTrace = new WeakMap ( ) ;
75
+ const overrideStackTrace = new SafeWeakMap ( ) ;
58
76
const kNoOverride = Symbol ( 'kNoOverride' ) ;
59
77
const prepareStackTrace = ( globalThis , error , trace ) => {
60
78
// API for node internals to override error stack formatting
@@ -370,8 +388,8 @@ function getMessage(key, args, self) {
370
388
if ( args . length === 0 )
371
389
return msg ;
372
390
373
- args . unshift ( msg ) ;
374
- return lazyInternalUtilInspect ( ) . format . apply ( null , args ) ;
391
+ ArrayPrototypeUnshift ( args , msg ) ;
392
+ return ReflectApply ( lazyInternalUtilInspect ( ) . format , null , args ) ;
375
393
}
376
394
377
395
let uvBinding ;
@@ -644,9 +662,9 @@ function addNumericalSeparator(val) {
644
662
let i = val . length ;
645
663
const start = val [ 0 ] === '-' ? 1 : 0 ;
646
664
for ( ; i >= start + 4 ; i -= 3 ) {
647
- res = `_${ val . slice ( i - 3 , i ) } ${ res } ` ;
665
+ res = `_${ StringPrototypeSlice ( val , i - 3 , i ) } ${ res } ` ;
648
666
}
649
- return `${ val . slice ( 0 , i ) } ${ res } ` ;
667
+ return `${ StringPrototypeSlice ( val , 0 , i ) } ${ res } ` ;
650
668
}
651
669
652
670
// Used to enhance the stack that will be picked up by the inspector
@@ -681,7 +699,8 @@ const fatalExceptionStackEnhancers = {
681
699
// ANSI escape sequences is not reliable.
682
700
if ( process . platform === 'win32' ) {
683
701
const info = internalBinding ( 'os' ) . getOSInformation ( ) ;
684
- const ver = info [ 2 ] . split ( '.' ) . map ( ( a ) => + a ) ;
702
+ const ver = ArrayPrototypeMap ( StringPrototypeSplit ( info [ 2 ] , '.' ) ,
703
+ Number ) ;
685
704
if ( ver [ 0 ] !== 10 || ver [ 2 ] < 14393 ) {
686
705
useColors = false ;
687
706
}
@@ -975,11 +994,11 @@ E('ERR_INVALID_ARG_TYPE',
975
994
}
976
995
977
996
let msg = 'The ' ;
978
- if ( name . endsWith ( ' argument' ) ) {
997
+ if ( StringPrototypeEndsWith ( name , ' argument' ) ) {
979
998
// For cases like 'first argument'
980
999
msg += `${ name } ` ;
981
1000
} else {
982
- const type = name . includes ( '.' ) ? 'property' : 'argument' ;
1001
+ const type = StringPrototypeIncludes ( name , '.' ) ? 'property' : 'argument' ;
983
1002
msg += `"${ name } " ${ type } ` ;
984
1003
}
985
1004
msg += 'must be ' ;
@@ -991,31 +1010,31 @@ E('ERR_INVALID_ARG_TYPE',
991
1010
for ( const value of expected ) {
992
1011
assert ( typeof value === 'string' ,
993
1012
'All expected entries have to be of type string' ) ;
994
- if ( kTypes . includes ( value ) ) {
995
- types . push ( value . toLowerCase ( ) ) ;
996
- } else if ( classRegExp . test ( value ) ) {
997
- instances . push ( value ) ;
1013
+ if ( ArrayPrototypeIncludes ( kTypes , value ) ) {
1014
+ ArrayPrototypePush ( types , StringPrototypeToLowerCase ( value ) ) ;
1015
+ } else if ( RegExpPrototypeTest ( classRegExp , value ) ) {
1016
+ ArrayPrototypePush ( instances , value ) ;
998
1017
} else {
999
1018
assert ( value !== 'object' ,
1000
1019
'The value "object" should be written as "Object"' ) ;
1001
- other . push ( value ) ;
1020
+ ArrayPrototypePush ( other , value ) ;
1002
1021
}
1003
1022
}
1004
1023
1005
1024
// Special handle `object` in case other instances are allowed to outline
1006
1025
// the differences between each other.
1007
1026
if ( instances . length > 0 ) {
1008
- const pos = types . indexOf ( 'object' ) ;
1027
+ const pos = ArrayPrototypeIndexOf ( types , 'object' ) ;
1009
1028
if ( pos !== - 1 ) {
1010
- types . splice ( pos , 1 ) ;
1011
- instances . push ( 'Object' ) ;
1029
+ ArrayPrototypeSplice ( types , pos , 1 ) ;
1030
+ ArrayPrototypePush ( instances , 'Object' ) ;
1012
1031
}
1013
1032
}
1014
1033
1015
1034
if ( types . length > 0 ) {
1016
1035
if ( types . length > 2 ) {
1017
- const last = types . pop ( ) ;
1018
- msg += `one of type ${ types . join ( ', ' ) } , or ${ last } ` ;
1036
+ const last = ArrayPrototypePop ( types ) ;
1037
+ msg += `one of type ${ ArrayPrototypeJoin ( types , ', ' ) } , or ${ last } ` ;
1019
1038
} else if ( types . length === 2 ) {
1020
1039
msg += `one of type ${ types [ 0 ] } or ${ types [ 1 ] } ` ;
1021
1040
} else {
@@ -1027,8 +1046,9 @@ E('ERR_INVALID_ARG_TYPE',
1027
1046
1028
1047
if ( instances . length > 0 ) {
1029
1048
if ( instances . length > 2 ) {
1030
- const last = instances . pop ( ) ;
1031
- msg += `an instance of ${ instances . join ( ', ' ) } , or ${ last } ` ;
1049
+ const last = ArrayPrototypePop ( instances ) ;
1050
+ msg +=
1051
+ `an instance of ${ ArrayPrototypeJoin ( instances , ', ' ) } , or ${ last } ` ;
1032
1052
} else {
1033
1053
msg += `an instance of ${ instances [ 0 ] } ` ;
1034
1054
if ( instances . length === 2 ) {
@@ -1041,12 +1061,12 @@ E('ERR_INVALID_ARG_TYPE',
1041
1061
1042
1062
if ( other . length > 0 ) {
1043
1063
if ( other . length > 2 ) {
1044
- const last = other . pop ( ) ;
1045
- msg += `one of ${ other . join ( ', ' ) } , or ${ last } ` ;
1064
+ const last = ArrayPrototypePop ( other ) ;
1065
+ msg += `one of ${ ArrayPrototypeJoin ( other , ', ' ) } , or ${ last } ` ;
1046
1066
} else if ( other . length === 2 ) {
1047
1067
msg += `one of ${ other [ 0 ] } or ${ other [ 1 ] } ` ;
1048
1068
} else {
1049
- if ( other [ 0 ] . toLowerCase ( ) !== other [ 0 ] )
1069
+ if ( StringPrototypeToLowerCase ( other [ 0 ] ) !== other [ 0 ] )
1050
1070
msg += 'an ' ;
1051
1071
msg += `${ other [ 0 ] } ` ;
1052
1072
}
@@ -1068,17 +1088,17 @@ E('ERR_INVALID_ARG_TYPE',
1068
1088
let inspected = lazyInternalUtilInspect ( )
1069
1089
. inspect ( actual , { colors : false } ) ;
1070
1090
if ( inspected . length > 25 )
1071
- inspected = `${ inspected . slice ( 0 , 25 ) } ...` ;
1091
+ inspected = `${ StringPrototypeSlice ( inspected , 0 , 25 ) } ...` ;
1072
1092
msg += `. Received type ${ typeof actual } (${ inspected } )` ;
1073
1093
}
1074
1094
return msg ;
1075
1095
} , TypeError ) ;
1076
1096
E ( 'ERR_INVALID_ARG_VALUE' , ( name , value , reason = 'is invalid' ) => {
1077
1097
let inspected = lazyInternalUtilInspect ( ) . inspect ( value ) ;
1078
1098
if ( inspected . length > 128 ) {
1079
- inspected = `${ inspected . slice ( 0 , 128 ) } ...` ;
1099
+ inspected = `${ StringPrototypeSlice ( inspected , 0 , 128 ) } ...` ;
1080
1100
}
1081
- const type = name . includes ( '.' ) ? 'property' : 'argument' ;
1101
+ const type = StringPrototypeIncludes ( name , '.' ) ? 'property' : 'argument' ;
1082
1102
return `The ${ type } '${ name } ' ${ reason } . Received ${ inspected } ` ;
1083
1103
} , TypeError , RangeError ) ;
1084
1104
E ( 'ERR_INVALID_ASYNC_ID' , 'Invalid %s value: %s' , RangeError ) ;
@@ -1195,9 +1215,10 @@ E('ERR_MANIFEST_ASSERT_INTEGRITY',
1195
1215
moduleURL
1196
1216
} " does not match the expected integrity.`;
1197
1217
if ( realIntegrities . size ) {
1198
- const sri = [ ...realIntegrities . entries ( ) ] . map ( ( [ alg , dgs ] ) => {
1199
- return `${ alg } -${ dgs } ` ;
1200
- } ) . join ( ' ' ) ;
1218
+ const sri = ArrayPrototypeJoin (
1219
+ ArrayFrom ( realIntegrities . entries ( ) , ( [ alg , dgs ] ) => `${ alg } -${ dgs } ` ) ,
1220
+ ' '
1221
+ ) ;
1201
1222
msg += ` Integrities found are: ${ sri } ` ;
1202
1223
} else {
1203
1224
msg += ' The resource was not found in the policy.' ;
@@ -1225,8 +1246,11 @@ E('ERR_MISSING_ARGS',
1225
1246
let msg = 'The ' ;
1226
1247
const len = args . length ;
1227
1248
const wrap = ( a ) => `"${ a } "` ;
1228
- args = args . map (
1229
- ( a ) => ( ArrayIsArray ( a ) ? a . map ( wrap ) . join ( ' or ' ) : wrap ( a ) )
1249
+ args = ArrayPrototypeMap (
1250
+ args ,
1251
+ ( a ) => ( ArrayIsArray ( a ) ?
1252
+ ArrayPrototypeJoin ( ArrayPrototypeMap ( a , wrap ) , ' or ' ) :
1253
+ wrap ( a ) )
1230
1254
) ;
1231
1255
switch ( len ) {
1232
1256
case 1 :
@@ -1236,7 +1260,7 @@ E('ERR_MISSING_ARGS',
1236
1260
msg += `${ args [ 0 ] } and ${ args [ 1 ] } arguments` ;
1237
1261
break ;
1238
1262
default :
1239
- msg += args . slice ( 0 , len - 1 ) . join ( ', ' ) ;
1263
+ msg += ArrayPrototypeJoin ( ArrayPrototypeSlice ( args , 0 , len - 1 ) , ', ' ) ;
1240
1264
msg += `, and ${ args [ len - 1 ] } arguments` ;
1241
1265
break ;
1242
1266
}
@@ -1299,9 +1323,10 @@ E('ERR_QUIC_INVALID_TLS_SESSION_TICKET',
1299
1323
'Invalid TLS session ticket' , Error ) ;
1300
1324
E ( 'ERR_QUIC_VERSION_NEGOTIATION' ,
1301
1325
( version , requestedVersions , supportedVersions ) => {
1326
+ const requestedVersionsString = ArrayPrototypeJoin ( requestedVersions , ', ' ) ;
1302
1327
return 'QUIC session received version negotiation from server. ' +
1303
- `Version: ${ version } . Requested: ${ requestedVersions . join ( ', ' ) } ` +
1304
- `Supported: ${ supportedVersions . join ( ', ' ) } ` ;
1328
+ `Version: ${ version } . Requested: ${ requestedVersionsString } ` +
1329
+ `Supported: ${ ArrayPrototypeJoin ( supportedVersions , ', ' ) } ` ;
1305
1330
} ,
1306
1331
Error ) ;
1307
1332
E ( 'ERR_REQUIRE_ESM' ,
@@ -1447,18 +1472,18 @@ E('ERR_VM_MODULE_STATUS', 'Module status %s', Error);
1447
1472
E ( 'ERR_WASI_ALREADY_STARTED' , 'WASI instance has already started' , Error ) ;
1448
1473
E ( 'ERR_WORKER_INIT_FAILED' , 'Worker initialization failure: %s' , Error ) ;
1449
1474
E ( 'ERR_WORKER_INVALID_EXEC_ARGV' , ( errors , msg = 'invalid execArgv flags' ) =>
1450
- `Initiated Worker with ${ msg } : ${ errors . join ( ', ' ) } ` ,
1475
+ `Initiated Worker with ${ msg } : ${ ArrayPrototypeJoin ( errors , ', ' ) } ` ,
1451
1476
Error ) ;
1452
1477
E ( 'ERR_WORKER_NOT_RUNNING' , 'Worker instance not running' , Error ) ;
1453
1478
E ( 'ERR_WORKER_OUT_OF_MEMORY' ,
1454
1479
'Worker terminated due to reaching memory limit: %s' , Error ) ;
1455
1480
E ( 'ERR_WORKER_PATH' , ( filename ) =>
1456
1481
'The worker script or module filename must be an absolute path or a ' +
1457
1482
'relative path starting with \'./\' or \'../\'.' +
1458
- ( filename . startsWith ( 'file://' ) ?
1483
+ ( StringPrototypeStartsWith ( filename , 'file://' ) ?
1459
1484
' Wrap file:// URLs with `new URL`.' : ''
1460
1485
) +
1461
- ( filename . startsWith ( 'data:text/javascript' ) ?
1486
+ ( StringPrototypeStartsWith ( filename , 'data:text/javascript' ) ?
1462
1487
' Wrap data: URLs with `new URL`.' : ''
1463
1488
) +
1464
1489
` Received "${ filename } "` ,
0 commit comments