[ES2015 profile]add TypedArray intrinsic object (#1507)
* add %TypedArray% intrinsic object * implement Int8Array * will implement other types and prototype functions in the following patches. JerryScript-DCO-1.0-Signed-off-by: Zidong Jiang zidong.jiang@intel.com
This commit is contained in:
committed by
László Langó
parent
177c30de78
commit
adfe61b4ed
@@ -81,8 +81,7 @@ ecma_op_create_arraybuffer_object (const ecma_value_t *arguments_list_p, /**< li
|
||||
* extend_part
|
||||
* data buffer
|
||||
*
|
||||
* @return ecma value
|
||||
* Returned value must be freed with ecma_free_value
|
||||
* @return ecma_object_t *
|
||||
*/
|
||||
ecma_object_t *
|
||||
ecma_arraybuffer_new_object (ecma_length_t length) /**< length of the arraybuffer */
|
||||
@@ -95,9 +94,60 @@ ecma_arraybuffer_new_object (ecma_length_t length) /**< length of the arraybuffe
|
||||
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p;
|
||||
ext_object_p->u.class_prop.class_id = LIT_MAGIC_STRING_ARRAY_BUFFER_UL;
|
||||
ext_object_p->u.class_prop.u.length = length;
|
||||
|
||||
lit_utf8_byte_t *buf = (lit_utf8_byte_t *) (ext_object_p + 1);
|
||||
memset (buf, 0, length);
|
||||
|
||||
return object_p;
|
||||
} /* ecma_arraybuffer_new_object */
|
||||
|
||||
/**
|
||||
* Helper function: create arraybuffer object by cloning another arraybuffer
|
||||
*
|
||||
* See also: ES2015 24.1.1.4
|
||||
*
|
||||
* @return ecma_object_t *
|
||||
*/
|
||||
ecma_object_t *
|
||||
ecma_arraybuffer_new_object_by_clone_arraybuffer (ecma_object_t *src_p, /**< the src arraybuffer */
|
||||
ecma_length_t offset) /**< the offset */
|
||||
{
|
||||
ecma_length_t length = ecma_arraybuffer_get_length (src_p);
|
||||
|
||||
JERRY_ASSERT (offset <= length);
|
||||
|
||||
ecma_length_t clone_length = length - offset;
|
||||
ecma_object_t *dst_p = ecma_arraybuffer_new_object (clone_length);
|
||||
lit_utf8_byte_t *src_buf = ecma_arraybuffer_get_buffer (src_p);
|
||||
lit_utf8_byte_t *dst_buf = ecma_arraybuffer_get_buffer (dst_p);
|
||||
memcpy (dst_buf, src_buf + offset, clone_length);
|
||||
|
||||
return dst_p;
|
||||
} /* ecma_arraybuffer_new_object_by_clone_arraybuffer */
|
||||
|
||||
/**
|
||||
* Helper function: check if the target is ArrayBuffer
|
||||
*
|
||||
*
|
||||
* See also: ES2015 24.1.1.4
|
||||
*
|
||||
* @return bool True if it is ArrayBuffer
|
||||
* Flase if it is not Object or it is not ArrayBuffer
|
||||
*/
|
||||
bool
|
||||
ecma_is_arraybuffer (ecma_value_t target) /**< the target value */
|
||||
{
|
||||
if (!ecma_is_value_object (target))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
ecma_object_t *obj_p = ecma_get_object_from_value (target);
|
||||
lit_magic_string_id_t class_id = ecma_object_get_class_name (obj_p);
|
||||
|
||||
return class_id == LIT_MAGIC_STRING_ARRAY_BUFFER_UL;
|
||||
} /* ecma_is_arraybuffer */
|
||||
|
||||
/**
|
||||
* Helper function: return the length of the buffer inside the arraybuffer object
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user