From d5c292d33f7d11f3d2ca0a74f8cf21bc012ff619 Mon Sep 17 00:00:00 2001 From: pjh456 <147148383@qq.com> Date: Tue, 30 Jun 2026 15:18:13 +0800 Subject: [PATCH] =?UTF-8?q?style:=20=E4=BF=AE=E5=A4=8D=20clippy=20--all-ta?= =?UTF-8?q?rgets=20=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tests/structural_hash_tests.rs | 5 +- crates/oxide_vm/src/vm.rs | 242 +++++++++--------- crates/oxide_vm/tests/builtins_array_tests.rs | 4 +- crates/oxide_vm/tests/builtins_date_tests.rs | 2 +- .../oxide_vm/tests/builtins_number_tests.rs | 4 +- 5 files changed, 129 insertions(+), 128 deletions(-) diff --git a/crates/oxide_compiler/tests/structural_hash_tests.rs b/crates/oxide_compiler/tests/structural_hash_tests.rs index ec1602e0..0efb803b 100644 --- a/crates/oxide_compiler/tests/structural_hash_tests.rs +++ b/crates/oxide_compiler/tests/structural_hash_tests.rs @@ -170,8 +170,7 @@ fn structural_hash_distinguishes_optional_chain_shape() { #[test] fn compiled_module_rejects_optional_chain_assignment_target() { let allocator = Allocator::default(); - match oxide_parser::parse(&allocator, "a?.b = 1") { - Ok(program) => assert!(Compiler::new().compile(&program).is_err()), - Err(_) => {} + if let Ok(program) = oxide_parser::parse(&allocator, "a?.b = 1") { + assert!(Compiler::new().compile(&program).is_err()); } } diff --git a/crates/oxide_vm/src/vm.rs b/crates/oxide_vm/src/vm.rs index 7c6ad125..87467b6a 100644 --- a/crates/oxide_vm/src/vm.rs +++ b/crates/oxide_vm/src/vm.rs @@ -1175,6 +1175,127 @@ impl Default for Vm { } } +impl oxide_runtime_api::VmHost for Vm { + fn reg(&self, idx: u8) -> JsValue { + self.reg(idx) + } + fn set_reg(&mut self, idx: u8, val: JsValue) { + self.set_reg(idx, val); + } + fn alloc_object(&mut self, obj: JsObject) -> *mut JsObject { + self.alloc_object(obj) + } + fn new_string(&mut self, s: &str) -> JsValue { + self.new_string(s) + } + fn kernel_core(&self) -> &Arc { + self.kernel_core() + } + fn session(&self) -> &KernelSession { + self.session() + } + fn epoch(&self) -> &Epoch { + self.epoch() + } + fn take_uncaught_value(&mut self) -> Option { + self.last_uncaught_value.take() + } + fn property_key_si(&mut self, val: JsValue) -> u32 { + self.property_key_si(val) + } + fn resolve_property(&self, obj: &JsObject, prop_name_si: u32) -> Option { + self.resolve_property(obj, prop_name_si) + } + fn get_own_property_slot(&self, obj: &JsObject, prop_name_si: u32) -> Option { + self.get_own_property_slot(obj, prop_name_si) + } + fn ordinary_get(&mut self, obj: &JsObject, prop_name_si: u32, receiver: JsValue) -> Result { + self.ordinary_get(obj, prop_name_si, receiver) + } + fn ordinary_set( + &mut self, obj: &mut JsObject, prop_name_si: u32, val: JsValue, receiver: JsValue, + ) -> Result<(), String> { + self.ordinary_set(obj, prop_name_si, val, receiver) + } + fn define_data_property( + &mut self, obj: &mut JsObject, prop_name_si: u32, val: JsValue, attributes: PropAttributes, + ) -> Result<(), String> { + self.define_data_property(obj, prop_name_si, val, attributes) + } + fn define_accessor_property( + &mut self, obj: &mut JsObject, prop_name_si: u32, get: JsValue, set: JsValue, attributes: PropAttributes, + ) -> Result<(), String> { + self.define_accessor_property(obj, prop_name_si, get, set, attributes) + } + fn set_or_create_prop_value(&mut self, obj: &mut JsObject, prop_name_si: u32, val: JsValue) { + self.set_or_create_prop_value(obj, prop_name_si, val) + } + fn lookup_str(&self, val: JsValue) -> Option { + self.lookup_str(val) + } + fn coerce_primitive_bounded(&mut self, value: JsValue, prefer_string: bool) -> Result { + self.coerce_primitive_bounded(value, prefer_string) + } + fn coerce_number_bounded(&mut self, value: JsValue) -> Result { + self.coerce_number_bounded(value) + } + fn call_function_sync(&mut self, callee: JsValue, receiver: JsValue, args: &[JsValue]) -> Result { + self.call_function_sync(callee, receiver, args) + } + fn checked_object_ptr(&mut self, val: JsValue, error_msg: &str) -> Result, String> { + self.checked_object_ptr(val, error_msg) + } + fn raise_type_error(&mut self, msg: &str) -> Result<(), String> { + self.raise_type_error(msg) + } + fn error_message_text(&self, kind: &str, msg: &str) -> String { + self.error_message_text(kind, msg) + } + fn call_stack_function_names(&self) -> Vec { + self.frames + .iter() + .rev() + .map(|f| { + self.kernel_core + .perm_interner() + .lookup(f.function_name) + .unwrap_or("") + .to_string() + }) + .collect() + } + fn promote_if_needed_for_write_ptr(&mut self, target_ptr: *mut JsObject, value: JsValue) -> JsValue { + self.promote_if_needed_for_write_ptr(target_ptr, value) + } + fn step_rng(&mut self) { + self.step_rng() + } + fn math_rng_value(&self) -> f64 { + self.math_rng_value() + } + fn sub_module_function_name(&self, sub_idx: u16) -> String { + self.sub_modules + .get(sub_idx as usize) + .and_then(|m| m.function_name.clone()) + .unwrap_or_default() + } + fn symbol_intern(&mut self, desc: String) -> u32 { + self.symbols.intern(desc) + } + fn symbol_description(&self, idx: u32) -> Option<&str> { + self.symbols.description(idx) + } + fn symbol_lookup_global(&self, key: &str) -> Option { + self.symbols.lookup_global(key) + } + fn symbol_register_global(&mut self, key: String, idx: u32) { + self.symbols.register_global(key, idx) + } + fn symbol_key_for_id(&self, idx: u32) -> Option { + self.symbols.key_for_id(idx) + } +} + #[cfg(test)] mod tests { use super::{opcode, JsValue, TryHandler, Vm}; @@ -1511,124 +1632,3 @@ mod tests { assert_eq!(vm.reg(255), JsValue::int(13)); } } - -impl oxide_runtime_api::VmHost for Vm { - fn reg(&self, idx: u8) -> JsValue { - self.reg(idx) - } - fn set_reg(&mut self, idx: u8, val: JsValue) { - self.set_reg(idx, val); - } - fn alloc_object(&mut self, obj: JsObject) -> *mut JsObject { - self.alloc_object(obj) - } - fn new_string(&mut self, s: &str) -> JsValue { - self.new_string(s) - } - fn kernel_core(&self) -> &Arc { - self.kernel_core() - } - fn session(&self) -> &KernelSession { - self.session() - } - fn epoch(&self) -> &Epoch { - self.epoch() - } - fn take_uncaught_value(&mut self) -> Option { - self.last_uncaught_value.take() - } - fn property_key_si(&mut self, val: JsValue) -> u32 { - self.property_key_si(val) - } - fn resolve_property(&self, obj: &JsObject, prop_name_si: u32) -> Option { - self.resolve_property(obj, prop_name_si) - } - fn get_own_property_slot(&self, obj: &JsObject, prop_name_si: u32) -> Option { - self.get_own_property_slot(obj, prop_name_si) - } - fn ordinary_get(&mut self, obj: &JsObject, prop_name_si: u32, receiver: JsValue) -> Result { - self.ordinary_get(obj, prop_name_si, receiver) - } - fn ordinary_set( - &mut self, obj: &mut JsObject, prop_name_si: u32, val: JsValue, receiver: JsValue, - ) -> Result<(), String> { - self.ordinary_set(obj, prop_name_si, val, receiver) - } - fn define_data_property( - &mut self, obj: &mut JsObject, prop_name_si: u32, val: JsValue, attributes: PropAttributes, - ) -> Result<(), String> { - self.define_data_property(obj, prop_name_si, val, attributes) - } - fn define_accessor_property( - &mut self, obj: &mut JsObject, prop_name_si: u32, get: JsValue, set: JsValue, attributes: PropAttributes, - ) -> Result<(), String> { - self.define_accessor_property(obj, prop_name_si, get, set, attributes) - } - fn set_or_create_prop_value(&mut self, obj: &mut JsObject, prop_name_si: u32, val: JsValue) { - self.set_or_create_prop_value(obj, prop_name_si, val) - } - fn lookup_str(&self, val: JsValue) -> Option { - self.lookup_str(val) - } - fn coerce_primitive_bounded(&mut self, value: JsValue, prefer_string: bool) -> Result { - self.coerce_primitive_bounded(value, prefer_string) - } - fn coerce_number_bounded(&mut self, value: JsValue) -> Result { - self.coerce_number_bounded(value) - } - fn call_function_sync(&mut self, callee: JsValue, receiver: JsValue, args: &[JsValue]) -> Result { - self.call_function_sync(callee, receiver, args) - } - fn checked_object_ptr(&mut self, val: JsValue, error_msg: &str) -> Result, String> { - self.checked_object_ptr(val, error_msg) - } - fn raise_type_error(&mut self, msg: &str) -> Result<(), String> { - self.raise_type_error(msg) - } - fn error_message_text(&self, kind: &str, msg: &str) -> String { - self.error_message_text(kind, msg) - } - fn call_stack_function_names(&self) -> Vec { - self.frames - .iter() - .rev() - .map(|f| { - self.kernel_core - .perm_interner() - .lookup(f.function_name) - .unwrap_or("") - .to_string() - }) - .collect() - } - fn promote_if_needed_for_write_ptr(&mut self, target_ptr: *mut JsObject, value: JsValue) -> JsValue { - self.promote_if_needed_for_write_ptr(target_ptr, value) - } - fn step_rng(&mut self) { - self.step_rng() - } - fn math_rng_value(&self) -> f64 { - self.math_rng_value() - } - fn sub_module_function_name(&self, sub_idx: u16) -> String { - self.sub_modules - .get(sub_idx as usize) - .and_then(|m| m.function_name.clone()) - .unwrap_or_default() - } - fn symbol_intern(&mut self, desc: String) -> u32 { - self.symbols.intern(desc) - } - fn symbol_description(&self, idx: u32) -> Option<&str> { - self.symbols.description(idx) - } - fn symbol_lookup_global(&self, key: &str) -> Option { - self.symbols.lookup_global(key) - } - fn symbol_register_global(&mut self, key: String, idx: u32) { - self.symbols.register_global(key, idx) - } - fn symbol_key_for_id(&self, idx: u32) -> Option { - self.symbols.key_for_id(idx) - } -} diff --git a/crates/oxide_vm/tests/builtins_array_tests.rs b/crates/oxide_vm/tests/builtins_array_tests.rs index 82cb7800..40d663c9 100644 --- a/crates/oxide_vm/tests/builtins_array_tests.rs +++ b/crates/oxide_vm/tests/builtins_array_tests.rs @@ -132,13 +132,13 @@ fn array_index_of_not_found() { #[test] fn array_includes_true() { let (_vm, result) = eval("[1,2,3].includes(2)").unwrap(); - assert_eq!(result.as_bool(), true); + assert!(result.as_bool()); } #[test] fn array_includes_false() { let (_vm, result) = eval("[1,2,3].includes(99)").unwrap(); - assert_eq!(result.as_bool(), false); + assert!(!result.as_bool()); } #[test] diff --git a/crates/oxide_vm/tests/builtins_date_tests.rs b/crates/oxide_vm/tests/builtins_date_tests.rs index 1af524fa..1e5ee10f 100644 --- a/crates/oxide_vm/tests/builtins_date_tests.rs +++ b/crates/oxide_vm/tests/builtins_date_tests.rs @@ -148,7 +148,7 @@ fn date_local_getters_differ_from_utc() { if utc_hour != local_hour { assert_ne!(local_hour, utc_hour, "in non-UTC+0, local vs UTC hours should differ"); } - assert!(local_hour >= 0.0 && local_hour < 24.0); + assert!((0.0..24.0).contains(&local_hour)); } #[test] diff --git a/crates/oxide_vm/tests/builtins_number_tests.rs b/crates/oxide_vm/tests/builtins_number_tests.rs index 846c5aac..a185c00c 100644 --- a/crates/oxide_vm/tests/builtins_number_tests.rs +++ b/crates/oxide_vm/tests/builtins_number_tests.rs @@ -55,7 +55,9 @@ fn parse_int_hex() { fn parse_float_decimal() { let mut vm = Vm::new(); let result = eval(&mut vm, "parseFloat('3.14')").unwrap(); - assert!((result.as_double() - 3.14).abs() < 0.001); + #[allow(clippy::approx_constant)] + let expected = 3.14; + assert!((result.as_double() - expected).abs() < 0.001); } #[test]