Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > setTimeout() & ECMA

Reply
Thread Tools

setTimeout() & ECMA

 
 
Andre
Guest
Posts: n/a
 
      03-11-2006
Hi,

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?

Andre

 
Reply With Quote
 
 
 
 
Jim Ley
Guest
Posts: n/a
 
      03-11-2006
On 11 Mar 2006 12:38:13 -0800, "Andre" <(E-Mail Removed)>
wrote:

>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?


setTimeout is not standardised anywhere.

Jim.
 
Reply With Quote
 
 
 
 
Randy Webb
Guest
Posts: n/a
 
      03-11-2006
Andre said the following on 3/11/2006 3:38 PM:
> Hi,
>
> 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?


It would surprise me if there was one as it's irrelevant to the language
itself. But, if it does exist, then it's irrelevant anyway because I can
write a timeout to last as long as I want no matter what any spec may say.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
 
Reply With Quote
 
Douglas Crockford
Guest
Posts: n/a
 
      03-11-2006
>> 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?


> It would surprise me if there was one as it's irrelevant to the language
> itself. But, if it does exist, then it's irrelevant anyway because I can
> write a timeout to last as long as I want no matter what any spec may say.


It may surprise you that setTimeout is not covered by an ECMA standard, nor by a
W3C standard. There are some holes in the web standards. This is one of them.
I'm looking to the WHAT Working Group to fix this. See
http://www.whatwg.org/specs/web-apps/current-work/

There doesn't seem to be a problem in setting the timeout value to something
that is vastly greater than the MTBF of the browser. All that means is that the
timeout may never fire.

http://javascript.crockford.com/
 
Reply With Quote
 
Randy Webb
Guest
Posts: n/a
 
      03-11-2006
Douglas Crockford said the following on 3/11/2006 5:56 PM:
>>> 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?

>
>> It would surprise me if there was one as it's irrelevant to the
>> language itself. But, if it does exist, then it's irrelevant anyway
>> because I can write a timeout to last as long as I want no matter what
>> any spec may say.

>
> It may surprise you that setTimeout is not covered by an ECMA standard,
> nor by a W3C standard.


It does but it doesn't.

> There are some holes in the web standards. This is one of them. I'm
> looking to the WHAT Working Group to fix this. See
> http://www.whatwg.org/specs/web-apps/current-work/



Is there some underlying problem with setTimeout that it needs to be
standardized for any reason other than so it is standardized?


> There doesn't seem to be a problem in setting the timeout value to
> something that is vastly greater than the MTBF of the browser. All that
> means is that the timeout may never fire.


True. But even if there were a limit to a single call to setTimeout you
can exceed that limit by using multiple or recursive setTimeouts to get
the desired result. So any attempt to set a limit on the timer of
setTimeout would lead to more problems than it ever tried to solve and
would lead to code that looked something like this:

var timer1 = 0;
var loops = 30;

function SetTimeOut(){
if (timer1 == loops)
{
realFunctionYouWantToCall();
}
else{
timer1++;
window.setTimeout(SetTimeOut,maxValue);
}
}
window.setTimeout(SetTimeOut,maxValue);

Where maxValue would be the maximum value you could pass to setTimeout.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
 
Reply With Quote
 
Jim Ley
Guest
Posts: n/a
 
      03-12-2006
On Sat, 11 Mar 2006 18:55:20 -0500, Randy Webb
<(E-Mail Removed)> wrote:

>Is there some underlying problem with setTimeout that it needs to be
>standardized for any reason other than so it is standardized?


None at all, these de facto standards don't need to be standardised,
in fact standardising them can be very difficult. What is useful is
documenting what UAs do in a single place.

The WHAT WG Individual here is doing a valuable thing, unfortunately
writing it up as a spec is less helpful.

In any case, the work on the window object is also being documented by
W3 WEB API group <URL: http://www.w3.org/2006/webapi/ > including
setTimeout - You can even join in the discussion, e.g. <URL:
http://www.w3.org/mid/20060306174809...3c4-bis.w3.org >

(and is likely to leave the Web Apps in the WHAT...)

Jim.
 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      03-12-2006
Andre wrote:

> 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
 
Reply With Quote
 
Randy Webb
Guest
Posts: n/a
 
      03-12-2006
Jim Ley said the following on 3/11/2006 7:17 PM:
> On Sat, 11 Mar 2006 18:55:20 -0500, Randy Webb
> <(E-Mail Removed)> wrote:
>
>> Is there some underlying problem with setTimeout that it needs to be
>> standardized for any reason other than so it is standardized?

>
> None at all, these de facto standards don't need to be standardised,
> in fact standardising them can be very difficult. What is useful is
> documenting what UAs do in a single place.


Agreed.

> The WHAT WG Individual here is doing a valuable thing, unfortunately
> writing it up as a spec is less helpful.


Understood. As long as there is no limit on the time, as I showed, it is
easily circumvented making it moot to add it and only leads to
complicating code.

> In any case, the work on the window object is also being documented by
> W3 WEB API group <URL: http://www.w3.org/2006/webapi/ > including
> setTimeout - You can even join in the discussion, e.g. <URL:
> http://www.w3.org/mid/20060306174809...3c4-bis.w3.org >
>
> (and is likely to leave the Web Apps in the WHAT...)


I might read up on it Looks to be interesting.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
 
Reply With Quote
 
Dr John Stockton
Guest
Posts: n/a
 
      03-12-2006
JRS: In article <(E-Mail Removed). com>,
dated Sat, 11 Mar 2006 12:38:13 remote, seen in
news:comp.lang.javascript, Andre <(E-Mail Removed)> posted :

>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?


The value is a Number of milliseconds, and its limit is therefore the
maximum IEEE Double, a bit over 1.7E308, meaning about 5.3E297 years.

It's probable that the timeout operation will be implemented by the
operating system, and that the OS will impose a lower usable limit.
That's likely to be 2^N-1 ms, where N = 31 or 32. In Windows, 32,
allowing 49 days 17:02:47.295.

The MTBF of the browser should exceed 50 days; that of the OS might not.

Untested.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
 
Reply With Quote
 
Douglas Crockford
Guest
Posts: n/a
 
      03-13-2006
>>>> 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 are some holes in the web standards. This is one of them. I'm
>> looking to the WHAT Working Group to fix this. See
>> http://www.whatwg.org/specs/web-apps/current-work/


> Is there some underlying problem with setTimeout that it needs to be
> standardized for any reason other than so it is standardized?


The original question was what does the standard say? When you look to the
standard to answer questions, and the standard does not exist, that could be
viewed as a problem.

The lack of a standard should also be a concern to people who are dedicated to
standards based development. There are some fierce web developers who refuse to
touch anything that is not strictly standards compliant. How can a browser be
fully standards compliant if there do not exist standards for it to conform to?

Defacto standards and proprietary standards are not sufficient, I think.

http://javascript.crockford.com/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
The format of documents produced by Microsoft Office 2007 is notOOXML (Ecma 376). peterwn NZ Computing 12 02-17-2008 11:50 PM
Regex to transform java code to ecma script pondus Ruby 2 10-31-2006 04:41 AM
ECMA-372 is stepping in on C++ Michael Rasmussen C++ 12 01-22-2006 02:14 PM
Which to Learn: Javascript, Jscript, JScript.NET, ECMA 262 (3rd ed)? John Bentley Javascript 14 02-05-2004 06:14 PM
ECMA/IE/DNS/IIS/asp.net, I have no idea PJ ASP .Net 0 08-21-2003 09:44 AM



Advertisments