Closed Bug 301693 Opened 19 years ago Closed 19 years ago

Bug when creating anonymous function

Categories

(Core :: JavaScript Engine, defect)

1.7 Branch
defect
Not set
critical

Tracking

()

RESOLVED INVALID

People

(Reporter: ralf, Unassigned)

References

Details

User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; de-DE; rv:1.7.8) Gecko/20050511 Firefox/1.0.4
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; de-DE; rv:1.7.8) Gecko/20050511 Firefox/1.0.4

Dear mozilla team ...

I think the following JavaScript program is syntactically correct, but you get a
syntax error in the latest Mozilla/Firefox versions (in the past it was okay)...
Since in Javascript functions are first-class citizens this example shoud be
correct JS code (even if useless and senseless)...

<script type="text/javascript" language="JavaScript">
<!--
function() {};
//-->
</script>


The following similar program still works well:


<script type="text/javascript" language="JavaScript">
<!--
42;
//-->
</script>

It sounds like a minor issue but it's really a big issue for our software
company ... we have problems in all of our projects due to this problem ....

Thanks a lot in advance

Have fun
Ralf

Reproducible: Always
No, this is a syntax error, function declarations require an identifier, see 
ECMA 262, chapter 13. This has been fixed recently in bug 299209. 

Can't you just use a function expression, the following is syntactically 
correct:

<script>
void function() {}
</script>
Hi Erik,

many thanks for your answer.
You are right: A function declaraton requires an identifier.
But not a function EXPRESSION.

function() {} is an expression.

I hope I am right when saying a standalone expression is syntactically correct
and so is a JavaScript program consisting of only one single expression (Like /*
start program */ 42 /* end program */).

To be more detailed:
The real issue is that eval("function () {...}") does not work any longer (but I
think it's the same problem).

Thanks for your help

Regards
Ralf
*** Bug 301698 has been marked as a duplicate of this bug. ***
Assignee: general → general
Component: General → JavaScript Engine
Product: Mozilla Application Suite → Core
QA Contact: general → general
Version: unspecified → 1.7 Branch
Ralf: parenthesize to force expression context.  Per ECMA-262, eval takes a
program source string as its argument, and again, the ECMA grammar explicitly
forbids unnamed function declarations (see ECMA-262 Ed. 3, 12.4 -- notice the
lookahead restriction).

/be
Status: UNCONFIRMED → RESOLVED
Closed: 19 years ago
Resolution: --- → INVALID
Hi everybody,

okay, that's convincing ... ;o)
Thank you very very much for your help.

Have a nice day
Ralf
You need to log in before you can comment on or make changes to this bug.