-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
web-sys: unnecessary &mut requirement in WebUSB functions, potentially others #3963
Comments
This is the case because web-sys is auto-generated from WebIDL, which doesn't include any information about whether or not buffers passed to functions are mutable. Because of that, it conservatively assumes that all buffers are mutable, since it can't result in UB if a web API tries to mutate an immutable buffer and it's backwards-compatible to change a slice from mutable to immutable. That change is made by adding the functions whose slices should be immutable to a big list: wasm-bindgen/crates/webidl/src/constants.rs Lines 43 to 105 in fa6d2bc
|
@spookyvision Do you want to see if WebIDL is aware of the limitation? Solve the problem upstream? |
I did a quick scan of the WebIDL spec and it doesn't seem they have a concept of (im)mutability, sadly. I might be wrong, but since the spec refers JavaScript a lot, it's probably closely modeled based on JS semantics. |
several WebUSB functions that take a
[u8]
slice, e.g., transfer_out_with_u8_array, require it be passed as&mut
. As far as I can tell this is not required since USB transfers are unidirectional.full list of affected functions:
other APIs might also be affected - I searched the docs for
with_u8_array
and found e.g. ReadableByteStreamController::enqueue_with_u8_array taking a&mut
buffer which at first glance is only used for reading.The text was updated successfully, but these errors were encountered: