Add gc::Mark and gc::IsMarked functions. (Bug 687843, r=billm)
authorNicolas Pierron <npierron@mozilla.com>
Mon, 31 Oct 2011 15:41:48 -0700
changeset 79482 b1818463edc1c1acf461eaf76641d84c1cf29a9d
parent 79481 e59e852dd0f853a51b2849268d6a13250f05cfca
child 79483 a3b0534b657c3a4c5a2753960b0109bc7e92fdb9
push id21408
push userkhuey@mozilla.com
push dateTue, 01 Nov 2011 14:32:20 +0000
treeherdermozilla-central@cd9add22f090 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbillm
bugs687843
milestone10.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
Add gc::Mark and gc::IsMarked functions. (Bug 687843, r=billm) Use overloading to choose the Mark/IsMarked function based on the static type of the argument. ---
js/src/jsgcmark.h
--- a/js/src/jsgcmark.h
+++ b/js/src/jsgcmark.h
@@ -173,12 +173,49 @@ void
 MarkChildren(JSTracer *trc, const Shape *shape);
 
 void
 MarkChildren(JSTracer *trc, JSScript *script);
 
 void
 MarkChildren(JSTracer *trc, JSXML *xml);
 
+/*
+ * Use function overloading to decide which function should be called based on
+ * the type of the object. The static type is used at compile time to link to
+ * the corresponding Mark/IsMarked function.
+ */
+inline void
+Mark(JSTracer *trc, const js::Value &v, const char *name)
+{
+    MarkValue(trc, v, name);
+}
+
+inline void
+Mark(JSTracer *trc, JSObject *o, const char *name)
+{
+    MarkObject(trc, *o, name);
+}
+
+inline bool
+IsMarked(JSContext *cx, const js::Value &v)
+{
+    if (v.isMarkable())
+        return !IsAboutToBeFinalized(cx, v.toGCThing());
+    return true;
+}
+
+inline bool
+IsMarked(JSContext *cx, JSObject *o)
+{
+    return !IsAboutToBeFinalized(cx, o);
+}
+
+inline bool
+IsMarked(JSContext *cx, Cell *cell)
+{
+    return !IsAboutToBeFinalized(cx, cell);
+}
+
 }
 }
 
 #endif