Implementing String's constructor and [[GetOwnProperty]].
This commit is contained in:
@@ -405,6 +405,9 @@ ecma_gc_mark (ecma_object_t *object_p, /**< start object */
|
||||
}
|
||||
|
||||
case ECMA_INTERNAL_PROPERTY_FORMAL_PARAMETERS: /* a collection of strings */
|
||||
case ECMA_INTERNAL_PROPERTY_PRIMITIVE_STRING_VALUE: /* compressed pointer to a ecma_string_t */
|
||||
case ECMA_INTERNAL_PROPERTY_PRIMITIVE_NUMBER_VALUE: /* compressed pointer to a ecma_number_t */
|
||||
case ECMA_INTERNAL_PROPERTY_PRIMITIVE_BOOLEAN_VALUE: /* a simple boolean value */
|
||||
case ECMA_INTERNAL_PROPERTY_PROVIDE_THIS: /* a boolean */
|
||||
case ECMA_INTERNAL_PROPERTY_CLASS: /* an enum */
|
||||
case ECMA_INTERNAL_PROPERTY_CODE: /* an integer */
|
||||
|
||||
@@ -183,6 +183,9 @@ typedef enum
|
||||
ECMA_INTERNAL_PROPERTY_PARAMETERS_MAP, /**< [[ParametersMap]] */
|
||||
ECMA_INTERNAL_PROPERTY_CODE, /**< [[Code]] */
|
||||
ECMA_INTERNAL_PROPERTY_FORMAL_PARAMETERS, /**< [[FormalParameters]] */
|
||||
ECMA_INTERNAL_PROPERTY_PRIMITIVE_STRING_VALUE, /**< [[Primitive value]] for String objects */
|
||||
ECMA_INTERNAL_PROPERTY_PRIMITIVE_NUMBER_VALUE, /**< [[Primitive value]] for Number objects */
|
||||
ECMA_INTERNAL_PROPERTY_PRIMITIVE_BOOLEAN_VALUE, /**< [[Primitive value]] for Boolean objects */
|
||||
|
||||
/** provideThis property of lexical environment */
|
||||
ECMA_INTERNAL_PROPERTY_PROVIDE_THIS,
|
||||
@@ -212,7 +215,7 @@ typedef enum
|
||||
/**
|
||||
* Bit-mask of non-instantiated built-in's properties (bits 32-63)
|
||||
*/
|
||||
ECMA_INTERNAL_PROPERTY_NON_INSTANTIATED_BUILT_IN_MASK_32_63,
|
||||
ECMA_INTERNAL_PROPERTY_NON_INSTANTIATED_BUILT_IN_MASK_32_63
|
||||
} ecma_internal_property_id_t;
|
||||
|
||||
/**
|
||||
@@ -298,7 +301,7 @@ typedef struct ecma_property_t
|
||||
struct __packed ecma_internal_property_t
|
||||
{
|
||||
/** Internal property's type */
|
||||
unsigned int type : 4;
|
||||
unsigned int type : 5;
|
||||
|
||||
/** Value (may be a compressed pointer) */
|
||||
uint32_t value;
|
||||
@@ -740,6 +743,8 @@ typedef enum
|
||||
ECMA_MAGIC_STRING_SIN, /**< "sin" */
|
||||
ECMA_MAGIC_STRING_SQRT, /**< "sqrt" */
|
||||
ECMA_MAGIC_STRING_TAN, /**< "tan" */
|
||||
ECMA_MAGIC_STRING_FROM_CHAR_CODE_UL, /**< "fromCharCode" */
|
||||
ECMA_MAGIC_STRING__EMPTY, /**< "" */
|
||||
ECMA_MAGIC_STRING__COUNT /**< number of magic strings */
|
||||
} ecma_magic_string_id_t;
|
||||
|
||||
|
||||
@@ -992,6 +992,36 @@ ecma_string_get_length (const ecma_string_t *string_p) /**< ecma-string */
|
||||
}
|
||||
} /* ecma_string_get_length */
|
||||
|
||||
/**
|
||||
* Get character from specified position in the ecma-string.
|
||||
*
|
||||
* @return character value
|
||||
*/
|
||||
ecma_char_t
|
||||
ecma_string_get_char_at_pos (const ecma_string_t *string_p, /**< ecma-string */
|
||||
uint32_t index) /**< index of character */
|
||||
{
|
||||
uint32_t length = (uint32_t) ecma_string_get_length (string_p);
|
||||
JERRY_ASSERT (index < (uint32_t) length);
|
||||
|
||||
size_t buffer_size = sizeof (ecma_char_t) * (length + 1);
|
||||
ecma_char_t *zt_str_p = mem_heap_alloc_block (buffer_size,
|
||||
MEM_HEAP_ALLOC_SHORT_TERM);
|
||||
|
||||
if (zt_str_p == NULL)
|
||||
{
|
||||
jerry_exit (ERR_MEMORY);
|
||||
}
|
||||
|
||||
ecma_string_to_zt_string (string_p, zt_str_p, (ssize_t) buffer_size);
|
||||
|
||||
ecma_char_t ch = zt_str_p [index];
|
||||
|
||||
mem_heap_free_block (zt_str_p);
|
||||
|
||||
return ch;
|
||||
} /* ecma_string_get_char_at_pos */
|
||||
|
||||
/**
|
||||
* Compare zero-terminated string to zero-terminated string
|
||||
*
|
||||
@@ -1309,6 +1339,8 @@ ecma_get_magic_string_zt (ecma_magic_string_id_t id) /**< magic string id */
|
||||
case ECMA_MAGIC_STRING_SIN: return (ecma_char_t*) "sin";
|
||||
case ECMA_MAGIC_STRING_SQRT: return (ecma_char_t*) "sqrt";
|
||||
case ECMA_MAGIC_STRING_TAN: return (ecma_char_t*) "tan";
|
||||
case ECMA_MAGIC_STRING_FROM_CHAR_CODE_UL: return (ecma_char_t*) "fromCharCode";
|
||||
case ECMA_MAGIC_STRING__EMPTY: return (ecma_char_t*) "";
|
||||
case ECMA_MAGIC_STRING__COUNT: break;
|
||||
}
|
||||
|
||||
|
||||
@@ -655,6 +655,23 @@ ecma_free_internal_property (ecma_property_t *property_p) /**< the property */
|
||||
break;
|
||||
}
|
||||
|
||||
case ECMA_INTERNAL_PROPERTY_PRIMITIVE_STRING_VALUE: /* compressed pointer to a ecma_string_t */
|
||||
{
|
||||
ecma_string_t *str_p = ECMA_GET_POINTER (property_value);
|
||||
ecma_deref_ecma_string (str_p);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case ECMA_INTERNAL_PROPERTY_PRIMITIVE_NUMBER_VALUE: /* pointer to a ecma_number_t */
|
||||
{
|
||||
ecma_number_t *num_p = ECMA_GET_POINTER (property_value);
|
||||
ecma_dealloc_number (num_p);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case ECMA_INTERNAL_PROPERTY_PRIMITIVE_BOOLEAN_VALUE: /* a simple boolean value */
|
||||
case ECMA_INTERNAL_PROPERTY_SCOPE: /* a lexical environment */
|
||||
case ECMA_INTERNAL_PROPERTY_PARAMETERS_MAP: /* an object */
|
||||
case ECMA_INTERNAL_PROPERTY_BINDING_OBJECT: /* an object */
|
||||
|
||||
@@ -113,6 +113,7 @@ extern bool ecma_compare_ecma_strings (const ecma_string_t *string1_p,
|
||||
extern bool ecma_compare_ecma_strings_relational (const ecma_string_t *string1_p,
|
||||
const ecma_string_t *string2_p);
|
||||
extern int32_t ecma_string_get_length (const ecma_string_t *string_p);
|
||||
extern ecma_char_t ecma_string_get_char_at_pos (const ecma_string_t *string_p, uint32_t index);
|
||||
extern bool ecma_compare_zt_strings (const ecma_char_t *string1_p, const ecma_char_t *string2_p);
|
||||
extern bool ecma_compare_zt_strings_relational (const ecma_char_t *string1_p, const ecma_char_t *string2_p);
|
||||
extern ssize_t ecma_copy_zt_string_to_buffer (const ecma_char_t *string_p, ecma_char_t *buffer_p, ssize_t buffer_size);
|
||||
|
||||
Reference in New Issue
Block a user