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