Style fixes regarding 'empty' value: introducing ecma_is_empty_completion_value, reducing usage of the 'empty' value, listing possible usage cases of the 'empty' value in the comment to it's definition.

This commit is contained in:
Ruben Ayrapetyan
2014-07-28 21:21:31 +04:00
parent 177a2d1382
commit 3ee0e8a8a5
7 changed files with 81 additions and 60 deletions
+1 -2
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 )
+4 -8
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);
+8 -2
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 */
+36 -4
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 */
/**
* @}
* @}
+3 -1
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);
+21 -34
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 */
/**
+8 -9
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);
}