Bug 8993

Summary: Support function declaration in case statements
Product: WebKit Reporter: Anders Carlsson <andersca>
Component: JavaScriptCoreAssignee: Geoffrey Garen <ggaren>
Status: RESOLVED FIXED    
Severity: Normal    
Priority: P2    
Version: 420+   
Hardware: Mac   
OS: OS X 10.4   
Bug Depends on:    
Bug Blocks: 7788    
Attachments:
Description Flags
layout test
none
Patch with layout test and ChangeLog
none
Patch to prented that case statements are surrounded by curly braces
none
My implementation, for reference
none
Actually include the code changes ggaren: review+

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.