Idan Horowitz 4 роки тому
батько
коміт
9d2e90d569

+ 12 - 0
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.atan2, atan2, 2, attr);
     define_native_function(vm.names.fround, fround, 1, attr);
     define_native_function(vm.names.fround, fround, 1, attr);
     define_native_function(vm.names.hypot, hypot, 2, 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.log, log, 1, attr);
     define_native_function(vm.names.log2, log2, 1, attr);
     define_native_function(vm.names.log2, log2, 1, attr);
     define_native_function(vm.names.log10, log10, 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()));
     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<i32>(a * b));
+}
+
 JS_DEFINE_NATIVE_FUNCTION(MathObject::log)
 JS_DEFINE_NATIVE_FUNCTION(MathObject::log)
 {
 {
     auto number = vm.argument(0).to_number(global_object);
     auto number = vm.argument(0).to_number(global_object);

+ 1 - 0
Userland/Libraries/LibJS/Runtime/MathObject.h

@@ -47,6 +47,7 @@ private:
     JS_DECLARE_NATIVE_FUNCTION(atan2);
     JS_DECLARE_NATIVE_FUNCTION(atan2);
     JS_DECLARE_NATIVE_FUNCTION(fround);
     JS_DECLARE_NATIVE_FUNCTION(fround);
     JS_DECLARE_NATIVE_FUNCTION(hypot);
     JS_DECLARE_NATIVE_FUNCTION(hypot);
+    JS_DECLARE_NATIVE_FUNCTION(imul);
     JS_DECLARE_NATIVE_FUNCTION(log);
     JS_DECLARE_NATIVE_FUNCTION(log);
     JS_DECLARE_NATIVE_FUNCTION(log2);
     JS_DECLARE_NATIVE_FUNCTION(log2);
     JS_DECLARE_NATIVE_FUNCTION(log10);
     JS_DECLARE_NATIVE_FUNCTION(log10);