@@ -168,6 +168,10 @@ URLPattern::URLPattern(Environment* env,
168
168
169
169
void URLPattern::MemoryInfo (MemoryTracker* tracker) const {
170
170
tracker->TraitTrackInline (url_pattern_, " url_pattern" );
171
+ #define URL_PATTERN_CACHED_VALUES (_, lowercase ) \
172
+ tracker->TrackField (#lowercase, lowercase);
173
+ URL_PATTERN_COMPONENTS (URL_PATTERN_CACHED_VALUES)
174
+ #undef URL_PATTERN_CACHED_VALUES
171
175
}
172
176
173
177
void URLPattern::New (const FunctionCallbackInfo<Value>& args) {
@@ -466,10 +470,20 @@ URLPattern::URLPatternOptions::FromJsObject(Environment* env,
466
470
return options;
467
471
}
468
472
473
+ // Perform value lookup and cache the result in a v8::Global.
469
474
#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 ()); \
475
+ MaybeLocal<Value> URLPattern::uppercase_name () { \
476
+ auto isolate = env ()->isolate (); \
477
+ if (lowercase_name.IsEmpty ()) { \
478
+ Local<Value> value; \
479
+ if (ToV8Value (env ()->context (), url_pattern_.get_ ##lowercase_name ()) \
480
+ .ToLocal (&value)) { \
481
+ lowercase_name.Reset (isolate, value); \
482
+ return value; \
483
+ } \
484
+ return {}; \
485
+ } \
486
+ return lowercase_name.Get (isolate); \
473
487
}
474
488
URL_PATTERN_COMPONENTS (URL_PATTERN_COMPONENT_GETTERS)
475
489
#undef URL_PATTERN_COMPONENT_GETTERS
0 commit comments