Bug 8993 - Support function declaration in case statements
Summary: Support function declaration in case statements
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: 420+
Hardware: Mac OS X 10.4
: P2 Normal
Assignee: Geoffrey Garen
URL:
Keywords:
Depends on:
Blocks: 7788
  Show dependency treegraph
 
Reported: 2006-05-19 06:21 PDT by Anders Carlsson
Modified: 2006-05-20 13:14 PDT (History)
0 users

See Also:


Attachments
layout test (1.09 KB, text/html)
2006-05-19 15:48 PDT, Geoffrey Garen
no flags Details
Patch with layout test and ChangeLog (5.94 KB, patch)
2006-05-19 16:49 PDT, Geoffrey Garen
no flags Details | Formatted Diff | Diff
Patch to prented that case statements are surrounded by curly braces (10.27 KB, patch)
2006-05-19 20:30 PDT, Geoffrey Garen
no flags Details | Formatted Diff | Diff
My implementation, for reference (2.89 KB, patch)
2006-05-20 01:15 PDT, Anders Carlsson
no flags Details | Formatted Diff | Diff
Actually include the code changes (15.85 KB, patch)
2006-05-20 01:19 PDT, Anders Carlsson
ggaren: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Anders Carlsson 2006-05-19 06:21:40 PDT
The spec doesn't support this, but all other browsers support it.
Comment 1 Geoffrey Garen 2006-05-19 15:47:31 PDT
Interestingly enough, WebKit supports this if the function case statement's body is enclosed in curly braces.
Comment 2 Geoffrey Garen 2006-05-19 15:48:35 PDT
Created attachment 8421 [details]
layout test
Comment 3 Geoffrey Garen 2006-05-19 15:59:03 PDT
I'll take this one.
Comment 4 Geoffrey Garen 2006-05-19 16:49:02 PDT
Created attachment 8422 [details]
Patch with layout test and ChangeLog
Comment 5 Geoffrey Garen 2006-05-19 20:30:12 PDT
Created attachment 8427 [details]
Patch to prented that case statements are surrounded by curly braces

I like this patch better because it follows my own advice and also removes cruft from the grammar.

I still don't see why functions need to be distinguished in the grammar from plain old statements. Perhaps we can change that in another patch.
Comment 6 Darin Adler 2006-05-19 23:04:52 PDT
Comment on attachment 8427 [details]
Patch to prented that case statements are surrounded by curly braces

The grammar comes straight out of the ECMA standard. If there are things wrong with it, it probably means there are places where other browsers don't match the standard.

The CaseClause and DefaultClause productions are on page 68 of ECMA-262 3rd edition.
Comment 7 Anders Carlsson 2006-05-20 01:15:11 PDT
Created attachment 8429 [details]
My implementation, for reference

I realize now that I had forgotten to upload my patch! Sorry about that, Geoff.

It looks like we have different solutions to the problem. My patch always processes any function declarations wheras your patch does it before evaluating a case statement. 

I've tested with Opera, WinIE, MacIE and Firefox and everyone except Firefox follows the behavior I've implemented.
Comment 8 Anders Carlsson 2006-05-20 01:19:55 PDT
Created attachment 8430 [details]
Actually include the code changes
Comment 9 Geoffrey Garen 2006-05-20 08:00:25 PDT
That's funny -- I tested only in Firefox :). The IE/Opera behavior seems strange to me, but for compatibility's sake, I think it's best.

Anders, it looks like you uploaded only your layout test. Can you upload your patch as well?
Comment 10 Anders Carlsson 2006-05-20 08:47:35 PDT
I did that, it's in http://bugzilla.opendarwin.org/attachment.cgi?id=8430
Comment 11 Geoffrey Garen 2006-05-20 11:36:26 PDT
Comment on attachment 8430 [details]
Actually include the code changes 

OK, I'm gonna r+ this one since it's the IE/Opera behavior.