Bug 812617 - Provide a JSBindingFinalized hook for the native classes using Web IDL bindings to know when their JS wrapper has been finalized; r=bzbarsky
authorPeter Van der Beken <peterv@propagandism.org>
Sun, 17 Mar 2013 21:47:12 -0400
changeset 125357 ea947ec162a17ce543e6b2a7edebacc9ccf9729c
parent 125356 4f119b3f804681f10a5ad9f42cfcf6aec3dcd4a1
child 125358 20247b8020f18071bbf2c0f0cdfb25b1ac7c2686
push id24889
push usereakhgari@mozilla.com
push dateTue, 19 Mar 2013 03:41:50 +0000
treeherdermozilla-inbound@20247b8020f1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbzbarsky
bugs812617
milestone22.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 812617 - Provide a JSBindingFinalized hook for the native classes using Web IDL bindings to know when their JS wrapper has been finalized; r=bzbarsky
dom/bindings/BindingUtils.h
dom/bindings/Codegen.py
--- a/dom/bindings/BindingUtils.h
+++ b/dom/bindings/BindingUtils.h
@@ -1662,16 +1662,35 @@ void SetXrayExpandoChain(JSObject *obj, 
  * pre is a string that should be prefixed to the value.
  * post is a string that should be prefixed to the value.
  * v contains the JSString for the value if the function returns true.
  */
 bool
 NativeToString(JSContext* cx, JSObject* wrapper, JSObject* obj, const char* pre,
                const char* post, JS::Value* v);
 
+HAS_MEMBER(JSBindingFinalized)
+
+template<class T, bool hasCallback=HasJSBindingFinalizedMember<T>::Value>
+struct JSBindingFinalized
+{
+  static void Finalized(T* self)
+  {
+  }
+};
+
+template<class T>
+struct JSBindingFinalized<T, true>
+{
+  static void Finalized(T* self)
+  {
+    self->JSBindingFinalized();
+  }
+};
+
 nsresult
 ReparentWrapper(JSContext* aCx, JSObject* aObj);
 
 /**
  * Used to implement the hasInstance hook of an interface object.
  *
  * instance should not be a security wrapper.
  */
--- a/dom/bindings/Codegen.py
+++ b/dom/bindings/Codegen.py
@@ -914,17 +914,18 @@ class CGDeferredFinalize(CGAbstractStati
     return true;
   }
   return false;""" % { 'smartPtr': smartPtr }
 
 def finalizeHook(descriptor, hookName, context):
     if descriptor.customFinalize:
         finalize = "self->%s(%s);" % (hookName, context)
     else:
-        finalize = "ClearWrapper(self, self);\n" if descriptor.wrapperCache else ""
+        finalize = "JSBindingFinalized<%s>::Finalized(self);\n" % descriptor.nativeType
+        finalize += "ClearWrapper(self, self);\n" if descriptor.wrapperCache else ""
         if descriptor.workers:
             finalize += "self->Release();"
         elif descriptor.nativeOwnership == 'nsisupports':
             finalize += """XPCJSRuntime *rt = nsXPConnect::GetRuntimeInstance();
 if (rt) {
   rt->DeferredRelease(reinterpret_cast<nsISupports*>(self));
 } else {
   NS_RELEASE(self);