Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Firefox function parameter values not undefined when I'd expect themto be

Reply
Thread Tools

Firefox function parameter values not undefined when I'd expect themto be

 
 
news@chthonic.f9.co.uk
Guest
Posts: n/a
 
      02-17-2010
First off, I KNOW this was a stupid thing to do and I've recoded the
function I was using to eliminate the parameter entirely, but I just
spent several hours debugging this and need to share

I have a function that calls itself via setTimeout and is occasionally
called directly. That function has an optional parameter which I was
relying on NOT begin set to anything (ie being undefined) when called
from the setTimeout, and being set to a particular number when called
directly.

Of the few browsers I've tested, IE8 and Opera 9.64 gives undefined
for all calls as you'd expected, but firefox 3.5.7 gives undefined for
the first call and then zero and the occasional random numbers as the
parameter value:

<html>
<head>
<title>timeout bug test</title>
<script type="text/javascript">
var timerDelay = 1000;
function doSomething(optionalParameter) {
var outputElement = document.getElementById('output');
outputElement.innerHTML += '<br>optionalParameter = '
+ optionalParameter;
window.setTimeout(doSomething, timerDelay);
}
</script>
</head>
<body onload="doSomething();">
<p id="output"></p>
</body>
</html>

The answer, as I've said, is don't do it this way. But the question
is, is this a bug in Firefox, or a case where the language behaviour
is not defined.

I'd appreciate people's thoughts.

Mike
--
Mike Trinder
www.chthonicionic.net
 
Reply With Quote
 
 
 
 
Richard Cornford
Guest
Posts: n/a
 
      02-17-2010
On Feb 17, 12:38 pm, (E-Mail Removed)9.co.uk wrote:
<snip>
> The answer, as I've said, is don't do it this way. But the
> question is, is this a bug in Firefox, or a case where the
> language behaviour is not defined.


Neither, this is not a language issue, but rather a hose environment
issue. The/any - setTimeout - function is provided by the (browser)
host and since no applicable standard exists, its behaviour should not
be expected to be consistent between environments.

The specific behaviour you describe in Firefox has been in that family
of browsers since Netscape 4 at least. There are even people who
maintain that it is the 'correct' behaviour, and charge Microsoft,
etc. with failing when the do not reproduce it.

> I'd appreciate people's thoughts.


Browser scripting is not an area where observations made in any number
of specific environments can be generalised as being applicable in all
environments.

Richard.
 
Reply With Quote
 
 
 
 
news@chthonic.f9.co.uk
Guest
Posts: n/a
 
      02-17-2010
On Feb 17, 2:07*pm, Stefan Weiss <(E-Mail Removed)> wrote:
> On 17/02/10 13:38, (E-Mail Removed)9.co.uk wrote:
>
>
>
> > First off, I KNOW this was a stupid thing to do and I've recoded the
> > function I was using to eliminate the parameter entirely, but I just
> > spent several hours debugging this and need to share

>
> > I have a function that calls itself via setTimeout and is occasionally
> > called directly. That function has an optional parameter which I was
> > relying on NOT begin set to anything (ie being undefined) when called
> > from the setTimeout, and being set to a particular number when called
> > directly.

>
> > Of the few browsers I've tested, IE8 and Opera 9.64 gives undefined
> > for all calls as you'd expected, but firefox 3.5.7 gives undefined for
> > the first call and then zero and the occasional random numbers as the
> > parameter value:

>
> > <html>
> > <head>
> > * <title>timeout bug test</title>
> > * <script type="text/javascript">
> > * * *var timerDelay = 1000;
> > * * * *function doSomething(optionalParameter) {
> > * * * * *var outputElement = document.getElementById('output');
> > * * * * *outputElement.innerHTML += '<br>optionalParameter = '
> > * * * * * * * + optionalParameter;
> > * * * * *window.setTimeout(doSomething, timerDelay);
> > * * * *}
> > * </script>
> > </head>
> > <body onload="doSomething();">
> > * <p id="output"></p>
> > </body>
> > </html>

>
> > The answer, as I've said, is don't do it this way. But the question
> > is, is this a bug in Firefox, or a case where the language behaviour
> > is not defined.

>
> Actually, it's both. As Richard said, window.setTimeout is not a
> language feature, and thus its behavior is not defined by the language
> standard.
>
> Your specific observation is a very old bug (or rather oddity) in
> Mozilla browsers: the extra argument is the "lateness" of the function
> call.


Doh! As soon as you mentioned that, I remembered this from way, way
back. It bit me particularly badly because I was expecting a numeric
parameter or "undefined" and mozilla was helpfully giving me a numeric
every time.

>
> This bug has been closed as WONTFIX, apparently to maintain
> compatibility with Netscape 4:
>
> https://bugzilla.mozilla.org/show_bug.cgi?id=10637
>


I'm sure this will please all the Netscape 4 users out there

Thanks for the comprehensive reply (and thanks too to Richard who got
in there first with a more general response)

Mike

 
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
Passing parameter to function not expecting parameter Mister B C Programming 8 08-26-2010 08:01 AM
How to pass a parameter for a function parameter in a function AzamSharp Javascript 2 07-05-2008 12:24 AM
how to expect eof with expect+pty Simon Strandgaard Ruby 4 12-20-2006 04:00 PM
Bug in $obj->expect() ... ? (Expect 1.15) Phil Perl Misc 0 07-07-2006 07:25 AM
write a function such that when ever i call this function in some other function .it should give me tha data type and value of calling function parameter komal C++ 6 01-25-2005 11:13 AM



Advertisments