@@ -141,6 +141,16 @@ void URLImpl::Ctor(const v8::FunctionCallbackInfo<v8::Value> &args) {
141141
142142 auto result = ada::parse<ada::url_aggregator>(url_string, &base_url.value ());
143143
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 );
144154 if (result) {
145155 url = result.value ();
146156 } else {
@@ -149,7 +159,6 @@ void URLImpl::Ctor(const v8::FunctionCallbackInfo<v8::Value> &args) {
149159 return ;
150160 }
151161 }
152-
153162 } else {
154163 auto result = ada::parse<ada::url_aggregator>(url_string, nullptr );
155164 if (result) {
@@ -242,7 +251,6 @@ void URLImpl::GetHostName(v8::Local<v8::String> property,
242251 auto value = ptr->GetURL ()->get_hostname ();
243252
244253 info.GetReturnValue ().Set (ToV8String (isolate, value.data (), (int )value.length ()));
245-
246254}
247255
248256void URLImpl::SetHostName (v8::Local<v8::String> property,
@@ -271,7 +279,6 @@ void URLImpl::GetHref(v8::Local<v8::String> property,
271279 auto value = ptr->GetURL ()->get_href ();
272280
273281 info.GetReturnValue ().Set (ToV8String (isolate, value.data (), (int )value.length ()));
274-
275282}
276283
277284void URLImpl::SetHref (v8::Local<v8::String> property,
@@ -299,7 +306,6 @@ void URLImpl::GetOrigin(v8::Local<v8::String> property,
299306 auto value = ptr->GetURL ()->get_origin ();
300307
301308 info.GetReturnValue ().Set (ToV8String (isolate, value.c_str ()));
302-
303309}
304310
305311void URLImpl::GetPassword (v8::Local<v8::String> property,
@@ -314,7 +320,6 @@ void URLImpl::GetPassword(v8::Local<v8::String> property,
314320 auto value = ptr->GetURL ()->get_password ();
315321
316322 info.GetReturnValue ().Set (ToV8String (isolate, value.data (), (int )value.length ()));
317-
318323}
319324
320325void URLImpl::SetPassword (v8::Local<v8::String> property,
@@ -341,8 +346,7 @@ void URLImpl::GetPathName(v8::Local<v8::String> property,
341346
342347 auto value = ptr->GetURL ()->get_pathname ();
343348
344- info.GetReturnValue ().Set (ToV8String (isolate, value.data ()));
345-
349+ info.GetReturnValue ().Set (ToV8String (isolate, value.data (), (int )value.length ()));
346350}
347351
348352void URLImpl::SetPathName (v8::Local<v8::String> property,
@@ -370,7 +374,6 @@ void URLImpl::GetPort(v8::Local<v8::String> property,
370374 auto value = ptr->GetURL ()->get_port ();
371375
372376 info.GetReturnValue ().Set (ToV8String (isolate, value.data (), (int )value.length ()));
373-
374377}
375378
376379void URLImpl::SetPort (v8::Local<v8::String> property,
@@ -398,7 +401,6 @@ void URLImpl::GetProtocol(v8::Local<v8::String> property,
398401 auto value = ptr->GetURL ()->get_protocol ();
399402
400403 info.GetReturnValue ().Set (ToV8String (isolate, value.data (), (int )value.length ()));
401-
402404}
403405
404406void URLImpl::SetProtocol (v8::Local<v8::String> property,
@@ -427,7 +429,6 @@ void URLImpl::GetSearch(v8::Local<v8::String> property,
427429 auto value = ptr->GetURL ()->get_search ();
428430
429431 info.GetReturnValue ().Set (ToV8String (isolate, value.data (), (int )value.length ()));
430-
431432}
432433
433434void URLImpl::SetSearch (v8::Local<v8::String> property,
@@ -456,7 +457,6 @@ void URLImpl::GetUserName(v8::Local<v8::String> property,
456457 auto value = ptr->GetURL ()->get_username ();
457458
458459 info.GetReturnValue ().Set (ToV8String (isolate, value.data (), (int )value.length ()));
459-
460460}
461461
462462void URLImpl::SetUserName (v8::Local<v8::String> property,
@@ -473,39 +473,36 @@ void URLImpl::SetUserName(v8::Local<v8::String> property,
473473}
474474
475475
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 ());
478478 if (ptr == nullptr ) {
479- args .GetReturnValue ().SetEmptyString ();
479+ info .GetReturnValue ().SetEmptyString ();
480480 return ;
481481 }
482- auto isolate = args .GetIsolate ();
482+ auto isolate = info .GetIsolate ();
483483
484484
485485 auto value = ptr->GetURL ()->get_href ();
486486
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 ()));
490488}
491489
492490
493- void URLImpl::CanParse (const v8::FunctionCallbackInfo<v8::Value> &args ) {
491+ void URLImpl::CanParse (const v8::FunctionCallbackInfo<v8::Value> &info ) {
494492 bool value;
495- auto count = args .Length ();
493+ auto count = info .Length ();
496494
497-
498- auto isolate = args.GetIsolate ();
495+ auto isolate = info.GetIsolate ();
499496 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>());
502499 std::string_view base_string_view (base_string.data (), base_string.length ());
503500 value = can_parse (url_string, &base_string_view);
504501 } 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 );
506503 }
507504
508- args .GetReturnValue ().Set (value);
505+ info .GetReturnValue ().Set (value);
509506}
510507
511508
0 commit comments