Improve ecma_typedarray_info_t (#3205)
- The structure members have been renamed and the members got more detailed description. - Updated the usage of the typedarray info structure in all occurrences to use absolute addressing from the underlying arraybuffer pointer. This patch also fixes #3204. JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
This commit is contained in:
@@ -185,14 +185,12 @@ ecma_op_object_get_own_property (ecma_object_t *object_p, /**< the object */
|
||||
if (array_index != ECMA_STRING_NOT_ARRAY_INDEX)
|
||||
{
|
||||
ecma_typedarray_info_t info = ecma_typedarray_get_info (object_p);
|
||||
ecma_typedarray_getter_fn_t getter_cb = ecma_get_typedarray_getter_fn (info.typedarray_id);
|
||||
ecma_value_t value = ECMA_VALUE_UNDEFINED;
|
||||
|
||||
if (array_index < info.typedarray_length)
|
||||
if (array_index < info.length)
|
||||
{
|
||||
ecma_length_t byte_pos = (array_index << info.shift) + info.offset;
|
||||
lit_utf8_byte_t *src_buffer = ecma_arraybuffer_get_buffer (info.typedarray_buffer_p) + byte_pos;
|
||||
ecma_number_t num = getter_cb (src_buffer);
|
||||
ecma_length_t byte_pos = array_index << info.shift;
|
||||
ecma_number_t num = ecma_get_typedarray_element (info.buffer_p + byte_pos, info.id);
|
||||
value = ecma_make_number_value (num);
|
||||
}
|
||||
|
||||
@@ -556,16 +554,14 @@ ecma_op_object_find_own (ecma_value_t base_value, /**< base value */
|
||||
if (array_index != ECMA_STRING_NOT_ARRAY_INDEX)
|
||||
{
|
||||
ecma_typedarray_info_t info = ecma_typedarray_get_info (object_p);
|
||||
ecma_typedarray_getter_fn_t getter_cb = ecma_get_typedarray_getter_fn (info.typedarray_id);
|
||||
|
||||
if (array_index >= info.typedarray_length)
|
||||
if (array_index >= info.length)
|
||||
{
|
||||
return ECMA_VALUE_UNDEFINED;
|
||||
}
|
||||
|
||||
ecma_length_t byte_pos = (array_index << info.shift) + info.offset;
|
||||
lit_utf8_byte_t *src_buffer = ecma_arraybuffer_get_buffer (info.typedarray_buffer_p) + byte_pos;
|
||||
ecma_number_t num = getter_cb (src_buffer);
|
||||
ecma_length_t byte_pos = array_index << info.shift;
|
||||
ecma_number_t num = ecma_get_typedarray_element (info.buffer_p + byte_pos, info.id);
|
||||
return ecma_make_number_value (num);
|
||||
}
|
||||
|
||||
@@ -1091,16 +1087,14 @@ ecma_op_object_put (ecma_object_t *object_p, /**< the object */
|
||||
}
|
||||
|
||||
ecma_typedarray_info_t info = ecma_typedarray_get_info (object_p);
|
||||
ecma_typedarray_setter_fn_t setter_cb = ecma_get_typedarray_setter_fn (info.typedarray_id);
|
||||
|
||||
if (array_index >= info.typedarray_length)
|
||||
if (array_index >= info.length)
|
||||
{
|
||||
return ecma_reject (is_throw);
|
||||
}
|
||||
|
||||
ecma_length_t byte_pos = (array_index << info.shift) + info.offset;
|
||||
lit_utf8_byte_t *src_buffer = ecma_arraybuffer_get_buffer (info.typedarray_buffer_p) + byte_pos;
|
||||
setter_cb (src_buffer, num_var);
|
||||
ecma_length_t byte_pos = array_index << info.shift;
|
||||
ecma_set_typedarray_element (info.buffer_p + byte_pos, num_var, info.id);
|
||||
|
||||
return ECMA_VALUE_TRUE;
|
||||
}
|
||||
|
||||
@@ -692,7 +692,7 @@ ecma_op_typedarray_from (ecma_value_t items_val, /**< the source array-like obje
|
||||
{
|
||||
ecma_object_t *new_typedarray_p = ecma_get_object_from_value (new_typedarray);
|
||||
ecma_typedarray_info_t info = ecma_typedarray_get_info (new_typedarray_p);
|
||||
ecma_typedarray_setter_fn_t setter_cb = ecma_get_typedarray_setter_fn (info.typedarray_id);
|
||||
ecma_typedarray_setter_fn_t setter_cb = ecma_get_typedarray_setter_fn (info.id);
|
||||
ecma_value_t error = ECMA_VALUE_EMPTY;
|
||||
ecma_number_t num_var;
|
||||
|
||||
@@ -724,14 +724,13 @@ ecma_op_typedarray_from (ecma_value_t items_val, /**< the source array-like obje
|
||||
ret_value = ECMA_VALUE_ERROR;
|
||||
}
|
||||
|
||||
if (index >= info.typedarray_length)
|
||||
if (index >= info.length)
|
||||
{
|
||||
ret_value = ecma_raise_type_error (ECMA_ERR_MSG ("Invalid argument type."));
|
||||
}
|
||||
|
||||
ecma_length_t byte_pos = (index << info.shift) + info.offset;
|
||||
lit_utf8_byte_t *src_buffer = ecma_arraybuffer_get_buffer (info.typedarray_buffer_p) + byte_pos;
|
||||
setter_cb (src_buffer, num_var);
|
||||
ecma_length_t byte_pos = index << info.shift;
|
||||
setter_cb (info.buffer_p + byte_pos, num_var);
|
||||
|
||||
ECMA_FINALIZE (mapped_value);
|
||||
}
|
||||
@@ -744,14 +743,13 @@ ecma_op_typedarray_from (ecma_value_t items_val, /**< the source array-like obje
|
||||
ret_value = ECMA_VALUE_ERROR;
|
||||
}
|
||||
|
||||
if (index >= info.typedarray_length)
|
||||
if (index >= info.length)
|
||||
{
|
||||
ret_value = ecma_raise_type_error (ECMA_ERR_MSG ("Invalid argument type."));
|
||||
}
|
||||
|
||||
ecma_length_t byte_pos = (index << info.shift) + info.offset;
|
||||
lit_utf8_byte_t *src_buffer = ecma_arraybuffer_get_buffer (info.typedarray_buffer_p) + byte_pos;
|
||||
setter_cb (src_buffer, num_var);
|
||||
ecma_length_t byte_pos = index << info.shift;
|
||||
setter_cb (info.buffer_p + byte_pos, num_var);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1101,9 +1099,6 @@ ecma_op_typedarray_define_index_prop (ecma_object_t *obj_p, /**< a TypedArray ob
|
||||
|
||||
if (property_desc_p->flags & ECMA_PROP_IS_VALUE_DEFINED)
|
||||
{
|
||||
ecma_typedarray_info_t info = ecma_typedarray_get_info (obj_p);
|
||||
ecma_typedarray_setter_fn_t setter_cb = ecma_get_typedarray_setter_fn (info.typedarray_id);
|
||||
|
||||
ecma_number_t num_var;
|
||||
ecma_value_t error = ecma_get_number (property_desc_p->value, &num_var);
|
||||
|
||||
@@ -1112,16 +1107,15 @@ ecma_op_typedarray_define_index_prop (ecma_object_t *obj_p, /**< a TypedArray ob
|
||||
ecma_free_value (JERRY_CONTEXT (error_value));
|
||||
return false;
|
||||
}
|
||||
ecma_typedarray_info_t info = ecma_typedarray_get_info (obj_p);
|
||||
|
||||
if (index >= info.typedarray_length)
|
||||
if (index >= info.length)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
ecma_length_t byte_pos = (index << info.shift) + info.offset;
|
||||
lit_utf8_byte_t *src_buffer = ecma_arraybuffer_get_buffer (info.typedarray_buffer_p) + byte_pos;
|
||||
setter_cb (src_buffer, num_var);
|
||||
|
||||
lit_utf8_byte_t *src_buffer = info.buffer_p + (index << info.shift);
|
||||
ecma_set_typedarray_element (src_buffer, num_var, info.id);
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -1191,13 +1185,13 @@ ecma_typedarray_get_info (ecma_object_t *typedarray_p)
|
||||
{
|
||||
ecma_typedarray_info_t info;
|
||||
|
||||
info.typedarray_buffer_p = ecma_typedarray_get_arraybuffer (typedarray_p);
|
||||
info.buffer_p = ecma_typedarray_get_buffer (typedarray_p);
|
||||
info.typedarray_id = ecma_get_typedarray_id (typedarray_p);
|
||||
info.typedarray_length = ecma_typedarray_get_length (typedarray_p);
|
||||
info.offset = ecma_typedarray_get_offset (typedarray_p);
|
||||
info.id = ecma_get_typedarray_id (typedarray_p);
|
||||
info.length = ecma_typedarray_get_length (typedarray_p);
|
||||
info.shift = ecma_typedarray_get_element_size_shift (typedarray_p);
|
||||
info.element_size = (uint8_t) (1 << info.shift);
|
||||
info.offset = ecma_typedarray_get_offset (typedarray_p);
|
||||
info.array_buffer_p = ecma_typedarray_get_arraybuffer (typedarray_p);
|
||||
info.buffer_p = ecma_arraybuffer_get_buffer (info.array_buffer_p) + info.offset;
|
||||
|
||||
return info;
|
||||
} /* ecma_typedarray_get_info */
|
||||
|
||||
Reference in New Issue
Block a user