Re: [whatwg/webidl] ObservableArray without assignment (#1027)

> Is there any other Web IDL type where that's true?

`FrozenArray<>` is the biggest example, used (with such a setter) in the accessibility object model and in the media session API. We make a copy of the incoming iterable object into an array, freeze the resulting array, and then start returning that.

Arguably this is true for all "primitive" Web IDL types, e.g. if you do

```js
document.title = { toString() { return "foo"; } };
```

this will perform a "copy-on-assignment" of the right-hand side onto the internal title property, and `document.title`'s getter will return a serialization of the result. I appreciate it's a bit different since the "normal" use case for primitive setters is to assign a correctly-typed primitive to the right-hand side; in such a normal use case you could either make an argument that the behavior is copy-on-assign, or that it's storing a reference, since the `===` operator gives you no way to distinguish.

A variant is how numeric properties are treated, i.e.

```js
element.tabIndex = 1.1;
```

will perform a "normalizing copy" of `1.1` into `1`, so that `el.tabIndex` will return `1` and not the original `1.1`. Again, not quite the same, but IMO similar in spirit.

Of the remaining types that can be used as the type of a settable attribute in Web IDL, we have:

- `object`/`symbol`/interface types/callback interface types: usually treated as opaque references, with no copies involved. (Unless something special is going on with a particular `object` usage, like is done in HTML's `valueAsDate`.)
- `Promise<T>`: nominally has copy semantics, but in practice I don't believe anything on the platform uses settable promise attributes, and I feel like we might have some issue filed somewhere to disallow them being ever introduced?
- buffer source types: kind of unclear; the Web IDL spec does references for the basic conversion algorithm, but encourages specs to make a copy of their contained bytes when possible. This is also another case where settable attributes of this type are rare, although I do see one in Web RTC.

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

Received on Wednesday, 10 November 2021 16:37:28 UTC