Bug 480975 - Make document fragments participate correctly in the wrapper cache. r+sr=jst
authorBlake Kaplan <mrbkap@gmail.com>
Fri, 20 Mar 2009 16:14:14 -0700
changeset 26432 825869c4798a0225eff37aaeaf04f505d54775ac
parent 26431 b48482c54995ef7fb8b6d6506da910a7c4d4c815
child 26433 35c8ac2aac227473785dc37366b441ad4c9634dc
push id6065
push usermrbkap@mozilla.com
push dateFri, 20 Mar 2009 23:14:30 +0000
treeherdermozilla-central@825869c4798a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs480975
milestone1.9.2a1pre
Bug 480975 - Make document fragments participate correctly in the wrapper cache. r+sr=jst
dom/base/nsDOMClassInfo.cpp
dom/base/nsDOMClassInfo.h
--- a/dom/base/nsDOMClassInfo.cpp
+++ b/dom/base/nsDOMClassInfo.cpp
@@ -632,18 +632,19 @@ static nsDOMClassInfoData sClassInfoData
   NS_DEFINE_CLASSINFO_DATA(XMLDocument, nsDocumentSH,
                            DOCUMENT_SCRIPTABLE_FLAGS)
   NS_DEFINE_CLASSINFO_DATA(DocumentType, nsNodeSH,
                            NODE_SCRIPTABLE_FLAGS)
   NS_DEFINE_CLASSINFO_DATA(DOMImplementation, nsDOMGenericSH,
                            DOM_DEFAULT_SCRIPTABLE_FLAGS)
   NS_DEFINE_CLASSINFO_DATA(DOMException, nsDOMGenericSH,
                            DOM_DEFAULT_SCRIPTABLE_FLAGS)
-  NS_DEFINE_CLASSINFO_DATA(DocumentFragment, nsDOMGenericSH,
-                           DOM_DEFAULT_SCRIPTABLE_FLAGS)
+  NS_DEFINE_CLASSINFO_DATA(DocumentFragment, nsDocumentFragmentSH,
+                           DOM_DEFAULT_SCRIPTABLE_FLAGS |
+                           nsIXPCScriptable::WANT_FINALIZE)
   NS_DEFINE_CLASSINFO_DATA(Element, nsElementSH,
                            ELEMENT_SCRIPTABLE_FLAGS)
   NS_DEFINE_CLASSINFO_DATA(Attr, nsAttributeSH,
                            NODE_SCRIPTABLE_FLAGS)
   NS_DEFINE_CLASSINFO_DATA(Text, nsNodeSH,
                            NODE_SCRIPTABLE_FLAGS)
   NS_DEFINE_CLASSINFO_DATA(Comment, nsNodeSH,
                            NODE_SCRIPTABLE_FLAGS)
@@ -7112,17 +7113,39 @@ NS_IMETHODIMP
 nsNodeSH::Finalize(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
                    JSObject *obj)
 {
   nsINode* node = static_cast<nsINode*>(wrapper->Native());
   node->ClearWrapper();
 
   return NS_OK;
 }
- 
+
+// DocumentFragment helper.
+
+NS_IMETHODIMP
+nsDocumentFragmentSH::PostCreate(nsIXPConnectWrappedNative *wrapper,
+                                 JSContext *cx, JSObject *obj)
+{
+  nsINode* node = static_cast<nsINode*>(wrapper->Native());
+  node->SetWrapper(wrapper);
+
+  return nsDOMGenericSH::PostCreate(wrapper, cx, obj);
+}
+
+NS_IMETHODIMP
+nsDocumentFragmentSH::Finalize(nsIXPConnectWrappedNative *wrapper,
+                               JSContext *cx, JSObject *obj)
+{
+  nsINode* node = static_cast<nsINode*>(wrapper->Native());
+  node->ClearWrapper();
+
+  return NS_OK;
+}
+
 // EventReceiver helper
 
 // static
 PRBool
 nsEventReceiverSH::ReallyIsEventName(jsval id, jschar aFirstChar)
 {
   // I wonder if this is faster than using a hash...
 
--- a/dom/base/nsDOMClassInfo.h
+++ b/dom/base/nsDOMClassInfo.h
@@ -349,16 +349,40 @@ protected:
   static const JSClass *sXPCNativeWrapperClass;
 
 public:
   static PRBool sDoSecurityCheckInAddProperty;
 };
 
 typedef nsDOMClassInfo nsDOMGenericSH;
 
+class nsDocumentFragmentSH : public nsDOMGenericSH
+{
+protected:
+  nsDocumentFragmentSH(nsDOMClassInfoData* aData) : nsDOMGenericSH(aData)
+  {
+  }
+
+  virtual ~nsDocumentFragmentSH()
+  {
+  }
+
+public:
+  NS_IMETHOD PostCreate(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
+                        JSObject *obj);
+  NS_IMETHOD Finalize(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
+                      JSObject *obj);
+
+  static nsIClassInfo *doCreate(nsDOMClassInfoData* aData)
+  {
+    return new nsDocumentFragmentSH(aData);
+  }
+};
+
+
 // EventProp scriptable helper, this class should be the base class of
 // all objects that should support things like
 // obj.onclick=function{...}
 
 class nsEventReceiverSH : public nsDOMGenericSH
 {
 protected:
   nsEventReceiverSH(nsDOMClassInfoData* aData) : nsDOMGenericSH(aData)