Cleanup code around JERRY_UNREACHABLEs (#2342)

`JERRY_UNREACHABLE`s often signal code structure that could be
improved: they can usually either be rewritten to `JERRY_ASSERT`s
or eliminated by restructuring loops, `if`s or `#if`s. Roughly,
the only valid occurences are in default cases of `switch`es. And
even they can often be merged into non-default cases.

Moreover, it is dangerous to write meaningful code after
`JERRY_UNREACHABLE` because it pretends as if there was a way to
recover from an impossible situation.

This patch rewrites/eliminates `JERRY_UNREACHABLE`s where possible
and removes misleading code from after them.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
This commit is contained in:
Akos Kiss
2018-05-25 07:27:30 +02:00
committed by GitHub
parent acb3e71436
commit 4779451284
24 changed files with 168 additions and 256 deletions
+8 -15
View File
@@ -714,11 +714,6 @@ ecma_copy_value (ecma_value_t value) /**< value description */
{
switch (ecma_get_value_type_field (value))
{
case ECMA_TYPE_DIRECT:
case ECMA_TYPE_DIRECT_STRING:
{
return value;
}
case ECMA_TYPE_FLOAT:
{
ecma_number_t *num_p = (ecma_number_t *) ecma_get_pointer_from_ecma_value (value);
@@ -737,8 +732,10 @@ ecma_copy_value (ecma_value_t value) /**< value description */
}
default:
{
JERRY_UNREACHABLE ();
return ECMA_VALUE_UNDEFINED;
JERRY_ASSERT (ecma_get_value_type_field (value) == ECMA_TYPE_DIRECT
|| ecma_get_value_type_field (value) == ECMA_TYPE_DIRECT_STRING);
return value;
}
}
} /* ecma_copy_value */
@@ -905,13 +902,6 @@ ecma_free_value (ecma_value_t value) /**< value description */
{
switch (ecma_get_value_type_field (value))
{
case ECMA_TYPE_DIRECT:
case ECMA_TYPE_DIRECT_STRING:
{
/* no memory is allocated */
break;
}
case ECMA_TYPE_FLOAT:
{
ecma_number_t *number_p = (ecma_number_t *) ecma_get_pointer_from_ecma_value (value);
@@ -934,7 +924,10 @@ ecma_free_value (ecma_value_t value) /**< value description */
default:
{
JERRY_UNREACHABLE ();
JERRY_ASSERT (ecma_get_value_type_field (value) == ECMA_TYPE_DIRECT
|| ecma_get_value_type_field (value) == ECMA_TYPE_DIRECT_STRING);
/* no memory is allocated */
break;
}
}