diff --git a/crates/history/src/utils.rs b/crates/history/src/utils.rs index 24422d48..8aa4f346 100644 --- a/crates/history/src/utils.rs +++ b/crates/history/src/utils.rs @@ -2,16 +2,17 @@ use std::cell::RefCell; use std::rc::{Rc, Weak}; use std::sync::atomic::{AtomicU32, Ordering}; +#[cfg(not(target_os = "wasi"))] use wasm_bindgen::throw_str; -#[cfg(not(target_arch = "wasm32"))] +#[cfg(any(not(target_arch = "wasm32"), target_os = "wasi"))] pub(crate) fn get_id() -> u32 { static ID_CTR: AtomicU32 = AtomicU32::new(0); ID_CTR.fetch_add(1, Ordering::SeqCst) } -#[cfg(target_arch = "wasm32")] +#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))] pub(crate) fn get_id() -> u32 { static ID_CTR: AtomicU32 = AtomicU32::new(0); static INIT: std::sync::Once = std::sync::Once::new(); @@ -30,19 +31,28 @@ pub(crate) fn get_id() -> u32 { pub(crate) fn assert_absolute_path(path: &str) { if !path.starts_with('/') { + #[cfg(not(target_os = "wasi"))] throw_str("You cannot use relative path with this history type."); + #[cfg(target_os = "wasi")] + panic!("You cannot use relative path with this history type."); } } pub(crate) fn assert_no_query(path: &str) { if path.contains('?') { + #[cfg(not(target_os = "wasi"))] throw_str("You cannot have query in path, try use a variant of this method with `_query`."); + #[cfg(target_os = "wasi")] + panic!("You cannot have query in path, try use a variant of this method with `_query`."); } } pub(crate) fn assert_no_fragment(path: &str) { if path.contains('#') { + #[cfg(not(target_os = "wasi"))] throw_str("You cannot use fragments (hash) in memory history."); + #[cfg(target_os = "wasi")] + panic!("You cannot use fragments (hash) in memory history."); } } diff --git a/crates/history/tests/query.rs b/crates/history/tests/query.rs index 28ffb75b..a7fc176e 100644 --- a/crates/history/tests/query.rs +++ b/crates/history/tests/query.rs @@ -1,8 +1,8 @@ #![cfg(feature = "query")] -#[cfg(target_arch = "wasm32")] +#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))] use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure}; -#[cfg(target_arch = "wasm32")] +#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))] wasm_bindgen_test_configure!(run_in_browser); use gloo_history::query::*;