Aren’t membranes incompatible with private data via WeakMaps?
Axel Rauschmayer
rauschma at icloud.com
Sat Nov 21 23:02:52 UTC 2015
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
axel at rauschma.de
rauschma.de
More information about the es-discuss
mailing list