@@ -466,10 +466,20 @@ URLPattern::URLPatternOptions::FromJsObject(Environment* env,
466
466
return options;
467
467
}
468
468
469
- #define URL_PATTERN_COMPONENT_GETTERS (uppercase_name, lowercase_name ) \
470
- MaybeLocal<Value> URLPattern::uppercase_name () const { \
471
- auto context = env ()->context (); \
472
- return ToV8Value (context, url_pattern_.get_ ##lowercase_name ()); \
469
+ // Perform value lookup and cache the result in a v8::Global.
470
+ #define URL_PATTERN_COMPONENT_GETTERS (uppercase_name, lowercase_name ) \
471
+ MaybeLocal<Value> URLPattern::uppercase_name () { \
472
+ auto isolate = env ()->isolate (); \
473
+ if (lowercase_name.IsEmpty ()) { \
474
+ Local<Value> value; \
475
+ if (ToV8Value (env ()->context (), url_pattern_.get_ ##lowercase_name ()) \
476
+ .ToLocal (&value)) { \
477
+ lowercase_name.Reset (isolate, value); \
478
+ return value; \
479
+ } \
480
+ return {}; \
481
+ } \
482
+ return lowercase_name.Get (isolate); \
473
483
}
474
484
URL_PATTERN_COMPONENTS (URL_PATTERN_COMPONENT_GETTERS)
475
485
#undef URL_PATTERN_COMPONENT_GETTERS
@@ -654,7 +664,7 @@ static void Initialize(Local<Object> target,
654
664
SetProtoMethodNoSideEffect (isolate, ctor_tmpl, " exec" , URLPattern::Exec);
655
665
SetProtoMethodNoSideEffect (isolate, ctor_tmpl, " test" , URLPattern::Test);
656
666
SetConstructorFunction (context, target, " URLPattern" , ctor_tmpl);
657
- }
667
+ }
658
668
659
669
} // namespace node::url_pattern
660
670
0 commit comments