Catch-all proposal based on proxies

Tom Van Cutsem tomvc at google.com
Mon Dec 7 17:31:56 PST 2009


On Mon, Dec 7, 2009 at 4:44 PM, Mike Samuel <mikesamuel at gmail.com> wrote:

> Under "This avoids questions like:",
> does the proposal also avoid
>   5. Can property trapping be defined on host objects
>

Yes, it does avoid this issue. One cannot trap properties of host objects.
But one can define a proxy that redirects property access to a host object.

"The Type of a Proxy"
> Why does the type change upon fixing?
> Is it an error to pass a value v s.t. (typeof v !== 'function') to
> Proxy.createFunction?   Specifically RegExps?
>

The "applyTrap" and "constructTrap" arguments to Proxy.createFunction should
be callable, so anything with an internal [[Call]] method will do.


> "Equality:"
> Would defining a Proxy.proxies(proxy, obj) that returns true iff obj
> was the argument to Proxy.create{,Function} that created proxy allow a
> useful level of equality checking?  That would allow limited checking
> by code that already possesses a handle to the underlying object
> without potentially leaking an underlying object to a bad proxy.
>

For this proposal it does not make sense to ask whether a proxy proxies a
particular object 'obj'. However, it does make sense to ask something
similar like "Proxy.isHandledBy(proxy, handler)", which would return true
iff 'handler' equals the proxy's internal handler attribute. Such a method
cannot be defined by user code, since given a proxy it's impossible to get a
reference to its handler. If there's a good use case for providing such a
function, it could be added.


> "[[DefaultValue]] (hint)"
> "[[Class]]"
> The rule for "[[Class]]" means that it's possible to create proxy an
> array in every way but that the isArray test used by common libraries
> cannot be spoofed:
>     '[object Array]' !== Object.prototype.toString.call(myArrayProxy)
> What is the proper behavior here?
>

This is a good point. Our current proposal does not allow proxies to
influence the value of their [[Class]] attribute, so the above "isArray"
test would fail for a proxy trying to emulate an array.

Cheers,
Tom
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20091207/a9987d84/attachment.html>


More information about the es-discuss mailing list