Re: [whatwg/webidl] provide clearer advice about USVString vs. DOMString (#84)

jan-ivar left a comment (whatwg/webidl#84)

I'd like clearer advice on whether to use USVString for read-only attributes like [url](https://w3c.github.io/webrtc-pc/#dom-rtcicecandidate-url) in https://github.com/w3c/webrtc-pc/issues/3029.

Personally, I find such WebIDL annotations on output helpful (as a shortcut to reading algorithms) even though I know they don't translate to processing steps the way they do on input. E.g. much like I'd expect a method to never return a dictionary without its `required` members filled in, I'd expect a read-only `USVString` attribute to be free of surrogates.

> Is https://w3ctag.github.io/design-principles/#idl-string-types a sufficient fix for this?

It seems preoccupied with input, except _"...strings whose most common algorithms operate on [scalar values](https://infra.spec.whatwg.org/#scalar-value)"_ which suggests yes (use USVString on the read-only [url](https://w3c.github.io/webrtc-pc/#dom-rtcicecandidate-url) attribute).

But https://webidl.spec.whatwg.org/#idl-USVString warns no: _"... only use [USVString](https://webidl.spec.whatwg.org/#idl-USVString) for APIs that perform text processing and need a string of [scalar values](https://infra.spec.whatwg.org/#scalar-value) to operate on. Most APIs that use strings should instead be using [DOMString](https://webidl.spec.whatwg.org/#idl-DOMString), which does not make any interpretations of the [code units](https://infra.spec.whatwg.org/#code-unit) in the string. When in doubt, use [DOMString](https://webidl.spec.whatwg.org/#idl-DOMString)."_ — this seems to match @domenic's https://github.com/w3ctag/design-principles/issues/93#issuecomment-379816152: _"Only use USVString when it saves you a step of standards text, by rolling that step into the Web IDL type conversion."_

Can we clarify the guideline and align the warning with it?

-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/webidl/issues/84#issuecomment-2738553014
You are receiving this because you are subscribed to this thread.

Message ID: <whatwg/webidl/issues/84/2738553014@github.com>

Received on Wednesday, 19 March 2025 23:52:17 UTC