From ff78971413478430218d700fd202b949338c41b5 Mon Sep 17 00:00:00 2001 From: CrazyboyQCD Date: Fri, 19 Jul 2024 16:39:44 +0800 Subject: [PATCH 1/3] fix: fix wrong neg operation --- core/engine/src/value/operations.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/engine/src/value/operations.rs b/core/engine/src/value/operations.rs index c26a0b00bab..711dbd38e76 100644 --- a/core/engine/src/value/operations.rs +++ b/core/engine/src/value/operations.rs @@ -479,8 +479,8 @@ impl JsValue { Self::Rational(num) => Self::new(-num), Self::Integer(0) => Self::new(-f64::from(0)), Self::Integer(num) => Self::new(-num), - Self::Boolean(true) => Self::new(1), - Self::Boolean(false) | Self::Null => Self::new(0), + Self::Boolean(true) => Self::new(-f64::from(1)), + Self::Boolean(false) | Self::Null => Self::new(-f64::from(0)), Self::BigInt(ref x) => Self::new(JsBigInt::neg(x)), }) } From 6882a55c5a84a7fb2a9cde34685d560bbb9e16a2 Mon Sep 17 00:00:00 2001 From: CrazyboyQCD Date: Fri, 19 Jul 2024 16:46:06 +0800 Subject: [PATCH 2/3] chore: merge match arm --- core/engine/src/value/operations.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core/engine/src/value/operations.rs b/core/engine/src/value/operations.rs index 711dbd38e76..d243315beaa 100644 --- a/core/engine/src/value/operations.rs +++ b/core/engine/src/value/operations.rs @@ -477,10 +477,9 @@ impl JsValue { ), Self::String(ref str) => Self::new(-str.to_number()), Self::Rational(num) => Self::new(-num), - Self::Integer(0) => Self::new(-f64::from(0)), + Self::Integer(0) | Self::Boolean(false) | Self::Null => Self::new(-f64::from(0)), Self::Integer(num) => Self::new(-num), Self::Boolean(true) => Self::new(-f64::from(1)), - Self::Boolean(false) | Self::Null => Self::new(-f64::from(0)), Self::BigInt(ref x) => Self::new(JsBigInt::neg(x)), }) } From ae54e48c532b5e41099a7d23aa2983dca7819024 Mon Sep 17 00:00:00 2001 From: CrazyboyQCD Date: Tue, 23 Jul 2024 08:36:56 +0800 Subject: [PATCH 3/3] chore: add tests --- core/engine/src/value/tests.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/engine/src/value/tests.rs b/core/engine/src/value/tests.rs index 4d8fffc169f..c689a1fc3cd 100644 --- a/core/engine/src/value/tests.rs +++ b/core/engine/src/value/tests.rs @@ -64,6 +64,9 @@ fn abstract_equality_comparison() { TestAction::assert("+0 == 0"), TestAction::assert("-0 == 0"), TestAction::assert("0 == false"), + TestAction::assert("-0 == -false"), + TestAction::assert("-0 == -null"), + TestAction::assert("-1 == -true"), TestAction::assert("'' == false"), TestAction::assert("'' == 0"), TestAction::assert("'17' == 17"),