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:
committed by
Dániel Bátyai
parent
f1883b9e7d
commit
c3510fc03d
@@ -41,6 +41,7 @@ enum
|
||||
ECMA_DATAVIEW_PROTOTYPE_BYTE_OFFSET_GETTER,
|
||||
ECMA_DATAVIEW_PROTOTYPE_GET_INT8,
|
||||
ECMA_DATAVIEW_PROTOTYPE_GET_UINT8,
|
||||
ECMA_DATAVIEW_PROTOTYPE_GET_UINT8_CLAMPED, /* unused value */
|
||||
ECMA_DATAVIEW_PROTOTYPE_GET_INT16,
|
||||
ECMA_DATAVIEW_PROTOTYPE_GET_UINT16,
|
||||
ECMA_DATAVIEW_PROTOTYPE_GET_INT32,
|
||||
@@ -51,6 +52,7 @@ enum
|
||||
#endif /* ENABLED (JERRY_NUMBER_TYPE_FLOAT64) */
|
||||
ECMA_DATAVIEW_PROTOTYPE_SET_INT8,
|
||||
ECMA_DATAVIEW_PROTOTYPE_SET_UINT8,
|
||||
ECMA_DATAVIEW_PROTOTYPE_SET_UINT8_CLAMPED, /* unused value */
|
||||
ECMA_DATAVIEW_PROTOTYPE_SET_INT16,
|
||||
ECMA_DATAVIEW_PROTOTYPE_SET_UINT16,
|
||||
ECMA_DATAVIEW_PROTOTYPE_SET_INT32,
|
||||
@@ -75,23 +77,6 @@ enum
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Corresponding typedarray mappings for the {get,set}{[U]int, Float}{8, 16, 32, 64} routines
|
||||
*/
|
||||
static const uint8_t ecma_dataview_type_mapping[] =
|
||||
{
|
||||
ECMA_BUILTIN_ID_INT8ARRAY,
|
||||
ECMA_BUILTIN_ID_UINT8ARRAY,
|
||||
ECMA_BUILTIN_ID_INT16ARRAY,
|
||||
ECMA_BUILTIN_ID_UINT16ARRAY,
|
||||
ECMA_BUILTIN_ID_INT32ARRAY,
|
||||
ECMA_BUILTIN_ID_UINT32ARRAY,
|
||||
ECMA_BUILTIN_ID_FLOAT32ARRAY,
|
||||
#if ENABLED (JERRY_NUMBER_TYPE_FLOAT64)
|
||||
ECMA_BUILTIN_ID_FLOAT64ARRAY,
|
||||
#endif /* ENABLED (JERRY_NUMBER_TYPE_FLOAT64) */
|
||||
};
|
||||
|
||||
/**
|
||||
* The DataView.prototype object's {buffer, byteOffset, byteLength} getters
|
||||
*
|
||||
@@ -168,9 +153,9 @@ ecma_builtin_dataview_prototype_dispatch_routine (uint16_t builtin_routine_id, /
|
||||
case ECMA_DATAVIEW_PROTOTYPE_GET_UINT32:
|
||||
{
|
||||
ecma_value_t little_endian = arguments_number > 1 ? arguments_list_p[1] : ECMA_VALUE_FALSE;
|
||||
uint8_t type = ecma_dataview_type_mapping[builtin_routine_id - ECMA_DATAVIEW_PROTOTYPE_GET_INT8];
|
||||
ecma_typedarray_type_t id = (ecma_typedarray_type_t) (builtin_routine_id - ECMA_DATAVIEW_PROTOTYPE_GET_INT8);
|
||||
|
||||
return ecma_op_dataview_get_set_view_value (this_arg, byte_offset, little_endian, ECMA_VALUE_EMPTY, type);
|
||||
return ecma_op_dataview_get_set_view_value (this_arg, byte_offset, little_endian, ECMA_VALUE_EMPTY, id);
|
||||
}
|
||||
case ECMA_DATAVIEW_PROTOTYPE_SET_FLOAT32:
|
||||
#if ENABLED (JERRY_NUMBER_TYPE_FLOAT64)
|
||||
@@ -183,25 +168,25 @@ ecma_builtin_dataview_prototype_dispatch_routine (uint16_t builtin_routine_id, /
|
||||
{
|
||||
ecma_value_t value_to_set = arguments_number > 1 ? arguments_list_p[1] : ECMA_VALUE_UNDEFINED;
|
||||
ecma_value_t little_endian = arguments_number > 2 ? arguments_list_p[2] : ECMA_VALUE_FALSE;
|
||||
uint8_t type = ecma_dataview_type_mapping[builtin_routine_id - ECMA_DATAVIEW_PROTOTYPE_SET_INT8];
|
||||
ecma_typedarray_type_t id = (ecma_typedarray_type_t) (builtin_routine_id - ECMA_DATAVIEW_PROTOTYPE_SET_INT8);
|
||||
|
||||
return ecma_op_dataview_get_set_view_value (this_arg, byte_offset, little_endian, value_to_set, type);
|
||||
return ecma_op_dataview_get_set_view_value (this_arg, byte_offset, little_endian, value_to_set, id);
|
||||
}
|
||||
case ECMA_DATAVIEW_PROTOTYPE_GET_INT8:
|
||||
case ECMA_DATAVIEW_PROTOTYPE_GET_UINT8:
|
||||
{
|
||||
uint8_t type = ecma_dataview_type_mapping[builtin_routine_id - ECMA_DATAVIEW_PROTOTYPE_GET_INT8];
|
||||
ecma_typedarray_type_t id = (ecma_typedarray_type_t) (builtin_routine_id - ECMA_DATAVIEW_PROTOTYPE_GET_INT8);
|
||||
|
||||
return ecma_op_dataview_get_set_view_value (this_arg, byte_offset, ECMA_VALUE_FALSE, ECMA_VALUE_EMPTY, type);
|
||||
return ecma_op_dataview_get_set_view_value (this_arg, byte_offset, ECMA_VALUE_FALSE, ECMA_VALUE_EMPTY, id);
|
||||
}
|
||||
default:
|
||||
{
|
||||
JERRY_ASSERT (builtin_routine_id == ECMA_DATAVIEW_PROTOTYPE_SET_INT8
|
||||
|| builtin_routine_id == ECMA_DATAVIEW_PROTOTYPE_SET_UINT8);
|
||||
ecma_value_t value_to_set = arguments_number > 1 ? arguments_list_p[1] : ECMA_VALUE_UNDEFINED;
|
||||
uint8_t type = ecma_dataview_type_mapping[builtin_routine_id - ECMA_DATAVIEW_PROTOTYPE_SET_INT8];
|
||||
ecma_typedarray_type_t id = (ecma_typedarray_type_t) (builtin_routine_id - ECMA_DATAVIEW_PROTOTYPE_SET_INT8);
|
||||
|
||||
return ecma_op_dataview_get_set_view_value (this_arg, byte_offset, ECMA_VALUE_FALSE, value_to_set, type);
|
||||
return ecma_op_dataview_get_set_view_value (this_arg, byte_offset, ECMA_VALUE_FALSE, value_to_set, id);
|
||||
}
|
||||
}
|
||||
} /* ecma_builtin_dataview_prototype_dispatch_routine */
|
||||
|
||||
@@ -288,42 +288,31 @@ BUILTIN (ECMA_BUILTIN_ID_TYPEDARRAY_PROTOTYPE,
|
||||
true,
|
||||
typedarray_prototype)
|
||||
|
||||
/* The %TypedArray% intrinsic object (ES2015 22.2.1) */
|
||||
/* The %TypedArray% intrinsic object (ES2015 22.2.1)
|
||||
Note: The routines must be in this order. */
|
||||
BUILTIN_ROUTINE (ECMA_BUILTIN_ID_TYPEDARRAY,
|
||||
ECMA_OBJECT_TYPE_FUNCTION,
|
||||
ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE,
|
||||
true,
|
||||
typedarray)
|
||||
|
||||
BUILTIN (ECMA_BUILTIN_ID_INT8ARRAY_PROTOTYPE,
|
||||
ECMA_OBJECT_TYPE_GENERAL,
|
||||
ECMA_BUILTIN_ID_TYPEDARRAY_PROTOTYPE,
|
||||
true,
|
||||
int8array_prototype)
|
||||
|
||||
BUILTIN_ROUTINE (ECMA_BUILTIN_ID_INT8ARRAY,
|
||||
ECMA_OBJECT_TYPE_FUNCTION,
|
||||
ECMA_BUILTIN_ID_TYPEDARRAY,
|
||||
true,
|
||||
int8array)
|
||||
|
||||
BUILTIN (ECMA_BUILTIN_ID_UINT8ARRAY_PROTOTYPE,
|
||||
ECMA_OBJECT_TYPE_GENERAL,
|
||||
ECMA_BUILTIN_ID_TYPEDARRAY_PROTOTYPE,
|
||||
true,
|
||||
uint8array_prototype)
|
||||
|
||||
BUILTIN_ROUTINE (ECMA_BUILTIN_ID_UINT8ARRAY,
|
||||
ECMA_OBJECT_TYPE_FUNCTION,
|
||||
ECMA_BUILTIN_ID_TYPEDARRAY,
|
||||
true,
|
||||
uint8array)
|
||||
|
||||
BUILTIN (ECMA_BUILTIN_ID_INT16ARRAY_PROTOTYPE,
|
||||
ECMA_OBJECT_TYPE_GENERAL,
|
||||
ECMA_BUILTIN_ID_TYPEDARRAY_PROTOTYPE,
|
||||
true,
|
||||
int16array_prototype)
|
||||
BUILTIN_ROUTINE (ECMA_BUILTIN_ID_UINT8CLAMPEDARRAY,
|
||||
ECMA_OBJECT_TYPE_FUNCTION,
|
||||
ECMA_BUILTIN_ID_TYPEDARRAY,
|
||||
true,
|
||||
uint8clampedarray)
|
||||
|
||||
BUILTIN_ROUTINE (ECMA_BUILTIN_ID_INT16ARRAY,
|
||||
ECMA_OBJECT_TYPE_FUNCTION,
|
||||
@@ -331,48 +320,24 @@ BUILTIN_ROUTINE (ECMA_BUILTIN_ID_INT16ARRAY,
|
||||
true,
|
||||
int16array)
|
||||
|
||||
BUILTIN (ECMA_BUILTIN_ID_UINT16ARRAY_PROTOTYPE,
|
||||
ECMA_OBJECT_TYPE_GENERAL,
|
||||
ECMA_BUILTIN_ID_TYPEDARRAY_PROTOTYPE,
|
||||
true,
|
||||
uint16array_prototype)
|
||||
|
||||
BUILTIN_ROUTINE (ECMA_BUILTIN_ID_UINT16ARRAY,
|
||||
ECMA_OBJECT_TYPE_FUNCTION,
|
||||
ECMA_BUILTIN_ID_TYPEDARRAY,
|
||||
true,
|
||||
uint16array)
|
||||
|
||||
BUILTIN (ECMA_BUILTIN_ID_INT32ARRAY_PROTOTYPE,
|
||||
ECMA_OBJECT_TYPE_GENERAL,
|
||||
ECMA_BUILTIN_ID_TYPEDARRAY_PROTOTYPE,
|
||||
true,
|
||||
int32array_prototype)
|
||||
|
||||
BUILTIN_ROUTINE (ECMA_BUILTIN_ID_INT32ARRAY,
|
||||
ECMA_OBJECT_TYPE_FUNCTION,
|
||||
ECMA_BUILTIN_ID_TYPEDARRAY,
|
||||
true,
|
||||
int32array)
|
||||
|
||||
BUILTIN (ECMA_BUILTIN_ID_UINT32ARRAY_PROTOTYPE,
|
||||
ECMA_OBJECT_TYPE_GENERAL,
|
||||
ECMA_BUILTIN_ID_TYPEDARRAY_PROTOTYPE,
|
||||
true,
|
||||
uint32array_prototype)
|
||||
|
||||
BUILTIN_ROUTINE (ECMA_BUILTIN_ID_UINT32ARRAY,
|
||||
ECMA_OBJECT_TYPE_FUNCTION,
|
||||
ECMA_BUILTIN_ID_TYPEDARRAY,
|
||||
true,
|
||||
uint32array)
|
||||
|
||||
BUILTIN (ECMA_BUILTIN_ID_FLOAT32ARRAY_PROTOTYPE,
|
||||
ECMA_OBJECT_TYPE_GENERAL,
|
||||
ECMA_BUILTIN_ID_TYPEDARRAY_PROTOTYPE,
|
||||
true,
|
||||
float32array_prototype)
|
||||
|
||||
BUILTIN_ROUTINE (ECMA_BUILTIN_ID_FLOAT32ARRAY,
|
||||
ECMA_OBJECT_TYPE_FUNCTION,
|
||||
ECMA_BUILTIN_ID_TYPEDARRAY,
|
||||
@@ -380,12 +345,6 @@ BUILTIN_ROUTINE (ECMA_BUILTIN_ID_FLOAT32ARRAY,
|
||||
float32array)
|
||||
|
||||
#if ENABLED (JERRY_NUMBER_TYPE_FLOAT64)
|
||||
BUILTIN (ECMA_BUILTIN_ID_FLOAT64ARRAY_PROTOTYPE,
|
||||
ECMA_OBJECT_TYPE_GENERAL,
|
||||
ECMA_BUILTIN_ID_TYPEDARRAY_PROTOTYPE,
|
||||
true,
|
||||
float64array_prototype)
|
||||
|
||||
BUILTIN_ROUTINE (ECMA_BUILTIN_ID_FLOAT64ARRAY,
|
||||
ECMA_OBJECT_TYPE_FUNCTION,
|
||||
ECMA_BUILTIN_ID_TYPEDARRAY,
|
||||
@@ -393,18 +352,62 @@ BUILTIN_ROUTINE (ECMA_BUILTIN_ID_FLOAT64ARRAY,
|
||||
float64array)
|
||||
#endif /* ENABLED (JERRY_NUMBER_TYPE_FLOAT64) */
|
||||
|
||||
|
||||
BUILTIN (ECMA_BUILTIN_ID_INT8ARRAY_PROTOTYPE,
|
||||
ECMA_OBJECT_TYPE_GENERAL,
|
||||
ECMA_BUILTIN_ID_TYPEDARRAY_PROTOTYPE,
|
||||
true,
|
||||
int8array_prototype)
|
||||
|
||||
BUILTIN (ECMA_BUILTIN_ID_UINT8ARRAY_PROTOTYPE,
|
||||
ECMA_OBJECT_TYPE_GENERAL,
|
||||
ECMA_BUILTIN_ID_TYPEDARRAY_PROTOTYPE,
|
||||
true,
|
||||
uint8array_prototype)
|
||||
|
||||
BUILTIN (ECMA_BUILTIN_ID_UINT8CLAMPEDARRAY_PROTOTYPE,
|
||||
ECMA_OBJECT_TYPE_GENERAL,
|
||||
ECMA_BUILTIN_ID_TYPEDARRAY_PROTOTYPE,
|
||||
true,
|
||||
uint8clampedarray_prototype)
|
||||
|
||||
BUILTIN_ROUTINE (ECMA_BUILTIN_ID_UINT8CLAMPEDARRAY,
|
||||
ECMA_OBJECT_TYPE_FUNCTION,
|
||||
ECMA_BUILTIN_ID_TYPEDARRAY,
|
||||
true,
|
||||
uint8clampedarray)
|
||||
BUILTIN (ECMA_BUILTIN_ID_INT16ARRAY_PROTOTYPE,
|
||||
ECMA_OBJECT_TYPE_GENERAL,
|
||||
ECMA_BUILTIN_ID_TYPEDARRAY_PROTOTYPE,
|
||||
true,
|
||||
int16array_prototype)
|
||||
|
||||
BUILTIN (ECMA_BUILTIN_ID_UINT16ARRAY_PROTOTYPE,
|
||||
ECMA_OBJECT_TYPE_GENERAL,
|
||||
ECMA_BUILTIN_ID_TYPEDARRAY_PROTOTYPE,
|
||||
true,
|
||||
uint16array_prototype)
|
||||
|
||||
BUILTIN (ECMA_BUILTIN_ID_INT32ARRAY_PROTOTYPE,
|
||||
ECMA_OBJECT_TYPE_GENERAL,
|
||||
ECMA_BUILTIN_ID_TYPEDARRAY_PROTOTYPE,
|
||||
true,
|
||||
int32array_prototype)
|
||||
|
||||
BUILTIN (ECMA_BUILTIN_ID_UINT32ARRAY_PROTOTYPE,
|
||||
ECMA_OBJECT_TYPE_GENERAL,
|
||||
ECMA_BUILTIN_ID_TYPEDARRAY_PROTOTYPE,
|
||||
true,
|
||||
uint32array_prototype)
|
||||
|
||||
BUILTIN (ECMA_BUILTIN_ID_FLOAT32ARRAY_PROTOTYPE,
|
||||
ECMA_OBJECT_TYPE_GENERAL,
|
||||
ECMA_BUILTIN_ID_TYPEDARRAY_PROTOTYPE,
|
||||
true,
|
||||
float32array_prototype)
|
||||
|
||||
#if ENABLED (JERRY_NUMBER_TYPE_FLOAT64)
|
||||
BUILTIN (ECMA_BUILTIN_ID_FLOAT64ARRAY_PROTOTYPE,
|
||||
ECMA_OBJECT_TYPE_GENERAL,
|
||||
ECMA_BUILTIN_ID_TYPEDARRAY_PROTOTYPE,
|
||||
true,
|
||||
float64array_prototype)
|
||||
#endif /* ENABLED (JERRY_NUMBER_TYPE_FLOAT64) */
|
||||
#endif /* ENABLED (JERRY_ES2015_BUILTIN_TYPEDARRAY) */
|
||||
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_PROMISE)
|
||||
|
||||
@@ -66,7 +66,7 @@ ecma_builtin_float32array_dispatch_construct (const ecma_value_t *arguments_list
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
return ecma_typedarray_helper_dispatch_construct (arguments_list_p, arguments_list_len,
|
||||
ECMA_BUILTIN_ID_FLOAT32ARRAY);
|
||||
ECMA_FLOAT32_ARRAY);
|
||||
} /* ecma_builtin_float32array_dispatch_construct */
|
||||
|
||||
/**
|
||||
|
||||
@@ -67,7 +67,7 @@ ecma_builtin_float64array_dispatch_construct (const ecma_value_t *arguments_list
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
return ecma_typedarray_helper_dispatch_construct (arguments_list_p, arguments_list_len,
|
||||
ECMA_BUILTIN_ID_FLOAT64ARRAY);
|
||||
ECMA_FLOAT64_ARRAY);
|
||||
} /* ecma_builtin_float64array_dispatch_construct */
|
||||
|
||||
/**
|
||||
|
||||
@@ -66,7 +66,7 @@ ecma_builtin_int16array_dispatch_construct (const ecma_value_t *arguments_list_p
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
return ecma_typedarray_helper_dispatch_construct (arguments_list_p, arguments_list_len,
|
||||
ECMA_BUILTIN_ID_INT16ARRAY);
|
||||
ECMA_INT16_ARRAY);
|
||||
} /* ecma_builtin_int16array_dispatch_construct */
|
||||
|
||||
/**
|
||||
|
||||
@@ -66,7 +66,7 @@ ecma_builtin_int32array_dispatch_construct (const ecma_value_t *arguments_list_p
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
return ecma_typedarray_helper_dispatch_construct (arguments_list_p, arguments_list_len,
|
||||
ECMA_BUILTIN_ID_INT32ARRAY);
|
||||
ECMA_INT32_ARRAY);
|
||||
} /* ecma_builtin_int32array_dispatch_construct */
|
||||
|
||||
/**
|
||||
|
||||
@@ -66,7 +66,7 @@ ecma_builtin_int8array_dispatch_construct (const ecma_value_t *arguments_list_p,
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
return ecma_typedarray_helper_dispatch_construct (arguments_list_p, arguments_list_len,
|
||||
ECMA_BUILTIN_ID_INT8ARRAY);
|
||||
ECMA_INT8_ARRAY);
|
||||
} /* ecma_builtin_int8array_dispatch_construct */
|
||||
|
||||
/**
|
||||
|
||||
@@ -25,182 +25,6 @@
|
||||
#define ECMA_BUILTINS_INTERNAL
|
||||
#include "ecma-builtins-internal.h"
|
||||
|
||||
/**
|
||||
* Returns true if the builtin is a TypedArray type.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
bool
|
||||
ecma_typedarray_helper_is_typedarray (uint8_t builtin_id) /**< the builtin id of a type **/
|
||||
{
|
||||
switch (builtin_id)
|
||||
{
|
||||
case ECMA_BUILTIN_ID_INT8ARRAY:
|
||||
case ECMA_BUILTIN_ID_UINT8ARRAY:
|
||||
case ECMA_BUILTIN_ID_UINT8CLAMPEDARRAY:
|
||||
case ECMA_BUILTIN_ID_INT16ARRAY:
|
||||
case ECMA_BUILTIN_ID_UINT16ARRAY:
|
||||
case ECMA_BUILTIN_ID_INT32ARRAY:
|
||||
case ECMA_BUILTIN_ID_UINT32ARRAY:
|
||||
case ECMA_BUILTIN_ID_FLOAT32ARRAY:
|
||||
#if ENABLED (JERRY_NUMBER_TYPE_FLOAT64)
|
||||
case ECMA_BUILTIN_ID_FLOAT64ARRAY:
|
||||
#endif /* ENABLED (JERRY_NUMBER_TYPE_FLOAT64) */
|
||||
{
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} /* ecma_typedarray_helper_is_typedarray */
|
||||
|
||||
/**
|
||||
* Get the element shift size of a TypedArray type.
|
||||
*
|
||||
* @return uint8_t
|
||||
*/
|
||||
uint8_t
|
||||
ecma_typedarray_helper_get_shift_size (uint8_t builtin_id) /**< the builtin id of the typedarray **/
|
||||
{
|
||||
switch (builtin_id)
|
||||
{
|
||||
case ECMA_BUILTIN_ID_INT8ARRAY:
|
||||
case ECMA_BUILTIN_ID_UINT8ARRAY:
|
||||
case ECMA_BUILTIN_ID_UINT8CLAMPEDARRAY:
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
case ECMA_BUILTIN_ID_INT16ARRAY:
|
||||
case ECMA_BUILTIN_ID_UINT16ARRAY:
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
case ECMA_BUILTIN_ID_INT32ARRAY:
|
||||
case ECMA_BUILTIN_ID_UINT32ARRAY:
|
||||
case ECMA_BUILTIN_ID_FLOAT32ARRAY:
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
#if ENABLED (JERRY_NUMBER_TYPE_FLOAT64)
|
||||
case ECMA_BUILTIN_ID_FLOAT64ARRAY:
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_NUMBER_TYPE_FLOAT64) */
|
||||
default:
|
||||
{
|
||||
JERRY_UNREACHABLE ();
|
||||
}
|
||||
}
|
||||
} /* ecma_typedarray_helper_get_shift_size */
|
||||
|
||||
/**
|
||||
* Get the built-in TypedArray type from a magic string.
|
||||
*
|
||||
* @return uint8_t
|
||||
*/
|
||||
uint8_t
|
||||
ecma_typedarray_helper_get_builtin_id (ecma_object_t *obj_p) /**< typedarray object **/
|
||||
{
|
||||
#define TYPEDARRAY_ID_CASE(magic_id, builtin_id) \
|
||||
case magic_id: \
|
||||
{ \
|
||||
return builtin_id; \
|
||||
}
|
||||
|
||||
switch (ecma_object_get_class_name (obj_p))
|
||||
{
|
||||
TYPEDARRAY_ID_CASE (LIT_MAGIC_STRING_INT8_ARRAY_UL, ECMA_BUILTIN_ID_INT8ARRAY)
|
||||
TYPEDARRAY_ID_CASE (LIT_MAGIC_STRING_UINT8_ARRAY_UL, ECMA_BUILTIN_ID_UINT8ARRAY)
|
||||
TYPEDARRAY_ID_CASE (LIT_MAGIC_STRING_UINT8_CLAMPED_ARRAY_UL, ECMA_BUILTIN_ID_UINT8CLAMPEDARRAY)
|
||||
TYPEDARRAY_ID_CASE (LIT_MAGIC_STRING_INT16_ARRAY_UL, ECMA_BUILTIN_ID_INT16ARRAY)
|
||||
TYPEDARRAY_ID_CASE (LIT_MAGIC_STRING_UINT16_ARRAY_UL, ECMA_BUILTIN_ID_UINT16ARRAY)
|
||||
TYPEDARRAY_ID_CASE (LIT_MAGIC_STRING_INT32_ARRAY_UL, ECMA_BUILTIN_ID_INT32ARRAY)
|
||||
TYPEDARRAY_ID_CASE (LIT_MAGIC_STRING_UINT32_ARRAY_UL, ECMA_BUILTIN_ID_UINT32ARRAY)
|
||||
TYPEDARRAY_ID_CASE (LIT_MAGIC_STRING_FLOAT32_ARRAY_UL, ECMA_BUILTIN_ID_FLOAT32ARRAY)
|
||||
#if ENABLED (JERRY_NUMBER_TYPE_FLOAT64)
|
||||
TYPEDARRAY_ID_CASE (LIT_MAGIC_STRING_FLOAT64_ARRAY_UL, ECMA_BUILTIN_ID_FLOAT64ARRAY)
|
||||
#endif /* ENABLED (JERRY_NUMBER_TYPE_FLOAT64) */
|
||||
default:
|
||||
{
|
||||
JERRY_UNREACHABLE ();
|
||||
}
|
||||
}
|
||||
#undef TYPEDARRAY_ID_CASE
|
||||
} /* ecma_typedarray_helper_get_builtin_id */
|
||||
|
||||
/**
|
||||
* Get the magic string of a TypedArray type.
|
||||
*
|
||||
* @return lit_magic_string_id_t
|
||||
*/
|
||||
lit_magic_string_id_t
|
||||
ecma_typedarray_helper_get_magic_string (uint8_t builtin_id) /**< the builtin id of the typedarray **/
|
||||
{
|
||||
#define TYPEDARRAY_ID_CASE(builtin_id, magic_id) \
|
||||
case builtin_id: \
|
||||
{ \
|
||||
return (lit_magic_string_id_t) magic_id; \
|
||||
}
|
||||
|
||||
switch (builtin_id)
|
||||
{
|
||||
TYPEDARRAY_ID_CASE (ECMA_BUILTIN_ID_INT8ARRAY, LIT_MAGIC_STRING_INT8_ARRAY_UL)
|
||||
TYPEDARRAY_ID_CASE (ECMA_BUILTIN_ID_UINT8ARRAY, LIT_MAGIC_STRING_UINT8_ARRAY_UL)
|
||||
TYPEDARRAY_ID_CASE (ECMA_BUILTIN_ID_UINT8CLAMPEDARRAY, LIT_MAGIC_STRING_UINT8_CLAMPED_ARRAY_UL)
|
||||
TYPEDARRAY_ID_CASE (ECMA_BUILTIN_ID_INT16ARRAY, LIT_MAGIC_STRING_INT16_ARRAY_UL)
|
||||
TYPEDARRAY_ID_CASE (ECMA_BUILTIN_ID_UINT16ARRAY, LIT_MAGIC_STRING_UINT16_ARRAY_UL)
|
||||
TYPEDARRAY_ID_CASE (ECMA_BUILTIN_ID_INT32ARRAY, LIT_MAGIC_STRING_INT32_ARRAY_UL)
|
||||
TYPEDARRAY_ID_CASE (ECMA_BUILTIN_ID_UINT32ARRAY, LIT_MAGIC_STRING_UINT32_ARRAY_UL)
|
||||
TYPEDARRAY_ID_CASE (ECMA_BUILTIN_ID_FLOAT32ARRAY, LIT_MAGIC_STRING_FLOAT32_ARRAY_UL)
|
||||
#if ENABLED (JERRY_NUMBER_TYPE_FLOAT64)
|
||||
TYPEDARRAY_ID_CASE (ECMA_BUILTIN_ID_FLOAT64ARRAY, LIT_MAGIC_STRING_FLOAT64_ARRAY_UL)
|
||||
#endif /* ENABLED (JERRY_NUMBER_TYPE_FLOAT64) */
|
||||
default:
|
||||
{
|
||||
JERRY_UNREACHABLE ();
|
||||
}
|
||||
}
|
||||
#undef TYPEDARRAY_ID_CASE
|
||||
} /* ecma_typedarray_helper_get_magic_string */
|
||||
|
||||
/**
|
||||
* Get the prototype ID of a TypedArray type.
|
||||
*
|
||||
* @return uint8_t
|
||||
*/
|
||||
uint8_t
|
||||
ecma_typedarray_helper_get_prototype_id (uint8_t builtin_id) /**< the builtin id of the typedarray **/
|
||||
{
|
||||
#define TYPEDARRAY_ID_CASE(builtin_id) \
|
||||
case builtin_id: \
|
||||
{ \
|
||||
return builtin_id ## _PROTOTYPE; \
|
||||
}
|
||||
|
||||
switch (builtin_id)
|
||||
{
|
||||
TYPEDARRAY_ID_CASE (ECMA_BUILTIN_ID_INT8ARRAY)
|
||||
TYPEDARRAY_ID_CASE (ECMA_BUILTIN_ID_UINT8ARRAY)
|
||||
TYPEDARRAY_ID_CASE (ECMA_BUILTIN_ID_UINT8CLAMPEDARRAY)
|
||||
TYPEDARRAY_ID_CASE (ECMA_BUILTIN_ID_INT16ARRAY)
|
||||
TYPEDARRAY_ID_CASE (ECMA_BUILTIN_ID_UINT16ARRAY)
|
||||
TYPEDARRAY_ID_CASE (ECMA_BUILTIN_ID_INT32ARRAY)
|
||||
TYPEDARRAY_ID_CASE (ECMA_BUILTIN_ID_UINT32ARRAY)
|
||||
TYPEDARRAY_ID_CASE (ECMA_BUILTIN_ID_FLOAT32ARRAY)
|
||||
#if ENABLED (JERRY_NUMBER_TYPE_FLOAT64)
|
||||
TYPEDARRAY_ID_CASE (ECMA_BUILTIN_ID_FLOAT64ARRAY)
|
||||
#endif /* ENABLED (JERRY_NUMBER_TYPE_FLOAT64) */
|
||||
default:
|
||||
{
|
||||
JERRY_UNREACHABLE ();
|
||||
}
|
||||
}
|
||||
#undef TYPEDARRAY_ID_CASE
|
||||
} /* ecma_typedarray_helper_get_prototype_id */
|
||||
|
||||
/**
|
||||
* Common implementation of the [[Construct]] call of TypedArrays.
|
||||
*
|
||||
@@ -210,17 +34,16 @@ ecma_typedarray_helper_get_prototype_id (uint8_t builtin_id) /**< the builtin id
|
||||
ecma_value_t
|
||||
ecma_typedarray_helper_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */
|
||||
ecma_length_t arguments_list_len, /**< number of arguments */
|
||||
uint8_t builtin_id) /**< the builtin id of the typedarray */
|
||||
ecma_typedarray_type_t typedarray_id) /**< id of the typedarray */
|
||||
{
|
||||
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
|
||||
JERRY_ASSERT (ecma_typedarray_helper_is_typedarray (builtin_id));
|
||||
|
||||
ecma_object_t *prototype_obj_p = ecma_builtin_get (ecma_typedarray_helper_get_prototype_id (builtin_id));
|
||||
ecma_object_t *prototype_obj_p = ecma_builtin_get (ecma_typedarray_helper_get_prototype_id (typedarray_id));
|
||||
ecma_value_t val = ecma_op_create_typedarray (arguments_list_p,
|
||||
arguments_list_len,
|
||||
prototype_obj_p,
|
||||
ecma_typedarray_helper_get_shift_size (builtin_id),
|
||||
ecma_typedarray_helper_get_magic_string (builtin_id));
|
||||
ecma_typedarray_helper_get_shift_size (typedarray_id),
|
||||
typedarray_id);
|
||||
|
||||
return val;
|
||||
} /* ecma_typedarray_helper_dispatch_construct */
|
||||
|
||||
@@ -26,16 +26,10 @@
|
||||
* @{
|
||||
*/
|
||||
|
||||
bool ecma_typedarray_helper_is_typedarray (uint8_t builtin_id);
|
||||
uint8_t ecma_typedarray_helper_get_shift_size (uint8_t builtin_id);
|
||||
uint8_t ecma_typedarray_helper_get_builtin_id (ecma_object_t *obj_p);
|
||||
lit_magic_string_id_t ecma_typedarray_helper_get_magic_string (uint8_t builtin_id);
|
||||
uint8_t ecma_typedarray_helper_get_prototype_id (uint8_t builtin_id);
|
||||
|
||||
ecma_value_t
|
||||
ecma_typedarray_helper_dispatch_construct (const ecma_value_t *arguments_list_p,
|
||||
ecma_length_t arguments_list_len,
|
||||
uint8_t builtin_id);
|
||||
ecma_typedarray_type_t typedarray_id);
|
||||
|
||||
/**
|
||||
* @}
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include "ecma-try-catch-macro.h"
|
||||
#include "jrt.h"
|
||||
#include "jrt-libc-includes.h"
|
||||
#include "jcontext.h"
|
||||
#include "ecma-gc.h"
|
||||
#include "jmem.h"
|
||||
#include "ecma-iterator-object.h"
|
||||
@@ -202,14 +203,20 @@ ecma_builtin_typedarray_prototype_exec_routine (ecma_value_t this_arg, /**< this
|
||||
}
|
||||
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (this_arg);
|
||||
uint32_t len = ecma_typedarray_get_length (obj_p);
|
||||
ecma_typedarray_info_t info = ecma_typedarray_get_info (obj_p);
|
||||
|
||||
ecma_typedarray_getter_fn_t typedarray_getter_cb = ecma_get_typedarray_getter_fn (info.typedarray_id);
|
||||
|
||||
ecma_object_t *func_object_p = ecma_get_object_from_value (cb_func_val);
|
||||
lit_utf8_byte_t *target_p = ecma_arraybuffer_get_buffer (info.typedarray_buffer_p) + info.offset;
|
||||
ecma_length_t byte_pos = 0;
|
||||
ecma_value_t ret_value = ECMA_VALUE_EMPTY;
|
||||
|
||||
for (uint32_t index = 0; index < len && ecma_is_value_empty (ret_value); index++)
|
||||
for (uint32_t index = 0; index < info.typedarray_length && ecma_is_value_empty (ret_value); index++)
|
||||
{
|
||||
ecma_value_t current_index = ecma_make_uint32_value (index);
|
||||
ecma_value_t get_value = ecma_op_typedarray_get_index_prop (obj_p, index);
|
||||
ecma_value_t current_index = ecma_make_uint32_value (index);
|
||||
ecma_number_t element_num = typedarray_getter_cb (target_p + byte_pos);
|
||||
ecma_value_t get_value = ecma_make_number_value (element_num);
|
||||
|
||||
JERRY_ASSERT (ecma_is_value_number (get_value));
|
||||
|
||||
@@ -230,6 +237,8 @@ ecma_builtin_typedarray_prototype_exec_routine (ecma_value_t this_arg, /**< this
|
||||
ret_value = ECMA_VALUE_TRUE;
|
||||
}
|
||||
|
||||
byte_pos += info.element_size;
|
||||
|
||||
ECMA_FINALIZE (call_value);
|
||||
|
||||
ecma_fast_free_value (current_index);
|
||||
@@ -424,51 +433,65 @@ ecma_builtin_typedarray_prototype_map (ecma_value_t this_arg, /**< this argument
|
||||
return ecma_raise_type_error (ECMA_ERR_MSG ("Callback function is not callable."));
|
||||
}
|
||||
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (this_arg);
|
||||
uint32_t len = ecma_typedarray_get_length (obj_p);
|
||||
ecma_object_t *func_object_p = ecma_get_object_from_value (cb_func_val);
|
||||
ecma_value_t ret_value = ECMA_VALUE_EMPTY;
|
||||
ecma_object_t *src_obj_p = ecma_get_object_from_value (this_arg);
|
||||
ecma_typedarray_info_t src_info = ecma_typedarray_get_info (src_obj_p);
|
||||
|
||||
ecma_value_t new_typedarray = ecma_op_create_typedarray_with_type_and_length (obj_p, len);
|
||||
ecma_object_t *func_object_p = ecma_get_object_from_value (cb_func_val);
|
||||
|
||||
ecma_value_t new_typedarray = ecma_op_create_typedarray_with_type_and_length (src_obj_p, src_info.typedarray_length);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (new_typedarray))
|
||||
{
|
||||
return new_typedarray;
|
||||
}
|
||||
|
||||
ecma_object_t *new_obj_p = ecma_get_object_from_value (new_typedarray);
|
||||
ecma_object_t *target_obj_p = ecma_get_object_from_value (new_typedarray);
|
||||
ecma_typedarray_info_t target_info = ecma_typedarray_get_info (target_obj_p);
|
||||
|
||||
for (uint32_t index = 0; index < len && ecma_is_value_empty (ret_value); index++)
|
||||
ecma_typedarray_getter_fn_t src_typedarray_getter_cb = ecma_get_typedarray_getter_fn (src_info.typedarray_id);
|
||||
ecma_typedarray_setter_fn_t target_typedarray_setter_cb = ecma_get_typedarray_setter_fn (target_info.typedarray_id);
|
||||
|
||||
lit_utf8_byte_t *src_buff_p = ecma_arraybuffer_get_buffer (src_info.typedarray_buffer_p) + src_info.offset;
|
||||
ecma_length_t src_byte_pos = 0;
|
||||
|
||||
for (uint32_t index = 0; index < src_info.typedarray_length; index++)
|
||||
{
|
||||
ecma_value_t current_index = ecma_make_uint32_value (index);
|
||||
ecma_value_t get_value = ecma_op_typedarray_get_index_prop (obj_p, index);
|
||||
ecma_value_t current_index = ecma_make_uint32_value (index);
|
||||
ecma_number_t element_num = src_typedarray_getter_cb (src_buff_p + src_byte_pos);
|
||||
ecma_value_t get_value = ecma_make_number_value (element_num);
|
||||
ecma_value_t call_args[] = { get_value, current_index, this_arg };
|
||||
|
||||
ECMA_TRY_CATCH (mapped_value, ecma_op_function_call (func_object_p, cb_this_arg, call_args, 3), ret_value);
|
||||
|
||||
bool set_status = ecma_op_typedarray_set_index_prop (new_obj_p, index, mapped_value);
|
||||
|
||||
if (!set_status)
|
||||
ecma_value_t mapped_value = ecma_op_function_call (func_object_p, cb_this_arg, call_args, 3);
|
||||
if (ECMA_IS_VALUE_ERROR (mapped_value))
|
||||
{
|
||||
ret_value = ecma_raise_type_error (ECMA_ERR_MSG ("error in typedarray set"));
|
||||
ecma_free_value (current_index);
|
||||
ecma_free_value (get_value);
|
||||
return mapped_value;
|
||||
}
|
||||
|
||||
ECMA_FINALIZE (mapped_value);
|
||||
ecma_number_t mapped_num;
|
||||
if (ECMA_IS_VALUE_ERROR (ecma_get_number (mapped_value, &mapped_num)))
|
||||
{
|
||||
ecma_free_value (mapped_value);
|
||||
ecma_free_value (current_index);
|
||||
ecma_free_value (get_value);
|
||||
return ECMA_VALUE_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_length_t target_byte_pos = (index << target_info.shift) + target_info.offset;
|
||||
lit_utf8_byte_t *target_buff_p = ecma_arraybuffer_get_buffer (target_info.typedarray_buffer_p) + target_byte_pos;
|
||||
target_typedarray_setter_cb (target_buff_p, mapped_num);
|
||||
}
|
||||
|
||||
src_byte_pos += src_info.element_size;
|
||||
|
||||
ecma_fast_free_value (mapped_value);
|
||||
ecma_fast_free_value (current_index);
|
||||
ecma_fast_free_value (get_value);
|
||||
}
|
||||
|
||||
if (ecma_is_value_empty (ret_value))
|
||||
{
|
||||
ret_value = new_typedarray;
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_free_value (new_typedarray);
|
||||
}
|
||||
|
||||
return ret_value;
|
||||
return new_typedarray;
|
||||
} /* ecma_builtin_typedarray_prototype_map */
|
||||
|
||||
/**
|
||||
@@ -495,9 +518,13 @@ ecma_builtin_typedarray_prototype_reduce_with_direction (ecma_value_t this_arg,
|
||||
}
|
||||
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (this_arg);
|
||||
uint32_t len = ecma_typedarray_get_length (obj_p);
|
||||
ecma_typedarray_info_t info = ecma_typedarray_get_info (obj_p);
|
||||
|
||||
if (len == 0)
|
||||
ecma_typedarray_getter_fn_t getter_cb = ecma_get_typedarray_getter_fn (info.typedarray_id);
|
||||
lit_utf8_byte_t *src_buffer = ecma_arraybuffer_get_buffer (info.typedarray_buffer_p) + info.offset;
|
||||
ecma_length_t byte_pos;
|
||||
|
||||
if (info.typedarray_length == 0)
|
||||
{
|
||||
if (ecma_is_value_undefined (initial_val))
|
||||
{
|
||||
@@ -507,14 +534,17 @@ ecma_builtin_typedarray_prototype_reduce_with_direction (ecma_value_t this_arg,
|
||||
return ecma_copy_value (initial_val);
|
||||
}
|
||||
|
||||
JERRY_ASSERT (len > 0);
|
||||
JERRY_ASSERT (info.typedarray_length > 0);
|
||||
|
||||
ecma_value_t accumulator = ECMA_VALUE_UNDEFINED;
|
||||
uint32_t index = is_right ? (len - 1) : 0;
|
||||
uint32_t index = is_right ? (info.typedarray_length - 1) : 0;
|
||||
|
||||
if (ecma_is_value_undefined (initial_val))
|
||||
{
|
||||
accumulator = ecma_op_typedarray_get_index_prop (obj_p, index);
|
||||
|
||||
byte_pos = (index << info.shift) + info.offset;
|
||||
ecma_number_t acc_num = getter_cb (src_buffer + byte_pos);
|
||||
accumulator = ecma_make_number_value (acc_num);
|
||||
|
||||
JERRY_ASSERT (ecma_is_value_number (accumulator));
|
||||
|
||||
@@ -531,7 +561,7 @@ ecma_builtin_typedarray_prototype_reduce_with_direction (ecma_value_t this_arg,
|
||||
{
|
||||
index++;
|
||||
|
||||
if (index == len)
|
||||
if (index == info.typedarray_length)
|
||||
{
|
||||
return accumulator;
|
||||
}
|
||||
@@ -547,7 +577,10 @@ ecma_builtin_typedarray_prototype_reduce_with_direction (ecma_value_t this_arg,
|
||||
while (true)
|
||||
{
|
||||
ecma_value_t current_index = ecma_make_uint32_value (index);
|
||||
ecma_value_t get_value = ecma_op_typedarray_get_index_prop (obj_p, index);
|
||||
byte_pos = (index << info.shift) + info.offset;
|
||||
ecma_number_t get_num = getter_cb (src_buffer + byte_pos);
|
||||
ecma_value_t get_value = ecma_make_number_value (get_num);
|
||||
|
||||
ecma_value_t call_args[] = { accumulator, get_value, current_index, this_arg };
|
||||
|
||||
JERRY_ASSERT (ecma_is_value_number (get_value));
|
||||
@@ -581,7 +614,7 @@ ecma_builtin_typedarray_prototype_reduce_with_direction (ecma_value_t this_arg,
|
||||
{
|
||||
index++;
|
||||
|
||||
if (index == len)
|
||||
if (index == info.typedarray_length)
|
||||
{
|
||||
break;
|
||||
}
|
||||
@@ -656,26 +689,29 @@ ecma_builtin_typedarray_prototype_filter (ecma_value_t this_arg, /**< this argum
|
||||
}
|
||||
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (this_arg);
|
||||
uint32_t len = ecma_typedarray_get_length (obj_p);
|
||||
lit_utf8_byte_t *buffer_p = ecma_typedarray_get_buffer (obj_p);
|
||||
uint8_t shift = ecma_typedarray_get_element_size_shift (obj_p);
|
||||
uint8_t element_size = (uint8_t) (1 << shift);
|
||||
ecma_typedarray_info_t info = ecma_typedarray_get_info (obj_p);
|
||||
|
||||
ecma_typedarray_getter_fn_t getter_cb = ecma_get_typedarray_getter_fn (info.typedarray_id);
|
||||
|
||||
ecma_object_t *func_object_p = ecma_get_object_from_value (cb_func_val);
|
||||
ecma_value_t ret_value = ECMA_VALUE_EMPTY;
|
||||
|
||||
if (len == 0)
|
||||
if (info.typedarray_length == 0)
|
||||
{
|
||||
return ecma_op_create_typedarray_with_type_and_length (obj_p, 0);
|
||||
}
|
||||
|
||||
JMEM_DEFINE_LOCAL_ARRAY (pass_value_list_p, len * element_size, lit_utf8_byte_t);
|
||||
JMEM_DEFINE_LOCAL_ARRAY (pass_value_list_p, info.typedarray_length * info.element_size, lit_utf8_byte_t);
|
||||
|
||||
lit_utf8_byte_t *pass_value_p = pass_value_list_p;
|
||||
lit_utf8_byte_t *src_buffer = ecma_arraybuffer_get_buffer (info.typedarray_buffer_p) + info.offset;
|
||||
ecma_length_t byte_pos = 0;
|
||||
|
||||
for (uint32_t index = 0; index < len && ecma_is_value_empty (ret_value); index++)
|
||||
for (uint32_t index = 0; index < info.typedarray_length && ecma_is_value_empty (ret_value); index++)
|
||||
{
|
||||
ecma_value_t current_index = ecma_make_uint32_value (index);
|
||||
ecma_value_t get_value = ecma_op_typedarray_get_index_prop (obj_p, index);
|
||||
ecma_number_t get_num = getter_cb (src_buffer + byte_pos);
|
||||
ecma_value_t get_value = ecma_make_number_value (get_num);
|
||||
|
||||
JERRY_ASSERT (ecma_is_value_number (get_value));
|
||||
|
||||
@@ -685,11 +721,12 @@ ecma_builtin_typedarray_prototype_filter (ecma_value_t this_arg, /**< this argum
|
||||
|
||||
if (ecma_op_to_boolean (call_value))
|
||||
{
|
||||
memcpy (pass_value_p, buffer_p, element_size);
|
||||
pass_value_p += element_size;
|
||||
memcpy (pass_value_p, info.buffer_p, info.element_size);
|
||||
pass_value_p += info.element_size;
|
||||
}
|
||||
|
||||
buffer_p += element_size;
|
||||
info.buffer_p += info.element_size;
|
||||
byte_pos += info.element_size;
|
||||
|
||||
ECMA_FINALIZE (call_value);
|
||||
|
||||
@@ -699,7 +736,7 @@ ecma_builtin_typedarray_prototype_filter (ecma_value_t this_arg, /**< this argum
|
||||
|
||||
if (ecma_is_value_empty (ret_value))
|
||||
{
|
||||
uint32_t pass_num = (uint32_t) ((pass_value_p - pass_value_list_p) >> shift);
|
||||
uint32_t pass_num = (uint32_t) ((pass_value_p - pass_value_list_p) >> info.shift);
|
||||
|
||||
ret_value = ecma_op_create_typedarray_with_type_and_length (obj_p, pass_num);
|
||||
|
||||
@@ -738,23 +775,21 @@ ecma_builtin_typedarray_prototype_reverse (ecma_value_t this_arg) /**< this argu
|
||||
}
|
||||
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (this_arg);
|
||||
uint32_t len = ecma_typedarray_get_length (obj_p);
|
||||
lit_utf8_byte_t *buffer_p = ecma_typedarray_get_buffer (obj_p);
|
||||
uint8_t shift = ecma_typedarray_get_element_size_shift (obj_p);
|
||||
uint8_t element_size = (uint8_t) (1 << shift);
|
||||
uint32_t middle = (len / 2) << shift;
|
||||
uint32_t buffer_last = (len << shift) - element_size;
|
||||
ecma_typedarray_info_t info = ecma_typedarray_get_info (obj_p);
|
||||
|
||||
for (uint32_t lower = 0; lower < middle; lower += element_size)
|
||||
uint32_t middle = (info.typedarray_length / 2) << info.shift;
|
||||
uint32_t buffer_last = (info.typedarray_length << info.shift) - info.element_size;
|
||||
|
||||
for (uint32_t lower = 0; lower < middle; lower += info.element_size)
|
||||
{
|
||||
uint32_t upper = buffer_last - lower;
|
||||
lit_utf8_byte_t *lower_p = buffer_p + lower;
|
||||
lit_utf8_byte_t *upper_p = buffer_p + upper;
|
||||
lit_utf8_byte_t *lower_p = info.buffer_p + lower;
|
||||
lit_utf8_byte_t *upper_p = info.buffer_p + upper;
|
||||
|
||||
lit_utf8_byte_t tmp[8];
|
||||
memcpy (&tmp[0], lower_p, element_size);
|
||||
memcpy (lower_p, upper_p, element_size);
|
||||
memcpy (upper_p, &tmp[0], element_size);
|
||||
memcpy (&tmp[0], lower_p, info.element_size);
|
||||
memcpy (lower_p, upper_p, info.element_size);
|
||||
memcpy (upper_p, &tmp[0], info.element_size);
|
||||
}
|
||||
|
||||
return ecma_copy_value (this_arg);
|
||||
@@ -792,52 +827,17 @@ ecma_op_typedarray_set_with_typedarray (ecma_value_t this_arg, /**< this argumen
|
||||
}
|
||||
|
||||
ecma_object_t *target_typedarray_p = ecma_get_object_from_value (this_arg);
|
||||
ecma_typedarray_info_t target_info = ecma_typedarray_get_info (target_typedarray_p);
|
||||
|
||||
ecma_object_t *src_typedarray_p = ecma_get_object_from_value (arr_val);
|
||||
ecma_typedarray_info_t src_info = ecma_typedarray_get_info (src_typedarray_p);
|
||||
|
||||
/* 9. targetBuffer */
|
||||
ecma_object_t *target_arraybuffer_p = ecma_typedarray_get_arraybuffer (target_typedarray_p);
|
||||
lit_utf8_byte_t *target_buffer_p = ecma_arraybuffer_get_buffer (target_arraybuffer_p);
|
||||
lit_utf8_byte_t *target_buffer_p = ecma_arraybuffer_get_buffer (target_info.typedarray_buffer_p);
|
||||
lit_utf8_byte_t *src_buffer_p = ecma_arraybuffer_get_buffer (src_info.typedarray_buffer_p);
|
||||
|
||||
/* 11. targetLength */
|
||||
ecma_length_t target_length = ecma_typedarray_get_length (target_typedarray_p);
|
||||
|
||||
/* 12. srcBuffer */
|
||||
ecma_object_t *src_arraybuffer_p = ecma_typedarray_get_arraybuffer (src_typedarray_p);
|
||||
lit_utf8_byte_t *src_buffer_p = ecma_arraybuffer_get_buffer (src_arraybuffer_p);
|
||||
|
||||
/* 15. targetType */
|
||||
lit_magic_string_id_t target_class_id = ecma_object_get_class_name (target_typedarray_p);
|
||||
|
||||
/* 16. targetElementSize */
|
||||
uint8_t target_shift = ecma_typedarray_get_element_size_shift (target_typedarray_p);
|
||||
uint8_t target_element_size = (uint8_t) (1 << target_shift);
|
||||
|
||||
/* 17. targetByteOffset */
|
||||
ecma_length_t target_byte_offset = ecma_typedarray_get_offset (target_typedarray_p);
|
||||
|
||||
/* 19. srcType */
|
||||
lit_magic_string_id_t src_class_id = ecma_object_get_class_name (src_typedarray_p);
|
||||
|
||||
/* 20. srcElementSize */
|
||||
uint8_t src_shift = ecma_typedarray_get_element_size_shift (src_typedarray_p);
|
||||
uint8_t src_element_size = (uint8_t) (1 << src_shift);
|
||||
|
||||
/* 21. srcLength */
|
||||
ecma_length_t src_length = ecma_typedarray_get_length (src_typedarray_p);
|
||||
uint32_t src_length_uint32 = ecma_number_to_uint32 (src_length);
|
||||
|
||||
if ((ecma_number_t) src_length_uint32 != src_length)
|
||||
{
|
||||
return ecma_raise_range_error (ECMA_ERR_MSG ("Invalid source length"));
|
||||
}
|
||||
|
||||
/* 22. srcByteOffset */
|
||||
ecma_length_t src_byte_offset = ecma_typedarray_get_offset (src_typedarray_p);
|
||||
|
||||
/* 23. */
|
||||
uint32_t target_offset_uint32 = ecma_number_to_uint32 (target_offset_num);
|
||||
|
||||
if ((int64_t) src_length_uint32 + target_offset_uint32 > target_length)
|
||||
if ((int64_t) src_info.typedarray_length + target_offset_uint32 > target_info.typedarray_length)
|
||||
{
|
||||
return ecma_raise_range_error (ECMA_ERR_MSG ("Invalid range of index"));
|
||||
}
|
||||
@@ -849,24 +849,28 @@ ecma_op_typedarray_set_with_typedarray (ecma_value_t this_arg, /**< this argumen
|
||||
}
|
||||
|
||||
/* 26. targetByteIndex */
|
||||
uint32_t target_byte_index = target_offset_uint32 * target_element_size + target_byte_offset;
|
||||
uint32_t target_byte_index = target_offset_uint32 * target_info.element_size + target_info.offset;
|
||||
|
||||
/* 27. limit */
|
||||
uint32_t limit = target_byte_index + target_element_size * src_length_uint32;
|
||||
uint32_t limit = target_byte_index + target_info.element_size * src_info.typedarray_length;
|
||||
|
||||
if (src_class_id == target_class_id)
|
||||
if (src_info.typedarray_id == target_info.typedarray_id)
|
||||
{
|
||||
memmove (target_buffer_p + target_byte_index, src_buffer_p + src_byte_offset,
|
||||
target_element_size * src_length_uint32);
|
||||
memmove (target_buffer_p + target_byte_index, src_buffer_p + src_info.offset,
|
||||
target_info.element_size * src_info.typedarray_length);
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_typedarray_getter_fn_t src_typedarray_getter_cb = ecma_get_typedarray_getter_fn (src_info.typedarray_id);
|
||||
ecma_typedarray_setter_fn_t target_typedarray_setter_cb = ecma_get_typedarray_setter_fn (target_info.typedarray_id);
|
||||
|
||||
while (target_byte_index < limit)
|
||||
{
|
||||
ecma_number_t elem_num = ecma_get_typedarray_element (src_buffer_p + src_byte_offset, src_class_id);
|
||||
ecma_set_typedarray_element (target_buffer_p + target_byte_index, elem_num, target_class_id);
|
||||
src_byte_offset += src_element_size;
|
||||
target_byte_index += target_element_size;
|
||||
ecma_length_t src_byte_offset = src_info.offset;
|
||||
ecma_number_t elem_num = src_typedarray_getter_cb (src_buffer_p + src_byte_offset);
|
||||
target_typedarray_setter_cb (target_buffer_p + target_byte_index, elem_num);
|
||||
src_byte_offset += src_info.element_size;
|
||||
target_byte_index += target_info.element_size;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -913,19 +917,9 @@ ecma_builtin_typedarray_prototype_set (ecma_value_t this_arg, /**< this argument
|
||||
}
|
||||
uint32_t target_offset_uint32 = ecma_number_to_uint32 (target_offset_num);
|
||||
|
||||
/* 11. targetLength */
|
||||
/* 11. ~ 15. */
|
||||
ecma_object_t *typedarray_p = ecma_get_object_from_value (this_arg);
|
||||
ecma_length_t target_length = ecma_typedarray_get_length (typedarray_p);
|
||||
|
||||
/* 13. targetElementSize */
|
||||
uint8_t shift = ecma_typedarray_get_element_size_shift (typedarray_p);
|
||||
uint8_t element_size = (uint8_t) (1 << shift);
|
||||
|
||||
/* 14. targetType */
|
||||
lit_magic_string_id_t target_class_id = ecma_object_get_class_name (typedarray_p);
|
||||
|
||||
/* 9., 15. */
|
||||
lit_utf8_byte_t *target_buffer_p = ecma_typedarray_get_buffer (typedarray_p);
|
||||
ecma_typedarray_info_t target_info = ecma_typedarray_get_info (typedarray_p);
|
||||
|
||||
/* 16.~ 17. */
|
||||
ECMA_TRY_CATCH (source_obj, ecma_op_to_object (arr_val), ret_val);
|
||||
@@ -952,15 +946,17 @@ ecma_builtin_typedarray_prototype_set (ecma_value_t this_arg, /**< this argument
|
||||
}
|
||||
|
||||
/* 20. if srcLength + targetOffset > targetLength, throw a RangeError */
|
||||
if ((int64_t) source_length_uint32 + target_offset_uint32 > target_length)
|
||||
if ((int64_t) source_length_uint32 + target_offset_uint32 > target_info.typedarray_length)
|
||||
{
|
||||
ret_val = ecma_raise_range_error (ECMA_ERR_MSG ("Invalid range of index"));
|
||||
}
|
||||
|
||||
/* 21.~ 25. */
|
||||
uint32_t target_byte_index = target_offset_uint32 * element_size;
|
||||
uint32_t target_byte_index = target_offset_uint32 * target_info.element_size;
|
||||
uint32_t k = 0;
|
||||
|
||||
ecma_typedarray_setter_fn_t target_typedarray_setter_cb = ecma_get_typedarray_setter_fn (target_info.typedarray_id);
|
||||
|
||||
while (k < source_length_uint32 && ecma_is_value_empty (ret_val))
|
||||
{
|
||||
ecma_string_t *k_str_p = ecma_new_ecma_string_from_uint32 (k);
|
||||
@@ -971,7 +967,7 @@ ecma_builtin_typedarray_prototype_set (ecma_value_t this_arg, /**< this argument
|
||||
|
||||
ECMA_OP_TO_NUMBER_TRY_CATCH (elem_num, elem, ret_val);
|
||||
|
||||
ecma_set_typedarray_element (target_buffer_p + target_byte_index, elem_num, target_class_id);
|
||||
target_typedarray_setter_cb (target_info.buffer_p + target_byte_index, elem_num);
|
||||
|
||||
ECMA_OP_TO_NUMBER_FINALIZE (elem_num);
|
||||
ECMA_FINALIZE (elem);
|
||||
@@ -979,7 +975,7 @@ ecma_builtin_typedarray_prototype_set (ecma_value_t this_arg, /**< this argument
|
||||
ecma_deref_ecma_string (k_str_p);
|
||||
|
||||
k++;
|
||||
target_byte_index += element_size;
|
||||
target_byte_index += target_info.element_size;
|
||||
}
|
||||
|
||||
ECMA_OP_TO_NUMBER_FINALIZE (source_length_num);
|
||||
@@ -1239,30 +1235,26 @@ ecma_builtin_typedarray_prototype_subarray (ecma_value_t this_arg, /**< this arg
|
||||
}
|
||||
|
||||
ecma_object_t *src_typedarray_p = ecma_get_object_from_value (this_arg);
|
||||
|
||||
/* 5. buffer */
|
||||
ecma_object_t *src_typedarray_arraybuffer_p = ecma_typedarray_get_arraybuffer (src_typedarray_p);
|
||||
|
||||
/* 6. srcLength */
|
||||
ecma_length_t src_length = ecma_typedarray_get_length (src_typedarray_p);
|
||||
ecma_typedarray_info_t info = ecma_typedarray_get_info (src_typedarray_p);
|
||||
|
||||
/* 9. beginIndex, 12. endIndex */
|
||||
uint32_t begin_index_uint32 = 0, end_index_uint32 = 0;
|
||||
|
||||
/* 7. relativeBegin */
|
||||
ECMA_OP_TO_NUMBER_TRY_CATCH (relative_begin, begin, ret_value);
|
||||
begin_index_uint32 = ecma_builtin_helper_array_index_normalize (relative_begin, src_length, false);
|
||||
|
||||
begin_index_uint32 = ecma_builtin_helper_array_index_normalize (relative_begin, info.typedarray_length, false);
|
||||
|
||||
if (ecma_is_value_undefined (end))
|
||||
{
|
||||
end_index_uint32 = (uint32_t) src_length;
|
||||
end_index_uint32 = (uint32_t) info.typedarray_length;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* 10. relativeEnd */
|
||||
ECMA_OP_TO_NUMBER_TRY_CATCH (relative_end, end, ret_value);
|
||||
|
||||
end_index_uint32 = ecma_builtin_helper_array_index_normalize (relative_end, src_length, false);
|
||||
end_index_uint32 = ecma_builtin_helper_array_index_normalize (relative_end, info.typedarray_length, false);
|
||||
|
||||
ECMA_OP_TO_NUMBER_FINALIZE (relative_end);
|
||||
}
|
||||
@@ -1282,25 +1274,17 @@ ecma_builtin_typedarray_prototype_subarray (ecma_value_t this_arg, /**< this arg
|
||||
subarray_length = end_index_uint32 - begin_index_uint32;
|
||||
}
|
||||
|
||||
/* 15. elementSize */
|
||||
uint8_t shift = ecma_typedarray_get_element_size_shift (src_typedarray_p);
|
||||
uint8_t element_size = (uint8_t) (1 << shift);
|
||||
|
||||
/* 16. srcByteOffset */
|
||||
ecma_length_t src_byte_offset = ecma_typedarray_get_offset (src_typedarray_p);
|
||||
|
||||
/* 17. beginByteOffset */
|
||||
ecma_length_t begin_byte_offset = src_byte_offset + begin_index_uint32 * element_size;
|
||||
ecma_length_t begin_byte_offset = info.offset + begin_index_uint32 * info.element_size;
|
||||
|
||||
uint8_t src_builtin_id = ecma_typedarray_helper_get_builtin_id (src_typedarray_p);
|
||||
ecma_value_t arguments_p[3] =
|
||||
{
|
||||
ecma_make_object_value (src_typedarray_arraybuffer_p),
|
||||
ecma_make_object_value (info.typedarray_buffer_p),
|
||||
ecma_make_uint32_value (begin_byte_offset),
|
||||
ecma_make_uint32_value (subarray_length)
|
||||
};
|
||||
|
||||
ret_value = ecma_typedarray_helper_dispatch_construct (arguments_p, 3, src_builtin_id);
|
||||
ret_value = ecma_typedarray_helper_dispatch_construct (arguments_p, 3, info.typedarray_id);
|
||||
|
||||
ecma_free_value (arguments_p[1]);
|
||||
ecma_free_value (arguments_p[2]);
|
||||
@@ -1336,24 +1320,25 @@ ecma_builtin_typedarray_prototype_fill (ecma_value_t this_arg, /**< this argumen
|
||||
}
|
||||
|
||||
ecma_object_t *typedarray_p = ecma_get_object_from_value (this_arg);
|
||||
ecma_object_t *typedarray_arraybuffer_p = ecma_typedarray_get_arraybuffer (typedarray_p);
|
||||
lit_utf8_byte_t *buffer_p = ecma_arraybuffer_get_buffer (typedarray_arraybuffer_p);
|
||||
ecma_length_t length = ecma_typedarray_get_length (typedarray_p);
|
||||
ecma_typedarray_info_t info = ecma_typedarray_get_info (typedarray_p);
|
||||
|
||||
lit_utf8_byte_t *buffer_p = ecma_arraybuffer_get_buffer (info.typedarray_buffer_p);
|
||||
|
||||
uint32_t begin_index_uint32 = 0, end_index_uint32 = 0;
|
||||
|
||||
ECMA_OP_TO_NUMBER_TRY_CATCH (relative_begin, begin, ret_value);
|
||||
begin_index_uint32 = ecma_builtin_helper_array_index_normalize (relative_begin, length, false);
|
||||
|
||||
begin_index_uint32 = ecma_builtin_helper_array_index_normalize (relative_begin, info.typedarray_length, false);
|
||||
|
||||
if (ecma_is_value_undefined (end))
|
||||
{
|
||||
end_index_uint32 = (uint32_t) length;
|
||||
end_index_uint32 = (uint32_t) info.typedarray_length;
|
||||
}
|
||||
else
|
||||
{
|
||||
ECMA_OP_TO_NUMBER_TRY_CATCH (relative_end, end, ret_value);
|
||||
|
||||
end_index_uint32 = ecma_builtin_helper_array_index_normalize (relative_end, length, false);
|
||||
end_index_uint32 = ecma_builtin_helper_array_index_normalize (relative_end, info.typedarray_length, false);
|
||||
|
||||
ECMA_OP_TO_NUMBER_FINALIZE (relative_end);
|
||||
}
|
||||
@@ -1372,18 +1357,14 @@ ecma_builtin_typedarray_prototype_fill (ecma_value_t this_arg, /**< this argumen
|
||||
subarray_length = end_index_uint32 - begin_index_uint32;
|
||||
}
|
||||
|
||||
uint8_t shift = ecma_typedarray_get_element_size_shift (typedarray_p);
|
||||
ecma_length_t byte_offset = ecma_typedarray_get_offset (typedarray_p);
|
||||
lit_magic_string_id_t class_id = ecma_object_get_class_name (typedarray_p);
|
||||
|
||||
uint8_t element_size = (uint8_t) (1 << shift);
|
||||
uint32_t byte_index = byte_offset + begin_index_uint32 * element_size;
|
||||
uint32_t limit = byte_index + subarray_length * element_size;
|
||||
ecma_typedarray_setter_fn_t typedarray_setter_cb = ecma_get_typedarray_setter_fn (info.typedarray_id);
|
||||
uint32_t byte_index = info.offset + begin_index_uint32 * info.element_size;
|
||||
uint32_t limit = byte_index + subarray_length * info.element_size;
|
||||
|
||||
while (byte_index < limit)
|
||||
{
|
||||
ecma_set_typedarray_element (buffer_p + byte_index, value_num, class_id);
|
||||
byte_index += element_size;
|
||||
typedarray_setter_cb (buffer_p + byte_index, value_num);
|
||||
byte_index += info.element_size;
|
||||
}
|
||||
|
||||
return ecma_copy_value (this_arg);
|
||||
@@ -1505,67 +1486,64 @@ ecma_builtin_typedarray_prototype_sort (ecma_value_t this_arg, /**< this argumen
|
||||
}
|
||||
|
||||
ecma_object_t *typedarray_p = ecma_get_object_from_value (this_arg);
|
||||
ecma_length_t typedarray_length = ecma_typedarray_get_length (typedarray_p);
|
||||
ecma_typedarray_info_t info = ecma_typedarray_get_info (typedarray_p);
|
||||
|
||||
if (!typedarray_length)
|
||||
if (!info.typedarray_length)
|
||||
{
|
||||
return ecma_copy_value (this_arg);
|
||||
}
|
||||
|
||||
ecma_value_t ret_value = ECMA_VALUE_EMPTY;
|
||||
|
||||
JMEM_DEFINE_LOCAL_ARRAY (values_buffer, typedarray_length, ecma_value_t);
|
||||
|
||||
lit_magic_string_id_t class_id = ecma_object_get_class_name (typedarray_p);
|
||||
lit_utf8_byte_t *typedarray_buffer_p = ecma_typedarray_get_buffer (typedarray_p);
|
||||
uint8_t shift = ecma_typedarray_get_element_size_shift (typedarray_p);
|
||||
uint8_t element_size = (uint8_t) (1 << shift);
|
||||
JMEM_DEFINE_LOCAL_ARRAY (values_buffer, info.typedarray_length, ecma_value_t);
|
||||
|
||||
uint32_t byte_index = 0, buffer_index = 0;
|
||||
uint32_t limit = typedarray_length * element_size;
|
||||
uint32_t limit = info.typedarray_length * info.element_size;
|
||||
|
||||
ecma_typedarray_getter_fn_t typedarray_getter_cb = ecma_get_typedarray_getter_fn (info.typedarray_id);
|
||||
/* Copy unsorted array into a native c array. */
|
||||
while (byte_index < limit)
|
||||
{
|
||||
JERRY_ASSERT (buffer_index < typedarray_length);
|
||||
ecma_number_t element_num = ecma_get_typedarray_element (typedarray_buffer_p + byte_index,
|
||||
class_id);
|
||||
JERRY_ASSERT (buffer_index < info.typedarray_length);
|
||||
ecma_number_t element_num = typedarray_getter_cb (info.buffer_p + byte_index);
|
||||
ecma_value_t element_value = ecma_make_number_value (element_num);
|
||||
values_buffer[buffer_index++] = element_value;
|
||||
byte_index += element_size;
|
||||
byte_index += info.element_size;
|
||||
}
|
||||
|
||||
JERRY_ASSERT (buffer_index == typedarray_length);
|
||||
JERRY_ASSERT (buffer_index == info.typedarray_length);
|
||||
|
||||
const ecma_builtin_helper_sort_compare_fn_t sort_cb = &ecma_builtin_typedarray_prototype_sort_compare_helper;
|
||||
ECMA_TRY_CATCH (sort_value,
|
||||
ecma_builtin_helper_array_heap_sort_helper (values_buffer,
|
||||
(uint32_t) (typedarray_length - 1),
|
||||
(uint32_t) (info.typedarray_length - 1),
|
||||
compare_func,
|
||||
sort_cb),
|
||||
ret_value);
|
||||
ECMA_FINALIZE (sort_value);
|
||||
|
||||
ecma_typedarray_setter_fn_t typedarray_setter_cb = ecma_get_typedarray_setter_fn (info.typedarray_id);
|
||||
|
||||
if (ecma_is_value_empty (ret_value))
|
||||
{
|
||||
byte_index = 0;
|
||||
buffer_index = 0;
|
||||
limit = typedarray_length * element_size;
|
||||
limit = info.typedarray_length * info.element_size;
|
||||
/* Put sorted values from the native array back into the typedarray buffer. */
|
||||
while (byte_index < limit)
|
||||
{
|
||||
JERRY_ASSERT (buffer_index < typedarray_length);
|
||||
JERRY_ASSERT (buffer_index < info.typedarray_length);
|
||||
ecma_value_t element_value = values_buffer[buffer_index++];
|
||||
ecma_number_t element_num = ecma_get_number_from_value (element_value);
|
||||
ecma_set_typedarray_element (typedarray_buffer_p + byte_index, element_num, class_id);
|
||||
byte_index += element_size;
|
||||
typedarray_setter_cb (info.buffer_p + byte_index, element_num);
|
||||
byte_index += info.element_size;
|
||||
}
|
||||
|
||||
JERRY_ASSERT (buffer_index == typedarray_length);
|
||||
JERRY_ASSERT (buffer_index == info.typedarray_length);
|
||||
}
|
||||
|
||||
/* Free values that were copied to the local array. */
|
||||
for (uint32_t index = 0; index < typedarray_length; index++)
|
||||
for (uint32_t index = 0; index < info.typedarray_length; index++)
|
||||
{
|
||||
ecma_free_value (values_buffer[index]);
|
||||
}
|
||||
@@ -1608,19 +1586,17 @@ ecma_builtin_typedarray_prototype_find_helper (ecma_value_t this_arg, /**< this
|
||||
ecma_object_t *func_object_p = ecma_get_object_from_value (predicate);
|
||||
|
||||
ecma_object_t *typedarray_p = ecma_get_object_from_value (this_arg);
|
||||
uint32_t typedarray_length = ecma_typedarray_get_length (typedarray_p);
|
||||
lit_magic_string_id_t class_id = ecma_object_get_class_name (typedarray_p);
|
||||
lit_utf8_byte_t *typedarray_buffer_p = ecma_typedarray_get_buffer (typedarray_p);
|
||||
uint8_t shift = ecma_typedarray_get_element_size_shift (typedarray_p);
|
||||
uint8_t element_size = (uint8_t) (1 << shift);
|
||||
ecma_typedarray_info_t info = ecma_typedarray_get_info (typedarray_p);
|
||||
|
||||
uint32_t buffer_index = 0;
|
||||
uint32_t limit = typedarray_length * element_size;
|
||||
uint32_t limit = info.typedarray_length * info.element_size;
|
||||
|
||||
for (uint32_t byte_index = 0; byte_index < limit; byte_index += element_size)
|
||||
ecma_typedarray_getter_fn_t typedarray_getter_cb = ecma_get_typedarray_getter_fn (info.typedarray_id);
|
||||
|
||||
for (uint32_t byte_index = 0; byte_index < limit; byte_index += info.element_size)
|
||||
{
|
||||
JERRY_ASSERT (buffer_index < typedarray_length);
|
||||
ecma_number_t element_num = ecma_get_typedarray_element (typedarray_buffer_p + byte_index, class_id);
|
||||
JERRY_ASSERT (buffer_index < info.typedarray_length);
|
||||
ecma_number_t element_num = typedarray_getter_cb (info.buffer_p + byte_index);
|
||||
ecma_value_t element_value = ecma_make_number_value (element_num);
|
||||
|
||||
ecma_value_t call_args[] = { element_value, ecma_make_uint32_value (buffer_index), this_arg };
|
||||
@@ -1711,23 +1687,19 @@ ecma_builtin_typedarray_prototype_index_helper (ecma_value_t this_arg, /**< this
|
||||
}
|
||||
|
||||
ecma_object_t *typedarray_p = ecma_get_object_from_value (this_arg);
|
||||
uint32_t length = ecma_typedarray_get_length (typedarray_p);
|
||||
lit_magic_string_id_t class_id = ecma_object_get_class_name (typedarray_p);
|
||||
lit_utf8_byte_t *typedarray_buffer_p = ecma_typedarray_get_buffer (typedarray_p);
|
||||
uint8_t shift = ecma_typedarray_get_element_size_shift (typedarray_p);
|
||||
uint8_t element_size = (uint8_t) (1 << shift);
|
||||
uint32_t limit = length * element_size;
|
||||
ecma_typedarray_info_t info = ecma_typedarray_get_info (typedarray_p);
|
||||
uint32_t limit = info.typedarray_length * info.element_size;
|
||||
uint32_t from_index;
|
||||
|
||||
if (args_number == 0
|
||||
|| length == 0
|
||||
|| !ecma_is_value_number (args[0]))
|
||||
|| !ecma_is_value_number (args[0])
|
||||
|| info.typedarray_length == 0)
|
||||
{
|
||||
return ecma_make_integer_value (-1);
|
||||
}
|
||||
if (args_number == 1)
|
||||
{
|
||||
from_index = is_last_index_of ? length - 1 : 0;
|
||||
from_index = is_last_index_of ? info.typedarray_length - 1 : 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1741,29 +1713,29 @@ ecma_builtin_typedarray_prototype_index_helper (ecma_value_t this_arg, /**< this
|
||||
if (!ecma_number_is_nan (num_var)
|
||||
&& is_last_index_of
|
||||
&& num_var < 0
|
||||
&& fabs (num_var) > length)
|
||||
&& fabs (num_var) > info.typedarray_length)
|
||||
{
|
||||
return ecma_make_integer_value (-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
from_index = ecma_builtin_helper_array_index_normalize (num_var, length, is_last_index_of);
|
||||
from_index = ecma_builtin_helper_array_index_normalize (num_var, info.typedarray_length, is_last_index_of);
|
||||
}
|
||||
}
|
||||
|
||||
ecma_number_t search_num = ecma_get_number_from_value (args[0]);
|
||||
|
||||
int32_t increment = is_last_index_of ? -element_size : element_size;
|
||||
int32_t increment = is_last_index_of ? -info.element_size : info.element_size;
|
||||
|
||||
for (int32_t position = (int32_t) from_index * element_size;
|
||||
for (int32_t position = (int32_t) from_index * info.element_size;
|
||||
(is_last_index_of ? position >= 0 : (uint32_t) position < limit);
|
||||
position += increment)
|
||||
{
|
||||
ecma_number_t element_num = ecma_get_typedarray_element (typedarray_buffer_p + position, class_id);
|
||||
ecma_number_t element_num = ecma_get_typedarray_element (info.buffer_p + position, info.typedarray_id);
|
||||
|
||||
if (search_num == element_num)
|
||||
{
|
||||
return ecma_make_number_value ((ecma_number_t) position / element_size);
|
||||
return ecma_make_number_value ((ecma_number_t) position / info.element_size);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1856,17 +1828,17 @@ ecma_builtin_typedarray_prototype_copy_within (ecma_value_t this_arg, /**< this
|
||||
}
|
||||
|
||||
ecma_object_t *typedarray_p = ecma_get_object_from_value (this_arg);
|
||||
lit_utf8_byte_t *typedarray_buffer_p = ecma_typedarray_get_buffer (typedarray_p);
|
||||
uint32_t length = ecma_typedarray_get_length (typedarray_p);
|
||||
uint8_t shift = ecma_typedarray_get_element_size_shift (typedarray_p);
|
||||
uint8_t element_size = (uint8_t) (1 << shift);
|
||||
ecma_typedarray_info_t info = ecma_typedarray_get_info (typedarray_p);
|
||||
uint32_t target = 0;
|
||||
uint32_t start = 0;
|
||||
uint32_t end = length;
|
||||
uint32_t end = info.typedarray_length;
|
||||
|
||||
if (args_number > 0)
|
||||
{
|
||||
ecma_value_t target_value = ecma_builtin_get_uint32_value_from_argument (args[0], length, &target, false);
|
||||
ecma_value_t target_value = ecma_builtin_get_uint32_value_from_argument (args[0],
|
||||
info.typedarray_length,
|
||||
&target,
|
||||
false);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (target_value))
|
||||
{
|
||||
@@ -1875,7 +1847,10 @@ ecma_builtin_typedarray_prototype_copy_within (ecma_value_t this_arg, /**< this
|
||||
|
||||
if (args_number > 1)
|
||||
{
|
||||
ecma_value_t start_value = ecma_builtin_get_uint32_value_from_argument (args[1], length, &start, false);
|
||||
ecma_value_t start_value = ecma_builtin_get_uint32_value_from_argument (args[1],
|
||||
info.typedarray_length,
|
||||
&start,
|
||||
false);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (start_value))
|
||||
{
|
||||
@@ -1884,7 +1859,10 @@ ecma_builtin_typedarray_prototype_copy_within (ecma_value_t this_arg, /**< this
|
||||
|
||||
if (args_number > 2)
|
||||
{
|
||||
ecma_value_t end_value = ecma_builtin_get_uint32_value_from_argument (args[2], length, &end, true);
|
||||
ecma_value_t end_value = ecma_builtin_get_uint32_value_from_argument (args[2],
|
||||
info.typedarray_length,
|
||||
&end,
|
||||
true);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (end_value))
|
||||
{
|
||||
@@ -1895,18 +1873,18 @@ ecma_builtin_typedarray_prototype_copy_within (ecma_value_t this_arg, /**< this
|
||||
}
|
||||
|
||||
int32_t distance = (int32_t) (end - start);
|
||||
int32_t offset = (int32_t) (length - target);
|
||||
int32_t offset = (int32_t) (info.typedarray_length - target);
|
||||
int32_t count = JERRY_MIN (distance, offset);
|
||||
|
||||
if (target >= length || end == 0 || start >= end)
|
||||
if (target >= info.typedarray_length || start >= end || end == 0)
|
||||
{
|
||||
return ecma_copy_value (this_arg);
|
||||
}
|
||||
else
|
||||
{
|
||||
memmove (typedarray_buffer_p + (target * element_size),
|
||||
typedarray_buffer_p + (start * element_size),
|
||||
(size_t) (count * element_size));
|
||||
memmove (info.buffer_p + (target * info.element_size),
|
||||
info.buffer_p + (start * info.element_size),
|
||||
(size_t) (count * info.element_size));
|
||||
}
|
||||
|
||||
return ecma_copy_value (this_arg);
|
||||
@@ -1932,13 +1910,16 @@ ecma_builtin_typedarray_prototype_slice (ecma_value_t this_arg, /**< this argume
|
||||
}
|
||||
|
||||
ecma_object_t *typedarray_p = ecma_get_object_from_value (this_arg);
|
||||
uint32_t length = ecma_typedarray_get_length (typedarray_p);
|
||||
ecma_typedarray_info_t info = ecma_typedarray_get_info (typedarray_p);
|
||||
uint32_t start = 0;
|
||||
uint32_t end = length;
|
||||
uint32_t end = info.typedarray_length;
|
||||
|
||||
if (args_number > 0)
|
||||
{
|
||||
ecma_value_t start_value = ecma_builtin_get_uint32_value_from_argument (args[0], length, &start, false);
|
||||
ecma_value_t start_value = ecma_builtin_get_uint32_value_from_argument (args[0],
|
||||
info.typedarray_length,
|
||||
&start,
|
||||
false);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (start_value))
|
||||
{
|
||||
@@ -1947,7 +1928,10 @@ ecma_builtin_typedarray_prototype_slice (ecma_value_t this_arg, /**< this argume
|
||||
|
||||
if (args_number > 1)
|
||||
{
|
||||
ecma_value_t end_value = ecma_builtin_get_uint32_value_from_argument (args[1], length, &end, true);
|
||||
ecma_value_t end_value = ecma_builtin_get_uint32_value_from_argument (args[1],
|
||||
info.typedarray_length,
|
||||
&end,
|
||||
true);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (end_value))
|
||||
{
|
||||
@@ -1968,17 +1952,13 @@ ecma_builtin_typedarray_prototype_slice (ecma_value_t this_arg, /**< this argume
|
||||
|
||||
if (count > 0)
|
||||
{
|
||||
lit_utf8_byte_t *typedarray_buffer_p = ecma_typedarray_get_buffer (typedarray_p);
|
||||
uint8_t shift = ecma_typedarray_get_element_size_shift (typedarray_p);
|
||||
uint8_t element_size = (uint8_t) (1 << shift);
|
||||
|
||||
ecma_object_t *new_typedarray_p = ecma_get_object_from_value (new_typedarray);
|
||||
lit_utf8_byte_t *new_typedarray_buffer_p = ecma_typedarray_get_buffer (new_typedarray_p);
|
||||
uint32_t src_byte_index = (start * element_size);
|
||||
uint32_t src_byte_index = (start * info.element_size);
|
||||
|
||||
memcpy (new_typedarray_buffer_p,
|
||||
typedarray_buffer_p + src_byte_index,
|
||||
count * element_size);
|
||||
info.buffer_p + src_byte_index,
|
||||
count * info.element_size);
|
||||
}
|
||||
|
||||
return new_typedarray;
|
||||
@@ -1997,7 +1977,7 @@ static ecma_value_t
|
||||
ecma_builtin_typedarray_prototype_to_locale_string_helper (ecma_object_t *this_obj, /**< TypedArray object */
|
||||
uint32_t index) /** array index */
|
||||
{
|
||||
lit_magic_string_id_t class_id = ecma_object_get_class_name (this_obj);
|
||||
ecma_typedarray_type_t class_id = ecma_get_typedarray_id (this_obj);
|
||||
lit_utf8_byte_t *typedarray_buffer_p = ecma_typedarray_get_buffer (this_obj);
|
||||
|
||||
ecma_value_t ret_value = ECMA_VALUE_EMPTY;
|
||||
@@ -2073,12 +2053,10 @@ ecma_builtin_typedarray_prototype_to_locale_string (ecma_value_t this_arg) /**<
|
||||
}
|
||||
|
||||
ecma_object_t *typedarray_p = ecma_get_object_from_value (this_arg);
|
||||
uint32_t length = ecma_typedarray_get_length (typedarray_p);
|
||||
uint8_t shift = ecma_typedarray_get_element_size_shift (typedarray_p);
|
||||
uint8_t element_size = (uint8_t) (1 << shift);
|
||||
uint32_t limit = length * element_size;
|
||||
ecma_typedarray_info_t info = ecma_typedarray_get_info (typedarray_p);
|
||||
uint32_t limit = info.typedarray_length * info.element_size;
|
||||
|
||||
if (length == 0)
|
||||
if (info.typedarray_length == 0)
|
||||
{
|
||||
return ecma_make_magic_string_value (LIT_MAGIC_STRING__EMPTY);
|
||||
}
|
||||
@@ -2092,7 +2070,7 @@ ecma_builtin_typedarray_prototype_to_locale_string (ecma_value_t this_arg) /**<
|
||||
|
||||
ecma_string_t *return_string_p = ecma_get_string_from_value (first_element);
|
||||
|
||||
for (uint32_t k = element_size; k < limit; k += element_size)
|
||||
for (uint32_t k = info.element_size; k < limit; k += info.element_size)
|
||||
{
|
||||
return_string_p = ecma_append_magic_string_to_string (return_string_p, LIT_MAGIC_STRING_COMMA_CHAR);
|
||||
ecma_value_t next_element = ecma_builtin_typedarray_prototype_to_locale_string_helper (typedarray_p, k);
|
||||
|
||||
@@ -99,17 +99,17 @@ ecma_builtin_typedarray_from (ecma_value_t this_arg, /**< 'this' argument */
|
||||
return ecma_raise_type_error (ECMA_ERR_MSG ("'this' is not a typedarray constructor"));
|
||||
}
|
||||
|
||||
ecma_object_t *proto_p = ecma_builtin_get (ecma_typedarray_helper_get_prototype_id (builtin_id));
|
||||
const uint8_t element_size_shift = ecma_typedarray_helper_get_shift_size (builtin_id);
|
||||
const lit_magic_string_id_t class_id = ecma_typedarray_helper_get_magic_string (builtin_id);
|
||||
ecma_typedarray_type_t typedarray_id = ecma_typedarray_helper_builtin_to_typedarray_id (builtin_id);
|
||||
|
||||
ecma_object_t *proto_p = ecma_builtin_get (ecma_typedarray_helper_get_prototype_id (typedarray_id));
|
||||
const uint8_t element_size_shift = ecma_typedarray_helper_get_shift_size (typedarray_id);
|
||||
|
||||
return ecma_op_typedarray_from (source,
|
||||
map_fn,
|
||||
this_in_fn,
|
||||
proto_p,
|
||||
element_size_shift,
|
||||
class_id);
|
||||
typedarray_id);
|
||||
|
||||
} /* ecma_builtin_typedarray_from */
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ ecma_builtin_uint16array_dispatch_construct (const ecma_value_t *arguments_list_
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
return ecma_typedarray_helper_dispatch_construct (arguments_list_p, arguments_list_len,
|
||||
ECMA_BUILTIN_ID_UINT16ARRAY);
|
||||
ECMA_UINT16_ARRAY);
|
||||
} /* ecma_builtin_uint16array_dispatch_construct */
|
||||
|
||||
/**
|
||||
|
||||
@@ -30,6 +30,8 @@
|
||||
#define BUILTIN_UNDERSCORED_ID uint32array
|
||||
#include "ecma-builtin-internal-routines-template.inc.h"
|
||||
|
||||
#include "ecma-builtin-typedarray-helpers.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
@@ -65,14 +67,8 @@ ecma_builtin_uint32array_dispatch_construct (const ecma_value_t *arguments_list_
|
||||
{
|
||||
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
|
||||
|
||||
ecma_object_t *prototype_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_UINT32ARRAY_PROTOTYPE);
|
||||
ecma_value_t val = ecma_op_create_typedarray (arguments_list_p,
|
||||
arguments_list_len,
|
||||
prototype_obj_p,
|
||||
2,
|
||||
LIT_MAGIC_STRING_UINT32_ARRAY_UL);
|
||||
|
||||
return val;
|
||||
return ecma_typedarray_helper_dispatch_construct (arguments_list_p, arguments_list_len,
|
||||
ECMA_UINT32_ARRAY);
|
||||
} /* ecma_builtin_uint32array_dispatch_construct */
|
||||
|
||||
/**
|
||||
|
||||
@@ -66,7 +66,7 @@ ecma_builtin_uint8array_dispatch_construct (const ecma_value_t *arguments_list_p
|
||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||
{
|
||||
return ecma_typedarray_helper_dispatch_construct (arguments_list_p, arguments_list_len,
|
||||
ECMA_BUILTIN_ID_UINT8ARRAY);
|
||||
ECMA_UINT8_ARRAY);
|
||||
} /* ecma_builtin_uint8array_dispatch_construct */
|
||||
|
||||
/**
|
||||
|
||||
@@ -30,6 +30,8 @@
|
||||
#define BUILTIN_UNDERSCORED_ID uint8clampedarray
|
||||
#include "ecma-builtin-internal-routines-template.inc.h"
|
||||
|
||||
#include "ecma-builtin-typedarray-helpers.h"
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
@@ -65,15 +67,8 @@ ecma_builtin_uint8clampedarray_dispatch_construct (const ecma_value_t *arguments
|
||||
{
|
||||
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
|
||||
|
||||
ecma_object_t *prototype_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_UINT8CLAMPEDARRAY_PROTOTYPE);
|
||||
ecma_value_t val = ecma_op_create_typedarray (arguments_list_p,
|
||||
arguments_list_len,
|
||||
prototype_obj_p,
|
||||
0,
|
||||
LIT_MAGIC_STRING_UINT8_CLAMPED_ARRAY_UL);
|
||||
|
||||
|
||||
return val;
|
||||
return ecma_typedarray_helper_dispatch_construct (arguments_list_p, arguments_list_len,
|
||||
ECMA_UINT8_CLAMPED_ARRAY);
|
||||
} /* ecma_builtin_uint8clampedarray_dispatch_construct */
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user