diff --git a/src/rust/jsg-test/tests/coercion_safety.rs b/src/rust/jsg-test/tests/coercion_safety.rs index 0750c317ce6..d79c9ea729c 100644 --- a/src/rust/jsg-test/tests/coercion_safety.rs +++ b/src/rust/jsg-test/tests/coercion_safety.rs @@ -718,7 +718,7 @@ impl Conversion { .set(lock, 0, undefined) } Self::DictKeys | Self::DictValue | Self::DictValueCoercion => { - jsg::Dict::::from_js(lock, value).map(drop) + jsg::Dict::::from_js(lock, value).map(drop) } } } diff --git a/src/rust/jsg-test/tests/dict.rs b/src/rust/jsg-test/tests/dict.rs index fe064ece779..c62d8456779 100644 --- a/src/rust/jsg-test/tests/dict.rs +++ b/src/rust/jsg-test/tests/dict.rs @@ -7,7 +7,6 @@ use jsg::Dict; use jsg::FromJS; -use jsg::Number; use jsg::v8; use jsg_macros::jsg_method; use jsg_macros::jsg_property; @@ -22,9 +21,9 @@ struct Records { impl Records { /// Describes the entries, in order, as `key=value` pairs. #[jsg_method] - pub fn describe(&self, dict: Dict) -> String { + pub fn describe(&self, dict: Dict) -> String { dict.into_iter() - .map(|(key, value)| format!("{key}={}", value.value())) + .map(|(key, value)| format!("{key}={value}")) .collect::>() .join(",") } @@ -38,29 +37,25 @@ impl Records { } #[jsg_method] - pub fn count_present(&self, dict: Dict>) -> Number { - Number::from(u32::try_from(dict.into_iter().filter(|(_, v)| v.is_some()).count()).unwrap()) + pub fn count_present(&self, dict: Dict>) -> f64 { + f64::from(u32::try_from(dict.into_iter().filter(|(_, v)| v.is_some()).count()).unwrap()) } #[jsg_method] - pub fn total_lengths(&self, dict: Dict>) -> Number { - Number::from(u32::try_from(dict.into_iter().map(|(_, v)| v.len()).sum::()).unwrap()) + pub fn total_lengths(&self, dict: Dict>) -> f64 { + f64::from(u32::try_from(dict.into_iter().map(|(_, v)| v.len()).sum::()).unwrap()) } #[jsg_method] - pub fn sum_nested(&self, dict: Dict>) -> Number { - Number::new( - dict.into_iter() - .flat_map(|(_, inner)| inner.into_iter().map(|(_, v)| v.value())) - .sum(), - ) + pub fn sum_nested(&self, dict: Dict>) -> f64 { + dict.into_iter() + .flat_map(|(_, inner)| inner.into_iter().map(|(_, v)| v)) + .sum() } #[jsg_method] - pub fn count_functions<'s>(&self, dict: Dict>) -> Number { - Number::from( - u32::try_from(dict.into_iter().filter(|(_, v)| v.is_function()).count()).unwrap(), - ) + pub fn count_functions<'s>(&self, dict: Dict>) -> f64 { + f64::from(u32::try_from(dict.into_iter().filter(|(_, v)| v.is_function()).count()).unwrap()) } #[jsg_method] @@ -69,16 +64,16 @@ impl Records { } #[jsg_method] - pub fn make(&self, keys: Vec) -> Dict { + pub fn make(&self, keys: Vec) -> Dict { keys.into_iter() - .zip(1..) - .map(|(key, n)| (key, Number::from(n))) + .zip(1u32..) + .map(|(key, n)| (key, f64::from(n))) .collect() } /// Is terminated and then returns a `Dict`, which is converted after the termination. #[jsg_method] - pub fn terminate_then_make(&self, lock: &mut jsg::Lock<'_>) -> Dict { + pub fn terminate_then_make(&self, lock: &mut jsg::Lock<'_>) -> Dict { crate::Harness::terminate_and_deliver(lock); self.make(vec!["a".to_owned()]) } @@ -188,10 +183,10 @@ fn values_other_than_objects_are_not_dicts() { ); } let value = ctx.eval_raw(lock, "[1]").unwrap(); - let err = Dict::::from_js(lock, value).unwrap_err(); + let err = Dict::::from_js(lock, value).unwrap_err(); assert_eq!(err.message, "Expected object but got array"); let value = ctx.eval_raw(lock, "1").unwrap(); - let err = Dict::::from_js(lock, value).unwrap_err(); + let err = Dict::::from_js(lock, value).unwrap_err(); assert_eq!(err.message, "Expected object but got number"); }); } @@ -436,6 +431,10 @@ fn dicts_round_trip() { } #[test] +#[expect( + clippy::float_cmp, + reason = "the values are small integers, exactly representable" +)] fn get_by_name_and_keys() { with_records(|lock, ctx| { let value = ctx @@ -449,11 +448,11 @@ fn get_by_name_and_keys() { .collect(); assert_eq!(names, ["b", "a"]); let value = object.get_by_name(lock, keys[1].into()).unwrap(); - assert_eq!(Number::from_js(lock, value).unwrap(), Number::new(3.0)); + assert_eq!(f64::from_js(lock, value).unwrap(), 3.0); let symbol = ctx.eval_raw(lock, "Symbol.for('s')").unwrap(); let symbol = v8::Local::::try_from(symbol).unwrap(); let value = object.get_by_name(lock, symbol.into()).unwrap(); - assert_eq!(Number::from_js(lock, value).unwrap(), Number::new(2.0)); + assert_eq!(f64::from_js(lock, value).unwrap(), 2.0); }); } diff --git a/src/rust/jsg/dict.rs b/src/rust/jsg/dict.rs index b0cfcb82305..64599852614 100644 --- a/src/rust/jsg/dict.rs +++ b/src/rust/jsg/dict.rs @@ -29,8 +29,8 @@ /// } /// /// #[jsg_method] -/// pub fn get_counts(&self) -> Dict { -/// Dict::from(vec![("hits".to_owned(), jsg::Number::new(3.0))]) +/// pub fn get_counts(&self) -> Dict { +/// Dict::from(vec![("hits".to_owned(), 3.0)]) /// } /// ``` #[derive(Debug, Clone, PartialEq, Eq, Hash)]