Diff
Modified: trunk/Source/WebCore/ChangeLog (197689 => 197690)
--- trunk/Source/WebCore/ChangeLog 2016-03-07 18:41:30 UTC (rev 197689)
+++ trunk/Source/WebCore/ChangeLog 2016-03-07 18:41:56 UTC (rev 197690)
@@ -1,3 +1,69 @@
+2016-03-06 Gavin Barraclough <[email protected]>
+
+ Convert DOMTimer to std::chrono::milliseconds
+ https://bugs.webkit.org/show_bug.cgi?id=155085
+
+ Reviewed by Andreas Kling.
+
+ DOMTimer currently uses a mix of millisecond (was int, now std::chrono) and second (as double)
+ time values. Constant conversion back and forth is a complete mess. Stop that.
+
+ * dom/Document.cpp:
+ (WebCore::Document::minimumTimerInterval):
+ (WebCore::Document::timerAlignmentInterval):
+ * dom/Document.h:
+ - double -> std::chrono::milliseconds
+ * dom/ScriptExecutionContext.cpp:
+ (WebCore::ScriptExecutionContext::adjustMinimumTimerInterval):
+ (WebCore::ScriptExecutionContext::minimumTimerInterval):
+ (WebCore::ScriptExecutionContext::timerAlignmentInterval):
+ * dom/ScriptExecutionContext.h:
+ - double -> std::chrono::milliseconds
+ * page/DOMTimer.cpp:
+ (WebCore::DOMTimer::updateTimerIntervalIfNecessary):
+ (WebCore::DOMTimer::intervalClampedToMinimum):
+ (WebCore::DOMTimer::alignedFireTime):
+ * page/DOMTimer.h:
+ - double -> std::chrono::milliseconds
+ * page/Page.cpp:
+ (WebCore::Page::setTimerThrottlingState):
+ (WebCore::Page::setTimerAlignmentIntervalIncreaseLimit):
+ (WebCore::Page::updateDOMTimerAlignmentInterval):
+ * page/Page.h:
+ - double -> std::chrono::milliseconds
+ * page/Settings.cpp:
+ (WebCore::Settings::setNeedsAdobeFrameReloadingQuirk):
+ (WebCore::Settings::setMinimumDOMTimerInterval):
+ * page/Settings.h:
+ - double -> std::chrono::milliseconds
+ * page/SuspendableTimer.h:
+ (WebCore::SuspendableTimer::startRepeating):
+ (WebCore::SuspendableTimer::startOneShot):
+ (WebCore::SuspendableTimer::repeatIntervalMS):
+ (WebCore::SuspendableTimer::augmentFireInterval):
+ (WebCore::SuspendableTimer::augmentRepeatInterval):
+ - added std::chrono::milliseconds interface.
+ * platform/Timer.cpp:
+ (WebCore::TimerBase::setNextFireTime):
+ - restructured for new alignedFireTime signatured, moved zero-delay handling to here.
+ This change made because inside alignedFireTime fireTime will have already been truncated.
+ * platform/Timer.h:
+ (WebCore::TimerBase::msToSeconds):
+ (WebCore::TimerBase::secondsToMS):
+ - internal helper functions to bridge std::chrono::milliseconds to internal double.
+ (WebCore::TimerBase::startRepeating):
+ (WebCore::TimerBase::startOneShot):
+ (WebCore::TimerBase::repeatIntervalMS):
+ (WebCore::TimerBase::augmentFireInterval):
+ (WebCore::TimerBase::augmentRepeatInterval):
+ - expanded std::chrono::milliseconds interface.
+ (WebCore::TimerBase::alignedFireTime):
+ - changed to std::chrono::milliseconds, made return value Optional (null means no alignment).
+ * testing/InternalSettings.cpp:
+ (WebCore::InternalSettings::setMinimumTimerInterval):
+ * testing/InternalSettings.h:
+ - double -> std::chrono::milliseconds
+
2016-03-07 Andreas Kling <[email protected]>
Make RenderStyle copy-on-write a bit less.
Modified: trunk/Source/WebCore/dom/Document.cpp (197689 => 197690)
--- trunk/Source/WebCore/dom/Document.cpp 2016-03-07 18:41:30 UTC (rev 197689)
+++ trunk/Source/WebCore/dom/Document.cpp 2016-03-07 18:41:56 UTC (rev 197690)
@@ -2915,7 +2915,7 @@
write("\n", ownerDocument);
}
-double Document::minimumTimerInterval() const
+std::chrono::milliseconds Document::minimumTimerInterval() const
{
auto* page = this->page();
if (!page)
@@ -2932,9 +2932,9 @@
didChangeTimerAlignmentInterval();
}
-double Document::timerAlignmentInterval(bool hasReachedMaxNestingLevel) const
+std::chrono::milliseconds Document::timerAlignmentInterval(bool hasReachedMaxNestingLevel) const
{
- double alignmentInterval = ScriptExecutionContext::timerAlignmentInterval(hasReachedMaxNestingLevel);
+ auto alignmentInterval = ScriptExecutionContext::timerAlignmentInterval(hasReachedMaxNestingLevel);
// Apply Document-level DOMTimer throttling only if timers have reached their maximum nesting level as the Page may still be visible.
if (m_isTimerThrottlingEnabled && hasReachedMaxNestingLevel)
Modified: trunk/Source/WebCore/dom/Document.h (197689 => 197690)
--- trunk/Source/WebCore/dom/Document.h 2016-03-07 18:41:30 UTC (rev 197689)
+++ trunk/Source/WebCore/dom/Document.h 2016-03-07 18:41:56 UTC (rev 197690)
@@ -1355,9 +1355,9 @@
void addMessage(MessageSource, MessageLevel, const String& message, const String& sourceURL, unsigned lineNumber, unsigned columnNumber, RefPtr<Inspector::ScriptCallStack>&&, JSC::ExecState* = nullptr, unsigned long requestIdentifier = 0) final;
- double minimumTimerInterval() const final;
+ std::chrono::milliseconds minimumTimerInterval() const final;
- double timerAlignmentInterval(bool hasReachedMaxNestingLevel) const final;
+ std::chrono::milliseconds timerAlignmentInterval(bool hasReachedMaxNestingLevel) const final;
void updateTitleFromTitleElement();
void updateTitle(const StringWithDirection&);
Modified: trunk/Source/WebCore/dom/ScriptExecutionContext.cpp (197689 => 197690)
--- trunk/Source/WebCore/dom/ScriptExecutionContext.cpp 2016-03-07 18:41:30 UTC (rev 197689)
+++ trunk/Source/WebCore/dom/ScriptExecutionContext.cpp 2016-03-07 18:41:56 UTC (rev 197690)
@@ -426,7 +426,7 @@
return *m_publicURLManager;
}
-void ScriptExecutionContext::adjustMinimumTimerInterval(double oldMinimumTimerInterval)
+void ScriptExecutionContext::adjustMinimumTimerInterval(std::chrono::milliseconds oldMinimumTimerInterval)
{
if (minimumTimerInterval() != oldMinimumTimerInterval) {
for (auto& timer : m_timeouts.values())
@@ -434,7 +434,7 @@
}
}
-double ScriptExecutionContext::minimumTimerInterval() const
+std::chrono::milliseconds ScriptExecutionContext::minimumTimerInterval() const
{
// The default implementation returns the DOMTimer's default
// minimum timer interval. FIXME: to make it work with dedicated
@@ -450,7 +450,7 @@
timer->didChangeAlignmentInterval();
}
-double ScriptExecutionContext::timerAlignmentInterval(bool) const
+std::chrono::milliseconds ScriptExecutionContext::timerAlignmentInterval(bool) const
{
return DOMTimer::defaultAlignmentInterval();
}
Modified: trunk/Source/WebCore/dom/ScriptExecutionContext.h (197689 => 197690)
--- trunk/Source/WebCore/dom/ScriptExecutionContext.h 2016-03-07 18:41:30 UTC (rev 197689)
+++ trunk/Source/WebCore/dom/ScriptExecutionContext.h 2016-03-07 18:41:56 UTC (rev 197690)
@@ -170,11 +170,11 @@
WEBCORE_EXPORT JSC::VM& vm();
// Interval is in seconds.
- void adjustMinimumTimerInterval(double oldMinimumTimerInterval);
- virtual double minimumTimerInterval() const;
+ void adjustMinimumTimerInterval(std::chrono::milliseconds oldMinimumTimerInterval);
+ virtual std::chrono::milliseconds minimumTimerInterval() const;
void didChangeTimerAlignmentInterval();
- virtual double timerAlignmentInterval(bool hasReachedMaxNestingLevel) const;
+ virtual std::chrono::milliseconds timerAlignmentInterval(bool hasReachedMaxNestingLevel) const;
virtual EventQueue& eventQueue() const = 0;
Modified: trunk/Source/WebCore/page/DOMTimer.cpp (197689 => 197690)
--- trunk/Source/WebCore/page/DOMTimer.cpp 2016-03-07 18:41:30 UTC (rev 197689)
+++ trunk/Source/WebCore/page/DOMTimer.cpp 2016-03-07 18:41:56 UTC (rev 197690)
@@ -53,9 +53,8 @@
namespace WebCore {
static const std::chrono::milliseconds maxIntervalForUserGestureForwarding = std::chrono::milliseconds(1000); // One second matches Gecko.
-static const int minIntervalForNonUserObservableChangeTimers = 1000; // Empirically determined to maximize battery life.
+static const std::chrono::milliseconds minIntervalForNonUserObservableChangeTimers = std::chrono::milliseconds(1000); // Empirically determined to maximize battery life.
static const int maxTimerNestingLevel = 5;
-static const double _oneMillisecond_ = 0.001;
class DOMTimerFireState {
public:
@@ -387,53 +386,52 @@
{
ASSERT(m_nestingLevel <= maxTimerNestingLevel);
- double previousInterval = m_currentTimerInterval;
+ auto previousInterval = m_currentTimerInterval;
m_currentTimerInterval = intervalClampedToMinimum();
-
- if (WTF::areEssentiallyEqual(previousInterval, m_currentTimerInterval, oneMillisecond))
+ if (previousInterval == m_currentTimerInterval)
return;
if (repeatInterval()) {
- ASSERT(WTF::areEssentiallyEqual(repeatInterval(), previousInterval, oneMillisecond));
- LOG(DOMTimers, "%p - Updating DOMTimer's repeat interval from %g ms to %g ms due to throttling.", this, previousInterval * 1000., m_currentTimerInterval * 1000.);
+ ASSERT(repeatIntervalMS() == previousInterval);
+ LOG(DOMTimers, "%p - Updating DOMTimer's repeat interval from %lld ms to %lld ms due to throttling.", this, previousInterval.count(), m_currentTimerInterval.count());
augmentRepeatInterval(m_currentTimerInterval - previousInterval);
} else {
- LOG(DOMTimers, "%p - Updating DOMTimer's fire interval from %g ms to %g ms due to throttling.", this, previousInterval * 1000., m_currentTimerInterval * 1000.);
+ LOG(DOMTimers, "%p - Updating DOMTimer's fire interval from %lld ms to %lld ms due to throttling.", this, previousInterval.count(), m_currentTimerInterval.count());
augmentFireInterval(m_currentTimerInterval - previousInterval);
}
}
-double DOMTimer::intervalClampedToMinimum() const
+std::chrono::milliseconds DOMTimer::intervalClampedToMinimum() const
{
ASSERT(scriptExecutionContext());
ASSERT(m_nestingLevel <= maxTimerNestingLevel);
- double intervalInSeconds = std::max(oneMillisecond, m_originalInterval.count() * oneMillisecond);
+ auto interval = std::max(std::chrono::milliseconds(1), m_originalInterval);
// Only apply throttling to repeating timers.
if (m_nestingLevel < maxTimerNestingLevel)
- return intervalInSeconds;
+ return interval;
// Apply two throttles - the global (per Page) minimum, and also a per-timer throttle.
- intervalInSeconds = std::max(intervalInSeconds, scriptExecutionContext()->minimumTimerInterval());
+ interval = std::max(interval, scriptExecutionContext()->minimumTimerInterval());
if (m_throttleState == ShouldThrottle)
- intervalInSeconds = std::max(intervalInSeconds, minIntervalForNonUserObservableChangeTimers * oneMillisecond);
- return intervalInSeconds;
+ interval = std::max(interval, minIntervalForNonUserObservableChangeTimers);
+ return interval;
}
-double DOMTimer::alignedFireTime(double fireTime) const
+Optional<std::chrono::milliseconds> DOMTimer::alignedFireTime(std::chrono::milliseconds fireTime) const
{
- if (double alignmentInterval = scriptExecutionContext()->timerAlignmentInterval(m_nestingLevel >= maxTimerNestingLevel)) {
- // Don't mess with zero-delay timers.
- if (!fireTime)
- return fireTime;
- static const double randomizedAlignment = randomNumber();
- // Force alignment to randomizedAlignment fraction of the way between alignemntIntervals, e.g.
- // if alignmentInterval is 10 and randomizedAlignment is 0.3 this will align to 3, 13, 23, ...
- return (ceil(fireTime / alignmentInterval - randomizedAlignment) + randomizedAlignment) * alignmentInterval;
- }
+ auto alignmentInterval = scriptExecutionContext()->timerAlignmentInterval(m_nestingLevel >= maxTimerNestingLevel);
+ if (alignmentInterval == std::chrono::milliseconds::zero())
+ return Nullopt;
+
+ static const double randomizedProportion = randomNumber();
- return fireTime;
+ // Force alignment to randomizedAlignment fraction of the way between alignemntIntervals, e.g.
+ // if alignmentInterval is 10 and randomizedAlignment is 0.3 this will align to 3, 13, 23, ...
+ auto randomizedOffset = std::chrono::duration_cast<std::chrono::milliseconds>(alignmentInterval * randomizedProportion);
+ auto adjustedFireTime = fireTime - randomizedOffset;
+ return adjustedFireTime - (adjustedFireTime % alignmentInterval) + alignmentInterval + randomizedOffset;
}
const char* DOMTimer::activeDOMObjectName() const
Modified: trunk/Source/WebCore/page/DOMTimer.h (197689 => 197690)
--- trunk/Source/WebCore/page/DOMTimer.h 2016-03-07 18:41:30 UTC (rev 197689)
+++ trunk/Source/WebCore/page/DOMTimer.h 2016-03-07 18:41:56 UTC (rev 197690)
@@ -46,9 +46,9 @@
public:
virtual ~DOMTimer();
- static double defaultMinimumInterval() { return 0.004; } // 4 milliseconds.
- static double defaultAlignmentInterval() { return 0; }
- static double hiddenPageAlignmentInterval() { return 1.0; } // 1 second.
+ static std::chrono::milliseconds defaultMinimumInterval() { return std::chrono::milliseconds(4); }
+ static std::chrono::milliseconds defaultAlignmentInterval() { return std::chrono::milliseconds::zero(); }
+ static std::chrono::milliseconds hiddenPageAlignmentInterval() { return std::chrono::milliseconds(1000); }
// Creates a new timer owned by specified ScriptExecutionContext, starts it
// and returns its Id.
@@ -65,7 +65,7 @@
DOMTimer(ScriptExecutionContext&, std::unique_ptr<ScheduledAction>, std::chrono::milliseconds interval, bool singleShot);
friend class Internals;
- double intervalClampedToMinimum() const;
+ std::chrono::milliseconds intervalClampedToMinimum() const;
bool isDOMTimersThrottlingEnabled(Document&) const;
void updateThrottlingStateIfNecessary(const DOMTimerFireState&);
@@ -73,7 +73,7 @@
// SuspendableTimer
void fired() override;
void didStop() override;
- double alignedFireTime(double) const override;
+ Optional<std::chrono::milliseconds> alignedFireTime(std::chrono::milliseconds) const override;
// ActiveDOMObject API.
const char* activeDOMObjectName() const override;
@@ -89,7 +89,7 @@
std::unique_ptr<ScheduledAction> m_action;
std::chrono::milliseconds m_originalInterval;
TimerThrottleState m_throttleState;
- double m_currentTimerInterval;
+ std::chrono::milliseconds m_currentTimerInterval;
bool m_shouldForwardUserGesture;
};
Modified: trunk/Source/WebCore/page/Page.cpp (197689 => 197690)
--- trunk/Source/WebCore/page/Page.cpp 2016-03-07 18:41:30 UTC (rev 197689)
+++ trunk/Source/WebCore/page/Page.cpp 2016-03-07 18:41:56 UTC (rev 197690)
@@ -1206,7 +1206,7 @@
return;
m_timerThrottlingState = state;
- m_timerThrottlingStateLastChangedTime = monotonicallyIncreasingTime();
+ m_timerThrottlingStateLastChangedTime = std::chrono::steady_clock::now();
updateDOMTimerAlignmentInterval();
@@ -1221,8 +1221,7 @@
void Page::setTimerAlignmentIntervalIncreaseLimit(std::chrono::milliseconds limit)
{
- // FIXME: std::chrono-ify all timer allignment related code.
- m_timerAlignmentIntervalIncreaseLimit = limit.count() * 0.001;
+ m_timerAlignmentIntervalIncreaseLimit = limit;
// If (m_timerAlignmentIntervalIncreaseLimit < m_timerAlignmentInterval) then we need
// to update m_timerAlignmentInterval, if greater then need to restart the increase timer.
@@ -1248,8 +1247,8 @@
if (m_isPrerender)
m_timerAlignmentInterval = m_timerAlignmentIntervalIncreaseLimit;
else {
- ASSERT(m_timerThrottlingStateLastChangedTime);
- m_timerAlignmentInterval = monotonicallyIncreasingTime() - m_timerThrottlingStateLastChangedTime;
+ ASSERT(m_timerThrottlingStateLastChangedTime.time_since_epoch() != std::chrono::steady_clock::duration::zero());
+ m_timerAlignmentInterval = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - m_timerThrottlingStateLastChangedTime);
// If we're below the limit, set the timer. If above, clamp to limit.
if (m_timerAlignmentInterval < m_timerAlignmentIntervalIncreaseLimit)
needsIncreaseTimer = true;
Modified: trunk/Source/WebCore/page/Page.h (197689 => 197690)
--- trunk/Source/WebCore/page/Page.h 2016-03-07 18:41:30 UTC (rev 197689)
+++ trunk/Source/WebCore/page/Page.h 2016-03-07 18:41:56 UTC (rev 197690)
@@ -219,7 +219,7 @@
ProgressTracker& progress() const { return *m_progress; }
BackForwardController& backForward() const { return *m_backForwardController; }
- double domTimerAlignmentInterval() const { return m_timerAlignmentInterval; }
+ std::chrono::milliseconds domTimerAlignmentInterval() const { return m_timerAlignmentInterval; }
#if ENABLE(VIEW_MODE_CSS_MEDIA)
enum ViewMode {
@@ -621,10 +621,10 @@
#endif // ENABLE(VIEW_MODE_CSS_MEDIA)
TimerThrottlingState m_timerThrottlingState { TimerThrottlingState::Disabled };
- double m_timerThrottlingStateLastChangedTime { 0 };
- double m_timerAlignmentInterval;
+ std::chrono::steady_clock::time_point m_timerThrottlingStateLastChangedTime { std::chrono::steady_clock::duration::zero() };
+ std::chrono::milliseconds m_timerAlignmentInterval;
Timer m_timerAlignmentIntervalIncreaseTimer;
- double m_timerAlignmentIntervalIncreaseLimit { 0 };
+ std::chrono::milliseconds m_timerAlignmentIntervalIncreaseLimit { 0 };
bool m_isEditable;
bool m_isPrerender;
Modified: trunk/Source/WebCore/page/Settings.cpp (197689 => 197690)
--- trunk/Source/WebCore/page/Settings.cpp 2016-03-07 18:41:30 UTC (rev 197689)
+++ trunk/Source/WebCore/page/Settings.cpp 2016-03-07 18:41:56 UTC (rev 197690)
@@ -464,9 +464,9 @@
m_needsAdobeFrameReloadingQuirk = shouldNotReloadIFramesForUnchangedSRC;
}
-void Settings::setMinimumDOMTimerInterval(double interval)
+void Settings::setMinimumDOMTimerInterval(std::chrono::milliseconds interval)
{
- double oldTimerInterval = m_minimumDOMTimerInterval;
+ auto oldTimerInterval = m_minimumDOMTimerInterval;
m_minimumDOMTimerInterval = interval;
if (!m_page)
Modified: trunk/Source/WebCore/page/Settings.h (197689 => 197690)
--- trunk/Source/WebCore/page/Settings.h 2016-03-07 18:41:30 UTC (rev 197689)
+++ trunk/Source/WebCore/page/Settings.h 2016-03-07 18:41:56 UTC (rev 197690)
@@ -152,8 +152,8 @@
WEBCORE_EXPORT void setNeedsAdobeFrameReloadingQuirk(bool);
bool needsAcrobatFrameReloadingQuirk() const { return m_needsAdobeFrameReloadingQuirk; }
- WEBCORE_EXPORT void setMinimumDOMTimerInterval(double); // Initialized to DOMTimer::defaultMinimumInterval().
- double minimumDOMTimerInterval() const { return m_minimumDOMTimerInterval; }
+ WEBCORE_EXPORT void setMinimumDOMTimerInterval(std::chrono::milliseconds); // Initialized to DOMTimer::defaultMinimumInterval().
+ std::chrono::milliseconds minimumDOMTimerInterval() const { return m_minimumDOMTimerInterval; }
WEBCORE_EXPORT void setLayoutInterval(std::chrono::milliseconds);
std::chrono::milliseconds layoutInterval() const { return m_layoutInterval; }
@@ -303,7 +303,7 @@
const std::unique_ptr<FontGenericFamilies> m_fontGenericFamilies;
SecurityOrigin::StorageBlockingPolicy m_storageBlockingPolicy;
std::chrono::milliseconds m_layoutInterval;
- double m_minimumDOMTimerInterval;
+ std::chrono::milliseconds m_minimumDOMTimerInterval;
#if ENABLE(TEXT_AUTOSIZING)
float m_textAutosizingFontScaleFactor;
Modified: trunk/Source/WebCore/page/SuspendableTimer.h (197689 => 197690)
--- trunk/Source/WebCore/page/SuspendableTimer.h 2016-03-07 18:41:30 UTC (rev 197689)
+++ trunk/Source/WebCore/page/SuspendableTimer.h 2016-03-07 18:41:56 UTC (rev 197690)
@@ -43,11 +43,19 @@
// Part of TimerBase interface used by SuspendableTimer clients, modified to work when suspended.
bool isActive() const { return TimerBase::isActive() || (m_suspended && m_savedIsActive); }
bool isSuspended() const { return m_suspended; }
+
void startRepeating(double repeatInterval);
void startOneShot(double interval);
double repeatInterval() const;
void augmentFireInterval(double delta);
void augmentRepeatInterval(double delta);
+
+ void startRepeating(std::chrono::milliseconds repeatInterval) { startRepeating(msToSeconds(repeatInterval)); }
+ void startOneShot(std::chrono::milliseconds interval) { startOneShot(msToSeconds(interval)); }
+ std::chrono::milliseconds repeatIntervalMS() const { return secondsToMS(repeatInterval()); }
+ void augmentFireInterval(std::chrono::milliseconds delta) { augmentFireInterval(msToSeconds(delta)); }
+ void augmentRepeatInterval(std::chrono::milliseconds delta) { augmentRepeatInterval(msToSeconds(delta)); }
+
using TimerBase::didChangeAlignmentInterval;
using TimerBase::operator new;
using TimerBase::operator delete;
Modified: trunk/Source/WebCore/platform/Timer.cpp (197689 => 197690)
--- trunk/Source/WebCore/platform/Timer.cpp 2016-03-07 18:41:30 UTC (rev 197689)
+++ trunk/Source/WebCore/platform/Timer.cpp 2016-03-07 18:41:56 UTC (rev 197690)
@@ -367,13 +367,13 @@
ASSERT(!inHeap() || hasValidHeapPosition());
}
-void TimerBase::setNextFireTime(double newUnalignedTime)
+void TimerBase::setNextFireTime(double newTime)
{
ASSERT(canAccessThreadLocalDataForThread(m_thread));
ASSERT(!m_wasDeleted);
- if (m_unalignedNextFireTime != newUnalignedTime)
- m_unalignedNextFireTime = newUnalignedTime;
+ if (m_unalignedNextFireTime != newTime)
+ m_unalignedNextFireTime = newTime;
// Accessing thread global data is slow. Cache the heap pointer.
if (!m_cachedThreadGlobalTimerHeap)
@@ -381,7 +381,12 @@
// Keep heap valid while changing the next-fire time.
double oldTime = m_nextFireTime;
- double newTime = alignedFireTime(newUnalignedTime);
+ // Don't realign zero-delay timers.
+ if (newTime) {
+ if (auto newAlignedTime = alignedFireTime(secondsToMS(newTime)))
+ newTime = msToSeconds(newAlignedTime.value());
+ }
+
if (oldTime != newTime) {
m_nextFireTime = newTime;
// FIXME: This should be part of ThreadTimers, or another per-thread structure.
Modified: trunk/Source/WebCore/platform/Timer.h (197689 => 197690)
--- trunk/Source/WebCore/platform/Timer.h 2016-03-07 18:41:30 UTC (rev 197689)
+++ trunk/Source/WebCore/platform/Timer.h 2016-03-07 18:41:56 UTC (rev 197690)
@@ -29,6 +29,7 @@
#include <chrono>
#include <functional>
#include <wtf/Noncopyable.h>
+#include <wtf/Optional.h>
#include <wtf/Threading.h>
#include <wtf/Vector.h>
@@ -45,6 +46,10 @@
class TimerBase {
WTF_MAKE_NONCOPYABLE(TimerBase);
WTF_MAKE_FAST_ALLOCATED;
+protected:
+ static inline double msToSeconds(std::chrono::milliseconds duration) { return duration.count() * 0.001; }
+ static inline std::chrono::milliseconds secondsToMS(double duration) { return std::chrono::milliseconds((std::chrono::milliseconds::rep)(duration * 1000)); }
+
public:
WEBCORE_EXPORT TimerBase();
WEBCORE_EXPORT virtual ~TimerBase();
@@ -52,9 +57,9 @@
WEBCORE_EXPORT void start(double nextFireInterval, double repeatInterval);
void startRepeating(double repeatInterval) { start(repeatInterval, repeatInterval); }
- void startRepeating(std::chrono::milliseconds repeatInterval) { startRepeating(repeatInterval.count() * 0.001); }
+ void startRepeating(std::chrono::milliseconds repeatInterval) { startRepeating(msToSeconds(repeatInterval)); }
void startOneShot(double interval) { start(interval, 0); }
- void startOneShot(std::chrono::milliseconds interval) { startOneShot(interval.count() * 0.001); }
+ void startOneShot(std::chrono::milliseconds interval) { startOneShot(msToSeconds(interval)); }
WEBCORE_EXPORT void stop();
bool isActive() const;
@@ -62,9 +67,12 @@
double nextFireInterval() const;
double nextUnalignedFireInterval() const;
double repeatInterval() const { return m_repeatInterval; }
+ std::chrono::milliseconds repeatIntervalMS() const { return secondsToMS(repeatInterval()); }
void augmentFireInterval(double delta) { setNextFireTime(m_nextFireTime + delta); }
+ void augmentFireInterval(std::chrono::milliseconds delta) { augmentFireInterval(msToSeconds(delta)); }
void augmentRepeatInterval(double delta) { augmentFireInterval(delta); m_repeatInterval += delta; }
+ void augmentRepeatInterval(std::chrono::milliseconds delta) { augmentRepeatInterval(msToSeconds(delta)); }
void didChangeAlignmentInterval();
@@ -73,7 +81,7 @@
private:
virtual void fired() = 0;
- virtual double alignedFireTime(double fireTime) const { return fireTime; }
+ virtual Optional<std::chrono::milliseconds> alignedFireTime(std::chrono::milliseconds) const { return Nullopt; }
void checkConsistency() const;
void checkHeapIndex() const;
Modified: trunk/Source/WebCore/testing/InternalSettings.cpp (197689 => 197690)
--- trunk/Source/WebCore/testing/InternalSettings.cpp 2016-03-07 18:41:30 UTC (rev 197689)
+++ trunk/Source/WebCore/testing/InternalSettings.cpp 2016-03-07 18:41:56 UTC (rev 197690)
@@ -466,7 +466,7 @@
void InternalSettings::setMinimumTimerInterval(double intervalInSeconds, ExceptionCode& ec)
{
InternalSettingsGuardForSettings();
- settings()->setMinimumDOMTimerInterval(intervalInSeconds);
+ settings()->setMinimumDOMTimerInterval(std::chrono::milliseconds((std::chrono::milliseconds::rep)(intervalInSeconds * 1000)));
}
void InternalSettings::setDefaultVideoPosterURL(const String& url, ExceptionCode& ec)
Modified: trunk/Source/WebCore/testing/InternalSettings.h (197689 => 197690)
--- trunk/Source/WebCore/testing/InternalSettings.h 2016-03-07 18:41:30 UTC (rev 197689)
+++ trunk/Source/WebCore/testing/InternalSettings.h 2016-03-07 18:41:56 UTC (rev 197690)
@@ -75,7 +75,7 @@
bool m_originalUsesOverlayScrollbars;
bool m_langAttributeAwareFormControlUIEnabled;
bool m_imagesEnabled;
- double m_minimumTimerInterval;
+ std::chrono::milliseconds m_minimumTimerInterval;
#if ENABLE(VIDEO_TRACK)
bool m_shouldDisplaySubtitles;
bool m_shouldDisplayCaptions;
Modified: trunk/Source/WebKit/win/ChangeLog (197689 => 197690)
--- trunk/Source/WebKit/win/ChangeLog 2016-03-07 18:41:30 UTC (rev 197689)
+++ trunk/Source/WebKit/win/ChangeLog 2016-03-07 18:41:56 UTC (rev 197690)
@@ -1,3 +1,17 @@
+2016-03-06 Gavin Barraclough <[email protected]>
+
+ Convert DOMTimer to std::chrono::milliseconds
+ https://bugs.webkit.org/show_bug.cgi?id=155085
+
+ Reviewed by Andreas Kling.
+
+ DOMTimer currently uses a mix of millisecond (was int, now std::chrono) and second (as double)
+ time values. Constant conversion back and forth is a complete mess. Stop that.
+
+ * WebView.cpp:
+ (WebView::setMinimumTimerInterval):
+ - Convert double argument into std::chrono::milliseconds.
+
2016-03-05 Yusuke Suzuki <[email protected]>
[ES6] Support Reflect.construct
Modified: trunk/Source/WebKit/win/WebView.cpp (197689 => 197690)
--- trunk/Source/WebKit/win/WebView.cpp 2016-03-07 18:41:30 UTC (rev 197689)
+++ trunk/Source/WebKit/win/WebView.cpp 2016-03-07 18:41:56 UTC (rev 197690)
@@ -7220,7 +7220,7 @@
{
if (!interval)
return E_POINTER;
- *interval = DOMTimer::defaultMinimumInterval();
+ *interval = DOMTimer::defaultMinimumInterval().count() / 1000.;
return S_OK;
}
@@ -7229,7 +7229,8 @@
if (!m_page)
return E_FAIL;
- page()->settings().setMinimumDOMTimerInterval(interval);
+ auto intervalMS = std::chrono::milliseconds((std::chrono::milliseconds::rep)(interval * 1000));
+ page()->settings().setMinimumDOMTimerInterval(intervalMS);
return S_OK;
}