Issue #2304 - Part 2 - Prerequisite: Teach GCPolicy about Maybe. https://bugzilla.mozilla.org/show_bug.cgi?id=1377008

This commit is contained in:
Brian Smith 2026-03-06 23:47:55 -06:00 committed by OwnedByWuigi
commit 64dc722b28

View file

@ -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<mozilla::UniquePtr<T, D>>
}
};
// GCPolicy<Maybe<T>> forwards tracing/sweeping to GCPolicy<T*> if
// when the Maybe<T> is full.
template <typename T>
struct GCPolicy<mozilla::Maybe<T>>
{
static mozilla::Maybe<T> initial() { return mozilla::Maybe<T>(); }
static void trace(JSTracer* trc, mozilla::Maybe<T>* tp, const char* name) {
if (tp->isSome())
GCPolicy<T>::trace(trc, tp->ptr(), name);
}
static bool needsSweep(mozilla::Maybe<T>* tp) {
if (tp->isSome())
return GCPolicy<T>::needsSweep(tp->ptr());
return false;
}
};
} // namespace JS
#endif // GCPolicyAPI_h