diff --git a/Libraries/LibJS/Runtime/CommonPropertyNames.h b/Libraries/LibJS/Runtime/CommonPropertyNames.h index c79625caee..6037687e40 100644 --- a/Libraries/LibJS/Runtime/CommonPropertyNames.h +++ b/Libraries/LibJS/Runtime/CommonPropertyNames.h @@ -60,11 +60,13 @@ namespace JS { P(Symbol) \ P(UTC) \ P(abs) \ + P(acos) \ P(acosh) \ P(apply) \ P(arguments) \ P(asIntN) \ P(asUintN) \ + P(asin) \ P(asinh) \ P(atan) \ P(atanh) \ diff --git a/Libraries/LibJS/Runtime/MathObject.cpp b/Libraries/LibJS/Runtime/MathObject.cpp index 177229a069..c4057f30ff 100644 --- a/Libraries/LibJS/Runtime/MathObject.cpp +++ b/Libraries/LibJS/Runtime/MathObject.cpp @@ -60,7 +60,9 @@ void MathObject::initialize(GlobalObject& global_object) define_native_function(vm.names.expm1, expm1, 1, attr); define_native_function(vm.names.sign, sign, 1, attr); define_native_function(vm.names.clz32, clz32, 1, attr); + define_native_function(vm.names.acos, acos, 1, attr); define_native_function(vm.names.acosh, acosh, 1, attr); + define_native_function(vm.names.asin, asin, 1, attr); define_native_function(vm.names.asinh, asinh, 1, attr); define_native_function(vm.names.atan, atan, 1, attr); define_native_function(vm.names.atanh, atanh, 1, attr); @@ -273,6 +275,18 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::clz32) return Value(__builtin_clz((unsigned)number.as_double())); } +JS_DEFINE_NATIVE_FUNCTION(MathObject::acos) +{ + auto number = vm.argument(0).to_number(global_object); + if (vm.exception()) + return {}; + if (number.is_nan() || number.as_double() > 1 || number.as_double() < -1) + return js_nan(); + if (number.as_double() == 1) + return Value(0); + return Value(::acos(number.as_double())); +} + JS_DEFINE_NATIVE_FUNCTION(MathObject::acosh) { auto number = vm.argument(0).to_number(global_object); @@ -283,6 +297,16 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::acosh) return Value(::acosh(number.as_double())); } +JS_DEFINE_NATIVE_FUNCTION(MathObject::asin) +{ + auto number = vm.argument(0).to_number(global_object); + if (vm.exception()) + return {}; + if (number.is_nan() || number.is_positive_zero() || number.is_negative_zero()) + return number; + return Value(::asin(number.as_double())); +} + JS_DEFINE_NATIVE_FUNCTION(MathObject::asinh) { auto number = vm.argument(0).to_number(global_object); diff --git a/Libraries/LibJS/Runtime/MathObject.h b/Libraries/LibJS/Runtime/MathObject.h index cf84b28344..ff5f779775 100644 --- a/Libraries/LibJS/Runtime/MathObject.h +++ b/Libraries/LibJS/Runtime/MathObject.h @@ -56,7 +56,9 @@ private: JS_DECLARE_NATIVE_FUNCTION(expm1); JS_DECLARE_NATIVE_FUNCTION(sign); JS_DECLARE_NATIVE_FUNCTION(clz32); + JS_DECLARE_NATIVE_FUNCTION(acos); JS_DECLARE_NATIVE_FUNCTION(acosh); + JS_DECLARE_NATIVE_FUNCTION(asin); JS_DECLARE_NATIVE_FUNCTION(asinh); JS_DECLARE_NATIVE_FUNCTION(atan); JS_DECLARE_NATIVE_FUNCTION(atanh);