Bug 14090 - Redeclaring function throws syntax error
Summary: Redeclaring function throws syntax error
Status: RESOLVED DUPLICATE of bug 13790
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: 523.x (Safari 3)
Hardware: Mac OS X 10.4
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-06-12 09:18 PDT by Brad Fults
Modified: 2008-11-24 16:16 PST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Brad Fults 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.
Comment 1 Mark Rowe (bdash) 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;
    };
}

Comment 2 Cameron Zwarich (cpst) 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.
Comment 3 Alexey Proskuryakov 2008-06-09 16:57:54 PDT
Per the bug description, this sounds like a compatibility issue.
Comment 4 Cameron Zwarich (cpst) 2008-11-24 16:16:08 PST

*** This bug has been marked as a duplicate of 13790 ***