Firefox dies on simple script

  • Thread starter Christopher Benson-Manica
  • Start date
C

Christopher Benson-Manica

Is Firefox 1.0.1 within its rights to crash when presented with the
following script?

<html>
<head>
<script>
var foo="foo";
window.onerror=function( msg, url, line ) {
switch( msg ) {
default: break;
case foo: break;
}
}
</script></head></html>

I'm betting not; I'm planning to file a bug report.
 
C

Christopher Benson-Manica

kaeli said:
Why is your default at the beginning?

In the actual code, the default case falls through to another case
after alerting the user appropriately.
 
R

RobG

Christopher said:
Is Firefox 1.0.1 within its rights to crash when presented with the
following script?

<html>
<head>
<script>
var foo="foo";
window.onerror=function( msg, url, line ) {
switch( msg ) {
default: break;
case foo: break;
}
}
</script></head></html>

I'm betting not; I'm planning to file a bug report.

No script should cause the browser itself to crash, regardless
of syntactical correctness, so yes it's a bug in Firefox.

The ECMA spec does not state explicitly that the default
statement must be in any particular position:

<URL:http://www.mozilla.org/js/language/E262-3.pdf>

Section 12.11

However, putting it first with a single 'break' statement means
that none of the following clauses will be evaluated and
therefore it's something that is only likely to happen whilst
debugging.

There are a number of work-arounds, the simplest being to put a
trivial clause ahead of the default so that it is no longer
first:

window.onerror=function( msg, url, line ) {
switch( msg ) {
case foo2: continue;
default: break;
case foo: break;
}
}
 
M

Martin Honnen

Christopher said:
Is Firefox 1.0.1 within its rights to crash when presented with the
following script?

<html>
<head>
<script>
var foo="foo";
window.onerror=function( msg, url, line ) {
switch( msg ) {
default: break;
case foo: break;
}
}
</script></head></html>

I'm betting not; I'm planning to file a bug report.

Crash is always a bug, I seached whether you had filed one but couldn't
find it so I filed this as
<https://bugzilla.mozilla.org/show_bug.cgi?id=285755>
 
R

rh

RobG wrote:

The ECMA spec does not state explicitly that the default
statement must be in any particular position:

<URL:http://www.mozilla.org/js/language/E262-3.pdf>

Section 12.11

However, putting it first with a single 'break' statement means
that none of the following clauses will be evaluated and
therefore it's something that is only likely to happen whilst
debugging.

I don't think 12.11 reads quite that way. All "case" clauses should be
tested prior to forcing the default, regardless of the source-text
position of the "default" clause.

So the only time the source-text position of the default should be of
consequence is when there is a fall-through from a preceding case
statement execution sequence.
There are a number of work-arounds, the simplest being to put a
trivial clause ahead of the default so that it is no longer
first:

window.onerror=function( msg, url, line ) {
switch( msg ) {
case foo2: continue;
default: break;
case foo: break;
}
}

And while that's the right idea for a work-around, recall that
"continue" can only be used within an iterative construct. Something
like

case msg+'#':
default: break;


would seem to be a better choice as a (never-successful case) buffer.

../rh
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,743
Latest member
WoodrowMea

Latest Threads

Top