@@ -585,77 +585,17 @@ void URLPattern::Test(const FunctionCallbackInfo<Value>& args) {
585585 args.GetReturnValue ().Set (url_pattern->Test (env, input, baseURL_opt));
586586}
587587
588- void URLPattern::Protocol (const FunctionCallbackInfo<Value>& info) {
589- URLPattern* url_pattern;
590- ASSIGN_OR_RETURN_UNWRAP (&url_pattern, info.This ());
591- Local<Value> result;
592- if (url_pattern->Protocol ().ToLocal (&result)) {
593- info.GetReturnValue ().Set (result);
594- }
595- }
596-
597- void URLPattern::Username (const FunctionCallbackInfo<Value>& info) {
598- URLPattern* url_pattern;
599- ASSIGN_OR_RETURN_UNWRAP (&url_pattern, info.This ());
600- Local<Value> result;
601- if (url_pattern->Username ().ToLocal (&result)) {
602- info.GetReturnValue ().Set (result);
603- }
604- }
605-
606- void URLPattern::Password (const FunctionCallbackInfo<Value>& info) {
607- URLPattern* url_pattern;
608- ASSIGN_OR_RETURN_UNWRAP (&url_pattern, info.This ());
609- Local<Value> result;
610- if (url_pattern->Password ().ToLocal (&result)) {
611- info.GetReturnValue ().Set (result);
612- }
613- }
614-
615- void URLPattern::Hostname (const FunctionCallbackInfo<Value>& info) {
616- URLPattern* url_pattern;
617- ASSIGN_OR_RETURN_UNWRAP (&url_pattern, info.This ());
618- Local<Value> result;
619- if (url_pattern->Hostname ().ToLocal (&result)) {
620- info.GetReturnValue ().Set (result);
621- }
622- }
623-
624- void URLPattern::Port (const FunctionCallbackInfo<Value>& info) {
625- URLPattern* url_pattern;
626- ASSIGN_OR_RETURN_UNWRAP (&url_pattern, info.This ());
627- Local<Value> result;
628- if (url_pattern->Port ().ToLocal (&result)) {
629- info.GetReturnValue ().Set (result);
630- }
631- }
632-
633- void URLPattern::Pathname (const FunctionCallbackInfo<Value>& info) {
634- URLPattern* url_pattern;
635- ASSIGN_OR_RETURN_UNWRAP (&url_pattern, info.This ());
636- Local<Value> result;
637- if (url_pattern->Pathname ().ToLocal (&result)) {
638- info.GetReturnValue ().Set (result);
639- }
640- }
641-
642- void URLPattern::Search (const FunctionCallbackInfo<Value>& info) {
643- URLPattern* url_pattern;
644- ASSIGN_OR_RETURN_UNWRAP (&url_pattern, info.This ());
645- Local<Value> result;
646- if (url_pattern->Search ().ToLocal (&result)) {
647- info.GetReturnValue ().Set (result);
648- }
649- }
650-
651- void URLPattern::Hash (const FunctionCallbackInfo<Value>& info) {
652- URLPattern* url_pattern;
653- ASSIGN_OR_RETURN_UNWRAP (&url_pattern, info.This ());
654- Local<Value> result;
655- if (url_pattern->Hash ().ToLocal (&result)) {
656- info.GetReturnValue ().Set (result);
588+ #define URL_PATTERN_COMPONENT_GETTERS (uppercase_name, lowercase_name ) \
589+ void URLPattern::uppercase_name (const FunctionCallbackInfo<Value>& info) { \
590+ URLPattern* url_pattern; \
591+ ASSIGN_OR_RETURN_UNWRAP (&url_pattern, info.This ()); \
592+ Local<Value> result; \
593+ if (url_pattern->uppercase_name ().ToLocal (&result)) { \
594+ info.GetReturnValue ().Set (result); \
595+ } \
657596 }
658- }
597+ URL_PATTERN_COMPONENTS (URL_PATTERN_COMPONENT_GETTERS)
598+ #undef URL_PATTERN_COMPONENT_GETTERS
659599
660600void URLPattern::HasRegexpGroups (const FunctionCallbackInfo<Value>& info) {
661601 URLPattern* url_pattern;
@@ -665,14 +605,10 @@ void URLPattern::HasRegexpGroups(const FunctionCallbackInfo<Value>& info) {
665605
666606static void RegisterExternalReferences (ExternalReferenceRegistry* registry) {
667607 registry->Register (URLPattern::New);
668- registry->Register (URLPattern::Protocol);
669- registry->Register (URLPattern::Username);
670- registry->Register (URLPattern::Password);
671- registry->Register (URLPattern::Hostname);
672- registry->Register (URLPattern::Port);
673- registry->Register (URLPattern::Pathname);
674- registry->Register (URLPattern::Search);
675- registry->Register (URLPattern::Hash);
608+ #define URL_PATTERN_COMPONENT_GETTERS (uppercase_name, _ ) \
609+ registry->Register (URLPattern::uppercase_name);
610+ URL_PATTERN_COMPONENTS (URL_PATTERN_COMPONENT_GETTERS)
611+ #undef URL_PATTERN_COMPONENT_GETTERS
676612 registry->Register (URLPattern::HasRegexpGroups);
677613 registry->Register (URLPattern::Exec);
678614 registry->Register (URLPattern::Test);
@@ -695,61 +631,18 @@ static void Initialize(Local<Object> target,
695631 auto signature = Signature::New (isolate, ctor_tmpl);
696632
697633 instance_template->SetInternalFieldCount (URLPattern::kInternalFieldCount );
698- prototype_template->SetAccessorProperty (
699- env->protocol_string (),
700- FunctionTemplate::New (
701- isolate, URLPattern::Protocol, Local<Value>(), signature),
702- Local<FunctionTemplate>(),
703- attributes);
704-
705- prototype_template->SetAccessorProperty (
706- env->username_string (),
707- FunctionTemplate::New (
708- isolate, URLPattern::Username, Local<Value>(), signature),
709- Local<FunctionTemplate>(),
710- attributes);
711-
712- prototype_template->SetAccessorProperty (
713- env->password_string (),
714- FunctionTemplate::New (
715- isolate, URLPattern::Password, Local<Value>(), signature),
716- Local<FunctionTemplate>(),
717- attributes);
718-
719- prototype_template->SetAccessorProperty (
720- env->hostname_string (),
721- FunctionTemplate::New (
722- isolate, URLPattern::Hostname, Local<Value>(), signature),
723- Local<FunctionTemplate>(),
724- attributes);
725634
726- prototype_template->SetAccessorProperty (
727- env->port_string (),
728- FunctionTemplate::New (
729- isolate, URLPattern::Port, Local<Value>(), signature),
730- Local<FunctionTemplate>(),
731- attributes);
732-
733- prototype_template->SetAccessorProperty (
734- env->pathname_string (),
735- FunctionTemplate::New (
736- isolate, URLPattern::Pathname, Local<Value>(), signature),
737- Local<FunctionTemplate>(),
738- attributes);
739-
740- prototype_template->SetAccessorProperty (
741- env->search_string (),
742- FunctionTemplate::New (
743- isolate, URLPattern::Search, Local<Value>(), signature),
744- Local<FunctionTemplate>(),
745- attributes);
746-
747- prototype_template->SetAccessorProperty (
748- env->hash_string (),
749- FunctionTemplate::New (
750- isolate, URLPattern::Hash, Local<Value>(), signature),
751- Local<FunctionTemplate>(),
635+ #define ENV_GETTER (lowercase_name ) env->lowercase_name##_string()
636+ #define URL_PATTERN_COMPONENT_GETTERS (uppercase_name, lowercase_name ) \
637+ prototype_template->SetAccessorProperty ( \
638+ GET_PROPERTY_NAME (lowercase_name), \
639+ FunctionTemplate::New ( \
640+ isolate, URLPattern::uppercase_name, Local<Value>(), signature), \
641+ Local<FunctionTemplate>(), \
752642 attributes);
643+ URL_PATTERN_COMPONENTS (URL_PATTERN_COMPONENT_GETTERS)
644+ #undef URL_PATTERN_COMPONENT_GETTERS
645+ #undef ENV_GETTER
753646
754647 prototype_template->SetAccessorProperty (
755648 env->has_regexp_groups_string (),
0 commit comments