Bug 14090
Summary: | Redeclaring function throws syntax error | ||
---|---|---|---|
Product: | WebKit | Reporter: | Brad Fults <bfults> |
Component: | JavaScriptCore | Assignee: | 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
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 | ||
---|---|---|
Add attachment proposed patch, testcase, etc. |
Mark Rowe (bdash)
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)
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
Per the bug description, this sounds like a compatibility issue.
Cameron Zwarich (cpst)
*** This bug has been marked as a duplicate of 13790 ***