Bug 19143 - setTimeout and setInterval should clamp at the maximum timeout value
setTimeout and setInterval should clamp at the maximum timeout value
Status: RESOLVED WONTFIX
Product: HTML WG
Classification: Unclassified
Component: HTML5 spec
unspecified
PC All
: P2 normal
: ---
Assigned To: Edward O'Connor
HTML WG Bugzilla archive list
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2012-09-29 15:13 UTC by Aaron McBride
Modified: 2012-12-05 21:01 UTC (History)
6 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Aaron McBride 2012-09-29 15:13:30 UTC
The timeout is currently defined as a signed 32-bit int (aka "long").  I recently ran into a case where some code overflowed this int.  In all cases I found, the browsers treated the timeout as 0 (or possibly 4-10ms).  It seems reasonable that if the spec says to clamp small values to 4ms, then it would be nice to clamp large values to the something useful like the maximum allowed value (2^31 - 1).  It might also make sense to change from long to unsigned long, but that's a different issue.

Here's the sample code that got me in trouble:
setInterval(function () { console.log('test') }, 300000000000)

Here's where I filed an issue with Mozilla:
https://bugzilla.mozilla.org/show_bug.cgi?id=795373

and Chromium:
http://code.google.com/p/chromium/issues/detail?id=152991
Comment 1 Boris Zbarsky 2012-09-29 15:32:25 UTC
Given that all browsers agree here, I would worry about web compat issues with changes.

In particular, I'm >70% confident that using unsigned long would break sites that currently pass "-1" to setTimeout and expect that to mean "as soon as possible", because it would suddenly mean "never".
Comment 2 Aaron McBride 2012-09-29 16:06:21 UTC
Would it be possible to clamp before doing ToUint32, so -1 would become 4 before underflowing?  If that's not possible, then I agree that the type change isn't worth all of the problems.  That aside, does clamping the max make sense?
Comment 3 Boris Zbarsky 2012-11-29 17:37:29 UTC
> Would it be possible to clamp before doing ToUint32

Yes, using [Clamp].  That might be a reasonable thing to do, generally speaking, if we're not worried about sites that are passing in large numbers and expecting immediate firing.
Comment 4 Edward O'Connor 2012-12-05 21:01:35 UTC
EDITOR'S RESPONSE: This is an Editor's Response to your comment. If you are
satisfied with this response, please change the state of this bug to CLOSED. If
you have additional information and would like the Editor to reconsider, please
reopen this bug. If you would like to escalate the issue to the full HTML
Working Group, please add the TrackerRequest keyword to this bug, and suggest
title and text for the Tracker Issue; or you may create a Tracker Issue
yourself, if you are able to do so. For more details, see this document:

   http://dev.w3.org/html5/decision-policy/decision-policy.html

Status: Rejected
Change Description: No spec change.
Rationale: Given that all browsers currently interoperate, I don't think
we should risk the compat risk. The extant Web corpus has all sorts of
crazy values being passed to setTimeout.