Skip to content
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

Preparing for Immutable / Limited ArrayBuffer #3588

Open
jasnell opened this issue Feb 21, 2025 · 0 comments
Open

Preparing for Immutable / Limited ArrayBuffer #3588

jasnell opened this issue Feb 21, 2025 · 0 comments

Comments

@jasnell
Copy link
Member

jasnell commented Feb 21, 2025

The Immutable ArrayBuffer and Limited ArrayBuffer proposals are advancing in TC-39. We have some time before we need to worry about them but we do need to prepare.

An Immutable ArrayBuffer is exactly what it says on the tin. Once allocated and marked immutable, the memory is expected to remain stable and unmodified -- even at the host runtime level. This obviously means that our current ArrayBuffer <-> kj::Array<kj::byte> type mapping will need to be updated to account for the possible immutability of the underlying backing store.

To support this, I am proposing:

  • We update jsg::BufferSource to add a new "isImmutable()" property, and when the jsg::BufferSource is wrapping an immutable backing store, the kj::ArrayPtr<T> it produces to provide access to the underlying data would be a kj::ArrayPtr<const kj::byte>. Modifications to the underlying data would be blocked.
  • We add a new Immutable ArrayBuffer <-> const kj::Array<const kj::byte> type mapping and make it so that the current ArrayBuffer <-> kj::Array<kj::byte> type mapping receives an immutable ArrayBuffer an error is thrown.

The Limited ArrayBuffer proposal provides a way of generating a read-only View of an otherwise mutable ArrayBuffer. When given such a view, it MUST be treated equivalently as an Immutable ArrayBuffer even if the underlying backing store is mutable. We ought to be able to handle this transparently in the type mapping modifications mentioned above.

There is no rush on this, however, and the changes required are relatively straightforward so work on this should proceed only when v8 implements the feature and ships it unflagged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant