Andre said:
Does anyone know whether the ECMA, or an other standard document,
specifies a maximum for the value that can be pass to the setTimeOut()
function in Javascript?
There is no setTimeOut() function, and there is no Javascript.
That was easy
Seriously, the language we are talking about in this case is either
(Netscape) JavaScript, or (Microsoft) JScript, or an implementation
of one or both of them. With the exception of JavaScript 1.0, both
languages are indeed conforming ECMAScript implementations.
But as Jim already said, setTimeout(), as it is spelled properly,
is not defined by any specification as yet. It is a method of the
host object that can be referred to by `window' (and often, if not
always, a method of the Global Object in HTML UAs), which was never
really a part of any programming language, instead it is a feature
of the AOM/DOM of an HTML user agent. (Although it is included in
the JavaScript References from versions 1.0 to 1.3, thereby referring
to the Netscape Navigator AOM/DOM.)
Probably you mean the value of the second argument of that method,
specifying the timeout length in milliseconds. So far there is no
reference material that says anything about a maximum value for it
explicitly:
JavaScript 1.3 Reference
<URL:
http://research.nihonsoft.org/javascript/ClientReferenceJS13/window.html#1203758>
Gecko DOM Reference
<URL:
http://developer.mozilla.org/en/docs/DOM:window.setTimeout>
MSDN Library: HTML and DHTML Reference
<URL:
http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/settimeout.asp>
Opera DOM
<URL:
http://www.opera.com/docs/specs/opera6/js/index.dml>
KHTML (Konqueror, Safari)
<
http://developer.kde.org/documentation/library/3.1-api/khtml/html/classKJS_1_1ScheduledAction.html>
....
<
http://developer.kde.org/documentation/library/3.4-api/khtml/html/classKJS_1_1ScheduledAction.html>
But for some UAs, you can read the Source, Luke:
<URL:
http://lxr.mozilla.org/mozilla1.8.0/source/dom/src/base/nsGlobalWindow.cpp#5971>
The lines
| #define DOM_MAX_TIMEOUT_VALUE PR_BIT(8 * sizeof(PRIntervalTime) - 1)
and
,-<URL:
http://lxr.mozilla.org/mozilla1.8.0/source/nsprpub/pr/include/prtypes.h#240>
| #define PR_BIT(n) ((PRUint32)1 << (n))
,-<URL:
http://lxr.mozilla.org/mozilla1.8.0/source/nsprpub/pr/include/prinrval.h#61>
| typedef PRUint32 PRIntervalTime;
,-<URL:
http://lxr.mozilla.org/mozilla1.8.0/source/nsprpub/pr/include/prtypes.h#330>
| typedef unsigned int PRUint32;
suggest (if I understand it correctly) that the maximum timeout length in a
Gecko-based UAs compiled for and running on a 32-bit machine is (following
the preprocessor steps)
PR_BIT(8 * sizeof(PRIntervalTime) - 1)
== ((unsigned int)1 << (8 * sizeof(PRUint32) - 1))
== ((unsigned int)1 << (8 * sizeof(unsigned int) - 1))
== ((unsigned int)1 << (8 * 4 - 1))
== ((unsigned int)1 << 31)
== 2147483648
milliseconds, which equals 24 standard days, 20 hours, 31 minutes, and
23.648 seconds. According to nsGlobalWindow.cpp, lines 6051 to 6055,
greater values will be normalized to that value.
What is most interesting is that this source code also makes it clear that
Gecko 1.8.0-based UAs (such as Firefox 1.5.0.1) will not handle timeouts or
intervals shorter than 10 milliseconds (nsGlobalWindow.cpp, lines 6044 to
6049, and 191 and 192). So if you provide a smaller value, the actual
timeout/interval length will be 10 milliseconds.
And for KHTML-based UAs:
<URL:
http://developer.kde.org/documentation/library/3.4-api/khtml/html/kjs__window_8h-source.html#l00177>
Since the value must be parsed by an ECMAScript implementation, the general
theoretical maximum value is max(IEEE754_DOUBLE), 1.798E308, which equals
about 5.7E297 years. However, it is probable that other implementations
also use an Integer type here, which would restrict the maximum value for
window.setTimeout() to the maximum value an extended integer register can
hold on the particular platform, assuming the use of a generic data type
in the UA's source code, such as `unsigned int' in C++.
If you mean the length of the string that can be used as the first argument
instead, there is nothing in the reference material about that either.
String literals (and C++ strings, which are in fact pointers to character
data) can be of arbitrary length; it is just a matter of available memory.
HTH
PointedEars