Optimize typed array access (#4806)

Use uint32 indexes instead of double indexes.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
Zoltan Herczeg
2021-11-02 11:07:56 +01:00
committed by GitHub
parent 960b99766c
commit 89e367bbfd
10 changed files with 203 additions and 190 deletions
+5 -1
View File
@@ -3309,7 +3309,11 @@ jerry_has_own_property (const jerry_value_t obj_val, /**< object value */
} }
#endif /* JERRY_BUILTIN_PROXY */ #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 */ } /* jerry_has_own_property */
/** /**
+13
View File
@@ -514,6 +514,19 @@ typedef enum
*/ */
#define ECMA_PROPERTY_TYPE_NOT_FOUND_AND_STOP ECMA_PROPERTY_TYPE_DELETED #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. * Abstract property representation.
* *
@@ -147,7 +147,7 @@ ecma_builtin_object_prototype_object_has_own_property (ecma_object_t *obj_p, /**
} }
#endif /* JERRY_BUILTIN_PROXY */ #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 */ } /* ecma_builtin_object_prototype_object_has_own_property */
/** /**
@@ -1352,7 +1352,7 @@ static ecma_value_t
ecma_builtin_typedarray_prototype_at (ecma_typedarray_info_t *info_p, /**< object info */ ecma_builtin_typedarray_prototype_at (ecma_typedarray_info_t *info_p, /**< object info */
const ecma_value_t index) /**< index argument */ 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_length_t res_index;
ecma_value_t return_value = ecma_builtin_helper_calculate_index (index, len, &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 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 */ } /* ecma_builtin_typedarray_prototype_at */
/** /**
@@ -102,8 +102,10 @@ ecma_op_general_object_delete (ecma_object_t *obj_p, /**< the object */
ECMA_PROPERTY_GET_NO_OPTIONS); ECMA_PROPERTY_GET_NO_OPTIONS);
/* 2. */ /* 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; 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, &ext_property_ref.property_ref,
ECMA_PROPERTY_GET_VALUE | ECMA_PROPERTY_GET_EXT_REFERENCE); 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. */ /* 3. */
if (!ecma_op_ordinary_object_is_extensible (object_p)) if (!ecma_op_ordinary_object_is_extensible (object_p))
{ {
+93 -116
View File
@@ -139,49 +139,42 @@ ecma_op_object_get_own_property (ecma_object_t *object_p, /**< the object */
{ {
break; break;
} }
ecma_number_t num = ecma_string_to_number (property_name_p);
bool is_same; uint32_t index = ecma_string_get_array_index (property_name_p);
if (num <= 0)
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 else
{ {
ecma_string_t *num_to_str = ecma_new_ecma_string_from_number (num); ecma_fast_free_value (value);
is_same = ecma_compare_ecma_strings (property_name_p, num_to_str);
ecma_deref_ecma_string (num_to_str);
} }
if (is_same) return ECMA_PROPERTY_ENUMERABLE_WRITABLE | ECMA_PROPERTY_VIRTUAL;
{
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;
} }
#endif /* JERRY_BUILTIN_TYPEDARRAY */ #endif /* JERRY_BUILTIN_TYPEDARRAY */
#if JERRY_MODULE_SYSTEM #if JERRY_MODULE_SYSTEM
@@ -457,48 +450,25 @@ ecma_op_object_has_property (ecma_object_t *object_p, /**< the object */
} }
#endif /* JERRY_BUILTIN_PROXY */ #endif /* JERRY_BUILTIN_PROXY */
#if JERRY_BUILTIN_TYPEDARRAY /* 2 - 3. */
if (ecma_object_is_typedarray (object_p) && !ecma_prop_name_is_symbol (property_name_p)) 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); #if JERRY_BUILTIN_TYPEDARRAY
bool is_same; if (JERRY_UNLIKELY (property == ECMA_PROPERTY_TYPE_NOT_FOUND_AND_THROW))
if (num <= 0)
{ {
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 */ #endif /* JERRY_BUILTIN_TYPEDARRAY */
/* 2 - 3. */ JERRY_ASSERT (property == ECMA_PROPERTY_TYPE_NOT_FOUND_AND_STOP
if (ecma_op_ordinary_object_has_own_property (object_p, property_name_p)) || ECMA_PROPERTY_IS_FOUND (property));
{
return ECMA_VALUE_TRUE; 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); 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; break;
} }
ecma_number_t num = ecma_string_to_number (property_name_p); uint32_t index = ecma_string_get_array_index (property_name_p);
bool is_same;
if (num <= 0) if (index == ECMA_STRING_NOT_ARRAY_INDEX)
{ {
is_same = true; JERRY_ASSERT (index == UINT32_MAX);
}
else if (!ecma_typedarray_is_element_index (property_name_p))
{ {
ecma_string_t *num_to_str = ecma_new_ecma_string_from_number (num); break;
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);
{ return ecma_get_typedarray_element (&info, index);
ecma_typedarray_info_t info = ecma_typedarray_get_info (object_p);
return ecma_get_typedarray_element (&info, num);
}
break;
} }
#endif /* JERRY_BUILTIN_TYPEDARRAY */ #endif /* JERRY_BUILTIN_TYPEDARRAY */
#if JERRY_MODULE_SYSTEM #if JERRY_MODULE_SYSTEM
@@ -1447,25 +1411,20 @@ ecma_op_object_put_with_receiver (ecma_object_t *object_p, /**< the object */
break; break;
} }
ecma_number_t num = ecma_string_to_number (property_name_p); uint32_t index = ecma_string_get_array_index (property_name_p);
bool is_same;
if (num <= 0) if (index == ECMA_STRING_NOT_ARRAY_INDEX)
{ {
is_same = true; JERRY_ASSERT (index == UINT32_MAX);
}
else if (!ecma_typedarray_is_element_index (property_name_p))
{ {
ecma_string_t *num_to_str = ecma_new_ecma_string_from_number (num); break;
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);
{ return ecma_set_typedarray_element (&info, value, index);
ecma_typedarray_info_t info = ecma_typedarray_get_info (object_p);
return ecma_set_typedarray_element (&info, value, num);
}
break;
} }
#endif /* JERRY_BUILTIN_TYPEDARRAY */ #endif /* JERRY_BUILTIN_TYPEDARRAY */
#if JERRY_MODULE_SYSTEM #if JERRY_MODULE_SYSTEM
@@ -1668,8 +1627,7 @@ ecma_op_object_put_with_receiver (ecma_object_t *object_p, /**< the object */
&property_ref, &property_ref,
ECMA_PROPERTY_GET_NO_OPTIONS); ECMA_PROPERTY_GET_NO_OPTIONS);
if (inherited_property != ECMA_PROPERTY_TYPE_NOT_FOUND if (ECMA_PROPERTY_IS_FOUND (inherited_property))
&& inherited_property != ECMA_PROPERTY_TYPE_NOT_FOUND_AND_STOP)
{ {
JERRY_ASSERT (ECMA_PROPERTY_IS_NAMED_PROPERTY (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); create_new_property = ecma_is_property_writable (inherited_property);
break; break;
} }
JERRY_ASSERT (inherited_property == ECMA_PROPERTY_TYPE_NOT_FOUND
|| inherited_property == ECMA_PROPERTY_TYPE_NOT_FOUND_AND_STOP);
} }
#if JERRY_BUILTIN_PROXY #if JERRY_BUILTIN_PROXY
@@ -1962,13 +1923,18 @@ ecma_op_object_get_own_property_descriptor (ecma_object_t *object_p, /**< the ob
&property_ref, &property_ref,
ECMA_PROPERTY_GET_VALUE); 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; 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 * @return true - if property is found
* false - otherwise * 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_op_ordinary_object_has_own_property (ecma_object_t *object_p, /**< the object */
ecma_string_t *property_name_p) /**< property name */ 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, NULL,
ECMA_PROPERTY_GET_NO_OPTIONS); 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 */ } /* ecma_op_ordinary_object_has_own_property */
#if JERRY_BUILTIN_WEAKREF || JERRY_BUILTIN_CONTAINER #if JERRY_BUILTIN_WEAKREF || JERRY_BUILTIN_CONTAINER
+1 -1
View File
@@ -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_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); 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_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_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); ecma_value_t ecma_op_object_find (ecma_object_t *object_p, ecma_string_t *property_name_p);
@@ -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 extern inline ecma_value_t JERRY_ATTR_ALWAYS_INLINE
ecma_get_typedarray_element (ecma_typedarray_info_t *info_p, /**< typedarray info */ 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); 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; return ECMA_VALUE_ERROR;
} }
if (ecma_number_is_negative (num) if (index >= info_p->length)
|| num >= info_p->length
|| ((ecma_number_t) (uint32_t) num) != num)
{ {
return ECMA_VALUE_UNDEFINED; 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 */ } /* 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 extern inline ecma_value_t JERRY_ATTR_ALWAYS_INLINE
ecma_set_typedarray_element (ecma_typedarray_info_t *info_p, /**< typedarray info */ ecma_set_typedarray_element (ecma_typedarray_info_t *info_p, /**< typedarray info */
ecma_value_t value, /**< value to be set */ ecma_value_t value, /**< value to be set */
ecma_number_t num) /**< element index */ uint32_t index) /**< element index */
{ {
ecma_value_t to_num; ecma_value_t to_num;
if (ECMA_TYPEDARRAY_IS_BIGINT_TYPE (info_p->id)) 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; return ECMA_VALUE_ERROR;
} }
if (ecma_number_is_negative (num) if (index >= info_p->length)
|| num >= info_p->length
|| ((ecma_number_t) (uint32_t) num) != num)
{ {
ecma_free_value (to_num); ecma_free_value (to_num);
return ECMA_VALUE_FALSE; 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); 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 */ } /* ecma_set_typedarray_element */
/** /**
@@ -1834,9 +1830,29 @@ ecma_is_typedarray (ecma_value_t value) /**< the target need to be checked */
} /* ecma_is_typedarray */ } /* 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 void
ecma_op_typedarray_list_lazy_property_names (ecma_object_t *obj_p, /**< a TypedArray object */ 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_value_t
ecma_op_typedarray_define_own_property (ecma_object_t *obj_p, /**< TypedArray object */ 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 */ const ecma_property_descriptor_t *property_desc_p) /**< property descriptor */
{ {
JERRY_ASSERT (ecma_object_is_typedarray (obj_p)); 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); return ecma_op_general_object_define_own_property (obj_p, property_name_p, property_desc_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
&& !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; return set_element;
}
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 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 */ } /* ecma_op_typedarray_define_own_property */
/** /**
@@ -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_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_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_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 ecma_set_typedarray_element (ecma_typedarray_info_t *info_p,
ecma_value_t value, ecma_value_t value,
ecma_number_t num); uint32_t index);
bool ecma_typedarray_helper_is_typedarray (ecma_builtin_id_t builtin_id); 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_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); 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_object_is_typedarray (ecma_object_t *obj_p);
bool ecma_is_typedarray (ecma_value_t target); 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, 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, ecma_property_counter_t *prop_counter_p,
jerry_property_filter_t filter); jerry_property_filter_t filter);
ecma_value_t ecma_op_typedarray_define_own_property (ecma_object_t *obj_p, 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); 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, ecma_value_t ecma_op_create_typedarray_with_type_and_length (ecma_typedarray_type_t typedarray_id,
uint32_t array_length); uint32_t array_length);
+5 -2
View File
@@ -1726,8 +1726,11 @@ opfunc_lexical_scope_has_restricted_binding (vm_frame_ctx_t *frame_ctx_p, /**< f
NULL, NULL,
ECMA_PROPERTY_GET_NO_OPTIONS); ECMA_PROPERTY_GET_NO_OPTIONS);
return ecma_make_boolean_value ((property != ECMA_PROPERTY_TYPE_NOT_FOUND JERRY_ASSERT (property == ECMA_PROPERTY_TYPE_NOT_FOUND
&& !ecma_is_property_configurable (property))); || 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 */ } /* opfunc_lexical_scope_has_restricted_binding */
#endif /* JERRY_ESNEXT */ #endif /* JERRY_ESNEXT */