Skip to content
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

Changed write functions of FileSystemSyncAccessHandle to accept immutable buffers #3537

Merged
merged 7 commits into from
Aug 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
* Replaced `curl` with `ureq`. By default we now use Rustls instead of OpenSSL.
[#3511](https://github.com/rustwasm/wasm-bindgen/pull/3511)

* Changed mutability of the argument `buffer` in `write` functions to immutable for `FileSystemSyncAccessHandle` and `FileSystemWritableFileStream`.
It was also automatically changed for `IdbFileHandle`, which is deprecated.
[#3537](https://github.com/rustwasm/wasm-bindgen/pull/3537)

### Fixed

* Fixed bindings and comments for `Atomics.wait`.
Expand Down
4 changes: 2 additions & 2 deletions crates/web-sys/src/features/gen_FileSystemSyncAccessHandle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ extern "C" {
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn write_with_u8_array(
this: &FileSystemSyncAccessHandle,
buffer: &mut [u8],
buffer: &[u8],
) -> Result<f64, JsValue>;
#[cfg(web_sys_unstable_apis)]
#[cfg(feature = "FileSystemReadWriteOptions")]
Expand Down Expand Up @@ -194,7 +194,7 @@ extern "C" {
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn write_with_u8_array_and_options(
this: &FileSystemSyncAccessHandle,
buffer: &mut [u8],
buffer: &[u8],
options: &FileSystemReadWriteOptions,
) -> Result<f64, JsValue>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ extern "C" {
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn write_with_u8_array(
this: &FileSystemWritableFileStream,
data: &mut [u8],
data: &[u8],
) -> Result<::js_sys::Promise, JsValue>;
#[cfg(web_sys_unstable_apis)]
#[cfg(feature = "Blob")]
Expand Down
2 changes: 1 addition & 1 deletion crates/web-sys/src/features/gen_IdbFileHandle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ extern "C" {
#[doc = "*This API requires the following crate features to be activated: `IdbFileHandle`, `IdbFileRequest`*"]
pub fn write_with_u8_array(
this: &IdbFileHandle,
value: &mut [u8],
value: &[u8],
) -> Result<Option<IdbFileRequest>, JsValue>;
#[cfg(all(feature = "Blob", feature = "IdbFileRequest",))]
# [wasm_bindgen (catch , method , structural , js_class = "IDBFileHandle" , js_name = write)]
Expand Down
21 changes: 21 additions & 0 deletions crates/web-sys/tests/wasm/whitelisted_immutable_slices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
//! @see https://github.com/rustwasm/wasm-bindgen/issues/1005

use wasm_bindgen::{JsCast, JsValue};
#[cfg(web_sys_unstable_apis)]
use web_sys::{
FileSystemReadWriteOptions, FileSystemSyncAccessHandle, FileSystemWritableFileStream,
};
use web_sys::{WebGl2RenderingContext, WebGlRenderingContext, WebSocket};

// Ensure that our whitelisted WebGlRenderingContext methods compile with immutable slices.
Expand Down Expand Up @@ -71,6 +75,23 @@ fn test_websocket_immutable_slices() {
ws.send_with_u8_array(&[0]);
}

// Ensure that our whitelisted FileSystemSyncAccessHandle methods compile with immutable slices.
#[cfg(web_sys_unstable_apis)]
fn test_file_system_sync_access_handle_immutable_slices() {
let sa = JsValue::null().unchecked_into::<FileSystemSyncAccessHandle>();
let opt = JsValue::null().unchecked_into::<FileSystemReadWriteOptions>();

sa.write_with_u8_array(&[0]);
sa.write_with_u8_array_and_options(&[0], &opt);
}

// Ensure that our whitelisted FileSystemWritableFileStream methods compile with immutable slices.
#[cfg(web_sys_unstable_apis)]
fn test_file_system_writable_file_stream_immutable_slices() {
let wf = JsValue::null().unchecked_into::<FileSystemWritableFileStream>();
wf.write_with_u8_array(&[0]);
}

// TODO:
//#[wasm_bindgen_test]
//fn test_another_types_immutable_slices_here() {
Expand Down
2 changes: 2 additions & 0 deletions crates/webidl/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ pub(crate) static IMMUTABLE_SLICE_WHITELIST: Lazy<BTreeSet<&'static str>> = Lazy
"copyToChannel",
// FontFace
"FontFace", // TODO: Add another type's functions here. Leave a comment header with the type name
// FileSystemSyncAccessHandle and FileSystemWritableFileStream
"write",
])
});

Expand Down