Re: [webidl] Add a [Maplike] tag?

I've gone ahead and started using some pretend syntax for this in
<http://dev.w3.org/csswg/css-variables/#the-CSSVariablesMap-interface>:

[MapClass(DOMString, DOMString)]
interface CSSVariablesMap {
  DOMString get(DOMString varName);
  boolean has(DOMString varName);
  void set(DOMString varName, DOMString varValue);
  DOMString delete(DOMString varName);
}

The [MapClass(keyType, valType, iteratorType?)] extended attribute
takes two or three arguments.  The first two specify the types
required of its keys and values.  The interface MUST define the "map
tuples" for the interface, which consist of a unique key paired with a
value.  Unless manually defined in the interface, the entries(),
keys(), and values() methods, and the .size attribute, are
automatically defined in terms of the "map tuples".  The third
argument to the extended attribute defines which of the three is used
for the @@iterator() method, and must be either "entries", "keys",
"values", or omitted (which is the same as "entries").

The interface MAY manually define the get() and has() methods;
otherwise, they're automatically defined in terms of the "map tuples".
 The interface MAY manually define set() and delete() methods;
otherwise, they automatically throw TypeErrors with a message
indicating that the interface is readonly.  (Can we make the methods
auto-throw if the interface is used on a readonly attribute?)

The remaining Map methods (currently just clear() and forEach()) MAY
be manually defined; otherwise, they're automatically defined as in
<https://gist.github.com/jorendorff/5662673>.

The [MapClass] object has Map.prototype on its prototype chain, just
like [ArrayClass] and Array.prototype.

The [SetClass(valType)] extended attribute is defined similarly.

~TJ

Received on Tuesday, 11 June 2013 01:37:13 UTC