mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-11 18:20:43 +09:00
LibJS: Use CallBuiltin for Math.cos()
This commit is contained in:
parent
c02535e9f9
commit
878cc16d7a
Notes:
github-actions[bot]
2025-05-26 19:53:48 +00:00
Author: https://github.com/kalenikaliaksandr
Commit: 878cc16d7a
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4884
Reviewed-by: https://github.com/awesomekling ✅
4 changed files with 13 additions and 4 deletions
|
@ -23,7 +23,8 @@ namespace JS::Bytecode {
|
|||
O(MathRandom, math_random, Math, random, 0) \
|
||||
O(MathRound, math_round, Math, round, 1) \
|
||||
O(MathSqrt, math_sqrt, Math, sqrt, 1) \
|
||||
O(MathSin, math_sin, Math, sin, 1)
|
||||
O(MathSin, math_sin, Math, sin, 1) \
|
||||
O(MathCos, math_cos, Math, cos, 1)
|
||||
|
||||
enum class Builtin : u8 {
|
||||
#define DEFINE_BUILTIN_ENUM(name, ...) name,
|
||||
|
|
|
@ -2821,6 +2821,8 @@ static ThrowCompletionOr<Value> dispatch_builtin_call(Bytecode::Interpreter& int
|
|||
return TRY(MathObject::sqrt_impl(interpreter.vm(), interpreter.get(arguments[0])));
|
||||
case Builtin::MathSin:
|
||||
return TRY(MathObject::sin_impl(interpreter.vm(), interpreter.get(arguments[0])));
|
||||
case Builtin::MathCos:
|
||||
return TRY(MathObject::cos_impl(interpreter.vm(), interpreter.get(arguments[0])));
|
||||
case Bytecode::Builtin::__Count:
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ void MathObject::initialize(Realm& realm)
|
|||
define_native_function(realm, vm.names.min, min, 2, attr);
|
||||
define_native_function(realm, vm.names.trunc, trunc, 1, attr);
|
||||
define_native_function(realm, vm.names.sin, sin, 1, attr, Bytecode::Builtin::MathSin);
|
||||
define_native_function(realm, vm.names.cos, cos, 1, attr);
|
||||
define_native_function(realm, vm.names.cos, cos, 1, attr, Bytecode::Builtin::MathCos);
|
||||
define_native_function(realm, vm.names.tan, tan, 1, attr);
|
||||
define_native_function(realm, vm.names.pow, pow, 2, attr, Bytecode::Builtin::MathPow);
|
||||
define_native_function(realm, vm.names.exp, exp, 1, attr, Bytecode::Builtin::MathExp);
|
||||
|
@ -392,10 +392,10 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::clz32)
|
|||
}
|
||||
|
||||
// 21.3.2.12 Math.cos ( x ), https://tc39.es/ecma262/#sec-math.cos
|
||||
JS_DEFINE_NATIVE_FUNCTION(MathObject::cos)
|
||||
ThrowCompletionOr<Value> MathObject::cos_impl(VM& vm, Value value)
|
||||
{
|
||||
// 1. Let n be ? ToNumber(x).
|
||||
auto number = TRY(vm.argument(0).to_number(vm));
|
||||
auto number = TRY(value.to_number(vm));
|
||||
|
||||
// 2. If n is NaN, n is +∞𝔽, or n is -∞𝔽, return NaN.
|
||||
if (number.is_nan() || number.is_infinity())
|
||||
|
@ -409,6 +409,11 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::cos)
|
|||
return Value(::cos(number.as_double()));
|
||||
}
|
||||
|
||||
JS_DEFINE_NATIVE_FUNCTION(MathObject::cos)
|
||||
{
|
||||
return cos_impl(vm, vm.argument(0));
|
||||
}
|
||||
|
||||
// 21.3.2.13 Math.cosh ( x ), https://tc39.es/ecma262/#sec-math.cosh
|
||||
JS_DEFINE_NATIVE_FUNCTION(MathObject::cosh)
|
||||
{
|
||||
|
|
|
@ -29,6 +29,7 @@ public:
|
|||
static ThrowCompletionOr<Value> sum_precise_impl(VM&, Value);
|
||||
static ThrowCompletionOr<Value> imul_impl(VM&, Value, Value);
|
||||
static ThrowCompletionOr<Value> sin_impl(VM&, Value);
|
||||
static ThrowCompletionOr<Value> cos_impl(VM&, Value);
|
||||
|
||||
static Value random_impl();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue