Add immutable array buffer awareness to structuredClone#11033
Add immutable array buffer awareness to structuredClone#11033gibson042 wants to merge 6 commits into
Conversation
|
Can you work on getting the build passing? Also, it would be good to update the PR title and commit message to specify that this is about preventing transferring of such immutable array buffers; structured cloning them is still allowed. |
|
|
||
| <li><p>If <var>transferable</var> has an [[ArrayBufferData]] internal slot and | ||
| <span>IsSharedArrayBuffer</span>(<var>transferable</var>) is true, then throw a | ||
| <span>IsSharedArrayBuffer</span>(<var>transferable</var>) is true or |
There was a problem hiding this comment.
Nit:
| <span>IsSharedArrayBuffer</span>(<var>transferable</var>) is true or | |
| either <span>IsSharedArrayBuffer</span>(<var>transferable</var>) is true or |
since otherwise a valid reading at least at first glance is "(transferable has an [[ArrayBufferData]] internal slot and IsSharedArrayBuffer(transferable) is true) or IsImmutableBuffer(transferable) is true)".
|
Cloning should preserve immutability (tc39/proposal-immutable-arraybuffer#19 (comment)), the same way it currently preserves resizability. |
ef5df7e to
2f4d3cb
Compare
Done.
Done.
Done: 2f4d3cb |
bakkot
left a comment
There was a problem hiding this comment.
I'm not an HTML reviewer, but LGTM
| <li><p>Set <var>serialized</var> to { [[Type]]: "ImmutableArrayBuffer", [[ArrayBufferData]]: | ||
| <var>value</var>.[[ArrayBufferData]], [[ArrayBufferByteLength]]: | ||
| <var>value</var>.[[ArrayBufferByteLength]] }.</p></li> |
There was a problem hiding this comment.
Is value.[[ArrayBufferData]] supposed to be able to be kept alive in the serialization? Unlike for SABs, serializing immutable ArrayBuffers doesn't throw if forStorage is true, meaning that the serialization could be deserialized at some future time in a different process that doesn't share any memory with the current one.
At the very least we should have a note saying that implementations should make sure that a forStorage serialization actually serializes the buffer's contents, but a non-for-storage one might serialize a pointer to the buffer data instead.
There was a problem hiding this comment.
Is
value.[[ArrayBufferData]]supposed to be able to be kept alive in the serialization? Unlike for SABs, serializing immutable ArrayBuffers doesn't throw if forStorage is true, meaning that the serialization could be deserialized at some future time in a different process that doesn't share any memory with the current one.
That's a good question. I'm not very well versed in the particulars here, but my instinct is that I've got it correct—an immutable array buffer should behave like any other non-shared array buffer when forStorage is true, such that it could be deserialized into a new immutable array buffer with identical contents by a completely independent process at some point in the future.
I like your idea of a note, and have attempted to update accordingly.
…ith forStorage true vs. false
| [[ArrayBufferData]] internal slot value is <var>serialized</var>.[[ArrayBufferData]], whose | ||
| [[ArrayBufferByteLength]] internal slot value is | ||
| <var>serialized</var>.[[ArrayBufferByteLength]], and whose [[ArrayBufferIsImmutable]] internal | ||
| slot is present.</p></li> |
There was a problem hiding this comment.
Is it possible for a slot to not have a value in this way?
There was a problem hiding this comment.
Technically yes, but it's obviously not great and I see now that things are moving away from it. I've updated accordingly.
There was a problem hiding this comment.
But for the record, the document.all HTMLAllCollection seems to be another example—it has an [[IsHTMLDDA]] internal slot for which no value is ever specified AFAICT.
There was a problem hiding this comment.
And in ECMAScript, Object Internal Methods and Internal Slots defines the initial value of an internal slot to be undefined.
…uffer with forStorage true vs. false
…hich are not detachable)
domenic
left a comment
There was a problem hiding this comment.
Thanks for doing this; LGTM. We can merge this whenever there is sufficient implementer interest, but if we want to merge it before TC39 stage 4 then instead of linking to https://tc39.es/ecma262/#sec-isimmutablebuffer we'll need to update the link to something that resolves. (See other examples of how HTML references pre-stage-4 TC39 proposals below the big list of terms.)
I'll mark this "do not merge yet" until we're ready in that regard, either way, but the spec text itself looks great.
…eviewers,sfink Spec PR: <whatwg/html#11033> Differential Revision: https://phabricator.services.mozilla.com/D249411
…eviewers,sfink Spec PR: <whatwg/html#11033> Differential Revision: https://phabricator.services.mozilla.com/D249411
…eviewers,sfink Spec PR: <whatwg/html#11033> Differential Revision: https://phabricator.services.mozilla.com/D249411
…eviewers,sfink Spec PR: <whatwg/html#11033> Differential Revision: https://phabricator.services.mozilla.com/D249411
…eviewers,sfink Spec PR: <whatwg/html#11033> Differential Revision: https://phabricator.services.mozilla.com/D249411 UltraBlame original commit: c3d3c452364f15aa0ba169d968075d5acca6d2ca
…eviewers,sfink Spec PR: <whatwg/html#11033> Differential Revision: https://phabricator.services.mozilla.com/D249411 UltraBlame original commit: da0c4055945e2adeb6d7e5d24bc34e0f114364a7
…eviewers,sfink Spec PR: <whatwg/html#11033> Differential Revision: https://phabricator.services.mozilla.com/D249411 UltraBlame original commit: c3d3c452364f15aa0ba169d968075d5acca6d2ca
…eviewers,sfink Spec PR: <whatwg/html#11033> Differential Revision: https://phabricator.services.mozilla.com/D249411 UltraBlame original commit: da0c4055945e2adeb6d7e5d24bc34e0f114364a7
…eviewers,sfink Spec PR: <whatwg/html#11033> Differential Revision: https://phabricator.services.mozilla.com/D249411 UltraBlame original commit: c3d3c452364f15aa0ba169d968075d5acca6d2ca
…eviewers,sfink Spec PR: <whatwg/html#11033> Differential Revision: https://phabricator.services.mozilla.com/D249411 UltraBlame original commit: da0c4055945e2adeb6d7e5d24bc34e0f114364a7
* The serializer must preserve immutability. * Transferring an immutable array buffer is not allowed. Currently the backing store is always copied. Potentially it could be shared for postMessage. See: whatwg/html#11033 Bug: 450237486 Change-Id: I0be6081a29454c8557b81c364b9f49332d15427c Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/7462754 Auto-Submit: Olivier Flückiger <olivf@chromium.org> Commit-Queue: Olivier Flückiger <olivf@chromium.org> Reviewed-by: Leszek Swirski <leszeks@chromium.org> Cr-Commit-Position: refs/heads/main@{#104746}
|
Looks like there's implementations in both Spidermonkey and V8. Presumably that counts as two interested implementations, so, time to land? |
|
Who has the ability to merge now? Perhaps @annevk? |
annevk
left a comment
There was a problem hiding this comment.
This looks good, but someone needs to fill out OP. There's a lot of checkboxes not checked.
| </li> | ||
|
|
||
| <li> | ||
| <p>Otherwise, if <span>IsImmutableBuffer</span>(<var>value</var>) is true, then:</p> |
There was a problem hiding this comment.
| <p>Otherwise, if <span>IsImmutableBuffer</span>(<var>value</var>) is true, then:</p> | |
| <p>Otherwise, if <span>IsImmutableBuffer</span>(<var>value</var>) is true:</p> |
| </li> | ||
|
|
||
| <li> | ||
| <p>Otherwise, if <var>serialized</var>.[[Type]] is "ImmutableArrayBuffer", then:</p> |
There was a problem hiding this comment.
| <p>Otherwise, if <var>serialized</var>.[[Type]] is "ImmutableArrayBuffer", then:</p> | |
| <p>Otherwise, if <var>serialized</var>.[[Type]] is "ImmutableArrayBuffer":</p> |
There was a problem hiding this comment.
Why would the pattern used for type "ImmutableArrayBuffer" differ from the pattern used for types "SharedArrayBuffer" and "GrowableSharedArrayBuffer"?
There was a problem hiding this comment.
Yeah we need to do a more general pass to remove these.
Submitted tests at web-platform-tests/wpt#59803 , and crossed off AAM/ARIA/MDN checkboxes as no-op. I think the rest need implementer engagement, but am happy to be corrected. |
|
You can find links to V8 and SM implementations in the pingbacks, which I think count as interest? The others presumably need bugs filed (though it probably doesn't make sense to file bugs on Node or Deno in advance of V8 implementing, so I guess just JSC). |
|
What's the Web IDL story for these? |
whatwg/webidl#1487 and whatwg/webidl#1598 tc39/proposal-import-bytes#28 also covers a lot |
|
Thanks for the pointers. So the Web IDL integration seems incomplete. The tentative proposal is that any API that takes a buffer or view today will accept an immutable buffer automatically. This seems like it should work fine for Fetch, but not Encoding's |
Ref tc39/proposal-immutable-arraybuffer#30
Immutable ArrayBuffers is currently at Stage 2, but seeking advancement in next week's Ecma TC39 meeting. Because immutable ArrayBuffers cannot be detached,
structuredCloneshould perform the relevant test.Corresponding HTML AAM & ARIA in HTML issues & PRs:MDN issue is filed:(See WHATWG Working Mode: Changes for more details.)
/infrastructure.html ( diff )
/structured-data.html ( diff )