Hi David,

As I understand it, the difference between the two patterns you presented is
not so much in using a "full" forwarding handler versus an "own" forwarding
handler, but in the fact that you pass different initial prototypes.

Consider:
var p = Proxy.create(fullForwardingHandler(target),
Object.getPrototypeOf(target));

Here, p and target also refer to the same prototype, it's orthogonal to
specifying a "full" or "own" handler. Regardless of the kind of forwarding
handler, inheritance will work just fine. I understand they work fine for
different reasons, but is the difference really worth complicating the API
by introducing two kinds of forwarding handlers?

To be clear: I'm not opposed to your idea of distinguishing "own" from
"full" forwarding handlers, but since the former can easily be defined in
terms of the latter (delete all derived traps), the question becomes: should
we standardize both or should we standardize just the minimum features, and
allow developers to build other useful abstractions on top?

Cheers,
Tom

2011/3/22 David Bruant <david.bru...@labri.fr>

> Hi,
>
> I'd like to discuss forwarding proxy patterns. I'll call "full handler"
> a handler with all current traps and "own handler" a handler with just
> the own properties layer traps.
> The current forwarding proxy pattern is:
> ---
> var p = Proxy.create(fullForwardingHandler(target));
> ---
> Any interaction with p is delegated to target.
> To visualize the prototype chain, we have:
> -------
> p --> null
> target --> Object.getPrototypeOf(target) --> ... --> null
> -------
> Notably, all prototype-climbing calls are delegated to the target
> prototype chain regardless of what p prototype is (I'll get back to that
> later)
>
> We have seen a limitation of providing a full forwarding handler
> systematically
> (
> http://wiki.ecmascript.org/doku.php?id=strawman:derived_traps_forwarding_handler
> ).
> Regardless of what is decided on the strawman, some people may want to
> only provide own traps. One "lighter" way to provide the same forwarding
> handler would be to do:
> var p = Proxy.create(ownForwardingHandler(target),
> Object.getPrototypeOf(target));
> Which would visualize as:
> ---
> p -----------
>             \
> target --> Object.getPrototypeOf(target) --> ... --> null
> ---
> So at the own layer, p and target act exactly the same. They also act
> the same when it comes to inheritance but not thanks to prototype
> climbing traps. They do so because they natively delegate to the same
> prototype object and use the default trap behavior. So, they are also
> consistent with instanceof and Object.getPrototypeOf (and the prototype
> is correct when the proxy is fixed which is a consistent side-effect.
> This doesn't happen with current full forwarding and null prototype).
>
> Ok, now that we are able to be in sync only at the own layer, one
> interesting pattern is the following
> ---
> p --> Object.getPrototypeOf(p) --> ... --> null
> target --> Object.getPrototypeOf(target) --> ... --> null
> ---
> with p and target in sync at the own layer. For all own operations, p
> would forward to target, however, for all proto-climbing operations p
> would use its own properties. Actually, this works without any effort
> with the OwnForwardingHandler since its default derived traps delegate
> to the correct prototype by default.
> This pattern could be used for a new prototype inheritance pattern where
> o1 could inherit from p, o2 from target. They would both feel they
> inherit from the same object (since p and target are in sync) while, one
> step further inheriting from completely different objects.
>
> All of this is just a discussion on the forwarding proxy pattern. But I
> think it was worth pointing the potential limitations of how this
> pattern is currently presented (limitations which are different from the
> one previously noticed which led to
> strawman:derived_traps_forwarding_handler).
>
> David
> _______________________________________________
> es-discuss mailing list
> es-discuss@mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to