Bug 379727: Using tracing instead of explicit root management. r=alfred.peng sr=brendan
authorigor@mir2.org
Wed, 09 May 2007 04:11:53 -0700
changeset 1310 a55e99e20025e80555a93a9e3f4ac8755ebd998b
parent 1309 7acc820959ead6182933526411b815601fd4206b
child 1311 2f160c6425fedc00e2ac3c63591d6b625d5a3141
push idunknown
push userunknown
push dateunknown
reviewersalfred.peng, brendan
bugs379727
milestone1.9a5pre
Bug 379727: Using tracing instead of explicit root management. r=alfred.peng sr=brendan
js/src/liveconnect/jsj_JavaMember.c
--- a/js/src/liveconnect/jsj_JavaMember.c
+++ b/js/src/liveconnect/jsj_JavaMember.c
@@ -80,38 +80,31 @@ jsj_CreateJavaMember(JSContext *cx, jsva
         return NULL;
     
     JavaMember_obj = JS_NewObject(cx, &JavaMember_class, 0, 0);
     if (!JavaMember_obj) {
         JS_free(cx, member_val);
         return NULL;
     }
 
+    member_val->method_val = method_val;
+    member_val->field_val = field_val;
     JS_SetPrivate(cx, JavaMember_obj, (void *)member_val);
-    member_val->method_val = method_val;
-    JS_AddNamedRoot(cx, &member_val->method_val, "&member_val->method_val");
-    member_val->field_val = field_val;
-    if (JSVAL_IS_GCTHING(field_val))
-        JS_AddNamedRoot(cx, &member_val->field_val, "&member_val->field_val");
 
     return JavaMember_obj;
 }
 
 JS_STATIC_DLL_CALLBACK(void)
 JavaMember_finalize(JSContext *cx, JSObject *obj)
 {
     JavaMethodOrFieldValue *member_val;
 
     member_val = JS_GetPrivate(cx, obj);
     if (!member_val)
         return;
-
-    JS_RemoveRoot(cx, &member_val->method_val);
-    if (JSVAL_IS_GCTHING(member_val->field_val))
-        JS_RemoveRoot(cx, &member_val->field_val);
     JS_free(cx, member_val);
 }
 
 JS_STATIC_DLL_CALLBACK(JSBool)
 JavaMember_convert(JSContext *cx, JSObject *obj, JSType type, jsval *vp)
 {
     JavaMethodOrFieldValue *member_val;
         
@@ -152,29 +145,41 @@ JavaMember_convert(JSContext *cx, JSObje
  */
 JS_STATIC_DLL_CALLBACK(JSBool)
 JavaMember_Call(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
 {
     JS_ASSERT(0);
     return JS_TRUE;
 }
 
+JS_STATIC_DLL_CALLBACK(void)
+JavaMember_trace(JSTracer *trc, JSObject *obj)
+{
+    JavaMethodOrFieldValue *member_val;
+
+    member_val = (JavaMethodOrFieldValue *)JS_GetPrivate(trc->context, obj);
+    if (member_val) {
+        JS_CALL_VALUE_TRACER(trc, member_val->method_val, "method_val");
+        JS_CALL_VALUE_TRACER(trc, member_val->field_val, "field_val");
+    }
+}
+
 JSClass JavaMember_class = {
-    "JavaMember", JSCLASS_HAS_PRIVATE,
+    "JavaMember", JSCLASS_HAS_PRIVATE | JSCLASS_MARK_IS_TRACE,
     JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub,
     JS_EnumerateStub, JS_ResolveStub, 
     JavaMember_convert, JavaMember_finalize,
 
     NULL, /* getObjectOps */
     NULL, /* checkAccess */
     JavaMember_Call,
     NULL, /* construct */
     NULL, /* xdrObject */
     NULL, /* hasInstance */
-    NULL, /* mark */
+    JS_CLASS_TRACE(JavaMember_trace), /* mark/trace */
     0,    /* spare */
 };
 
 JSBool
 jsj_init_JavaMember(JSContext *cx, JSObject *global_obj)
 {
     if (!JS_InitClass(cx, global_obj, 
         0, &JavaMember_class, 0, 0,