use js_sys::Object;
use wasm_bindgen::prelude::*;
#[wasm_bindgen(js_name = "getSimd128Status")]
pub fn get_simd128_status() -> JsValue {
let obj = Object::new();
let compiled_with = cfg!(target_feature = "simd128");
js_sys::Reflect::set(
&obj,
&"compiled_with".into(),
&JsValue::from_bool(compiled_with),
)
.unwrap_or_default();
js_sys::Reflect::set(
&obj,
&"runtime_detected".into(),
&JsValue::from_bool(compiled_with),
)
.unwrap_or_default();
js_sys::Reflect::set(&obj, &"user_agent".into(), &JsValue::from_str("")).unwrap_or_default();
obj.into()
}
#[cfg(test)]
#[cfg(not(target_arch = "wasm32"))]
mod tests {
use crate::service_worker::ServiceWorkerOptions;
#[test]
fn simd_check_compiled_with_bool_type() {
let compiled_with: bool = cfg!(target_feature = "simd128");
let _: bool = compiled_with;
let _ = compiled_with;
}
#[test]
#[cfg(target_feature = "simd128")]
fn simd_check_returns_compiled_true_when_simd128_feature() {
let compiled_with: bool = cfg!(target_feature = "simd128");
assert!(compiled_with, "simd128 feature flag must be true");
}
#[test]
fn simd_check_struct_default_values() {
let opts = ServiceWorkerOptions::default();
assert_eq!(
opts.gguf_path_prefix, "/models/",
"default gguf_path_prefix must be '/models/'"
);
assert_eq!(
opts.cache_name, "oxillama-model-cache-v1",
"default cache_name must be 'oxillama-model-cache-v1'"
);
}
}