[heycam/webidl] Introduce new string type for names/keys with length limit (#552)

Many places in the platform allow DOMStrings for map keys or resource names, e.g. localStorage keys, Indexed DB database/store/index names, Service Worker Cache names, and so on. Specs do not define length limits, making it up to the UA to impose a limit to prevent OOMs. Rather than forcing each spec to specify a limit and behavior, we could introduce a new string type in WebIDL so that specs just need to use the type and bindings code in each UA will do the work.

Context:
* https://github.com/w3c/ServiceWorker/issues/1310 (SW's Cache API)
* https://github.com/inexorabletash/web-locks/issues/36 (proposal for a Locks API)
* https://github.com/w3c/IndexedDB/issues/207 (IDB discussion about problems with arbitrary length strings; we didn't do anything specific there)

Plausible names include "KeyString" or "NameString", but I'm not a huge fan of either. "Key" only makes sense if the map is fairly explicit. "Name" could imply that these are human readable and thus should be normalized, have locale-aware collation, etc.

Since I'm a nerd I have a hard time not picking a power-of-two limit (e.g. 1024), or feeling like I'm intentionally avoiding picking such a number (e.g. 1000).

But as a straw man:

> **NameString**
> The NameString type corresponds to the set of all possible sequences of code units up to length 1000. Such sequences are commonly interpreted as UTF-16 encoded strings although this is not required. 
>
>> Specifications should use the NameString type to represent strings that are provided by script to serve as the programmatic names of resources, such as the names of database tables or keys in a configuration map. These strings are assumed to have a fixed length within a web application, and to not contain arbitrary user data.

And the ECMAScript binding steps would be something like:

> An ECMAScript value V is converted to an IDL NameString value by running the following algorithm:
> 1. Let x be ToString(V).
> 1. If the length of x is greater than 1000, then throw a TypeError.
> 1. Return the IDL NameString value that represents the same sequence of code units as the one the ECMAScript String value x represents.
> 
> The result of converting an IDL NameString value to an ECMAScript value is the String value that represents the same sequence of code units that the IDL NameString represents.

See also: 
* #335 - i.e. we'd probably want something over in [Infra](https://infra.spec.whatwg.org/) too


-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/heycam/webidl/issues/552

Received on Friday, 27 April 2018 18:52:34 UTC