webidl
webidl copied to clipboard
It is unclear if [AllowShared] BufferSource is valid
The spec says "A type that is not a buffer source type must not be associated with the [AllowShared] extended attribute." and "The buffer source types are ArrayBuffer, DataView, and the typed array types."
BufferSource is a union type typedef (ArrayBufferView or ArrayBuffer) BufferSource;
Yet https://heycam.github.io/webidl/#AllowShared has an example using [AllowShared] BufferSource.
There is some discussion in #827.
See also #342 and #865.
My current thinking on this:
- SharedArrayBuffer should be its own IDL type. We should not overload the ArrayBuffer IDL type to being able to represent ArrayBuffer and SharedArrayBuffer JS types.
- [AllowShared] only applies to ArrayBufferView types.
- We should leave BufferSource as-is.
- We should add SharedBufferSource that also accepts SharedArrayBuffer and that uses [AllowShared] in front of ArrayBufferView.
The outcome of that might well be that [AllowShared] BufferSource is valid as [AllowShared] would end up ignored for ArrayBuffer. I don't have strong feelings about that.
+1 for Anne's proposal.
Only a nitpick I see is that, considering ArrayBuffer vs SharedArrayBuffer, BufferSource vs SharedBufferSource could be a little confusing. IIUC, the proposal is:
typedef (ArrayBuffer or SharedArrayBuffer or [AllowShared] Int8Array or ...) SharedBufferSource;
Considering ArrayBuffer vs SharedArrayBuffer, the proposed SharedBufferSource does not correspond to SharedArrayBuffer. It corresponds to (ArrayBuffer or SharedArrayBuffer). "Shared" prefix looks confusing to me.
That makes sense, I guess for clarity AllowSharedBufferSource
would be better, to indicate it's allowed, but not enforced.
Defined as:
typedef (SharedArrayBuffer or [AllowShared] BufferSource) AllowSharedBufferSource;
I think that works because [AllowShared] ArrayBuffer
would end up ignored. Though we could flatten it a bit more if that would be preferred:
typedef (ArrayBuffer or SharedArrayBuffer or [AllowShared] ArrayBufferView) AllowSharedBufferSource;
cc @Constellation
I think that works because [AllowShared] ArrayBuffer would end up ignored.
What makes that ignored? That behavior does make sense to me, but I don’t think it’s what’s currently specified. Type-applicable EAs get distributed to union members unilaterally right now, they aren’t filtered by whether a member does or doesn’t permit that annotation, so I think it would presently imply an error.
You're right, #827 still exists.