return when desugaring to closures

Brendan Eich brendan at mozilla.com
Fri Oct 17 11:30:10 PDT 2008


On Oct 17, 2008, at 11:05 AM, Waldemar Horwat wrote:

> Brendan Eich wrote:
>> Is this a perfectly valid for-in statement?
>>
>> for (a = b in c);
>>
>> Not according to ES3's grammar. An assignment expression is not  
>> valid on
>> the left of the for-in's "in":
>>
>> /IterationStatement /*:*
>> *      ...*
>> *      for ( */LeftHandSideExpression /*in */Expression /*) */ 
>> Statement/
>> *      for ( var */VariableDeclarationNoIn /*in */Expression /*)

(Note VariableDeclarationNoIn after var.)


>>
>> */Statement/
>>
>> LeftHandSideExpression does not produce an unparenthesized
>> AssignmentExpression, and if  you parenthesize then PutValue will  
>> throw
>> on the non-Reference result of the assignment, the ReferenceError at
>> runtime which again can become SyntaxError at compile time.
>
> I accidentally took out the "var" in editing the message.  It should  
> have been
>
> for (var a = ...)
>
>    Waldemar
> _

In that case the -NoIn sub-grammar should apply, extended to  
LetExpressionNoIn. So

for (let (a = b) c in d);

would do what you want. We would have to change SpiderMonkey for this  
edge case, but that is our problem (and unlikely to break anyone).

/be



More information about the Es-discuss mailing list