Assigning to globals in strict mode

Jason Orendorff jason.orendorff at gmail.com
Tue Oct 19 10:30:24 PDT 2010


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


More information about the es5-discuss mailing list