From 779c94e9570eb95bd35731881637082fc40afdb7 Mon Sep 17 00:00:00 2001 From: Pauan Date: Mon, 7 Apr 2025 06:22:47 +0200 Subject: [PATCH 1/3] Removing usage of eval Fixes #967 --- src/host/webaudio/mod.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/host/webaudio/mod.rs b/src/host/webaudio/mod.rs index dc9c0d9bf..e91793efe 100644 --- a/src/host/webaudio/mod.rs +++ b/src/host/webaudio/mod.rs @@ -2,7 +2,6 @@ extern crate js_sys; extern crate wasm_bindgen; extern crate web_sys; -use self::js_sys::eval; use self::wasm_bindgen::prelude::*; use self::wasm_bindgen::JsCast; use self::web_sys::{AudioContext, AudioContextOptions}; @@ -493,11 +492,7 @@ fn default_output_device() -> Option { // Detects whether the `AudioContext` global variable is available. fn is_webaudio_available() -> bool { - if let Ok(audio_context_is_defined) = eval("typeof AudioContext !== 'undefined'") { - audio_context_is_defined.as_bool().unwrap() - } else { - false - } + js_sys::Reflect::get(&js_sys::global(), &JsValue::from("AudioContext")).unwrap().is_truthy() } // Whether or not the given stream configuration is valid for building a stream. From da17b145df617afa8e4c0da67c4f56b53818e22d Mon Sep 17 00:00:00 2001 From: Pauan Date: Sun, 6 Apr 2025 21:25:08 -0700 Subject: [PATCH 2/3] rustfmt --- src/host/webaudio/mod.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/host/webaudio/mod.rs b/src/host/webaudio/mod.rs index e91793efe..fb835b735 100644 --- a/src/host/webaudio/mod.rs +++ b/src/host/webaudio/mod.rs @@ -492,7 +492,9 @@ fn default_output_device() -> Option { // Detects whether the `AudioContext` global variable is available. fn is_webaudio_available() -> bool { - js_sys::Reflect::get(&js_sys::global(), &JsValue::from("AudioContext")).unwrap().is_truthy() + js_sys::Reflect::get(&js_sys::global(), &JsValue::from("AudioContext")) + .unwrap() + .is_truthy() } // Whether or not the given stream configuration is valid for building a stream. From 52c3b05f50520212b39b79dcb7e4c7cd6c71cab1 Mon Sep 17 00:00:00 2001 From: Pauan Date: Sun, 6 Apr 2025 21:35:58 -0700 Subject: [PATCH 3/3] Updating to use the latest version of IntoWasmAbi --- src/lib.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 98444c239..efea3a379 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -33,7 +33,7 @@ //! ``` //! //! Before we can create a stream, we must decide what the configuration of the audio stream is -//! going to be. +//! going to be. //! You can query all the supported configurations with the //! [`supported_input_configs()`] and [`supported_output_configs()`] methods. //! These produce a list of [`SupportedStreamConfigRange`] structs which can later be turned into @@ -225,7 +225,7 @@ pub type FrameCount = u32; /// behavior of the given host. Note, the default buffer size may be surprisingly /// large, leading to latency issues. If low latency is desired, [`Fixed(FrameCount)`] /// should be used in accordance with the [`SupportedBufferSize`] range produced by -/// the [`SupportedStreamConfig`] API. +/// the [`SupportedStreamConfig`] API. /// /// [`Default`]: BufferSize::Default /// [`Fixed(FrameCount)`]: BufferSize::Fixed @@ -243,7 +243,8 @@ impl wasm_bindgen::describe::WasmDescribe for BufferSize { #[cfg(target_os = "emscripten")] impl wasm_bindgen::convert::IntoWasmAbi for BufferSize { - type Abi = Option; + type Abi = as wasm_bindgen::convert::IntoWasmAbi>::Abi; + fn into_abi(self) -> Self::Abi { match self { Self::Default => None,