Update ToLength operation to conform ES6 spec (#4007)
JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
This commit is contained in:
@@ -2075,6 +2075,22 @@ typedef struct
|
||||
} ecma_revocable_proxy_object_t;
|
||||
#endif /* ENABLED (JERRY_BUILTIN_PROXY) */
|
||||
|
||||
#if ENABLED (JERRY_ESNEXT)
|
||||
/**
|
||||
* Type to repesent the maximum property index
|
||||
*
|
||||
* For ES6+ the maximum valid property index is 2**53 - 1
|
||||
*/
|
||||
typedef uint64_t ecma_length_t;
|
||||
#else /* !ENABLED (JERRY_ESNEXT) */
|
||||
/**
|
||||
* Type to repesent the maximum property index
|
||||
*
|
||||
* For ES5+ the maximum valid property index is 2**32 - 1
|
||||
*/
|
||||
typedef uint32_t ecma_length_t;
|
||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||
|
||||
/**
|
||||
* Struct for counting the different types properties in objects
|
||||
*/
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
|
||||
#include "ecma-alloc.h"
|
||||
#include "ecma-conversion.h"
|
||||
#include "ecma-exceptions.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
@@ -547,7 +548,32 @@ ecma_new_non_direct_string_from_uint32 (uint32_t uint32_number) /**< uint32 valu
|
||||
} /* ecma_new_non_direct_string_from_uint32 */
|
||||
|
||||
/**
|
||||
* Allocate new ecma-string and fill it with ecma-number
|
||||
* Allocate new ecma-string and fill it with property length number
|
||||
*
|
||||
* @return pointer to ecma-string descriptor
|
||||
*/
|
||||
ecma_string_t *
|
||||
ecma_new_ecma_string_from_length (ecma_length_t number) /**< property length */
|
||||
{
|
||||
if (JERRY_LIKELY (number <= ECMA_DIRECT_STRING_MAX_IMM))
|
||||
{
|
||||
return (ecma_string_t *) ECMA_CREATE_DIRECT_STRING (ECMA_DIRECT_STRING_UINT, (uintptr_t) number);
|
||||
}
|
||||
|
||||
#if ENABLED (JERRY_ESNEXT)
|
||||
JERRY_ASSERT (number <= ECMA_NUMBER_MAX_SAFE_INTEGER);
|
||||
|
||||
if (JERRY_UNLIKELY (number > UINT32_MAX))
|
||||
{
|
||||
return ecma_new_ecma_string_from_number ((ecma_number_t) number);
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||
|
||||
return ecma_new_non_direct_string_from_uint32 ((uint32_t) number);
|
||||
} /* ecma_new_ecma_string_from_length */
|
||||
|
||||
/**
|
||||
* Allocate new ecma-string and fill it with uint32 number
|
||||
*
|
||||
* @return pointer to ecma-string descriptor
|
||||
*/
|
||||
@@ -2493,7 +2519,7 @@ ecma_string_pad (ecma_value_t original_string_p, /**< Input ecma string */
|
||||
{
|
||||
|
||||
/* 3 */
|
||||
uint32_t int_max_length;
|
||||
ecma_length_t int_max_length;
|
||||
if (ECMA_IS_VALUE_ERROR (ecma_op_to_length (max_length, &int_max_length)))
|
||||
{
|
||||
return ECMA_VALUE_ERROR;
|
||||
@@ -2524,8 +2550,14 @@ ecma_string_pad (ecma_value_t original_string_p, /**< Input ecma string */
|
||||
}
|
||||
}
|
||||
|
||||
if (int_max_length >= UINT32_MAX)
|
||||
{
|
||||
ecma_deref_ecma_string (filler_p);
|
||||
return ecma_raise_range_error (ECMA_ERR_MSG ("Maximum string length is reached."));
|
||||
}
|
||||
|
||||
/* 9 */
|
||||
uint32_t fill_len = int_max_length - string_length;
|
||||
uint32_t fill_len = (uint32_t) int_max_length - string_length;
|
||||
|
||||
/* 10 */
|
||||
uint32_t filler_length = ecma_string_get_length (filler_p);
|
||||
@@ -2899,15 +2931,19 @@ ecma_stringbuilder_destroy (ecma_stringbuilder_t *builder_p) /**< string builder
|
||||
*/
|
||||
uint32_t
|
||||
ecma_op_advance_string_index (ecma_string_t *str_p, /**< input string */
|
||||
uint32_t index, /**< given character index */
|
||||
ecma_length_t index_num, /**< given character index */
|
||||
bool is_unicode) /**< true - if regexp object's "unicode" flag is set
|
||||
false - otherwise */
|
||||
{
|
||||
if (index >= UINT32_MAX - 1)
|
||||
JERRY_ASSERT (index_num <= ECMA_NUMBER_MAX_SAFE_INTEGER);
|
||||
|
||||
/* Note: The internal string length limit is 2^32 */
|
||||
if (JERRY_UNLIKELY (index_num >= (UINT32_MAX - 1)))
|
||||
{
|
||||
return UINT32_MAX;
|
||||
}
|
||||
|
||||
uint32_t index = (uint32_t) index_num;
|
||||
uint32_t next_index = index + 1;
|
||||
|
||||
if (!is_unicode)
|
||||
|
||||
@@ -530,6 +530,23 @@ ecma_is_number_equal_to_positive_zero (ecma_number_t ecma_number) /**< number */
|
||||
#endif /* !ENABLED (JERRY_NUMBER_TYPE_FLOAT64) */
|
||||
} /* ecma_is_number_equal_to_positive_zero */
|
||||
|
||||
/**
|
||||
* Encode a property length number into an ecma-value
|
||||
*
|
||||
* @return ecma-value
|
||||
*/
|
||||
ecma_value_t
|
||||
ecma_make_length_value (ecma_length_t number) /**< number to be encoded */
|
||||
{
|
||||
if (number <= ECMA_INTEGER_NUMBER_MAX)
|
||||
{
|
||||
return ecma_make_integer_value ((ecma_integer_value_t) number);
|
||||
}
|
||||
|
||||
JERRY_ASSERT (number <= ECMA_NUMBER_MAX_SAFE_INTEGER);
|
||||
return ecma_create_float_number ((ecma_number_t) number);
|
||||
} /* ecma_make_length_value */
|
||||
|
||||
/**
|
||||
* Encode a number into an ecma-value
|
||||
*
|
||||
|
||||
@@ -256,6 +256,7 @@ ecma_value_t JERRY_ATTR_CONST ecma_make_boolean_value (bool boolean_value);
|
||||
ecma_value_t JERRY_ATTR_CONST ecma_make_integer_value (ecma_integer_value_t integer_value);
|
||||
ecma_value_t ecma_make_nan_value (void);
|
||||
ecma_value_t ecma_make_float_value (ecma_number_t *ecma_num_p);
|
||||
ecma_value_t ecma_make_length_value (ecma_length_t length);
|
||||
ecma_value_t ecma_make_number_value (ecma_number_t ecma_number);
|
||||
ecma_value_t ecma_make_int32_value (int32_t int32_number);
|
||||
ecma_value_t ecma_make_uint32_value (uint32_t uint32_number);
|
||||
@@ -297,7 +298,7 @@ lit_magic_string_id_t ecma_get_typeof_lit_id (ecma_value_t value);
|
||||
#if ENABLED (JERRY_ESNEXT)
|
||||
ecma_string_t *ecma_new_symbol_from_descriptor_string (ecma_value_t string_desc);
|
||||
bool ecma_prop_name_is_symbol (ecma_string_t *string_p);
|
||||
uint32_t ecma_op_advance_string_index (ecma_string_t *str_p, uint32_t index, bool is_unicode);
|
||||
uint32_t ecma_op_advance_string_index (ecma_string_t *str_p, ecma_length_t index_num, bool is_unicode);
|
||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||
#if ENABLED (JERRY_BUILTIN_MAP) || ENABLED (JERRY_BUILTIN_SET)
|
||||
ecma_string_t *ecma_new_map_key_string (ecma_value_t value);
|
||||
@@ -312,6 +313,7 @@ ecma_string_t *ecma_new_ecma_string_from_code_unit (ecma_char_t code_unit);
|
||||
#if ENABLED (JERRY_ESNEXT)
|
||||
ecma_string_t *ecma_new_ecma_string_from_code_units (ecma_char_t first_code_unit, ecma_char_t second_code_unit);
|
||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||
ecma_string_t *ecma_new_ecma_string_from_length (ecma_length_t index);
|
||||
ecma_string_t *ecma_new_ecma_string_from_uint32 (uint32_t uint32_number);
|
||||
ecma_string_t *ecma_new_non_direct_string_from_uint32 (uint32_t uint32_number);
|
||||
ecma_string_t *ecma_get_ecma_string_from_uint32 (uint32_t uint32_number);
|
||||
|
||||
Reference in New Issue
Block a user