Bug 1377008 - Teach GCPolicy about Maybe;r?jonco draft
authorDavid Teller <dteller@mozilla.com>
Wed, 28 Jun 2017 17:45:21 -0700
changeset 601675 53f154eafdd7969e04ac978886b2235c333241d9
parent 598569 5456e68aafc268021815d220ad75ae304d4bd744
child 601687 88757b07d32d963a9aad33a571b70665afff7091
child 602148 5950a23f41f8c7b66b761251ea693f555fe9bc88
child 602303 9ae76a7cc10b5e736e2a270bef8f403df95ae1b4
child 602496 a64ad33f78f9404563b745f1d8039532512e68cb
child 602893 cf9ecddc2f28d58a48d7311e647aae31407b02d1
push id66176
push userbmo:dteller@mozilla.com
push dateThu, 29 Jun 2017 00:36:19 +0000
reviewersjonco
bugs1377008
milestone56.0a1
Bug 1377008 - Teach GCPolicy about Maybe;r?jonco MozReview-Commit-ID: CdfNBojdx3K
js/public/GCPolicyAPI.h
--- 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