@@ -141,6 +141,16 @@ void URLImpl::Ctor(const v8::FunctionCallbackInfo<v8::Value> &args) {
141
141
142
142
auto result = ada::parse<ada::url_aggregator>(url_string, &base_url.value ());
143
143
144
+ if (result) {
145
+ url = result.value ();
146
+ } else {
147
+ isolate->ThrowException (
148
+ v8::Exception::TypeError (ToV8String (isolate, " " )));
149
+ return ;
150
+ }
151
+ } else {
152
+ // treat 2nd arg as undefined otherwise.
153
+ auto result = ada::parse<ada::url_aggregator>(url_string, nullptr );
144
154
if (result) {
145
155
url = result.value ();
146
156
} else {
@@ -149,7 +159,6 @@ void URLImpl::Ctor(const v8::FunctionCallbackInfo<v8::Value> &args) {
149
159
return ;
150
160
}
151
161
}
152
-
153
162
} else {
154
163
auto result = ada::parse<ada::url_aggregator>(url_string, nullptr );
155
164
if (result) {
@@ -242,7 +251,6 @@ void URLImpl::GetHostName(v8::Local<v8::String> property,
242
251
auto value = ptr->GetURL ()->get_hostname ();
243
252
244
253
info.GetReturnValue ().Set (ToV8String (isolate, value.data (), (int )value.length ()));
245
-
246
254
}
247
255
248
256
void URLImpl::SetHostName (v8::Local<v8::String> property,
@@ -271,7 +279,6 @@ void URLImpl::GetHref(v8::Local<v8::String> property,
271
279
auto value = ptr->GetURL ()->get_href ();
272
280
273
281
info.GetReturnValue ().Set (ToV8String (isolate, value.data (), (int )value.length ()));
274
-
275
282
}
276
283
277
284
void URLImpl::SetHref (v8::Local<v8::String> property,
@@ -299,7 +306,6 @@ void URLImpl::GetOrigin(v8::Local<v8::String> property,
299
306
auto value = ptr->GetURL ()->get_origin ();
300
307
301
308
info.GetReturnValue ().Set (ToV8String (isolate, value.c_str ()));
302
-
303
309
}
304
310
305
311
void URLImpl::GetPassword (v8::Local<v8::String> property,
@@ -314,7 +320,6 @@ void URLImpl::GetPassword(v8::Local<v8::String> property,
314
320
auto value = ptr->GetURL ()->get_password ();
315
321
316
322
info.GetReturnValue ().Set (ToV8String (isolate, value.data (), (int )value.length ()));
317
-
318
323
}
319
324
320
325
void URLImpl::SetPassword (v8::Local<v8::String> property,
@@ -341,8 +346,7 @@ void URLImpl::GetPathName(v8::Local<v8::String> property,
341
346
342
347
auto value = ptr->GetURL ()->get_pathname ();
343
348
344
- info.GetReturnValue ().Set (ToV8String (isolate, value.data ()));
345
-
349
+ info.GetReturnValue ().Set (ToV8String (isolate, value.data (), (int )value.length ()));
346
350
}
347
351
348
352
void URLImpl::SetPathName (v8::Local<v8::String> property,
@@ -370,7 +374,6 @@ void URLImpl::GetPort(v8::Local<v8::String> property,
370
374
auto value = ptr->GetURL ()->get_port ();
371
375
372
376
info.GetReturnValue ().Set (ToV8String (isolate, value.data (), (int )value.length ()));
373
-
374
377
}
375
378
376
379
void URLImpl::SetPort (v8::Local<v8::String> property,
@@ -398,7 +401,6 @@ void URLImpl::GetProtocol(v8::Local<v8::String> property,
398
401
auto value = ptr->GetURL ()->get_protocol ();
399
402
400
403
info.GetReturnValue ().Set (ToV8String (isolate, value.data (), (int )value.length ()));
401
-
402
404
}
403
405
404
406
void URLImpl::SetProtocol (v8::Local<v8::String> property,
@@ -427,7 +429,6 @@ void URLImpl::GetSearch(v8::Local<v8::String> property,
427
429
auto value = ptr->GetURL ()->get_search ();
428
430
429
431
info.GetReturnValue ().Set (ToV8String (isolate, value.data (), (int )value.length ()));
430
-
431
432
}
432
433
433
434
void URLImpl::SetSearch (v8::Local<v8::String> property,
@@ -456,7 +457,6 @@ void URLImpl::GetUserName(v8::Local<v8::String> property,
456
457
auto value = ptr->GetURL ()->get_username ();
457
458
458
459
info.GetReturnValue ().Set (ToV8String (isolate, value.data (), (int )value.length ()));
459
-
460
460
}
461
461
462
462
void URLImpl::SetUserName (v8::Local<v8::String> property,
@@ -473,39 +473,36 @@ void URLImpl::SetUserName(v8::Local<v8::String> property,
473
473
}
474
474
475
475
476
- void URLImpl::ToString (const v8::FunctionCallbackInfo<v8::Value> &args ) {
477
- URLImpl *ptr = GetPointer (args .This ());
476
+ void URLImpl::ToString (const v8::FunctionCallbackInfo<v8::Value> &info ) {
477
+ URLImpl *ptr = GetPointer (info .This ());
478
478
if (ptr == nullptr ) {
479
- args .GetReturnValue ().SetEmptyString ();
479
+ info .GetReturnValue ().SetEmptyString ();
480
480
return ;
481
481
}
482
- auto isolate = args .GetIsolate ();
482
+ auto isolate = info .GetIsolate ();
483
483
484
484
485
485
auto value = ptr->GetURL ()->get_href ();
486
486
487
- auto ret = ToV8String (isolate, value.data (), (int )value.length ());
488
-
489
- args.GetReturnValue ().Set (ret);
487
+ info.GetReturnValue ().Set (ToV8String (isolate, value.data (), (int )value.length ()));
490
488
}
491
489
492
490
493
- void URLImpl::CanParse (const v8::FunctionCallbackInfo<v8::Value> &args ) {
491
+ void URLImpl::CanParse (const v8::FunctionCallbackInfo<v8::Value> &info ) {
494
492
bool value;
495
- auto count = args .Length ();
493
+ auto count = info .Length ();
496
494
497
-
498
- auto isolate = args.GetIsolate ();
495
+ auto isolate = info.GetIsolate ();
499
496
if (count > 1 ) {
500
- auto url_string = tns::ToString (isolate, args [0 ].As <v8::String>());
501
- auto base_string = tns::ToString (isolate, args [1 ].As <v8::String>());
497
+ auto url_string = tns::ToString (isolate, info [0 ].As <v8::String>());
498
+ auto base_string = tns::ToString (isolate, info [1 ].As <v8::String>());
502
499
std::string_view base_string_view (base_string.data (), base_string.length ());
503
500
value = can_parse (url_string, &base_string_view);
504
501
} else {
505
- value = can_parse (tns::ToString (isolate, args [0 ].As <v8::String>()).c_str (), nullptr );
502
+ value = can_parse (tns::ToString (isolate, info [0 ].As <v8::String>()).c_str (), nullptr );
506
503
}
507
504
508
- args .GetReturnValue ().Set (value);
505
+ info .GetReturnValue ().Set (value);
509
506
}
510
507
511
508
0 commit comments