Sorry, I didn’t read the thread thoroughly (so maybe I’ll repeat someone). But
here are some serious issues with your proposal:
------
1. Assignment of properties deep in the object hierarchy split in two
instructions:
```js
var a = { __proto__: { foo: { bar: 2 } } } with safe-prototype;
var b = a.foo;
b.bar = 3;
```
Should the last line trigger copy-on-write around `a.__proto__`?
If you say ”no”, it means that the meaning of the code is changed unexpectedly
with an apparent innocuous code refactoring.
If you say ”yes”, it is dreadful action-at-distance, because the two last lines
of code may be very distant, indeed even in two distinct files. — It would be
less an issue if prototypes were, say, just abstract templates. But they are
not, they are concrete objects, so:
```js
var proto = { foo: { bar: 2 } };
var a1 = { __proto__: proto } with safe-prototype;
var a2 = { __proto__: proto } with safe-prototype;
var b1 = a1.foo;
var b2 = a2.foo
b1 === b2; // true
b1.bar = 3;
b1 === b2; // ???
```
------
2. Object mutations unrelated to the value of its properties:
```js
var a = { __proto__: { foo: new Map([ [ 'bar', 2 ] ]) } } with safe-prototype;
a.foo.set('bar', 3);
```
Unless you have deep knowledge of the internal state and/or the implementation
of the modified object (which you don’t have in case of a user-implementated
one), you cannot reliably detect when an object is mutated.
Note the subtle difference between:
* `[].push(1)` — You will detect object mutation, because it will add a
concrete property on the Array object.
* `(new Set).add(1)` — You won’t detect mutation, because only internal state
of the Set object is modified.
* `(new RandomUserDefinedCollection).put(1)` — That depends on the
implementation of the `RandomUserDefinedCollection` class.
—Claude
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss