Fix for bug 818219 (Replace HTMLElement quickstubs with new binding methods) - Add a constructor to callbacks to allow conversion between callback types. r=bz.
authorPeter Van der Beken <peterv@propagandism.org>
Thu, 06 Dec 2012 11:41:14 +0100
changeset 125061 f23cff8ec6c9ab4cac0c4582967647140855a625
parent 125060 92187bc8ec482fc7b86992d45946f77a8eb6de25
child 125062 79fc9d732bf7778dd90cfcc08d5e38bc452aa5b8
push id297
push userlsblakk@mozilla.com
push dateTue, 26 Mar 2013 17:28:00 +0000
treeherdermozilla-release@64d7b45c34e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs818219
milestone20.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
Fix for bug 818219 (Replace HTMLElement quickstubs with new binding methods) - Add a constructor to callbacks to allow conversion between callback types. r=bz.
dom/bindings/CallbackFunction.h
dom/bindings/Codegen.py
--- a/dom/bindings/CallbackFunction.h
+++ b/dom/bindings/CallbackFunction.h
@@ -83,16 +83,26 @@ public:
 
   bool HasGrayCallable() const
   {
     // Play it safe in case this gets called after unlink.
     return mCallable && xpc_IsGrayGCThing(mCallable);
   }
 
 protected:
+  explicit CallbackFunction(CallbackFunction* aCallbackFunction)
+    : mCallable(aCallbackFunction->mCallable)
+  {
+    // Set mCallable before we hold, on the off chance that a GC could somehow
+    // happen in there... (which would be pretty odd, granted).
+    // Make sure we'll be able to drop as needed
+    nsLayoutStatics::AddRef();
+    NS_HOLD_JS_OBJECTS(this, CallbackFunction);
+  }
+
   void DropCallback()
   {
     if (mCallable) {
       mCallable = nullptr;
       NS_DROP_JS_OBJECTS(this, CallbackFunction);
       nsLayoutStatics::Release();
     }
   }
--- a/dom/bindings/Codegen.py
+++ b/dom/bindings/Codegen.py
@@ -7373,17 +7373,17 @@ class CGCallbackFunction(CGClass):
             # same return type as what CallCallback generates.  So we want to
             # take advantage of all its CGNativeMember infrastructure, but that
             # infrastructure can't deal with templates and most especially
             # template arguments.  So just cheat and have CallCallback compute
             # all those things for us.
             callCallback = CallCallback(callback, descriptorProvider)
             CGClass.__init__(self, name,
                              bases=[ClassBase("CallbackFunction")],
-                             constructors=[self.getConstructor()],
+                             constructors=self.getConstructors(),
                              methods=self.getCallImpls(callCallback))
             self.generatable = True
         except NoSuchDescriptorError, err:
             if not descriptorProvider.workers:
                 raise err
             self.generatable = False
 
     def define(self):
@@ -7391,28 +7391,36 @@ class CGCallbackFunction(CGClass):
             return ""
         return CGClass.define(self)
 
     def declare(self):
         if not self.generatable:
             return ""
         return CGClass.declare(self)
 
-    def getConstructor(self):
-        return ClassConstructor(
+    def getConstructors(self):
+        return [ClassConstructor(
             [Argument("JSContext*", "cx"),
              Argument("JSObject*", "aOwner"),
              Argument("JSObject*", "aCallable"),
              Argument("bool*", "aInited")],
             bodyInHeader=True,
             visibility="public",
             baseConstructors=[
                 "CallbackFunction(cx, aOwner, aCallable, aInited)"
                 ],
-            body="")
+            body=""),
+            ClassConstructor(
+            [Argument("CallbackFunction*", "aOther")],
+            bodyInHeader=True,
+            visibility="public",
+            baseConstructors=[
+                "CallbackFunction(aOther)"
+                ],
+            body="")]
 
     def getCallImpls(self, callCallback):
         args = list(callCallback.args)
         # Strip out the JSContext*/JSObject* args
         # that got added.
         assert args[0].name == "cx" and args[0].argType == "JSContext*"
         assert args[1].name == "aThisObj" and args[1].argType == "JSObject*"
         args = args[2:]