Bug 14090

Summary: Redeclaring function throws syntax error
Product: WebKit Reporter: Brad Fults <bfults>
Component: JavaScriptCoreAssignee: Nobody <webkit-unassigned>
Status: RESOLVED DUPLICATE    
Severity: Normal CC: mrowe, zwarich
Priority: P2    
Version: 523.x (Safari 3)   
Hardware: Mac   
OS: OS X 10.4   

Brad Fults
Reported 2007-06-12 09:18:04 PDT
Using http://mochikit.com/examples/interpreter/ as a simple CLI. In r22084 nightly: >>> for (var i=10;i>=0;i--) function x(k) { return ++k; }; Error: line 1 message Parse error name SyntaxError In Firefox 2.0.0.4: >>> for (var i=10;i>=0;i--) function x(k) { return ++k; }; [no error] In Opera 9.21: >>> for (var i=10;i>=0;i--) function x(k) { return ++k; }; [no error] Similar results can be found in IE.
Attachments
Mark Rowe (bdash)
Comment 1 2007-06-13 16:21:30 PDT
This appears to be due to the lack of {}'s inside the for statement. The following example throws a syntax error: for (var i = 10; i >= 0; i--) function x(k) { return ++k; }; The following example does not: for (var i = 10; i >= 0; i--) { function x(k) { return ++k; }; }
Cameron Zwarich (cpst)
Comment 2 2008-06-09 16:39:22 PDT
This is invalid syntax, according to the grammar in the ECMA spec. The body of a for loop is a Statement, and a FunctionDeclaration is not a Statement. Unless this is actually a compatibility issue, we should probably close this bug.
Alexey Proskuryakov
Comment 3 2008-06-09 16:57:54 PDT
Per the bug description, this sounds like a compatibility issue.
Cameron Zwarich (cpst)
Comment 4 2008-11-24 16:16:08 PST
*** This bug has been marked as a duplicate of 13790 ***
Note You need to log in before you can comment on or make changes to this bug.