Skip to content

Commit 95bf437

Browse files
authored
Account for [AllowShared] and improve setters generated from interface attributes (rustwasm#4156)
1 parent e575aba commit 95bf437

File tree

68 files changed

+8167
-364
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+8167
-364
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@
2929
* Added `unsupported` crate to `wasm_bindgen_test(unsupported = test)` as a way of running tests on non-Wasm targets as well.
3030
[#4150](https://github.com/rustwasm/wasm-bindgen/pull/4150)
3131

32+
* Added additional bindings for methods taking buffer view types (e.g. `&[u8]`) with corresponding JS types (e.g. `Uint8Array`).
33+
[#4156](https://github.com/rustwasm/wasm-bindgen/pull/4156)
34+
35+
* Added additional bindings for setters from WebIDL interface attributes with applicaple parameter types of just `JsValue`.
36+
[#4156](https://github.com/rustwasm/wasm-bindgen/pull/4156)
37+
3238
### Changed
3339

3440
* Implicitly enable reference type and multivalue transformations if the module already makes use of the corresponding target features.
@@ -49,6 +55,9 @@
4955
* Updated the WebGPU API to the current draft as of 2024-10-07.
5056
[#4145](https://github.com/rustwasm/wasm-bindgen/pull/4145)
5157

58+
* Deprecated generated setters from WebIDL interface attribute taking `JsValue` in favor of newer bindings with specific parameter types.
59+
[#4156](https://github.com/rustwasm/wasm-bindgen/pull/4156)
60+
5261
### Fixed
5362

5463
* Fixed linked modules emitting snippet files when not using `--split-linked-modules`.
@@ -88,6 +97,9 @@
8897
* Fixed string enums not generating TypeScript types.
8998
[#4147](https://github.com/rustwasm/wasm-bindgen/pull/4147)
9099

100+
* Bindings that take buffer view types (e.g. `&[u8]`) as parameters will now correctly return a `Result` when they might not support a backing `SharedArrayBuffer`. This only applies to new and unstable APIs, which won't cause a breaking in the API.
101+
[#4156](https://github.com/rustwasm/wasm-bindgen/pull/4156)
102+
91103
--------------------------------------------------------------------------------
92104

93105
## [0.2.93](https://github.com/rustwasm/wasm-bindgen/compare/0.2.92...0.2.93)

crates/web-sys/src/features/gen_AnalyserNode.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,25 +101,62 @@ extern "C" {
101101
#[doc = ""]
102102
#[doc = "*This API requires the following crate features to be activated: `AnalyserNode`*"]
103103
pub fn get_byte_frequency_data(this: &AnalyserNode, array: &mut [u8]);
104+
# [wasm_bindgen (method , structural , js_class = "AnalyserNode" , js_name = getByteFrequencyData)]
105+
#[doc = "The `getByteFrequencyData()` method."]
106+
#[doc = ""]
107+
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/AnalyserNode/getByteFrequencyData)"]
108+
#[doc = ""]
109+
#[doc = "*This API requires the following crate features to be activated: `AnalyserNode`*"]
110+
pub fn get_byte_frequency_data_with_u8_array(this: &AnalyserNode, array: &::js_sys::Uint8Array);
104111
# [wasm_bindgen (method , structural , js_class = "AnalyserNode" , js_name = getByteTimeDomainData)]
105112
#[doc = "The `getByteTimeDomainData()` method."]
106113
#[doc = ""]
107114
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/AnalyserNode/getByteTimeDomainData)"]
108115
#[doc = ""]
109116
#[doc = "*This API requires the following crate features to be activated: `AnalyserNode`*"]
110117
pub fn get_byte_time_domain_data(this: &AnalyserNode, array: &mut [u8]);
118+
# [wasm_bindgen (method , structural , js_class = "AnalyserNode" , js_name = getByteTimeDomainData)]
119+
#[doc = "The `getByteTimeDomainData()` method."]
120+
#[doc = ""]
121+
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/AnalyserNode/getByteTimeDomainData)"]
122+
#[doc = ""]
123+
#[doc = "*This API requires the following crate features to be activated: `AnalyserNode`*"]
124+
pub fn get_byte_time_domain_data_with_u8_array(
125+
this: &AnalyserNode,
126+
array: &::js_sys::Uint8Array,
127+
);
111128
# [wasm_bindgen (method , structural , js_class = "AnalyserNode" , js_name = getFloatFrequencyData)]
112129
#[doc = "The `getFloatFrequencyData()` method."]
113130
#[doc = ""]
114131
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/AnalyserNode/getFloatFrequencyData)"]
115132
#[doc = ""]
116133
#[doc = "*This API requires the following crate features to be activated: `AnalyserNode`*"]
117134
pub fn get_float_frequency_data(this: &AnalyserNode, array: &mut [f32]);
135+
# [wasm_bindgen (method , structural , js_class = "AnalyserNode" , js_name = getFloatFrequencyData)]
136+
#[doc = "The `getFloatFrequencyData()` method."]
137+
#[doc = ""]
138+
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/AnalyserNode/getFloatFrequencyData)"]
139+
#[doc = ""]
140+
#[doc = "*This API requires the following crate features to be activated: `AnalyserNode`*"]
141+
pub fn get_float_frequency_data_with_f32_array(
142+
this: &AnalyserNode,
143+
array: &::js_sys::Float32Array,
144+
);
118145
# [wasm_bindgen (method , structural , js_class = "AnalyserNode" , js_name = getFloatTimeDomainData)]
119146
#[doc = "The `getFloatTimeDomainData()` method."]
120147
#[doc = ""]
121148
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/AnalyserNode/getFloatTimeDomainData)"]
122149
#[doc = ""]
123150
#[doc = "*This API requires the following crate features to be activated: `AnalyserNode`*"]
124151
pub fn get_float_time_domain_data(this: &AnalyserNode, array: &mut [f32]);
152+
# [wasm_bindgen (method , structural , js_class = "AnalyserNode" , js_name = getFloatTimeDomainData)]
153+
#[doc = "The `getFloatTimeDomainData()` method."]
154+
#[doc = ""]
155+
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/AnalyserNode/getFloatTimeDomainData)"]
156+
#[doc = ""]
157+
#[doc = "*This API requires the following crate features to be activated: `AnalyserNode`*"]
158+
pub fn get_float_time_domain_data_with_f32_array(
159+
this: &AnalyserNode,
160+
array: &::js_sys::Float32Array,
161+
);
125162
}

crates/web-sys/src/features/gen_AudioBuffer.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,35 @@ extern "C" {
6565
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/AudioBuffer/copyFromChannel)"]
6666
#[doc = ""]
6767
#[doc = "*This API requires the following crate features to be activated: `AudioBuffer`*"]
68+
pub fn copy_from_channel_with_f32_array(
69+
this: &AudioBuffer,
70+
destination: &::js_sys::Float32Array,
71+
channel_number: i32,
72+
) -> Result<(), JsValue>;
73+
# [wasm_bindgen (catch , method , structural , js_class = "AudioBuffer" , js_name = copyFromChannel)]
74+
#[doc = "The `copyFromChannel()` method."]
75+
#[doc = ""]
76+
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/AudioBuffer/copyFromChannel)"]
77+
#[doc = ""]
78+
#[doc = "*This API requires the following crate features to be activated: `AudioBuffer`*"]
6879
pub fn copy_from_channel_with_start_in_channel(
6980
this: &AudioBuffer,
7081
destination: &mut [f32],
7182
channel_number: i32,
7283
start_in_channel: u32,
7384
) -> Result<(), JsValue>;
85+
# [wasm_bindgen (catch , method , structural , js_class = "AudioBuffer" , js_name = copyFromChannel)]
86+
#[doc = "The `copyFromChannel()` method."]
87+
#[doc = ""]
88+
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/AudioBuffer/copyFromChannel)"]
89+
#[doc = ""]
90+
#[doc = "*This API requires the following crate features to be activated: `AudioBuffer`*"]
91+
pub fn copy_from_channel_with_f32_array_and_start_in_channel(
92+
this: &AudioBuffer,
93+
destination: &::js_sys::Float32Array,
94+
channel_number: i32,
95+
start_in_channel: u32,
96+
) -> Result<(), JsValue>;
7497
# [wasm_bindgen (catch , method , structural , js_class = "AudioBuffer" , js_name = copyToChannel)]
7598
#[doc = "The `copyToChannel()` method."]
7699
#[doc = ""]
@@ -88,12 +111,35 @@ extern "C" {
88111
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/AudioBuffer/copyToChannel)"]
89112
#[doc = ""]
90113
#[doc = "*This API requires the following crate features to be activated: `AudioBuffer`*"]
114+
pub fn copy_to_channel_with_f32_array(
115+
this: &AudioBuffer,
116+
source: &::js_sys::Float32Array,
117+
channel_number: i32,
118+
) -> Result<(), JsValue>;
119+
# [wasm_bindgen (catch , method , structural , js_class = "AudioBuffer" , js_name = copyToChannel)]
120+
#[doc = "The `copyToChannel()` method."]
121+
#[doc = ""]
122+
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/AudioBuffer/copyToChannel)"]
123+
#[doc = ""]
124+
#[doc = "*This API requires the following crate features to be activated: `AudioBuffer`*"]
91125
pub fn copy_to_channel_with_start_in_channel(
92126
this: &AudioBuffer,
93127
source: &[f32],
94128
channel_number: i32,
95129
start_in_channel: u32,
96130
) -> Result<(), JsValue>;
131+
# [wasm_bindgen (catch , method , structural , js_class = "AudioBuffer" , js_name = copyToChannel)]
132+
#[doc = "The `copyToChannel()` method."]
133+
#[doc = ""]
134+
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/AudioBuffer/copyToChannel)"]
135+
#[doc = ""]
136+
#[doc = "*This API requires the following crate features to be activated: `AudioBuffer`*"]
137+
pub fn copy_to_channel_with_f32_array_and_start_in_channel(
138+
this: &AudioBuffer,
139+
source: &::js_sys::Float32Array,
140+
channel_number: i32,
141+
start_in_channel: u32,
142+
) -> Result<(), JsValue>;
97143
# [wasm_bindgen (catch , method , structural , js_class = "AudioBuffer" , js_name = getChannelData)]
98144
#[doc = "The `getChannelData()` method."]
99145
#[doc = ""]

crates/web-sys/src/features/gen_AudioContext.rs

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,42 @@ extern "C" {
362362
real: &mut [f32],
363363
imag: &mut [f32],
364364
) -> Result<PeriodicWave, JsValue>;
365+
#[cfg(feature = "PeriodicWave")]
366+
# [wasm_bindgen (catch , method , structural , js_class = "AudioContext" , js_name = createPeriodicWave)]
367+
#[doc = "The `createPeriodicWave()` method."]
368+
#[doc = ""]
369+
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/createPeriodicWave)"]
370+
#[doc = ""]
371+
#[doc = "*This API requires the following crate features to be activated: `AudioContext`, `PeriodicWave`*"]
372+
pub fn create_periodic_wave_with_f32_array_and_f32_slice(
373+
this: &AudioContext,
374+
real: &::js_sys::Float32Array,
375+
imag: &mut [f32],
376+
) -> Result<PeriodicWave, JsValue>;
377+
#[cfg(feature = "PeriodicWave")]
378+
# [wasm_bindgen (catch , method , structural , js_class = "AudioContext" , js_name = createPeriodicWave)]
379+
#[doc = "The `createPeriodicWave()` method."]
380+
#[doc = ""]
381+
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/createPeriodicWave)"]
382+
#[doc = ""]
383+
#[doc = "*This API requires the following crate features to be activated: `AudioContext`, `PeriodicWave`*"]
384+
pub fn create_periodic_wave_with_f32_slice_and_f32_array(
385+
this: &AudioContext,
386+
real: &mut [f32],
387+
imag: &::js_sys::Float32Array,
388+
) -> Result<PeriodicWave, JsValue>;
389+
#[cfg(feature = "PeriodicWave")]
390+
# [wasm_bindgen (catch , method , structural , js_class = "AudioContext" , js_name = createPeriodicWave)]
391+
#[doc = "The `createPeriodicWave()` method."]
392+
#[doc = ""]
393+
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/createPeriodicWave)"]
394+
#[doc = ""]
395+
#[doc = "*This API requires the following crate features to be activated: `AudioContext`, `PeriodicWave`*"]
396+
pub fn create_periodic_wave_with_f32_array_and_f32_array(
397+
this: &AudioContext,
398+
real: &::js_sys::Float32Array,
399+
imag: &::js_sys::Float32Array,
400+
) -> Result<PeriodicWave, JsValue>;
365401
#[cfg(all(feature = "PeriodicWave", feature = "PeriodicWaveConstraints",))]
366402
# [wasm_bindgen (catch , method , structural , js_class = "AudioContext" , js_name = createPeriodicWave)]
367403
#[doc = "The `createPeriodicWave()` method."]
@@ -375,6 +411,45 @@ extern "C" {
375411
imag: &mut [f32],
376412
constraints: &PeriodicWaveConstraints,
377413
) -> Result<PeriodicWave, JsValue>;
414+
#[cfg(all(feature = "PeriodicWave", feature = "PeriodicWaveConstraints",))]
415+
# [wasm_bindgen (catch , method , structural , js_class = "AudioContext" , js_name = createPeriodicWave)]
416+
#[doc = "The `createPeriodicWave()` method."]
417+
#[doc = ""]
418+
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/createPeriodicWave)"]
419+
#[doc = ""]
420+
#[doc = "*This API requires the following crate features to be activated: `AudioContext`, `PeriodicWave`, `PeriodicWaveConstraints`*"]
421+
pub fn create_periodic_wave_with_f32_array_and_f32_slice_and_constraints(
422+
this: &AudioContext,
423+
real: &::js_sys::Float32Array,
424+
imag: &mut [f32],
425+
constraints: &PeriodicWaveConstraints,
426+
) -> Result<PeriodicWave, JsValue>;
427+
#[cfg(all(feature = "PeriodicWave", feature = "PeriodicWaveConstraints",))]
428+
# [wasm_bindgen (catch , method , structural , js_class = "AudioContext" , js_name = createPeriodicWave)]
429+
#[doc = "The `createPeriodicWave()` method."]
430+
#[doc = ""]
431+
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/createPeriodicWave)"]
432+
#[doc = ""]
433+
#[doc = "*This API requires the following crate features to be activated: `AudioContext`, `PeriodicWave`, `PeriodicWaveConstraints`*"]
434+
pub fn create_periodic_wave_with_f32_slice_and_f32_array_and_constraints(
435+
this: &AudioContext,
436+
real: &mut [f32],
437+
imag: &::js_sys::Float32Array,
438+
constraints: &PeriodicWaveConstraints,
439+
) -> Result<PeriodicWave, JsValue>;
440+
#[cfg(all(feature = "PeriodicWave", feature = "PeriodicWaveConstraints",))]
441+
# [wasm_bindgen (catch , method , structural , js_class = "AudioContext" , js_name = createPeriodicWave)]
442+
#[doc = "The `createPeriodicWave()` method."]
443+
#[doc = ""]
444+
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/createPeriodicWave)"]
445+
#[doc = ""]
446+
#[doc = "*This API requires the following crate features to be activated: `AudioContext`, `PeriodicWave`, `PeriodicWaveConstraints`*"]
447+
pub fn create_periodic_wave_with_f32_array_and_f32_array_and_constraints(
448+
this: &AudioContext,
449+
real: &::js_sys::Float32Array,
450+
imag: &::js_sys::Float32Array,
451+
constraints: &PeriodicWaveConstraints,
452+
) -> Result<PeriodicWave, JsValue>;
378453
#[cfg(feature = "ScriptProcessorNode")]
379454
# [wasm_bindgen (catch , method , structural , js_class = "AudioContext" , js_name = createScriptProcessor)]
380455
#[doc = "The `createScriptProcessor()` method."]

crates/web-sys/src/features/gen_AudioData.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,25 @@ extern "C" {
159159
#[doc = ""]
160160
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
161161
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
162-
pub fn copy_to_with_u8_array(
162+
pub fn copy_to_with_u8_slice(
163163
this: &AudioData,
164164
destination: &mut [u8],
165165
options: &AudioDataCopyToOptions,
166166
) -> Result<(), JsValue>;
167+
#[cfg(web_sys_unstable_apis)]
168+
#[cfg(feature = "AudioDataCopyToOptions")]
169+
# [wasm_bindgen (catch , method , structural , js_class = "AudioData" , js_name = copyTo)]
170+
#[doc = "The `copyTo()` method."]
171+
#[doc = ""]
172+
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/AudioData/copyTo)"]
173+
#[doc = ""]
174+
#[doc = "*This API requires the following crate features to be activated: `AudioData`, `AudioDataCopyToOptions`*"]
175+
#[doc = ""]
176+
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
177+
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
178+
pub fn copy_to_with_u8_array(
179+
this: &AudioData,
180+
destination: &::js_sys::Uint8Array,
181+
options: &AudioDataCopyToOptions,
182+
) -> Result<(), JsValue>;
167183
}

crates/web-sys/src/features/gen_AudioParam.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,16 @@ extern "C" {
114114
start_time: f64,
115115
duration: f64,
116116
) -> Result<AudioParam, JsValue>;
117+
# [wasm_bindgen (catch , method , structural , js_class = "AudioParam" , js_name = setValueCurveAtTime)]
118+
#[doc = "The `setValueCurveAtTime()` method."]
119+
#[doc = ""]
120+
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/AudioParam/setValueCurveAtTime)"]
121+
#[doc = ""]
122+
#[doc = "*This API requires the following crate features to be activated: `AudioParam`*"]
123+
pub fn set_value_curve_at_time_with_f32_array(
124+
this: &AudioParam,
125+
values: &::js_sys::Float32Array,
126+
start_time: f64,
127+
duration: f64,
128+
) -> Result<AudioParam, JsValue>;
117129
}

0 commit comments

Comments
 (0)