-
Notifications
You must be signed in to change notification settings - Fork 195
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
read-only ArrayBuffer is strange #300
Comments
Thanks. I'm not modifying the values from the spec once it's created, and I'd like to get back to actual ES types. However, I tried |
Oh, you're right of course; that doesn't freeze the underlying data. Dang. Blocking specs on TC39 is never a path to success :-/. Maybe the read-only ArrayBuffer cases could be changed to functions that return normal ArrayBuffers? |
For the uses in the main spec, writable ArrayBuffers aren't terrible. They're fields reporting data to the website, and the UA would never read any mutations the website makes. I'd rather have them writable than make them functions, although that's a matter of taste. The scanning spec does use some ArrayBuffer fields after they're exposed to websites. I'm inclined to leave the read-only ArrayBuffers in the spec until someone starts implementing Scanning, just in case TC39 comes through quickly, but there are also several alternatives we can fall back to at that point. |
I really doubt TC39 will come through on this; it's been discussed before and rejected because of fairly nasty performance implications for code that manipulates typed arrays. I strongly suggest not specifying something that is not actually implementable. |
https://github.com/tc39/proposal-immutable-arraybuffer is now at Stage 2, has enthusiastic support from some implementations, and has not (yet?) had any serious objections. It does not make the ArrayBuffer immutable in place, but rather makes a new Immutable ArrayBuffer while detaching the original, so that the operation is zero-copy for the data itself. |
Would proposed JavaScript Immutable ArrayBuffers help? Would they conflict?
Ping. I am about to ask for advancement to stage 2.7 at tc39, so any timely answer or opinions would be most useful. Thanks! |
Overall I'm supportive of this however given that Web Bluetooth has been deployed for many years it would take some investigation to determine whether the ArrayBuffers it exposes ( It think this matters more to specs like WebGPU and WebNN where it is useful to model an immutable memory region because the underlying platform requires it (e.g. a device buffer which is mapped read-only). |
I think you want to create a normal ArrayBuffer, then freeze it (by applying SetIntegrityLevel(O, "frozen")). Note that this makes it immutable, not just read-only; I couldn't tell whether you were modifying the values from the spec or not.
The text was updated successfully, but these errors were encountered: