File tree 3 files changed +26
-9
lines changed
3 files changed +26
-9
lines changed Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+ const common = require ( '../common.js' ) ;
3
+ const url = require ( 'url' ) ;
4
+ const URL = url . URL ;
5
+
6
+ const bench = common . createBenchmark ( main , {
7
+ type : [ 'valid' , 'invalid' ] ,
8
+ e : [ 1e5 ] ,
9
+ } ) ;
10
+
11
+ // This benchmark is used to compare the `Invalid URL` path of the URL parser
12
+ function main ( { type, e } ) {
13
+ const url = type === 'valid' ? 'https://www.nodejs.org' : 'www.nodejs.org' ;
14
+ bench . start ( ) ;
15
+ for ( let i = 0 ; i < e ; i ++ ) {
16
+ try {
17
+ new URL ( url ) ;
18
+ } catch {
19
+ // do nothing
20
+ }
21
+ }
22
+ bench . end ( e ) ;
23
+ }
Original file line number Diff line number Diff line change @@ -780,13 +780,7 @@ class URL {
780
780
base = `${ base } ` ;
781
781
}
782
782
783
- const href = bindingUrl . parse ( input , base ) ;
784
-
785
- if ( ! href ) {
786
- throw new ERR_INVALID_URL ( input ) ;
787
- }
788
-
789
- this . #updateContext( href ) ;
783
+ this . #updateContext( bindingUrl . parse ( input , base ) ) ;
790
784
}
791
785
792
786
[ inspect . custom ] ( depth , opts ) {
Original file line number Diff line number Diff line change @@ -243,15 +243,15 @@ void BindingData::Parse(const FunctionCallbackInfo<Value>& args) {
243
243
base =
244
244
ada::parse<ada::url_aggregator>(Utf8Value (isolate, args[1 ]).ToString ());
245
245
if (!base) {
246
- return args. GetReturnValue (). Set ( false );
246
+ return THROW_ERR_INVALID_URL (realm-> env (), " Invalid URL " );
247
247
}
248
248
base_pointer = &base.value ();
249
249
}
250
250
auto out =
251
251
ada::parse<ada::url_aggregator>(input.ToStringView (), base_pointer);
252
252
253
253
if (!out) {
254
- return args. GetReturnValue (). Set ( false );
254
+ return THROW_ERR_INVALID_URL (realm-> env (), " Invalid URL " );
255
255
}
256
256
257
257
binding_data->UpdateComponents (out->get_components (), out->type );
You can’t perform that action at this time.
0 commit comments