Implement BigInt.prototype.toLocaleString (#4355)
JerryScript-DCO-1.0-Signed-off-by: Orkenyi Virag orkvi@inf.u-szeged.hu
This commit is contained in:
@@ -24,6 +24,19 @@
|
|||||||
/**
|
/**
|
||||||
* This object has a custom dispatch function.
|
* This object has a custom dispatch function.
|
||||||
*/
|
*/
|
||||||
|
#define BUILTIN_CUSTOM_DISPATCH
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List of built-in routine identifiers.
|
||||||
|
*/
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
ECMA_BIGINT_PROTOTYPE_ROUTINE_START = 0,
|
||||||
|
ECMA_BIGINT_PROTOTYPE_VALUE_OF,
|
||||||
|
ECMA_BIGINT_PROTOTYPE_TO_STRING,
|
||||||
|
ECMA_BIGINT_PROTOTYPE_TO_LOCALE_STRING,
|
||||||
|
};
|
||||||
|
|
||||||
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-bigint-prototype.inc.h"
|
#define BUILTIN_INC_HEADER_NAME "ecma-builtin-bigint-prototype.inc.h"
|
||||||
#define BUILTIN_UNDERSCORED_ID bigint_prototype
|
#define BUILTIN_UNDERSCORED_ID bigint_prototype
|
||||||
#include "ecma-builtin-internal-routines-template.inc.h"
|
#include "ecma-builtin-internal-routines-template.inc.h"
|
||||||
@@ -86,13 +99,6 @@ ecma_builtin_bigint_prototype_object_to_string (ecma_value_t this_arg, /**< this
|
|||||||
const ecma_value_t *arguments_list_p, /**< arguments list */
|
const ecma_value_t *arguments_list_p, /**< arguments list */
|
||||||
uint32_t arguments_list_len) /**< number of arguments */
|
uint32_t arguments_list_len) /**< number of arguments */
|
||||||
{
|
{
|
||||||
ecma_value_t bigint = ecma_builtin_bigint_prototype_object_value_of (this_arg);
|
|
||||||
|
|
||||||
if (ECMA_IS_VALUE_ERROR (bigint))
|
|
||||||
{
|
|
||||||
return bigint;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t radix = 10;
|
uint32_t radix = 10;
|
||||||
|
|
||||||
if (arguments_list_len > 0 && !ecma_is_value_undefined (arguments_list_p[0]))
|
if (arguments_list_len > 0 && !ecma_is_value_undefined (arguments_list_p[0]))
|
||||||
@@ -101,21 +107,18 @@ ecma_builtin_bigint_prototype_object_to_string (ecma_value_t this_arg, /**< this
|
|||||||
|
|
||||||
if (ECMA_IS_VALUE_ERROR (ecma_op_to_integer (arguments_list_p[0], &arg_num)))
|
if (ECMA_IS_VALUE_ERROR (ecma_op_to_integer (arguments_list_p[0], &arg_num)))
|
||||||
{
|
{
|
||||||
ecma_free_value (bigint);
|
|
||||||
return ECMA_VALUE_ERROR;
|
return ECMA_VALUE_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (arg_num < 2 || arg_num > 36)
|
if (arg_num < 2 || arg_num > 36)
|
||||||
{
|
{
|
||||||
ecma_free_value (bigint);
|
|
||||||
return ecma_raise_range_error (ECMA_ERR_MSG ("Radix must be between 2 and 36"));
|
return ecma_raise_range_error (ECMA_ERR_MSG ("Radix must be between 2 and 36"));
|
||||||
}
|
}
|
||||||
|
|
||||||
radix = (uint32_t) arg_num;
|
radix = (uint32_t) arg_num;
|
||||||
}
|
}
|
||||||
|
|
||||||
ecma_string_t *string_p = ecma_bigint_to_string (bigint, radix);
|
ecma_string_t *string_p = ecma_bigint_to_string (this_arg, radix);
|
||||||
ecma_free_value (bigint);
|
|
||||||
|
|
||||||
if (string_p == NULL)
|
if (string_p == NULL)
|
||||||
{
|
{
|
||||||
@@ -125,6 +128,55 @@ ecma_builtin_bigint_prototype_object_to_string (ecma_value_t this_arg, /**< this
|
|||||||
return ecma_make_string_value (string_p);
|
return ecma_make_string_value (string_p);
|
||||||
} /* ecma_builtin_bigint_prototype_object_to_string */
|
} /* ecma_builtin_bigint_prototype_object_to_string */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dispatcher of the built-in's routines
|
||||||
|
*
|
||||||
|
* @return ecma value
|
||||||
|
* Returned value must be freed with ecma_free_value.
|
||||||
|
*/
|
||||||
|
ecma_value_t
|
||||||
|
ecma_builtin_bigint_prototype_dispatch_routine (uint8_t builtin_routine_id, /**< built-in wide routine
|
||||||
|
* identifier */
|
||||||
|
ecma_value_t this_arg, /**< 'this' argument value */
|
||||||
|
const ecma_value_t arguments_list_p[], /**< list of arguments
|
||||||
|
* passed to routine */
|
||||||
|
uint32_t arguments_number) /**< length of arguments' list */
|
||||||
|
{
|
||||||
|
ecma_value_t this_value = ecma_builtin_bigint_prototype_object_value_of (this_arg);
|
||||||
|
ecma_value_t ret_val;
|
||||||
|
|
||||||
|
if (ECMA_IS_VALUE_ERROR (this_value))
|
||||||
|
{
|
||||||
|
return this_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (builtin_routine_id)
|
||||||
|
{
|
||||||
|
case ECMA_BIGINT_PROTOTYPE_VALUE_OF:
|
||||||
|
{
|
||||||
|
ret_val = this_value;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ECMA_BIGINT_PROTOTYPE_TO_STRING:
|
||||||
|
{
|
||||||
|
ret_val = ecma_builtin_bigint_prototype_object_to_string (this_value, arguments_list_p, arguments_number);
|
||||||
|
ecma_free_value (this_value);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ECMA_BIGINT_PROTOTYPE_TO_LOCALE_STRING:
|
||||||
|
{
|
||||||
|
ret_val = ecma_builtin_bigint_prototype_object_to_string (this_value, 0, 0);
|
||||||
|
ecma_free_value (this_value);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
JERRY_UNREACHABLE ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret_val;
|
||||||
|
} /* ecma_builtin_bigint_prototype_dispatch_routine */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
* @}
|
* @}
|
||||||
|
|||||||
@@ -36,8 +36,9 @@ STRING_VALUE (LIT_GLOBAL_SYMBOL_TO_STRING_TAG,
|
|||||||
|
|
||||||
/* Routine properties:
|
/* Routine properties:
|
||||||
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
|
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
|
||||||
ROUTINE (LIT_MAGIC_STRING_VALUE_OF_UL, ecma_builtin_bigint_prototype_object_value_of, 0, 0)
|
ROUTINE (LIT_MAGIC_STRING_TO_STRING_UL, ECMA_BIGINT_PROTOTYPE_TO_STRING, NON_FIXED, 0)
|
||||||
ROUTINE (LIT_MAGIC_STRING_TO_STRING_UL, ecma_builtin_bigint_prototype_object_to_string, NON_FIXED, 0)
|
ROUTINE (LIT_MAGIC_STRING_VALUE_OF_UL, ECMA_BIGINT_PROTOTYPE_VALUE_OF, 0, 0)
|
||||||
|
ROUTINE (LIT_MAGIC_STRING_TO_LOCALE_STRING_UL, ECMA_BIGINT_PROTOTYPE_TO_LOCALE_STRING, 0, 0)
|
||||||
|
|
||||||
#endif /* JERRY_BUILTIN_BIGINT */
|
#endif /* JERRY_BUILTIN_BIGINT */
|
||||||
|
|
||||||
|
|||||||
@@ -126,8 +126,6 @@
|
|||||||
<test id="built-ins/TypedArray/prototype/join/return-abrupt-from-separator.js"><reason></reason></test>
|
<test id="built-ins/TypedArray/prototype/join/return-abrupt-from-separator.js"><reason></reason></test>
|
||||||
<test id="built-ins/TypedArray/prototype/slice/set-values-from-different-ctor-type.js"><reason></reason></test>
|
<test id="built-ins/TypedArray/prototype/slice/set-values-from-different-ctor-type.js"><reason></reason></test>
|
||||||
<test id="built-ins/TypedArray/prototype/sort/sorted-values.js"><reason></reason></test>
|
<test id="built-ins/TypedArray/prototype/sort/sorted-values.js"><reason></reason></test>
|
||||||
<test id="built-ins/TypedArray/prototype/toLocaleString/BigInt/get-length-uses-internal-arraylength.js"><reason></reason></test>
|
|
||||||
<test id="built-ins/TypedArray/prototype/toLocaleString/BigInt/return-result.js"><reason></reason></test>
|
|
||||||
<test id="built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/byteoffset-is-negative-zero.js"><reason></reason></test>
|
<test id="built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/byteoffset-is-negative-zero.js"><reason></reason></test>
|
||||||
<test id="built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/defined-negative-length.js"><reason></reason></test>
|
<test id="built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/defined-negative-length.js"><reason></reason></test>
|
||||||
<test id="built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/toindex-byteoffset.js"><reason></reason></test>
|
<test id="built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/toindex-byteoffset.js"><reason></reason></test>
|
||||||
@@ -648,10 +646,8 @@
|
|||||||
<test id="intl402/BigInt/prototype/toLocaleString/de-DE.js"><reason></reason></test>
|
<test id="intl402/BigInt/prototype/toLocaleString/de-DE.js"><reason></reason></test>
|
||||||
<test id="intl402/BigInt/prototype/toLocaleString/default-options-object-prototype.js"><reason></reason></test>
|
<test id="intl402/BigInt/prototype/toLocaleString/default-options-object-prototype.js"><reason></reason></test>
|
||||||
<test id="intl402/BigInt/prototype/toLocaleString/en-US.js"><reason></reason></test>
|
<test id="intl402/BigInt/prototype/toLocaleString/en-US.js"><reason></reason></test>
|
||||||
<test id="intl402/BigInt/prototype/toLocaleString/prop-desc.js"><reason></reason></test>
|
|
||||||
<test id="intl402/BigInt/prototype/toLocaleString/returns-same-results-as-NumberFormat.js"><reason></reason></test>
|
<test id="intl402/BigInt/prototype/toLocaleString/returns-same-results-as-NumberFormat.js"><reason></reason></test>
|
||||||
<test id="intl402/BigInt/prototype/toLocaleString/taint-Intl-NumberFormat.js"><reason></reason></test>
|
<test id="intl402/BigInt/prototype/toLocaleString/taint-Intl-NumberFormat.js"><reason></reason></test>
|
||||||
<test id="intl402/BigInt/prototype/toLocaleString/this-value-invalid.js"><reason></reason></test>
|
|
||||||
<test id="intl402/BigInt/prototype/toLocaleString/throws-same-exceptions-as-NumberFormat.js"><reason></reason></test>
|
<test id="intl402/BigInt/prototype/toLocaleString/throws-same-exceptions-as-NumberFormat.js"><reason></reason></test>
|
||||||
<test id="intl402/Collator/builtin.js"><reason></reason></test>
|
<test id="intl402/Collator/builtin.js"><reason></reason></test>
|
||||||
<test id="intl402/Collator/constructor-options-throwing-getters.js"><reason></reason></test>
|
<test id="intl402/Collator/constructor-options-throwing-getters.js"><reason></reason></test>
|
||||||
|
|||||||
Reference in New Issue
Block a user