Merge branch 'master' of git-server:jerry

This commit is contained in:
Ilmir Usmanov 2014-07-29 11:55:37 +04:00
commit ac22173ddd
10 changed files with 233 additions and 63 deletions

View File

@ -127,8 +127,7 @@ run_int_from_pos (int start_pos,
completion = __opfuncs[curr->op_idx](*curr, &int_data);
JERRY_ASSERT( !ecma_is_completion_value_normal( completion)
|| ecma_is_completion_value_normal_simple_value(completion,
ECMA_SIMPLE_VALUE_EMPTY) );
|| ecma_is_empty_completion_value( completion) );
} while ( completion.type == ECMA_COMPLETION_TYPE_NORMAL );
if ( completion.type == ECMA_COMPLETION_TYPE_BREAK )

View File

@ -912,8 +912,7 @@ opfunc_pre_incr(OPCODE opdata, /**< operation data */
ecma_completion_value_t reg_assignment_res = set_variable_value (int_data,
dst_var_idx,
new_num_value);
JERRY_ASSERT( ecma_is_completion_value_normal_simple_value (reg_assignment_res,
ECMA_SIMPLE_VALUE_EMPTY) );
JERRY_ASSERT( ecma_is_empty_completion_value( reg_assignment_res) );
ecma_dealloc_number( new_num_p);
@ -963,8 +962,7 @@ opfunc_pre_decr(OPCODE opdata, /**< operation data */
ecma_completion_value_t reg_assignment_res = set_variable_value (int_data,
dst_var_idx,
new_num_value);
JERRY_ASSERT( ecma_is_completion_value_normal_simple_value (reg_assignment_res,
ECMA_SIMPLE_VALUE_EMPTY) );
JERRY_ASSERT( ecma_is_empty_completion_value (reg_assignment_res) );
ecma_dealloc_number( new_num_p);
@ -1014,8 +1012,7 @@ opfunc_post_incr(OPCODE opdata, /**< operation data */
ecma_completion_value_t reg_assignment_res = set_variable_value (int_data,
dst_var_idx,
old_value.value);
JERRY_ASSERT( ecma_is_completion_value_normal_simple_value (reg_assignment_res,
ECMA_SIMPLE_VALUE_EMPTY) );
JERRY_ASSERT( ecma_is_empty_completion_value( reg_assignment_res) );
ECMA_FINALIZE(old_num_value);
ECMA_FINALIZE(old_value);
@ -1063,8 +1060,7 @@ opfunc_post_decr(OPCODE opdata, /**< operation data */
ecma_completion_value_t reg_assignment_res = set_variable_value (int_data,
dst_var_idx,
old_value.value);
JERRY_ASSERT( ecma_is_completion_value_normal_simple_value (reg_assignment_res,
ECMA_SIMPLE_VALUE_EMPTY) );
JERRY_ASSERT( ecma_is_empty_completion_value (reg_assignment_res) );
ECMA_FINALIZE(old_num_value);
ECMA_FINALIZE(old_value);

View File

@ -63,12 +63,18 @@ typedef enum {
* Simple ecma-values
*/
typedef enum {
ECMA_SIMPLE_VALUE_EMPTY, /**< empty value (see also: ECMA-262 v5, 8.9 Completion specification type) */
/**
* Empty value is implementation defined value, used for:
* - representing empty value in completion values (see also: ECMA-262 v5, 8.9 Completion specification type);
* - values of uninitialized immutable bindings;
* - values of empty register variables.
*/
ECMA_SIMPLE_VALUE_EMPTY,
ECMA_SIMPLE_VALUE_UNDEFINED, /**< undefined value */
ECMA_SIMPLE_VALUE_NULL, /**< null value */
ECMA_SIMPLE_VALUE_FALSE, /**< boolean false */
ECMA_SIMPLE_VALUE_TRUE, /**< boolean true */
ECMA_SIMPLE_VALUE_ARRAY_REDIRECT, /**< special value for an array's elements that exists,
ECMA_SIMPLE_VALUE_ARRAY_REDIRECT, /**< implementation defined value for an array's elements that exists,
but is stored directly in the array's property list
(used for array elements with non-default attribute values) */
ECMA_SIMPLE_VALUE__COUNT /** count of simple ecma-values */
@ -183,7 +189,51 @@ typedef enum
} ecma_property_configurable_value_t;
/**
* Description of ecma-property.
* Description of ECMA property descriptor
*
* See also: ECMA-262 v5, 8.10.
*/
typedef struct
{
/** Is [[Value]] defined? */
unsigned int is_value_defined : 1;
/** Is [[Get]] defined? */
unsigned int is_get_defined : 1;
/** Is [[Set]] defined? */
unsigned int is_set_defined : 1;
/** Is [[Writable]] defined? */
unsigned int is_writable_defined : 1;
/** Is [[Enumerable]] defined? */
unsigned int is_enumerable_defined : 1;
/** Is [[Configurable]] defined? */
unsigned int is_configurable_defined : 1;
/** [[Value]] */
ecma_value_t value;
/** [[Get]] */
ecma_value_t get;
/** [[Set]] */
ecma_value_t set;
/** [[Writable]] */
ecma_property_writable_value_t writable;
/** [[Enumerable]] */
ecma_property_enumerable_value_t enumerable;
/** [[Configurable]] */
ecma_property_configurable_value_t configurable;
} ecma_property_descriptor_t;
/**
* Description of ecma-property
*/
typedef struct ecma_property_t {
/** Property's type (ecma_property_type_t) */

View File

@ -282,6 +282,24 @@ ecma_make_completion_value(ecma_completion_type_t type, /**< type */
return (ecma_completion_value_t) { .type = type, .value = value, .target = target };
} /* ecma_make_completion_value */
/**
* Simple normal completion value constructor
*
* @return completion value
*/
ecma_completion_value_t
ecma_make_simple_completion_value( ecma_simple_value_t simple_value) /**< simple ecma-value */
{
JERRY_ASSERT( simple_value == ECMA_SIMPLE_VALUE_UNDEFINED
|| simple_value == ECMA_SIMPLE_VALUE_NULL
|| simple_value == ECMA_SIMPLE_VALUE_FALSE
|| simple_value == ECMA_SIMPLE_VALUE_TRUE );
return ecma_make_completion_value( ECMA_COMPLETION_TYPE_NORMAL,
ecma_make_simple_value( simple_value),
ECMA_TARGET_ID_RESERVED);
} /* ecma_make_simple_completion_value */
/**
* Throw completion value constructor.
*
@ -308,8 +326,8 @@ ecma_completion_value_t
ecma_make_empty_completion_value( void)
{
return ecma_make_completion_value( ECMA_COMPLETION_TYPE_NORMAL,
ecma_make_simple_value( ECMA_SIMPLE_VALUE_EMPTY),
ECMA_TARGET_ID_RESERVED);
ecma_make_simple_value( ECMA_SIMPLE_VALUE_EMPTY),
ECMA_TARGET_ID_RESERVED);
} /* ecma_make_empty_completion_value */
/**
@ -321,8 +339,8 @@ ecma_completion_value_t
ecma_copy_completion_value( ecma_completion_value_t value) /**< completion value */
{
return ecma_make_completion_value( value.type,
ecma_copy_value( value.value),
value.target);
ecma_copy_value( value.value),
value.target);
} /* ecma_copy_completion_value */
/**
@ -412,6 +430,20 @@ ecma_is_completion_value_normal_false( ecma_completion_value_t value) /**< compl
return ecma_is_completion_value_normal_simple_value( value, ECMA_SIMPLE_VALUE_FALSE);
} /* ecma_is_completion_value_normal_false */
/**
* Check if the completion value is normal empty value.
*
* @return true - if the completion type is normal and
* value contains empty simple value,
* false - otherwise.
*/
bool
ecma_is_empty_completion_value( ecma_completion_value_t value) /**< completion value */
{
return ( ecma_is_completion_value_normal( value)
&& ecma_is_value_empty( value.value) );
} /* ecma_is_empty_completion_value */
/**
* @}
* @}

View File

@ -700,6 +700,96 @@ ecma_free_array( ecma_array_first_chunk_t *first_chunk_p) /**< first chunk of th
}
} /* ecma_free_array */
/**
* ECMA property descriptor constructor.
*
* @return ecma property descriptor
*/
ecma_property_descriptor_t
ecma_make_property_descriptor( bool is_value_defined, /**< is [[Value]] defined */
bool is_get_defined, /**< is [[Get]] defined */
bool is_set_defined, /**< is [[Set]] defined */
bool is_writable_defined, /**< is [[Writable]] defined */
bool is_enumerable_defined, /**< is [[Enumerable]] defined */
bool is_configurable_defined, /**< is [[Configurable]] defined */
ecma_value_t value, /**< [[Value]] */
ecma_value_t get, /**< [[Get]] */
ecma_value_t set, /**< [[Set]] */
ecma_property_writable_value_t writable, /**< [[Writable]] */
ecma_property_enumerable_value_t enumerable, /**< [[Enumerable]] */
ecma_property_configurable_value_t configurable) /**< [[Configurable]] */
{
ecma_property_descriptor_t prop_desc;
prop_desc.is_value_defined = is_value_defined;
prop_desc.is_get_defined = is_get_defined;
prop_desc.is_set_defined = is_set_defined;
prop_desc.is_writable_defined = is_writable_defined;
prop_desc.is_enumerable_defined = is_enumerable_defined;
prop_desc.is_configurable_defined = is_configurable_defined;
if ( prop_desc.is_value_defined )
{
prop_desc.value = value;
}
if ( prop_desc.is_get_defined )
{
prop_desc.get = get;
}
if ( prop_desc.is_set_defined )
{
prop_desc.set = set;
}
if ( prop_desc.is_writable_defined )
{
prop_desc.writable = writable;
}
if ( prop_desc.is_enumerable_defined )
{
prop_desc.enumerable = enumerable;
}
if ( prop_desc.is_configurable_defined )
{
prop_desc.configurable = configurable;
}
return prop_desc;
} /* ecma_make_property_descriptor */
/**
* Free the ecma property descriptor.
*/
void
ecma_free_property_descriptor( ecma_property_descriptor_t prop_desc) /**< ECMA property descriptor */
{
if ( prop_desc.is_value_defined )
{
ecma_free_value( prop_desc.value);
}
if ( prop_desc.is_get_defined )
{
ecma_free_value( prop_desc.get);
}
if ( prop_desc.is_set_defined )
{
ecma_free_value( prop_desc.set);
}
prop_desc.is_value_defined = false;
prop_desc.is_get_defined = false;
prop_desc.is_set_defined = false;
prop_desc.is_writable_defined = false;
prop_desc.is_enumerable_defined = false;
prop_desc.is_configurable_defined = false;
} /* ecma_free_property_descriptor */
/**
* @}
* @}

View File

@ -56,6 +56,7 @@ extern ecma_value_t ecma_copy_value( const ecma_value_t value);
extern void ecma_free_value( const ecma_value_t value);
extern ecma_completion_value_t ecma_make_completion_value( ecma_completion_type_t type, ecma_value_t value, uint8_t target);
extern ecma_completion_value_t ecma_make_simple_completion_value( ecma_simple_value_t simple_value);
extern ecma_completion_value_t ecma_make_throw_value( ecma_object_t *exception_p);
extern ecma_completion_value_t ecma_make_empty_completion_value( void);
extern ecma_completion_value_t ecma_copy_completion_value( ecma_completion_value_t value);
@ -64,8 +65,9 @@ extern void ecma_free_completion_value( ecma_completion_value_t completion_value
extern bool ecma_is_completion_value_normal( ecma_completion_value_t value);
extern bool ecma_is_completion_value_throw( ecma_completion_value_t value);
extern bool ecma_is_completion_value_normal_simple_value( ecma_completion_value_t value, ecma_simple_value_t simple_value);
extern bool ecma_is_completion_value_normal_false( ecma_completion_value_t value);
extern bool ecma_is_completion_value_normal_true( ecma_completion_value_t value);
extern bool ecma_is_completion_value_normal_false( ecma_completion_value_t value);
extern bool ecma_is_empty_completion_value( ecma_completion_value_t value);
extern ecma_object_t* ecma_create_object( ecma_object_t *prototype_object_p, bool is_extensible);
extern ecma_object_t* ecma_create_lexical_environment( ecma_object_t *outer_lexical_environment_p, ecma_lexical_environment_type_t type);
@ -94,6 +96,21 @@ extern bool ecma_compare_zt_string_to_ecma_string( const ecma_char_t *string_p,
extern bool ecma_compare_ecma_string_to_ecma_string(const ecma_array_first_chunk_t *string1_p, const ecma_array_first_chunk_t *string2_p);
extern void ecma_free_array( ecma_array_first_chunk_t *first_chunk_p);
extern ecma_property_descriptor_t ecma_make_property_descriptor( bool is_value_defined,
bool is_get_defined,
bool is_set_defined,
bool is_writable_defined,
bool is_enumerable_defined,
bool is_configurable_defined,
ecma_value_t value,
ecma_value_t get,
ecma_value_t set,
ecma_property_writable_value_t writable,
ecma_property_enumerable_value_t enumerable,
ecma_property_configurable_value_t configurable);
extern void ecma_free_property_descriptor( ecma_property_descriptor_t prop_desc);
#endif /* !JERRY_ECMA_HELPERS_H */
/**

View File

@ -44,25 +44,18 @@ ecma_op_check_object_coercible( ecma_value_t value) /**< ecma-value */
{
case ECMA_TYPE_SIMPLE:
{
switch ( (ecma_simple_value_t)value.value )
{
case ECMA_SIMPLE_VALUE_UNDEFINED:
case ECMA_SIMPLE_VALUE_NULL:
{
return ecma_make_throw_value( ecma_new_standard_error( ECMA_ERROR_TYPE));
}
case ECMA_SIMPLE_VALUE_FALSE:
case ECMA_SIMPLE_VALUE_TRUE:
{
break;
}
case ECMA_SIMPLE_VALUE_EMPTY:
case ECMA_SIMPLE_VALUE_ARRAY_REDIRECT:
case ECMA_SIMPLE_VALUE__COUNT:
{
JERRY_UNREACHABLE();
}
}
if ( ecma_is_value_undefined( value) )
{
return ecma_make_throw_value( ecma_new_standard_error( ECMA_ERROR_TYPE));
}
else if ( ecma_is_value_boolean( value) )
{
break;
}
else
{
JERRY_UNREACHABLE();
}
break;
}
@ -130,8 +123,6 @@ ecma_op_to_primitive( ecma_value_t value, /**< ecma-value */
ecma_completion_value_t
ecma_op_to_boolean( ecma_value_t value) /**< ecma-value */
{
ecma_simple_value_t res = ECMA_SIMPLE_VALUE_EMPTY;
switch ( (ecma_type_t)value.value_type )
{
case ECMA_TYPE_NUMBER:
@ -139,8 +130,9 @@ ecma_op_to_boolean( ecma_value_t value) /**< ecma-value */
ecma_number_t *num_p = ecma_get_pointer( value.value);
TODO( Implement according to ECMA );
res = ( *num_p == 0 ) ? ECMA_SIMPLE_VALUE_FALSE:
ECMA_SIMPLE_VALUE_TRUE;
return ecma_make_simple_completion_value( ( *num_p == 0 ) ? ECMA_SIMPLE_VALUE_FALSE
: ECMA_SIMPLE_VALUE_TRUE );
break;
}
@ -148,11 +140,11 @@ ecma_op_to_boolean( ecma_value_t value) /**< ecma-value */
{
if ( ecma_is_value_boolean (value ) )
{
res = value.value;
return ecma_make_simple_completion_value( value.value);
} else if ( ecma_is_value_undefined (value)
|| ecma_is_value_null( value) )
{
res = ECMA_SIMPLE_VALUE_FALSE;
return ecma_make_simple_completion_value( ECMA_SIMPLE_VALUE_FALSE);
} else
{
JERRY_UNREACHABLE();
@ -164,14 +156,14 @@ ecma_op_to_boolean( ecma_value_t value) /**< ecma-value */
{
ecma_array_first_chunk_t *str_p = ecma_get_pointer( value.value);
res = ( str_p->header.unit_number == 0 ) ? ECMA_SIMPLE_VALUE_FALSE:
ECMA_SIMPLE_VALUE_TRUE;
return ecma_make_simple_completion_value( ( str_p->header.unit_number == 0 ) ? ECMA_SIMPLE_VALUE_FALSE
: ECMA_SIMPLE_VALUE_TRUE );
break;
}
case ECMA_TYPE_OBJECT:
{
res = ECMA_SIMPLE_VALUE_TRUE;
return ecma_make_simple_completion_value( ECMA_SIMPLE_VALUE_TRUE);
break;
}
@ -181,12 +173,7 @@ ecma_op_to_boolean( ecma_value_t value) /**< ecma-value */
}
}
JERRY_ASSERT( res == ECMA_SIMPLE_VALUE_FALSE
|| res == ECMA_SIMPLE_VALUE_TRUE );
return ecma_make_completion_value (ECMA_COMPLETION_TYPE_NORMAL,
ecma_make_simple_value( res),
ECMA_TARGET_ID_RESERVED);
JERRY_UNREACHABLE();
} /* ecma_op_to_boolean */
/**

View File

@ -186,8 +186,7 @@ ecma_op_get_binding_value(ecma_object_t *lex_env_p, /**< lexical environment */
return ecma_make_completion_value( ECMA_COMPLETION_TYPE_NORMAL,
ecma_copy_value( prop_value),
ECMA_TARGET_ID_RESERVED);
} else if ( prop_value.value_type == ECMA_TYPE_SIMPLE
&& prop_value.value == ECMA_SIMPLE_VALUE_EMPTY )
} else if ( ecma_is_value_empty( prop_value) )
{
/* unitialized immutable binding */
if ( is_strict )
@ -318,13 +317,14 @@ ecma_op_create_immutable_binding(ecma_object_t *lex_env_p, /**< lexical environm
* Whether immutable bindings are deletable seems not to be defined by ECMA v5.
*/
ecma_property_t *prop_p = ecma_create_named_property( lex_env_p,
name_p,
ECMA_PROPERTY_NOT_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_NOT_CONFIGURABLE);
name_p,
ECMA_PROPERTY_NOT_WRITABLE,
ECMA_PROPERTY_NOT_ENUMERABLE,
ECMA_PROPERTY_NOT_CONFIGURABLE);
JERRY_ASSERT( prop_p->u.named_data_property.value.value_type == ECMA_TYPE_SIMPLE );
JERRY_ASSERT( ecma_is_value_undefined( prop_p->u.named_data_property.value ) );
prop_p->u.named_data_property.value.value_type = ECMA_TYPE_SIMPLE;
prop_p->u.named_data_property.value.value = ECMA_SIMPLE_VALUE_EMPTY;
}
case ECMA_LEXICAL_ENVIRONMENT_OBJECTBOUND:
@ -358,8 +358,7 @@ ecma_op_initialize_immutable_binding(ecma_object_t *lex_env_p, /**< lexical envi
/* The binding must be unitialized immutable binding */
JERRY_ASSERT( prop_p->u.named_data_property.writable == ECMA_PROPERTY_NOT_WRITABLE
&& prop_p->u.named_data_property.value.value_type == ECMA_TYPE_SIMPLE
&& prop_p->u.named_data_property.value.value == ECMA_SIMPLE_VALUE_EMPTY );
&& ecma_is_value_empty( prop_p->u.named_data_property.value) );
prop_p->u.named_data_property.value = ecma_copy_value( value);
}

View File

@ -166,7 +166,7 @@ ecma_op_object_default_value( ecma_object_t *obj_p, /**< the object */
ecma_completion_value_t
ecma_op_object_define_own_property( ecma_object_t *obj_p, /**< the object */
ecma_array_first_chunk_t *property_name_p, /**< property name */
ecma_property_t property_desc, /**< property descriptor */
ecma_property_descriptor_t property_desc, /**< property descriptor */
bool is_throw) /**< flag that controls failure handling */
{
JERRY_UNIMPLEMENTED_REF_UNUSED_VARS( obj_p, property_name_p, property_desc, is_throw);

View File

@ -41,7 +41,7 @@ extern ecma_completion_value_t ecma_op_object_delete( ecma_object_t *obj_p,
extern ecma_completion_value_t ecma_op_object_default_value( ecma_object_t *obj_p, ecma_preferred_type_hint_t hint);
extern ecma_completion_value_t ecma_op_object_define_own_property( ecma_object_t *obj_p,
ecma_array_first_chunk_t *property_name_p,
ecma_property_t property_desc,
ecma_property_descriptor_t property_desc,
bool is_throw);
/**