Assigning to globals in strict mode

Brendan Eich brendan at mozilla.org
Tue Oct 19 13:09:45 PDT 2010


On Oct 19, 2010, at 12:05 PM, Oliver Hunt wrote:

> On Oct 19, 2010, at 11:59 AM, Mark S. Miller wrote:
> 
>> On Tue, Oct 19, 2010 at 11:49 AM, Oliver Hunt <oliver at apple.com> wrote:
>> I interpreted this as meaning the exception occurs when we fail to find a reference to write to. eg. immediately following the evaluation of the LHS.
>> 
>> This also results in
>> 
>> "use strict"; undeclared = global.undeclared = 5;
>> 
>> throwing without creating the global property undeclared.
>> 
>> Minefield nightlies currently throw after evaluating rhs, webkit throws after the lhs is evaluated.
>> 
>> Given I think both interpretations are valid the spec really should be updated to state the exact moment that an exception is thrown.
>> 
>> I agree. Which interpretation do you recommend?
> 
> I honestly think that throwing after LHS is evaluated and found to be an undefined reference makes the most sense -- it prevents the example i brought up earlier from really being a problem (as you never get to the point where the global is created) and prevents you from causing any side effects prior to the exception being thrown.

Agreed, LHS evaluation, before RHS evaluation, is the place to throw.


> OTOH if we thought of this in terms of getters/setters:
> 
> o = {get foo (){}, set foo(){ throw "argh!"; }}
> with (o)
>   foo = 5;
> 
> Doesn't throw until the [[Put]] occurs.

That's a different case, though. The setter has already been evaluated and bound in to foo in o, in a prior statement, even. There's no unresolved reference at the time the LHS of |foo = 5| is evaluated.

/be

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


More information about the es5-discuss mailing list