Actually, freezing would prevent the pattern: forwardingHandler+"delta
definition" (where you only override a few traps). So I'm just going to
defend seal.

For the no-op forwarding proxy example
(http://wiki.ecmascript.org/doku.php?id=harmony:proxies#examplea_no-op_forwarding_proxy),
if the handlerMaker function is only used once in the context of :
Proxy.create(handlerMaker(aProxy));
then no, not even the least reason to seal.

However, if you do:
var h = handlerMaker(aProxy);
then the risk is taken that a handler method gets deleted. Deleting a
property may trigger an error or perform an unexpected behavior
depending on if the trap is fundamental or derived. Sealing the object
avoids unexpected delete by throwing an error (at least in strict mode.
Not sure in non-strict) making a bug easier to find.
Finally, for this particular case there is no obvious reason to extend
the handler or to be allowed to reconfigure the properties.

I don't know if it is what you call a "strong reason".

My opinion on preventExtension, seal and freeze is to use them when they
don't prevent any usage of the object and when they could be helpful
with detecting stupid mistakes (who has never wasted at least a couple
of minutes after a myDiv.innerHtml = 'blabla'?). I obviously won't force
anyone to share my opinion.

David


Le 26/01/2011 23:59, Brendan Eich a écrit :
> We avoid freeze-didacticism in general ;-) -- is there a strong reason to 
> freeze in this example?
>
> /be
>
> On Jan 26, 2011, at 2:51 PM, David Bruant wrote:
>
>> Le 26/01/2011 22:31, Brendan Eich a écrit :
>>> On Jan 26, 2011, at 11:02 AM, David Bruant wrote:
>>>
>>>>> On the question of proxy parameters for all traps (well, receiver for get 
>>>>> and set): fewer args are better, and closure capture of proxy by handler 
>>>>> avoids leaking the proxy to handler friends, if that matters. Likewise 
>>>>> you can't get the handler from the proxy.
>>>> If you handlers are frozen, there should be no leaking, shouldn't there? 
>>>> (I actually think that freezing the handler should be done in the no-op 
>>>> forwarding proxy example or any handler factory, but that's another issue).
>>> No default freezing is going to be imposed. :-|
>> I didn't mean to impose freezing objects, sorry for the
>> misunderstanding. I was more going for highly encouraging people to do
>> so by showing it in the no-op forwarding proxy example.
>>
>> David
>

_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to