On Jan 20, 2013, at 9:03 AM, David Bruant wrote:
> Le 20/01/2013 16:49, Kevin Smith a écrit :
>> Got it. And one more (thanks for bearing with me)
> I forked the thread. Go crazy if you have other questions :-)
>
>> what affect does throwing an error have within a trap?
> You can think of it as an internal error, very much like
> Object.defineProperty throws a TypeError when the first argument isn't an
> object.
It's just an exception and propagates up the stack until handled. Very few (if
any, I can't think of any without going and looking at the Proxy spec.) are
handled in the Proxy implementation so the exception will propagate to the
proxy.foo() caller.
>
>> var target = {
>> foo: function() { this.bar; console.log("after bar"); },
when called via proxy.foo() this will be by proxy when foo is invoked. So so
this.bar does a Proxy get trap that throws. If there was a try-catch around
this.bar it would catch the exception.
>> bar: 0
>> };
>>
>> var proxy = new Proxy(target, {
>> get: function(obj, name) {
>> if (name === "bar") throw new Error("boom");
>> return obj[name];
>> }
>> });
Note that the full signature of the get trap is: function(obj, name, receiver).
To work in all cases, the last line really needs to be:
return Reflect.get(obj,name,receiver);
>>
>> proxy.foo();
>>
>> Does the stack unwind as with normal error handling? Does "after bar" get
>> logged? (FF18 answers yes to the first and no to the second question.)
> I agree with FF18 here.
> This case is relatively easy and the get trap is supported by Firefox
> implementation, but always aware that for now, some traps aren't implemented,
> some invariant-related checks aren't performed, other are overly performed.
> You can see the known issues in the dependency tree of the direct proxy bug:
> https://bugzilla.mozilla.org/showdependencytree.cgi?id=703537&hide_resolved=1
>
> David
> _______________________________________________
> 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