Firefox setTimeout() bug demonstration

The following test calls a function doWork() that repeatedly calls itself with setTimeout() with a given delay. When behaving correctly, these times displayed should be no less than the delay.

Firefox 3.0.1 and older versions do not behave correctly. Specifically, the timeout often fires too early, sometimes signifcantly too early and repeatedly. A 2000ms spinloop is inserted after 1000ms to help demonstrate this (the problem may occur even before the spinloop). This can be a problem when trying to do smooth DHTML animation.

I believe this is related to https://bugzilla.mozilla.org/show_bug.cgi?id=291386

Click below to run the test with various delays:
10ms delay.
16ms delay.
50ms delay.
100ms delay.