Converting an existing object to a proxy

Cormac Flanagan cormac at
Thu May 26 17:04:18 PDT 2011

[documenting/expanding some ideas briefly discussed at today's meeting]

The current proxy proposal has a method to create a new proxy:

var proxy = Proxy.create(handler, proto);

We could extend this proposal to allow an existing object to be
converted to a proxy, via:

var proxy = Proxy.createFrom(object, handler, proto);

Here, the return value 'proxy' is the same address as the argument 'object'.
The original object thus becomes a proxy. Any state of the original object
is discarded.

This extension appears to support additional applications, such as
registering an observer on an existing object. The target object would
first be cloned, then the target object would be converted into a proxy that
dispatches to the cloned object, but which also notifies observers about
accesses/updates to the (now proxified) object.

There are a number of open issues relating to security etc:
In particular, what objects can be proxified in this way - perhaps not
frozen object,
or objects with non-configurable properties or with unique names.

A design goal is that for any object that could be proxified,
we can replace it with a proxy in a way that is semantically transparent.

      - Cormac

More information about the es-discuss mailing list