LibJS: Add builtin for Math.random()

This commit is contained in:
Andreas Kling 2025-04-03 12:01:31 +02:00 committed by Andreas Kling
commit ec590ef3e6
Notes: github-actions[bot] 2025-04-03 11:57:34 +00:00
4 changed files with 22 additions and 13 deletions

View file

@ -12,15 +12,16 @@
namespace JS::Bytecode {
// TitleCaseName, snake_case_name, base, property, argument_count
#define JS_ENUMERATE_BUILTINS(O) \
O(MathAbs, math_abs, Math, abs, 1) \
O(MathLog, math_log, Math, log, 1) \
O(MathPow, math_pow, Math, pow, 2) \
O(MathExp, math_exp, Math, exp, 1) \
O(MathCeil, math_ceil, Math, ceil, 1) \
O(MathFloor, math_floor, Math, floor, 1) \
O(MathImul, math_imul, Math, imul, 2) \
O(MathRound, math_round, Math, round, 1) \
#define JS_ENUMERATE_BUILTINS(O) \
O(MathAbs, math_abs, Math, abs, 1) \
O(MathLog, math_log, Math, log, 1) \
O(MathPow, math_pow, Math, pow, 2) \
O(MathExp, math_exp, Math, exp, 1) \
O(MathCeil, math_ceil, Math, ceil, 1) \
O(MathFloor, math_floor, Math, floor, 1) \
O(MathImul, math_imul, Math, imul, 2) \
O(MathRandom, math_random, Math, random, 0) \
O(MathRound, math_round, Math, round, 1) \
O(MathSqrt, math_sqrt, Math, sqrt, 1)
enum class Builtin : u8 {

View file

@ -2599,6 +2599,8 @@ static ThrowCompletionOr<Value> dispatch_builtin_call(Bytecode::Interpreter& int
return TRY(MathObject::floor_impl(interpreter.vm(), interpreter.get(arguments[0])));
case Builtin::MathImul:
return TRY(MathObject::imul_impl(interpreter.vm(), interpreter.get(arguments[0]), interpreter.get(arguments[1])));
case Builtin::MathRandom:
return MathObject::random_impl();
case Builtin::MathRound:
return TRY(MathObject::round_impl(interpreter.vm(), interpreter.get(arguments[0])));
case Builtin::MathSqrt: