From 9d2e90d5693ae9a76aa5b77bbab5e369478b9a91 Mon Sep 17 00:00:00 2001 From: Idan Horowitz Date: Sat, 5 Jun 2021 01:43:10 +0300 Subject: [PATCH] LibJS: Add Math.imul() --- Userland/Libraries/LibJS/Runtime/MathObject.cpp | 12 ++++++++++++ Userland/Libraries/LibJS/Runtime/MathObject.h | 1 + 2 files changed, 13 insertions(+) diff --git a/Userland/Libraries/LibJS/Runtime/MathObject.cpp b/Userland/Libraries/LibJS/Runtime/MathObject.cpp index c48c09916d..907f8f4048 100644 --- a/Userland/Libraries/LibJS/Runtime/MathObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/MathObject.cpp @@ -51,6 +51,7 @@ void MathObject::initialize(GlobalObject& global_object) define_native_function(vm.names.atan2, atan2, 2, attr); define_native_function(vm.names.fround, fround, 1, attr); define_native_function(vm.names.hypot, hypot, 2, attr); + define_native_function(vm.names.imul, imul, 2, attr); define_native_function(vm.names.log, log, 1, attr); define_native_function(vm.names.log2, log2, 1, attr); define_native_function(vm.names.log10, log10, 1, attr); @@ -428,6 +429,17 @@ JS_DEFINE_NATIVE_FUNCTION(MathObject::hypot) return Value(::sqrt(hypot.as_double())); } +JS_DEFINE_NATIVE_FUNCTION(MathObject::imul) +{ + auto a = vm.argument(0).to_u32(global_object); + if (vm.exception()) + return {}; + auto b = vm.argument(1).to_u32(global_object); + if (vm.exception()) + return {}; + return Value(static_cast(a * b)); +} + JS_DEFINE_NATIVE_FUNCTION(MathObject::log) { auto number = vm.argument(0).to_number(global_object); diff --git a/Userland/Libraries/LibJS/Runtime/MathObject.h b/Userland/Libraries/LibJS/Runtime/MathObject.h index 016c4c6541..16b139f65a 100644 --- a/Userland/Libraries/LibJS/Runtime/MathObject.h +++ b/Userland/Libraries/LibJS/Runtime/MathObject.h @@ -47,6 +47,7 @@ private: JS_DECLARE_NATIVE_FUNCTION(atan2); JS_DECLARE_NATIVE_FUNCTION(fround); JS_DECLARE_NATIVE_FUNCTION(hypot); + JS_DECLARE_NATIVE_FUNCTION(imul); JS_DECLARE_NATIVE_FUNCTION(log); JS_DECLARE_NATIVE_FUNCTION(log2); JS_DECLARE_NATIVE_FUNCTION(log10);