From ab8000b43216974fe360aa953ffd88f7afe7acc9 Mon Sep 17 00:00:00 2001 From: raskad <32105367+raskad@users.noreply.github.com> Date: Fri, 25 Nov 2022 02:10:05 +0100 Subject: [PATCH 1/2] Fix `PartialEq` for `JsBigInt` and `f64` --- boa_engine/src/bigint.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/boa_engine/src/bigint.rs b/boa_engine/src/bigint.rs index 029350cb9fb..7a239fe3287 100644 --- a/boa_engine/src/bigint.rs +++ b/boa_engine/src/bigint.rs @@ -453,21 +453,21 @@ impl PartialEq for i32 { impl PartialEq for JsBigInt { #[inline] fn eq(&self, other: &f64) -> bool { - if other.fract() != 0.0 { - return false; + if other.fract().is_zero() { + RawBigInt::from_f64(*other).map_or(false, |bigint| self.inner.as_ref() == &bigint) + } else { + false } - - self.inner.as_ref() == &RawBigInt::from(*other as i64) } } impl PartialEq for f64 { #[inline] fn eq(&self, other: &JsBigInt) -> bool { - if self.fract() != 0.0 { - return false; + if self.fract().is_zero() { + RawBigInt::from_f64(*self).map_or(false, |bigint| other.inner.as_ref() == &bigint) + } else { + false } - - &RawBigInt::from(*self as i64) == other.inner.as_ref() } } From 6a15a13e2df6e16a0cc84907cf6c86f3ff5a3c24 Mon Sep 17 00:00:00 2001 From: raskad <32105367+raskad@users.noreply.github.com> Date: Fri, 25 Nov 2022 18:03:18 +0100 Subject: [PATCH 2/2] Apply suggestions --- boa_engine/src/bigint.rs | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/boa_engine/src/bigint.rs b/boa_engine/src/bigint.rs index 7a239fe3287..df113190f54 100644 --- a/boa_engine/src/bigint.rs +++ b/boa_engine/src/bigint.rs @@ -453,21 +453,15 @@ impl PartialEq for i32 { impl PartialEq for JsBigInt { #[inline] fn eq(&self, other: &f64) -> bool { - if other.fract().is_zero() { - RawBigInt::from_f64(*other).map_or(false, |bigint| self.inner.as_ref() == &bigint) - } else { - false - } + other.fract().is_zero() + && RawBigInt::from_f64(*other).map_or(false, |bigint| self.inner.as_ref() == &bigint) } } impl PartialEq for f64 { #[inline] fn eq(&self, other: &JsBigInt) -> bool { - if self.fract().is_zero() { - RawBigInt::from_f64(*self).map_or(false, |bigint| other.inner.as_ref() == &bigint) - } else { - false - } + self.fract().is_zero() + && RawBigInt::from_f64(*self).map_or(false, |bigint| other.inner.as_ref() == &bigint) } }