From 3c59bb599807724453682343ce3a0d2e9487ae55 Mon Sep 17 00:00:00 2001 From: "Olli.Pettay@helsinki.fi" Date: Tue, 26 Jun 2007 21:25:27 -0700 Subject: [PATCH] wasn't going to check in this --- content/xbl/src/nsBindingManager.cpp | 40 +++++++++++++--------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/content/xbl/src/nsBindingManager.cpp b/content/xbl/src/nsBindingManager.cpp index 2d7696b8458c..5ebf6e288606 100644 --- a/content/xbl/src/nsBindingManager.cpp +++ b/content/xbl/src/nsBindingManager.cpp @@ -840,38 +840,36 @@ nsBindingManager::ProcessAttachedQueue() mAttachedStack.Compact(); } -// Keep bindings and bound elements alive while executing detached handlers. -struct BindingTableReadClosure -{ - nsCOMArray mBoundElements; - nsBindingList mBindings; -}; - PR_STATIC_CALLBACK(PLDHashOperator) AccumulateBindingsToDetach(nsISupports *aKey, nsXBLBinding *aBinding, - void* aClosure) + void* aVoidArray) { - BindingTableReadClosure* closure = - NS_STATIC_CAST(BindingTableReadClosure*, aClosure); - if (aBinding && closure->mBindings.AppendElement(aBinding)) { - if (!closure->mBoundElements.AppendObject(aBinding->GetBoundElement())) { - closure->mBindings.RemoveElementAt(closure->mBindings.Length() - 1); - } - } + nsVoidArray* arr = NS_STATIC_CAST(nsVoidArray*, aVoidArray); + // Hold an owning reference to this binding, just in case + if (arr->AppendElement(aBinding)) + NS_ADDREF(aBinding); return PL_DHASH_NEXT; } +PR_STATIC_CALLBACK(PRBool) +ExecuteDetachedHandler(void* aBinding, void* aClosure) +{ + NS_PRECONDITION(aBinding, "Null binding in list?"); + nsXBLBinding* binding = NS_STATIC_CAST(nsXBLBinding*, aBinding); + binding->ExecuteDetachedHandler(); + // Drop our ref to the binding now + NS_RELEASE(binding); + return PR_TRUE; +} + void nsBindingManager::ExecuteDetachedHandlers() { // Walk our hashtable of bindings. if (mBindingTable.IsInitialized()) { - BindingTableReadClosure closure; - mBindingTable.EnumerateRead(AccumulateBindingsToDetach, &closure); - PRUint32 i, count = closure.mBindings.Length(); - for (i = 0; i < count; ++i) { - closure.mBindings[i]->ExecuteDetachedHandler(); - } + nsVoidArray bindingsToDetach; + mBindingTable.EnumerateRead(AccumulateBindingsToDetach, &bindingsToDetach); + bindingsToDetach.EnumerateForwards(ExecuteDetachedHandler, nsnull); } }