From 82be51dc85b1a3a2d6427c3c53b474dab94106bd Mon Sep 17 00:00:00 2001 From: kipcode66 Date: Thu, 27 Jul 2023 22:31:09 -0400 Subject: [PATCH 1/6] Update gen_FileSystemSyncAccessHandle.rs Removed unnecessary `mut` for the write functions. --- crates/web-sys/src/features/gen_FileSystemSyncAccessHandle.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/web-sys/src/features/gen_FileSystemSyncAccessHandle.rs b/crates/web-sys/src/features/gen_FileSystemSyncAccessHandle.rs index 30d81b46b83..8b293264f7c 100644 --- a/crates/web-sys/src/features/gen_FileSystemSyncAccessHandle.rs +++ b/crates/web-sys/src/features/gen_FileSystemSyncAccessHandle.rs @@ -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; #[cfg(web_sys_unstable_apis)] #[cfg(feature = "FileSystemReadWriteOptions")] @@ -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; } From e1160ca2b597e66b1cbf25ee32be79eae659efb5 Mon Sep 17 00:00:00 2001 From: kipcode66 Date: Fri, 28 Jul 2023 12:12:22 -0400 Subject: [PATCH 2/6] updated whitelist & tests --- .../gen_FileSystemSyncAccessHandle.rs | 4 ++-- .../gen_FileSystemWritableFileStream.rs | 2 +- .../web-sys/src/features/gen_IdbFileHandle.rs | 2 +- .../wasm/whitelisted_immutable_slices.rs | 19 +++++++++++++++++++ crates/webidl/src/constants.rs | 2 ++ 5 files changed, 25 insertions(+), 4 deletions(-) diff --git a/crates/web-sys/src/features/gen_FileSystemSyncAccessHandle.rs b/crates/web-sys/src/features/gen_FileSystemSyncAccessHandle.rs index 30d81b46b83..8b293264f7c 100644 --- a/crates/web-sys/src/features/gen_FileSystemSyncAccessHandle.rs +++ b/crates/web-sys/src/features/gen_FileSystemSyncAccessHandle.rs @@ -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; #[cfg(web_sys_unstable_apis)] #[cfg(feature = "FileSystemReadWriteOptions")] @@ -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; } diff --git a/crates/web-sys/src/features/gen_FileSystemWritableFileStream.rs b/crates/web-sys/src/features/gen_FileSystemWritableFileStream.rs index c3698228340..56f11326193 100644 --- a/crates/web-sys/src/features/gen_FileSystemWritableFileStream.rs +++ b/crates/web-sys/src/features/gen_FileSystemWritableFileStream.rs @@ -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")] diff --git a/crates/web-sys/src/features/gen_IdbFileHandle.rs b/crates/web-sys/src/features/gen_IdbFileHandle.rs index 91ce76a4244..4881af976e3 100644 --- a/crates/web-sys/src/features/gen_IdbFileHandle.rs +++ b/crates/web-sys/src/features/gen_IdbFileHandle.rs @@ -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, JsValue>; #[cfg(all(feature = "Blob", feature = "IdbFileRequest",))] # [wasm_bindgen (catch , method , structural , js_class = "IDBFileHandle" , js_name = write)] diff --git a/crates/web-sys/tests/wasm/whitelisted_immutable_slices.rs b/crates/web-sys/tests/wasm/whitelisted_immutable_slices.rs index 14bda73c0f9..042fe3d815f 100644 --- a/crates/web-sys/tests/wasm/whitelisted_immutable_slices.rs +++ b/crates/web-sys/tests/wasm/whitelisted_immutable_slices.rs @@ -11,6 +11,8 @@ //! @see https://github.com/rustwasm/wasm-bindgen/issues/1005 use wasm_bindgen::{JsCast, JsValue}; +#[cfg(web_sys_unstable_apis)] +use web_sys::{FileSystemSyncAccessHandle, FileSystemWritableFileStream}; use web_sys::{WebGl2RenderingContext, WebGlRenderingContext, WebSocket}; // Ensure that our whitelisted WebGlRenderingContext methods compile with immutable slices. @@ -71,6 +73,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::(); + let opt = JsValue::null().unchecked_into::(); + + 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::(); + wf.write_with_u8_array(&[0]); +} + // TODO: //#[wasm_bindgen_test] //fn test_another_types_immutable_slices_here() { diff --git a/crates/webidl/src/constants.rs b/crates/webidl/src/constants.rs index 79814e4644b..57b77913483 100644 --- a/crates/webidl/src/constants.rs +++ b/crates/webidl/src/constants.rs @@ -92,6 +92,8 @@ pub(crate) static IMMUTABLE_SLICE_WHITELIST: Lazy> = Lazy "copyToChannel", // FontFace "FontFace", // TODO: Add another type's functions here. Leave a comment header with the type name + // FileSystemWritableFileStream and FileSystemWritableFileStream + "write", ]) }); From e0ed9ea79fd1982a61baab99b88e70b162f08433 Mon Sep 17 00:00:00 2001 From: kipcode66 Date: Fri, 28 Jul 2023 12:20:10 -0400 Subject: [PATCH 3/6] fix: missing FileSystemReadWriteOptions --- crates/web-sys/tests/wasm/whitelisted_immutable_slices.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/web-sys/tests/wasm/whitelisted_immutable_slices.rs b/crates/web-sys/tests/wasm/whitelisted_immutable_slices.rs index 042fe3d815f..25cb266caaa 100644 --- a/crates/web-sys/tests/wasm/whitelisted_immutable_slices.rs +++ b/crates/web-sys/tests/wasm/whitelisted_immutable_slices.rs @@ -12,7 +12,7 @@ use wasm_bindgen::{JsCast, JsValue}; #[cfg(web_sys_unstable_apis)] -use web_sys::{FileSystemSyncAccessHandle, FileSystemWritableFileStream}; +use web_sys::{FileSystemSyncAccessHandle, FileSystemWritableFileStream, FileSystemReadWriteOptions}; use web_sys::{WebGl2RenderingContext, WebGlRenderingContext, WebSocket}; // Ensure that our whitelisted WebGlRenderingContext methods compile with immutable slices. From 7140d4e15c4473875710ed9869c159f4a6df85ca Mon Sep 17 00:00:00 2001 From: kipcode66 Date: Fri, 28 Jul 2023 12:24:51 -0400 Subject: [PATCH 4/6] fix: formatting --- crates/web-sys/tests/wasm/whitelisted_immutable_slices.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/web-sys/tests/wasm/whitelisted_immutable_slices.rs b/crates/web-sys/tests/wasm/whitelisted_immutable_slices.rs index 25cb266caaa..30d70bf3f6d 100644 --- a/crates/web-sys/tests/wasm/whitelisted_immutable_slices.rs +++ b/crates/web-sys/tests/wasm/whitelisted_immutable_slices.rs @@ -12,7 +12,9 @@ use wasm_bindgen::{JsCast, JsValue}; #[cfg(web_sys_unstable_apis)] -use web_sys::{FileSystemSyncAccessHandle, FileSystemWritableFileStream, FileSystemReadWriteOptions}; +use web_sys::{ + FileSystemReadWriteOptions, FileSystemSyncAccessHandle, FileSystemWritableFileStream, +}; use web_sys::{WebGl2RenderingContext, WebGlRenderingContext, WebSocket}; // Ensure that our whitelisted WebGlRenderingContext methods compile with immutable slices. From ef3ae133b3b95a9417bf14d12bb295ff5e7136b6 Mon Sep 17 00:00:00 2001 From: kipcode66 Date: Fri, 28 Jul 2023 12:53:33 -0400 Subject: [PATCH 5/6] fix: comment --- crates/webidl/src/constants.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/webidl/src/constants.rs b/crates/webidl/src/constants.rs index 57b77913483..3118807ff81 100644 --- a/crates/webidl/src/constants.rs +++ b/crates/webidl/src/constants.rs @@ -92,7 +92,7 @@ pub(crate) static IMMUTABLE_SLICE_WHITELIST: Lazy> = Lazy "copyToChannel", // FontFace "FontFace", // TODO: Add another type's functions here. Leave a comment header with the type name - // FileSystemWritableFileStream and FileSystemWritableFileStream + // FileSystemSyncAccessHandle and FileSystemWritableFileStream "write", ]) }); From a52495a8f32e378865c787514aa333d23ec0f36d Mon Sep 17 00:00:00 2001 From: kipcode66 Date: Fri, 4 Aug 2023 09:47:46 -0400 Subject: [PATCH 6/6] updated changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bdb6a1baad5..3915651c568 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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`.