Add finalize and trace hooks
authorBen Turner <bent.mozilla@gmail.com>
Tue, 07 Feb 2012 18:43:07 -0800
changeset 86012 c22458a8e35d46f417c1b1938444c69f6d9fb2e5
parent 86011 9a987b9287c584246387b9470211b0bf2eba2312
child 86013 f1866b7282c9ff8f49341aa99f960d7bc5c6b71c
push id92
push userbturner@mozilla.com
push dateWed, 08 Feb 2012 02:43:03 +0000
milestone13.0a1
Add finalize and trace hooks
dom/bindings/Codegen.py
--- a/dom/bindings/Codegen.py
+++ b/dom/bindings/Codegen.py
@@ -37,24 +37,24 @@ DOMJSClass Class = {
     JSCLASS_IS_DOMJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(1),
     JS_PropertyStub,       /* addProperty */
     JS_PropertyStub,       /* delProperty */
     JS_PropertyStub,       /* getProperty */
     JS_StrictPropertyStub, /* setProperty */
     JS_EnumerateStub,
     JS_ResolveStub,
     JS_ConvertStub,
-    NULL,                  /* finalize */
+    _finalize,
     NULL,                  /* reserved0 */
     NULL,                  /* checkAccess */
     NULL,                  /* call */
     NULL,                  /* construct */
     NULL,                  /* xdrObject */
     NULL,                  /* hasInstance */
-    NULL,                  /* trace */
+    _trace,
     NULL                   /* reserved1 */
   },
   { %s }, -1, %s
 };
 """ % (self.descriptor.interface.identifier.name, prototypeChainString,
        str(self.descriptor.nativeIsISupports).lower())
 
 class CGPrototypeJSClass(CGThing):
@@ -548,25 +548,58 @@ class SetterCall(GetterSetterCall):
 class CGAbstractBindingMethod(CGAbstractStaticMethod):
     def __init__(self, descriptor, name, returnType, args):
         CGAbstractStaticMethod.__init__(self, descriptor, name,
                                         returnType, args)
     def definition_body(self):
         return (self.unwrap_this() + self.generate_code())
 
     def unwrap_this(self):
+        returnStr = ' false' if self.returnType == 'JSBool' else ''
         return """
   %s *self;
   if (!UnwrapThis(cx, obj, %s, %s, &self))
-    return false;
+    return%s;
+""" % (self.descriptor.nativeClass, "id::" + self.descriptor.name,
+       "depth::" + self.descriptor.name, returnStr)
+
+    def generate_code(self):
+        assert(False) # Override me
+
+class CGClassFinalizeMethod(CGAbstractBindingMethod):
+    def __init__(self, descriptor):
+        args = [Argument('JSContext*', 'cx'), Argument('JSObject*', 'obj')]
+        CGAbstractBindingMethod.__init__(self, descriptor, '_finalize', 'void',
+                                         args)
+
+    def generate_code(self):
+        return """
+#if 0
+  self->%s(%s);
+#endif""" % (self.name, ', '.join([str(a.name) for a in self.args]))
+
+class CGClassTraceMethod(CGAbstractBindingMethod):
+    def __init__(self, descriptor):
+        args = [Argument('JSTracer*', 'trc'), Argument('JSObject*', 'obj')]
+        CGAbstractBindingMethod.__init__(self, descriptor, '_trace', 'void',
+                                         args)
+
+    def unwrap_this(self):
+        return """
+  %s *self;
+  if (!UnwrapThis(trc->context, obj, %s, %s, &self))
+    return;
 """ % (self.descriptor.nativeClass, "id::" + self.descriptor.name,
        "depth::" + self.descriptor.name)
 
     def generate_code(self):
-        assert(False) # Override me
+        return """
+#if 0
+  self->%s(%s);
+#endif""" % (self.name, ', '.join([str(a.name) for a in self.args]))
 
 def MakeNativeName(name):
     return name[0].upper() + name[1:]
 
 class CGNativeMethod(CGAbstractBindingMethod):
     def __init__(self, descriptor, method):
         self.method = method
         args = [Argument('JSContext*', 'cx'), Argument('uintN', 'argc'),
@@ -626,16 +659,19 @@ class CGDescriptor(CGThing):
         # XXXbholley - Not everything should actually have a jsclass.
         cgThings = [CGNativeMethod(descriptor, m) for m in
                     descriptor.interface.members if m.isMethod()]
         cgThings.extend([CGNativeGetter(descriptor, a) for a in
                          descriptor.interface.members if a.isAttr()])
         cgThings.extend([CGNativeSetter(descriptor, a) for a in
                          descriptor.interface.members if
                          a.isAttr() and not a.readonly])
+        cgThings.extend([CGClassFinalizeMethod(descriptor)])
+        cgThings.extend([CGClassTraceMethod(descriptor)])
+
         # XXXbz this should check for [NoInterfaceObject]
         if True:
             cgThings.append(CGConstructorJSClass(descriptor))
         cgThings.extend([CGDOMJSClass(descriptor),
                          CGPrototypeJSClass(descriptor),
                          CGCreateProtoObjectMethod(descriptor),
                          CGGetProtoObjectMethod(descriptor)])