NoEventDispatchAssertion.h [plain text]
#ifndef NoEventDispatchAssertion_h
#define NoEventDispatchAssertion_h
#include <wtf/MainThread.h>
namespace WebCore {
class NoEventDispatchAssertion {
public:
NoEventDispatchAssertion()
{
#if !ASSERT_DISABLED
if (!isMainThread())
return;
++s_count;
#endif
}
NoEventDispatchAssertion(const NoEventDispatchAssertion&)
: NoEventDispatchAssertion()
{
}
~NoEventDispatchAssertion()
{
#if !ASSERT_DISABLED
if (!isMainThread())
return;
ASSERT(s_count);
s_count--;
#endif
}
static bool isEventDispatchForbidden()
{
#if ASSERT_DISABLED
return false;
#else
return isMainThread() && s_count;
#endif
}
static unsigned dropTemporarily()
{
#if ASSERT_DISABLED
return 0;
#else
unsigned count = s_count;
s_count = 0;
return count;
#endif
}
static void restoreDropped(unsigned count)
{
#if ASSERT_DISABLED
UNUSED_PARAM(count);
#else
ASSERT(!s_count);
s_count = count;
#endif
}
#if !ASSERT_DISABLED
private:
WEBCORE_EXPORT static unsigned s_count;
#endif
};
}
#endif