Le 07/12/2011 19:23, Xavier MONTILLET a écrit :
> Imagine you have a proxy set dynamically, meaning that you don't have
> the traps written in the code, you just pass variables. Then you need
> the undefined value to behave the way it does
You don't need undefined, you can delete the property.

> or you can't default to forwarding.
Even if you couldn't delete the property, you can implement the default
behavior in JavaScript. Something along the lines of:
function trap(...args){
    return Reflect.trap(...args);
}
The default handlers will be also provided in a module if I recall
correctly.

> But I think there is a need to "disable" a trap. Meaning that instead
> of forwarding, it would throw an error. So I'd say:
>
> var p =Proxy({prop:1}, {get:undefined,set:null});
> p.prop;// 1
> p.prop = 2;// error: no set trap
I've proposed once that in some API, null and undefined had different
semantics and someone (Brendan, maybe?) said that there is no precedent
of this. I would assume the same stands here (and is another argument to
trigger default trap on property non-existence rather than undefined)

If someone ever considers changing traps dynamically, the trouble will
be hard enough by itself and I think the language should do as much as
possible to help catching errors early.
-----
function h(g, s){
    return {get: g, set:s};
}

var p = Proxy({}, h(function(...args){console.log(args);}));
p.a = 1;
-----
I would claim that in this (simplified-maybe-not-fully-realistic) case
the missing second argument in the h function is very likely to be a bug
and I would be thankful to the language to warn me about it.

David

> On Tue, Dec 6, 2011 at 11:13 PM, David Bruant <[email protected]> wrote:
>> Hi,
>>
>> "All traps are optional. If missing (more precisely, if
>> handler[trapName] returns undefined), the proxy defaults to forwarding
>> the intercepted operation to its target object." [1]
>>
>> Proxy({}, {get:undefined}).someProperty;
>>
>> In this case, the description says that the operation is forwarded. I
>> would prefer a TypeError to be thrown in this case.
>>
>> Opinions?
>>
>> David
>>
>> [1] http://wiki.ecmascript.org/doku.php?id=harmony:direct_proxies
>> _______________________________________________
>> es-discuss mailing list
>> [email protected]
>> https://mail.mozilla.org/listinfo/es-discuss

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

Reply via email to