esm: avoid try/catch when validating urls
Due to URL.canParse
, we can avoid try/catch block and have faster validation. The previous implementation was not performant due to:
- Unnecessary string serialization - We don't need
href
,origin
etc. for validating if a URL is valid or not. -
URL.canParse
can be written with V8 Fast API - enabling more performance out of this pull request. -
URL.canParse
does not return anything except a boolean.
cc @nodejs/url