Bug 1673837 - Part 1: Create nsDOMMutationEnterLeave RAII class r=smaug

Differential Revision: https://phabricator.services.mozilla.com/D95352
This commit is contained in:
Kagami Sascha Rosylight 2020-11-09 15:51:25 +00:00
Родитель 95066793fc
Коммит f34f7cb3e7
2 изменённых файлов: 20 добавлений и 14 удалений

Просмотреть файл

@ -60,10 +60,7 @@ enum class IsRemoveNotification {
// |Document* doc|
#define IMPL_MUTATION_NOTIFICATION(func_, content_, params_, remove_) \
PR_BEGIN_MACRO \
bool needsEnterLeave = doc->MayHaveDOMMutationObservers(); \
if (needsEnterLeave) { \
nsDOMMutationObserver::EnterMutationHandling(); \
} \
nsDOMMutationEnterLeave enterLeave(doc); \
nsINode* node = content_; \
COMPOSED_DOC_DECL \
NS_ASSERTION(node->OwnerDoc() == doc, "Bogus document"); \
@ -98,17 +95,11 @@ enum class IsRemoveNotification {
presShell->func_ params_; \
} \
} \
if (needsEnterLeave) { \
nsDOMMutationObserver::LeaveMutationHandling(); \
} \
PR_END_MACRO
#define IMPL_ANIMATION_NOTIFICATION(func_, content_, params_) \
PR_BEGIN_MACRO \
bool needsEnterLeave = doc->MayHaveDOMMutationObservers(); \
if (needsEnterLeave) { \
nsDOMMutationObserver::EnterMutationHandling(); \
} \
nsDOMMutationEnterLeave enterLeave(doc); \
nsINode* node = content_; \
do { \
nsINode::nsSlots* slots = node->GetExistingSlots(); \
@ -122,9 +113,6 @@ enum class IsRemoveNotification {
node = node->GetParentNode(); \
} \
} while (node); \
if (needsEnterLeave) { \
nsDOMMutationObserver::LeaveMutationHandling(); \
} \
PR_END_MACRO
namespace mozilla {

Просмотреть файл

@ -875,4 +875,22 @@ inline nsDOMMutationObserver* nsMutationReceiverBase::Observer() {
: static_cast<nsDOMMutationObserver*>(mObserver);
}
class MOZ_RAII nsDOMMutationEnterLeave {
public:
explicit nsDOMMutationEnterLeave(mozilla::dom::Document* aDoc)
: mNeeded(aDoc->MayHaveDOMMutationObservers()) {
if (mNeeded) {
nsDOMMutationObserver::EnterMutationHandling();
}
}
~nsDOMMutationEnterLeave() {
if (mNeeded) {
nsDOMMutationObserver::LeaveMutationHandling();
}
}
private:
const bool mNeeded;
};
#endif