[Harmony Proxies] Proxy argument for all traps

David Bruant bruant.d at gmail.com
Mon Dec 12 05:11:03 PST 2011


I have recently been writing some code. I have not had the need for a
proxy argument, but found a very close pattern that I thought would
benefit from a "proxy" argument
Here is a gist ( https://gist.github.com/1466999 ) with an example of
the pattern.

The makeProxyWhichCallOnDelete constructor takes a function as argument
(farg). It will call farg when the delete trap is called.

In client code, I create a weak map. I create a function (f) which reads
the value of the weak map based on its first argument.
With this function as argument, I create some proxies with the
constructor, assign a value to these proxies in the weak map.

In the implementation in the gist, the delete trap calls farg with the
target, but it's a dummy choice. In my particular case, I would like to
have the identity of the proxy, not the target.

In the end, my f function is pointless since it can't retrieve the weak
map values since it does not play with the right objects.

The use case I derived this pattern from is not problematic because:
* I initialize the constructor with the target (so I have a reference to
it and can use this as weak map key)
* I create one proxy per target.
In cases where either one of these condition is not respected, having
access to the proxy identity is required to do something useful.

Of course, having the proxy as argument is not an obligation since we
there is the technique of creating the handler, creating the proxy and
assign "handler.proxy = proxy;", but it's awkward and does not work with
sharing handlers.


More information about the es-discuss mailing list