-
Notifications
You must be signed in to change notification settings - Fork 22.6k
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
Reference for stage 3 resizablearraybuffer #24407
Reference for stage 3 resizablearraybuffer #24407
Conversation
Lmk when it's ready for review. Content LGTM but I have a lot of editorial suggestions, which I'll probably just commit directly to this branch. |
You can go ahead with the editorial suggestions; I'm mainly setting it to draft so that it doesn't end up getting merged before the SMEs are able to give it a tech review. |
files/en-us/web/javascript/reference/global_objects/arraybuffer/index.md
Show resolved
Hide resolved
Several thoughts:
We should try to include all information from the proposal that doesn't seem exclusively useful for implementers! |
files/en-us/web/javascript/reference/global_objects/arraybuffer/resize/index.md
Outdated
Show resolved
Hide resolved
files/en-us/web/javascript/reference/global_objects/arraybuffer/index.md
Outdated
Show resolved
Hide resolved
files/en-us/web/javascript/reference/global_objects/sharedarraybuffer/index.md
Outdated
Show resolved
Hide resolved
This pull request has merge conflicts that must be resolved before it can be merged. |
Let me preface this by saying that I am not as much of an expert with the core JS language as you or Mr @Elchi3 ... but I've got a few questions about your thoughts before I try to make any further changes.
There is no mention of
I didn't think the typed array view could affect the underlying array buffer. Something like If you create a resizable
What landing page? The main
In my experience, it is not common practice to document the behavior of internal slots on MDN. Is this useful to web developers?
What security concerns were you thinking of specifically, and where would you mention them? |
There's indeed no direct exposition of how it works, just feel like you may want to explore it, because the proposal quotes WASM as a motivation. See the "Sync up capability with WebAssembly memory.grow" and "WebGPU buffers" sections.
Yes, that's what I'm thinking of. Only array buffer resizing can affect typed arrays, but not the other way. The important thing to note is that this only happens when the typed array was created with
I'm talking about what APIs you may use to help with buffer resizing (
Sorry, when I say "slots", I mean "array buffer indices". For example: const rab = new ArrayBuffer(0, { maxByteLength: 1024 ** 2 });
const u32a = new Uint32Array(rab);
rab.resize(1000);
console.log(u32a[50]); // 0, not some junk value, as you may expect if the memory is not initialized
Out-of-bounds memory access, etc. Frankly I'm not expert on security either, but you may want to research based on the "Security" section of the proposal. This doesn't have to be in this initial PR. |
I don't think that's true (the sentence starting with "this only happens"). E.g.,
-> I'd say here "the typed array is affected", too.
undefined, not 0, no? See https://tc39.es/ecma262/#sec-integerindexedelementget . Re: security: I don't think there's anything actionable for JavaScript programmers there. The browsers will make sure the proposal is implemented in a sound way, so that no rogue memory access can occur. |
RE: only happens when the typed array was created with RE: accessing out-of-bounds memory. Because resizeable buffers are not merged yet, the main spec is not updated. You need to look at the revised AO in the proposal spec. But you are right, out-of-bounds typed arrays act as if they are detached, which means they have RE: security, it's okay to just note that "the way the API is designed have got you covered". For example, you are not allowed to shrink shared memory; you are never allowed to access memory not allocated to you; etc. These are the things developers may care about that should be explicitly spelled out. |
@marjakh @Josh-Cena OK, I've had another go, taking on board your new comments. What do you think? |
files/en-us/web/javascript/reference/global_objects/typedarray/index.md
Outdated
Show resolved
Hide resolved
files/en-us/web/javascript/reference/global_objects/typedarray/index.md
Outdated
Show resolved
Hide resolved
files/en-us/web/javascript/reference/global_objects/typedarray/index.md
Outdated
Show resolved
Hide resolved
@marjakh thanks for the further comments. I've made some more changes - let me know what you think. |
@@ -78,6 +78,14 @@ Depending on whether the above security measures are taken, the various memory-s | |||
|
|||
The WebAssembly Threads proposal also defines a new set of [atomic](https://github.com/WebAssembly/threads/blob/master/proposals/threads/Overview.md#atomic-memory-accesses) instructions. Just as `SharedArrayBuffer` and its methods are unconditionally enabled (and only sharing between threads is gated on the new headers), the WebAssembly atomic instructions are also unconditionally allowed. | |||
|
|||
### Growing SharedArrayBuffers | |||
|
|||
`SharedArrayBuffer`s can be made growable by including the `maxByteLength` option when calling the {{jsxref("SharedArrayBuffer.SharedArrayBuffer", "constructor", "", "nocode")}}. You can query whether an `ArrayBuffer` is growable and what its maximum size is by accessing its {{jsxref("SharedArrayBuffer.prototype.growable", "growable")}} and {{jsxref("SharedArrayBuffer.prototype.maxByteLength", "maxByteLength")}} properties, respectively. You can assign a new size to a growable `SharedArrayBuffer` with a {{jsxref("SharedArrayBuffer.prototype.grow()", "grow()")}} call. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"You can query whether an
ArrayBuffer
is growable"
Should this be SharedArrayBuffer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch — updated in next commit
console.log(float32[0]) // Returns undefined | ||
``` | ||
|
||
If you then grow `buffer` again, `float32`'s size will increase again. This can potentially bring a typed array that previously became out-of-bounds, back in bounds: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you then grow
buffer
again,float32
's size will increase again. This can potentially bring [...]
This is also slightly untrue / expressed in an unspecific way: The size will increase only in the case where the growing brings it back in bounds. Now it sounds like the size will always increase if you grow the buffer, and that in addition it might become in-bounds.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see what you are getting at. Text updated again.
|
||
#### Behavior of length-tracking TypedArrays | ||
|
||
In this case, `float32` is created without a specific size so it is non-length-tracking, and will grow to contain `array` as it is grown: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
non-length-tracking
Should be: length-tracking
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops, yup! Updated.
Thanks for working on this so relentlessly through the iterations! This feature has many subtleties and it's tricky to get all the details right. I left a couple of small comments, the rest looks good! Thanks! |
@marjakh no problem! It's really important to have these discussions to make sure we explain things precisely. Can you have one more quick look, just to make sure things are all OK now? |
Everything looks good now, thanks! |
@marjakh Super, thanks! |
@Josh-Cena, @marjakh has now given this the thumbs-up from the SME tech review standpoint. Do you have the privs to merge it? If not, maybe @Elchi3 could have a quick look and give it his stamp? There is also a set of related interactive examples at mdn/interactive-examples#2434. Can you help me to get these reviewed and approved? Thanks in advance. |
I will do a last round of review this week and get it merged. Thank you for the work! |
Super, cheers! |
7fbdc24
to
bcbbc3c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This LGTM. I've pushed one little change in bcbbc3c and I'd like to get a thumbs-up from both @chrisdavidmills and @marjakh before I merge this.
@Josh-Cena LGTM! |
The latest edits look good, thanks! |
Thank you both! |
W00t! Thanks for all your hard work on this @Josh-Cena ! |
Description
This PR adds content for the new features related to the Resizable ArrayBuffer and growable SharedArrayBuffer Stage 3 draft, which was implemented in Chrome 111+.
See my research document for exact details of what has been added, and other required work.
Motivation
Additional details
Related issues and pull requests
Fixes #24369