Improve typedArray get, set (#3023)

Here are the following changes:
  - The getter and setter methods are callback based now, and we can use
    them with the proper typedArray id
  - The typedArray set_element and get_element methods are using memcpy now.
  - There is a new struct which contains basic informations from typedArray,
    and we are using this in most of the prototype methods.
  - Eliminated ecma_op_typedarray_set_index_prop and
    ecma_op_typedarray_get_index_prop, because these methods
    also calculated the same informations which are in the new
    struct, so we use the new method instead.

Co-authored-by: Robert Fancsik frobert@inf.u-szeged.hu
JerryScript-DCO-1.0-Signed-off-by: Adam Szilagyi aszilagy@inf.u-szeged.hu
This commit is contained in:
Szilagyi Adam
2019-10-02 16:39:26 +02:00
committed by Dániel Bátyai
parent f1883b9e7d
commit c3510fc03d
22 changed files with 935 additions and 888 deletions
@@ -15,7 +15,6 @@
#include "ecma-arraybuffer-object.h"
#include "ecma-builtins.h"
#include "ecma-builtin-typedarray-helpers.h"
#include "ecma-exceptions.h"
#include "ecma-gc.h"
#include "ecma-helpers.h"
@@ -250,7 +249,7 @@ ecma_op_dataview_get_set_view_value (ecma_value_t view, /**< the operation's 'vi
ecma_value_t is_little_endian_value, /**< the operation's
* 'isLittleEndian' argument */
ecma_value_t value_to_set, /**< the operation's 'value' argument */
uint8_t type) /**< the operation's 'type' argument */
ecma_typedarray_type_t id) /**< the operation's 'type' argument */
{
/* 1 - 2. */
ecma_dataview_object_t *view_p = ecma_op_dataview_get_object (view);
@@ -293,7 +292,7 @@ ecma_op_dataview_get_set_view_value (ecma_value_t view, /**< the operation's 'vi
uint32_t view_size = view_p->header.u.class_prop.u.length;
/* 12. */
uint8_t element_size = (uint8_t) (1 << (ecma_typedarray_helper_get_shift_size (type)));
uint8_t element_size = (uint8_t) (1 << (ecma_typedarray_helper_get_shift_size (id)));
/* 13. */
if ((uint32_t) get_index + element_size > view_size)
@@ -303,7 +302,6 @@ ecma_op_dataview_get_set_view_value (ecma_value_t view, /**< the operation's 'vi
/* 14. */
uint32_t buffer_index = (uint32_t) get_index + view_offset;
lit_magic_string_id_t id = ecma_typedarray_helper_get_magic_string (type);
lit_utf8_byte_t *block_p = ecma_arraybuffer_get_buffer (buffer_p) + buffer_index;
bool system_is_little_endian = ecma_dataview_check_little_endian ();
@@ -30,7 +30,8 @@
ecma_value_t ecma_op_dataview_create (const ecma_value_t *arguments_list_p, ecma_length_t arguments_list_len);
ecma_dataview_object_t *ecma_op_dataview_get_object (ecma_value_t this_arg);
ecma_value_t ecma_op_dataview_get_set_view_value (ecma_value_t view, ecma_value_t request_index,
ecma_value_t little_endian, ecma_value_t value_to_set, uint8_t type);
ecma_value_t little_endian, ecma_value_t value_to_set,
ecma_typedarray_type_t id);
/**
* @}
+44 -6
View File
@@ -25,9 +25,12 @@
#include "ecma-objects-arguments.h"
#include "ecma-objects-general.h"
#include "ecma-objects.h"
#include "jcontext.h"
#if ENABLED (JERRY_ES2015_BUILTIN_TYPEDARRAY)
#include "ecma-typedarray-object.h"
#include "ecma-arraybuffer-object.h"
#include "ecma-try-catch-macro.h"
#endif /* ENABLED (JERRY_ES2015_BUILTIN_TYPEDARRAY) */
/** \addtogroup ecma ECMA
@@ -181,7 +184,17 @@ ecma_op_object_get_own_property (ecma_object_t *object_p, /**< the object */
if (array_index != ECMA_STRING_NOT_ARRAY_INDEX)
{
ecma_value_t value = ecma_op_typedarray_get_index_prop (object_p, 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)
{
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);
value = ecma_make_number_value (num);
}
if (!ecma_is_value_undefined (value))
{
@@ -542,7 +555,18 @@ ecma_op_object_find_own (ecma_value_t base_value, /**< base value */
if (array_index != ECMA_STRING_NOT_ARRAY_INDEX)
{
return ecma_op_typedarray_get_index_prop (object_p, 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)
{
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);
return ecma_make_number_value (num);
}
ecma_number_t num = ecma_string_to_number (property_name_p);
@@ -1057,14 +1081,28 @@ ecma_op_object_put (ecma_object_t *object_p, /**< the object */
if (array_index != ECMA_STRING_NOT_ARRAY_INDEX)
{
bool set_status = ecma_op_typedarray_set_index_prop (object_p, array_index, value);
ecma_number_t num_var;
ecma_value_t error = ecma_get_number (value, &num_var);
if (set_status)
if (ECMA_IS_VALUE_ERROR (error))
{
return ECMA_VALUE_TRUE;
ecma_free_value (JERRY_CONTEXT (error_value));
return ecma_reject (is_throw);
}
return ecma_reject (is_throw);
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)
{
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);
return ECMA_VALUE_TRUE;
}
ecma_number_t num = ecma_string_to_number (property_name_p);
File diff suppressed because it is too large Load Diff
@@ -17,6 +17,7 @@
#define ECMA_TYPEDARRAY_OBJECT_H
#include "ecma-globals.h"
#include "ecma-builtins.h"
#if ENABLED (JERRY_ES2015_BUILTIN_TYPEDARRAY)
@@ -27,12 +28,25 @@
* @{
*/
uint8_t ecma_typedarray_helper_get_shift_size (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_number_t ecma_get_typedarray_element (lit_utf8_byte_t *src_p,
ecma_typedarray_type_t typedarray_id);
void ecma_set_typedarray_element (lit_utf8_byte_t *dst_p,
ecma_number_t value,
ecma_typedarray_type_t typedarray_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_builtin_id_t ecma_typedarray_helper_get_prototype_id (ecma_typedarray_type_t typedarray_id);
ecma_typedarray_type_t ecma_typedarray_helper_builtin_to_typedarray_id (ecma_builtin_id_t builtin_id);
ecma_value_t ecma_op_typedarray_from (ecma_value_t items_val,
ecma_value_t map_fn_val,
ecma_value_t this_val,
ecma_object_t *proto_p,
uint8_t element_size_shift,
lit_magic_string_id_t class_id);
ecma_typedarray_type_t typedarray_id);
ecma_length_t ecma_typedarray_get_length (ecma_object_t *typedarray_p);
ecma_length_t ecma_typedarray_get_offset (ecma_object_t *typedarray_p);
lit_utf8_byte_t *ecma_typedarray_get_buffer (ecma_object_t *typedarray_p);
@@ -42,26 +56,20 @@ ecma_value_t ecma_op_create_typedarray (const ecma_value_t *arguments_list_p,
ecma_length_t arguments_list_len,
ecma_object_t *proto_p,
uint8_t element_size_shift,
lit_magic_string_id_t class_id);
ecma_typedarray_type_t typedarray_id);
bool ecma_is_typedarray (ecma_value_t target);
void ecma_set_typedarray_element (lit_utf8_byte_t *dst_p,
ecma_number_t value,
lit_magic_string_id_t class_id);
ecma_number_t ecma_get_typedarray_element (lit_utf8_byte_t *src,
lit_magic_string_id_t class_id);
void ecma_op_typedarray_list_lazy_property_names (ecma_object_t *obj_p,
ecma_collection_t *main_collection_p);
ecma_value_t ecma_op_typedarray_get_index_prop (ecma_object_t *obj_p, uint32_t index);
bool ecma_op_typedarray_define_index_prop (ecma_object_t *obj_p,
uint32_t index,
const ecma_property_descriptor_t *property_desc_p);
bool ecma_op_typedarray_set_index_prop (ecma_object_t *obj_p, uint32_t index, ecma_value_t value);
ecma_value_t ecma_op_create_typedarray_with_type_and_length (ecma_object_t *obj_p,
ecma_length_t array_length);
ecma_typedarray_info_t ecma_typedarray_get_info (ecma_object_t *typedarray_p);
ecma_value_t ecma_typedarray_create_object_with_length (ecma_length_t array_length,
ecma_object_t *proto_p,
uint8_t element_size_shift,
lit_magic_string_id_t class_id);
ecma_typedarray_type_t typedarray_id);
/**
* @}