Skip to content

How to return a SharedArrayBuffer object #865

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
annevk opened this issue Mar 27, 2020 · 2 comments · Fixed by #1311
Closed

How to return a SharedArrayBuffer object #865

annevk opened this issue Mar 27, 2020 · 2 comments · Fixed by #1311

Comments

@annevk
Copy link
Member

annevk commented Mar 27, 2020

As far as I can tell a JS SharedArrayBuffer can enter IDL through an IDL ArrayBuffer that's effectively a pointer to the JS object.

Now assuming #342 is fixed and you can use [AllowShared] ArrayBuffer as return value, what language do you use to return a SharedArrayBuffer? Do you need to construct the JS object, then make an IDL ArrayBuffer object that points to it, and then return the IDL object?

@TimothyGu
Copy link
Member

Since Web IDL never seems to say an IDL ArrayBuffer has to be an actual JavaScript ArrayBuffer, couldn't you just use ArrayBuffer as the return type in IDL? I.e., the [AllowShared] part in the return type isn't actually strictly necessary.

@domenic
Copy link
Member

domenic commented Mar 27, 2020

Sure, but how do you write spec prose saying that the IDL ArrayBuffer is actually a JavaScript SharedArrayBuffer? @annevk's last sentence points to one route, but it's kind of icky, as we'd like IDL to be an intermediary layer so that specs don't have to touch JS objects so directly.

annevk added a commit that referenced this issue May 30, 2023
Generally IDL objects have been 1:1 with ECMAScript objects, except for
SharedArrayBuffer. That was instead represented as
[AllowShared] ArrayBuffer, although that includes ArrayBuffer as well.
This created a number of challenges, e.g., how to return a
SharedArrayBuffer object.

So we make these changes here that will also require corresponding
downstream fixes:

* SharedArrayBuffer is now its own type.
* [AllowShared] only applies to buffer view types.
* AllowSharedBufferSource takes over from [AllowShared] BufferSource.

Fixes #865 and fixes #961.
annevk added a commit that referenced this issue Jun 15, 2023
Generally IDL objects have been 1:1 with ECMAScript objects, except for
SharedArrayBuffer. That was instead represented as
[AllowShared] ArrayBuffer, although that includes ArrayBuffer as well.
This created a number of challenges, e.g., how to return a
SharedArrayBuffer object.

So we make these changes here that will also require corresponding
downstream fixes:

* SharedArrayBuffer is now its own type.
* [AllowShared] only applies to buffer view types.
* AllowSharedBufferSource takes over from [AllowShared] BufferSource.

Downstream is tracked by #1320.

Fixes #865 and fixes #961.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

3 participants