Fix BufferSource
algorithms for shared and resizable buffers
#1529
+50
−35
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Previously, many
BufferSource
algorithms were using internal slots such as[[ByteOffset]]
and[[ByteLength]]
directly. However, with the addition ofSharedArrayBuffer
(#353, #1311) and[AllowResizable]
(#982), this comes with extra caveats:SharedArrayBuffer
, we need to useArrayBufferByteLength
to matchSharedArrayBuffer.prototype.byteLength
.TypedArrayByteLength
. Similarly, for a length-trackingDataView
, we need to useGetViewByteLength
.DataView
, we first need to check if the view is still inbounds usingIsArrayBufferViewOutOfBounds
.Transferring an
ArrayBuffer
must also take into account whether it should remain resizable or not. Fortunately, we can use the newArrayBufferCopyAndDetach
operation for that.preserveResizability
parameter to "transfer anArrayBuffer
", so specifications can choose whether to preserve resizability or not. By default, this is not preserved. (Most specs aren't using[AllowResizable]
yet anyway.)realm
parameter of that algorithm, sinceArrayBufferCopyAndDetach
doesn't accept such a parameter. According to WebDex, no specs were actually using that parameter anyway.Open questions:
SharedArrayBuffer
, what memory ordering should we use? ECMAScript seems to useSEQ-CST
pretty much everywhere (e.g.%TypedArray%.prototype.byteLength
), but "get a copy of the bytes" usesUNORDERED
forGetValueFromBuffer
.Fixes #1312.
Fixes #1385.
(See WHATWG Working Mode: Changes for more details.)
Preview | Diff