[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:
Zidong Jiang
2017-01-13 18:04:34 +08:00
committed by László Langó
parent 177c30de78
commit adfe61b4ed
43 changed files with 2327 additions and 119 deletions
+67 -15
View File
@@ -31,6 +31,10 @@
#include "vm-defines.h"
#include "vm-stack.h"
#ifndef CONFIG_DISABLE_ARRAYBUFFER_BUILTIN
#include "ecma-typedarray-object.h"
#endif
#define JERRY_INTERNAL
#include "jerry-internal.h"
@@ -259,14 +263,35 @@ ecma_gc_mark (ecma_object_t *object_p) /**< object to mark from */
switch (ecma_get_object_type (object_p))
{
case ECMA_OBJECT_TYPE_ARGUMENTS:
case ECMA_OBJECT_TYPE_PSEUDO_ARRAY:
{
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p;
ecma_object_t *lex_env_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_object_t,
ext_object_p->u.arguments.lex_env_cp);
switch (ext_object_p->u.pseudo_array.type)
{
case ECMA_PSEUDO_ARRAY_ARGUMENTS:
{
ecma_object_t *lex_env_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_object_t,
ext_object_p->u.pseudo_array.u2.lex_env_cp);
ecma_gc_set_object_visited (lex_env_p, true);
break;
}
#ifndef CONFIG_DISABLE_TYPEDARRAY_BUILTIN
case ECMA_PSEUDO_ARRAY_TYPEDARRAY:
case ECMA_PSEUDO_ARRAY_TYPEDARRAY_WITH_INFO:
{
ecma_gc_set_object_visited (ecma_typedarray_get_arraybuffer (object_p), true);
break;
}
#endif /* !CONFIG_DISABLE_TYPEDARRAY_BUILTIN */
default:
{
JERRY_UNREACHABLE ();
break;
}
}
ecma_gc_set_object_visited (lex_env_p, true);
break;
}
case ECMA_OBJECT_TYPE_BOUND_FUNCTION:
@@ -503,25 +528,52 @@ ecma_gc_sweep (ecma_object_t *object_p) /**< object to free */
return;
}
if (object_type == ECMA_OBJECT_TYPE_ARGUMENTS)
if (object_type == ECMA_OBJECT_TYPE_PSEUDO_ARRAY)
{
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p;
ecma_length_t formal_params_number = ext_object_p->u.arguments.length;
jmem_cpointer_t *arg_Literal_p = (jmem_cpointer_t *) (ext_object_p + 1);
for (ecma_length_t i = 0; i < formal_params_number; i++)
switch (ext_object_p->u.pseudo_array.type)
{
if (arg_Literal_p[i] != JMEM_CP_NULL)
case ECMA_PSEUDO_ARRAY_ARGUMENTS:
{
ecma_string_t *name_p = JMEM_CP_GET_NON_NULL_POINTER (ecma_string_t, arg_Literal_p[i]);
ecma_deref_ecma_string (name_p);
ecma_length_t formal_params_number = ext_object_p->u.pseudo_array.u1.length;
jmem_cpointer_t *arg_Literal_p = (jmem_cpointer_t *) (ext_object_p + 1);
for (ecma_length_t i = 0; i < formal_params_number; i++)
{
if (arg_Literal_p[i] != JMEM_CP_NULL)
{
ecma_string_t *name_p = JMEM_CP_GET_NON_NULL_POINTER (ecma_string_t, arg_Literal_p[i]);
ecma_deref_ecma_string (name_p);
}
}
size_t formal_params_size = formal_params_number * sizeof (jmem_cpointer_t);
ecma_dealloc_extended_object (ext_object_p, sizeof (ecma_extended_object_t) + formal_params_size);
return;
}
#ifndef CONFIG_DISABLE_TYPEDARRAY_BUILTIN
case ECMA_PSEUDO_ARRAY_TYPEDARRAY:
{
ecma_dealloc_extended_object ((ecma_extended_object_t *) object_p,
sizeof (ecma_extended_object_t));
return;
}
case ECMA_PSEUDO_ARRAY_TYPEDARRAY_WITH_INFO:
{
ecma_dealloc_extended_object ((ecma_extended_object_t *) object_p,
sizeof (ecma_extended_typedarray_object_t));
return;
}
#endif /* !CONFIG_DISABLE_TYPEDARRAY_BUILTIN */
default:
{
JERRY_UNREACHABLE ();
break;
}
}
size_t formal_params_size = formal_params_number * sizeof (jmem_cpointer_t);
ecma_dealloc_extended_object (ext_object_p, sizeof (ecma_extended_object_t) + formal_params_size);
return;
JERRY_UNREACHABLE ();
}
if (object_type == ECMA_OBJECT_TYPE_BOUND_FUNCTION)
+60 -10
View File
@@ -291,6 +291,11 @@ typedef enum
*/
#define ECMA_PROPERTY_TYPE_NOT_FOUND ECMA_PROPERTY_TYPE_DELETED
/**
* Type of property not found and no more searching in the proto chain.
*/
#define ECMA_PROPERTY_TYPE_NOT_FOUND_AND_STOP ECMA_PROPERTY_TYPE_HASHMAP
/**
* Property flag list (for ECMA_PROPERTY_TYPE_NAMEDDATA
* and ECMA_PROPERTY_TYPE_NAMEDACCESSOR).
@@ -321,6 +326,12 @@ typedef enum
#define ECMA_PROPERTY_CONFIGURABLE_WRITABLE \
(ECMA_PROPERTY_FLAG_CONFIGURABLE | ECMA_PROPERTY_FLAG_WRITABLE)
/**
* Property flags enumerable, writable.
*/
#define ECMA_PROPERTY_ENUMERABLE_WRITABLE \
(ECMA_PROPERTY_FLAG_ENUMERABLE | ECMA_PROPERTY_FLAG_WRITABLE)
/**
* No attributes can be changed for this property.
*/
@@ -488,7 +499,7 @@ typedef struct
} ecma_extended_property_ref_t;
/**
* Option flags for ecma_op_object_get_property
* Option flags for ecma_op_object_get_property.
*/
typedef enum
{
@@ -498,7 +509,7 @@ typedef enum
} ecma_property_get_option_bits_t;
/**
* Internal object types
* Internal object types.
*/
typedef enum
{
@@ -509,13 +520,25 @@ typedef enum
ECMA_OBJECT_TYPE_EXTERNAL_FUNCTION = 3, /**< External (host) function object */
ECMA_OBJECT_TYPE_ARRAY = 4, /**< Array object (15.4) */
ECMA_OBJECT_TYPE_BOUND_FUNCTION = 5, /**< Function objects (15.3), created through 15.3.4.5 routine */
ECMA_OBJECT_TYPE_ARGUMENTS = 6, /**< Arguments object (10.6) */
ECMA_OBJECT_TYPE_PSEUDO_ARRAY = 6, /**< Array-like object, such as Arguments object (10.6) */
ECMA_OBJECT_TYPE__MAX = ECMA_OBJECT_TYPE_ARGUMENTS /**< maximum value */
ECMA_OBJECT_TYPE__MAX = ECMA_OBJECT_TYPE_PSEUDO_ARRAY /**< maximum value */
} ecma_object_type_t;
/**
* Types of lexical environments
* Types of objects with class property.
*/
typedef enum
{
ECMA_PSEUDO_ARRAY_ARGUMENTS = 0, /**< Arguments object (10.6) */
ECMA_PSEUDO_ARRAY_TYPEDARRAY = 1, /**< TypedArray which does NOT need extra space to store length and offset */
ECMA_PSEUDO_ARRAY_TYPEDARRAY_WITH_INFO = 2, /**< TypedArray which NEEDS extra space to store length and offset */
ECMA_PSEUDO_ARRAY__MAX = ECMA_PSEUDO_ARRAY_TYPEDARRAY_WITH_INFO /**< maximum value */
} ecma_pseudo_array_type_t;
/**
* Types of lexical environments.
*/
typedef enum
{
@@ -629,13 +652,14 @@ typedef struct
struct
{
uint16_t class_id; /**< class id of the object */
/*
* Description of extra fields. These extra fields depends on the class_id.
*/
union
{
ecma_value_t value; /**< value of the object (e.g. boolean, number, string, etc.) */
uint32_t length; /**< length related property (e.g. length of ArrayBuffer) */
uint32_t length; /**< length related property (e.g. length of ArrayBuffer) */
} u;
} class_prop;
@@ -658,13 +682,24 @@ typedef struct
} array;
/*
* Description of arguments objects.
* Description of pseudo array objects.
*/
struct
{
ecma_value_t lex_env_cp; /**< lexical environment */
uint32_t length; /**< length of names */
} arguments;
uint8_t type; /**< pseudo array type, e.g. Arguments, TypedArray*/
uint8_t extra_info; /**< extra infomations about the object.
* e.g. element_width_shift for typed arrays */
union
{
uint16_t length; /**< for arguments: length of names */
uint16_t class_id; /**< for typedarray: the specific class name */
} u1;
union
{
ecma_value_t lex_env_cp; /**< for arguments: lexical environment */
ecma_value_t arraybuffer; /**< for typedarray: internal arraybuffer */
} u2;
} pseudo_array;
/*
* Description of bound function object.
@@ -1121,6 +1156,21 @@ typedef struct
#endif /* !CONFIG_ECMA_LCACHE_DISABLE */
#ifndef CONFIG_DISABLE_TYPEDARRAY_BUILTIN
/**
* Some internal properties of TypedArray object.
* It is only used when the offset is not 0, and
* the array-length is not buffer-length / element_size.
*/
typedef struct
{
ecma_extended_object_t extended_object; /**< extended object part */
ecma_length_t byte_offset; /**< the byteoffset of the above arraybuffer */
ecma_length_t array_length; /**< the array length */
} ecma_extended_typedarray_object_t;
#endif /* !CONFIG_DISABLE_TYPEDARRAY_BUILTIN */
/**
* @}
* @}