mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-24 18:02:20 +00:00
LibJS: Use CallBuiltin for Math.sin()
Improves performance on https://pierre.co/
This commit is contained in:
parent
04fac0031c
commit
c02535e9f9
Notes:
github-actions[bot]
2025-05-26 19:53:53 +00:00
Author: https://github.com/kalenikaliaksandr
Commit: c02535e9f9
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4884
Reviewed-by: https://github.com/awesomekling ✅
4 changed files with 14 additions and 4 deletions
|
@ -42,7 +42,7 @@ void MathObject::initialize(Realm& realm)
|
|||
define_native_function(realm, vm.names.max, max, 2, attr);
|
||||
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);
|
||||
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.tan, tan, 1, attr);
|
||||
define_native_function(realm, vm.names.pow, pow, 2, attr, Bytecode::Builtin::MathPow);
|
||||
|
@ -905,10 +905,10 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::sign)
|
|||
}
|
||||
|
||||
// 21.3.2.31 Math.sin ( x ), https://tc39.es/ecma262/#sec-math.sin
|
||||
JS_DEFINE_NATIVE_FUNCTION(MathObject::sin)
|
||||
ThrowCompletionOr<Value> MathObject::sin_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 +0𝔽, or n is -0𝔽, return n.
|
||||
if (number.is_nan() || number.is_positive_zero() || number.is_negative_zero())
|
||||
|
@ -922,6 +922,11 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::sin)
|
|||
return Value(::sin(number.as_double()));
|
||||
}
|
||||
|
||||
JS_DEFINE_NATIVE_FUNCTION(MathObject::sin)
|
||||
{
|
||||
return sin_impl(vm, vm.argument(0));
|
||||
}
|
||||
|
||||
// 21.3.2.32 Math.sinh ( x ), https://tc39.es/ecma262/#sec-math.sinh
|
||||
JS_DEFINE_NATIVE_FUNCTION(MathObject::sinh)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue