Proxy questions

Allen Wirfs-Brock allen at
Sun Jan 20 09:31:16 PST 2013

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 caller.

>>    var target = {
>>      foo: function() {; console.log("after bar"); },
when called via this will be by proxy when foo is invoked.  So so does a Proxy get trap that throws.  If there was a try-catch around 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);

>> 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:
> David
> _______________________________________________
> es-discuss mailing list
> es-discuss at

More information about the es-discuss mailing list