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.
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; }; }
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.
Per the bug description, this sounds like a compatibility issue.
*** This bug has been marked as a duplicate of 13790 ***