2424const {
2525 Array,
2626 ArrayIsArray,
27- ArrayPrototypeForEach,
28- ArrayPrototypeIncludes,
29- ArrayPrototypeJoin,
30- ArrayPrototypePush,
31- ArrayPrototypeReduce,
32- ArrayPrototypeSome,
3327 JSONParse,
3428 ObjectDefineProperty,
3529 ObjectFreeze,
36- RegExpPrototypeExec,
37- RegExpPrototypeSymbolReplace,
3830 StringFromCharCode,
39- StringPrototypeCharCodeAt,
40- StringPrototypeEndsWith,
41- StringPrototypeIncludes,
42- StringPrototypeIndexOf,
43- StringPrototypeSlice,
44- StringPrototypeSplit,
45- StringPrototypeStartsWith,
46- StringPrototypeSubstring,
4731} = primordials ;
4832
4933const {
@@ -122,7 +106,7 @@ ObjectDefineProperty(exports, 'rootCertificates', {
122106// ("\x06spdy/2\x08http/1.1\x08http/1.0")
123107function convertProtocols ( protocols ) {
124108 const lens = new Array ( protocols . length ) ;
125- const buff = Buffer . allocUnsafe ( ArrayPrototypeReduce ( protocols , ( p , c , i ) => {
109+ const buff = Buffer . allocUnsafe ( protocols . reduce ( ( p , c , i ) => {
126110 const len = Buffer . byteLength ( c ) ;
127111 if ( len > 255 ) {
128112 throw new ERR_OUT_OF_RANGE ( 'The byte length of the protocol at index ' +
@@ -158,20 +142,17 @@ exports.convertALPNProtocols = function convertALPNProtocols(protocols, out) {
158142} ;
159143
160144function unfqdn ( host ) {
161- return RegExpPrototypeSymbolReplace ( / [ . ] $ / , host , '' ) ;
145+ return host . replace ( / [ . ] $ / , '' ) ;
162146}
163147
164148// String#toLowerCase() is locale-sensitive so we use
165149// a conservative version that only lowercases A-Z.
166150function toLowerCase ( c ) {
167- return StringFromCharCode ( 32 + StringPrototypeCharCodeAt ( c , 0 ) ) ;
151+ return StringFromCharCode ( 32 + c . charCodeAt ( 0 ) ) ;
168152}
169153
170154function splitHost ( host ) {
171- return StringPrototypeSplit (
172- RegExpPrototypeSymbolReplace ( / [ A - Z ] / g, unfqdn ( host ) , toLowerCase ) ,
173- '.' ,
174- ) ;
155+ return unfqdn ( host ) . replace ( / [ A - Z ] / g, toLowerCase ) . split ( '.' ) ;
175156}
176157
177158function check ( hostParts , pattern , wildcards ) {
@@ -185,15 +166,15 @@ function check(hostParts, pattern, wildcards) {
185166 return false ;
186167
187168 // Pattern has empty components, e.g. "bad..example.com".
188- if ( ArrayPrototypeIncludes ( patternParts , '' ) )
169+ if ( patternParts . includes ( '' ) )
189170 return false ;
190171
191172 // RFC 6125 allows IDNA U-labels (Unicode) in names but we have no
192173 // good way to detect their encoding or normalize them so we simply
193174 // reject them. Control characters and blanks are rejected as well
194175 // because nothing good can come from accepting them.
195- const isBad = ( s ) => RegExpPrototypeExec ( / [ ^ \u0021 - \u007F ] / u, s ) !== null ;
196- if ( ArrayPrototypeSome ( patternParts , isBad ) )
176+ const isBad = ( s ) => / [ ^ \u0021 - \u007F ] / u. test ( s ) ;
177+ if ( patternParts . some ( isBad ) )
197178 return false ;
198179
199180 // Check host parts from right to left first.
@@ -204,13 +185,13 @@ function check(hostParts, pattern, wildcards) {
204185
205186 const hostSubdomain = hostParts [ 0 ] ;
206187 const patternSubdomain = patternParts [ 0 ] ;
207- const patternSubdomainParts = StringPrototypeSplit ( patternSubdomain , '*' ) ;
188+ const patternSubdomainParts = patternSubdomain . split ( '*' ) ;
208189
209190 // Short-circuit when the subdomain does not contain a wildcard.
210191 // RFC 6125 does not allow wildcard substitution for components
211192 // containing IDNA A-labels (Punycode) so match those verbatim.
212193 if ( patternSubdomainParts . length === 1 ||
213- StringPrototypeIncludes ( patternSubdomain , 'xn--' ) )
194+ patternSubdomain . includes ( 'xn--' ) )
214195 return hostSubdomain === patternSubdomain ;
215196
216197 if ( ! wildcards )
@@ -229,10 +210,10 @@ function check(hostParts, pattern, wildcards) {
229210 if ( prefix . length + suffix . length > hostSubdomain . length )
230211 return false ;
231212
232- if ( ! StringPrototypeStartsWith ( hostSubdomain , prefix ) )
213+ if ( ! hostSubdomain . startsWith ( prefix ) )
233214 return false ;
234215
235- if ( ! StringPrototypeEndsWith ( hostSubdomain , suffix ) )
216+ if ( ! hostSubdomain . endsWith ( suffix ) )
236217 return false ;
237218
238219 return true ;
@@ -250,30 +231,29 @@ function splitEscapedAltNames(altNames) {
250231 let currentToken = '' ;
251232 let offset = 0 ;
252233 while ( offset !== altNames . length ) {
253- const nextSep = StringPrototypeIndexOf ( altNames , ', ', offset ) ;
254- const nextQuote = StringPrototypeIndexOf ( altNames , '"' , offset ) ;
234+ const nextSep = altNames . indexOf ( ', ', offset ) ;
235+ const nextQuote = altNames . indexOf ( '"' , offset ) ;
255236 if ( nextQuote !== - 1 && ( nextSep === - 1 || nextQuote < nextSep ) ) {
256237 // There is a quote character and there is no separator before the quote.
257- currentToken += StringPrototypeSubstring ( altNames , offset , nextQuote ) ;
258- const match = RegExpPrototypeExec (
259- jsonStringPattern , StringPrototypeSubstring ( altNames , nextQuote ) ) ;
238+ currentToken += altNames . substring ( offset , nextQuote ) ;
239+ const match = jsonStringPattern . exec ( altNames . substring ( nextQuote ) ) ;
260240 if ( ! match ) {
261241 throw new ERR_TLS_CERT_ALTNAME_FORMAT ( ) ;
262242 }
263243 currentToken += JSONParse ( match [ 0 ] ) ;
264244 offset = nextQuote + match [ 0 ] . length ;
265245 } else if ( nextSep !== - 1 ) {
266246 // There is a separator and no quote before it.
267- currentToken += StringPrototypeSubstring ( altNames , offset , nextSep ) ;
268- ArrayPrototypePush ( result , currentToken ) ;
247+ currentToken += altNames . substring ( offset , nextSep ) ;
248+ result . push ( currentToken ) ;
269249 currentToken = '' ;
270250 offset = nextSep + 2 ;
271251 } else {
272- currentToken += StringPrototypeSubstring ( altNames , offset ) ;
252+ currentToken += altNames . substring ( offset ) ;
273253 offset = altNames . length ;
274254 }
275255 }
276- ArrayPrototypePush ( result , currentToken ) ;
256+ result . push ( currentToken ) ;
277257 return result ;
278258}
279259
@@ -286,14 +266,14 @@ exports.checkServerIdentity = function checkServerIdentity(hostname, cert) {
286266 hostname = '' + hostname ;
287267
288268 if ( altNames ) {
289- const splitAltNames = StringPrototypeIncludes ( altNames , '"' ) ?
269+ const splitAltNames = altNames . includes ( '"' ) ?
290270 splitEscapedAltNames ( altNames ) :
291- StringPrototypeSplit ( altNames , ', ' ) ;
292- ArrayPrototypeForEach ( splitAltNames , ( name ) => {
293- if ( StringPrototypeStartsWith ( name , 'DNS:' ) ) {
294- ArrayPrototypePush ( dnsNames , StringPrototypeSlice ( name , 4 ) ) ;
295- } else if ( StringPrototypeStartsWith ( name , 'IP Address:' ) ) {
296- ArrayPrototypePush ( ips , canonicalizeIP ( StringPrototypeSlice ( name , 11 ) ) ) ;
271+ altNames . split ( ', ' ) ;
272+ splitAltNames . forEach ( ( name ) => {
273+ if ( name . startsWith ( 'DNS:' ) ) {
274+ dnsNames . push ( name . slice ( 4 ) ) ;
275+ } else if ( name . startsWith ( 'IP Address:' ) ) {
276+ ips . push ( canonicalizeIP ( name . slice ( 11 ) ) ) ;
297277 }
298278 } ) ;
299279 }
@@ -304,16 +284,15 @@ exports.checkServerIdentity = function checkServerIdentity(hostname, cert) {
304284 hostname = unfqdn ( hostname ) ; // Remove trailing dot for error messages.
305285
306286 if ( net . isIP ( hostname ) ) {
307- valid = ArrayPrototypeIncludes ( ips , canonicalizeIP ( hostname ) ) ;
287+ valid = ips . includes ( canonicalizeIP ( hostname ) ) ;
308288 if ( ! valid )
309- reason = `IP: ${ hostname } is not in the cert's list: ` +
310- ArrayPrototypeJoin ( ips , ', ' ) ;
289+ reason = `IP: ${ hostname } is not in the cert's list: ` + ips . join ( ', ' ) ;
311290 } else if ( dnsNames . length > 0 || subject ?. CN ) {
312291 const hostParts = splitHost ( hostname ) ;
313292 const wildcard = ( pattern ) => check ( hostParts , pattern , true ) ;
314293
315294 if ( dnsNames . length > 0 ) {
316- valid = ArrayPrototypeSome ( dnsNames , wildcard ) ;
295+ valid = dnsNames . some ( wildcard ) ;
317296 if ( ! valid )
318297 reason =
319298 `Host: ${ hostname } . is not in the cert's altnames: ${ altNames } ` ;
@@ -322,7 +301,7 @@ exports.checkServerIdentity = function checkServerIdentity(hostname, cert) {
322301 const cn = subject . CN ;
323302
324303 if ( ArrayIsArray ( cn ) )
325- valid = ArrayPrototypeSome ( cn , wildcard ) ;
304+ valid = cn . some ( wildcard ) ;
326305 else if ( cn )
327306 valid = wildcard ( cn ) ;
328307
0 commit comments