C. Scott Ananian
ecmascript at cscott.net
Thu Apr 30 18:56:29 UTC 2015
Can you make an alternative proposal that still preserves the essential
property of Object.freeze on collections -- that is to say, preserves
object identity while preventing future writes?
Here's another strawman:
> Add "[[Immutable]]" to the arguments of OrdinaryCreateFromConstructor in
step 2 of 184.108.40.206 (Map) and 220.127.116.11 (Set)
> Add "If the [[Immutable]] internal slot of M is true, throw a TypeError
exception" between steps 3 and 4 of 18.104.22.168 (Map.prototype.clear),
22.214.171.124 (Map.prototype.delete), 126.96.36.199 (Map.prototype.set), 188.8.131.52
(Set.prototype.add), 184.108.40.206 (Set.prototype.clear), and 220.127.116.11
> Add `Map.prototype.makeReadOnly()` and `Set.prototype.makeReadOnly()`
methods with the definition:
> 1. Let M be the this value.
> 2. If Type(M) is not Object, throw a TypeError exception
> 3. If M does not have a [[Immutable]] internal slot, throw a TypeError
> 4. Set the [[Immutable]] internal slot of M to true.
This is somewhat awkward and ad-hoc, but it won't break ES6 code.
I am concerned about this issue in part because as written is seems to be
impossible to prevent writes to Map. If you subclass it, freeze it,
override set/delete/etc it is still possible to mutate the map using
`Map.set.call(m, 'a', 'b');`. And there is no way for use code to get at
the [[MapData]] slot to protect it.
On Thu, Apr 30, 2015 at 2:42 PM, C. Scott Ananian <ecmascript at cscott.net>
> On Thu, Apr 30, 2015 at 2:22 PM, Mark S. Miller <erights at google.com>
>> It would also not be compatible with ES6 code. SES will be freezing Map,
>> Set, WeakMap, and WeakSet instances in order to tamper proof their API. I
>> expect many others will as well. Having this freeze then cause a
>> non-mutability in ES7 will break all such ES6 code. This is a non-starter
>> all around.
> Couldn't SES use
> Object.seal/Object.preventExtensions/Object.defineProperty to perform
> tamper-proofing without flipping the "frozen" bit?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the es-discuss