mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 21:58:12 +00:00
LibJS: Throw RangeError on BigInt exponentiation with negative exponent
https://tc39.es/ecma262/#sec-numeric-types-bigint-exponentiate
This commit is contained in:
parent
11138f5c1f
commit
fa6bce5087
3 changed files with 13 additions and 1 deletions
|
@ -941,8 +941,13 @@ Value exp(GlobalObject& global_object, Value lhs, Value rhs)
|
|||
return {};
|
||||
if (both_number(lhs_numeric, rhs_numeric))
|
||||
return Value(pow(lhs_numeric.as_double(), rhs_numeric.as_double()));
|
||||
if (both_bigint(lhs_numeric, rhs_numeric))
|
||||
if (both_bigint(lhs_numeric, rhs_numeric)) {
|
||||
if (rhs_numeric.as_bigint().big_integer().is_negative()) {
|
||||
vm.throw_exception<RangeError>(global_object, ErrorType::NegativeExponent);
|
||||
return {};
|
||||
}
|
||||
return js_bigint(vm.heap(), Crypto::NumberTheory::Power(lhs_numeric.as_bigint().big_integer(), rhs_numeric.as_bigint().big_integer()));
|
||||
}
|
||||
vm.throw_exception<TypeError>(global_object, ErrorType::BigIntBadOperatorOtherType, "exponentiation");
|
||||
return {};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue