Assigning to ReadOnly properties

Brendan Eich brendan at mozilla.org
Mon Nov 12 11:26:32 PST 2007


On Nov 12, 2007, at 9:34 AM, Jonathan Watt wrote:

> I like the idea of a pragma more than opt-in versioning since it  
> can be used
> in-place, and (I guess) placed before and after a section of code  
> to turn the
> handling on then off again.

Pragmas are block-scoped, so just one should do.

>>    use readonly error
>>
>> or perhaps
>>
>>    use readonly throw
>>
>> We try to make pragmas more readable, sometimes with an extra word;
>> not sure this is the best way to phrase it still, but the idea would
>> be to enable throwing of a ReadOnlyError on assignment to a ReadOnly
>> property. Comments?
>
> Why not just:
>
>   use ReadOnlyError

Sure -- pragma convention so far  has been terse and lower-case, e.g.  
'use strict' or 'use decimal ...'.

> It's short, intuitive, and you don't need to remember whether it's  
> "error" or
> "throw" in the pragma. If you can use pragmas multiple times to  
> toggle things on
> and then off again, perhaps make it:
>
>   use ReadOnlyError on
>
>   // some code that should throw on assignment to ReadOnly properties
>
>   use ReadOnlyError off

I'm going to summon Jeff Dyer here.

> Ultimately, the ability to catch this class of error is more  
> important to me
> than the syntax to turn the feature on.

Indeed, but syntax is necessary and we may as well hash it out here.

Speaking of catching, it would be unfortunate if you wrote

   try { something that might set a ReadOnly property }
   catch (e : ReadOnlyError) { ... }

but forgot the pragma, and never heard a word of warning. There are  
no warnings in the spec, so normative error seems best. But if you're  
bothering to catch ReadOnlyError, must you also 'use ReadOnlyError'  
first (in the try, or in a block enclosing the whole try-catch)?

The pragma is necessary, since you may want termination semantics  
(use ReadOnlyError w/o ever catching that exception). But if you do  
catch, must you use as well? I'm throwing this out for some quick  
discussion. Thanks for posting about ReadOnly errors, I had it on my  
to-do list but you beat me to it :-).

/be




More information about the Es4-discuss mailing list