void EventListenerService::NotifyAboutMainThreadListenerChangeInternal(dom::EventTarget* aTarget, nsAtom* aName) { MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(aTarget); if (mChangeListeners.IsEmpty()) { return; } if (!mPendingListenerChanges) { mPendingListenerChanges = nsArrayBase::Create(); nsCOMPtr<nsIRunnable> runnable = NewRunnableMethod("EventListenerService::NotifyPendingChanges", this, &EventListenerService::NotifyPendingChanges); if (nsCOMPtr<nsIGlobalObject> global = aTarget->GetOwnerGlobal()) { global->Dispatch(TaskCategory::Other, runnable.forget()); } else if (nsCOMPtr<nsINode> node = do_QueryInterface(aTarget)) { node->OwnerDoc()->Dispatch(TaskCategory::Other, runnable.forget()); } else { NS_DispatchToCurrentThread(runnable); } } RefPtr<EventListenerChange> changes = mPendingListenerChangesSet.LookupForAdd(aTarget).OrInsert( [this, aTarget] () { EventListenerChange* c = new EventListenerChange(aTarget); mPendingListenerChanges->AppendElement(c); return c; }); changes->AddChangedListenerName(aName); }
void EventListenerService::NotifyAboutMainThreadListenerChangeInternal(dom::EventTarget* aTarget, nsIAtom* aName) { MOZ_ASSERT(NS_IsMainThread()); if (mChangeListeners.IsEmpty()) { return; } if (!mPendingListenerChanges) { mPendingListenerChanges = nsArrayBase::Create(); NS_DispatchToCurrentThread(NewRunnableMethod(this, &EventListenerService::NotifyPendingChanges)); } RefPtr<EventListenerChange> changes = mPendingListenerChangesSet.Get(aTarget); if (!changes) { changes = new EventListenerChange(aTarget); mPendingListenerChanges->AppendElement(changes, false); mPendingListenerChangesSet.Put(aTarget, changes); } changes->AddChangedListenerName(aName); }