javascript-private-state icon indicating copy to clipboard operation
javascript-private-state copied to clipboard

How does this interact with Proxies?

Open ljharb opened this issue 10 years ago • 3 comments

Per your example in https://github.com/wycats/javascript-private-state#private-slots-are-lexical-and-class-private - what if another is a Proxy for DataObj?

What would the proxy traps look like if the proxy is able to intercept data slot getting/setting? If it's not able to, would data slot access simply pass through any proxy?

ljharb avatar Nov 12 '15 01:11 ljharb

There is intentionally no MOP operations (proxy traps) for accessing private slots. This was a security requirement.

From a proxy perspective private slots work exactly like internal data slots. The default trap handlers do not transparently allow access to either internal data slots or private slots. But a membrane style proxy can be written whose handler will transparently all such accesses..

allenwb avatar Nov 12 '15 04:11 allenwb

Makes sense - how would I write a proxy such that another.#data would work the same as if it wasn't a proxy?

ljharb avatar Nov 12 '15 04:11 ljharb

A fully transparent membrane proxy is too complicated for me to try to do off the cuff. I'm sure that Mark Miller to Tom Van Custem could point you at a complete example.

The problem is the same as for built-ins. The default method invocation passes the Proxy rather than the target as the this value to the method. But, the Proxy object fails any internal/private slots accesses that the method might perform.

allenwb avatar Nov 12 '15 05:11 allenwb