Skip to content

Commit 2ea518d

Browse files
authored
Removing usage of eval (#968)
* Removing usage of eval Fixes #967 * rustfmt * Updating to use the latest version of IntoWasmAbi
1 parent c5a163e commit 2ea518d

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

src/host/webaudio/mod.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ extern crate js_sys;
22
extern crate wasm_bindgen;
33
extern crate web_sys;
44

5-
use self::js_sys::eval;
65
use self::wasm_bindgen::prelude::*;
76
use self::wasm_bindgen::JsCast;
87
use self::web_sys::{AudioContext, AudioContextOptions};
@@ -493,11 +492,9 @@ fn default_output_device() -> Option<Device> {
493492

494493
// Detects whether the `AudioContext` global variable is available.
495494
fn is_webaudio_available() -> bool {
496-
if let Ok(audio_context_is_defined) = eval("typeof AudioContext !== 'undefined'") {
497-
audio_context_is_defined.as_bool().unwrap()
498-
} else {
499-
false
500-
}
495+
js_sys::Reflect::get(&js_sys::global(), &JsValue::from("AudioContext"))
496+
.unwrap()
497+
.is_truthy()
501498
}
502499

503500
// Whether or not the given stream configuration is valid for building a stream.

src/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
//! ```
3434
//!
3535
//! Before we can create a stream, we must decide what the configuration of the audio stream is
36-
//! going to be.
36+
//! going to be.
3737
//! You can query all the supported configurations with the
3838
//! [`supported_input_configs()`] and [`supported_output_configs()`] methods.
3939
//! These produce a list of [`SupportedStreamConfigRange`] structs which can later be turned into
@@ -225,7 +225,7 @@ pub type FrameCount = u32;
225225
/// behavior of the given host. Note, the default buffer size may be surprisingly
226226
/// large, leading to latency issues. If low latency is desired, [`Fixed(FrameCount)`]
227227
/// should be used in accordance with the [`SupportedBufferSize`] range produced by
228-
/// the [`SupportedStreamConfig`] API.
228+
/// the [`SupportedStreamConfig`] API.
229229
///
230230
/// [`Default`]: BufferSize::Default
231231
/// [`Fixed(FrameCount)`]: BufferSize::Fixed
@@ -243,7 +243,8 @@ impl wasm_bindgen::describe::WasmDescribe for BufferSize {
243243

244244
#[cfg(target_os = "emscripten")]
245245
impl wasm_bindgen::convert::IntoWasmAbi for BufferSize {
246-
type Abi = Option<u32>;
246+
type Abi = <Option<FrameCount> as wasm_bindgen::convert::IntoWasmAbi>::Abi;
247+
247248
fn into_abi(self) -> Self::Abi {
248249
match self {
249250
Self::Default => None,

0 commit comments

Comments
 (0)