Title: [291998] trunk
Revision
291998
Author
[email protected]
Date
2022-03-28 15:35:26 -0700 (Mon, 28 Mar 2022)

Log Message

Remove the 1ms minimum for setTimeout
https://bugs.webkit.org/show_bug.cgi?id=221124
<rdar://problem/73852354>

Reviewed by Sam Weinig.

LayoutTests/imported/w3c:

* web-platform-tests/html/webappapis/timers/zero-settimeout.any-expected.txt:
* web-platform-tests/html/webappapis/timers/zero-settimeout.any.html:
* web-platform-tests/html/webappapis/timers/zero-settimeout.any.js:
(async_test):
* web-platform-tests/html/webappapis/timers/zero-settimeout.any.worker-expected.txt:
* web-platform-tests/html/webappapis/timers/zero-settimeout.any.worker.html:
New test checking that 0ms and 1ms timeouts are called in the right
order.

* web-platform-tests/FileAPI/file/File-constructor.any.worker-expected.txt:
* web-platform-tests/html/webappapis/microtask-queuing/queue-microtask-exceptions.any.worker-expected.txt:
* web-platform-tests/workers/interfaces/WorkerUtils/importScripts/report-error-cross-origin.sub.any.worker-expected.txt:
* web-platform-tests/workers/interfaces/WorkerUtils/importScripts/report-error-redirect-to-cross-origin.sub.any.worker-expected.txt:
* web-platform-tests/workers/interfaces/WorkerUtils/importScripts/report-error-same-origin.sub.any.worker-expected.txt:
* web-platform-tests/workers/interfaces/WorkerUtils/importScripts/report-error-setTimeout-cross-origin.sub.any.worker-expected.txt:
* web-platform-tests/workers/interfaces/WorkerUtils/importScripts/report-error-setTimeout-redirect-to-cross-origin.sub.any.worker-expected.txt:
* web-platform-tests/workers/interfaces/WorkerUtils/importScripts/report-error-setTimeout-same-origin.sub.any.worker-expected.txt:
Disable console output in some worker tests where the reduced timeout
would cause intemittent failures due to the console message sometimes
not making it to the test output in time.

Source/WebCore:

This patch removes the 1ms minimum for setTimeout. The HTML spec makes
no mention of such a minimum, and Firefox and Chrome do not enforce
this minimum. Removing this for setTimeout results in a 0.7-2.1%
improvement on Speedometer, depending on platform and hardware.

The WPT added here demonstrates how this change can affect pages: if a
page schedules a 1ms and then a 0ms timeout in the same turn of the
event loop, then with this patch they will now be fired in the reverse
order. Since Firefox and Chrome do not impose a 1ms minimum, this
reduces the risk of this being a compatbility problem.

Scheduling a 0ms timeout will cause its callback to be called the next
time around the event loop. Other, non-timer queued tasks, will be
pre-empted. This behavior is permitted by the HTML spec, since the
event loop processing model[1] states that the implementation can
choose which task source to service, and timer callbacks are
dispatched using their own task source. Due to the way the SharedTimer
is called, we don't need to literally dispatch a task with a new
TaskSource::Timer source. (If we decided later to make a different
about whether to service timer callbacks before tasks from all other
task sources, we might need to.)

Not addressing the setTimeout 1ms minimum here, which should likely also
be removed.

While we're here, settle on "one shot" rather rather than "single
shot" as the term for timers that fire once.

[1] https://html.spec.whatwg.org/#event-loop-processing-model

Tests: imported/w3c/web-platform-tests/html/webappapis/timers/zero-settimeout.any.html
       imported/w3c/web-platform-tests/html/webappapis/timers/zero-settimeout.any.worker.html

* page/DOMTimer.h:
* page/DOMTimer.cpp:
(WebCore::DOMTimer::DOMTimer):
(WebCore::DOMTimer::install):
(WebCore::DOMTimer::fired):
(WebCore::DOMTimer::updateTimerIntervalIfNecessary):
(WebCore::DOMTimer::intervalClampedToMinimum const):

LayoutTests:

* TestExpectations: Disable console output in some worker tests where
the reduced timeout would cause intemittent failures due to the
console message sometimes not making it to the test output in time.
* js/script-tests/weakref-finalizationregistry.js:
(turnEventLoop): Use a timeout of 1ms instead of 0ms so that
the deferred work task that calls the JS FinalizationRegistry
callback gets a chance to run before we continue on to the
assertion that it was run.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (291997 => 291998)


--- trunk/LayoutTests/ChangeLog	2022-03-28 22:23:39 UTC (rev 291997)
+++ trunk/LayoutTests/ChangeLog	2022-03-28 22:35:26 UTC (rev 291998)
@@ -1,3 +1,20 @@
+2022-03-28  Cameron McCormack  <[email protected]>
+
+        Remove the 1ms minimum for setTimeout
+        https://bugs.webkit.org/show_bug.cgi?id=221124
+        <rdar://problem/73852354>
+
+        Reviewed by Sam Weinig.
+
+        * TestExpectations: Disable console output in some worker tests where
+        the reduced timeout would cause intemittent failures due to the
+        console message sometimes not making it to the test output in time.
+        * js/script-tests/weakref-finalizationregistry.js:
+        (turnEventLoop): Use a timeout of 1ms instead of 0ms so that
+        the deferred work task that calls the JS FinalizationRegistry
+        callback gets a chance to run before we continue on to the
+        assertion that it was run.
+
 2022-03-28  Antti Koivisto  <[email protected]>
 
         [CSS Container Queries] Another WPT import

Modified: trunk/LayoutTests/TestExpectations (291997 => 291998)


--- trunk/LayoutTests/TestExpectations	2022-03-28 22:23:39 UTC (rev 291997)
+++ trunk/LayoutTests/TestExpectations	2022-03-28 22:35:26 UTC (rev 291998)
@@ -4912,6 +4912,11 @@
 webkit.org/b/228176 fast/text/variable-system-font.html [ Pass ImageOnlyFailure ]
 webkit.org/b/228176 fast/text/variable-system-font-2.html [ Pass ImageOnlyFailure ]
 
+# Console message from workers sometimes don't make their way to test output, so disable them to avoid flakiness.
+imported/w3c/web-platform-tests/workers/interfaces/WorkerUtils/importScripts/ [ DumpJSConsoleLogInStdErr ]
+imported/w3c/web-platform-tests/FileAPI/file/File-constructor.any.worker.html [ DumpJSConsoleLogInStdErr ]
+imported/w3c/web-platform-tests/html/webappapis/microtask-queuing/queue-microtask-exceptions.any.worker.html [ DumpJSConsoleLogInStdErr ]
+
 # It passes in legacy line layout by sheer luck. Fails with FF and Chrome too (it expects "random" code points to be computed to zero width).
 fast/text/zero-width-characters-complex-script.html [ Failure ]
 

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (291997 => 291998)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2022-03-28 22:23:39 UTC (rev 291997)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2022-03-28 22:35:26 UTC (rev 291998)
@@ -1,3 +1,32 @@
+2022-03-28  Cameron McCormack  <[email protected]>
+
+        Remove the 1ms minimum for setTimeout
+        https://bugs.webkit.org/show_bug.cgi?id=221124
+        <rdar://problem/73852354>
+
+        Reviewed by Sam Weinig.
+
+        * web-platform-tests/html/webappapis/timers/zero-settimeout.any-expected.txt:
+        * web-platform-tests/html/webappapis/timers/zero-settimeout.any.html:
+        * web-platform-tests/html/webappapis/timers/zero-settimeout.any.js:
+        (async_test):
+        * web-platform-tests/html/webappapis/timers/zero-settimeout.any.worker-expected.txt:
+        * web-platform-tests/html/webappapis/timers/zero-settimeout.any.worker.html:
+        New test checking that 0ms and 1ms timeouts are called in the right
+        order.
+
+        * web-platform-tests/FileAPI/file/File-constructor.any.worker-expected.txt:
+        * web-platform-tests/html/webappapis/microtask-queuing/queue-microtask-exceptions.any.worker-expected.txt:
+        * web-platform-tests/workers/interfaces/WorkerUtils/importScripts/report-error-cross-origin.sub.any.worker-expected.txt:
+        * web-platform-tests/workers/interfaces/WorkerUtils/importScripts/report-error-redirect-to-cross-origin.sub.any.worker-expected.txt:
+        * web-platform-tests/workers/interfaces/WorkerUtils/importScripts/report-error-same-origin.sub.any.worker-expected.txt:
+        * web-platform-tests/workers/interfaces/WorkerUtils/importScripts/report-error-setTimeout-cross-origin.sub.any.worker-expected.txt:
+        * web-platform-tests/workers/interfaces/WorkerUtils/importScripts/report-error-setTimeout-redirect-to-cross-origin.sub.any.worker-expected.txt:
+        * web-platform-tests/workers/interfaces/WorkerUtils/importScripts/report-error-setTimeout-same-origin.sub.any.worker-expected.txt:
+        Disable console output in some worker tests where the reduced timeout
+        would cause intemittent failures due to the console message sometimes
+        not making it to the test output in time.
+
 2022-03-28  Antti Koivisto  <[email protected]>
 
         [CSS Container Queries] Another WPT import

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/FileAPI/file/File-constructor.any.worker-expected.txt (291997 => 291998)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/FileAPI/file/File-constructor.any.worker-expected.txt	2022-03-28 22:23:39 UTC (rev 291997)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/FileAPI/file/File-constructor.any.worker-expected.txt	2022-03-28 22:35:26 UTC (rev 291998)
@@ -1,4 +1,3 @@
-CONSOLE MESSAGE: ReferenceError: Can't find variable: document
 
 Harness Error (FAIL), message = ReferenceError: Can't find variable: document
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/webappapis/microtask-queuing/queue-microtask-exceptions.any.worker-expected.txt (291997 => 291998)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/webappapis/microtask-queuing/queue-microtask-exceptions.any.worker-expected.txt	2022-03-28 22:23:39 UTC (rev 291997)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/webappapis/microtask-queuing/queue-microtask-exceptions.any.worker-expected.txt	2022-03-28 22:35:26 UTC (rev 291998)
@@ -1,4 +1,3 @@
-CONSOLE MESSAGE: Error: boo
 
 PASS It rethrows exceptions
 

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/html/webappapis/timers/zero-settimeout.any-expected.txt (0 => 291998)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/webappapis/timers/zero-settimeout.any-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/webappapis/timers/zero-settimeout.any-expected.txt	2022-03-28 22:35:26 UTC (rev 291998)
@@ -0,0 +1,3 @@
+
+PASS A 0ms timeout should not be clamped to 1ms
+

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/html/webappapis/timers/zero-settimeout.any.html (0 => 291998)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/webappapis/timers/zero-settimeout.any.html	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/webappapis/timers/zero-settimeout.any.html	2022-03-28 22:35:26 UTC (rev 291998)
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/html/webappapis/timers/zero-settimeout.any.js (0 => 291998)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/webappapis/timers/zero-settimeout.any.js	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/webappapis/timers/zero-settimeout.any.js	2022-03-28 22:35:26 UTC (rev 291998)
@@ -0,0 +1,15 @@
+async_test((t) => {
+  let order = [];
+
+  function append(n) {
+    order.push(`${n}ms`);
+    if (order.length == 3) {
+      assert_array_equals(order, ["0ms", "1ms", "2ms"]);
+      t.done();
+    }
+  }
+
+  setTimeout(t.step_func(() => append(2)), 2);
+  setTimeout(t.step_func(() => append(1)), 1);
+  setTimeout(t.step_func(() => append(0)), 0);
+}, "A 0ms timeout should not be clamped to 1ms");

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/html/webappapis/timers/zero-settimeout.any.worker-expected.txt (0 => 291998)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/webappapis/timers/zero-settimeout.any.worker-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/webappapis/timers/zero-settimeout.any.worker-expected.txt	2022-03-28 22:35:26 UTC (rev 291998)
@@ -0,0 +1,3 @@
+
+PASS A 0ms timeout should not be clamped to 1ms
+

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/html/webappapis/timers/zero-settimeout.any.worker.html (0 => 291998)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/webappapis/timers/zero-settimeout.any.worker.html	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/webappapis/timers/zero-settimeout.any.worker.html	2022-03-28 22:35:26 UTC (rev 291998)
@@ -0,0 +1 @@
+<!-- This file is required for WebKit test infrastructure to run the templated test -->
\ No newline at end of file

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/workers/interfaces/WorkerUtils/importScripts/report-error-cross-origin.sub.any.worker-expected.txt (291997 => 291998)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/workers/interfaces/WorkerUtils/importScripts/report-error-cross-origin.sub.any.worker-expected.txt	2022-03-28 22:23:39 UTC (rev 291997)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/workers/interfaces/WorkerUtils/importScripts/report-error-cross-origin.sub.any.worker-expected.txt	2022-03-28 22:35:26 UTC (rev 291998)
@@ -1,4 +1,3 @@
-CONSOLE MESSAGE: Error: Script error.
 
 FAIL WorkerGlobalScope error event: error assert_equals: e.error should be a DOMException expected function "function DOMException() {
     [native code]

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/workers/interfaces/WorkerUtils/importScripts/report-error-redirect-to-cross-origin.sub.any.worker-expected.txt (291997 => 291998)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/workers/interfaces/WorkerUtils/importScripts/report-error-redirect-to-cross-origin.sub.any.worker-expected.txt	2022-03-28 22:23:39 UTC (rev 291997)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/workers/interfaces/WorkerUtils/importScripts/report-error-redirect-to-cross-origin.sub.any.worker-expected.txt	2022-03-28 22:35:26 UTC (rev 291998)
@@ -1,4 +1,3 @@
-CONSOLE MESSAGE: Error: Script error.
 
 FAIL WorkerGlobalScope error event: error assert_equals: e.error should be a DOMException expected function "function DOMException() {
     [native code]

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/workers/interfaces/WorkerUtils/importScripts/report-error-same-origin.sub.any.worker-expected.txt (291997 => 291998)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/workers/interfaces/WorkerUtils/importScripts/report-error-same-origin.sub.any.worker-expected.txt	2022-03-28 22:23:39 UTC (rev 291997)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/workers/interfaces/WorkerUtils/importScripts/report-error-same-origin.sub.any.worker-expected.txt	2022-03-28 22:35:26 UTC (rev 291998)
@@ -1,4 +1,3 @@
-CONSOLE MESSAGE: SyntaxError: Unexpected token ';'
 
 PASS WorkerGlobalScope error event: error
 PASS WorkerGlobalScope error event: message

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/workers/interfaces/WorkerUtils/importScripts/report-error-setTimeout-cross-origin.sub.any.worker-expected.txt (291997 => 291998)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/workers/interfaces/WorkerUtils/importScripts/report-error-setTimeout-cross-origin.sub.any.worker-expected.txt	2022-03-28 22:23:39 UTC (rev 291997)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/workers/interfaces/WorkerUtils/importScripts/report-error-setTimeout-cross-origin.sub.any.worker-expected.txt	2022-03-28 22:35:26 UTC (rev 291998)
@@ -1,4 +1,3 @@
-CONSOLE MESSAGE: Error: Script error.
 
 FAIL WorkerGlobalScope error event: error assert_equals: e.error should be a DOMException expected function "function DOMException() {
     [native code]

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/workers/interfaces/WorkerUtils/importScripts/report-error-setTimeout-redirect-to-cross-origin.sub.any.worker-expected.txt (291997 => 291998)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/workers/interfaces/WorkerUtils/importScripts/report-error-setTimeout-redirect-to-cross-origin.sub.any.worker-expected.txt	2022-03-28 22:23:39 UTC (rev 291997)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/workers/interfaces/WorkerUtils/importScripts/report-error-setTimeout-redirect-to-cross-origin.sub.any.worker-expected.txt	2022-03-28 22:35:26 UTC (rev 291998)
@@ -1,4 +1,3 @@
-CONSOLE MESSAGE: Error: Script error.
 
 FAIL WorkerGlobalScope error event: error assert_equals: e.error should be a DOMException expected function "function DOMException() {
     [native code]

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/workers/interfaces/WorkerUtils/importScripts/report-error-setTimeout-same-origin.sub.any.worker-expected.txt (291997 => 291998)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/workers/interfaces/WorkerUtils/importScripts/report-error-setTimeout-same-origin.sub.any.worker-expected.txt	2022-03-28 22:23:39 UTC (rev 291997)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/workers/interfaces/WorkerUtils/importScripts/report-error-setTimeout-same-origin.sub.any.worker-expected.txt	2022-03-28 22:35:26 UTC (rev 291998)
@@ -1,4 +1,3 @@
-CONSOLE MESSAGE: SyntaxError: Unexpected token ';'
 
 PASS WorkerGlobalScope error event: error
 PASS WorkerGlobalScope error event: message

Modified: trunk/LayoutTests/js/script-tests/weakref-finalizationregistry.js (291997 => 291998)


--- trunk/LayoutTests/js/script-tests/weakref-finalizationregistry.js	2022-03-28 22:23:39 UTC (rev 291997)
+++ trunk/LayoutTests/js/script-tests/weakref-finalizationregistry.js	2022-03-28 22:35:26 UTC (rev 291998)
@@ -18,7 +18,7 @@
         setTimeout(() => {
             gc();
             resolve();
-        }, 0);
+        }, 1);
     });
 }
 

Modified: trunk/Source/WebCore/ChangeLog (291997 => 291998)


--- trunk/Source/WebCore/ChangeLog	2022-03-28 22:23:39 UTC (rev 291997)
+++ trunk/Source/WebCore/ChangeLog	2022-03-28 22:35:26 UTC (rev 291998)
@@ -1,3 +1,52 @@
+2022-03-28  Cameron McCormack  <[email protected]>
+
+        Remove the 1ms minimum for setTimeout
+        https://bugs.webkit.org/show_bug.cgi?id=221124
+        <rdar://problem/73852354>
+
+        Reviewed by Sam Weinig.
+
+        This patch removes the 1ms minimum for setTimeout. The HTML spec makes
+        no mention of such a minimum, and Firefox and Chrome do not enforce
+        this minimum. Removing this for setTimeout results in a 0.7-2.1%
+        improvement on Speedometer, depending on platform and hardware.
+
+        The WPT added here demonstrates how this change can affect pages: if a
+        page schedules a 1ms and then a 0ms timeout in the same turn of the
+        event loop, then with this patch they will now be fired in the reverse
+        order. Since Firefox and Chrome do not impose a 1ms minimum, this
+        reduces the risk of this being a compatbility problem.
+
+        Scheduling a 0ms timeout will cause its callback to be called the next
+        time around the event loop. Other, non-timer queued tasks, will be
+        pre-empted. This behavior is permitted by the HTML spec, since the
+        event loop processing model[1] states that the implementation can
+        choose which task source to service, and timer callbacks are
+        dispatched using their own task source. Due to the way the SharedTimer
+        is called, we don't need to literally dispatch a task with a new
+        TaskSource::Timer source. (If we decided later to make a different
+        about whether to service timer callbacks before tasks from all other
+        task sources, we might need to.)
+
+        Not addressing the setTimeout 1ms minimum here, which should likely also
+        be removed.
+
+        While we're here, settle on "one shot" rather rather than "single
+        shot" as the term for timers that fire once.
+
+        [1] https://html.spec.whatwg.org/#event-loop-processing-model
+
+        Tests: imported/w3c/web-platform-tests/html/webappapis/timers/zero-settimeout.any.html
+               imported/w3c/web-platform-tests/html/webappapis/timers/zero-settimeout.any.worker.html
+
+        * page/DOMTimer.h:
+        * page/DOMTimer.cpp:
+        (WebCore::DOMTimer::DOMTimer):
+        (WebCore::DOMTimer::install):
+        (WebCore::DOMTimer::fired):
+        (WebCore::DOMTimer::updateTimerIntervalIfNecessary):
+        (WebCore::DOMTimer::intervalClampedToMinimum const):
+
 2022-03-28  Chris Dumez  <[email protected]>
 
         Prepare WebCore for making the String(const char*) constructor explicit

Modified: trunk/Source/WebCore/page/DOMTimer.cpp (291997 => 291998)


--- trunk/Source/WebCore/page/DOMTimer.cpp	2022-03-28 22:23:39 UTC (rev 291997)
+++ trunk/Source/WebCore/page/DOMTimer.cpp	2022-03-28 22:35:26 UTC (rev 291998)
@@ -49,6 +49,8 @@
 namespace WebCore {
 
 static const Seconds minIntervalForNonUserObservableChangeTimers { 1_s }; // Empirically determined to maximize battery life.
+static const Seconds minIntervalForOneShotTimers { 0_ms };
+static const Seconds minIntervalForRepeatingTimers { 1_ms };
 static const int maxTimerNestingLevel = 5;
 
 class DOMTimerFireState {
@@ -155,16 +157,17 @@
 
 bool NestedTimersMap::isTrackingNestedTimers = false;
 
-DOMTimer::DOMTimer(ScriptExecutionContext& context, Function<void(ScriptExecutionContext&)>&& action, Seconds interval, bool singleShot)
+DOMTimer::DOMTimer(ScriptExecutionContext& context, Function<void(ScriptExecutionContext&)>&& action, Seconds interval, bool oneShot)
     : SuspendableTimerBase(&context)
     , m_nestingLevel(context.timerNestingLevel())
     , m_action(WTFMove(action))
     , m_originalInterval(interval)
     , m_throttleState(Undetermined)
+    , m_oneShot(oneShot)
     , m_currentTimerInterval(intervalClampedToMinimum())
     , m_userGestureTokenToForward(UserGestureIndicator::currentUserGesture())
 {
-    if (singleShot)
+    if (oneShot)
         startOneShot(m_currentTimerInterval);
     else
         startRepeating(m_currentTimerInterval);
@@ -172,17 +175,17 @@
 
 DOMTimer::~DOMTimer() = default;
 
-int DOMTimer::install(ScriptExecutionContext& context, std::unique_ptr<ScheduledAction> action, Seconds timeout, bool singleShot)
+int DOMTimer::install(ScriptExecutionContext& context, std::unique_ptr<ScheduledAction> action, Seconds timeout, bool oneShot)
 {
     auto actionFunction = [action = "" context) mutable {
         action->execute(context);
     };
-    return DOMTimer::install(context, WTFMove(actionFunction), timeout, singleShot);
+    return DOMTimer::install(context, WTFMove(actionFunction), timeout, oneShot);
 }
 
-int DOMTimer::install(ScriptExecutionContext& context, Function<void(ScriptExecutionContext&)>&& action, Seconds timeout, bool singleShot)
+int DOMTimer::install(ScriptExecutionContext& context, Function<void(ScriptExecutionContext&)>&& action, Seconds timeout, bool oneShot)
 {
-    Ref<DOMTimer> timer = adoptRef(*new DOMTimer(context, WTFMove(action), timeout, singleShot));
+    Ref<DOMTimer> timer = adoptRef(*new DOMTimer(context, WTFMove(action), timeout, oneShot));
     timer->suspendIfNeeded();
 
     // Keep asking for the next id until we're given one that we don't already have.
@@ -190,7 +193,7 @@
         timer->m_timeoutId = context.circularSequentialID();
     } while (!context.addTimeout(timer->m_timeoutId, timer.get()));
 
-    InspectorInstrumentation::didInstallTimer(context, timer->m_timeoutId, timeout, singleShot);
+    InspectorInstrumentation::didInstallTimer(context, timer->m_timeoutId, timeout, oneShot);
 
     // Keep track of nested timer installs.
     if (NestedTimersMap* nestedTimers = NestedTimersMap::instanceForContext(context))
@@ -198,7 +201,7 @@
 #if ENABLE(CONTENT_CHANGE_OBSERVER)
     if (is<Document>(context)) {
         auto& document = downcast<Document>(context);
-        document.contentChangeObserver().didInstallDOMTimer(timer.get(), timeout, singleShot);
+        document.contentChangeObserver().didInstallDOMTimer(timer.get(), timeout, oneShot);
         if (DeferDOMTimersForScope::isDeferring())
             document.domTimerHoldingTank().add(timer.get());
     }
@@ -288,8 +291,6 @@
     // wait unit the end of this function to delete DOMTimer.
     Ref<DOMTimer> protectedThis(*this);
 
-    bool _oneShot_ = !repeatInterval();
-
     ASSERT(scriptExecutionContext());
     ScriptExecutionContext& context = *scriptExecutionContext();
 
@@ -297,7 +298,7 @@
     if (is<Document>(context)) {
         auto& document = downcast<Document>(context);
         if (auto* holdingTank = document.domTimerHoldingTankIfExists(); holdingTank && holdingTank->contains(*this)) {
-            if (oneShot)
+            if (m_oneShot)
                 startOneShot(0_s);
             return;
         }
@@ -315,7 +316,7 @@
     // Only the first execution of a multi-shot timer should get an affirmative user gesture indicator.
     m_userGestureTokenToForward = nullptr;
 
-    InspectorInstrumentation::willFireTimer(context, m_timeoutId, oneShot);
+    InspectorInstrumentation::willFireTimer(context, m_timeoutId, m_oneShot);
 
     // Simple case for non-one-shot timers.
     if (isActive()) {
@@ -326,7 +327,7 @@
 
         m_action(context);
 
-        InspectorInstrumentation::didFireTimer(context, m_timeoutId, oneShot);
+        InspectorInstrumentation::didFireTimer(context, m_timeoutId, m_oneShot);
 
         updateThrottlingStateIfNecessary(fireState);
         return;
@@ -344,13 +345,13 @@
 #endif
     m_action(context);
 
-    InspectorInstrumentation::didFireTimer(context, m_timeoutId, oneShot);
+    InspectorInstrumentation::didFireTimer(context, m_timeoutId, m_oneShot);
 
     // Check if we should throttle nested single-shot timers.
     if (nestedTimers) {
         for (auto& idAndTimer : *nestedTimers) {
             auto& timer = idAndTimer.value;
-            if (timer->isActive() && !timer->repeatInterval())
+            if (timer->isActive() && timer->m_oneShot)
                 timer->updateThrottlingStateIfNecessary(fireState);
         }
         nestedTimers->stopTracking();
@@ -374,13 +375,13 @@
     if (previousInterval == m_currentTimerInterval)
         return;
 
-    if (repeatInterval()) {
+    if (m_oneShot) {
+        LOG(DOMTimers, "%p - Updating DOMTimer's fire interval from %.2f ms to %.2f ms due to throttling.", this, previousInterval.milliseconds(), m_currentTimerInterval.milliseconds());
+        augmentFireInterval(m_currentTimerInterval - previousInterval);
+    } else {
         ASSERT(repeatInterval() == previousInterval);
         LOG(DOMTimers, "%p - Updating DOMTimer's repeat interval from %.2f ms to %.2f ms due to throttling.", this, previousInterval.milliseconds(), m_currentTimerInterval.milliseconds());
         augmentRepeatInterval(m_currentTimerInterval - previousInterval);
-    } else {
-        LOG(DOMTimers, "%p - Updating DOMTimer's fire interval from %.2f ms to %.2f ms due to throttling.", this, previousInterval.milliseconds(), m_currentTimerInterval.milliseconds());
-        augmentFireInterval(m_currentTimerInterval - previousInterval);
     }
 }
 
@@ -389,7 +390,7 @@
     ASSERT(scriptExecutionContext());
     ASSERT(m_nestingLevel <= maxTimerNestingLevel);
 
-    Seconds interval = std::max(1_ms, m_originalInterval);
+    Seconds interval = std::max(m_oneShot ? minIntervalForOneShotTimers : minIntervalForRepeatingTimers, m_originalInterval);
 
     // Only apply throttling to repeating timers.
     if (m_nestingLevel < maxTimerNestingLevel)

Modified: trunk/Source/WebCore/page/DOMTimer.h (291997 => 291998)


--- trunk/Source/WebCore/page/DOMTimer.h	2022-03-28 22:23:39 UTC (rev 291997)
+++ trunk/Source/WebCore/page/DOMTimer.h	2022-03-28 22:35:26 UTC (rev 291998)
@@ -92,6 +92,7 @@
     Function<void(ScriptExecutionContext&)> m_action;
     Seconds m_originalInterval;
     TimerThrottleState m_throttleState;
+    bool m_oneShot;
     Seconds m_currentTimerInterval;
     RefPtr<UserGestureToken> m_userGestureTokenToForward;
 };
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to