webidl icon indicating copy to clipboard operation
webidl copied to clipboard

It is unclear if [AllowShared] BufferSource is valid

Open smaug---- opened this issue 4 years ago • 3 comments

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.

smaug---- avatar Mar 03 '21 17:03 smaug----

There is some discussion in #827.

EdgarChen avatar Mar 03 '21 22:03 EdgarChen

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.

annevk avatar Mar 04 '21 07:03 annevk

+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.

yuki3 avatar Aug 04 '21 12:08 yuki3

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

annevk avatar May 07 '23 10:05 annevk

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.

bathos avatar May 07 '23 18:05 bathos

You're right, #827 still exists.

annevk avatar May 08 '23 08:05 annevk