diff --git a/Cargo.lock b/Cargo.lock index 5bdb7f01..1cdd3f7c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -40,17 +40,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "async-trait" -version = "0.1.92" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82f6aeea286b8eb4dd3431a1be1b59d290ace00f5bfd8e2a159bc2a05e2c1667" -dependencies = [ - "proc-macro2", - "quote", - "syn 3.0.6", -] - [[package]] name = "autocfg" version = "1.5.1" @@ -115,12 +104,6 @@ version = "1.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc652a48c352aef3ea3aed32080501cf3ef6ed5da78602a020c991775b0aff04" -[[package]] -name = "cast" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" - [[package]] name = "cc" version = "1.5.1" @@ -619,7 +602,6 @@ dependencies = [ "unescape", "ureq", "wasm-bindgen", - "wasm-bindgen-test", ] [[package]] @@ -640,16 +622,6 @@ version = "2.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98" -[[package]] -name = "minicov" -version = "0.3.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4869b6a491569605d66d3952bcdf03df789e5b536e5f0cf7758a7f08a55ae24d" -dependencies = [ - "cc", - "walkdir", -] - [[package]] name = "miniz_oxide" version = "0.8.9" @@ -735,15 +707,6 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2bf50223579dc7cdcfb3bfcacf7069ff68243f8c363f62ffa99cf000a6b9c451" -[[package]] -name = "nu-ansi-term" -version = "0.50.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5" -dependencies = [ - "windows-sys 0.61.2", -] - [[package]] name = "num-traits" version = "0.2.19" @@ -769,12 +732,6 @@ version = "1.21.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" -[[package]] -name = "oorandom" -version = "11.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6790f58c7ff633d8771f42965289203411a5e5c68388703c06e14f24770b41e" - [[package]] name = "percent-encoding" version = "2.3.2" @@ -931,15 +888,6 @@ version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f" -[[package]] -name = "same-file" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" -dependencies = [ - "winapi-util", -] - [[package]] name = "semver" version = "1.0.28" @@ -1228,16 +1176,6 @@ version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" -[[package]] -name = "walkdir" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" -dependencies = [ - "same-file", - "winapi-util", -] - [[package]] name = "wasi" version = "0.11.1+wasi-snapshot-preview1" @@ -1266,16 +1204,6 @@ dependencies = [ "wasm-bindgen-shared", ] -[[package]] -name = "wasm-bindgen-futures" -version = "0.4.78" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ef4c5d3d2cdf5c54f4231181768f5510842e350db025faf1f7163b1030ed928" -dependencies = [ - "js-sys", - "wasm-bindgen", -] - [[package]] name = "wasm-bindgen-macro" version = "0.2.129" @@ -1308,45 +1236,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "wasm-bindgen-test" -version = "0.3.78" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45863ef0bef521c12124eb39d9a38513c47db75f22e503c06beacd40afeb35db" -dependencies = [ - "async-trait", - "cast", - "js-sys", - "libm", - "minicov", - "nu-ansi-term", - "num-traits", - "oorandom", - "serde", - "serde_json", - "wasm-bindgen", - "wasm-bindgen-futures", - "wasm-bindgen-test-macro", - "wasm-bindgen-test-shared", -] - -[[package]] -name = "wasm-bindgen-test-macro" -version = "0.3.78" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c89dcab8b516b6b603baca9d550b7282d68fcc7f367e3956cff7ebf406a3f12" -dependencies = [ - "proc-macro2", - "quote", - "syn 3.0.6", -] - -[[package]] -name = "wasm-bindgen-test-shared" -version = "0.2.128" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f37b4f992cebe528ef34964ae69681ac0fe7080071e7298e46008f9d380302af" - [[package]] name = "webpki-roots" version = "0.26.11" diff --git a/Cargo.toml b/Cargo.toml index 51432fd0..3f19b8e2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -147,9 +147,6 @@ ureq = "2" ahash = { version = "0.8", default-features = false, features = ["serde", "no-rng", "std"] } getrandom = { version = "0.2.17", features = ["js"] } -[target.'cfg(target_arch = "wasm32")'.dev-dependencies] -wasm-bindgen-test = "0.3" - [profile.dev] incremental = false diff --git a/rust/src/instructions/math/vector/trigonometry/hyperbolic/inverse/atanhv_func.rs b/rust/src/instructions/math/vector/trigonometry/hyperbolic/inverse/atanhv_func.rs index 98a73bc1..d04366e9 100644 --- a/rust/src/instructions/math/vector/trigonometry/hyperbolic/inverse/atanhv_func.rs +++ b/rust/src/instructions/math/vector/trigonometry/hyperbolic/inverse/atanhv_func.rs @@ -19,10 +19,7 @@ use crate::types::value::Value; use crate::utils::{expected_type::expected_type, get_type_name::get_type_name}; #[inline(always)] pub fn atanhv_values(a_val: Value, num_type: PrimitiveTypes, ip: usize) -> Result { - atanhv_borrowed(&a_val, num_type, ip) -} -fn atanhv_borrowed(a_val: &Value, num_type: PrimitiveTypes, ip: usize) -> Result { - let arr_a = a_val.as_array().ok_or_else(|| VMError::TypeMismatch { + let arr_a = a_val.as_array().ok_or(VMError::TypeMismatch { ip, expected: expected_type(num_type, ExpectedCategory::Float), found: get_type_name(a_val.clone()), @@ -54,11 +51,11 @@ fn atanhv_borrowed(a_val: &Value, num_type: PrimitiveTypes, ip: usize) -> Result } #[inline] pub fn atanhv_func(stack: &mut Stack, num_type: PrimitiveTypes, ip: usize) -> Result<(), VMError> { - let value = stack.last().ok_or(VMError::StackUnderflow { + let value = stack.last().cloned().ok_or(VMError::StackUnderflow { ip, opcode: "ATANHV", })?; - let result = atanhv_borrowed(value, num_type, ip)?; + let result = atanhv_values(value, num_type, ip)?; *stack.last_mut().unwrap() = result; Ok(()) } @@ -87,38 +84,6 @@ mod tests { assert_eq!(stack, original); } #[test] - fn replaces_only_top_value_after_success() { - let mut stack = Stack::from_vec(vec![Value::Int32(7), array(vec![Value::Float32(0.5)])]); - atanhv_func(&mut stack, PrimitiveTypes::Flt, 16).unwrap(); - assert_eq!(stack[0], Value::Int32(7)); - assert!((stack[1].as_array().unwrap()[0].as_f32() - 0.5_f32.atanh()).abs() < f32::EPSILON); - } - #[test] - fn invalid_element_and_directive_preserve_stack() { - let mut stack = Stack::from_vec(vec![Value::Int32(7), array(vec![Value::Bool(false)])]); - let original = stack.clone(); - assert!(matches!( - atanhv_func(&mut stack, PrimitiveTypes::Flt, 19), - Err(VMError::TypeMismatch { - ip: 19, - found: "Boolean", - .. - }) - )); - assert_eq!(stack, original); - let mut stack = Stack::from_vec(vec![array(vec![Value::Float32(0.0)])]); - let original = stack.clone(); - assert!(matches!( - atanhv_func(&mut stack, PrimitiveTypes::Str, 20), - Err(VMError::TypeMismatch { - ip: 20, - found: "unknown", - .. - }) - )); - assert_eq!(stack, original); - } - #[test] fn validates_elements_and_directives() { assert!(atanhv_values(array(vec![Value::Float32(1.0)]), PrimitiveTypes::Flt, 11).is_ok()); assert!(matches!( diff --git a/rust/src/interfaces/wasm_interface.rs b/rust/src/interfaces/wasm_interface.rs index 6ce2379a..e85ec44c 100644 --- a/rust/src/interfaces/wasm_interface.rs +++ b/rust/src/interfaces/wasm_interface.rs @@ -309,14 +309,15 @@ impl WasmLightVM { } #[wasm_bindgen(js_name = "callExport")] pub fn call_export(&mut self, name: String, args: JsValue) -> Result { - let is_function = self.inner.functions.contains_key(name.as_str()); + let target_name = name.clone(); + let is_function = self.inner.functions.contains_key(target_name.as_str()); let serde_args: serde_json::Value = serde_wasm_bindgen::from_value(args).map_err(|e| { wasm_bindgen::JsValue::from(js_sys::Error::new(&format!("Invalid export args: {}", e))) })?; if is_function { let raw_result = self .inner - .call_exported_internal(name, serde_args) + .call_exported_internal(target_name, serde_args) .map_err(|e| wasm_bindgen::JsValue::from(js_sys::Error::new(&e.to_string())))?; let parsed: serde_json::Value = serde_json::from_str(&raw_result).map_err(|e| { let vm_err = VMError::SystemError(smol_str::SmolStr::from(format!( @@ -354,7 +355,7 @@ impl WasmLightVM { } else { let raw_result = self .inner - .var_exported_internal(name) + .var_exported_internal(target_name) .map_err(|e| wasm_bindgen::JsValue::from(js_sys::Error::new(&e.to_string())))?; let parsed: serde_json::Value = serde_json::from_str(&raw_result).map_err(|e| { let vm_err = VMError::SystemError(smol_str::SmolStr::from(format!( @@ -543,52 +544,6 @@ mod tests { assert_eq!(parse_event("start"), Some(VmEvent::Start)); assert_eq!(parse_event("finish"), Some(VmEvent::Finish)); } - #[cfg(target_arch = "wasm32")] - #[wasm_bindgen_test::wasm_bindgen_test] - fn call_export_returns_function_and_variable_values() { - let mut vm = vm_with_control_capability(); - vm.inner.caps.insert(Capability::Observe); - vm.inner.nightly = true; - vm.inner - .load_internal( - serde_json::json!([ - ["jump", 7], - ["func", "add", 2, 2, 6, "a", "b"], - ["get", "a"], - ["get", "b"], - ["add", "int"], - ["return"], - ["stop"], - ["export", "add"], - ["val", "x"], - ["push", 5], - ["set", "x"], - ["export", "x"] - ]) - .to_string(), - ) - .unwrap(); - let function_result = vm - .call_export( - "add".to_string(), - serde_wasm_bindgen::to_value(&serde_json::json!([5, 6])).unwrap(), - ) - .unwrap(); - assert_eq!( - serde_wasm_bindgen::from_value::(function_result).unwrap(), - 11 - ); - let variable_result = vm - .call_export( - "x".to_string(), - serde_wasm_bindgen::to_value(&serde_json::json!([])).unwrap(), - ) - .unwrap(); - assert_eq!( - serde_wasm_bindgen::from_value::(variable_result).unwrap(), - 5 - ); - } #[test] fn tools_optimizer_typed_output_matches_string_boundary() { let bytecode = serde_json::json!([["stop"]]);