Fix the builtin Math.min and Math.max function
JerryScript-DCO-1.0-Signed-off-by: Kristof Kosztyo kkosztyo.u-szeged@partner.samsung.com
This commit is contained in:
@@ -332,20 +332,20 @@ ecma_builtin_math_object_max (ecma_value_t this_arg __attr_unused___, /**< 'this
|
|||||||
|
|
||||||
ecma_number_t ret_num = ecma_number_make_infinity (true);
|
ecma_number_t ret_num = ecma_number_make_infinity (true);
|
||||||
|
|
||||||
bool is_just_convert = false;
|
bool is_NaN = false;
|
||||||
|
|
||||||
for (ecma_length_t arg_index = 0;
|
for (ecma_length_t arg_index = 0;
|
||||||
arg_index < args_number;
|
arg_index < args_number && ecma_is_completion_value_empty (ret_value);
|
||||||
arg_index++)
|
arg_index++)
|
||||||
{
|
{
|
||||||
ECMA_OP_TO_NUMBER_TRY_CATCH (arg_num, args[arg_index], ret_value);
|
ECMA_OP_TO_NUMBER_TRY_CATCH (arg_num, args[arg_index], ret_value);
|
||||||
|
|
||||||
if (!is_just_convert)
|
if (!is_NaN)
|
||||||
{
|
{
|
||||||
if (unlikely (ecma_number_is_nan (arg_num)))
|
if (unlikely (ecma_number_is_nan (arg_num)))
|
||||||
{
|
{
|
||||||
ret_num = arg_num;
|
ret_num = arg_num;
|
||||||
is_just_convert = true;
|
is_NaN = true;
|
||||||
}
|
}
|
||||||
else if (ecma_number_is_zero (arg_num) /* both numbers are zeroes */
|
else if (ecma_number_is_zero (arg_num) /* both numbers are zeroes */
|
||||||
&& ecma_number_is_zero (ret_num))
|
&& ecma_number_is_zero (ret_num))
|
||||||
@@ -360,7 +360,6 @@ ecma_builtin_math_object_max (ecma_value_t this_arg __attr_unused___, /**< 'this
|
|||||||
if (!ecma_number_is_negative (arg_num))
|
if (!ecma_number_is_negative (arg_num))
|
||||||
{
|
{
|
||||||
ret_num = arg_num;
|
ret_num = arg_num;
|
||||||
is_just_convert = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (ecma_number_is_infinity (ret_num)) /* ret_num is negative infinity */
|
else if (ecma_number_is_infinity (ret_num)) /* ret_num is negative infinity */
|
||||||
@@ -384,21 +383,16 @@ ecma_builtin_math_object_max (ecma_value_t this_arg __attr_unused___, /**< 'this
|
|||||||
}
|
}
|
||||||
|
|
||||||
ECMA_OP_TO_NUMBER_FINALIZE (arg_num);
|
ECMA_OP_TO_NUMBER_FINALIZE (arg_num);
|
||||||
|
|
||||||
if (ecma_is_completion_value_throw (ret_value))
|
|
||||||
{
|
|
||||||
return ret_value;
|
|
||||||
}
|
|
||||||
|
|
||||||
JERRY_ASSERT (ecma_is_completion_value_empty (ret_value));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
JERRY_ASSERT (ecma_is_completion_value_empty (ret_value));
|
if (ecma_is_completion_value_empty (ret_value))
|
||||||
|
{
|
||||||
|
ecma_number_t *num_p = ecma_alloc_number ();
|
||||||
|
*num_p = ret_num;
|
||||||
|
ret_value = ecma_make_normal_completion_value (ecma_make_number_value (num_p));
|
||||||
|
}
|
||||||
|
|
||||||
ecma_number_t *num_p = ecma_alloc_number ();
|
return ret_value;
|
||||||
*num_p = ret_num;
|
|
||||||
|
|
||||||
return ecma_make_normal_completion_value (ecma_make_number_value (num_p));
|
|
||||||
} /* ecma_builtin_math_object_max */
|
} /* ecma_builtin_math_object_max */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -419,20 +413,20 @@ ecma_builtin_math_object_min (ecma_value_t this_arg __attr_unused___, /**< 'this
|
|||||||
|
|
||||||
ecma_number_t ret_num = ecma_number_make_infinity (false);
|
ecma_number_t ret_num = ecma_number_make_infinity (false);
|
||||||
|
|
||||||
bool is_just_convert = false;
|
bool is_NaN = false;
|
||||||
|
|
||||||
for (ecma_length_t arg_index = 0;
|
for (ecma_length_t arg_index = 0;
|
||||||
arg_index < args_number;
|
arg_index < args_number && ecma_is_completion_value_empty (ret_value);
|
||||||
arg_index++)
|
arg_index++)
|
||||||
{
|
{
|
||||||
ECMA_OP_TO_NUMBER_TRY_CATCH (arg_num, args[arg_index], ret_value);
|
ECMA_OP_TO_NUMBER_TRY_CATCH (arg_num, args[arg_index], ret_value);
|
||||||
|
|
||||||
if (!is_just_convert)
|
if (!is_NaN)
|
||||||
{
|
{
|
||||||
if (unlikely (ecma_number_is_nan (arg_num)))
|
if (unlikely (ecma_number_is_nan (arg_num)))
|
||||||
{
|
{
|
||||||
ret_num = arg_num;
|
ret_num = arg_num;
|
||||||
is_just_convert = true;
|
is_NaN = true;
|
||||||
}
|
}
|
||||||
else if (ecma_number_is_zero (arg_num) /* both numbers are zeroes */
|
else if (ecma_number_is_zero (arg_num) /* both numbers are zeroes */
|
||||||
&& ecma_number_is_zero (ret_num))
|
&& ecma_number_is_zero (ret_num))
|
||||||
@@ -447,7 +441,6 @@ ecma_builtin_math_object_min (ecma_value_t this_arg __attr_unused___, /**< 'this
|
|||||||
if (ecma_number_is_negative (arg_num))
|
if (ecma_number_is_negative (arg_num))
|
||||||
{
|
{
|
||||||
ret_num = arg_num;
|
ret_num = arg_num;
|
||||||
is_just_convert = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (ecma_number_is_infinity (ret_num)) /* ret_num is positive infinity */
|
else if (ecma_number_is_infinity (ret_num)) /* ret_num is positive infinity */
|
||||||
@@ -471,21 +464,16 @@ ecma_builtin_math_object_min (ecma_value_t this_arg __attr_unused___, /**< 'this
|
|||||||
}
|
}
|
||||||
|
|
||||||
ECMA_OP_TO_NUMBER_FINALIZE (arg_num);
|
ECMA_OP_TO_NUMBER_FINALIZE (arg_num);
|
||||||
|
|
||||||
if (ecma_is_completion_value_throw (ret_value))
|
|
||||||
{
|
|
||||||
return ret_value;
|
|
||||||
}
|
|
||||||
|
|
||||||
JERRY_ASSERT (ecma_is_completion_value_empty (ret_value));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
JERRY_ASSERT (ecma_is_completion_value_empty (ret_value));
|
if (ecma_is_completion_value_empty (ret_value))
|
||||||
|
{
|
||||||
|
ecma_number_t *num_p = ecma_alloc_number ();
|
||||||
|
*num_p = ret_num;
|
||||||
|
ret_value = ecma_make_normal_completion_value (ecma_make_number_value (num_p));
|
||||||
|
}
|
||||||
|
|
||||||
ecma_number_t *num_p = ecma_alloc_number ();
|
return ret_value;
|
||||||
*num_p = ret_num;
|
|
||||||
|
|
||||||
return ecma_make_normal_completion_value (ecma_make_number_value (num_p));
|
|
||||||
} /* ecma_builtin_math_object_min */
|
} /* ecma_builtin_math_object_min */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -14,6 +14,8 @@
|
|||||||
|
|
||||||
assert(isNaN (Math['max'] (1.0, NaN)));
|
assert(isNaN (Math['max'] (1.0, NaN)));
|
||||||
assert(isNaN (Math['max'] (NaN, 1.0)));
|
assert(isNaN (Math['max'] (NaN, 1.0)));
|
||||||
|
assert(isNaN (Math['max'] (Infinity, NaN)));
|
||||||
|
assert(isNaN (Math['max'] (NaN, Infinity)));
|
||||||
assert(Math['max'] (1.0, 3.0, 0.0) === 3.0);
|
assert(Math['max'] (1.0, 3.0, 0.0) === 3.0);
|
||||||
assert(Math['max'] (1.0, 3.0, Infinity) === Infinity);
|
assert(Math['max'] (1.0, 3.0, Infinity) === Infinity);
|
||||||
assert(Math['max'] (1.0, 3.0, -Infinity) === 3.0);
|
assert(Math['max'] (1.0, 3.0, -Infinity) === 3.0);
|
||||||
@@ -23,9 +25,5 @@ assert(Math['max'] (Infinity, Infinity) === Infinity);
|
|||||||
assert(Math['max'] (-Infinity, -Infinity) === -Infinity);
|
assert(Math['max'] (-Infinity, -Infinity) === -Infinity);
|
||||||
assert(Math['max'] () === -Infinity);
|
assert(Math['max'] () === -Infinity);
|
||||||
|
|
||||||
/*
|
|
||||||
FIXME: Uncomment when unary minus support appears.
|
|
||||||
|
|
||||||
assert(Math['max'] (0.0, -0.0) === 0.0);
|
assert(Math['max'] (0.0, -0.0) === 0.0);
|
||||||
assert(Math['max'] (-0.0, 0.0) === 0.0);
|
assert(Math['max'] (-0.0, 0.0) === 0.0);
|
||||||
*/
|
|
||||||
|
|||||||
Vendored
+2
-4
@@ -14,6 +14,8 @@
|
|||||||
|
|
||||||
assert(isNaN (Math['min'] (1.0, NaN)));
|
assert(isNaN (Math['min'] (1.0, NaN)));
|
||||||
assert(isNaN (Math['min'] (NaN, 1.0)));
|
assert(isNaN (Math['min'] (NaN, 1.0)));
|
||||||
|
assert(isNaN (Math['min'] (-Infinity, NaN)));
|
||||||
|
assert(isNaN (Math['min'] (NaN, -Infinity)));
|
||||||
assert(Math['min'] (1.0, 3.0, 0.0) === 0.0);
|
assert(Math['min'] (1.0, 3.0, 0.0) === 0.0);
|
||||||
assert(Math['min'] (1.0, 3.0, Infinity) === 1.0);
|
assert(Math['min'] (1.0, 3.0, Infinity) === 1.0);
|
||||||
assert(Math['min'] (1.0, 3.0, -Infinity) === -Infinity);
|
assert(Math['min'] (1.0, 3.0, -Infinity) === -Infinity);
|
||||||
@@ -23,9 +25,5 @@ assert(Math['min'] (Infinity, Infinity) === Infinity);
|
|||||||
assert(Math['min'] (-Infinity, -Infinity) === -Infinity);
|
assert(Math['min'] (-Infinity, -Infinity) === -Infinity);
|
||||||
assert(Math['min'] () === Infinity);
|
assert(Math['min'] () === Infinity);
|
||||||
|
|
||||||
/*
|
|
||||||
FIXME: Uncomment when unary minus support appears.
|
|
||||||
|
|
||||||
assert(Math['min'] (0.0, -0.0) === -0.0);
|
assert(Math['min'] (0.0, -0.0) === -0.0);
|
||||||
assert(Math['min'] (-0.0, 0.0) === -0.0);
|
assert(Math['min'] (-0.0, 0.0) === -0.0);
|
||||||
*/
|
|
||||||
|
|||||||
Reference in New Issue
Block a user