@@ -35,6 +35,7 @@ const {
35
35
} = require ( 'internal/errors' ) . codes ;
36
36
const { exitCodes : { kUnfinishedTopLevelAwait } } = internalBinding ( 'errors' ) ;
37
37
const { URL } = require ( 'internal/url' ) ;
38
+ const { canParse : urlCanParse } = internalBinding ( 'url' ) ;
38
39
const { receiveMessageOnPort } = require ( 'worker_threads' ) ;
39
40
const {
40
41
isAnyArrayBuffer,
@@ -272,17 +273,17 @@ class Hooks {
272
273
273
274
// Avoid expensive URL instantiation for known-good URLs
274
275
if ( ! this . #validatedUrls. has ( url ) ) {
275
- try {
276
- new URL ( url ) ;
277
- this . #validatedUrls. add ( url ) ;
278
- } catch {
276
+ // No need to convert to string, since the type is already validated
277
+ if ( ! urlCanParse ( url ) ) {
279
278
throw new ERR_INVALID_RETURN_PROPERTY_VALUE (
280
279
'a URL string' ,
281
280
hookErrIdentifier ,
282
281
'url' ,
283
282
url ,
284
283
) ;
285
284
}
285
+
286
+ this . #validatedUrls. add ( url ) ;
286
287
}
287
288
288
289
if (
@@ -352,16 +353,16 @@ class Hooks {
352
353
353
354
// Avoid expensive URL instantiation for known-good URLs
354
355
if ( ! this . #validatedUrls. has ( nextUrl ) ) {
355
- try {
356
- new URL ( nextUrl ) ;
357
- this . #validatedUrls. add ( nextUrl ) ;
358
- } catch {
356
+ // No need to convert to string, since the type is already validated
357
+ if ( ! urlCanParse ( nextUrl ) ) {
359
358
throw new ERR_INVALID_ARG_VALUE (
360
359
`${ hookErrIdentifier } url` ,
361
360
nextUrl ,
362
361
'should be a URL string' ,
363
362
) ;
364
363
}
364
+
365
+ this . #validatedUrls. add ( nextUrl ) ;
365
366
}
366
367
367
368
if ( ctx ) { validateObject ( ctx , `${ hookErrIdentifier } context` ) ; }
0 commit comments