Re: Aren’t membranes incompatible with private data via WeakMaps?

2015-11-21 Thread Mark S. Miller
Answering the question in the subject line, no. The key is the difference
between a standalone proxy and a membrane. With a membrane, the key is that
the:

* Countdown class
* Countdown.prototype
* Countdown.prototype.dec
* instances of the Countdown class
* the WeakMaps used by the Countdown class to store it private state
(_counter, _action)

are all on one side of the membrane. As is conventional, let's call that
the wet side, and the other side the dry side. Say both a Countdown
instance c and the WeakMap _action get passed through the membrane. Let's
name the corresponding dry proxies dry_c and dry_action. If, on the dry
side, someone does

dry_action.get(dry_c)

then this would trap on dry_action, passing dry_c back through the
membrane, resulting in the dry_action handler performing, on the wet side

const r = _action.get(c)

The wet result, r, of this invocation would get passed back through the
membrane, leading to the original expression returning dry_r.

Alternatively, let's say that someone on the dry side does

dry_c.dec()

This traps on dry_c, which looks up c's inherited "dec" method, passes that
back through the membrane, resulting in a dry_dec proxy for that method.
When that is invoked with dry_c as its this, it traps, invoking the wet dec
method with c as its this.

Conclusion: it all works fine.







On Sat, Nov 21, 2015 at 3:02 PM, Axel Rauschmayer 
wrote:

> Take, for example, the following class, which uses WeakMaps for its
> private data:
>
> ```js
> let _counter = new WeakMap();
> let _action = new WeakMap();
> class Countdown {
> constructor(counter, action) {
> _counter.set(this, counter);
> _action.set(this, action);
> }
> dec() {
> let counter = _counter.get(this);
> if (counter < 1) return;
> counter--;
> _counter.set(this, counter);
> if (counter === 0) {
> _action.get(this)();
> }
> }
> }
> ```
>
> If you wrap an instance of `Countdown` with a revocable Proxy (e.g. when
> it is returned by a method inside a membrane) that resets its private
> state, because its `this` changes.
>
> Right? If yes then I’d expect that to cause problems for code that uses
> WeakMaps for private data.
>
> --
> Dr. Axel Rauschmayer
> a...@rauschma.de
> rauschma.de
>
>
>
> ___
> es-discuss mailing list
> es-discuss@mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>



-- 
Cheers,
--MarkM
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Aren’t membranes incompatible with private data via WeakMaps?

2015-11-21 Thread Axel Rauschmayer
Take, for example, the following class, which uses WeakMaps for its private 
data:

```js
let _counter = new WeakMap();
let _action = new WeakMap();
class Countdown {
constructor(counter, action) {
_counter.set(this, counter);
_action.set(this, action);
}
dec() {
let counter = _counter.get(this);
if (counter < 1) return;
counter--;
_counter.set(this, counter);
if (counter === 0) {
_action.get(this)();
}
}
}
```

If you wrap an instance of `Countdown` with a revocable Proxy (e.g. when it is 
returned by a method inside a membrane) that resets its private state, because 
its `this` changes.

Right? If yes then I’d expect that to cause problems for code that uses 
WeakMaps for private data.

-- 
Dr. Axel Rauschmayer
a...@rauschma.de
rauschma.de



___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Is wiki.ecmascript.org down?

2015-11-21 Thread Claude Pache

> Le 21 nov. 2015 à 18:42, Axel Rauschmayer  a écrit :
> 
> is the document available somewhere else?

Yes, thanks to the Wayback machine: https://archive.org/web/
Direct link: 
https://web.archive.org/web/20150908004703/http://wiki.ecmascript.org/doku.php?id=strawman:proxy_symbol_decoupled

—Claude

___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Is wiki.ecmascript.org down?

2015-11-21 Thread Axel Rauschmayer
I wanted to read the following document, but couldn’t access the server: 
http://wiki.ecmascript.org/doku.php?id=strawman:proxy_symbol_decoupled 


Does the server still exist? If not, is the document available somewhere else?

Thanks!

Axel

-- 
Dr. Axel Rauschmayer
a...@rauschma.de
rauschma.de



___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss