Assigning to globals in strict mode

Oliver Hunt oliver at apple.com
Tue Oct 19 11:49:13 PDT 2010


On Oct 19, 2010, at 10:30 AM, Jason Orendorff wrote:

> On Mon, Oct 18, 2010 at 12:12 PM, Oliver Hunt <oliver at apple.com> wrote:
>>>> "use strict"; undeclared = (this.undeclared = 5);
>>> * The left hand side evaluates to an unresolveable strict Reference
>>> (§10.2.2.1);
>>> * the right hand side evaluates to 5;
>>> * assignment to the Reference throws, because it is still
>>> unresolveable (see IsUnresolvableReference, §8.7), even though
>>> undeclared now exists.
>> 
>> Err when does the exception get thrown?
>> I just realised the spec does not state explicitly when the error should be
>> thrown
>> "When an assignment occurs within strict mode code, its LeftHandSide must
>> not evaluate to an unresolvable reference. If it does a ReferenceError
>> exception is thrown upon assignment."
>> Does 'assignment' in that sentence mean when we reach the assignment
>> expression, or does it mean at the point of PutValue()?
> 
> That part is a note, so I think it's just meant to summarize the more
> explicit parts of the spec. As far as I can tell, the ReferenceError
> is thrown in PutValue step 5. (The note also mentions some cases where
> strict assignment triggers a TypeError; that happens in
> [[DefineOwnProperty]].)
> 
> -j
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.

--Oliver



More information about the es5-discuss mailing list