W3C home > Mailing lists > Public > public-script-coord@w3.org > October to December 2013

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

From: Domenic Denicola <domenic@domenicdenicola.com>
Date: Thu, 3 Oct 2013 00:14:19 +0000
To: Tab Atkins Jr. <jackalmage@gmail.com>, "public-script-coord@w3.org" <public-script-coord@w3.org>
Message-ID: <B4AE8F4E86E26C47AC407D49872F6F9F9B264EC9@BY2PRD0510MB354.namprd05.prod.outlook.com>
Forking threads since I took this on a tangent...

My preferred solution to the readonly "problem," in the pie-in-the-sky JSIDL future, would look something like this:

```jsidl
class Point {
  get number x
  get number y

  get number length
}

class MutablePoint extends Point {
   set x(ToNumber)
   set y(ToNumber)
}
```

Here the setters in MutablePoint do a brand check (similar to that at [1]), preventing you from applying them to Point.

I realize this doesn't help you until JSIDL becomes more realistic, but I am curious what the thoughts of you or others are on this list toward such a solution, as part of my ongoing gathering-pre-feedback process for JSIDL in general. I think that it strikes the right balance of expressiveness and verbosity.

---

Another idea I had, actually inspired by something Anne said, would the following. It tends more on the verbose side, but perhaps would be useful in that it exposing more primitives that can be discussed in prose.

```js
class Point {
  private [[x]], [[y]]	

  constructor(ToNumber x: [[x]], ToNumber y: [[y]])

  get number x: [[x]]
  get number y: [[y]]

  get number length
}

class MutablePoint extends Point {
  set x(ToNumber): [[x]]
  set y(ToNumber): [[y]]
}
```

Here spec algorithms (e.g. that for `length`) could refer to and manipulate the internal data properties `[[x]]` and `[[y]]`. This would desugar to manipulating the appropriately-hidden elements in the WeakMap, e.g. `[[x]]` stands in for `privates.get(this).x` in [1]. The colon syntax is just a way to perform the most-common operations on those internal properties; it has a slightly different meaning in each context I use it.

The goal, as with all of JSIDL, is to provide extremely simple desugaring to idiomatic ES. That's why I like this solution over some kind of declarative proxy creation, as nobody would use a proxy to enforce readonly-ness for this kind of simple situation.

Feedback welcomed and desired!

[1]: https://gist.github.com/domenic/6736258
Received on Thursday, 3 October 2013 00:14:56 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 17:14:18 UTC