evaling anonymous function declarations

Allen Wirfs-Brock Allen.Wirfs-Brock at microsoft.com
Fri Jun 12 16:49:05 PDT 2009


Waldemar's notes from the May F2F meeting say:

" We'll extend the function definition grammar to make the name optional.  If the name is missing, the function is not declared but instead it is returned as the completion value.  This is needed in practice by the current browsers' implementations of eval."

My recollection is that this phase of the meeting started by discussing the issue that eval ("3; function foo(){};}") should return 3,  but that the ES3/ ES5 spec. for Program doesn't actually produce that result.  My notes say we decided that the ES5 spec. should be corrected in that regard. I remember that there was also some discussion on the anonymous function declaration issue  but I don't specifically remember us reaching the conclusion Waldemar reports.

Basically, the anonymous function declaration issue is about whether or not eval("function () {};"); should return a function object or produce a syntax error although the suggested fix would also make such anonymous function declaration syntactically legal outside of evals.

Cursory testing suggests that Opera and Chrome return the function; that FF, and Safari throw a syntax error; and, that IE returns undefined.

Technically, this is "new syntax" (if we do this there will be valid ES5 programs that cause syntax errors on ES3 implementations) and it doesn't  meet the 3 out of 4 (or 5) guideline we've applied in the past.

I'm not necessarily against this change (I think there are good usability arguments in its favor) but I want to verify that we either actually agreed to it at the meeting or that there is sufficient consensus now to make the change.

Allen



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es5-discuss/attachments/20090612/43f2c889/attachment-0001.html>


More information about the es5-discuss mailing list