From 64dc722b28d34a153751a623a7f4f2e48a13655f Mon Sep 17 00:00:00 2001 From: Brian Smith Date: Fri, 6 Mar 2026 23:47:55 -0600 Subject: [PATCH] Issue #2304 - Part 2 - Prerequisite: Teach GCPolicy about Maybe. https://bugzilla.mozilla.org/show_bug.cgi?id=1377008 --- js/public/GCPolicyAPI.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/js/public/GCPolicyAPI.h b/js/public/GCPolicyAPI.h index cffaee7140..0649c23265 100644 --- a/js/public/GCPolicyAPI.h +++ b/js/public/GCPolicyAPI.h @@ -39,6 +39,7 @@ #ifndef GCPolicyAPI_h #define GCPolicyAPI_h +#include "mozilla/Maybe.h" #include "mozilla/UniquePtr.h" #include "js/TraceKind.h" @@ -160,6 +161,23 @@ struct GCPolicy> } }; +// GCPolicy> forwards tracing/sweeping to GCPolicy if +// when the Maybe is full. +template +struct GCPolicy> +{ + static mozilla::Maybe initial() { return mozilla::Maybe(); } + static void trace(JSTracer* trc, mozilla::Maybe* tp, const char* name) { + if (tp->isSome()) + GCPolicy::trace(trc, tp->ptr(), name); + } + static bool needsSweep(mozilla::Maybe* tp) { + if (tp->isSome()) + return GCPolicy::needsSweep(tp->ptr()); + return false; + } +}; + } // namespace JS #endif // GCPolicyAPI_h