mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 09:47:34 +00:00
LibJS+LibCrypto: Fix SignedBitInteger::bitwise_not and use it in LibJS
Bitwise operators are defined on two's complement, but SignedBitInteger uses sign-magnitude. Correctly convert between the two. Let LibJS delegate to SignedBitInteger for bitwise_not, like it does for all other bitwise_ operations on bigints. No behavior change (LibJS is now the only client of SignedBitInteger::bitwise_not()).
This commit is contained in:
parent
ec37eadb39
commit
945d962322
4 changed files with 15 additions and 5 deletions
|
@ -881,10 +881,7 @@ ThrowCompletionOr<Value> bitwise_not(GlobalObject& global_object, Value lhs)
|
|||
auto lhs_numeric = TRY(lhs.to_numeric(global_object));
|
||||
if (lhs_numeric.is_number())
|
||||
return Value(~TRY(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();
|
||||
return Value(js_bigint(vm, big_integer_bitwise_not));
|
||||
return Value(js_bigint(vm, lhs_numeric.as_bigint().big_integer().bitwise_not()));
|
||||
}
|
||||
|
||||
// 13.5.4 Unary + Operator, https://tc39.es/ecma262/#sec-unary-plus-operator
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue