RE: JSIDL ideas for read only (Was: RE: Figuring out easier readonly interfaces)

From: Boris Zbarsky [mailto:bzbarsky@MIT.EDU] 

> This is the general goal, yes.  But what actually happens here?  What actual prototype chain does that produce?  For example, what is the getter for the "x" own property of MutablePoint.prototype, if any?

Sure. The complete desugaring is similar to [1]. That is, the prototype chain is the same as produced by the corresponding JS class declarations, namely null -> Object.prototype -> Point.prototype -> MutablePoint.prototype. And the getter goes and gets the corresponding `x` out of a weak map (i.e. `return privates.get(this).x` using the desugaring of [1]).

A brand check might be necessary for the getters too to make this sound; I'd prefer to avoid that, as it seems unlike what you would write normally, but I can easily imagine that when I think about this harder, it'll be necessary for the general case. And now that I think about it, a brand check would produce a more informative error than trying to get property `x` of `undefined` if `privates.get(this)` did not exist.

Just to be more helpful, I've done the complete desugaring, with branding for both sides, in [2].

>> [1]: https://gist.github.com/domenic/6736258


[2]: https://gist.github.com/domenic/6808845

Received on Thursday, 3 October 2013 12:17:59 UTC