Bug 1251480 - Implement Rooted<UniquePtr<T>>, r=terrence
authorSteve Fink <sfink@mozilla.com>
Fri, 26 Feb 2016 11:56:29 -0800
changeset 322523 d0d2cd5f762bd3cc932d3d86ed6d4b1c465929b8
parent 322522 76ded94f97a300223053e43fb0790c97349a42d9
child 322524 80869f1474a46dd2abe12c79410ff7d0126980b7
push id5913
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 16:57:49 +0000
treeherdermozilla-beta@dcaf0a6fa115 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersterrence
bugs1251480
milestone47.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1251480 - Implement Rooted<UniquePtr<T>>, r=terrence
js/public/GCPolicyAPI.h
js/public/TraceKind.h
--- a/js/public/GCPolicyAPI.h
+++ b/js/public/GCPolicyAPI.h
@@ -30,16 +30,17 @@
 //         reason that GC-supporting weak containers can override the [sweep?]
 //         policy on a per-container basis.
 
 #ifndef GCPolicyAPI_h
 #define GCPolicyAPI_h
 
 #include "js/TraceKind.h"
 #include "js/TracingAPI.h"
+#include "mozilla/UniquePtr.h"
 
 class JSAtom;
 class JSFunction;
 class JSObject;
 class JSScript;
 class JSString;
 namespace JS {
 class Symbol;
@@ -106,11 +107,24 @@ struct GCPolicy<JS::Heap<T>>
     static void trace(JSTracer* trc, JS::Heap<T>* thingp, const char* name) {
         JS::TraceEdge(trc, thingp, name);
     }
     static bool needsSweep(JS::Heap<T>* thingp) {
         return gc::EdgeNeedsSweep(thingp);
     }
 };
 
+// GCPolicy<UniquePtr<T>> forwards the contained pointer to GCPolicy<T>.
+template <typename T, typename D>
+struct GCPolicy<mozilla::UniquePtr<T, D>>
+{
+    static mozilla::UniquePtr<T,D> initial() { return mozilla::UniquePtr<T,D>(); }
+    static void trace(JSTracer* trc, mozilla::UniquePtr<T,D>* tp, const char* name) {
+        GCPolicy<T>::trace(trc, tp->get(), name);
+    }
+    static bool needsSweep(mozilla::UniquePtr<T,D>* tp) {
+        return GCPolicy<T>::needsSweep(tp->get());
+    }
+};
+
 } // namespace js
 
 #endif // GCPolicyAPI_h
--- a/js/public/TraceKind.h
+++ b/js/public/TraceKind.h
@@ -3,16 +3,17 @@
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef js_TraceKind_h
 #define js_TraceKind_h
 
 #include "js/TypeDecls.h"
+#include "mozilla/UniquePtr.h"
 
 // Forward declarations of all the types a TraceKind can denote.
 namespace js {
 class BaseShape;
 class LazyScript;
 class ObjectGroup;
 class Shape;
 namespace jit {
@@ -129,19 +130,23 @@ JS_FOR_EACH_TRACEKIND(JS_EXPAND_DEF)
 // pointer types we can derive directly from the TraceKind; everything else
 // should go in the Traceable list and use GCPolicy<T>::trace for tracing.
 template <typename T>
 struct MapTypeToRootKind {
     static const JS::RootKind kind = JS::RootKind::Traceable;
 };
 template <typename T>
 struct MapTypeToRootKind<T*> {
-    static const JS::RootKind kind = \
+    static const JS::RootKind kind =
         JS::MapTraceKindToRootKind<JS::MapTypeToTraceKind<T>::kind>::kind;
 };
+template <typename T>
+struct MapTypeToRootKind<mozilla::UniquePtr<T>> {
+    static const JS::RootKind kind = JS::MapTypeToRootKind<T>::kind;
+};
 template <> struct MapTypeToRootKind<JS::Value> {
     static const JS::RootKind kind = JS::RootKind::Value;
 };
 template <> struct MapTypeToRootKind<jsid> {
     static const JS::RootKind kind = JS::RootKind::Id;
 };
 template <> struct MapTypeToRootKind<JSFunction*> : public MapTypeToRootKind<JSObject*> {};