webidl icon indicating copy to clipboard operation
webidl copied to clipboard

Add [AllowImmutable] extended attribute for immutable array buffers and views

Open anba opened this issue 7 months ago • 2 comments

What problem are you trying to solve?

https://github.com/tc39/proposal-immutable-arraybuffer will likely need a new [AllowImmutable] extended attribute, similar to #982 for resizable array buffers.

What solutions exist today?

No response

How would you solve it?

No response

Anything else?

See also https://github.com/tc39/proposal-immutable-arraybuffer/issues/43.

Proposed structured clone changes: https://github.com/whatwg/html/pull/11033.

anba avatar May 16 '25 12:05 anba

One thing that would be good to think about as I don't think we did this quite right with [AllowResizable] is where we would want to see this used. Because now we have resizable buffers in JavaScript, but nowhere to use them in the web platform. From a web developer perspective that is not exactly great.

For instance, we have a fair number of APIs that essentially copy the buffer input so ideally they should all adopt this out of the gate. No real reason for TextDecoder to still reject these the moment the JS engine supports them.

annevk avatar May 16 '25 14:05 annevk

I think the default should be to accept immutable buffers. Even for APIs which write to their argument (which are rare - TextEncoder encodeInto comes to mind, but little else) they'll just throw when they actually try to write. [Edit: actually no, since they manipulate things internally, some algorithms would need to be updated I'm sure.]

It would be nice for APIs which do a copy to be updated not to do that, but this is an unobservable optimization which engines could do anyway, so it's not strictly necessary.

Maybe instead there should be a [ForbidImmutable] attribute for the those rare cases?

bakkot avatar Jul 18 '25 18:07 bakkot