Truly independent web browser
LibWeb: Port WebAudio parameter and listener interfaces to Rust
Shannon Booth8fd163685ab9
diff --git a/Libraries/LibWeb/Bindings/Rust/src/web_audio/audio_listener.rs b/Libraries/LibWeb/Bindings/Rust/src/web_audio/audio_listener.rsnew file mode 100644index 00000000000..caeb00560c2--- /dev/null+++ b/Libraries/LibWeb/Bindings/Rust/src/web_audio/audio_listener.rs@@ -0,0 +1,230 @@+/*+ * Copyright (c) 2024, Jelle Raaijmakers <[email protected]>+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++use std::ffi::c_void;++use libjs_rust::api::{Trace, Vm};++use super::audio_param::{AudioParam, AutomationRate, FixedAutomationRate};+use crate::bindings::cpp_cell::CppCell;+use crate::bindings::interface::{Ref, Wrappable, allocate, cell_from_abi, cell_into_abi};+use crate::bindings::{CallContext, WebIdlResult};++// https://webaudio.github.io/web-audio-api/#AudioListener+#[derive(Trace)]+#[gc(crate = libjs_rust)]+pub(crate) struct AudioListener {+ forward_x: Ref<AudioParam>,+ forward_y: Ref<AudioParam>,+ forward_z: Ref<AudioParam>,+ position_x: Ref<AudioParam>,+ position_y: Ref<AudioParam>,+ position_z: Ref<AudioParam>,+ up_x: Ref<AudioParam>,+ up_y: Ref<AudioParam>,+ up_z: Ref<AudioParam>,+}++impl Wrappable for AudioListener {}+impl AudioListener {+ pub(crate) fn create(vm: &Vm, context: CppCell) -> Ref<Self> {+ allocate(vm, |_| Self {+ forward_x: AudioParam::create(+ vm,+ context.clone(),+ None,+ 0.,+ f32::MIN,+ f32::MAX,+ AutomationRate::ARate,+ FixedAutomationRate::No,+ ),+ forward_y: AudioParam::create(+ vm,+ context.clone(),+ None,+ 0.,+ f32::MIN,+ f32::MAX,+ AutomationRate::ARate,+ FixedAutomationRate::No,+ ),+ forward_z: AudioParam::create(+ vm,+ context.clone(),+ None,+ -1.,+ f32::MIN,+ f32::MAX,+ AutomationRate::ARate,+ FixedAutomationRate::No,+ ),+ position_x: AudioParam::create(+ vm,+ context.clone(),+ None,+ 0.,+ f32::MIN,+ f32::MAX,+ AutomationRate::ARate,+ FixedAutomationRate::No,+ ),+ position_y: AudioParam::create(+ vm,+ context.clone(),+ None,+ 0.,+ f32::MIN,+ f32::MAX,+ AutomationRate::ARate,+ FixedAutomationRate::No,+ ),+ position_z: AudioParam::create(+ vm,+ context.clone(),+ None,+ 0.,+ f32::MIN,+ f32::MAX,+ AutomationRate::ARate,+ FixedAutomationRate::No,+ ),+ up_x: AudioParam::create(+ vm,+ context.clone(),+ None,+ 0.,+ f32::MIN,+ f32::MAX,+ AutomationRate::ARate,+ FixedAutomationRate::No,+ ),+ up_y: AudioParam::create(+ vm,+ context.clone(),+ None,+ 1.,+ f32::MIN,+ f32::MAX,+ AutomationRate::ARate,+ FixedAutomationRate::No,+ ),+ up_z: AudioParam::create(+ vm,+ context.clone(),+ None,+ 0.,+ f32::MIN,+ f32::MAX,+ AutomationRate::ARate,+ FixedAutomationRate::No,+ ),+ })+ }++ pub(crate) fn forward_x(&self, _: &mut CallContext) -> WebIdlResult<Ref<AudioParam>> {+ Ok(self.forward_x)+ }++ pub(crate) fn forward_y(&self, _: &mut CallContext) -> WebIdlResult<Ref<AudioParam>> {+ Ok(self.forward_y)+ }++ pub(crate) fn forward_z(&self, _: &mut CallContext) -> WebIdlResult<Ref<AudioParam>> {+ Ok(self.forward_z)+ }++ pub(crate) fn position_x(&self, _: &mut CallContext) -> WebIdlResult<Ref<AudioParam>> {+ Ok(self.position_x)+ }++ pub(crate) fn position_y(&self, _: &mut CallContext) -> WebIdlResult<Ref<AudioParam>> {+ Ok(self.position_y)+ }++ pub(crate) fn position_z(&self, _: &mut CallContext) -> WebIdlResult<Ref<AudioParam>> {+ Ok(self.position_z)+ }++ pub(crate) fn up_x(&self, _: &mut CallContext) -> WebIdlResult<Ref<AudioParam>> {+ Ok(self.up_x)+ }++ pub(crate) fn up_y(&self, _: &mut CallContext) -> WebIdlResult<Ref<AudioParam>> {+ Ok(self.up_y)+ }++ pub(crate) fn up_z(&self, _: &mut CallContext) -> WebIdlResult<Ref<AudioParam>> {+ Ok(self.up_z)+ }++ // https://webaudio.github.io/web-audio-api/#dom-audiolistener-setposition+ pub(crate) fn set_position(&self, cx: &mut CallContext, x: f32, y: f32, z: f32) -> WebIdlResult<()> {+ // This method is DEPRECATED. It is equivalent to setting positionX.value, positionY.value, and+ // positionZ.value directly with the given x, y, and z values, respectively.++ // Consequently, if any of the positionX, positionY, and positionZ AudioParams for this AudioListener have an+ // automation curve set using setValueCurveAtTime() at the time this method is called, a NotSupportedError MUST be+ // thrown.++ AudioParam::set_value(&self.position_x, cx, x)?;+ AudioParam::set_value(&self.position_y, cx, y)?;+ AudioParam::set_value(&self.position_z, cx, z)?;+ Ok(())+ }++ // https://webaudio.github.io/web-audio-api/#dom-audiolistener-setorientation+ #[allow(clippy::too_many_arguments, reason = "the IDL operation has these arguments")]+ pub(crate) fn set_orientation(+ &self,+ cx: &mut CallContext,+ x: f32,+ y: f32,+ z: f32,+ x_up: f32,+ y_up: f32,+ z_up: f32,+ ) -> WebIdlResult<()> {+ // This method is DEPRECATED. It is equivalent to setting forwardX.value, forwardY.value,+ // forwardZ.value, upX.value, upY.value, and upZ.value directly with the given x, y, z, xUp,+ // yUp, and zUp values, respectively.++ // Consequently, if any of the forwardX, forwardY, forwardZ, upX, upY and upZ AudioParams have an automation curve+ // set using setValueCurveAtTime() at the time this method is called, a NotSupportedError MUST be thrown.++ AudioParam::set_value(&self.forward_x, cx, x)?;+ AudioParam::set_value(&self.forward_y, cx, y)?;+ AudioParam::set_value(&self.forward_z, cx, z)?;+ AudioParam::set_value(&self.up_x, cx, x_up)?;+ AudioParam::set_value(&self.up_y, cx, y_up)?;+ AudioParam::set_value(&self.up_z, cx, z_up)?;+ Ok(())+ }+}++#[unsafe(no_mangle)]+pub(crate) unsafe extern "C" fn web_rust_audio_listener_create(vm: &Vm, context: *mut c_void) -> *mut c_void {+ cell_into_abi(AudioListener::create(vm, unsafe { CppCell::from_raw(context) }))+}++#[unsafe(no_mangle)]+pub(crate) unsafe extern "C" fn web_rust_audio_listener_param(cell: *mut c_void, index: usize) -> *mut c_void {+ let listener: Ref<AudioListener> = unsafe { cell_from_abi(cell) };+ let param = match index {+ 0 => listener.forward_x,+ 1 => listener.forward_y,+ 2 => listener.forward_z,+ 3 => listener.position_x,+ 4 => listener.position_y,+ 5 => listener.position_z,+ 6 => listener.up_x,+ 7 => listener.up_y,+ 8 => listener.up_z,+ _ => unreachable!(),+ };+ cell_into_abi(param)+}diff --git a/Libraries/LibWeb/Bindings/Rust/src/web_audio/audio_param.rs b/Libraries/LibWeb/Bindings/Rust/src/web_audio/audio_param.rsnew file mode 100644index 00000000000..e76e44cb8e4--- /dev/null+++ b/Libraries/LibWeb/Bindings/Rust/src/web_audio/audio_param.rs@@ -0,0 +1,427 @@+/*+ * Copyright (c) 2024, Shannon Booth <[email protected]>+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++use std::cell::Cell;+use std::ffi::c_void;+use std::ptr::NonNull;+use std::sync::Arc;++use ak::Utf16String;+use libjs_rust::api::{Gc, RawNativeFunctionResult, Realm, Trace, Value, Vm};+use libweb_rust::web_audio::audio_param_timeline::{AudioParamTimeline, InsertResult};+use libweb_rust::web_audio::rendering::render_node::RenderAudioParam;++use crate::bindings::cpp_cell::CppCell;+use crate::bindings::interface::{Ref, Wrappable, allocate, cell_from_abi, cell_into_abi, realm_arguments};+use crate::bindings::{CallContext, Exception, WebIdlResult};++pub(crate) use libweb_rust::web_audio::rendering::render_node::AutomationRate;++#[derive(Clone, Copy, PartialEq, Eq)]+#[repr(u8)]+pub(crate) enum FixedAutomationRate {+ No,+ Yes,+}++// https://webaudio.github.io/web-audio-api/#AudioParam+#[derive(Trace)]+#[gc(crate = libjs_rust)]+pub(crate) struct AudioParam {+ context: CppCell,+ owner: Option<CppCell>,+ #[gc(untraced)]+ timeline: Arc<AudioParamTimeline>,+ #[gc(untraced)]+ render_param: Arc<RenderAudioParam>,++ // https://webaudio.github.io/web-audio-api/#dom-audioparam-current-value-slot+ current_value: Cell<f32>, // [[current value]]+ default_value: f32,+ min_value: f32,+ max_value: f32,+ #[gc(untraced)]+ automation_rate: Cell<AutomationRate>,+ #[gc(untraced)]+ fixed_automation_rate: FixedAutomationRate,+}++impl Wrappable for AudioParam {}+unsafe extern "C" {+ fn web_audio_context_current_time(context: *mut c_void) -> f64;+ fn web_audio_context_realm(context: *mut c_void) -> *mut c_void;+}++fn clamp(value: f32, min: f32, max: f32) -> f32 {+ assert!(max >= min);+ if value > max {+ return max;+ }+ if value < min {+ return min;+ }+ value+}++fn max(a: f64, b: f64) -> f64 {+ if a < b { b } else { a }+}++impl AudioParam {+ // The owner is the AudioNode this parameter belongs to, or null for AudioListener parameters.+ #[allow(clippy::too_many_arguments, reason = "preserve the C++ parameter initialization")]+ pub(crate) fn create(+ vm: &Vm,+ context: CppCell,+ owner: Option<CppCell>,+ default_value: f32,+ min_value: f32,+ max_value: f32,+ automation_rate: AutomationRate,+ fixed_automation_rate: FixedAutomationRate,+ ) -> Ref<Self> {+ allocate(vm, |_| {+ let timeline = Arc::new(AudioParamTimeline::new(default_value));+ let render_param = Arc::new(RenderAudioParam::new(+ Arc::clone(&timeline),+ min_value,+ max_value,+ automation_rate,+ ));+ Self {+ context,+ owner,+ timeline,+ render_param,+ current_value: Cell::new(default_value),+ default_value,+ min_value,+ max_value,+ automation_rate: Cell::new(automation_rate),+ fixed_automation_rate,+ }+ })+ }++ fn current_time(&self) -> f64 {+ unsafe { web_audio_context_current_time(self.context.as_ptr()) }+ }++ fn context_error(&self, vm: &Vm, name: &'static str, message: &[u8]) -> Exception {+ let realm = unsafe {+ Gc::from_non_null(NonNull::new(web_audio_context_realm(self.context.as_ptr()).cast::<Realm>()).unwrap())+ };+ Exception::Thrown(Exception::Dom(name, Utf16String::from_ascii(message)).throw(&CallContext::new(vm, realm)))+ }++ // https://webaudio.github.io/web-audio-api/#dom-audioparam-value+ // https://webaudio.github.io/web-audio-api/#simple-nominal-range+ pub(crate) fn value(&self, _: &mut CallContext) -> WebIdlResult<f32> {+ // Each AudioParam includes minValue and maxValue attributes that together form the simple nominal range+ // for the parameter. In effect, value of the parameter is clamped to the range [minValue, maxValue].+ if self.timeline.has_events() {+ return Ok(clamp(+ self.timeline.value_at_time(self.current_time()),+ self.min_value,+ self.max_value,+ ));+ }+ Ok(clamp(self.current_value.get(), self.min_value, self.max_value))+ }++ // https://webaudio.github.io/web-audio-api/#dom-audioparam-value+ pub(crate) fn set_value(this: &Ref<Self>, cx: &mut CallContext, value: f32) -> WebIdlResult<()> {+ // Setting this attribute has the effect of assigning the requested value to the [[current value]] slot, and calling+ // the setValueAtTime() method with the current AudioContext's currentTime and [[current value]].+ this.current_value.set(value);+ Self::set_value_at_time(this, cx, this.current_value.get(), this.current_time())?;+ Ok(())+ }++ // https://webaudio.github.io/web-audio-api/#computedvalue+ pub(crate) fn intrinsic_value_at_time(&self, time: f64) -> f32 {+ self.timeline.value_at_time(time)+ }++ // https://webaudio.github.io/web-audio-api/#dom-audioparam-automationrate+ pub(crate) fn automation_rate(&self, _: &mut CallContext) -> WebIdlResult<AutomationRate> {+ Ok(self.automation_rate.get())+ }++ // https://webaudio.github.io/web-audio-api/#dom-audioparam-automationrate+ pub(crate) fn set_automation_rate(&self, _: &mut CallContext, automation_rate: AutomationRate) -> WebIdlResult<()> {+ if automation_rate != self.automation_rate.get() && self.fixed_automation_rate == FixedAutomationRate::Yes {+ return Err(Exception::Dom(+ "InvalidStateError",+ Utf16String::from_ascii(b"Automation rate cannot be changed"),+ ));+ }+ self.automation_rate.set(automation_rate);+ self.render_param.set_automation_rate(automation_rate);+ Ok(())+ }++ // https://webaudio.github.io/web-audio-api/#dom-audioparam-defaultvalue+ pub(crate) fn default_value(&self, _: &mut CallContext) -> WebIdlResult<f32> {+ Ok(self.default_value)+ }++ // https://webaudio.github.io/web-audio-api/#dom-audioparam-minvalue+ pub(crate) fn min_value(&self, _: &mut CallContext) -> WebIdlResult<f32> {+ Ok(self.min_value)+ }++ // https://webaudio.github.io/web-audio-api/#dom-audioparam-maxvalue+ pub(crate) fn max_value(&self, _: &mut CallContext) -> WebIdlResult<f32> {+ Ok(self.max_value)+ }++ fn map_insert_result(&self, vm: &Vm, result: InsertResult) -> WebIdlResult<()> {+ match result {+ InsertResult::Success => Ok(()),+ InsertResult::EventContainedInValueCurve => Err(self.context_error(+ vm,+ "NotSupportedError",+ b"Cannot schedule an automation event during a value curve",+ )),+ InsertResult::ValueCurveOverlapsEvent => Err(self.context_error(+ vm,+ "NotSupportedError",+ b"Cannot schedule a value curve containing an automation event",+ )),+ }+ }++ // https://webaudio.github.io/web-audio-api/#dom-audioparam-setvalueattime+ pub(crate) fn set_value_at_time(+ this: &Ref<Self>,+ cx: &mut CallContext,+ value: f32,+ mut start_time: f64,+ ) -> WebIdlResult<Ref<Self>> {+ // A RangeError exception MUST be thrown if startTime is negative or is not a finite number.+ if start_time < 0. {+ return Err(Exception::range_error("startTime must not be negative"));+ }++ // If startTime is less than currentTime, it is clamped to currentTime.+ start_time = max(start_time, this.current_time());+ this.map_insert_result(cx.vm(), this.timeline.set_value_at_time(value, start_time))?;+ Ok(*this)+ }++ // https://webaudio.github.io/web-audio-api/#dom-audioparam-linearramptovalueattime+ pub(crate) fn linear_ramp_to_value_at_time(+ this: &Ref<Self>,+ cx: &mut CallContext,+ value: f32,+ mut end_time: f64,+ ) -> WebIdlResult<Ref<Self>> {+ // A RangeError exception MUST be thrown if endTime is negative or is not a finite number.+ if end_time < 0. {+ return Err(Exception::range_error("endTime must not be negative"));+ }++ // If endTime is less than currentTime, it is clamped to currentTime.+ let current_time = this.current_time();+ end_time = max(end_time, current_time);+ this.map_insert_result(+ cx.vm(),+ this.timeline+ .linear_ramp_to_value_at_time(value, end_time, current_time, this.current_value.get()),+ )?;+ Ok(*this)+ }++ // https://webaudio.github.io/web-audio-api/#dom-audioparam-exponentialramptovalueattime+ pub(crate) fn exponential_ramp_to_value_at_time(+ this: &Ref<Self>,+ cx: &mut CallContext,+ value: f32,+ mut end_time: f64,+ ) -> WebIdlResult<Ref<Self>> {+ // A RangeError exception MUST be thrown if value is equal to 0.+ if value == 0. {+ return Err(Exception::range_error("value must not be zero"));+ }++ // A RangeError exception MUST be thrown if endTime is negative or is not a finite number.+ if end_time < 0. {+ return Err(Exception::range_error("endTime must not be negative"));+ }++ // If endTime is less than currentTime, it is clamped to currentTime.+ let current_time = this.current_time();+ end_time = max(end_time, current_time);+ this.map_insert_result(+ cx.vm(),+ this.timeline+ .exponential_ramp_to_value_at_time(value, end_time, current_time, this.current_value.get()),+ )?;+ Ok(*this)+ }++ // https://webaudio.github.io/web-audio-api/#dom-audioparam-settargetattime+ pub(crate) fn set_target_at_time(+ this: &Ref<Self>,+ cx: &mut CallContext,+ target: f32,+ mut start_time: f64,+ time_constant: f32,+ ) -> WebIdlResult<Ref<Self>> {+ // A RangeError exception MUST be thrown if startTime is negative or is not a finite number.+ if start_time < 0. {+ return Err(Exception::range_error("startTime must not be negative"));+ }++ // A RangeError exception MUST be thrown if timeConstant is negative or is not a finite number.+ if time_constant < 0. {+ return Err(Exception::range_error("timeConstant must not be negative"));+ }++ // If startTime is less than currentTime, it is clamped to currentTime.+ start_time = max(start_time, this.current_time());+ this.map_insert_result(+ cx.vm(),+ this.timeline.set_target_at_time(target, start_time, time_constant),+ )?;+ Ok(*this)+ }++ // https://webaudio.github.io/web-audio-api/#dom-audioparam-setvaluecurveattime+ #[allow(+ clippy::redundant_clone,+ reason = "the C++ operation copies its borrowed sequence into the timeline"+ )]+ pub(crate) fn set_value_curve_at_time(+ this: &Ref<Self>,+ cx: &mut CallContext,+ values: Vec<f32>,+ mut start_time: f64,+ duration: f64,+ ) -> WebIdlResult<Ref<Self>> {+ // An InvalidStateError exception MUST be thrown if values has a length less than 2.+ if values.len() < 2 {+ return Err(this.context_error(+ cx.vm(),+ "InvalidStateError",+ b"values must contain at least two elements",+ ));+ }++ // A RangeError exception MUST be thrown if startTime is negative or is not a finite number.+ if start_time < 0. {+ return Err(Exception::range_error("startTime must not be negative"));+ }++ // A RangeError exception MUST be thrown if duration is not strictly positive or is not a finite number.+ if duration <= 0. {+ return Err(Exception::range_error("duration must be positive"));+ }++ // If startTime is less than currentTime, it is clamped to currentTime.+ start_time = max(start_time, this.current_time());+ this.map_insert_result(+ cx.vm(),+ this.timeline+ .set_value_curve_at_time(values.clone(), start_time, duration),+ )?;+ Ok(*this)+ }++ // https://webaudio.github.io/web-audio-api/#dom-audioparam-cancelscheduledvalues+ pub(crate) fn cancel_scheduled_values(+ this: &Ref<Self>,+ _: &mut CallContext,+ mut cancel_time: f64,+ ) -> WebIdlResult<Ref<Self>> {+ // A RangeError exception MUST be thrown if cancelTime is negative.+ if cancel_time < 0. {+ return Err(Exception::range_error("cancelTime must not be negative"));+ }++ // If cancelTime is less than currentTime, it is clamped to currentTime.+ cancel_time = max(cancel_time, this.current_time());+ this.timeline.cancel_scheduled_values(cancel_time);+ Ok(*this)+ }++ // https://webaudio.github.io/web-audio-api/#dom-audioparam-cancelandholdattime+ pub(crate) fn cancel_and_hold_at_time(+ this: &Ref<Self>,+ _: &mut CallContext,+ mut cancel_time: f64,+ ) -> WebIdlResult<Ref<Self>> {+ // A RangeError exception MUST be thrown if cancelTime is negative.+ if cancel_time < 0. {+ return Err(Exception::range_error("cancelTime must not be negative"));+ }++ // If cancelTime is less than currentTime, it is clamped to currentTime.+ cancel_time = max(cancel_time, this.current_time());+ this.timeline.cancel_and_hold_at_time(cancel_time);+ Ok(*this)+ }+}++#[unsafe(no_mangle)]+pub(crate) unsafe extern "C" fn web_rust_audio_param_create(+ vm: &Vm,+ context: *mut c_void,+ owner: *mut c_void,+ default_value: f32,+ min_value: f32,+ max_value: f32,+ automation_rate: AutomationRate,+ fixed: FixedAutomationRate,+) -> *mut c_void {+ cell_into_abi(AudioParam::create(+ vm,+ unsafe { CppCell::from_raw(context) },+ (!owner.is_null()).then(|| unsafe { CppCell::from_raw(owner) }),+ default_value,+ min_value,+ max_value,+ automation_rate,+ fixed,+ ))+}++#[unsafe(no_mangle)]+pub(crate) unsafe extern "C" fn web_rust_audio_param_context(cell: *mut c_void) -> *mut c_void {+ let param: Ref<AudioParam> = unsafe { cell_from_abi(cell) };+ param.context.as_ptr()+}++#[unsafe(no_mangle)]+pub(crate) unsafe extern "C" fn web_rust_audio_param_set_value(+ vm: *mut c_void,+ realm: *mut c_void,+ cell: *mut c_void,+ value: f32,+) -> RawNativeFunctionResult {+ let (vm, realm) = unsafe { realm_arguments(vm, realm) };+ let mut cx = CallContext::new(vm, realm);+ let param: Ref<AudioParam> = unsafe { cell_from_abi(cell) };+ RawNativeFunctionResult::from_completion(+ AudioParam::set_value(¶m, &mut cx, value)+ .map(|()| Value::UNDEFINED)+ .map_err(|error| error.throw(&cx)),+ )+}++#[unsafe(no_mangle)]+pub(crate) unsafe extern "C" fn web_rust_audio_param_intrinsic_value(cell: *mut c_void, time: f64) -> f32 {+ let param: Ref<AudioParam> = unsafe { cell_from_abi(cell) };+ param.intrinsic_value_at_time(time)+}++#[unsafe(no_mangle)]+pub(crate) unsafe extern "C" fn web_rust_audio_param_render_param(cell: *mut c_void) -> *const RenderAudioParam {+ let param: Ref<AudioParam> = unsafe { cell_from_abi(cell) };+ Arc::into_raw(Arc::clone(¶m.render_param))+}diff --git a/Libraries/LibWeb/Bindings/Rust/src/web_audio/audio_param_map.rs b/Libraries/LibWeb/Bindings/Rust/src/web_audio/audio_param_map.rsnew file mode 100644index 00000000000..ab2f4af9f80--- /dev/null+++ b/Libraries/LibWeb/Bindings/Rust/src/web_audio/audio_param_map.rs@@ -0,0 +1,108 @@+/*+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++use std::ffi::c_void;++use ak::Utf16String;+use libjs_rust::api::{Gc, GcRefCell, Map, Trace, Value, Vm};++use super::audio_param::AudioParam;+use crate::bindings::CallContext;+use crate::bindings::conversions::{ToJs, to_dom_string};+use crate::bindings::interface::{Ref, Wrappable, allocate, cell_from_abi, cell_into_abi, this_implementation, wrap};+use crate::bindings::maplike::Maplike;++// https://webaudio.github.io/web-audio-api/#AudioParamMap+#[derive(Trace)]+#[gc(crate = libjs_rust)]+pub(crate) struct AudioParamMap {+ entries: GcRefCell<Vec<(Utf16String, Ref<AudioParam>)>>,+}++impl Wrappable for AudioParamMap {}+impl AudioParamMap {+ pub(crate) fn create(vm: &Vm) -> Ref<Self> {+ allocate(vm, |_| Self {+ entries: GcRefCell::new(Vec::new()),+ })+ }++ pub(crate) fn set_entry(&self, vm: &Vm, key: Utf16String, value: Ref<AudioParam>) {+ let mut entries = self.entries.borrow_mut(vm);+ if let Some(entry) = entries.iter_mut().find(|entry| entry.0 == key) {+ entry.1 = value;+ } else {+ entries.push((key, value));+ }+ }+}++impl Maplike for AudioParamMap {+ // https://webidl.spec.whatwg.org/#js-map-has+ fn has(vm: &Vm) -> libjs_rust::api::ThrowCompletionOr<Value> {+ // 1. Let O be the this value, implementation-checked against A with identifier "has" and type "method".+ let (_, implementation, _cx) = this_implementation::<Self>(vm)?;++ // 2. Let map be the map entries of the IDL value that represents a reference to O.+ let map = &implementation.entries;++ // 3. Let keyType be the key type specified in the maplike declaration.+ // 4. Let key be keyArg converted to an IDL value of type keyType.+ let key = to_dom_string(vm, vm.argument(0))?;++ // 5. If key is -0, set key to +0.+ // NB: DOMString conversion cannot produce a numeric -0 key.+ // 6. If map[key] exists, then return true; otherwise return false.+ Ok(Value::from_bool(map.borrow().iter().any(|entry| entry.0 == key)))+ }++ fn map_entries(&self, cx: &CallContext) -> Gc<Map> {+ let map_entries = Map::create(cx.vm(), cx.realm());+ for (key, value) in &*self.entries.borrow() {+ let key = key.clone().to_js(cx).expect("a string converts to a JS value");+ let value = Value::from_object(wrap(cx, *value));+ map_entries.map_set(cx.vm(), key, value);+ }+ map_entries+ }++ fn map_value(&self, cx: &CallContext, key: &Utf16String) -> Option<Value> {+ let entries = self.entries.borrow();+ let entry = entries.iter().find(|entry| &entry.0 == key)?;+ Some(Value::from_object(wrap(cx, entry.1)))+ }+}++#[unsafe(no_mangle)]+pub(crate) unsafe extern "C" fn web_rust_audio_param_map_create(vm: &Vm) -> *mut c_void {+ cell_into_abi(AudioParamMap::create(vm))+}++#[unsafe(no_mangle)]+pub(crate) unsafe extern "C" fn web_rust_audio_param_map_set_entry(+ vm: &Vm,+ cell: *mut c_void,+ key: usize,+ param: *mut c_void,+) {+ let map: Ref<AudioParamMap> = unsafe { cell_from_abi(cell) };+ let param: Ref<AudioParam> = unsafe { cell_from_abi(param) };+ map.set_entry(vm, unsafe { ak::Utf16FlyString::from_raw_borrowed(key).into() }, param);+}++#[unsafe(no_mangle)]+pub(crate) unsafe extern "C" fn web_rust_audio_param_map_values(+ cell: *mut c_void,+ context: *mut c_void,+ callback: unsafe extern "C" fn(*mut c_void, *mut c_void),+) {+ let map: Ref<AudioParamMap> = unsafe { cell_from_abi(cell) };+ for (_key, value) in &*map.entries.borrow() {+ unsafe {+ callback(context, cell_into_abi(*value));+ }+ }+}diff --git a/Libraries/LibWeb/Bindings/Rust/src/web_audio/mod.rs b/Libraries/LibWeb/Bindings/Rust/src/web_audio/mod.rsindex 62bb0fe3200..04c435c6494 100644--- a/Libraries/LibWeb/Bindings/Rust/src/web_audio/mod.rs+++ b/Libraries/LibWeb/Bindings/Rust/src/web_audio/mod.rs@@ -5,4 +5,7 @@*/pub(crate) mod audio_buffer;+pub(crate) mod audio_listener;+pub(crate) mod audio_param;+pub(crate) mod audio_param_map;pub(crate) mod periodic_wave;diff --git a/Libraries/LibWeb/Rust/src/web_audio/rendering/render_node.rs b/Libraries/LibWeb/Rust/src/web_audio/rendering/render_node.rsindex 35a19698904..af5f6fe3d19 100644--- a/Libraries/LibWeb/Rust/src/web_audio/rendering/render_node.rs+++ b/Libraries/LibWeb/Rust/src/web_audio/rendering/render_node.rs@@ -78,7 +78,7 @@ struct ForeignRenderGraph {}impl RenderAudioParam {- pub(crate) fn new(+ pub fn new(timeline: Arc<AudioParamTimeline>,min_value: f32,max_value: f32,@@ -96,7 +96,7 @@ impl RenderAudioParam {}}- fn set_automation_rate(&self, automation_rate: AutomationRate) {+ pub fn set_automation_rate(&self, automation_rate: AutomationRate) {self.automation_rate.store(automation_rate as u8, Ordering::SeqCst);}diff --git a/Libraries/LibWeb/WebAudio/AudioListener.cpp b/Libraries/LibWeb/WebAudio/AudioListener.cppindex 48184fcc5c7..393a50246dd 100644--- a/Libraries/LibWeb/WebAudio/AudioListener.cpp+++ b/Libraries/LibWeb/WebAudio/AudioListener.cpp@@ -1,86 +1,33 @@/** Copyright (c) 2024, Jelle Raaijmakers <[email protected]>+ * Copyright (c) 2026-present, the Ladybird developers.** SPDX-License-Identifier: BSD-2-Clause*/-#include <LibGC/CellAllocator.h>-#include <LibGC/Heap.h>+#include <LibJS/HostClassBuilder.h>+#include <LibJS/Runtime/VM.h>#include <LibWeb/WebAudio/AudioListener.h>+#include <LibWeb/WebAudio/BaseAudioContext.h>namespace Web::WebAudio {-GC_DEFINE_ALLOCATOR(AudioListener);--AudioListener::AudioListener(GC::Ref<BaseAudioContext> context)- : m_forward_x(AudioParam::create(context, nullptr, 0.f, NumericLimits<float>::lowest(), NumericLimits<float>::max(), AutomationRate::ARate))- , m_forward_y(AudioParam::create(context, nullptr, 0.f, NumericLimits<float>::lowest(), NumericLimits<float>::max(), AutomationRate::ARate))- , m_forward_z(AudioParam::create(context, nullptr, -1.f, NumericLimits<float>::lowest(), NumericLimits<float>::max(), AutomationRate::ARate))- , m_position_x(AudioParam::create(context, nullptr, 0.f, NumericLimits<float>::lowest(), NumericLimits<float>::max(), AutomationRate::ARate))- , m_position_y(AudioParam::create(context, nullptr, 0.f, NumericLimits<float>::lowest(), NumericLimits<float>::max(), AutomationRate::ARate))- , m_position_z(AudioParam::create(context, nullptr, 0.f, NumericLimits<float>::lowest(), NumericLimits<float>::max(), AutomationRate::ARate))- , m_up_x(AudioParam::create(context, nullptr, 0.f, NumericLimits<float>::lowest(), NumericLimits<float>::max(), AutomationRate::ARate))- , m_up_y(AudioParam::create(context, nullptr, 1.f, NumericLimits<float>::lowest(), NumericLimits<float>::max(), AutomationRate::ARate))- , m_up_z(AudioParam::create(context, nullptr, 0.f, NumericLimits<float>::lowest(), NumericLimits<float>::max(), AutomationRate::ARate))-{+extern "C" {+void* web_rust_audio_listener_create(JSVM*, void* context);+void* web_rust_audio_listener_param(void*, size_t index);}-GC::Ref<AudioListener> AudioListener::create(GC::Ref<BaseAudioContext> context){- return GC::Heap::the().allocate<AudioListener>(context);-}--AudioListener::~AudioListener() = default;--// https://webaudio.github.io/web-audio-api/#dom-audiolistener-setposition-WebIDL::ExceptionOr<void> AudioListener::set_position(float x, float y, float z)-{- // This method is DEPRECATED. It is equivalent to setting positionX.value, positionY.value, and- // positionZ.value directly with the given x, y, and z values, respectively.-- // Consequently, if any of the positionX, positionY, and positionZ AudioParams for this AudioListener have an- // automation curve set using setValueCurveAtTime() at the time this method is called, a NotSupportedError MUST be- // thrown.-- TRY(m_position_x->set_value(x));- TRY(m_position_y->set_value(y));- TRY(m_position_z->set_value(z));-- return {};-}--// https://webaudio.github.io/web-audio-api/#dom-audiolistener-setorientation-WebIDL::ExceptionOr<void> AudioListener::set_orientation(float x, float y, float z, float x_up, float y_up, float z_up)-{- // This method is DEPRECATED. It is equivalent to setting forwardX.value, forwardY.value,- // forwardZ.value, upX.value, upY.value, and upZ.value directly with the given x, y, z, xUp,- // yUp, and zUp values, respectively.-- // Consequently, if any of the forwardX, forwardY, forwardZ, upX, upY and upZ AudioParams have an automation curve- // set using setValueCurveAtTime() at the time this method is called, a NotSupportedError MUST be thrown.-- TRY(m_forward_x->set_value(x));- TRY(m_forward_y->set_value(y));- TRY(m_forward_z->set_value(z));- TRY(m_up_x->set_value(x_up));- TRY(m_up_y->set_value(y_up));- TRY(m_up_z->set_value(z_up));-- return {};-}--void AudioListener::visit_edges(GC::Cell::Visitor& visitor)-{- Base::visit_edges(visitor);- visitor.visit(m_forward_x);- visitor.visit(m_forward_y);- visitor.visit(m_forward_z);- visitor.visit(m_position_x);- visitor.visit(m_position_y);- visitor.visit(m_position_z);- visitor.visit(m_up_x);- visitor.visit(m_up_y);- visitor.visit(m_up_z);+ return *static_cast<AudioListener*>(web_rust_audio_listener_create(JS::HostABI::vm_to_abi(JS::VM::the()), context.ptr()));}+GC::Ref<AudioParam> AudioListener::forward_x() const { return *static_cast<AudioParam*>(web_rust_audio_listener_param(const_cast<AudioListener*>(this), 0)); }+GC::Ref<AudioParam> AudioListener::forward_y() const { return *static_cast<AudioParam*>(web_rust_audio_listener_param(const_cast<AudioListener*>(this), 1)); }+GC::Ref<AudioParam> AudioListener::forward_z() const { return *static_cast<AudioParam*>(web_rust_audio_listener_param(const_cast<AudioListener*>(this), 2)); }+GC::Ref<AudioParam> AudioListener::position_x() const { return *static_cast<AudioParam*>(web_rust_audio_listener_param(const_cast<AudioListener*>(this), 3)); }+GC::Ref<AudioParam> AudioListener::position_y() const { return *static_cast<AudioParam*>(web_rust_audio_listener_param(const_cast<AudioListener*>(this), 4)); }+GC::Ref<AudioParam> AudioListener::position_z() const { return *static_cast<AudioParam*>(web_rust_audio_listener_param(const_cast<AudioListener*>(this), 5)); }+GC::Ref<AudioParam> AudioListener::up_x() const { return *static_cast<AudioParam*>(web_rust_audio_listener_param(const_cast<AudioListener*>(this), 6)); }+GC::Ref<AudioParam> AudioListener::up_y() const { return *static_cast<AudioParam*>(web_rust_audio_listener_param(const_cast<AudioListener*>(this), 7)); }+GC::Ref<AudioParam> AudioListener::up_z() const { return *static_cast<AudioParam*>(web_rust_audio_listener_param(const_cast<AudioListener*>(this), 8)); }}diff --git a/Libraries/LibWeb/WebAudio/AudioListener.h b/Libraries/LibWeb/WebAudio/AudioListener.hindex 9dad5066c4c..58fde1964ac 100644--- a/Libraries/LibWeb/WebAudio/AudioListener.h+++ b/Libraries/LibWeb/WebAudio/AudioListener.h@@ -1,64 +1,32 @@/** Copyright (c) 2024, Jelle Raaijmakers <[email protected]>+ * Copyright (c) 2026-present, the Ladybird developers.** SPDX-License-Identifier: BSD-2-Clause*/#pragma once-#include <LibJS/Forward.h>-#include <LibWeb/Bindings/Wrappable.h>-#include <LibWeb/Export.h>+#include <LibWeb/Bindings/AudioListener.h>+#include <LibWeb/Bindings/RustInterface.h>#include <LibWeb/WebAudio/AudioParam.h>-#include <LibWeb/WebIDL/ExceptionOr.h>namespace Web::WebAudio {-// https://webaudio.github.io/web-audio-api/#AudioListener-class AudioListener final : public Bindings::GCAllocatedWrappable {- WEB_WRAPPABLE(AudioListener, Bindings::GCAllocatedWrappable);- GC_DECLARE_ALLOCATOR(AudioListener);+class AudioListener final : public Bindings::RustInterfaceCell {+ WEB_RUST_INTERFACE(AudioListener, audio_listener)public:- static constexpr size_t position_x_offset() { return offsetof(AudioListener, m_position_x); }- static constexpr size_t position_y_offset() { return offsetof(AudioListener, m_position_y); }- static constexpr size_t position_z_offset() { return offsetof(AudioListener, m_position_z); }- static constexpr size_t forward_x_offset() { return offsetof(AudioListener, m_forward_x); }- static constexpr size_t forward_y_offset() { return offsetof(AudioListener, m_forward_y); }- static constexpr size_t forward_z_offset() { return offsetof(AudioListener, m_forward_z); }- static constexpr size_t up_x_offset() { return offsetof(AudioListener, m_up_x); }- static constexpr size_t up_y_offset() { return offsetof(AudioListener, m_up_y); }- static constexpr size_t up_z_offset() { return offsetof(AudioListener, m_up_z); }static GC::Ref<AudioListener> create(GC::Ref<BaseAudioContext>);- virtual ~AudioListener() override;-- GC::Ref<AudioParam> forward_x() const { return m_forward_x; }- GC::Ref<AudioParam> forward_y() const { return m_forward_y; }- GC::Ref<AudioParam> forward_z() const { return m_forward_z; }- GC::Ref<AudioParam> position_x() const { return m_position_x; }- GC::Ref<AudioParam> position_y() const { return m_position_y; }- GC::Ref<AudioParam> position_z() const { return m_position_z; }- GC::Ref<AudioParam> up_x() const { return m_up_x; }- GC::Ref<AudioParam> up_y() const { return m_up_y; }- GC::Ref<AudioParam> up_z() const { return m_up_z; }-- WebIDL::ExceptionOr<void> set_position(float x, float y, float z);- WebIDL::ExceptionOr<void> set_orientation(float x, float y, float z, float x_up, float y_up, float z_up);--private:- explicit AudioListener(GC::Ref<BaseAudioContext>);-- virtual void visit_edges(GC::Cell::Visitor&) override;-- GC::Ref<AudioParam> m_forward_x;- GC::Ref<AudioParam> m_forward_y;- GC::Ref<AudioParam> m_forward_z;- GC::Ref<AudioParam> m_position_x;- GC::Ref<AudioParam> m_position_y;- GC::Ref<AudioParam> m_position_z;- GC::Ref<AudioParam> m_up_x;- GC::Ref<AudioParam> m_up_y;- GC::Ref<AudioParam> m_up_z;+ GC::Ref<AudioParam> forward_x() const;+ GC::Ref<AudioParam> forward_y() const;+ GC::Ref<AudioParam> forward_z() const;+ GC::Ref<AudioParam> position_x() const;+ GC::Ref<AudioParam> position_y() const;+ GC::Ref<AudioParam> position_z() const;+ GC::Ref<AudioParam> up_x() const;+ GC::Ref<AudioParam> up_y() const;+ GC::Ref<AudioParam> up_z() const;};}diff --git a/Libraries/LibWeb/WebAudio/AudioListener.idl b/Libraries/LibWeb/WebAudio/AudioListener.idlindex a0df52c1426..2c42071dacc 100644--- a/Libraries/LibWeb/WebAudio/AudioListener.idl+++ b/Libraries/LibWeb/WebAudio/AudioListener.idl@@ -1,15 +1,15 @@// https://webaudio.github.io/web-audio-api/#AudioListener-[Exposed=Window]+[Exposed=Window, ImplementedIn=Rust]interface AudioListener {- [DirectGetter] readonly attribute AudioParam positionX;- [DirectGetter] readonly attribute AudioParam positionY;- [DirectGetter] readonly attribute AudioParam positionZ;- [DirectGetter] readonly attribute AudioParam forwardX;- [DirectGetter] readonly attribute AudioParam forwardY;- [DirectGetter] readonly attribute AudioParam forwardZ;- [DirectGetter] readonly attribute AudioParam upX;- [DirectGetter] readonly attribute AudioParam upY;- [DirectGetter] readonly attribute AudioParam upZ;+ readonly attribute AudioParam positionX;+ readonly attribute AudioParam positionY;+ readonly attribute AudioParam positionZ;+ readonly attribute AudioParam forwardX;+ readonly attribute AudioParam forwardY;+ readonly attribute AudioParam forwardZ;+ readonly attribute AudioParam upX;+ readonly attribute AudioParam upY;+ readonly attribute AudioParam upZ;undefined setPosition (float x, float y, float z);undefined setOrientation (float x, float y, float z, float xUp, float yUp, float zUp);};diff --git a/Libraries/LibWeb/WebAudio/AudioParam.cpp b/Libraries/LibWeb/WebAudio/AudioParam.cppindex c07aff5f0ae..be2405d4c25 100644--- a/Libraries/LibWeb/WebAudio/AudioParam.cpp+++ b/Libraries/LibWeb/WebAudio/AudioParam.cpp@@ -1,211 +1,39 @@/** Copyright (c) 2024, Shannon Booth <[email protected]>+ * Copyright (c) 2026-present, the Ladybird developers.** SPDX-License-Identifier: BSD-2-Clause*/-#include <LibGC/Heap.h>+#include <LibJS/HostClassBuilder.h>+#include <LibJS/Runtime/Realm.h>+#include <LibJS/Runtime/VM.h>+#include <LibWeb/WebAudio/AudioNode.h>#include <LibWeb/WebAudio/AudioParam.h>#include <LibWeb/WebAudio/BaseAudioContext.h>-#include <LibWeb/WebIDL/ExceptionOr.h>namespace Web::WebAudio {-GC_DEFINE_ALLOCATOR(AudioParam);--AudioParam::AudioParam(GC::Ref<BaseAudioContext> context, GC::Ptr<AudioNode> owner, float default_value, float min_value, float max_value, AutomationRate automation_rate, FixedAutomationRate fixed_automation_rate)- : m_context(context)- , m_owner(owner)- , m_timeline(adopt_ref(*new AudioParamTimeline(default_value)))- , m_render_param(adopt_ref(*new Rendering::RenderAudioParam(m_timeline, min_value, max_value, automation_rate)))- , m_current_value(default_value)- , m_default_value(default_value)- , m_min_value(min_value)- , m_max_value(max_value)- , m_automation_rate(automation_rate)- , m_fixed_automation_rate(fixed_automation_rate)-{-}--GC::Ref<AudioParam> AudioParam::create(GC::Ref<BaseAudioContext> context, GC::Ptr<AudioNode> owner, float default_value, float min_value, float max_value, AutomationRate automation_rate, FixedAutomationRate fixed_automation_rate)-{- return GC::Heap::the().allocate<AudioParam>(context, owner, default_value, min_value, max_value, automation_rate, fixed_automation_rate);+extern "C" {+void* web_rust_audio_param_create(JSVM*, void* context, void* owner, float default_value, float min_value, float max_value, u8 automation_rate, u8 fixed_rate);+void* web_rust_audio_param_context(void*);+JSCompletion web_rust_audio_param_set_value(JSVM*, void* realm, void* param, float value);+float web_rust_audio_param_intrinsic_value(void*, double time);+void const* web_rust_audio_param_render_param(void*);}-AudioParam::~AudioParam() = default;--// https://webaudio.github.io/web-audio-api/#dom-audioparam-value-// https://webaudio.github.io/web-audio-api/#simple-nominal-range-float AudioParam::value() const+GC::Ref<AudioParam> AudioParam::create(GC::Ref<BaseAudioContext> context, GC::Ptr<AudioNode> owner, float default_value, float min_value, float max_value, AutomationRate automation_rate, FixedAutomationRate fixed_rate){- // Each AudioParam includes minValue and maxValue attributes that together form the simple nominal range- // for the parameter. In effect, value of the parameter is clamped to the range [minValue, maxValue].- if (m_timeline->has_events())- return clamp(m_timeline->value_at_time(context()->current_time()), min_value(), max_value());- return clamp(m_current_value, min_value(), max_value());+ return *static_cast<AudioParam*>(web_rust_audio_param_create(JS::HostABI::vm_to_abi(JS::VM::the()), context.ptr(), owner.ptr(), default_value, min_value, max_value, to_underlying(automation_rate), to_underlying(fixed_rate)));}--// https://webaudio.github.io/web-audio-api/#dom-audioparam-value+GC::Ref<BaseAudioContext> AudioParam::context() const { return *static_cast<BaseAudioContext*>(web_rust_audio_param_context(const_cast<AudioParam*>(this))); }WebIDL::ExceptionOr<void> AudioParam::set_value(float value){- // Setting this attribute has the effect of assigning the requested value to the [[current value]] slot, and calling- // the setValueAtTime() method with the current AudioContext's currentTime and [[current value]].- m_current_value = value;- TRY(set_value_at_time(m_current_value, context()->current_time()));- return {};-}--// https://webaudio.github.io/web-audio-api/#dom-audioparam-automationrate-AutomationRate AudioParam::automation_rate() const-{- return m_automation_rate;-}--// https://webaudio.github.io/web-audio-api/#dom-audioparam-automationrate-WebIDL::ExceptionOr<void> AudioParam::set_automation_rate(AutomationRate automation_rate)-{- if (automation_rate != m_automation_rate && m_fixed_automation_rate == FixedAutomationRate::Yes)- return WebIDL::InvalidStateError::create("Automation rate cannot be changed"_utf16);-- m_automation_rate = automation_rate;- m_render_param->set_automation_rate(automation_rate);+ auto& vm = JS::VM::the();+ TRY(JS::HostABI::completion_from_abi<void>(web_rust_audio_param_set_value(JS::HostABI::vm_to_abi(vm), vm.current_realm(), this, value)));return {};}--WebIDL::ExceptionOr<void> AudioParam::map_insert_result(AudioParamTimeline::InsertResult result)-{- switch (result) {- case AudioParamTimeline::InsertResult::Success:- return {};- case AudioParamTimeline::InsertResult::EventContainedInValueCurve:- return WebIDL::NotSupportedError::create(context()->relevant_settings_object().realm(), "Cannot schedule an automation event during a value curve"_utf16);- case AudioParamTimeline::InsertResult::ValueCurveOverlapsEvent:- return WebIDL::NotSupportedError::create(context()->relevant_settings_object().realm(), "Cannot schedule a value curve containing an automation event"_utf16);- }- VERIFY_NOT_REACHED();-}--// https://webaudio.github.io/web-audio-api/#dom-audioparam-setvalueattime-WebIDL::ExceptionOr<GC::Ref<AudioParam>> AudioParam::set_value_at_time(float value, double start_time)-{- // A RangeError exception MUST be thrown if startTime is negative or is not a finite number.- if (start_time < 0)- return WebIDL::SimpleException { WebIDL::SimpleExceptionType::RangeError, "startTime must not be negative"_utf16 };-- // If startTime is less than currentTime, it is clamped to currentTime.- start_time = max(start_time, context()->current_time());-- TRY(map_insert_result(m_timeline->set_value_at_time(value, start_time)));- return GC::Ref { *this };-}--// https://webaudio.github.io/web-audio-api/#dom-audioparam-linearramptovalueattime-WebIDL::ExceptionOr<GC::Ref<AudioParam>> AudioParam::linear_ramp_to_value_at_time(float value, double end_time)-{- // A RangeError exception MUST be thrown if endTime is negative or is not a finite number.- if (end_time < 0)- return WebIDL::SimpleException { WebIDL::SimpleExceptionType::RangeError, "endTime must not be negative"_utf16 };-- // If endTime is less than currentTime, it is clamped to currentTime.- auto current_time = context()->current_time();- end_time = max(end_time, current_time);-- TRY(map_insert_result(m_timeline->linear_ramp_to_value_at_time(value, end_time, current_time, m_current_value)));- return GC::Ref { *this };-}--// https://webaudio.github.io/web-audio-api/#dom-audioparam-exponentialramptovalueattime-WebIDL::ExceptionOr<GC::Ref<AudioParam>> AudioParam::exponential_ramp_to_value_at_time(float value, double end_time)-{- // A RangeError exception MUST be thrown if value is equal to 0.- if (value == 0)- return WebIDL::SimpleException { WebIDL::SimpleExceptionType::RangeError, "value must not be zero"_utf16 };-- // A RangeError exception MUST be thrown if endTime is negative or is not a finite number.- if (end_time < 0)- return WebIDL::SimpleException { WebIDL::SimpleExceptionType::RangeError, "endTime must not be negative"_utf16 };-- // If endTime is less than currentTime, it is clamped to currentTime.- auto current_time = context()->current_time();- end_time = max(end_time, current_time);-- TRY(map_insert_result(m_timeline->exponential_ramp_to_value_at_time(value, end_time, current_time, m_current_value)));- return GC::Ref { *this };-}--// https://webaudio.github.io/web-audio-api/#dom-audioparam-settargetattime-WebIDL::ExceptionOr<GC::Ref<AudioParam>> AudioParam::set_target_at_time(float target, double start_time, float time_constant)-{- // A RangeError exception MUST be thrown if startTime is negative or is not a finite number.- if (start_time < 0)- return WebIDL::SimpleException { WebIDL::SimpleExceptionType::RangeError, "startTime must not be negative"_utf16 };-- // A RangeError exception MUST be thrown if timeConstant is negative or is not a finite number.- if (time_constant < 0)- return WebIDL::SimpleException { WebIDL::SimpleExceptionType::RangeError, "timeConstant must not be negative"_utf16 };-- // If startTime is less than currentTime, it is clamped to currentTime.- start_time = max(start_time, context()->current_time());-- TRY(map_insert_result(m_timeline->set_target_at_time(target, start_time, time_constant)));- return GC::Ref { *this };-}--// https://webaudio.github.io/web-audio-api/#dom-audioparam-setvaluecurveattime-WebIDL::ExceptionOr<GC::Ref<AudioParam>> AudioParam::set_value_curve_at_time(Span<float> values, double start_time, double duration)-{- // An InvalidStateError exception MUST be thrown if values has a length less than 2.- if (values.size() < 2)- return WebIDL::InvalidStateError::create(context()->relevant_settings_object().realm(), "values must contain at least two elements"_utf16);-- // A RangeError exception MUST be thrown if startTime is negative or is not a finite number.- if (start_time < 0)- return WebIDL::SimpleException { WebIDL::SimpleExceptionType::RangeError, "startTime must not be negative"_utf16 };-- // A RangeError exception MUST be thrown if duration is not strictly positive or is not a finite number.- if (duration <= 0)- return WebIDL::SimpleException { WebIDL::SimpleExceptionType::RangeError, "duration must be positive"_utf16 };-- // If startTime is less than currentTime, it is clamped to currentTime.- start_time = max(start_time, context()->current_time());-- TRY(map_insert_result(m_timeline->set_value_curve_at_time(Vector<float> { values }, start_time, duration)));- return GC::Ref { *this };-}--// https://webaudio.github.io/web-audio-api/#dom-audioparam-cancelscheduledvalues-WebIDL::ExceptionOr<GC::Ref<AudioParam>> AudioParam::cancel_scheduled_values(double cancel_time)-{- // A RangeError exception MUST be thrown if cancelTime is negative.- if (cancel_time < 0)- return WebIDL::SimpleException { WebIDL::SimpleExceptionType::RangeError, "cancelTime must not be negative"_utf16 };-- // If cancelTime is less than currentTime, it is clamped to currentTime.- cancel_time = max(cancel_time, context()->current_time());-- m_timeline->cancel_scheduled_values(cancel_time);- return GC::Ref { *this };-}--// https://webaudio.github.io/web-audio-api/#dom-audioparam-cancelandholdattime-WebIDL::ExceptionOr<GC::Ref<AudioParam>> AudioParam::cancel_and_hold_at_time(double cancel_time)-{- // A RangeError exception MUST be thrown if cancelTime is negative.- if (cancel_time < 0)- return WebIDL::SimpleException { WebIDL::SimpleExceptionType::RangeError, "cancelTime must not be negative"_utf16 };-- // If cancelTime is less than currentTime, it is clamped to currentTime.- cancel_time = max(cancel_time, context()->current_time());-- m_timeline->cancel_and_hold_at_time(cancel_time);- return GC::Ref { *this };-}--void AudioParam::visit_edges(GC::Cell::Visitor& visitor)-{- Base::visit_edges(visitor);- visitor.visit(m_context);- visitor.visit(m_owner);-}+float AudioParam::intrinsic_value_at_time(double time) const { return web_rust_audio_param_intrinsic_value(const_cast<AudioParam*>(this), time); }+NonnullRefPtr<Rendering::RenderAudioParam> AudioParam::render_param() const { return adopt_ref(*new Rendering::RenderAudioParam(web_rust_audio_param_render_param(const_cast<AudioParam*>(this)))); }}diff --git a/Libraries/LibWeb/WebAudio/AudioParam.h b/Libraries/LibWeb/WebAudio/AudioParam.hindex 5a19695097c..c3f1b30b3d1 100644--- a/Libraries/LibWeb/WebAudio/AudioParam.h+++ b/Libraries/LibWeb/WebAudio/AudioParam.h@@ -1,5 +1,6 @@/** Copyright (c) 2024, Shannon Booth <[email protected]>+ * Copyright (c) 2026-present, the Ladybird developers.** SPDX-License-Identifier: BSD-2-Clause*/@@ -7,87 +8,25 @@#pragma once#include <LibWeb/Bindings/AudioParam.h>-#include <LibWeb/Bindings/Wrappable.h>-#include <LibWeb/WebAudio/AudioParamTimeline.h>+#include <LibWeb/Bindings/RustInterface.h>#include <LibWeb/WebAudio/Rendering/RenderNode.h>+#include <LibWeb/WebIDL/ExceptionOr.h>namespace Web::WebAudio {using AutomationRate = Bindings::AutomationRate;-// https://webaudio.github.io/web-audio-api/#AudioParam-class AudioParam final : public Bindings::GCAllocatedWrappable {- WEB_WRAPPABLE(AudioParam, Bindings::GCAllocatedWrappable);- GC_DECLARE_ALLOCATOR(AudioParam);+class AudioParam final : public Bindings::RustInterfaceCell {+ WEB_RUST_INTERFACE(AudioParam, audio_param)public:- enum class FixedAutomationRate {- No,- Yes,- };- // The owner is the AudioNode this parameter belongs to, or null for AudioListener parameters.+ enum class FixedAutomationRate : u8 { No,+ Yes };static GC::Ref<AudioParam> create(GC::Ref<BaseAudioContext>, GC::Ptr<AudioNode> owner, float default_value, float min_value, float max_value, AutomationRate, FixedAutomationRate = FixedAutomationRate::No);-- virtual ~AudioParam() override;-- GC::Ref<BaseAudioContext> context() const { return m_context; }-- float value() const;+ GC::Ref<BaseAudioContext> context() const;WebIDL::ExceptionOr<void> set_value(float);-- // https://webaudio.github.io/web-audio-api/#computedvalue- float intrinsic_value_at_time(double time) const { return m_timeline->value_at_time(time); }-- AutomationRate automation_rate() const;- WebIDL::ExceptionOr<void> set_automation_rate(AutomationRate);-- // https://webaudio.github.io/web-audio-api/#dom-audioparam-defaultvalue- float default_value() const { return m_default_value; }-- // https://webaudio.github.io/web-audio-api/#dom-audioparam-minvalue- float min_value() const { return m_min_value; }-- // https://webaudio.github.io/web-audio-api/#dom-audioparam-maxvalue- float max_value() const { return m_max_value; }-- NonnullRefPtr<AudioParamTimeline> timeline() const { return m_timeline; }- NonnullRefPtr<Rendering::RenderAudioParam> render_param() const { return m_render_param; }-- WebIDL::ExceptionOr<GC::Ref<AudioParam>> set_value_at_time(float value, double start_time);- WebIDL::ExceptionOr<GC::Ref<AudioParam>> linear_ramp_to_value_at_time(float value, double end_time);- WebIDL::ExceptionOr<GC::Ref<AudioParam>> exponential_ramp_to_value_at_time(float value, double end_time);- WebIDL::ExceptionOr<GC::Ref<AudioParam>> set_target_at_time(float target, double start_time, float time_constant);- WebIDL::ExceptionOr<GC::Ref<AudioParam>> set_value_curve_at_time(Span<float> values, double start_time, double duration);- WebIDL::ExceptionOr<GC::Ref<AudioParam>> cancel_scheduled_values(double cancel_time);- WebIDL::ExceptionOr<GC::Ref<AudioParam>> cancel_and_hold_at_time(double cancel_time);--private:- WebIDL::ExceptionOr<void> map_insert_result(AudioParamTimeline::InsertResult);-- AudioParam(GC::Ref<BaseAudioContext>, GC::Ptr<AudioNode> owner, float default_value, float min_value, float max_value, AutomationRate, FixedAutomationRate = FixedAutomationRate::No);-- GC::Ref<BaseAudioContext> m_context;-- // An AudioParam is a facet of the AudioNode that exposes it, so holding on to the parameter keeps that node, and- // with it the node's render node and automation, alive.- GC::Ptr<AudioNode> m_owner;-- NonnullRefPtr<AudioParamTimeline> m_timeline;- NonnullRefPtr<Rendering::RenderAudioParam> m_render_param;-- // https://webaudio.github.io/web-audio-api/#dom-audioparam-current-value-slot- float m_current_value {}; // [[current value]]-- float m_default_value {};-- float m_min_value {};- float m_max_value {};-- AutomationRate m_automation_rate {};-- FixedAutomationRate m_fixed_automation_rate { FixedAutomationRate::No };-- virtual void visit_edges(GC::Cell::Visitor&) override;+ float intrinsic_value_at_time(double time) const;+ NonnullRefPtr<Rendering::RenderAudioParam> render_param() const;};}diff --git a/Libraries/LibWeb/WebAudio/AudioParam.idl b/Libraries/LibWeb/WebAudio/AudioParam.idlindex 7411068df2f..f8dbf2ae298 100644--- a/Libraries/LibWeb/WebAudio/AudioParam.idl+++ b/Libraries/LibWeb/WebAudio/AudioParam.idl@@ -5,7 +5,7 @@ enum AutomationRate {};// https://webaudio.github.io/web-audio-api/#AudioParam-[Exposed=Window]+[Exposed=Window, ImplementedIn=Rust]interface AudioParam {attribute float value;attribute AutomationRate automationRate;diff --git a/Libraries/LibWeb/WebAudio/AudioParamMap.cpp b/Libraries/LibWeb/WebAudio/AudioParamMap.cppindex fd403bfd464..131eb9d89ef 100644--- a/Libraries/LibWeb/WebAudio/AudioParamMap.cpp+++ b/Libraries/LibWeb/WebAudio/AudioParamMap.cpp@@ -4,64 +4,33 @@* SPDX-License-Identifier: BSD-2-Clause*/-#include <LibGC/Heap.h>-#include <LibJS/Runtime/Map.h>-#include <LibJS/Runtime/PrimitiveString.h>-#include <LibJS/Runtime/Realm.h>-#include <LibWeb/Bindings/WrapperWorld.h>+#include <LibJS/HostClassBuilder.h>+#include <LibJS/Runtime/VM.h>#include <LibWeb/WebAudio/AudioParam.h>#include <LibWeb/WebAudio/AudioParamMap.h>-#include <LibWeb/WebAudio/BindingsGlue.h>namespace Web::WebAudio {-GC_DEFINE_ALLOCATOR(AudioParamMap);--GC::Ref<AudioParamMap> AudioParamMap::create()-{- return GC::Heap::the().allocate<AudioParamMap>();-}--AudioParamMap::AudioParamMap() = default;-AudioParamMap::~AudioParamMap() = default;--void AudioParamMap::visit_edges(Cell::Visitor& visitor)-{- Base::visit_edges(visitor);- for (auto const& entry : m_entries)- visitor.visit(entry.value);-}-+extern "C" {+void* web_rust_audio_param_map_create(JSVM*);+void web_rust_audio_param_map_set_entry(JSVM*, void* map, FlatPtr key, void* param);+void web_rust_audio_param_map_values(void* map, void* context, void (*callback)(void*, void*));}--namespace Web::Bindings {--static JS::Value wrapped_param(JS::Realm& realm, GC::Ref<WebAudio::AudioParam> param)-{- return Bindings::wrap(Bindings::host_defined_wrapper_world(realm), realm, param);-}--GC::Ref<JS::Map> map_entries(JS::Realm& realm, WebAudio::AudioParamMap& map)+GC::Ref<AudioParamMap> AudioParamMap::create(){- auto map_entries = JS::Map::create(realm);- for (auto const& entry : map.entries()) {- auto key = JS::PrimitiveString::create(realm.vm(), entry.key);- map_entries->map_set(JS::Value { key.ptr() }, wrapped_param(realm, entry.value));- }- return map_entries;+ return *static_cast<AudioParamMap*>(web_rust_audio_param_map_create(JS::HostABI::vm_to_abi(JS::VM::the())));}--Optional<JS::Value> map_get(JS::Realm& realm, WebAudio::AudioParamMap& map, Utf16View key)+void AudioParamMap::set_entry(Utf16FlyString key, GC::Ref<AudioParam> value){- auto it = map.entries().find(key);- if (it == map.entries().end())- return {};- return wrapped_param(realm, it->value);+ web_rust_audio_param_map_set_entry(JS::HostABI::vm_to_abi(JS::VM::the()), this, key.raw_identity(), value.ptr());}--bool map_has(WebAudio::AudioParamMap& map, Utf16View key)+GC::RootVector<GC::Ref<AudioParam>> AudioParamMap::values() const{- return map.entries().contains(key);+ GC::RootVector<GC::Ref<AudioParam>> values;+ web_rust_audio_param_map_values(const_cast<AudioParamMap*>(this), &values, [](void* context, void* param) {+ static_cast<GC::RootVector<GC::Ref<AudioParam>>*>(context)->append(*static_cast<AudioParam*>(param));+ });+ return values;}}diff --git a/Libraries/LibWeb/WebAudio/AudioParamMap.h b/Libraries/LibWeb/WebAudio/AudioParamMap.hindex ff7874a08ef..f7f6614ad50 100644--- a/Libraries/LibWeb/WebAudio/AudioParamMap.h+++ b/Libraries/LibWeb/WebAudio/AudioParamMap.h@@ -6,33 +6,22 @@#pragma once-#include <AK/HashMap.h>#include <AK/Utf16FlyString.h>-#include <LibWeb/Bindings/Wrappable.h>+#include <LibGC/RootVector.h>+#include <LibWeb/Bindings/AudioParamMap.h>+#include <LibWeb/Bindings/RustInterface.h>#include <LibWeb/Export.h>#include <LibWeb/Forward.h>namespace Web::WebAudio {-// https://webaudio.github.io/web-audio-api/#AudioParamMap-class WEB_API AudioParamMap final : public Bindings::GCAllocatedWrappable {- WEB_WRAPPABLE(AudioParamMap, Bindings::GCAllocatedWrappable);- GC_DECLARE_ALLOCATOR(AudioParamMap);+class WEB_API AudioParamMap final : public Bindings::RustInterfaceCell {+ WEB_RUST_INTERFACE(AudioParamMap, audio_param_map)public:static GC::Ref<AudioParamMap> create();-- virtual ~AudioParamMap() override;-- OrderedHashMap<Utf16FlyString, GC::Ref<AudioParam>> const& entries() const { return m_entries; }- void set_entry(Utf16FlyString key, GC::Ref<AudioParam> value) { m_entries.set(move(key), value); }--private:- AudioParamMap();-- virtual void visit_edges(Cell::Visitor&) override;-- OrderedHashMap<Utf16FlyString, GC::Ref<AudioParam>> m_entries;+ void set_entry(Utf16FlyString key, GC::Ref<AudioParam> value);+ GC::RootVector<GC::Ref<AudioParam>> values() const;};}diff --git a/Libraries/LibWeb/WebAudio/AudioParamMap.idl b/Libraries/LibWeb/WebAudio/AudioParamMap.idlindex cb7fe39c9b9..80a827425ef 100644--- a/Libraries/LibWeb/WebAudio/AudioParamMap.idl+++ b/Libraries/LibWeb/WebAudio/AudioParamMap.idl@@ -1,5 +1,5 @@// https://webaudio.github.io/web-audio-api/#AudioParamMap-[Exposed=Window]+[Exposed=Window, ImplementedIn=Rust]interface AudioParamMap {readonly maplike<DOMString, AudioParam>;};diff --git a/Libraries/LibWeb/WebAudio/AudioWorkletNode.cpp b/Libraries/LibWeb/WebAudio/AudioWorkletNode.cppindex 2d543a53fcb..024e9c15efa 100644--- a/Libraries/LibWeb/WebAudio/AudioWorkletNode.cpp+++ b/Libraries/LibWeb/WebAudio/AudioWorkletNode.cpp@@ -166,8 +166,8 @@ WebIDL::ExceptionOr<GC::Ref<AudioWorkletNode>> AudioWorkletNode::construct_impl(// Create the render mirror. Channel configuration rides in the constructor (the graph drops// SetChannelConfig messages that precede AddNode).Vector<NonnullRefPtr<Rendering::RenderAudioParam>> render_params;- for (auto const& entry : parameter_map->entries())- render_params.append(entry.value->render_param());+ for (auto const& param : parameter_map->values())+ render_params.append(param->render_param());node->queue_render_node_creation(make<Rendering::AudioWorkletRenderNode>(node->node_id(),options.number_of_inputs, options.number_of_outputs, pipe_config.quantum_size,pipe_config.output_channel_capacity,diff --git a/Libraries/LibWeb/WebAudio/BaseAudioContext.cpp b/Libraries/LibWeb/WebAudio/BaseAudioContext.cppindex f5a88a96bca..8a5a71480b7 100644--- a/Libraries/LibWeb/WebAudio/BaseAudioContext.cpp+++ b/Libraries/LibWeb/WebAudio/BaseAudioContext.cpp@@ -58,6 +58,11 @@ JSCompletion web_audio_verify_buffer_options(void* realm, u32 channels, u32 lengreturn JS::HostABI::normal_completion_to_abi(JS::HostABI::value_to_abi(JS::js_undefined()));}+extern "C" double web_audio_context_current_time(BaseAudioContext*);+extern "C" JS::Realm* web_audio_context_realm(BaseAudioContext*);+double web_audio_context_current_time(BaseAudioContext* context) { return context->current_time(); }+JS::Realm* web_audio_context_realm(BaseAudioContext* context) { return &context->relevant_settings_object().realm(); }+static JS::Value audio_buffer(JS::Realm& realm, GC::Ptr<AudioBuffer> buffer){if (!buffer)diff --git a/Libraries/LibWeb/WebAudio/ConstantSourceNode.idl b/Libraries/LibWeb/WebAudio/ConstantSourceNode.idlindex 93fcc3afd47..96cdede5626 100644--- a/Libraries/LibWeb/WebAudio/ConstantSourceNode.idl+++ b/Libraries/LibWeb/WebAudio/ConstantSourceNode.idl@@ -7,5 +7,5 @@ dictionary ConstantSourceOptions {[Exposed=Window]interface ConstantSourceNode : AudioScheduledSourceNode {constructor (BaseAudioContext context, optional ConstantSourceOptions options = {});- [DirectGetter] readonly attribute AudioParam offset;+ readonly attribute AudioParam offset;};diff --git a/Libraries/LibWeb/WebAudio/DelayNode.idl b/Libraries/LibWeb/WebAudio/DelayNode.idlindex 795f3ad5788..28e6689f6f6 100644--- a/Libraries/LibWeb/WebAudio/DelayNode.idl+++ b/Libraries/LibWeb/WebAudio/DelayNode.idl@@ -8,5 +8,5 @@ dictionary DelayOptions : AudioNodeOptions {[Exposed=Window]interface DelayNode : AudioNode {constructor (BaseAudioContext context, optional DelayOptions options = {});- [DirectGetter] readonly attribute AudioParam delayTime;+ readonly attribute AudioParam delayTime;};diff --git a/Libraries/LibWeb/WebAudio/DynamicsCompressorNode.idl b/Libraries/LibWeb/WebAudio/DynamicsCompressorNode.idlindex f7eda7b85f0..3d8f14548a5 100644--- a/Libraries/LibWeb/WebAudio/DynamicsCompressorNode.idl+++ b/Libraries/LibWeb/WebAudio/DynamicsCompressorNode.idl@@ -12,10 +12,10 @@ dictionary DynamicsCompressorOptions : AudioNodeOptions {interface DynamicsCompressorNode : AudioNode {constructor(BaseAudioContext context,optional DynamicsCompressorOptions options = {});- [DirectGetter] readonly attribute AudioParam threshold;- [DirectGetter] readonly attribute AudioParam knee;- [DirectGetter] readonly attribute AudioParam ratio;+ readonly attribute AudioParam threshold;+ readonly attribute AudioParam knee;+ readonly attribute AudioParam ratio;readonly attribute float reduction;- [DirectGetter] readonly attribute AudioParam attack;- [DirectGetter] readonly attribute AudioParam release;+ readonly attribute AudioParam attack;+ readonly attribute AudioParam release;};diff --git a/Libraries/LibWeb/WebAudio/GainNode.idl b/Libraries/LibWeb/WebAudio/GainNode.idlindex 0c9b2434d36..d131bd9486e 100644--- a/Libraries/LibWeb/WebAudio/GainNode.idl+++ b/Libraries/LibWeb/WebAudio/GainNode.idl@@ -7,5 +7,5 @@ dictionary GainOptions : AudioNodeOptions {[Exposed=Window]interface GainNode : AudioNode {constructor(BaseAudioContext context, optional GainOptions options = {});- [DirectGetter] readonly attribute AudioParam gain;+ readonly attribute AudioParam gain;};diff --git a/Libraries/LibWeb/WebAudio/OscillatorNode.idl b/Libraries/LibWeb/WebAudio/OscillatorNode.idlindex 9606f3035ae..9a2af70c1a4 100644--- a/Libraries/LibWeb/WebAudio/OscillatorNode.idl+++ b/Libraries/LibWeb/WebAudio/OscillatorNode.idl@@ -20,7 +20,7 @@ dictionary OscillatorOptions : AudioNodeOptions {interface OscillatorNode : AudioScheduledSourceNode {constructor(BaseAudioContext context, optional OscillatorOptions options = {});attribute OscillatorType type;- [DirectGetter] readonly attribute AudioParam frequency;- [DirectGetter] readonly attribute AudioParam detune;+ readonly attribute AudioParam frequency;+ readonly attribute AudioParam detune;undefined setPeriodicWave(PeriodicWave periodicWave);};diff --git a/Libraries/LibWeb/WebAudio/PannerNode.idl b/Libraries/LibWeb/WebAudio/PannerNode.idlindex a1d3fd2edbf..579b698877a 100644--- a/Libraries/LibWeb/WebAudio/PannerNode.idl+++ b/Libraries/LibWeb/WebAudio/PannerNode.idl@@ -34,12 +34,12 @@ dictionary PannerOptions : AudioNodeOptions {interface PannerNode : AudioNode {constructor(BaseAudioContext context, optional PannerOptions options = {});attribute PanningModelType panningModel;- [DirectGetter] readonly attribute AudioParam positionX;- [DirectGetter] readonly attribute AudioParam positionY;- [DirectGetter] readonly attribute AudioParam positionZ;- [DirectGetter] readonly attribute AudioParam orientationX;- [DirectGetter] readonly attribute AudioParam orientationY;- [DirectGetter] readonly attribute AudioParam orientationZ;+ readonly attribute AudioParam positionX;+ readonly attribute AudioParam positionY;+ readonly attribute AudioParam positionZ;+ readonly attribute AudioParam orientationX;+ readonly attribute AudioParam orientationY;+ readonly attribute AudioParam orientationZ;attribute DistanceModelType distanceModel;attribute double refDistance;attribute double maxDistance;diff --git a/Libraries/LibWeb/WebAudio/Rendering/RenderNode.cpp b/Libraries/LibWeb/WebAudio/Rendering/RenderNode.cppindex 20ff30d8c9c..8da587bca93 100644--- a/Libraries/LibWeb/WebAudio/Rendering/RenderNode.cpp+++ b/Libraries/LibWeb/WebAudio/Rendering/RenderNode.cpp@@ -17,6 +17,11 @@ RenderAudioParam::RenderAudioParam(NonnullRefPtr<AudioParamTimeline> timeline, fstatic_assert(to_underlying(Bindings::AutomationRate::KRate) == to_underlying(RustFFI::AutomationRate::KRate));}+RenderAudioParam::RenderAudioParam(void const* param)+ : m_param(param)+{+}+RenderAudioParam::~RenderAudioParam(){RustFFI::web_audio_render_param_destroy(m_param);diff --git a/Libraries/LibWeb/WebAudio/Rendering/RenderNode.h b/Libraries/LibWeb/WebAudio/Rendering/RenderNode.hindex 36b28532f6b..22276fcbd6b 100644--- a/Libraries/LibWeb/WebAudio/Rendering/RenderNode.h+++ b/Libraries/LibWeb/WebAudio/Rendering/RenderNode.h@@ -31,6 +31,7 @@ class WEB_API RenderAudioParam : public AtomicRefCounted<RenderAudioParam> {public:RenderAudioParam(NonnullRefPtr<AudioParamTimeline> timeline, float min_value, float max_value, Bindings::AutomationRate);+ explicit RenderAudioParam(void const* param);~RenderAudioParam();void set_automation_rate(Bindings::AutomationRate);diff --git a/Libraries/LibWeb/WebAudio/StereoPannerNode.idl b/Libraries/LibWeb/WebAudio/StereoPannerNode.idlindex adec6db895e..623ab72ac89 100644--- a/Libraries/LibWeb/WebAudio/StereoPannerNode.idl+++ b/Libraries/LibWeb/WebAudio/StereoPannerNode.idl@@ -7,5 +7,5 @@ dictionary StereoPannerOptions : AudioNodeOptions {[Exposed=Window]interface StereoPannerNode : AudioNode {constructor (BaseAudioContext context, optional StereoPannerOptions options = {});- [DirectGetter] readonly attribute AudioParam pan;+ readonly attribute AudioParam pan;};