浏览代码

LibJS: Convert MathObject functions to ThrowCompletionOr

Idan Horowitz 3 年之前
父节点
当前提交
23ea1f1a3e
共有 2 个文件被更改,包括 142 次插入142 次删除
  1. 107 107
      Userland/Libraries/LibJS/Runtime/MathObject.cpp
  2. 35 35
      Userland/Libraries/LibJS/Runtime/MathObject.h

+ 107 - 107
Userland/Libraries/LibJS/Runtime/MathObject.cpp

@@ -24,41 +24,41 @@ void MathObject::initialize(GlobalObject& global_object)
     auto& vm = this->vm();
     Object::initialize(global_object);
     u8 attr = Attribute::Writable | Attribute::Configurable;
-    define_old_native_function(vm.names.abs, abs, 1, attr);
-    define_old_native_function(vm.names.random, random, 0, attr);
-    define_old_native_function(vm.names.sqrt, sqrt, 1, attr);
-    define_old_native_function(vm.names.floor, floor, 1, attr);
-    define_old_native_function(vm.names.ceil, ceil, 1, attr);
-    define_old_native_function(vm.names.round, round, 1, attr);
-    define_old_native_function(vm.names.max, max, 2, attr);
-    define_old_native_function(vm.names.min, min, 2, attr);
-    define_old_native_function(vm.names.trunc, trunc, 1, attr);
-    define_old_native_function(vm.names.sin, sin, 1, attr);
-    define_old_native_function(vm.names.cos, cos, 1, attr);
-    define_old_native_function(vm.names.tan, tan, 1, attr);
-    define_old_native_function(vm.names.pow, pow, 2, attr);
-    define_old_native_function(vm.names.exp, exp, 1, attr);
-    define_old_native_function(vm.names.expm1, expm1, 1, attr);
-    define_old_native_function(vm.names.sign, sign, 1, attr);
-    define_old_native_function(vm.names.clz32, clz32, 1, attr);
-    define_old_native_function(vm.names.acos, acos, 1, attr);
-    define_old_native_function(vm.names.acosh, acosh, 1, attr);
-    define_old_native_function(vm.names.asin, asin, 1, attr);
-    define_old_native_function(vm.names.asinh, asinh, 1, attr);
-    define_old_native_function(vm.names.atan, atan, 1, attr);
-    define_old_native_function(vm.names.atanh, atanh, 1, attr);
-    define_old_native_function(vm.names.log1p, log1p, 1, attr);
-    define_old_native_function(vm.names.cbrt, cbrt, 1, attr);
-    define_old_native_function(vm.names.atan2, atan2, 2, attr);
-    define_old_native_function(vm.names.fround, fround, 1, attr);
-    define_old_native_function(vm.names.hypot, hypot, 2, attr);
-    define_old_native_function(vm.names.imul, imul, 2, attr);
-    define_old_native_function(vm.names.log, log, 1, attr);
-    define_old_native_function(vm.names.log2, log2, 1, attr);
-    define_old_native_function(vm.names.log10, log10, 1, attr);
-    define_old_native_function(vm.names.sinh, sinh, 1, attr);
-    define_old_native_function(vm.names.cosh, cosh, 1, attr);
-    define_old_native_function(vm.names.tanh, tanh, 1, attr);
+    define_native_function(vm.names.abs, abs, 1, attr);
+    define_native_function(vm.names.random, random, 0, attr);
+    define_native_function(vm.names.sqrt, sqrt, 1, attr);
+    define_native_function(vm.names.floor, floor, 1, attr);
+    define_native_function(vm.names.ceil, ceil, 1, attr);
+    define_native_function(vm.names.round, round, 1, attr);
+    define_native_function(vm.names.max, max, 2, attr);
+    define_native_function(vm.names.min, min, 2, attr);
+    define_native_function(vm.names.trunc, trunc, 1, attr);
+    define_native_function(vm.names.sin, sin, 1, attr);
+    define_native_function(vm.names.cos, cos, 1, attr);
+    define_native_function(vm.names.tan, tan, 1, attr);
+    define_native_function(vm.names.pow, pow, 2, attr);
+    define_native_function(vm.names.exp, exp, 1, attr);
+    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);
+    define_native_function(vm.names.log1p, log1p, 1, attr);
+    define_native_function(vm.names.cbrt, cbrt, 1, attr);
+    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);
+    define_native_function(vm.names.sinh, sinh, 1, attr);
+    define_native_function(vm.names.cosh, cosh, 1, attr);
+    define_native_function(vm.names.tanh, tanh, 1, attr);
 
     // 21.3.1 Value Properties of the Math Object, https://tc39.es/ecma262/#sec-value-properties-of-the-math-object
     define_direct_property(vm.names.E, Value(M_E), 0);
@@ -79,9 +79,9 @@ MathObject::~MathObject()
 }
 
 // 21.3.2.1 Math.abs ( x ), https://tc39.es/ecma262/#sec-math.abs
-JS_DEFINE_OLD_NATIVE_FUNCTION(MathObject::abs)
+JS_DEFINE_NATIVE_FUNCTION(MathObject::abs)
 {
-    auto number = TRY_OR_DISCARD(vm.argument(0).to_number(global_object));
+    auto number = TRY(vm.argument(0).to_number(global_object));
     if (number.is_nan())
         return js_nan();
     if (number.is_negative_zero())
@@ -92,34 +92,34 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(MathObject::abs)
 }
 
 // 21.3.2.27 Math.random ( ), https://tc39.es/ecma262/#sec-math.random
-JS_DEFINE_OLD_NATIVE_FUNCTION(MathObject::random)
+JS_DEFINE_NATIVE_FUNCTION(MathObject::random)
 {
     double r = (double)get_random<u32>() / (double)UINT32_MAX;
     return Value(r);
 }
 
 // 21.3.2.32 Math.sqrt ( x ), https://tc39.es/ecma262/#sec-math.sqrt
-JS_DEFINE_OLD_NATIVE_FUNCTION(MathObject::sqrt)
+JS_DEFINE_NATIVE_FUNCTION(MathObject::sqrt)
 {
-    auto number = TRY_OR_DISCARD(vm.argument(0).to_number(global_object));
+    auto number = TRY(vm.argument(0).to_number(global_object));
     if (number.is_nan())
         return js_nan();
     return Value(::sqrt(number.as_double()));
 }
 
 // 21.3.2.16 Math.floor ( x ), https://tc39.es/ecma262/#sec-math.floor
-JS_DEFINE_OLD_NATIVE_FUNCTION(MathObject::floor)
+JS_DEFINE_NATIVE_FUNCTION(MathObject::floor)
 {
-    auto number = TRY_OR_DISCARD(vm.argument(0).to_number(global_object));
+    auto number = TRY(vm.argument(0).to_number(global_object));
     if (number.is_nan())
         return js_nan();
     return Value(::floor(number.as_double()));
 }
 
 // 21.3.2.10 Math.ceil ( x ), https://tc39.es/ecma262/#sec-math.ceil
-JS_DEFINE_OLD_NATIVE_FUNCTION(MathObject::ceil)
+JS_DEFINE_NATIVE_FUNCTION(MathObject::ceil)
 {
-    auto number = TRY_OR_DISCARD(vm.argument(0).to_number(global_object));
+    auto number = TRY(vm.argument(0).to_number(global_object));
     if (number.is_nan())
         return js_nan();
     auto number_double = number.as_double();
@@ -129,9 +129,9 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(MathObject::ceil)
 }
 
 // 21.3.2.28 Math.round ( x ), https://tc39.es/ecma262/#sec-math.round
-JS_DEFINE_OLD_NATIVE_FUNCTION(MathObject::round)
+JS_DEFINE_NATIVE_FUNCTION(MathObject::round)
 {
-    auto value = TRY_OR_DISCARD(vm.argument(0).to_number(global_object)).as_double();
+    auto value = TRY(vm.argument(0).to_number(global_object)).as_double();
     double integer = ::ceil(value);
     if (integer - 0.5 > value)
         integer--;
@@ -139,11 +139,11 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(MathObject::round)
 }
 
 // 21.3.2.24 Math.max ( ...args ), https://tc39.es/ecma262/#sec-math.max
-JS_DEFINE_OLD_NATIVE_FUNCTION(MathObject::max)
+JS_DEFINE_NATIVE_FUNCTION(MathObject::max)
 {
     Vector<Value> coerced;
     for (size_t i = 0; i < vm.argument_count(); ++i)
-        coerced.append(TRY_OR_DISCARD(vm.argument(i).to_number(global_object)));
+        coerced.append(TRY(vm.argument(i).to_number(global_object)));
 
     auto highest = js_negative_infinity();
     for (auto& number : coerced) {
@@ -156,11 +156,11 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(MathObject::max)
 }
 
 // 21.3.2.25 Math.min ( ...args ), https://tc39.es/ecma262/#sec-math.min
-JS_DEFINE_OLD_NATIVE_FUNCTION(MathObject::min)
+JS_DEFINE_NATIVE_FUNCTION(MathObject::min)
 {
     Vector<Value> coerced;
     for (size_t i = 0; i < vm.argument_count(); ++i)
-        coerced.append(TRY_OR_DISCARD(vm.argument(i).to_number(global_object)));
+        coerced.append(TRY(vm.argument(i).to_number(global_object)));
 
     auto lowest = js_infinity();
     for (auto& number : coerced) {
@@ -173,9 +173,9 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(MathObject::min)
 }
 
 // 21.3.2.35 Math.trunc ( x ), https://tc39.es/ecma262/#sec-math.trunc
-JS_DEFINE_OLD_NATIVE_FUNCTION(MathObject::trunc)
+JS_DEFINE_NATIVE_FUNCTION(MathObject::trunc)
 {
-    auto number = TRY_OR_DISCARD(vm.argument(0).to_number(global_object));
+    auto number = TRY(vm.argument(0).to_number(global_object));
     if (number.is_nan())
         return js_nan();
     if (number.as_double() < 0)
@@ -184,37 +184,37 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(MathObject::trunc)
 }
 
 // 21.3.2.30 Math.sin ( x ), https://tc39.es/ecma262/#sec-math.sin
-JS_DEFINE_OLD_NATIVE_FUNCTION(MathObject::sin)
+JS_DEFINE_NATIVE_FUNCTION(MathObject::sin)
 {
-    auto number = TRY_OR_DISCARD(vm.argument(0).to_number(global_object));
+    auto number = TRY(vm.argument(0).to_number(global_object));
     if (number.is_nan())
         return js_nan();
     return Value(::sin(number.as_double()));
 }
 
 // 21.3.2.12 Math.cos ( x ), https://tc39.es/ecma262/#sec-math.cos
-JS_DEFINE_OLD_NATIVE_FUNCTION(MathObject::cos)
+JS_DEFINE_NATIVE_FUNCTION(MathObject::cos)
 {
-    auto number = TRY_OR_DISCARD(vm.argument(0).to_number(global_object));
+    auto number = TRY(vm.argument(0).to_number(global_object));
     if (number.is_nan())
         return js_nan();
     return Value(::cos(number.as_double()));
 }
 
 // 21.3.2.33 Math.tan ( x ), https://tc39.es/ecma262/#sec-math.tan
-JS_DEFINE_OLD_NATIVE_FUNCTION(MathObject::tan)
+JS_DEFINE_NATIVE_FUNCTION(MathObject::tan)
 {
-    auto number = TRY_OR_DISCARD(vm.argument(0).to_number(global_object));
+    auto number = TRY(vm.argument(0).to_number(global_object));
     if (number.is_nan())
         return js_nan();
     return Value(::tan(number.as_double()));
 }
 
 // 21.3.2.26 Math.pow ( base, exponent ), https://tc39.es/ecma262/#sec-math.pow
-JS_DEFINE_OLD_NATIVE_FUNCTION(MathObject::pow)
+JS_DEFINE_NATIVE_FUNCTION(MathObject::pow)
 {
-    auto base = TRY_OR_DISCARD(vm.argument(0).to_number(global_object));
-    auto exponent = TRY_OR_DISCARD(vm.argument(1).to_number(global_object));
+    auto base = TRY(vm.argument(0).to_number(global_object));
+    auto exponent = TRY(vm.argument(1).to_number(global_object));
     if (exponent.is_nan())
         return js_nan();
     if (exponent.is_positive_zero() || exponent.is_negative_zero())
@@ -265,27 +265,27 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(MathObject::pow)
 }
 
 // 21.3.2.14 Math.exp ( x ), https://tc39.es/ecma262/#sec-math.exp
-JS_DEFINE_OLD_NATIVE_FUNCTION(MathObject::exp)
+JS_DEFINE_NATIVE_FUNCTION(MathObject::exp)
 {
-    auto number = TRY_OR_DISCARD(vm.argument(0).to_number(global_object));
+    auto number = TRY(vm.argument(0).to_number(global_object));
     if (number.is_nan())
         return js_nan();
     return Value(::exp(number.as_double()));
 }
 
 // 21.3.2.15 Math.expm1 ( x ), https://tc39.es/ecma262/#sec-math.expm1
-JS_DEFINE_OLD_NATIVE_FUNCTION(MathObject::expm1)
+JS_DEFINE_NATIVE_FUNCTION(MathObject::expm1)
 {
-    auto number = TRY_OR_DISCARD(vm.argument(0).to_number(global_object));
+    auto number = TRY(vm.argument(0).to_number(global_object));
     if (number.is_nan())
         return js_nan();
     return Value(::expm1(number.as_double()));
 }
 
 // 21.3.2.29 Math.sign ( x ), https://tc39.es/ecma262/#sec-math.sign
-JS_DEFINE_OLD_NATIVE_FUNCTION(MathObject::sign)
+JS_DEFINE_NATIVE_FUNCTION(MathObject::sign)
 {
-    auto number = TRY_OR_DISCARD(vm.argument(0).to_number(global_object));
+    auto number = TRY(vm.argument(0).to_number(global_object));
     if (number.is_positive_zero())
         return Value(0);
     if (number.is_negative_zero())
@@ -298,18 +298,18 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(MathObject::sign)
 }
 
 // 21.3.2.11 Math.clz32 ( x ), https://tc39.es/ecma262/#sec-math.clz32
-JS_DEFINE_OLD_NATIVE_FUNCTION(MathObject::clz32)
+JS_DEFINE_NATIVE_FUNCTION(MathObject::clz32)
 {
-    auto number = TRY_OR_DISCARD(vm.argument(0).to_u32(global_object));
+    auto number = TRY(vm.argument(0).to_u32(global_object));
     if (number == 0)
         return Value(32);
     return Value(__builtin_clz(number));
 }
 
 // 21.3.2.2 Math.acos ( x ), https://tc39.es/ecma262/#sec-math.acos
-JS_DEFINE_OLD_NATIVE_FUNCTION(MathObject::acos)
+JS_DEFINE_NATIVE_FUNCTION(MathObject::acos)
 {
-    auto number = TRY_OR_DISCARD(vm.argument(0).to_number(global_object));
+    auto number = TRY(vm.argument(0).to_number(global_object));
     if (number.is_nan() || number.as_double() > 1 || number.as_double() < -1)
         return js_nan();
     if (number.as_double() == 1)
@@ -318,33 +318,33 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(MathObject::acos)
 }
 
 // 21.3.2.3 Math.acosh ( x ), https://tc39.es/ecma262/#sec-math.acosh
-JS_DEFINE_OLD_NATIVE_FUNCTION(MathObject::acosh)
+JS_DEFINE_NATIVE_FUNCTION(MathObject::acosh)
 {
-    auto value = TRY_OR_DISCARD(vm.argument(0).to_number(global_object)).as_double();
+    auto value = TRY(vm.argument(0).to_number(global_object)).as_double();
     if (value < 1)
         return js_nan();
     return Value(::acosh(value));
 }
 
 // 21.3.2.4 Math.asin ( x ), https://tc39.es/ecma262/#sec-math.asin
-JS_DEFINE_OLD_NATIVE_FUNCTION(MathObject::asin)
+JS_DEFINE_NATIVE_FUNCTION(MathObject::asin)
 {
-    auto number = TRY_OR_DISCARD(vm.argument(0).to_number(global_object));
+    auto number = TRY(vm.argument(0).to_number(global_object));
     if (number.is_nan() || number.is_positive_zero() || number.is_negative_zero())
         return number;
     return Value(::asin(number.as_double()));
 }
 
 // 21.3.2.5 Math.asinh ( x ), https://tc39.es/ecma262/#sec-math.asinh
-JS_DEFINE_OLD_NATIVE_FUNCTION(MathObject::asinh)
+JS_DEFINE_NATIVE_FUNCTION(MathObject::asinh)
 {
-    return Value(::asinh(TRY_OR_DISCARD(vm.argument(0).to_number(global_object)).as_double()));
+    return Value(::asinh(TRY(vm.argument(0).to_number(global_object)).as_double()));
 }
 
 // 21.3.2.6 Math.atan ( x ), https://tc39.es/ecma262/#sec-math.atan
-JS_DEFINE_OLD_NATIVE_FUNCTION(MathObject::atan)
+JS_DEFINE_NATIVE_FUNCTION(MathObject::atan)
 {
-    auto number = TRY_OR_DISCARD(vm.argument(0).to_number(global_object));
+    auto number = TRY(vm.argument(0).to_number(global_object));
     if (number.is_nan() || number.is_positive_zero() || number.is_negative_zero())
         return number;
     if (number.is_positive_infinity())
@@ -355,36 +355,36 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(MathObject::atan)
 }
 
 // 21.3.2.7 Math.atanh ( x ), https://tc39.es/ecma262/#sec-math.atanh
-JS_DEFINE_OLD_NATIVE_FUNCTION(MathObject::atanh)
+JS_DEFINE_NATIVE_FUNCTION(MathObject::atanh)
 {
-    auto value = TRY_OR_DISCARD(vm.argument(0).to_number(global_object)).as_double();
+    auto value = TRY(vm.argument(0).to_number(global_object)).as_double();
     if (value > 1 || value < -1)
         return js_nan();
     return Value(::atanh(value));
 }
 
 // 21.3.2.21 Math.log1p ( x ), https://tc39.es/ecma262/#sec-math.log1p
-JS_DEFINE_OLD_NATIVE_FUNCTION(MathObject::log1p)
+JS_DEFINE_NATIVE_FUNCTION(MathObject::log1p)
 {
-    auto value = TRY_OR_DISCARD(vm.argument(0).to_number(global_object)).as_double();
+    auto value = TRY(vm.argument(0).to_number(global_object)).as_double();
     if (value < -1)
         return js_nan();
     return Value(::log1p(value));
 }
 
 // 21.3.2.9 Math.cbrt ( x ), https://tc39.es/ecma262/#sec-math.cbrt
-JS_DEFINE_OLD_NATIVE_FUNCTION(MathObject::cbrt)
+JS_DEFINE_NATIVE_FUNCTION(MathObject::cbrt)
 {
-    return Value(::cbrt(TRY_OR_DISCARD(vm.argument(0).to_number(global_object)).as_double()));
+    return Value(::cbrt(TRY(vm.argument(0).to_number(global_object)).as_double()));
 }
 
 // 21.3.2.8 Math.atan2 ( y, x ), https://tc39.es/ecma262/#sec-math.atan2
-JS_DEFINE_OLD_NATIVE_FUNCTION(MathObject::atan2)
+JS_DEFINE_NATIVE_FUNCTION(MathObject::atan2)
 {
     auto constexpr three_quarters_pi = M_PI_4 + M_PI_2;
 
-    auto y = TRY_OR_DISCARD(vm.argument(0).to_number(global_object));
-    auto x = TRY_OR_DISCARD(vm.argument(1).to_number(global_object));
+    auto y = TRY(vm.argument(0).to_number(global_object));
+    auto x = TRY(vm.argument(1).to_number(global_object));
 
     if (y.is_nan() || x.is_nan())
         return js_nan();
@@ -438,20 +438,20 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(MathObject::atan2)
 }
 
 // 21.3.2.17 Math.fround ( x ), https://tc39.es/ecma262/#sec-math.fround
-JS_DEFINE_OLD_NATIVE_FUNCTION(MathObject::fround)
+JS_DEFINE_NATIVE_FUNCTION(MathObject::fround)
 {
-    auto number = TRY_OR_DISCARD(vm.argument(0).to_number(global_object));
+    auto number = TRY(vm.argument(0).to_number(global_object));
     if (number.is_nan())
         return js_nan();
     return Value((float)number.as_double());
 }
 
 // 21.3.2.18 Math.hypot ( ...args ), https://tc39.es/ecma262/#sec-math.hypot
-JS_DEFINE_OLD_NATIVE_FUNCTION(MathObject::hypot)
+JS_DEFINE_NATIVE_FUNCTION(MathObject::hypot)
 {
     Vector<Value> coerced;
     for (size_t i = 0; i < vm.argument_count(); ++i)
-        coerced.append(TRY_OR_DISCARD(vm.argument(i).to_number(global_object)));
+        coerced.append(TRY(vm.argument(i).to_number(global_object)));
 
     for (auto& number : coerced) {
         if (number.is_positive_infinity() || number.is_negative_infinity())
@@ -475,62 +475,62 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(MathObject::hypot)
 }
 
 // 21.3.2.19 Math.imul ( x, y ), https://tc39.es/ecma262/#sec-math.imul
-JS_DEFINE_OLD_NATIVE_FUNCTION(MathObject::imul)
+JS_DEFINE_NATIVE_FUNCTION(MathObject::imul)
 {
-    auto a = TRY_OR_DISCARD(vm.argument(0).to_u32(global_object));
-    auto b = TRY_OR_DISCARD(vm.argument(1).to_u32(global_object));
+    auto a = TRY(vm.argument(0).to_u32(global_object));
+    auto b = TRY(vm.argument(1).to_u32(global_object));
     return Value(static_cast<i32>(a * b));
 }
 
 // 21.3.2.20 Math.log ( x ), https://tc39.es/ecma262/#sec-math.log
-JS_DEFINE_OLD_NATIVE_FUNCTION(MathObject::log)
+JS_DEFINE_NATIVE_FUNCTION(MathObject::log)
 {
-    auto value = TRY_OR_DISCARD(vm.argument(0).to_number(global_object)).as_double();
+    auto value = TRY(vm.argument(0).to_number(global_object)).as_double();
     if (value < 0)
         return js_nan();
     return Value(::log(value));
 }
 
 // 21.3.2.23 Math.log2 ( x ), https://tc39.es/ecma262/#sec-math.log2
-JS_DEFINE_OLD_NATIVE_FUNCTION(MathObject::log2)
+JS_DEFINE_NATIVE_FUNCTION(MathObject::log2)
 {
-    auto value = TRY_OR_DISCARD(vm.argument(0).to_number(global_object)).as_double();
+    auto value = TRY(vm.argument(0).to_number(global_object)).as_double();
     if (value < 0)
         return js_nan();
     return Value(::log2(value));
 }
 
 // 21.3.2.22 Math.log10 ( x ), https://tc39.es/ecma262/#sec-math.log10
-JS_DEFINE_OLD_NATIVE_FUNCTION(MathObject::log10)
+JS_DEFINE_NATIVE_FUNCTION(MathObject::log10)
 {
-    auto value = TRY_OR_DISCARD(vm.argument(0).to_number(global_object)).as_double();
+    auto value = TRY(vm.argument(0).to_number(global_object)).as_double();
     if (value < 0)
         return js_nan();
     return Value(::log10(value));
 }
 
 // 21.3.2.31 Math.sinh ( x ), https://tc39.es/ecma262/#sec-math.sinh
-JS_DEFINE_OLD_NATIVE_FUNCTION(MathObject::sinh)
+JS_DEFINE_NATIVE_FUNCTION(MathObject::sinh)
 {
-    auto number = TRY_OR_DISCARD(vm.argument(0).to_number(global_object));
+    auto number = TRY(vm.argument(0).to_number(global_object));
     if (number.is_nan())
         return js_nan();
     return Value(::sinh(number.as_double()));
 }
 
 // 21.3.2.13 Math.cosh ( x ), https://tc39.es/ecma262/#sec-math.cosh
-JS_DEFINE_OLD_NATIVE_FUNCTION(MathObject::cosh)
+JS_DEFINE_NATIVE_FUNCTION(MathObject::cosh)
 {
-    auto number = TRY_OR_DISCARD(vm.argument(0).to_number(global_object));
+    auto number = TRY(vm.argument(0).to_number(global_object));
     if (number.is_nan())
         return js_nan();
     return Value(::cosh(number.as_double()));
 }
 
 // 21.3.2.34 Math.tanh ( x ), https://tc39.es/ecma262/#sec-math.tanh
-JS_DEFINE_OLD_NATIVE_FUNCTION(MathObject::tanh)
+JS_DEFINE_NATIVE_FUNCTION(MathObject::tanh)
 {
-    auto number = TRY_OR_DISCARD(vm.argument(0).to_number(global_object));
+    auto number = TRY(vm.argument(0).to_number(global_object));
     if (number.is_nan())
         return js_nan();
     if (number.is_positive_infinity())

+ 35 - 35
Userland/Libraries/LibJS/Runtime/MathObject.h

@@ -19,41 +19,41 @@ public:
     virtual ~MathObject() override;
 
 private:
-    JS_DECLARE_OLD_NATIVE_FUNCTION(abs);
-    JS_DECLARE_OLD_NATIVE_FUNCTION(random);
-    JS_DECLARE_OLD_NATIVE_FUNCTION(sqrt);
-    JS_DECLARE_OLD_NATIVE_FUNCTION(floor);
-    JS_DECLARE_OLD_NATIVE_FUNCTION(ceil);
-    JS_DECLARE_OLD_NATIVE_FUNCTION(round);
-    JS_DECLARE_OLD_NATIVE_FUNCTION(max);
-    JS_DECLARE_OLD_NATIVE_FUNCTION(min);
-    JS_DECLARE_OLD_NATIVE_FUNCTION(trunc);
-    JS_DECLARE_OLD_NATIVE_FUNCTION(sin);
-    JS_DECLARE_OLD_NATIVE_FUNCTION(cos);
-    JS_DECLARE_OLD_NATIVE_FUNCTION(tan);
-    JS_DECLARE_OLD_NATIVE_FUNCTION(pow);
-    JS_DECLARE_OLD_NATIVE_FUNCTION(exp);
-    JS_DECLARE_OLD_NATIVE_FUNCTION(expm1);
-    JS_DECLARE_OLD_NATIVE_FUNCTION(sign);
-    JS_DECLARE_OLD_NATIVE_FUNCTION(clz32);
-    JS_DECLARE_OLD_NATIVE_FUNCTION(acos);
-    JS_DECLARE_OLD_NATIVE_FUNCTION(acosh);
-    JS_DECLARE_OLD_NATIVE_FUNCTION(asin);
-    JS_DECLARE_OLD_NATIVE_FUNCTION(asinh);
-    JS_DECLARE_OLD_NATIVE_FUNCTION(atan);
-    JS_DECLARE_OLD_NATIVE_FUNCTION(atanh);
-    JS_DECLARE_OLD_NATIVE_FUNCTION(log1p);
-    JS_DECLARE_OLD_NATIVE_FUNCTION(cbrt);
-    JS_DECLARE_OLD_NATIVE_FUNCTION(atan2);
-    JS_DECLARE_OLD_NATIVE_FUNCTION(fround);
-    JS_DECLARE_OLD_NATIVE_FUNCTION(hypot);
-    JS_DECLARE_OLD_NATIVE_FUNCTION(imul);
-    JS_DECLARE_OLD_NATIVE_FUNCTION(log);
-    JS_DECLARE_OLD_NATIVE_FUNCTION(log2);
-    JS_DECLARE_OLD_NATIVE_FUNCTION(log10);
-    JS_DECLARE_OLD_NATIVE_FUNCTION(sinh);
-    JS_DECLARE_OLD_NATIVE_FUNCTION(cosh);
-    JS_DECLARE_OLD_NATIVE_FUNCTION(tanh);
+    JS_DECLARE_NATIVE_FUNCTION(abs);
+    JS_DECLARE_NATIVE_FUNCTION(random);
+    JS_DECLARE_NATIVE_FUNCTION(sqrt);
+    JS_DECLARE_NATIVE_FUNCTION(floor);
+    JS_DECLARE_NATIVE_FUNCTION(ceil);
+    JS_DECLARE_NATIVE_FUNCTION(round);
+    JS_DECLARE_NATIVE_FUNCTION(max);
+    JS_DECLARE_NATIVE_FUNCTION(min);
+    JS_DECLARE_NATIVE_FUNCTION(trunc);
+    JS_DECLARE_NATIVE_FUNCTION(sin);
+    JS_DECLARE_NATIVE_FUNCTION(cos);
+    JS_DECLARE_NATIVE_FUNCTION(tan);
+    JS_DECLARE_NATIVE_FUNCTION(pow);
+    JS_DECLARE_NATIVE_FUNCTION(exp);
+    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);
+    JS_DECLARE_NATIVE_FUNCTION(log1p);
+    JS_DECLARE_NATIVE_FUNCTION(cbrt);
+    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);
+    JS_DECLARE_NATIVE_FUNCTION(sinh);
+    JS_DECLARE_NATIVE_FUNCTION(cosh);
+    JS_DECLARE_NATIVE_FUNCTION(tanh);
 };
 
 }