Skip to content

Commit

Permalink
Remove a setTimeout()'s entry in the map of active timers after it runs
Browse files Browse the repository at this point in the history
It used to be unobservable whether a non-repeating timer that had already run its callback had an entry in the list of active timers or not, and so those entries were never removed from the list. However, calculation of the idle deadline, meaning that if a timer expires and is never cancelled, the deadline will be in the past.

This change avoids this case by removing non-repeating timers from the map of active timers after their callback runs.

Closes whatwg#7376.
  • Loading branch information
Andreu Botella authored Nov 30, 2021
1 parent cfb20f5 commit e9ba78f
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -96875,6 +96875,9 @@ enum <dfn enum>DOMParserSupportedType</dfn> {
<li><p>If <var>repeat</var> is true, then perform the <span>timer initialization
steps</span> again, given <var>global</var>, <var>handler</var>, <var>timeout</var>,
<var>arguments</var>, true, and <var>id</var>.</p></li>

<li><p>Otherwise, <span data-x="map remove">remove</span> <var>global</var>'s <span>map of
active timers</span>[<var>id</var>].</p></li>
</ol>
</li>

Expand All @@ -96886,16 +96889,9 @@ enum <dfn enum>DOMParserSupportedType</dfn> {
task">queues a global task</span> on the <dfn export>timer task source</dfn> given
<var>global</var> to run <var>task</var>.</p></li>

<li>
<p><span>Run steps after a timeout</span> given <var>global</var>, "<code
data-x="">setTimeout/setInterval</code>", <var>timeout</var>, <var>completionStep</var>, and
<var>id</var>.</p>

<p class="note">Once the task has been processed, if <var>repeat</var> is false, it is safe to
remove the entry for <var>id</var> from the <span>map of active timers</span> (there is no way
for the entry's existence to be detected past this point, so it does not technically matter one
way or the other).</p>
</li>
<li><p><span>Run steps after a timeout</span> given <var>global</var>, "<code
data-x="">setTimeout/setInterval</code>", <var>timeout</var>, <var>completionStep</var>, and
<var>id</var>.</p></li>

<li><p>Return <var>id</var>.</p></li>
</ol>
Expand Down Expand Up @@ -96996,6 +96992,9 @@ scheduleWork(); // queues a task to do lots of work</code></pre>
</li>

<li><p>Perform <var>completionSteps</var>.</p></li>

<li><p>If <var>timerKey</var> is a non-numeric value, <span data-x="map remove">remove</span>
<var>global</var>'s <span>map of active timers</span>[<var>timerKey</var>].</p></li>
</ol>
</li>
</ol>
Expand Down

0 comments on commit e9ba78f

Please sign in to comment.