Proxy.isProxy (Was: using Private name objects for declarative property definition.)

Allen Wirfs-Brock allen at
Wed Jul 13 12:18:18 PDT 2011

On Jul 13, 2011, at 8:44 AM, David Herman wrote:

> Putting private properties on a proxy or storing it in a weak map are simple protocols you can use to keep track of proxies that you know about. You can hide or expose this information then without however many or few clients you like. If you want to give people access to knowledge about your proxy, you can share the private name object or weak map so that they can look it up, or even provide a similar predicate to isProxy.

I buy that a non-reflectable private name can be used to brand proxies.  Coming from the perspective of a GC implementer, I'm suspicious of all arguments that are backstopped by requiring the use of weak maps, as their existence and size impose GC overhead.  Yes, there are some things that really require them, but without knowing the volume and volatility of the objects involved it is hard to say whether or not weak maps is going to be an acceptable solution for any particular problem. 

> By contrast, if you want to virtualize an object with a proxy and we provide isProxy, we've made it almost impossible to protect the abstraction. It becomes a universal on-off switch that you can turn off by hiding the isProxy predicate (via module loaders or deleting/mutating the function).

We want to stratify reflective meta-programming.  Violating the abstraction barrier of a proxy based abstraction is fine (and necessary), as long as you are operating in the meta strata. isProxy would clearly be a virtualization hazard if it existed on Proxy instances.  But as one of the stratified proxy-related reflective operations it isn't.  

> And to be even more concrete, if we want to use proxies for platform-level features, e.g. the DOM, then isProxy is something we *can't* turn off without violating the ECMAScript spec, so we're then *forced* to expose the implementation detail to anyone on the web who wants to look at it.

So far, there is nothing in the ECMAScript spec. that says anything about whether or not Proxy's may be used to implement built-ins, host objects, or anything else and by implication what isProxy (if it exists) might report for such objects.  I'd just as soon leave it that way. There are various ways that implementation details can get exposed.  For example, by toString'ing a method property.  I don't see why isProxy is any more of an abstraction leak than toString.  It is actually less, if we clearly position it as one of the meta-programming functions that are available via the Proxy module.  


More information about the es-discuss mailing list