DOMTimer::m_nestingLevel is prone to overflow
https://bugs.webkit.org/show_bug.cgi?id=136399

Reviewed by Alexey Proskuryakov.

Since this would happen after the 2 billionth timer fire this is unlikely,
and consequences aren't severe (breaks throttling).

This change has the following consequences.

    - m_nestingLevel saturates to its max value.
    - unnested timers are indicated by a nesting level of 0.
    - repeat timers update m_nestingLevel on every fire,
      not just those that should have been throttled.

The last point is subtle, but ultimately should be inconsequential. Timers
whose requested timeout is less that the minimum interval will saturate quickly
anyway; timers with an original interval greater than the minimum previously
wouldn't have incremented m_nestingLevel, but doing so now doesn't hurt since
they won't be throttled when they hit the threshold. This simplifies things
conceptually a little & reduces the test performed on each timer fire.

* page/DOMTimer.cpp:
(WebCore::shouldForwardUserGesture):
    - unnested timers are indicated by a nesting level of 0
(WebCore::DOMTimer::DOMTimer):
    - don't increment nesting level on construction
(WebCore::DOMTimer::fired):
    - saturating increments
(WebCore::DOMTimer::adjustMinimumTimerInterval):
(WebCore::DOMTimer::intervalClampedToMinimum):
    - added ASSERTs



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@173132 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Make timerNestingLevel threadsafe
https://bugs.webkit.org/show_bug.cgi?id=136401

Reviewed by Tim Horton.

timerNestingLevel, used by DOMTimer to determine whether a timer is 'nested'
(repeating, possible due to a timer rescheduling itself) is a global. Since
worker threads can set timers too this is not thread safe.

* dom/ScriptExecutionContext.cpp:
(WebCore::ScriptExecutionContext::ScriptExecutionContext):
    - added initialize m_timerNestingLevel
* dom/ScriptExecutionContext.h:
(WebCore::ScriptExecutionContext::timerNestingLevel):
(WebCore::ScriptExecutionContext::setTimerNestingLevel):
    - added accessors
* page/DOMTimer.cpp:
(WebCore::DOMTimer::DOMTimer):
(WebCore::DOMTimer::fired):
    - move timerNestingLevel to the context



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@173133 268f45cc-cd09-0410-ab3c-d52691b4dbfc