mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-01 05:39:11 +00:00
LibJS: Add builtin for Math.random()
This commit is contained in:
parent
714e8aec8a
commit
ec590ef3e6
Notes:
github-actions[bot]
2025-04-03 11:57:34 +00:00
Author: https://github.com/awesomekling
Commit: ec590ef3e6
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4204
4 changed files with 22 additions and 13 deletions
|
@ -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 {
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue