Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions crates/history/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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.");
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/history/tests/query.rs
Original file line number Diff line number Diff line change
@@ -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::*;
Expand Down