From 1c4f38a7c3b8b8d9ac18e18217e2ea4aae53de44 Mon Sep 17 00:00:00 2001 From: Gavin Sharp Date: Wed, 21 Aug 2013 16:45:52 -0700 Subject: [PATCH] Bug 907430: XBL constructors/destructors should have names, r=bz --HG-- extra : transplant_source : G%E8%B6%A4%9D%E3%A2%F8C%81%1Dc%3E%FC%CD%13%5Ea%8A%E0 --- content/xbl/src/nsXBLContentSink.cpp | 25 ++++++++++++++++++------ content/xbl/src/nsXBLContentSink.h | 2 ++ content/xbl/src/nsXBLProtoImpl.cpp | 12 ++++++++++-- content/xbl/src/nsXBLProtoImplMethod.cpp | 3 +++ content/xbl/src/nsXBLProtoImplMethod.h | 4 ++-- content/xbl/src/nsXBLSerialize.h | 2 +- 6 files changed, 37 insertions(+), 11 deletions(-) diff --git a/content/xbl/src/nsXBLContentSink.cpp b/content/xbl/src/nsXBLContentSink.cpp index 10f0273f08e8..cda14c82e6d0 100644 --- a/content/xbl/src/nsXBLContentSink.cpp +++ b/content/xbl/src/nsXBLContentSink.cpp @@ -54,7 +54,7 @@ nsXBLContentSink::nsXBLContentSink() mSecondaryState(eXBL_None), mDocInfo(nullptr), mIsChromeOrResource(false), - mFoundFirstBinding(false), + mFoundFirstBinding(false), mBinding(nullptr), mHandler(nullptr), mImplementation(nullptr), @@ -453,8 +453,15 @@ nsXBLContentSink::OnOpenContainer(const PRUnichar **aAtts, NS_ASSERTION(mBinding, "Must have binding here"); mSecondaryState = eXBL_InConstructor; + nsAutoString name; + if (!mCurrentBindingID.IsEmpty()) { + name.Assign(mCurrentBindingID); + name.AppendLiteral("_XBL_Constructor"); + } else { + name.AppendLiteral("XBL_Constructor"); + } nsXBLProtoImplAnonymousMethod* newMethod = - new nsXBLProtoImplAnonymousMethod(); + new nsXBLProtoImplAnonymousMethod(name.get()); if (newMethod) { newMethod->SetLineNumber(aLineNumber); mBinding->SetConstructor(newMethod); @@ -466,8 +473,15 @@ nsXBLContentSink::OnOpenContainer(const PRUnichar **aAtts, mSecondaryState == eXBL_None); NS_ASSERTION(mBinding, "Must have binding here"); mSecondaryState = eXBL_InDestructor; + nsAutoString name; + if (!mCurrentBindingID.IsEmpty()) { + name.Assign(mCurrentBindingID); + name.AppendLiteral("_XBL_Destructor"); + } else { + name.AppendLiteral("XBL_Destructor"); + } nsXBLProtoImplAnonymousMethod* newMethod = - new nsXBLProtoImplAnonymousMethod(); + new nsXBLProtoImplAnonymousMethod(name.get()); if (newMethod) { newMethod->SetLineNumber(aLineNumber); mBinding->SetDestructor(newMethod); @@ -529,9 +543,8 @@ nsresult nsXBLContentSink::ConstructBinding(uint32_t aLineNumber) { nsCOMPtr binding = GetCurrentContent(); - nsAutoString id; - binding->GetAttr(kNameSpaceID_None, nsGkAtoms::id, id); - NS_ConvertUTF16toUTF8 cid(id); + binding->GetAttr(kNameSpaceID_None, nsGkAtoms::id, mCurrentBindingID); + NS_ConvertUTF16toUTF8 cid(mCurrentBindingID); nsresult rv = NS_OK; diff --git a/content/xbl/src/nsXBLContentSink.h b/content/xbl/src/nsXBLContentSink.h index 75cd6dd851da..d0dd382aaca9 100644 --- a/content/xbl/src/nsXBLContentSink.h +++ b/content/xbl/src/nsXBLContentSink.h @@ -135,6 +135,8 @@ protected: bool mIsChromeOrResource; // For bug #45989 bool mFoundFirstBinding; + nsString mCurrentBindingID; + nsXBLPrototypeBinding* mBinding; nsXBLPrototypeHandler* mHandler; // current handler, owned by its PrototypeBinding nsXBLProtoImpl* mImplementation; diff --git a/content/xbl/src/nsXBLProtoImpl.cpp b/content/xbl/src/nsXBLProtoImpl.cpp index 6025464f404e..07cd1df16417 100644 --- a/content/xbl/src/nsXBLProtoImpl.cpp +++ b/content/xbl/src/nsXBLProtoImpl.cpp @@ -397,7 +397,11 @@ nsXBLProtoImpl::Read(nsIObjectInputStream* aStream, } case XBLBinding_Serialize_Constructor: { - mConstructor = new nsXBLProtoImplAnonymousMethod(); + nsAutoString name; + rv = aStream->ReadString(name); + NS_ENSURE_SUCCESS(rv, rv); + + mConstructor = new nsXBLProtoImplAnonymousMethod(name.get()); rv = mConstructor->Read(aStream); if (NS_FAILED(rv)) { delete mConstructor; @@ -410,7 +414,11 @@ nsXBLProtoImpl::Read(nsIObjectInputStream* aStream, } case XBLBinding_Serialize_Destructor: { - mDestructor = new nsXBLProtoImplAnonymousMethod(); + nsAutoString name; + rv = aStream->ReadString(name); + NS_ENSURE_SUCCESS(rv, rv); + + mDestructor = new nsXBLProtoImplAnonymousMethod(name.get()); rv = mDestructor->Read(aStream); if (NS_FAILED(rv)) { delete mDestructor; diff --git a/content/xbl/src/nsXBLProtoImplMethod.cpp b/content/xbl/src/nsXBLProtoImplMethod.cpp index 5c5ba1075217..69473738d706 100644 --- a/content/xbl/src/nsXBLProtoImplMethod.cpp +++ b/content/xbl/src/nsXBLProtoImplMethod.cpp @@ -372,6 +372,9 @@ nsXBLProtoImplAnonymousMethod::Write(nsIObjectOutputStream* aStream, nsresult rv = aStream->Write8(aType); NS_ENSURE_SUCCESS(rv, rv); + rv = aStream->WriteWStringZ(mName); + NS_ENSURE_SUCCESS(rv, rv); + // Calling fromMarkedLocation() is safe because mMethod is traced by the // Trace() method above, and because its value is never changed after it has // been set to a compiled method. diff --git a/content/xbl/src/nsXBLProtoImplMethod.h b/content/xbl/src/nsXBLProtoImplMethod.h index f5a2152d8bce..ec24b4b2df92 100644 --- a/content/xbl/src/nsXBLProtoImplMethod.h +++ b/content/xbl/src/nsXBLProtoImplMethod.h @@ -131,8 +131,8 @@ protected: class nsXBLProtoImplAnonymousMethod : public nsXBLProtoImplMethod { public: - nsXBLProtoImplAnonymousMethod() : - nsXBLProtoImplMethod(EmptyString().get()) + nsXBLProtoImplAnonymousMethod(const PRUnichar* aName) : + nsXBLProtoImplMethod(aName) {} nsresult Execute(nsIContent* aBoundElement); diff --git a/content/xbl/src/nsXBLSerialize.h b/content/xbl/src/nsXBLSerialize.h index 26e3e259e3f2..74d30a6abdc1 100644 --- a/content/xbl/src/nsXBLSerialize.h +++ b/content/xbl/src/nsXBLSerialize.h @@ -16,7 +16,7 @@ typedef uint8_t XBLBindingSerializeDetails; // A version number to ensure we don't load cached data in a different // file format. -#define XBLBinding_Serialize_Version 0x00000001 +#define XBLBinding_Serialize_Version 0x00000002 // Set for the first binding in a document #define XBLBinding_Serialize_IsFirstBinding 1