Notification proxies (Was: possible excessive proxy invariants for Object.keys/etc??)

Mark S. Miller erights at google.com
Mon Dec 3 07:38:42 PST 2012


What eternal[1] invariant does this bypass?

[1] https://mail.mozilla.org/pipermail/es-discuss/2011-May/014150.html

On Mon, Dec 3, 2012 at 3:33 AM, David Bruant <bruant.d at gmail.com> wrote:
> Le 03/12/2012 00:06, David Bruant a écrit :
>
>>> The call to action performs
>>> the original operation on target and remembers the result. After the
>>> trap returns, the proxy returns the remembered result of action.
>>
>>     target = {a:1};
>>     var p = new Proxy(target, {
>>         get: function(target, name, action){
>>             var v = action();
>>             target[name] = 2;
>>         }
>>     })
>>
>>     p.a; // ?
>>
>> If p.a is 1 because the call to "action" remembered the "1", then the
>> target and the proxy look awkwardly desynchronized. To know what's being
>> returned from the trap, one needs to remember when the action is being
>> called which makes writing traps harder I feel. With the current design,
>> looking at the return statements is enough.
>> If p.a is 2, I don't understand the point of "action". Or at least, I
>> don't see how it's better than just calling Reflect[trap].
>
> I've found much MUCH worse:
>
>
>     target = {a:1};
>     var p = new Proxy(target, {
>         get: function(target, name, action){
>             var v = action();
>             Object.defineProperty(target, name, {value:2, configurable:
> false, writable:false})
>         }
>     })
>
>     p.a; // 1 ?
>
> In that case, the mechanism used to bypass invariant checking is a way to
> bypass invariants entirely.
>
>
> David
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss



-- 
    Cheers,
    --MarkM


More information about the es-discuss mailing list