diff --git a/jerry-core/api/jerry.c b/jerry-core/api/jerry.c index 7beeb79bb..9eb0b6edc 100644 --- a/jerry-core/api/jerry.c +++ b/jerry-core/api/jerry.c @@ -3309,7 +3309,11 @@ jerry_has_own_property (const jerry_value_t obj_val, /**< object value */ } #endif /* JERRY_BUILTIN_PROXY */ - return ecma_make_boolean_value (ecma_op_ordinary_object_has_own_property (obj_p, prop_name_p)); +#if JERRY_BUILTIN_TYPEDARRAY + return jerry_return (ecma_op_ordinary_object_has_own_property (obj_p, prop_name_p)); +#else /* !JERRY_BUILTIN_TYPEDARRAY */ + return ecma_op_ordinary_object_has_own_property (obj_p, prop_name_p); +#endif /* JERRY_BUILTIN_TYPEDARRAY */ } /* jerry_has_own_property */ /** diff --git a/jerry-core/ecma/base/ecma-globals.h b/jerry-core/ecma/base/ecma-globals.h index 7ce5a8758..b4678a32b 100644 --- a/jerry-core/ecma/base/ecma-globals.h +++ b/jerry-core/ecma/base/ecma-globals.h @@ -514,6 +514,19 @@ typedef enum */ #define ECMA_PROPERTY_TYPE_NOT_FOUND_AND_STOP ECMA_PROPERTY_TYPE_DELETED +/** + * Type of property not found and an exception is thrown. + */ +#define ECMA_PROPERTY_TYPE_NOT_FOUND_AND_THROW \ + (ECMA_PROPERTY_FLAG_LCACHED | (ECMA_DIRECT_STRING_SPECIAL << ECMA_PROPERTY_NAME_TYPE_SHIFT)) + +/** + * Checks whether a property is not found. + */ +#define ECMA_PROPERTY_IS_FOUND(property) \ + (((property) & (ECMA_PROPERTY_FLAG_DATA | (ECMA_DIRECT_STRING_SPECIAL << ECMA_PROPERTY_NAME_TYPE_SHIFT))) \ + != (ECMA_DIRECT_STRING_SPECIAL << ECMA_PROPERTY_NAME_TYPE_SHIFT)) + /** * Abstract property representation. * diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-object-prototype.c b/jerry-core/ecma/builtin-objects/ecma-builtin-object-prototype.c index 664857fad..95e061569 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-object-prototype.c +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-object-prototype.c @@ -147,7 +147,7 @@ ecma_builtin_object_prototype_object_has_own_property (ecma_object_t *obj_p, /** } #endif /* JERRY_BUILTIN_PROXY */ - return ecma_make_boolean_value (ecma_op_ordinary_object_has_own_property (obj_p, prop_name_p)); + return ecma_op_ordinary_object_has_own_property (obj_p, prop_name_p); } /* ecma_builtin_object_prototype_object_has_own_property */ /** diff --git a/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-typedarray-prototype.c b/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-typedarray-prototype.c index b2e6d40dc..0be71d156 100644 --- a/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-typedarray-prototype.c +++ b/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-typedarray-prototype.c @@ -1352,7 +1352,7 @@ static ecma_value_t ecma_builtin_typedarray_prototype_at (ecma_typedarray_info_t *info_p, /**< object info */ const ecma_value_t index) /**< index argument */ { - ecma_length_t len = (ecma_length_t) info_p->length; + ecma_length_t len = info_p->length; ecma_length_t res_index; ecma_value_t return_value = ecma_builtin_helper_calculate_index (index, len, &res_index); @@ -1361,7 +1361,12 @@ ecma_builtin_typedarray_prototype_at (ecma_typedarray_info_t *info_p, /**< objec return return_value; } - return ecma_get_typedarray_element (info_p, (ecma_number_t) res_index); + if (res_index >= UINT32_MAX) + { + return ECMA_VALUE_UNDEFINED; + } + + return ecma_get_typedarray_element (info_p, (uint32_t) res_index); } /* ecma_builtin_typedarray_prototype_at */ /** diff --git a/jerry-core/ecma/operations/ecma-objects-general.c b/jerry-core/ecma/operations/ecma-objects-general.c index 91df8c36c..be9ef8036 100644 --- a/jerry-core/ecma/operations/ecma-objects-general.c +++ b/jerry-core/ecma/operations/ecma-objects-general.c @@ -102,8 +102,10 @@ ecma_op_general_object_delete (ecma_object_t *obj_p, /**< the object */ ECMA_PROPERTY_GET_NO_OPTIONS); /* 2. */ - if (property == ECMA_PROPERTY_TYPE_NOT_FOUND || property == ECMA_PROPERTY_TYPE_NOT_FOUND_AND_STOP) + if (!ECMA_PROPERTY_IS_FOUND (property)) { + JERRY_ASSERT (property == ECMA_PROPERTY_TYPE_NOT_FOUND + || property == ECMA_PROPERTY_TYPE_NOT_FOUND_AND_STOP); return ECMA_VALUE_TRUE; } @@ -419,8 +421,11 @@ ecma_op_general_object_define_own_property (ecma_object_t *object_p, /**< the ob &ext_property_ref.property_ref, ECMA_PROPERTY_GET_VALUE | ECMA_PROPERTY_GET_EXT_REFERENCE); - if (current_prop == ECMA_PROPERTY_TYPE_NOT_FOUND || current_prop == ECMA_PROPERTY_TYPE_NOT_FOUND_AND_STOP) + if (!ECMA_PROPERTY_IS_FOUND (current_prop)) { + JERRY_ASSERT (current_prop == ECMA_PROPERTY_TYPE_NOT_FOUND + || current_prop == ECMA_PROPERTY_TYPE_NOT_FOUND_AND_STOP); + /* 3. */ if (!ecma_op_ordinary_object_is_extensible (object_p)) { diff --git a/jerry-core/ecma/operations/ecma-objects.c b/jerry-core/ecma/operations/ecma-objects.c index 597f60a82..cee9064a1 100644 --- a/jerry-core/ecma/operations/ecma-objects.c +++ b/jerry-core/ecma/operations/ecma-objects.c @@ -139,49 +139,42 @@ ecma_op_object_get_own_property (ecma_object_t *object_p, /**< the object */ { break; } - ecma_number_t num = ecma_string_to_number (property_name_p); - bool is_same; - if (num <= 0) + + uint32_t index = ecma_string_get_array_index (property_name_p); + + if (index == ECMA_STRING_NOT_ARRAY_INDEX) { - is_same = true; + JERRY_ASSERT (index == UINT32_MAX); + + if (!ecma_typedarray_is_element_index (property_name_p)) + { + break; + } + } + + ecma_typedarray_info_t info = ecma_typedarray_get_info (object_p); + ecma_value_t value = ecma_get_typedarray_element (&info, index); + + if (ECMA_IS_VALUE_ERROR (value)) + { + return ECMA_PROPERTY_TYPE_NOT_FOUND_AND_THROW; + } + + if (JERRY_UNLIKELY (ecma_is_value_undefined (value))) + { + return ECMA_PROPERTY_TYPE_NOT_FOUND_AND_STOP; + } + + if (options & ECMA_PROPERTY_GET_VALUE) + { + property_ref_p->virtual_value = value; } else { - ecma_string_t *num_to_str = ecma_new_ecma_string_from_number (num); - is_same = ecma_compare_ecma_strings (property_name_p, num_to_str); - ecma_deref_ecma_string (num_to_str); + ecma_fast_free_value (value); } - if (is_same) - { - ecma_typedarray_info_t info = ecma_typedarray_get_info (object_p); - ecma_value_t value = ecma_get_typedarray_element (&info, num); - - if (ECMA_IS_VALUE_ERROR (value)) - { - property_ref_p->virtual_value = value; - return ECMA_PROPERTY_TYPE_NOT_FOUND; - } - - if (!ecma_is_value_undefined (value)) - { - if (options & ECMA_PROPERTY_GET_VALUE) - { - property_ref_p->virtual_value = value; - } - else - { - ecma_fast_free_value (value); - } - - return ECMA_PROPERTY_ENUMERABLE_WRITABLE | ECMA_PROPERTY_VIRTUAL; - } - else - { - return ECMA_PROPERTY_TYPE_NOT_FOUND; - } - } - break; + return ECMA_PROPERTY_ENUMERABLE_WRITABLE | ECMA_PROPERTY_VIRTUAL; } #endif /* JERRY_BUILTIN_TYPEDARRAY */ #if JERRY_MODULE_SYSTEM @@ -457,48 +450,25 @@ ecma_op_object_has_property (ecma_object_t *object_p, /**< the object */ } #endif /* JERRY_BUILTIN_PROXY */ -#if JERRY_BUILTIN_TYPEDARRAY - if (ecma_object_is_typedarray (object_p) && !ecma_prop_name_is_symbol (property_name_p)) + /* 2 - 3. */ + ecma_property_t property = ecma_op_object_get_own_property (object_p, + property_name_p, + NULL, + ECMA_PROPERTY_GET_NO_OPTIONS); + + if (property != ECMA_PROPERTY_TYPE_NOT_FOUND) { - ecma_number_t num = ecma_string_to_number (property_name_p); - bool is_same; - if (num <= 0) +#if JERRY_BUILTIN_TYPEDARRAY + if (JERRY_UNLIKELY (property == ECMA_PROPERTY_TYPE_NOT_FOUND_AND_THROW)) { - is_same = true; + return ECMA_VALUE_ERROR; } - else - { - ecma_string_t *num_to_str = ecma_new_ecma_string_from_number (num); - is_same = ecma_compare_ecma_strings (property_name_p, num_to_str); - ecma_deref_ecma_string (num_to_str); - } - - if (is_same) - { - ecma_typedarray_info_t info = ecma_typedarray_get_info (object_p); - - if (ecma_arraybuffer_is_detached (info.array_buffer_p)) - { - return ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_arraybuffer_is_detached)); - } - - if (!ecma_op_is_integer (num) - || num >= info.length - || num < 0 - || (ecma_number_is_negative (num) && ecma_number_is_zero (num))) - { - return ECMA_VALUE_FALSE; - } - - return ECMA_VALUE_TRUE; - } - } #endif /* JERRY_BUILTIN_TYPEDARRAY */ - /* 2 - 3. */ - if (ecma_op_ordinary_object_has_own_property (object_p, property_name_p)) - { - return ECMA_VALUE_TRUE; + JERRY_ASSERT (property == ECMA_PROPERTY_TYPE_NOT_FOUND_AND_STOP + || ECMA_PROPERTY_IS_FOUND (property)); + + return ecma_make_boolean_value (property != ECMA_PROPERTY_TYPE_NOT_FOUND_AND_STOP); } jmem_cpointer_t proto_cp = ecma_op_ordinary_object_get_prototype_of (object_p); @@ -604,26 +574,20 @@ ecma_op_object_find_own (ecma_value_t base_value, /**< base value */ break; } - ecma_number_t num = ecma_string_to_number (property_name_p); - bool is_same; - if (num <= 0) + uint32_t index = ecma_string_get_array_index (property_name_p); + + if (index == ECMA_STRING_NOT_ARRAY_INDEX) { - is_same = true; - } - else - { - ecma_string_t *num_to_str = ecma_new_ecma_string_from_number (num); - is_same = ecma_compare_ecma_strings (property_name_p, num_to_str); - ecma_deref_ecma_string (num_to_str); + JERRY_ASSERT (index == UINT32_MAX); + + if (!ecma_typedarray_is_element_index (property_name_p)) + { + break; + } } - if (is_same) - { - ecma_typedarray_info_t info = ecma_typedarray_get_info (object_p); - return ecma_get_typedarray_element (&info, num); - } - - break; + ecma_typedarray_info_t info = ecma_typedarray_get_info (object_p); + return ecma_get_typedarray_element (&info, index); } #endif /* JERRY_BUILTIN_TYPEDARRAY */ #if JERRY_MODULE_SYSTEM @@ -1447,25 +1411,20 @@ ecma_op_object_put_with_receiver (ecma_object_t *object_p, /**< the object */ break; } - ecma_number_t num = ecma_string_to_number (property_name_p); - bool is_same; - if (num <= 0) + uint32_t index = ecma_string_get_array_index (property_name_p); + + if (index == ECMA_STRING_NOT_ARRAY_INDEX) { - is_same = true; - } - else - { - ecma_string_t *num_to_str = ecma_new_ecma_string_from_number (num); - is_same = ecma_compare_ecma_strings (property_name_p, num_to_str); - ecma_deref_ecma_string (num_to_str); + JERRY_ASSERT (index == UINT32_MAX); + + if (!ecma_typedarray_is_element_index (property_name_p)) + { + break; + } } - if (is_same) - { - ecma_typedarray_info_t info = ecma_typedarray_get_info (object_p); - return ecma_set_typedarray_element (&info, value, num); - } - break; + ecma_typedarray_info_t info = ecma_typedarray_get_info (object_p); + return ecma_set_typedarray_element (&info, value, index); } #endif /* JERRY_BUILTIN_TYPEDARRAY */ #if JERRY_MODULE_SYSTEM @@ -1668,8 +1627,7 @@ ecma_op_object_put_with_receiver (ecma_object_t *object_p, /**< the object */ &property_ref, ECMA_PROPERTY_GET_NO_OPTIONS); - if (inherited_property != ECMA_PROPERTY_TYPE_NOT_FOUND - && inherited_property != ECMA_PROPERTY_TYPE_NOT_FOUND_AND_STOP) + if (ECMA_PROPERTY_IS_FOUND (inherited_property)) { JERRY_ASSERT (ECMA_PROPERTY_IS_NAMED_PROPERTY (inherited_property)); @@ -1683,6 +1641,9 @@ ecma_op_object_put_with_receiver (ecma_object_t *object_p, /**< the object */ create_new_property = ecma_is_property_writable (inherited_property); break; } + + JERRY_ASSERT (inherited_property == ECMA_PROPERTY_TYPE_NOT_FOUND + || inherited_property == ECMA_PROPERTY_TYPE_NOT_FOUND_AND_STOP); } #if JERRY_BUILTIN_PROXY @@ -1962,13 +1923,18 @@ ecma_op_object_get_own_property_descriptor (ecma_object_t *object_p, /**< the ob &property_ref, ECMA_PROPERTY_GET_VALUE); - if (ECMA_IS_VALUE_ERROR (property_ref.virtual_value)) + if (!ECMA_PROPERTY_IS_FOUND (property)) { - return property_ref.virtual_value; - } +#if JERRY_BUILTIN_TYPEDARRAY + if (JERRY_UNLIKELY (property == ECMA_PROPERTY_TYPE_NOT_FOUND_AND_THROW)) + { + return ECMA_VALUE_ERROR; + } +#endif /* JERRY_BUILTIN_TYPEDARRAY */ + + JERRY_ASSERT (property == ECMA_PROPERTY_TYPE_NOT_FOUND + || property == ECMA_PROPERTY_TYPE_NOT_FOUND_AND_STOP); - if (property == ECMA_PROPERTY_TYPE_NOT_FOUND || property == ECMA_PROPERTY_TYPE_NOT_FOUND_AND_STOP) - { return ECMA_VALUE_FALSE; } @@ -3488,7 +3454,7 @@ ecma_op_ordinary_object_prevent_extensions (ecma_object_t *object_p) /**< object * @return true - if property is found * false - otherwise */ -extern inline bool JERRY_ATTR_ALWAYS_INLINE +extern inline ecma_value_t JERRY_ATTR_ALWAYS_INLINE ecma_op_ordinary_object_has_own_property (ecma_object_t *object_p, /**< the object */ ecma_string_t *property_name_p) /**< property name */ { @@ -3499,7 +3465,18 @@ ecma_op_ordinary_object_has_own_property (ecma_object_t *object_p, /**< the obje NULL, ECMA_PROPERTY_GET_NO_OPTIONS); - return property != ECMA_PROPERTY_TYPE_NOT_FOUND && property != ECMA_PROPERTY_TYPE_NOT_FOUND_AND_STOP; +#if JERRY_BUILTIN_TYPEDARRAY + if (JERRY_UNLIKELY (property == ECMA_PROPERTY_TYPE_NOT_FOUND_AND_THROW)) + { + return ECMA_VALUE_ERROR; + } +#endif /* JERRY_BUILTIN_TYPEDARRAY */ + + JERRY_ASSERT (ECMA_PROPERTY_IS_FOUND (property) + || property == ECMA_PROPERTY_TYPE_NOT_FOUND + || property == ECMA_PROPERTY_TYPE_NOT_FOUND_AND_STOP); + + return ecma_make_boolean_value (ECMA_PROPERTY_IS_FOUND (property)); } /* ecma_op_ordinary_object_has_own_property */ #if JERRY_BUILTIN_WEAKREF || JERRY_BUILTIN_CONTAINER diff --git a/jerry-core/ecma/operations/ecma-objects.h b/jerry-core/ecma/operations/ecma-objects.h index 4e1336524..3044cde12 100644 --- a/jerry-core/ecma/operations/ecma-objects.h +++ b/jerry-core/ecma/operations/ecma-objects.h @@ -58,7 +58,7 @@ ecma_value_t ecma_raise_readonly_assignment (ecma_string_t *property_name_p, boo ecma_property_t ecma_op_object_get_own_property (ecma_object_t *object_p, ecma_string_t *property_name_p, ecma_property_ref_t *property_ref_p, uint32_t options); -bool ecma_op_ordinary_object_has_own_property (ecma_object_t *object_p, ecma_string_t *property_name_p); +ecma_value_t ecma_op_ordinary_object_has_own_property (ecma_object_t *object_p, ecma_string_t *property_name_p); ecma_value_t ecma_op_object_has_property (ecma_object_t *object_p, ecma_string_t *property_name_p); ecma_value_t ecma_op_object_find_own (ecma_value_t base_value, ecma_object_t *object_p, ecma_string_t *property_name_p); ecma_value_t ecma_op_object_find (ecma_object_t *object_p, ecma_string_t *property_name_p); diff --git a/jerry-core/ecma/operations/ecma-typedarray-object.c b/jerry-core/ecma/operations/ecma-typedarray-object.c index 397969697..8e635a2e4 100644 --- a/jerry-core/ecma/operations/ecma-typedarray-object.c +++ b/jerry-core/ecma/operations/ecma-typedarray-object.c @@ -634,7 +634,7 @@ ecma_get_typedarray_getter_fn (ecma_typedarray_type_t typedarray_id) /**< typeda */ extern inline ecma_value_t JERRY_ATTR_ALWAYS_INLINE ecma_get_typedarray_element (ecma_typedarray_info_t *info_p, /**< typedarray info */ - ecma_number_t num) /**< element index */ + uint32_t index) /**< element index */ { uint8_t *buffer_p = ecma_typedarray_get_buffer (info_p); @@ -643,14 +643,12 @@ ecma_get_typedarray_element (ecma_typedarray_info_t *info_p, /**< typedarray inf return ECMA_VALUE_ERROR; } - if (ecma_number_is_negative (num) - || num >= info_p->length - || ((ecma_number_t) (uint32_t) num) != num) + if (index >= info_p->length) { return ECMA_VALUE_UNDEFINED; } - return ecma_typedarray_getters[info_p->id](buffer_p + ((uint32_t) num << info_p->shift)); + return ecma_typedarray_getters[info_p->id](buffer_p + (index << info_p->shift)); } /* ecma_get_typedarray_element */ /** @@ -670,7 +668,7 @@ ecma_get_typedarray_setter_fn (ecma_typedarray_type_t typedarray_id) /**< typeda extern inline ecma_value_t JERRY_ATTR_ALWAYS_INLINE ecma_set_typedarray_element (ecma_typedarray_info_t *info_p, /**< typedarray info */ ecma_value_t value, /**< value to be set */ - ecma_number_t num) /**< element index */ + uint32_t index) /**< element index */ { ecma_value_t to_num; if (ECMA_TYPEDARRAY_IS_BIGINT_TYPE (info_p->id)) @@ -701,9 +699,7 @@ ecma_set_typedarray_element (ecma_typedarray_info_t *info_p, /**< typedarray inf return ECMA_VALUE_ERROR; } - if (ecma_number_is_negative (num) - || num >= info_p->length - || ((ecma_number_t) (uint32_t) num) != num) + if (index >= info_p->length) { ecma_free_value (to_num); return ECMA_VALUE_FALSE; @@ -711,7 +707,7 @@ ecma_set_typedarray_element (ecma_typedarray_info_t *info_p, /**< typedarray inf ecma_free_value (to_num); - return ecma_typedarray_setters[info_p->id](buffer_p + ((uint32_t) num << info_p->shift), value); + return ecma_typedarray_setters[info_p->id](buffer_p + (index << info_p->shift), value); } /* ecma_set_typedarray_element */ /** @@ -1834,9 +1830,29 @@ ecma_is_typedarray (ecma_value_t value) /**< the target need to be checked */ } /* ecma_is_typedarray */ /** - * List names of a TypedArray object's integer indexed properties + * Checks whether the property name is a valid element index * - * @return void + * @return true, if valid + * false, otherwise + */ +bool +ecma_typedarray_is_element_index (ecma_string_t *property_name_p) /**< property name */ +{ + ecma_number_t num = ecma_string_to_number (property_name_p); + + if (num == 0) + { + return true; + } + + ecma_string_t *num_to_str = ecma_new_ecma_string_from_number (num); + bool is_same = ecma_compare_ecma_strings (property_name_p, num_to_str); + ecma_deref_ecma_string (num_to_str); + return is_same; +} /* ecma_typedarray_is_element_index */ + +/** + * List names of a TypedArray object's integer indexed properties */ void ecma_op_typedarray_list_lazy_property_names (ecma_object_t *obj_p, /**< a TypedArray object */ @@ -1873,65 +1889,54 @@ ecma_op_typedarray_list_lazy_property_names (ecma_object_t *obj_p, /**< a TypedA */ ecma_value_t ecma_op_typedarray_define_own_property (ecma_object_t *obj_p, /**< TypedArray object */ - ecma_string_t *prop_name_p, /**< property name */ + ecma_string_t *property_name_p, /**< property name */ const ecma_property_descriptor_t *property_desc_p) /**< property descriptor */ { JERRY_ASSERT (ecma_object_is_typedarray (obj_p)); - if (!ecma_prop_name_is_symbol (prop_name_p)) + if (JERRY_UNLIKELY (ecma_prop_name_is_symbol (property_name_p))) { - ecma_number_t num = ecma_string_to_number (prop_name_p); - bool is_same; - if (num <= 0) + return ecma_op_general_object_define_own_property (obj_p, property_name_p, property_desc_p); + } + + uint32_t index = ecma_string_get_array_index (property_name_p); + + if (index == ECMA_STRING_NOT_ARRAY_INDEX + && !ecma_typedarray_is_element_index (property_name_p)) + { + return ecma_op_general_object_define_own_property (obj_p, property_name_p, property_desc_p); + } + + if ((property_desc_p->flags & (JERRY_PROP_IS_GET_DEFINED | JERRY_PROP_IS_SET_DEFINED)) + || ((property_desc_p->flags & (JERRY_PROP_IS_CONFIGURABLE_DEFINED | JERRY_PROP_IS_CONFIGURABLE)) + == (JERRY_PROP_IS_CONFIGURABLE_DEFINED | JERRY_PROP_IS_CONFIGURABLE)) + || ((property_desc_p->flags & JERRY_PROP_IS_ENUMERABLE_DEFINED) + && !(property_desc_p->flags & JERRY_PROP_IS_ENUMERABLE)) + || ((property_desc_p->flags & JERRY_PROP_IS_WRITABLE_DEFINED) + && !(property_desc_p->flags & JERRY_PROP_IS_WRITABLE))) + { + return ecma_raise_property_redefinition (property_name_p, property_desc_p->flags); + } + + ecma_typedarray_info_t info = ecma_typedarray_get_info (obj_p); + + if (index == ECMA_STRING_NOT_ARRAY_INDEX + || index >= info.length) + { + return ECMA_VALUE_FALSE; + } + + if (property_desc_p->flags & JERRY_PROP_IS_VALUE_DEFINED) + { + ecma_value_t set_element = ecma_set_typedarray_element (&info, property_desc_p->value, index); + + if (ECMA_IS_VALUE_ERROR (set_element)) { - is_same = true; - } - else - { - ecma_string_t *num_to_str = ecma_new_ecma_string_from_number (num); - is_same = ecma_compare_ecma_strings (prop_name_p, num_to_str); - ecma_deref_ecma_string (num_to_str); - } - - if (is_same) - { - if ((property_desc_p->flags & (JERRY_PROP_IS_GET_DEFINED | JERRY_PROP_IS_SET_DEFINED)) - || ((property_desc_p->flags & (JERRY_PROP_IS_CONFIGURABLE_DEFINED | JERRY_PROP_IS_CONFIGURABLE)) - == (JERRY_PROP_IS_CONFIGURABLE_DEFINED | JERRY_PROP_IS_CONFIGURABLE)) - || ((property_desc_p->flags & JERRY_PROP_IS_ENUMERABLE_DEFINED) - && !(property_desc_p->flags & JERRY_PROP_IS_ENUMERABLE)) - || ((property_desc_p->flags & JERRY_PROP_IS_WRITABLE_DEFINED) - && !(property_desc_p->flags & JERRY_PROP_IS_WRITABLE))) - { - return ecma_raise_property_redefinition (prop_name_p, property_desc_p->flags); - } - - ecma_typedarray_info_t info = ecma_typedarray_get_info (obj_p); - - if (!ecma_op_is_integer (num) - || num >= info.length - || num < 0 - || (ecma_number_is_negative (num) && ecma_number_is_zero (num))) - { - return ECMA_VALUE_FALSE; - } - - if (property_desc_p->flags & JERRY_PROP_IS_VALUE_DEFINED) - { - ecma_value_t set_element = ecma_set_typedarray_element (&info, property_desc_p->value, num); - - if (ECMA_IS_VALUE_ERROR (set_element)) - { - return set_element; - } - - } - - return ECMA_VALUE_TRUE; + return set_element; } } - return ecma_op_general_object_define_own_property (obj_p, prop_name_p, property_desc_p); + return ECMA_VALUE_TRUE; } /* ecma_op_typedarray_define_own_property */ /** diff --git a/jerry-core/ecma/operations/ecma-typedarray-object.h b/jerry-core/ecma/operations/ecma-typedarray-object.h index 70c90bbd3..bf728e88c 100644 --- a/jerry-core/ecma/operations/ecma-typedarray-object.h +++ b/jerry-core/ecma/operations/ecma-typedarray-object.h @@ -33,10 +33,10 @@ lit_magic_string_id_t ecma_get_typedarray_magic_string_id (ecma_typedarray_type_ ecma_typedarray_getter_fn_t ecma_get_typedarray_getter_fn (ecma_typedarray_type_t typedarray_id); ecma_typedarray_setter_fn_t ecma_get_typedarray_setter_fn (ecma_typedarray_type_t typedarray_id); ecma_value_t ecma_get_typedarray_element (ecma_typedarray_info_t *info_p, - ecma_number_t num); + uint32_t index); ecma_value_t ecma_set_typedarray_element (ecma_typedarray_info_t *info_p, ecma_value_t value, - ecma_number_t num); + uint32_t index); bool ecma_typedarray_helper_is_typedarray (ecma_builtin_id_t builtin_id); ecma_typedarray_type_t ecma_get_typedarray_id (ecma_object_t *obj_p); ecma_builtin_id_t ecma_typedarray_helper_get_prototype_id (ecma_typedarray_type_t typedarray_id); @@ -62,11 +62,12 @@ ecma_typedarray_iterators_helper (ecma_value_t this_arg, ecma_iterator_kind_t ki bool ecma_object_is_typedarray (ecma_object_t *obj_p); bool ecma_is_typedarray (ecma_value_t target); +bool ecma_typedarray_is_element_index (ecma_string_t *property_name_p); void ecma_op_typedarray_list_lazy_property_names (ecma_object_t *obj_p, ecma_collection_t *prop_names_p, ecma_property_counter_t *prop_counter_p, jerry_property_filter_t filter); ecma_value_t ecma_op_typedarray_define_own_property (ecma_object_t *obj_p, - ecma_string_t *prop_name_p, + ecma_string_t *property_name_p, const ecma_property_descriptor_t *property_desc_p); ecma_value_t ecma_op_create_typedarray_with_type_and_length (ecma_typedarray_type_t typedarray_id, uint32_t array_length); diff --git a/jerry-core/vm/opcodes.c b/jerry-core/vm/opcodes.c index ea23deef9..864c9671e 100644 --- a/jerry-core/vm/opcodes.c +++ b/jerry-core/vm/opcodes.c @@ -1726,8 +1726,11 @@ opfunc_lexical_scope_has_restricted_binding (vm_frame_ctx_t *frame_ctx_p, /**< f NULL, ECMA_PROPERTY_GET_NO_OPTIONS); - return ecma_make_boolean_value ((property != ECMA_PROPERTY_TYPE_NOT_FOUND - && !ecma_is_property_configurable (property))); + JERRY_ASSERT (property == ECMA_PROPERTY_TYPE_NOT_FOUND + || ECMA_PROPERTY_IS_FOUND (property)); + + return ecma_make_boolean_value (property != ECMA_PROPERTY_TYPE_NOT_FOUND + && !ecma_is_property_configurable (property)); } /* opfunc_lexical_scope_has_restricted_binding */ #endif /* JERRY_ESNEXT */