Bug 1377008 - Teach GCPolicy about Maybe;r?jonco
MozReview-Commit-ID: CdfNBojdx3K
--- a/js/public/GCPolicyAPI.h
+++ b/js/public/GCPolicyAPI.h
@@ -35,16 +35,17 @@
//
// There are some stock structs your specializations can inherit from.
// IgnoreGCPolicy<T> does nothing. StructGCPolicy<T> forwards the methods to the
// referent type T.
#ifndef GCPolicyAPI_h
#define GCPolicyAPI_h
+#include "mozilla/Maybe.h"
#include "mozilla/UniquePtr.h"
#include "js/TraceKind.h"
#include "js/TracingAPI.h"
// Expand the given macro D for each public GC pointer.
#define FOR_EACH_PUBLIC_GC_POINTER_TYPE(D) \
D(JS::Symbol*) \
@@ -154,11 +155,28 @@ struct GCPolicy<mozilla::UniquePtr<T, D>
}
static bool needsSweep(mozilla::UniquePtr<T,D>* tp) {
if (tp->get())
return GCPolicy<T>::needsSweep(tp->get());
return false;
}
};
+// 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