Open Bug 449016 Opened 17 years ago Updated 3 years ago

setTimeout should guarantee that the function is never called early (late is ok)

Categories

(Core :: DOM: Core & HTML, defect, P5)

x86
Windows Server 2003
defect

Tracking

()

UNCONFIRMED

People

(Reporter: coldboyqn, Unassigned)

Details

(Keywords: testcase, Whiteboard: DUPEME)

User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1 Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1 I setTimeout at a specific time, for a delay of 300 miliseconds, and what I expect is that the function will be called after 300 miliseconds, may be 301, but not 299. But, actually, Firefox does that (while IE6 does not, :)). Sometimes, It call the function after 295 miliseconds. Reproducible: Always Steps to Reproduce: 1. Create a HTML file like that: ============================================================================ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script type="text/javascript"> var PageManager = { test: function() { for (var i = 0; i < 1000; i++) { var rnd = Math.round(1000 * Math.random()); setTimeout(function() { PageManager.performCheck() }, rnd); } }, performCheck: function() { ///<summary>Perform if the setTimeout can operate correctly</summary> var now = (new Date()).getTime(); setTimeout(this.getCheckDelayFunction(now, 300), 300); }, getCheckDelayFunction: function(from, delay) { return function() { var now = (new Date()).getTime(); var realDelay = now - from; var log = ["Expect", delay, "Obtain", realDelay, "from", from, "now", now, "<br/>"]; var div = document.createElement("div"); div.innerHTML += log.join(" "); document.getElementById("wow").appendChild(div); //console.debug.apply(console, log); } } } </script> </head> <body> <div> <input type="button" onclick="PageManager.test();" value="Test SmartOperation"/> <div id="wow"></div> </div> </body> </html> ============================================================================ 2. Press the [Test SmartOperation] button 3. And see the bug Actual Results: The (javascript variable)realDelay is sometimes smaller than the (javascript variable)delay. Expected Results: I expect the the (javascript variable)realDelay will be always equal or greater than the (javascript variable)delay
Component: General → DOM
Keywords: testcase
Product: Firefox → Core
QA Contact: general → general
Summary: javascript setTimeout not operated correctly → setTimeout should guarantee that the function is never called early (late is ok)
Whiteboard: DUPEME
I can confirm this on Firefox for Linux, version 3.5.3 Additionally, the function which is called back by setTimeout has a "lateness" parameter. This lateness is often negative! This allows to somewhat compensate, but really, this should not have to be done. The lateness parameter: If you call setTimeout(myfct,15,arg), then from within myfct, you can access arguments[arguments.length-1] to be equal to the lateness (ie: the difference between the time the call actually took place and the time it should have taken place).
https://bugzilla.mozilla.org/show_bug.cgi?id=1472046 Move all DOM bugs that haven’t been updated in more than 3 years and has no one currently assigned to P5. If you have questions, please contact :mdaly.
Priority: -- → P5
Component: DOM → DOM: Core & HTML
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.