-
Notifications
You must be signed in to change notification settings - Fork 164
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
"byte length of a buffer source type" needs updating for resizable and detached buffers #1385
Comments
|
Huh, yeah, I didn't realize that "Uint8Array" meant specifically a |
Hm, actually, this is already an issue because of detached buffers. Reading the Consider writing the first byte into a Uint8Array backed by a detached buffer.
|
If destination's byte length - written is false we'd break and return, no? Anyway, keeping this open to tidy all these things up seems worth it. |
Sorry, that should read "true". On the first byte, written is 0, destination's byte length the original size of the array, and the number of bytes in result is 1 between and 4 (I assume; anyway it's some finite number). So as long as the TA originally had at least 4 bytes, that check passes and we don't break. |
It seems per https://software.hixie.ch/utilities/js/live-dom-viewer/?%3Cscript%3E%0As%20%3D%20new%20Uint8Array(new%20ArrayBuffer(8))%3B%0Aw(s.buffer.byteLength)%0Aw(s.byteLength)%3B%0ApostMessage(s%2C%20%22*%22%2C%20[s.buffer])%3B%0Aw(s.buffer.byteLength)%0Aw(s.byteLength)%3B%0Aw(new%20TextEncoder().encodeInto(%22fd%22%2C%20s))%3B%0A%3C%2Fscript%3E implementations already do the right thing here, but this is indeed a bug. |
Good catch. These should be checked for using https://tc39.es/ecma262/#sec-istypedarrayoutofbounds for simpler reasoning at the boundary, even if resizable buffers are currently disallowed. |
Is the intention to treat detached buffers as zero-length? That's kind of weird. I've copied that behavior into |
I think throwing a TypeError would be better. Not sure if |
What is the issue with the Web IDL Standard?
As of this proposal / PR, the
[[ByteLength]]
slot on TypedArrays and DataViews can be~auto~
instead of an integer. Consumers of the "byte length of a buffer source" operation (likeencodeInto
) probably want TypedArrayByteLength or GetViewByteLength instead of the raw value of the[[ByteLength]]
slot.Also, when getting the length of an ArrayBuffer, this should probably use the ArrayBufferByteLength abstract operation, not raw access of the slot.
There's some other raw uses of the
[[ByteLength]]
slot, like in "write a byte sequence bytes into an ArrayBufferView", which should probably also be updated.cc @syg
The text was updated successfully, but these errors were encountered: