зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1645339 - Use range-based for with nsTObserverArray in xpcom. r=froydnj
Differential Revision: https://phabricator.services.mozilla.com/D79484
This commit is contained in:
Родитель
1a13e8aef8
Коммит
298981065e
|
@ -58,49 +58,49 @@ enum class IsRemoveNotification {
|
|||
|
||||
// This macro expects the ownerDocument of content_ to be in scope as
|
||||
// |Document* doc|
|
||||
#define IMPL_MUTATION_NOTIFICATION(func_, content_, params_, remove_) \
|
||||
PR_BEGIN_MACRO \
|
||||
bool needsEnterLeave = doc->MayHaveDOMMutationObservers(); \
|
||||
if (needsEnterLeave) { \
|
||||
nsDOMMutationObserver::EnterMutationHandling(); \
|
||||
} \
|
||||
nsINode* node = content_; \
|
||||
COMPOSED_DOC_DECL \
|
||||
NS_ASSERTION(node->OwnerDoc() == doc, "Bogus document"); \
|
||||
if (remove_ == IsRemoveNotification::Yes && node->GetComposedDoc()) { \
|
||||
if (PresShell* presShell = doc->GetObservingPresShell()) { \
|
||||
presShell->func_ params_; \
|
||||
} \
|
||||
} \
|
||||
CALL_BINDING_MANAGER(func_, params_); \
|
||||
nsINode* last; \
|
||||
do { \
|
||||
nsINode::nsSlots* slots = node->GetExistingSlots(); \
|
||||
if (slots && !slots->mMutationObservers.IsEmpty()) { \
|
||||
NS_OBSERVER_AUTO_ARRAY_NOTIFY_OBSERVERS( \
|
||||
slots->mMutationObservers, nsIMutationObserver, 1, func_, params_); \
|
||||
} \
|
||||
last = node; \
|
||||
if (ShadowRoot* shadow = ShadowRoot::FromNode(node)) { \
|
||||
node = shadow->GetHost(); \
|
||||
} else { \
|
||||
node = node->GetParentNode(); \
|
||||
} \
|
||||
} while (node); \
|
||||
/* Whitelist NativeAnonymousChildListChange removal notifications from \
|
||||
* the assertion since it runs from UnbindFromTree, and thus we don't \
|
||||
* reach the document, but doesn't matter. */ \
|
||||
MOZ_ASSERT((last == doc) == wasInComposedDoc || \
|
||||
(remove_ == IsRemoveNotification::Yes && \
|
||||
!strcmp(#func_, "NativeAnonymousChildListChange"))); \
|
||||
if (remove_ == IsRemoveNotification::No && last == doc) { \
|
||||
if (PresShell* presShell = doc->GetObservingPresShell()) { \
|
||||
presShell->func_ params_; \
|
||||
} \
|
||||
} \
|
||||
if (needsEnterLeave) { \
|
||||
nsDOMMutationObserver::LeaveMutationHandling(); \
|
||||
} \
|
||||
#define IMPL_MUTATION_NOTIFICATION(func_, content_, params_, remove_) \
|
||||
PR_BEGIN_MACRO \
|
||||
bool needsEnterLeave = doc->MayHaveDOMMutationObservers(); \
|
||||
if (needsEnterLeave) { \
|
||||
nsDOMMutationObserver::EnterMutationHandling(); \
|
||||
} \
|
||||
nsINode* node = content_; \
|
||||
COMPOSED_DOC_DECL \
|
||||
NS_ASSERTION(node->OwnerDoc() == doc, "Bogus document"); \
|
||||
if (remove_ == IsRemoveNotification::Yes && node->GetComposedDoc()) { \
|
||||
if (PresShell* presShell = doc->GetObservingPresShell()) { \
|
||||
presShell->func_ params_; \
|
||||
} \
|
||||
} \
|
||||
CALL_BINDING_MANAGER(func_, params_); \
|
||||
nsINode* last; \
|
||||
do { \
|
||||
nsINode::nsSlots* slots = node->GetExistingSlots(); \
|
||||
if (slots && !slots->mMutationObservers.IsEmpty()) { \
|
||||
NS_OBSERVER_ARRAY_NOTIFY_OBSERVERS(slots->mMutationObservers, \
|
||||
nsIMutationObserver, func_, params_); \
|
||||
} \
|
||||
last = node; \
|
||||
if (ShadowRoot* shadow = ShadowRoot::FromNode(node)) { \
|
||||
node = shadow->GetHost(); \
|
||||
} else { \
|
||||
node = node->GetParentNode(); \
|
||||
} \
|
||||
} while (node); \
|
||||
/* Whitelist NativeAnonymousChildListChange removal notifications from \
|
||||
* the assertion since it runs from UnbindFromTree, and thus we don't \
|
||||
* reach the document, but doesn't matter. */ \
|
||||
MOZ_ASSERT((last == doc) == wasInComposedDoc || \
|
||||
(remove_ == IsRemoveNotification::Yes && \
|
||||
!strcmp(#func_, "NativeAnonymousChildListChange"))); \
|
||||
if (remove_ == IsRemoveNotification::No && last == doc) { \
|
||||
if (PresShell* presShell = doc->GetObservingPresShell()) { \
|
||||
presShell->func_ params_; \
|
||||
} \
|
||||
} \
|
||||
if (needsEnterLeave) { \
|
||||
nsDOMMutationObserver::LeaveMutationHandling(); \
|
||||
} \
|
||||
PR_END_MACRO
|
||||
|
||||
#define IMPL_ANIMATION_NOTIFICATION(func_, content_, params_) \
|
||||
|
@ -113,8 +113,8 @@ enum class IsRemoveNotification {
|
|||
do { \
|
||||
nsINode::nsSlots* slots = node->GetExistingSlots(); \
|
||||
if (slots && !slots->mMutationObservers.IsEmpty()) { \
|
||||
NS_OBSERVER_AUTO_ARRAY_NOTIFY_OBSERVERS_WITH_QI( \
|
||||
slots->mMutationObservers, nsIMutationObserver, 1, \
|
||||
NS_OBSERVER_ARRAY_NOTIFY_OBSERVERS_WITH_QI( \
|
||||
slots->mMutationObservers, nsIMutationObserver, \
|
||||
nsIAnimationObserver, func_, params_); \
|
||||
} \
|
||||
if (ShadowRoot* shadow = ShadowRoot::FromNode(node)) { \
|
||||
|
|
|
@ -121,9 +121,9 @@ class MutationObservers {
|
|||
static inline void NotifyParentChainChanged(nsIContent* aContent) {
|
||||
nsINode::nsSlots* slots = aContent->GetExistingSlots();
|
||||
if (slots && !slots->mMutationObservers.IsEmpty()) {
|
||||
NS_OBSERVER_AUTO_ARRAY_NOTIFY_OBSERVERS(slots->mMutationObservers,
|
||||
nsIMutationObserver, 1,
|
||||
ParentChainChanged, (aContent));
|
||||
NS_OBSERVER_ARRAY_NOTIFY_OBSERVERS(slots->mMutationObservers,
|
||||
nsIMutationObserver,
|
||||
ParentChainChanged, (aContent));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -623,9 +623,9 @@ void nsINode::LastRelease() {
|
|||
nsINode::nsSlots* slots = GetExistingSlots();
|
||||
if (slots) {
|
||||
if (!slots->mMutationObservers.IsEmpty()) {
|
||||
NS_OBSERVER_AUTO_ARRAY_NOTIFY_OBSERVERS(slots->mMutationObservers,
|
||||
nsIMutationObserver, 1,
|
||||
NodeWillBeDestroyed, (this));
|
||||
NS_OBSERVER_ARRAY_NOTIFY_OBSERVERS(slots->mMutationObservers,
|
||||
nsIMutationObserver,
|
||||
NodeWillBeDestroyed, (this));
|
||||
}
|
||||
|
||||
delete slots;
|
||||
|
|
|
@ -62,9 +62,7 @@ class ObserverList {
|
|||
* Call Notify() on each item in the list.
|
||||
*/
|
||||
void Broadcast(const T& aParam) {
|
||||
typename nsTObserverArray<Observer<T>*>::ForwardIterator iter(mObservers);
|
||||
while (iter.HasMore()) {
|
||||
Observer<T>* obs = iter.GetNext();
|
||||
for (Observer<T>* obs : mObservers.ForwardRange()) {
|
||||
obs->Notify(aParam);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -547,10 +547,7 @@ inline void ImplCycleCollectionTraverse(
|
|||
#define NS_OBSERVER_ARRAY_NOTIFY_XPCOM_OBSERVERS(array_, obstype_, func_, \
|
||||
params_) \
|
||||
do { \
|
||||
nsTObserverArray<obstype_*>::ForwardIterator iter_(array_); \
|
||||
RefPtr<obstype_> obs_; \
|
||||
while (iter_.HasMore()) { \
|
||||
obs_ = iter_.GetNext(); \
|
||||
for (RefPtr<obstype_> obs_ : array_.ForwardRange()) { \
|
||||
obs_->func_ params_; \
|
||||
} \
|
||||
} while (0)
|
||||
|
@ -558,33 +555,15 @@ inline void ImplCycleCollectionTraverse(
|
|||
// Note that this macro only works if the array holds pointers to XPCOM objects.
|
||||
#define NS_OBSERVER_ARRAY_NOTIFY_OBSERVERS(array_, obstype_, func_, params_) \
|
||||
do { \
|
||||
nsTObserverArray<obstype_*>::ForwardIterator iter_(array_); \
|
||||
obstype_* obs_; \
|
||||
while (iter_.HasMore()) { \
|
||||
obs_ = iter_.GetNext(); \
|
||||
for (obstype_ * obs_ : array_.ForwardRange()) { \
|
||||
obs_->func_ params_; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
// Note that this macro only works if the array holds pointers to XPCOM objects.
|
||||
#define NS_OBSERVER_AUTO_ARRAY_NOTIFY_OBSERVERS(array_, obstype_, num_, func_, \
|
||||
params_) \
|
||||
do { \
|
||||
nsAutoTObserverArray<obstype_*, num_>::ForwardIterator iter_(array_); \
|
||||
obstype_* obs_; \
|
||||
while (iter_.HasMore()) { \
|
||||
obs_ = iter_.GetNext(); \
|
||||
obs_->func_ params_; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define NS_OBSERVER_ARRAY_NOTIFY_OBSERVERS_WITH_QI(array_, basetype_, \
|
||||
obstype_, func_, params_) \
|
||||
do { \
|
||||
nsTObserverArray<basetype_*>::ForwardIterator iter_(array_); \
|
||||
basetype_* obsbase_; \
|
||||
while (iter_.HasMore()) { \
|
||||
obsbase_ = iter_.GetNext(); \
|
||||
for (basetype_ * obsbase_ : array_.ForwardRange()) { \
|
||||
nsCOMPtr<obstype_> obs_ = do_QueryInterface(obsbase_); \
|
||||
if (obs_) { \
|
||||
obs_->func_ params_; \
|
||||
|
@ -592,17 +571,4 @@ inline void ImplCycleCollectionTraverse(
|
|||
} \
|
||||
} while (0)
|
||||
|
||||
#define NS_OBSERVER_AUTO_ARRAY_NOTIFY_OBSERVERS_WITH_QI( \
|
||||
array_, basetype_, num_, obstype_, func_, params_) \
|
||||
do { \
|
||||
nsAutoTObserverArray<basetype_*, num_>::ForwardIterator iter_(array_); \
|
||||
basetype_* obsbase_; \
|
||||
while (iter_.HasMore()) { \
|
||||
obsbase_ = iter_.GetNext(); \
|
||||
nsCOMPtr<obstype_> obs_ = do_QueryInterface(obsbase_); \
|
||||
if (obs_) { \
|
||||
obs_->func_ params_; \
|
||||
} \
|
||||
} \
|
||||
} while (0)
|
||||
#endif // nsTObserverArray_h___
|
||||
|
|
|
@ -980,17 +980,13 @@ void canary_alarm_handler(int signum) {
|
|||
|
||||
#endif
|
||||
|
||||
#define NOTIFY_EVENT_OBSERVERS(observers_, func_, params_) \
|
||||
do { \
|
||||
if (!observers_.IsEmpty()) { \
|
||||
nsTObserverArray<nsCOMPtr<nsIThreadObserver>>::ForwardIterator iter_( \
|
||||
observers_); \
|
||||
nsCOMPtr<nsIThreadObserver> obs_; \
|
||||
while (iter_.HasMore()) { \
|
||||
obs_ = iter_.GetNext(); \
|
||||
obs_->func_ params_; \
|
||||
} \
|
||||
} \
|
||||
#define NOTIFY_EVENT_OBSERVERS(observers_, func_, params_) \
|
||||
do { \
|
||||
if (!observers_.IsEmpty()) { \
|
||||
for (nsCOMPtr<nsIThreadObserver> obs_ : observers_.ForwardRange()) { \
|
||||
obs_->func_ params_; \
|
||||
} \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#ifdef MOZ_COLLECTING_RUNNABLE_TELEMETRY
|
||||
|
|
Загрузка…
Ссылка в новой задаче