Title: [173133] trunk/Source/WebCore
Revision
173133
Author
[email protected]
Date
2014-08-29 18:33:24 -0700 (Fri, 29 Aug 2014)

Log Message

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

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (173132 => 173133)


--- trunk/Source/WebCore/ChangeLog	2014-08-30 01:11:23 UTC (rev 173132)
+++ trunk/Source/WebCore/ChangeLog	2014-08-30 01:33:24 UTC (rev 173133)
@@ -1,5 +1,28 @@
 2014-08-29  Gavin Barraclough  <[email protected]>
 
+        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
+
+2014-08-29  Gavin Barraclough  <[email protected]>
+
         DOMTimer::m_nestingLevel is prone to overflow
         https://bugs.webkit.org/show_bug.cgi?id=136399
 

Modified: trunk/Source/WebCore/dom/ScriptExecutionContext.cpp (173132 => 173133)


--- trunk/Source/WebCore/dom/ScriptExecutionContext.cpp	2014-08-30 01:11:23 UTC (rev 173132)
+++ trunk/Source/WebCore/dom/ScriptExecutionContext.cpp	2014-08-30 01:33:24 UTC (rev 173133)
@@ -80,6 +80,7 @@
     , m_reasonForSuspendingActiveDOMObjects(static_cast<ActiveDOMObject::ReasonForSuspension>(-1))
     , m_activeDOMObjectsAreStopped(false)
     , m_activeDOMObjectAdditionForbidden(false)
+    , m_timerNestingLevel(0)
 #if !ASSERT_DISABLED
     , m_inScriptExecutionContextDestructor(false)
     , m_activeDOMObjectRemovalForbidden(false)

Modified: trunk/Source/WebCore/dom/ScriptExecutionContext.h (173132 => 173133)


--- trunk/Source/WebCore/dom/ScriptExecutionContext.h	2014-08-30 01:11:23 UTC (rev 173132)
+++ trunk/Source/WebCore/dom/ScriptExecutionContext.h	2014-08-30 01:33:24 UTC (rev 173133)
@@ -175,6 +175,9 @@
     virtual bool unwrapCryptoKey(const Vector<uint8_t>& wrappedKey, Vector<uint8_t>& key) = 0;
 #endif
 
+    int timerNestingLevel() const { return m_timerNestingLevel; }
+    void setTimerNestingLevel(int timerNestingLevel) { m_timerNestingLevel = timerNestingLevel; }
+
 protected:
     class AddConsoleMessageTask : public Task {
     public:
@@ -223,6 +226,7 @@
 #endif
 
     bool m_activeDOMObjectAdditionForbidden;
+    int m_timerNestingLevel;
 
 #if !ASSERT_DISABLED
     bool m_inScriptExecutionContextDestructor;

Modified: trunk/Source/WebCore/page/DOMTimer.cpp (173132 => 173133)


--- trunk/Source/WebCore/page/DOMTimer.cpp	2014-08-30 01:11:23 UTC (rev 173132)
+++ trunk/Source/WebCore/page/DOMTimer.cpp	2014-08-30 01:33:24 UTC (rev 173133)
@@ -49,8 +49,6 @@
 static const int maxTimerNestingLevel = 5;
 static const double _oneMillisecond_ = 0.001;
 
-static int timerNestingLevel = 0;
-    
 static inline bool shouldForwardUserGesture(int interval, int nestingLevel)
 {
     return UserGestureIndicator::processingUserGesture()
@@ -60,7 +58,7 @@
 
 DOMTimer::DOMTimer(ScriptExecutionContext* context, std::unique_ptr<ScheduledAction> action, int interval, bool singleShot)
     : SuspendableTimer(context)
-    , m_nestingLevel(timerNestingLevel)
+    , m_nestingLevel(context->timerNestingLevel())
     , m_action(WTF::move(action))
     , m_originalInterval(interval)
     , m_shouldForwardUserGesture(shouldForwardUserGesture(interval, m_nestingLevel))
@@ -130,7 +128,7 @@
         ASSERT(!document->frame()->timersPaused());
     }
 #endif
-    timerNestingLevel = std::min(m_nestingLevel + 1, maxTimerNestingLevel);
+    context->setTimerNestingLevel(std::min(m_nestingLevel + 1, maxTimerNestingLevel));
 
     ASSERT(!isSuspended());
     ASSERT(!context->activeDOMObjectsAreSuspended());
@@ -192,7 +190,7 @@
 
     InspectorInstrumentation::didFireTimer(cookie);
 
-    timerNestingLevel = 0;
+    context->setTimerNestingLevel(0);
 }
 
 void DOMTimer::didStop()
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to