Unifying Block and ObjectLiteral (was: Re: block-lambda revival)

Brendan Eich brendan at mozilla.com
Thu Jun 30 20:31:01 PDT 2011


On Jun 30, 2011, at 6:32 PM, Mike Samuel wrote:

> 2011/6/28 Brendan Eich <brendan at mozilla.com>:
>> On Jun 23, 2011, at 3:27 PM, Brendan Eich wrote:
>> Block:
>>     { UnlabeledStatementFirstList }
>>     { WellLabeledStatement StatementList? }
> 
> If IfStatement is still defined
> 
> IfStatement :
>    if ( Expression ) Statement else Statement
>    if ( Expression ) Statement
> 
> then does this definition of Statement and Block change the program
> 
>   if (foo) { bar(); } else {}
> 
> to be equivalent to
> 
>   if (foo) { bar(); } else ({})
> 
> ?

No, remember I wrote "We'd still need the [lookahead ∉ {{, function}] restriction in ExpressionStatement."


> This is arguably a semantic change, but the change cannot be
> detectable by anything else the program could do.

That's not true if the {} in statement context were an expression whose result was discarded. In such an event (without the lookahead restriction and with some other restriction to disambiguate away from block-as-statement to block-as-expression), the completion value would differ from in ECMA-262 as it is, and eval or an embedding (javascript: URLs, e.g.) could tell.

But that empty block else clause is not a block-as-expression: it's a block-as-statement, so same semantics as in ECMA-262 as-is.

/be
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20110630/0afd7811/attachment.html>


More information about the es-discuss mailing list