wasn't going to check in this

This commit is contained in:
Olli.Pettay@helsinki.fi 2007-06-26 21:25:27 -07:00
parent 1ed587d4b9
commit 3c59bb5998

View File

@ -840,38 +840,36 @@ nsBindingManager::ProcessAttachedQueue()
mAttachedStack.Compact();
}
// Keep bindings and bound elements alive while executing detached handlers.
struct BindingTableReadClosure
{
nsCOMArray<nsIContent> 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);
}
}