Title: [241499] trunk
- Revision
- 241499
- Author
- [email protected]
- Date
- 2019-02-13 22:43:13 -0800 (Wed, 13 Feb 2019)
Log Message
Crash in DOMTimer::fired
https://bugs.webkit.org/show_bug.cgi?id=194638
Reviewed by Brent Fulgham.
Source/WebCore:
This patch continues the saga of hunting down timer related crashes after r239814, r225985, r227934.
The crash was caused by the bug that we don't remove a DOMTimer from NestedTimersMap if a DOMTimer
is created & installed inside another DOMTimer's callback (via execute call in DOMTimer::fired).
Fixed the crash by using a Ref in NestedTimersMap. This will keep the timer alive until we exit
from DOMTimer::fired. Because DOMTimer::fired always calls stopTracking() which clears the map
we would not leak these DOM timers.
We could, alternatively, use WeakPtr in NestedTimersMap but that would unnecessarily increase the
size of DOMTimer for a very marginal benefit of DOMTimer objcets being deleted slightly earlier.
Deleting itself in DOMTimer's destructor involves more logic & house keeping in the timer code,
and is no longer the preferred approach when dealing with these classes of bugs in WebKit.
Test: fast/dom/timer-destruction-during-firing.html
* page/DOMTimer.cpp:
(WebCore::NestedTimersMap::add):
(WebCore::DOMTimer::install):
(WebCore::DOMTimer::fired):
LayoutTests:
Added a regression test. It needs debug assertions without the fix.
* fast/dom/timer-destruction-during-firing-expected.txt: Added.
* fast/dom/timer-destruction-during-firing.html: Added.
Modified Paths
Added Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (241498 => 241499)
--- trunk/LayoutTests/ChangeLog 2019-02-14 05:33:04 UTC (rev 241498)
+++ trunk/LayoutTests/ChangeLog 2019-02-14 06:43:13 UTC (rev 241499)
@@ -1,3 +1,15 @@
+2019-02-13 Ryosuke Niwa <[email protected]>
+
+ Crash in DOMTimer::fired
+ https://bugs.webkit.org/show_bug.cgi?id=194638
+
+ Reviewed by Brent Fulgham.
+
+ Added a regression test. It needs debug assertions without the fix.
+
+ * fast/dom/timer-destruction-during-firing-expected.txt: Added.
+ * fast/dom/timer-destruction-during-firing.html: Added.
+
2019-02-13 Nikita Vasilyev <[email protected]>
Web Inspector: Styles: valid values in style attributes are reported as unsupported property values
Added: trunk/LayoutTests/fast/dom/timer-destruction-during-firing-expected.txt (0 => 241499)
--- trunk/LayoutTests/fast/dom/timer-destruction-during-firing-expected.txt (rev 0)
+++ trunk/LayoutTests/fast/dom/timer-destruction-during-firing-expected.txt 2019-02-14 06:43:13 UTC (rev 241499)
@@ -0,0 +1,3 @@
+This tests deleting DOMTimer inside another DOMTimer. WebKit should not hit any debug assertions.
+
+PASS
Added: trunk/LayoutTests/fast/dom/timer-destruction-during-firing.html (0 => 241499)
--- trunk/LayoutTests/fast/dom/timer-destruction-during-firing.html (rev 0)
+++ trunk/LayoutTests/fast/dom/timer-destruction-during-firing.html 2019-02-14 06:43:13 UTC (rev 241499)
@@ -0,0 +1,44 @@
+<!DOCTYPE html>
+<html>
+<body>
+<p>This tests deleting DOMTimer inside another DOMTimer. WebKit should not hit any debug assertions.</p>
+<p id="result"></p>
+<script src=""
+<script>
+
+if (!window.testRunner)
+ document.getElementById('result').textContent = 'This test requires testRunner';
+else {
+ testRunner.dumpAsText();
+ testRunner.waitUntilDone();
+
+ setTimeout(() => {
+ for (let k = 0; k < 50; k++) {
+ const frames = [];
+ for (let i = 0; i < 1; i++)
+ frames[i] = createTimerInNewFrame();
+ for (const frame of frames)
+ frame.remove();
+ frames.length = 0;
+ gc();
+ }
+ self.postMessage('end', '*');
+ }, 0);
+
+ window._onmessage_ = () => {
+ document.getElementById('result').textContent = 'PASS';
+ testRunner.notifyDone();
+ }
+}
+
+function createTimerInNewFrame()
+{
+ const frame = document.createElement('iframe');
+ document.body.appendChild(frame);
+ frame.contentWindow.setTimeout(() => {}, 0);
+ return frame;
+}
+
+</script>
+</body>
+</html>
Modified: trunk/Source/WebCore/ChangeLog (241498 => 241499)
--- trunk/Source/WebCore/ChangeLog 2019-02-14 05:33:04 UTC (rev 241498)
+++ trunk/Source/WebCore/ChangeLog 2019-02-14 06:43:13 UTC (rev 241499)
@@ -1,3 +1,31 @@
+2019-02-13 Ryosuke Niwa <[email protected]>
+
+ Crash in DOMTimer::fired
+ https://bugs.webkit.org/show_bug.cgi?id=194638
+
+ Reviewed by Brent Fulgham.
+
+ This patch continues the saga of hunting down timer related crashes after r239814, r225985, r227934.
+
+ The crash was caused by the bug that we don't remove a DOMTimer from NestedTimersMap if a DOMTimer
+ is created & installed inside another DOMTimer's callback (via execute call in DOMTimer::fired).
+
+ Fixed the crash by using a Ref in NestedTimersMap. This will keep the timer alive until we exit
+ from DOMTimer::fired. Because DOMTimer::fired always calls stopTracking() which clears the map
+ we would not leak these DOM timers.
+
+ We could, alternatively, use WeakPtr in NestedTimersMap but that would unnecessarily increase the
+ size of DOMTimer for a very marginal benefit of DOMTimer objcets being deleted slightly earlier.
+ Deleting itself in DOMTimer's destructor involves more logic & house keeping in the timer code,
+ and is no longer the preferred approach when dealing with these classes of bugs in WebKit.
+
+ Test: fast/dom/timer-destruction-during-firing.html
+
+ * page/DOMTimer.cpp:
+ (WebCore::NestedTimersMap::add):
+ (WebCore::DOMTimer::install):
+ (WebCore::DOMTimer::fired):
+
2019-02-13 Joseph Pecoraro <[email protected]>
Web Inspector: Crash when inspecting an element that constantly changes visibility
Modified: trunk/Source/WebCore/page/DOMTimer.cpp (241498 => 241499)
--- trunk/Source/WebCore/page/DOMTimer.cpp 2019-02-14 05:33:04 UTC (rev 241498)
+++ trunk/Source/WebCore/page/DOMTimer.cpp 2019-02-14 06:43:13 UTC (rev 241499)
@@ -113,7 +113,7 @@
DOMTimerFireState* DOMTimerFireState::current = nullptr;
struct NestedTimersMap {
- typedef HashMap<int, DOMTimer*>::const_iterator const_iterator;
+ typedef HashMap<int, Ref<DOMTimer>>::const_iterator const_iterator;
static NestedTimersMap* instanceForContext(ScriptExecutionContext& context)
{
@@ -139,10 +139,10 @@
nestedTimers.clear();
}
- void add(int timeoutId, DOMTimer* timer)
+ void add(int timeoutId, Ref<DOMTimer>&& timer)
{
if (isTrackingNestedTimers)
- nestedTimers.add(timeoutId, timer);
+ nestedTimers.add(timeoutId, WTFMove(timer));
}
void remove(int timeoutId)
@@ -162,7 +162,7 @@
}
static bool isTrackingNestedTimers;
- HashMap<int /* timeoutId */, DOMTimer*> nestedTimers;
+ HashMap<int /* timeoutId */, Ref<DOMTimer>> nestedTimers;
};
bool NestedTimersMap::isTrackingNestedTimers = false;
@@ -235,7 +235,7 @@
// Keep track of nested timer installs.
if (NestedTimersMap* nestedTimers = NestedTimersMap::instanceForContext(context))
- nestedTimers->add(timer->m_timeoutId, timer);
+ nestedTimers->add(timer->m_timeoutId, *timer);
return timer->m_timeoutId;
}
@@ -390,8 +390,8 @@
// Check if we should throttle nested single-shot timers.
if (nestedTimers) {
- for (auto& keyValue : *nestedTimers) {
- auto* timer = keyValue.value;
+ for (auto& idAndTimer : *nestedTimers) {
+ auto& timer = idAndTimer.value;
if (timer->isActive() && !timer->repeatInterval())
timer->updateThrottlingStateIfNecessary(fireState);
}
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes