summaryrefslogtreecommitdiff
path: root/Libraries
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2021-01-09 16:36:25 +0100
committerAndreas Kling <kling@serenityos.org>2021-01-09 19:09:02 +0100
commit9fca86109b925e374cd03686e327c39a9cf3a561 (patch)
treee1da20c93e39e9aac73ab20b0dffb9401665ae7a /Libraries
parentc55cb7843a134afff2f713fde7072ea4822be697 (diff)
downloadserenity-9fca86109b925e374cd03686e327c39a9cf3a561.zip
LibJS: Make bitwise NOT work correctly with NaN and Infinity
This was missing a "toInt32()" which returns 0 for NaN and Infinity. From the spec: 6.1.6.1.2 Number::bitwiseNOT ( x ) The abstract operation Number::bitwiseNOT takes argument x (a Number). It performs the following steps when called: Let oldValue be ! ToInt32(x). Return the result of applying bitwise complement to oldValue. The mathematical value of the result is exactly representable as a 32-bit two's complement bit string. Fixes #4868.
Diffstat (limited to 'Libraries')
-rw-r--r--Libraries/LibJS/Runtime/Value.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/Libraries/LibJS/Runtime/Value.cpp b/Libraries/LibJS/Runtime/Value.cpp
index ba6ef48478..a2139856cf 100644
--- a/Libraries/LibJS/Runtime/Value.cpp
+++ b/Libraries/LibJS/Runtime/Value.cpp
@@ -669,7 +669,7 @@ Value bitwise_not(GlobalObject& global_object, Value lhs)
if (global_object.vm().exception())
return {};
if (lhs_numeric.is_number())
- return Value(~(i32)lhs_numeric.as_double());
+ return Value(~lhs_numeric.to_i32(global_object));
auto big_integer_bitwise_not = lhs_numeric.as_bigint().big_integer();
big_integer_bitwise_not = big_integer_bitwise_not.plus(Crypto::SignedBigInteger { 1 });
big_integer_bitwise_not.negate();