Support BigInt to number conversion using Number constructor (#4121)

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
Zoltan Herczeg
2020-08-12 16:33:31 +02:00
committed by GitHub
parent 0c154306a8
commit 6adf0c1a87
21 changed files with 266 additions and 54 deletions
@@ -396,7 +396,7 @@ ecma_builtin_date_prototype_dispatch_set (uint16_t builtin_routine_id, /**< buil
for (uint32_t i = 0; i < conversions; i++)
{
ecma_value_t value = ecma_op_to_number (arguments_list[i]);
ecma_value_t value = ecma_op_to_number (arguments_list[i], ECMA_TO_NUMERIC_NO_OPTS);
if (ECMA_IS_VALUE_ERROR (value))
{
@@ -776,7 +776,7 @@ ecma_builtin_date_dispatch_construct (const ecma_value_t *arguments_list_p, /**<
}
else
{
ecma_value_t prim_value = ecma_op_to_number (argument);
ecma_value_t prim_value = ecma_op_to_number (argument, ECMA_TO_NUMERIC_NO_OPTS);
if (ECMA_IS_VALUE_ERROR (prim_value))
{
@@ -1269,7 +1269,7 @@ ecma_builtin_json_serialize_property (ecma_json_stringify_context_t *context_p,
/* 5.a */
if (class_name == LIT_MAGIC_STRING_NUMBER_UL)
{
value = ecma_op_to_number (value);
value = ecma_op_to_number (value, ECMA_TO_NUMERIC_NO_OPTS);
ecma_deref_object (obj_p);
if (ECMA_IS_VALUE_ERROR (value))
@@ -1598,7 +1598,7 @@ ecma_builtin_json_stringify (ecma_value_t this_arg, /**< 'this' argument */
/* 5.a */
if (class_name == LIT_MAGIC_STRING_NUMBER_UL)
{
ecma_value_t value = ecma_op_to_number (arg3);
ecma_value_t value = ecma_op_to_number (arg3, ECMA_TO_NUMERIC_NO_OPTS);
if (ECMA_IS_VALUE_ERROR (value))
{
@@ -135,7 +135,7 @@ ecma_builtin_math_object_max_min (bool is_max, /**< 'max' or 'min' operation */
}
else
{
ecma_value_t value = ecma_op_to_number (*arg);
ecma_value_t value = ecma_op_to_number (*arg, ECMA_TO_NUMERIC_NO_OPTS);
if (ECMA_IS_VALUE_ERROR (value))
{
@@ -215,7 +215,7 @@ ecma_builtin_math_object_hypot (const ecma_value_t *arg, /**< arguments list */
}
else
{
ecma_value_t value = ecma_op_to_number (*arg);
ecma_value_t value = ecma_op_to_number (*arg, ECMA_TO_NUMERIC_NO_OPTS);
if (ECMA_IS_VALUE_ERROR (value))
{
return value;
@@ -357,7 +357,7 @@ ecma_builtin_math_dispatch_routine (uint16_t builtin_routine_id, /**< built-in w
}
else
{
ecma_value_t value = ecma_op_to_number (arguments_list[0]);
ecma_value_t value = ecma_op_to_number (arguments_list[0], ECMA_TO_NUMERIC_NO_OPTS);
if (ECMA_IS_VALUE_ERROR (value))
{
@@ -379,7 +379,7 @@ ecma_builtin_math_dispatch_routine (uint16_t builtin_routine_id, /**< built-in w
}
else
{
ecma_value_t value = ecma_op_to_number (arguments_list[1]);
ecma_value_t value = ecma_op_to_number (arguments_list[1], ECMA_TO_NUMERIC_NO_OPTS);
if (ECMA_IS_VALUE_ERROR (value))
{
@@ -16,6 +16,7 @@
#include <math.h>
#include "ecma-alloc.h"
#include "ecma-bigint.h"
#include "ecma-builtins.h"
#include "ecma-conversion.h"
#include "ecma-exceptions.h"
@@ -84,7 +85,16 @@ ecma_builtin_number_dispatch_call (const ecma_value_t *arguments_list_p, /**< ar
}
else
{
ret_value = ecma_op_to_number (arguments_list_p[0]);
ret_value = ecma_op_to_number (arguments_list_p[0], ECMA_TO_NUMERIC_ALLOW_BIGINT);
#if ENABLED (JERRY_BUILTIN_BIGINT)
if (ecma_is_value_bigint (ret_value))
{
ecma_value_t bigint = ret_value;
ret_value = ecma_bigint_to_number (bigint);
ecma_free_value (bigint);
}
#endif /* ENABLED (JERRY_BUILTIN_BIGINT) */
}
return ret_value;
@@ -103,13 +113,30 @@ ecma_builtin_number_dispatch_construct (const ecma_value_t *arguments_list_p, /*
if (arguments_list_len == 0)
{
ecma_value_t completion = ecma_op_create_number_object (ecma_make_integer_value (0));
return completion;
return ecma_op_create_number_object (ecma_make_integer_value (0));
}
else
#if ENABLED (JERRY_BUILTIN_BIGINT)
ecma_value_t value = ecma_op_to_number (arguments_list_p[0], ECMA_TO_NUMERIC_ALLOW_BIGINT);
if (ecma_is_value_bigint (value))
{
return ecma_op_create_number_object (arguments_list_p[0]);
ecma_value_t bigint = value;
value = ecma_bigint_to_number (bigint);
ecma_free_value (bigint);
}
if (ECMA_IS_VALUE_ERROR (value))
{
return value;
}
ecma_value_t result = ecma_op_create_number_object (value);
ecma_free_value (value);
return result;
#else /* !ENABLED (JERRY_BUILTIN_BIGINT) */
return ecma_op_create_number_object (arguments_list_p[0]);
#endif /* ENABLED (JERRY_BUILTIN_BIGINT) */
} /* ecma_builtin_number_dispatch_construct */
#if ENABLED (JERRY_ESNEXT)
@@ -291,7 +291,7 @@ ecma_builtin_string_object_from_code_point (ecma_value_t this_arg, /**< 'this' a
for (uint32_t index = 0; index < args_number; index++)
{
ecma_value_t to_number_value = ecma_op_to_number (args[index]);
ecma_value_t to_number_value = ecma_op_to_number (args[index], ECMA_TO_NUMERIC_NO_OPTS);
if (ECMA_IS_VALUE_ERROR (to_number_value))
{